internals.sgml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <!doctype texinfo system "texinfo.dtd" [
  2. <!entity % manuals-version-def system "manuals-version">
  3. %manuals-version-def;
  4. ]>
  5. <texinfo>
  6. <setfilename>internals.info</>
  7. <titlepage>
  8. <title>dpkg Internals Manual</title>
  9. <author>Klee Dienes</author>
  10. <date>Version &manuals-version; (dpkg &dpkg-version;)</date>
  11. <abstract>
  12. This manual describes the internal structure of the <code/dpkg/ package
  13. management system.
  14. </abstract>
  15. </titlepage>
  16. <chapter>Copyright
  17. <p>
  18. Copyright &copy;1997 Klee Dienes <samp/&lt;klee@@mit.edu&gt;/.
  19. <p>
  20. This manual is free software; you may redistribute it and/or modify it
  21. under the terms of the GNU General Public License as published by the
  22. Free Software Foundation; either version 2, or (at your option) any
  23. later version.
  24. <p>
  25. This is distributed in the hope that it will be useful, but
  26. <em>without any warranty</em>; without even the implied warranty of
  27. merchantability or fitness for a particular purpose. See the GNU
  28. General Public License for more details.
  29. You should have received a copy of the GNU General Public License with
  30. your Debian GNU/Linux system, in <file>/usr/share/common-licenses/GPL</>, or
  31. with the <code/dpkg/ source package as the file <file>COPYING</>. If
  32. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  33. Cambridge, MA 02139, USA.
  34. </chapter>
  35. <chapter>Build Notes
  36. <section>Automake
  37. <p>
  38. This chapter by Tom Lees &lt;tom&at;lpsg.demon.co.uk&gt on Tue, 4 Mar 1997
  39. 21:34:57 +0000, with subsequent modifications by Klee Dienes &lt;klee&at;debian.org&gt;
  40. <p>
  41. This chapter contains general notes about the conversion to
  42. <code/automake/. If you plan on doing anything with <code/dpkg/, you
  43. should probably read all of this file first. You have been warned.
  44. <p>
  45. The current version of automake used is version <code/automake-1.1n/,
  46. which is currently a beta version. It has several significant
  47. advantages over the released version, including:
  48. <itemize>
  49. <item>it supports emacs lisp properly
  50. <item>It supports libtool properly
  51. <item>it includes the aclocal utility
  52. </itemize>
  53. <p>
  54. The <code/aclocal/ utility is a very useful program which will automatically
  55. build an <file/aclocal.m4/ file from the <file/configure.in/ file to include the
  56. appropriate macros.
  57. <p>
  58. <code/automake-1.1n/ can be retreived from
  59. <file>ftp://ftp.cygnus.com/pub/tromey</file>
  60. <p>
  61. This doesn't affect anything other than rebuilding the <file/Makefile.in/ files
  62. from the sources.
  63. <p>
  64. Probably the main difference which is noticable is that instead of
  65. using proprietary directory names, it now supports <code/configure
  66. --sharedstatedir/, and <code/configure --localstatedir/. To set these
  67. to the Debian defaults, you should use <code>./configure
  68. --localstatedir=/etc --sharedstatedir=/var/lib</>.
  69. <p>
  70. I have also customized the canonicalizing macros found in
  71. <code/autoconf-2.12/ to include the old way of finding the <code/dpkg/
  72. ``architecture'', i.e. to be a bit more smart. Instead of it trying to
  73. determine the architecture only, I changed it to use the `host',
  74. `build', and `target' system types. The target CPU type is checked
  75. against the archtable to find the architecture on which dpkg will run.
  76. <p>
  77. It uses <code/gcc --print-libgcc-file-name/ to find out the build
  78. architecture if possible (used later to determine ELF or <code/a.out/
  79. format), and also uses <code/dpkg --print-architecture/ if possible to
  80. modify the <samp/cpu/ field before it passes on the target alias to
  81. config.sub. If you want to specify the architecture, you should now
  82. use "--target=", rather than <code/--with-arch/, which was essentially
  83. a hack anyway. The old <code/--with-arch/ is still there, but it is
  84. somewhat less functional. I have also moved the <code/DPKG_CACHED_/
  85. macros into dpkg.m4 to make configure.in a bit more readable.
  86. <p>
  87. I also converted to libtool 0.7 (which can be found in the Debian
  88. distribution now). Essentially, this means that all the dpkg tools can
  89. be compiled against a shared <samp/libdpkg/ without much hassle (in
  90. fact, it is the default). You do not need to install libtool to use
  91. this feature (it works like autoconf), and generally, it should not be
  92. needed much at all.
  93. <p>
  94. The new <samp/dist/ targets will build a distribution including all
  95. files built by the <code/debiandoc2html/, <code/debiandoc2ps/, etc.,
  96. which are included in the distribution so that people may build <code/dpkg/
  97. without these (especially useful to porters).
  98. <p>
  99. A target <samp/make debian/ has been added, which will build the
  100. Debian files from a working directory (does a <samp/make dist/
  101. first). Now all we need is a modified dpkg-source so that the
  102. <file/dpkg-1.4.0.8.tar.gz/ GNU-distribution file can be used as part
  103. of the Debian dsitribution. I'm working on this, but it doesn't work
  104. too well at the moment (find it in examples).
  105. <p>
  106. I removed the <samp/make portable/ target - it doesn't do anything useful.
  107. <p>
  108. I have added <samp/make uninstall/ targets to aid non-Debian users who simply
  109. want to try out certain Debian packages, and the "dist" targets are also
  110. useful to build a "distribution" of the dpkg tool. Note that since automake
  111. automatically includes dependencies into the Makefiles in a distribution,
  112. if you want to modify the C files, it would be advisable to get and install
  113. automake, and then re-run it in the base dpkg distribution directory, so that
  114. automatic dependency generation will be switched back on, and any
  115. dependencies which change will be taken account of. The "make maintainer-clean"
  116. targets will remove all files which any of the following utilities create:
  117. <itemize>
  118. <item>automake
  119. <item>autoconf
  120. <item>aclocal
  121. <item>autoheader
  122. <item>gettextize
  123. <item>libtoolize
  124. </itemize>
  125. <p>
  126. If you want to modify any of the sources, I recommend that you do the following
  127. first (after having installed the appropriate utilities, of course):-
  128. <itemize>
  129. <item>
  130. make maintainer-clean
  131. <item>
  132. aclocal
  133. <item>
  134. autoheader
  135. <item>
  136. autoconf
  137. <item>
  138. gettextize
  139. <item>
  140. libtoolize (do not let automake run this, as it will cause it not to
  141. include the libtool files in the dist targets)
  142. <item>
  143. for i in COPYING INSTALL; do ln -s /usr/share/automake/$i .; done
  144. <item>
  145. automake
  146. </itemize>
  147. <p>
  148. I have also incorporated the patches originally made by Galen
  149. Hazelwood to internationalize dpkg using GNU gettext - see the file
  150. "NOTES.intl" for more information about this.
  151. <p>
  152. Other minor changes are:
  153. <itemize>
  154. <item>
  155. The version number is now determined from debian/changelog, not from
  156. the directory name.
  157. <item>
  158. Creation of version.h now handled from configure script, not Makefile.
  159. <item>
  160. include/dpkg.h is now generated from include/dpkg.h.in by a sed
  161. script, inserting the appropriate directory definitions - so now it
  162. supports changing the dpkg directories (can install in /usr/local)
  163. <item>
  164. Updated the COPYING (1 very minor change) and INSTALL files to those
  165. distributed with automake-1.1l
  166. <item>
  167. Since the shared libdpkg is now installed, I also made
  168. include/Makefile install dpkg.h and dpkg-db.h into /usr/include by
  169. default
  170. </itemize>
  171. Questions:
  172. <itemize>
  173. <item>
  174. Should I use <samp/localstatedir/ and <samp/sharedstatedir/ instead of
  175. <samp/sysconfdir/ and <samp/datadir/?
  176. </itemize>
  177. </section>
  178. <section>Internationalization
  179. <p>
  180. This section by Galen Hazelwood.
  181. <p>
  182. Dpkg is, to say the least, generous in its error reporting. The vast
  183. majority of the output strings are error messages of one kind or another.
  184. And if you feel that you've stumbled into the Department of Redundancy
  185. Department, you would be absolutely correct. Many of the error messages
  186. in dpkg.pot are duplicates, used at different points in the program.
  187. <p>
  188. To avoid swamping the translators completely, I made some executive decisions
  189. on what kinds of strings to translate. All the strings sent to debug() are
  190. left alone, on the grounds that these are for dpkg developers, and not for
  191. the general public. Most interal error messages were very cryptic, and
  192. would probably confuse the translators when seen just sitting there in
  193. the dpkg.pot file, and are also left alone. (I did mark some of the more
  194. verbose ones for translation.)
  195. <p>
  196. If others disagree with me about the necessity of translating these strings,
  197. it's easy enough to just go through and mark them later.
  198. <p>
  199. I added the startup gettext code to the main routine in dselect, which was
  200. necessary as many of the strings in lib are translated. Dselect is otherwise
  201. unchanged.
  202. <p>
  203. Changes:
  204. <itemize>
  205. <item>
  206. The files in intl and po were taken from gettext 0.10.26, by way of
  207. the gettextize program. I altered the makefiles to remove the VERSION
  208. symbol, which is only used in targets which dpkg does not support.
  209. <item>
  210. aclocal.m4 was stolen from the textutils package, configure.in was
  211. altered to use these new tests, symbols were added to acconfig.h, and
  212. the two new directories were added to Makefile.in.
  213. <item>
  214. The dpkg, dpkg-deb, md5sum, split, and dselect Makefiles now look for
  215. headers in ../intl, and try to link with whatever i18n libraries
  216. configure finds. They also now define LOCALEDIR in CFLAGS.
  217. <item>
  218. include/dpkg.h has the necessary NLS boilerplate, and the only file
  219. which dosen't include this (md5sum/md5sum.c) had it added directly.
  220. <item>
  221. The most intrusive change is due to a disagreement between xgettext
  222. and the dpkg coding style. Although xgettext understands string
  223. constant concatenation, it can't handle the case where preprocessor
  224. symbols are used as well. The dpkg code uses this a lot, especially
  225. in cases like this:
  226. <example>
  227. ohshite("error reading from " BACKEND " pipe");
  228. </example>
  229. where BACKEND is defined as "dpkg-deb". Because xgettext can't handle
  230. this, I have changed this usage in all cases to something like:
  231. <example>
  232. ohshite(_("error reading from dpkg-deb pipe");
  233. </example>
  234. This isn't very kind to Ian, I know. But what can I do?
  235. </itemize>
  236. </section>
  237. </chapter>
  238. <chapter>Code Internals
  239. <section>Structure Definitons
  240. <subsection>versionrevision
  241. <p>
  242. <example>
  243. struct versionrevision @{
  244. unsigned long epoch;
  245. char *version;
  246. char *revision;
  247. @};
  248. </example>
  249. <p>
  250. The <tt/versionrevision/ structure is used to store a Debian version specification
  251. </subsection>
  252. </section>
  253. <section>Functions
  254. <subsection>Parsing translation tables
  255. <p>
  256. Each of these tables is used to associate a set of strings with a
  257. corresponding set of integers.
  258. Current tables are:
  259. <p>
  260. <example>
  261. const struct namevalue booleaninfos[];
  262. </example>
  263. <p>
  264. Maps boolean strings (<code/"yes"/,<code/"no"/) to their binary values.
  265. <subsubsection><code/priorityinfos[]/
  266. <p>
  267. <example>
  268. const struct namevalue priorityinfos[];
  269. </example>
  270. <p>
  271. Maps priority strings to and from values of
  272. type <code/enum pkgpriority/.
  273. Current priority values are:
  274. <table>
  275. <item><code/required/</item>
  276. required
  277. <item><code/important/</item>
  278. important
  279. <item><code/standard/</item>
  280. standard
  281. <item><code/recommended/</item>
  282. recommended
  283. <item><code/optional/</item>
  284. optional
  285. <item><code/extra/</item>
  286. extra
  287. <item><code/contrib/</item>
  288. contrib
  289. <item><code/other/</item>
  290. other
  291. <item><code/unknown/</item>
  292. unknown
  293. <item><code/base/</item>
  294. This is obsolete, but is accepted as an alias for <code/required/.
  295. </table>
  296. </subsubsection>
  297. <subsubsection><code/statusinfos[]/
  298. <p>
  299. <example>
  300. const struct namevalue statusinfos[];
  301. </example>
  302. Maps package status strings to values of type <code/enum ???/.
  303. Package status strings are:
  304. "not-installed" "unpacked" "half-configured" "installed"
  305. "half-installed" "config-files" "postinst-failed" "removal-failed"
  306. </subsubsection>
  307. <subsubsection><code/eflaginfos[]/
  308. <p>
  309. <example>
  310. const struct namevalue eflaginfos[];
  311. </example>
  312. </subsubsection>
  313. <subsubsection><code/wantinfos[]/
  314. <p>
  315. <example>
  316. const struct namevalue wantinfos[];
  317. </example>
  318. </subsubsection>
  319. <subsubsection><code/nicknames[]/
  320. <p>
  321. <example>
  322. const struct nickname nicknames[];
  323. </example>
  324. Maps obsolete control fields to their current versions.
  325. </subsubsection>
  326. </subsection>
  327. <subsection>Parsing functions
  328. <subsubsection><code/parseerr/
  329. <findex/parseerr()/
  330. <p>
  331. <example>
  332. void parseerr
  333. (FILE *file, const char *filename, int lno,
  334. FILE *warnto, int *warncount, const struct pkginfo *pigp,
  335. int warnonly, const char *fmt, ...);
  336. </example>
  337. Report an error parsing a control data stream. Checks <var/file/ for
  338. error status on <var/file/, printing an error message to stderr and
  339. exiting with error status if an error is present on the stream.
  340. Formats the variable arguments according to the <code/printf/-style
  341. string in <var/fmt/, preceding the result with <var/filename/,
  342. <var/lno/, and <var/pigp/ (if not NULL). If <var/warnonly/ is 0,
  343. writes the result to stderr and exits with error status. Otherwise,
  344. increments <var/warncount/ and returns normally.
  345. </subsubsection>
  346. <subsubsection><code/illegal_packagename/
  347. <findex/illegal_packagename()/
  348. <p>
  349. <example>
  350. const char *illegal_packagename
  351. (const char *p, const char **ep)
  352. </example>
  353. Checks the package name at <var/p/ for proper syntax. Returns NULL in
  354. case of success, setting <var/*ep/ to point after the last character
  355. in the package name, including any trailing whitespace (as defined by
  356. isspace()). In case of error, returns the error message as a pointer
  357. to a static buffer.
  358. </subsubsection>
  359. <subsubsection><code/informativeversion/
  360. <findex/informativeversion()/
  361. <p>
  362. <example>
  363. int informativeversion(const struct versionrevision *version)
  364. </example>
  365. <p>
  366. Returns true if and only if the <code/versionrevision/ is non-empty;
  367. otherwise returns false.
  368. </subsubsection>
  369. <subsubsection><code/varbufversion/
  370. <findex/varbufversion()/
  371. <p>
  372. <example>
  373. void varbufversion
  374. (struct varbuf *vb,
  375. const struct versionrevision *version,
  376. enum versiondisplayepochwhen vdew);
  377. </example>
  378. Writes a human-readable representation of <var/version/ to <var/vb/.
  379. Possible values of <var/vdew/:
  380. <table>
  381. <item><tt/vdew_never/</item>
  382. never include epoch
  383. <item><tt/vdew_nonambig/</item>
  384. include epoch string if non-zero
  385. <item><tt/vdew_always/</item>
  386. always include epoch string
  387. </table>
  388. </subsubsection>
  389. <subsubsection><code/versiondescribe/
  390. <findex/versiondescribe()/
  391. <p>
  392. <example>
  393. const char *versiondescribe
  394. (const struct versionrevision *version,
  395. enum versiondisplayepochwhen vdew);
  396. </example>
  397. <p>
  398. Return a human-readable representation of <var/version/ as a pointer
  399. to a static buffer. If the version structure is empty, return
  400. <code/"&lt;none&gt;"/. Static buffers are allocated from a set of 10
  401. in round-robin fashion (they will be re-used after 10 successive calls
  402. to <code/versiondescribe/).
  403. </subsubsection>
  404. <subsubsection><code/parseversion/
  405. <findex/parseversion()/
  406. <p>
  407. <example>
  408. const char *parseversion
  409. (struct versionrevision *rversion, const char *string);
  410. </example>
  411. <p>
  412. Parse the contents of <var/string/ into <var/rversion/. If
  413. successful, returns NULL, otherwise returns a pointer to a static
  414. error string.
  415. </subsubsection>
  416. <subsubsection><code/parsemustfield/
  417. <findex/parsemustfield()/
  418. <p>
  419. <example>
  420. void parsemustfield
  421. (FILE *file, const char *filename, int lno,
  422. FILE *warnto, int *warncount,
  423. const struct pkginfo *pigp, int warnonly,
  424. char **value, const char *what);
  425. </example>
  426. </subsubsection>
  427. <subsubsection><code/skip_slash_dotslash/
  428. <findex/skip_slash_dotslash()/
  429. <p>
  430. <example>
  431. const char *skip_slash_dotslash (const char *p);
  432. </example>
  433. </subsubsection>
  434. <subsubsection><code/convert_string/
  435. <findex/convert_string()/
  436. <p>
  437. <example>
  438. static int convert_string
  439. (const char *filename, int lno, const char *what, int otherwise,
  440. FILE *warnto, int *warncount, const struct pkginfo *pigp,
  441. const char *startp, const struct namevalue *nvip,
  442. const char **endpp)
  443. </example>
  444. </subsubsection>
  445. </subsection>
  446. </section>
  447. <contents>
  448. <printindex name="fn">
  449. </texinfo>