]> git.donarmstrong.com Git - debian/debian-policy.git/blob - packaging.sgml
Shared library handling changes due to forthcoming dpkg changes
[debian/debian-policy.git] / packaging.sgml
1 <!doctype debiandoc system[
2 <!-- include version information so we don't have to hard code it
3      within the document -->
4 <!entity % versiondata SYSTEM "version.ent"> %versiondata;
5 ]>
6
7 <!--
8  Debian GNU/Linux Packaging Manual.
9  Copyright (C)1996 Ian Jackson; released under the terms of the GNU
10  General Public License, version 2 or (at your option) any later.
11  Revised: David A. Morris (bweaver@debian.org)
12  Maintainer since 1998, Christian Schwarz <schwarz@debian.org>
13  -->
14
15 <debiandoc>
16   <book>
17
18     <titlepag><title>Debian Packaging Manual</title>
19       <author>
20         <name>Ian Jackson </name>
21         <email>ijackson@gnu.ai.mit.edu</email>
22       </author>
23       <author>
24         <name>Revised: David A. Morris</name>
25         <email>bweaver@debian.org</email>
26       </author>
27       <author>
28         <name>Maintainer: Christian Schwarz </name>
29         <email>schwarz@debian.org</email>
30       </author>
31       <author>
32         <name>Maintainer: Manoj Srivastava </name>
33         <email>srivasta@debian.org</email>
34       </author>
35       <author>
36         <name>Maintainer: Julian Gilbey </name>
37         <email>J.D.Gilbey@qmw.ac.uk</email>
38       </author>
39       <author>
40         <name>Maintainer: The Debian Policy group </name>
41         <email>debian-policy@lists.debian.org</email>
42       </author>
43       <version>version &version;, &date;</version>
44         
45       <abstract>
46         This manual describes the technical aspects of creating Debian
47         binary and source packages.  It does not deal with the Debian
48         Project policy requirements, and it assumes familiarity with
49         <prgn>dpkg</prgn>'s functions from the system administrator's
50         perspective.  This package itself is maintained by a group of
51         maintainers that have no editorial powers. At the moment, the
52         list of maintainers is:
53         <enumlist>
54           <item>
55             <p>Michael Alan Dorman <email>mdorman@debian.org</email></p>
56           </item>
57           <item>
58             <p>Richard Braakman <email>dark@xs4all.nl</email></p>
59           </item>
60           <item>
61             <p>Philip Hands <email>phil@hands.com</email></p>
62           </item>
63           <item>
64             <p>Julian Gilbey <email>J.D.Gilbey@qmw.ac.uk</email></p>
65           </item>
66           <item>
67             <p>Manoj Srivastava <email>srivasta@debian.org</email></p>
68           </item>
69         </enumlist>
70       </abstract>
71
72
73       <copyright>
74         <copyrightsummary>Copyright &copy;1996 Ian Jackson.</copyrightsummary>
75         <p>
76           This manual is free software; you may redistribute it and/or
77           modify it under the terms of the GNU General Public License
78           as published by the Free Software Foundation; either version
79           2, or (at your option) any later version.
80         </p>
81
82         <p>
83           This is distributed in the hope that it will be useful, but
84           <em>without any warranty</em>; without even the implied
85           warranty of merchantability or fitness for a particular
86           purpose.  See the GNU General Public License for more
87           details.
88           </p>
89
90         <p>
91           A copy of the GNU General Public License is available as
92           <tt>/usr/doc/copyright/GPL</tt> in the Debian GNU/Linux
93           distribution or on the World Wide Web at
94           <tt>http://www.gnu.org/copyleft/gpl.html</tt>. You can also
95           obtain it by writing to the Free Software Foundation, Inc.,
96           59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
97         </p>
98       </copyright>
99
100     <toc detail="sect">
101
102     <!-- Describes the technical interface between a package and dpkg.
103
104     How to safely put shared libraries in a package.  Details of
105     dpkg's handling of individual files.  Sections on when to use
106     which feature (eg Replaces vs. Replaces/Conflicts
107     vs. update-alternatives vs. diversions) Cross-references to the
108     policy document (see below) where appropriate.  Description of the
109     interface between dselect and its access methods.  Hints on where
110     to start with a new package (ie, the hello package).  What to do
111     about file aliasing.
112     
113     file aliasing
114     
115     Manpages are required for: update-rc.d, diversions,
116     update-alternatives, install-info in a package.
117
118     -->
119
120     <chapt id="scope">
121       <heading>Introduction and scope of this manual</heading>
122
123       <p>
124         <prgn>dpkg</prgn> is a suite of programs for creating binary
125         package files and installing and removing them on Unix
126         systems.<footnote>
127           <p>
128             <prgn>dpkg</prgn> is targetted primarily at Debian
129             GNU/Linux, but may work on or be ported to other
130             systems.
131           </p>
132         </footnote>
133       </p>
134
135       <p>
136         The binary packages are designed for the management of
137         installed executable programs (usually compiled binaries) and
138         their associated data, though source code examples and
139         documentation are provided as part of some packages.</p>
140
141       <p>
142         This manual describes the technical aspects of creating Debian
143         binary packages (<tt>.deb</tt> files).  It documents the
144         behaviour of the package management programs
145         <prgn>dpkg</prgn>, <prgn>dselect</prgn> et al. and the way
146         they interact with packages.</p>
147
148       <p>
149         It also documents the interaction between
150         <prgn>dselect</prgn>'s core and the access method scripts it
151         uses to actually install the selected packages, and describes
152         how to create a new access method.</p>
153         
154       <p>
155         This manual does not go into detail about the options and
156         usage of the package building and installation tools.  It
157         should therefore be read in conjuction with those programs'
158         manpages.
159       </p>      
160
161       <p>
162         The utility programs which are provided with <prgn>dpkg</prgn>
163         for managing various system configuration and similar issues,
164         such as <prgn>update-rc.d</prgn> and
165         <prgn>install-info</prgn>, are not described in detail here -
166         please see their manpages.
167       </p>
168         
169       <p>
170         It does <em>not</em> describe the policy requirements imposed
171         on Debian packages, such as the permissions on files and
172         directories, documentation requirements, upload procedure, and
173         so on.  You should see the Debian packaging policy manual for
174         these details.  (Many of them will probably turn out to be
175         helpful even if you don't plan to upload your package and make
176         it available as part of the distribution.)
177       </p>
178         
179       <p>
180         It is assumed that the reader is reasonably familiar with the
181         <prgn>dpkg</prgn> System Administrators' manual.
182         Unfortunately this manual does not yet exist.
183       </p>
184         
185       <p>
186         The Debian version of the FSF's GNU hello program is provided
187         as an example for people wishing to create Debian
188         packages. The Debian <prgn>debmake</prgn> package is
189         recommended as a very helpful tool in creating and maintaining
190         Debian packages. However, while the tools and examples are
191         helpful, they do not replace the need to read and follow the
192         Policy and Programmer's Manual.</p>
193     </chapt>
194       
195     <chapt id="binarypkg"><heading>Binary packages
196       </heading>
197         
198       <p>
199         The binary package has two main sections.  The first part
200         consists of various control information files and scripts used
201         by <prgn>dpkg</prgn> when installing and removing.  See <ref
202         id="controlarea">.
203       </p>
204         
205       <p>
206         The second part is an archive containing the files and
207         directories to be installed.
208       </p>
209         
210       <p>
211         In the future binary packages may also contain other
212         components, such as checksums and digital signatures. The
213         format for the archive is described in full in the
214         <tt>deb(5)</tt> manpage.
215       </p>
216         
217         
218       <sect id="bincreating"><heading>Creating package files -
219       <prgn>dpkg-deb</prgn>
220         </heading>
221           
222         <p>
223           All manipulation of binary package files is done by
224           <prgn>dpkg-deb</prgn>; it's the only program that has
225           knowledge of the format.  (<prgn>dpkg-deb</prgn> may be
226           invoked by calling <prgn>dpkg</prgn>, as <prgn>dpkg</prgn>
227           will spot that the options requested are appropriate to
228           <prgn>dpkg-deb</prgn> and invoke that instead with the same
229           arguments.)
230         </p>
231           
232         <p>
233           In order to create a binary package you must make a
234           directory tree which contains all the files and directories
235           you want to have in the filesystem data part of the package.
236           In Debian-format source packages this directory is usually
237           <tt>debian/tmp</tt>, relative to the top of the package's
238           source tree.
239         </p>
240           
241         <p>
242           They should have the locations (relative to the root of the
243           directory tree you're constructing) ownerships and
244           permissions which you want them to have on the system when
245           they are installed.
246         </p>
247           
248         <p>
249           With current versions of <prgn>dpkg</prgn> the uid/username
250           and gid/groupname mappings for the users and groups being
251           used should be the same on the system where the package is
252           built and the one where it is installed.
253         </p>
254           
255         <p>
256           You need to add one special directory to the root of the
257           miniature filesystem tree you're creating:
258           <prgn>DEBIAN</prgn>.  It should contain the control
259           information files, notably the binary package control file
260           (see <ref id="controlfile">).
261         </p>
262           
263         <p>
264           The <prgn>DEBIAN</prgn> directory will not appear in the
265           filesystem archive of the package, and so won't be installed
266           by <prgn>dpkg</prgn> when the package is installed.
267         </p>
268           
269         <p>
270           When you've prepared the package, you should invoke:
271           <example>
272   dpkg --build <var>directory</var>
273           </example>
274         </p>
275           
276         <p>
277           This will build the package in
278           <tt><var>directory</var>.deb</tt>.  (<prgn>dpkg</prgn> knows
279           that <tt>--build</tt> is a <prgn>dpkg-deb</prgn> option, so
280           it invokes <prgn>dpkg-deb</prgn> with the same arguments to
281           build the package.)
282         </p>
283           
284         <p>
285           See the manpage <manref name="dpkg-deb" section="8"> for details of how
286           to examine the contents of this newly-created file.  You may find the
287           output of following commands enlightening:
288           <example>
289   dpkg-deb --info <var>filename</var>.deb
290   dpkg-deb --contents <var>filename</var>.deb
291   dpkg --contents <var>filename</var>.deb
292           </example>
293           To view the copyright file for a package you could use this command:
294           <example>
295   dpkg --fsys-tarfile <var>filename</var>.deb | tar xof usr/doc/<var>\*</var>copyright | less
296           </example>
297         </p>
298       </sect>
299
300       <sect id="controlarea">
301         <heading>
302           Package control information files
303         </heading>
304           
305         <p>
306           The control information portion of a binary package is a
307           collection of files with names known to <prgn>dpkg</prgn>.
308           It will treat the contents of these files specially - some
309           of them contain information used by <prgn>dpkg</prgn> when
310           installing or removing the package; others are scripts which
311           the package maintainer wants <prgn>dpkg</prgn> to run.
312         </p>
313           
314         <p>
315           It is possible to put other files in the package control
316           area, but this is not generally a good idea (though they
317           will largely be ignored).
318         </p>
319           
320         <p>
321           Here is a brief list of the control info files supported by
322           <prgn>dpkg</prgn> and a summary of what they're used for.
323         </p>
324           
325         <p>
326           <taglist>
327             <tag><tt>control</tt>
328             <item>
329               
330               <p>
331                 This is the key description file used by
332                 <prgn>dpkg</prgn>.  It specifies the package's name
333                 and version, gives its description for the user,
334                 states its relationships with other packages, and so
335                 forth.  See <ref id="controlfile">.
336               </p>
337                 
338               <p>
339                 It is usually generated automatically from information
340                 in the source package by the
341                 <prgn>dpkg-gencontrol</prgn> program, and with
342                 assistance from <prgn>dpkg-shlibdeps</prgn>.  See <ref
343                 id="sourcetools">.</p>
344             </item>
345               
346             <tag><tt>postinst</tt>, <tt>preinst</tt>, <tt>postrm</tt>,
347             <tt>prerm</tt>
348             </tag>
349             <item>
350               
351               <p>
352                 These are exectuable files (usually scripts) which
353                 <prgn>dpkg</prgn> runs during installation, upgrade
354                 and removal of packages.  They allow the package to
355                 deal with matters which are particular to that package
356                 or require more complicated processing than that
357                 provided by <prgn>dpkg</prgn>.  Details of when and
358                 how they are called are in <ref
359                 id="maintainerscripts">.
360               </p>
361                 
362               <p>
363                 It is very important to make these scripts
364                 idempotent.
365                 <footnote>
366                   <p>
367                     That means that if it runs successfully or fails
368                     and then you call it again it doesn't bomb out,
369                     but just ensures that everything is the way it
370                     ought to be.
371                   </p>
372                 </footnote> This is so that if an error occurs, the
373                 user interrupts <prgn>dpkg</prgn> or some other
374                 unforeseen circumstance happens you don't leave the
375                 user with a badly-broken package.
376               </p>
377                 
378               <p>
379                 The maintainer scripts are guaranteed to run with a
380                 controlling terminal and can interact with the user.
381                 If they need to prompt for passwords, do full-screen
382                 interaction or something similar you should do these
383                 things to and from <tt>/dev/tty</tt>, since
384                 <prgn>dpkg</prgn> will at some point redirect scripts'
385                 standard input and output so that it can log the
386                 installation process.  Likewise, because these scripts
387                 may be executed with standard output redirected into a
388                 pipe for logging purposes, Perl scripts should set
389                 unbuffered output by setting <tt>$|=1</tt> so that the
390                 output is printed immediately rather than being
391                 buffered.
392               </p>
393                 
394               <p>
395                 Each script should return a zero exit status for
396                 success, or a nonzero one for failure.</p>
397             </item>
398               
399             <tag><tt>conffiles</tt>
400             </tag>
401             <item>
402               
403               <p>
404                 This file contains a list of configuration files which
405                 are to be handled automatically by <prgn>dpkg</prgn>
406                 (see <ref id="conffiles">).  Note that not necessarily
407                 every configuration file should be listed here.</p>
408             </item>
409               
410             <tag><tt>shlibs</tt>
411             </tag>
412             <item>
413               
414               <p>
415                 This file contains a list of the shared libraries
416                 supplied by the package, with dependency details for
417                 each.  This is used by <prgn>dpkg-shlibdeps</prgn>
418                 when it determines what dependencies are required in a
419                 package control file. The <tt>shlibs</tt> file format
420                 is described on <ref id="shlibs">.
421               </p>
422             </item>
423           </taglist>
424         </p>
425         
426       <sect id="controlfile">
427         <heading>
428           The main control information file: <tt>control</tt>
429         </heading>
430         <p>
431           The most important control information file used by
432           <prgn>dpkg</prgn> when it installs a package is
433           <tt>control</tt>.  It contains all the package's `vital
434           statistics'.
435         </p>
436
437         <p>       
438           The binary package control files of packages built from
439           Debian sources are made by a special tool,
440           <prgn>dpkg-gencontrol</prgn>, which reads
441           <tt>debian/control</tt> and <tt>debian/changelog</tt> to
442           find the information it needs.  See <ref id="sourcepkg"> for
443           more details.
444         </p>
445
446         <p>       
447           The fields in binary package control files are:
448           <list compact="compact">
449             <item>
450               <p><qref id="f-Package"><tt>Package</tt></qref> (mandatory)</p>
451             </item>
452             <item>
453               <p><qref id="versions"><tt>Version</tt></qref> (mandatory)</p>
454             </item>
455             <item><p><qref id="f-Architecture"><tt>Architecture</tt></qref>
456                 (mandatory)
457                 <footnote>
458                   <p>
459                     This field should appear in all packages, though
460                     <prgn>dpkg</prgn> doesn't require it yet so that
461                     old packages can still be installed.
462                   </p>
463                 </footnote>
464               </p>
465             </item>
466             <item>
467               <p><qref id="relationships"><tt>Depends</tt>,
468                   <tt>Provides</tt> et al.</qref></p>
469             </item>
470             <item>
471               <p><qref id="f-Essential"><tt>Essential</tt></qref></p>
472             </item>
473             <item>
474               <p><qref id="f-Maintainer"><tt>Maintainer</tt></qref></p>
475             </item>
476             <item>
477               <p><qref id="f-classification"><tt>Section</tt>,
478                   <tt>Priority</tt></qref></p>
479             </item>
480             <item>
481               <p><qref id="f-Source"><tt>Source</tt></qref></p>
482             </item>
483             <item>
484               <p><qref id="descriptions"><tt>Description</tt></qref></p>
485             </item>
486             <item>
487               <p>
488                 <qref id="f-Installed-Size"><tt>Installed-Size</tt></qref>
489               </p>
490             </item> 
491           </list>
492             
493         <p>
494           A description of the syntax of control files and the purpose
495           of these fields is available in <ref id="controlfields">.
496         </p>
497       </sect>
498       <sect>
499         <heading>Time Stamps</heading>
500         <p>
501           Maintainers are encouraged to preserve the modification
502           times of the upstream source files in a package, as far as
503           is reasonably possible. 
504           <footnote>
505             <p>
506               The rationale is that there is some information conveyed
507               by knowing the age of the file, for example, you could
508               recognize that some documentation is very old by looking
509               at the modification time, so it would be nice if the
510               modification time of the upstream source would be
511               preserved.
512             </p>
513           </footnote>
514         </p>
515       </sect>
516     </chapt>
517
518     <chapt id="sourcepkg">
519       <heading>Source packages</heading>
520
521       <p>       
522         The Debian binary packages in the distribution are generated
523         from Debian sources, which are in a special format to assist
524         the easy and automatic building of binaries.
525       </p>
526
527       <p>       
528         There was a previous version of the Debian source format,
529         which is now being phased out.  Instructions for converting an
530         old-style package are given in the Debian policy manual.
531       </p>
532         
533       <sect id="sourcetools">
534         <heading>Tools for processing source packages</heading> 
535
536         <p>       
537           Various tools are provided for manipulating source packages;
538           they pack and unpack sources and help build of binary
539           packages and help manage the distribution of new versions.
540         </p>
541
542         <p>       
543           They are introduced and typical uses described here; see
544           <manref name="dpkg-source" section="1"> for full
545           documentation about their arguments and operation.
546         </p>
547
548         <p>       
549           For examples of how to construct a Debian source package,
550           and how to use those utilities that are used by Debian
551           source packages, please see the <prgn>hello</prgn> example
552           package.
553         </p>
554           
555         <sect1>
556           <heading>
557             <prgn>dpkg-source</prgn> - packs and unpacks Debian source
558             packages
559           </heading>
560
561           <p>       
562             This program is frequently used by hand, and is also
563             called from package-independent automated building scripts
564             such as <prgn>dpkg-buildpackage</prgn>.
565           </p>
566
567           <p>       
568             To unpack a package it is typically invoked with
569             <example>
570   dpkg-source -x <var>.../path/to/filename</var>.dsc
571             </example> 
572           </p>
573
574            <p>  
575             with the <tt><var>filename</var>.tar.gz</tt> and
576             <tt><var>filename</var>.diff.gz</tt> (if applicable) in
577             the same directory.  It unpacks into
578             <tt><var>package</var>-<var>version</var></tt>, and if
579             applicable
580             <tt><var>package</var>-<var>version</var>.orig</tt>, in
581             the current directory.
582           </p>
583
584           <p>       
585             To create a packed source archive it is typically invoked:
586             <example>
587   dpkg-source -b <var>package</var>-<var>version</var>
588           </example>
589           </p>
590
591           <p>
592             This will create the <tt>.dsc</tt>, <tt>.tar.gz</tt> and
593             <tt>.diff.gz</tt> (if appropriate) in the current
594             directory.  <prgn>dpkg-source</prgn> does not clean the
595             source tree first - this must be done separately if it is
596             required.
597           </p>
598
599           <p>       
600             See also <ref id="sourcearchives">.</p>
601         </sect1>
602           
603           
604         <sect1>
605           <heading>
606             <prgn>dpkg-buildpackage</prgn> - overall package-building
607             control script
608           </heading>
609
610           <p>       
611             <prgn>dpkg-buildpackage</prgn> is a script which invokes
612             <prgn>dpkg-source</prgn>, the <tt>debian/rules</tt>
613             targets <prgn>clean</prgn>, <prgn>build</prgn> and
614             <prgn>binary</prgn>, <prgn>dpkg-genchanges</prgn> and
615             <prgn>pgp</prgn> to build a signed source and binary
616             package upload.
617           </p>
618
619           <p>       
620             It is usually invoked by hand from the top level of the
621             built or unbuilt source directory.  It may be invoked with
622             no arguments; useful arguments include:
623             <taglist compact="compact">
624               <tag><tt>-uc</tt>, <tt>-us</tt></tag>
625               <item>
626                 <p>
627                   Do not PGP-sign the <tt>.changes</tt> file or the
628                   source package <tt>.dsc</tt> file, respectively.</p>
629               </item>
630               <tag><tt>-p<var>pgp-command</var></tt></tag>
631               <item>
632                 <p>
633                   Invoke <var>pgp-command</var> instead of finding
634                   <tt>pgp</tt> on the <prgn>PATH</prgn>.
635                   <var>pgp-command</var> must behave just like
636                   <prgn>pgp</prgn>.</p>
637               </item>
638               <tag><tt>-r<var>root-command</var></tt></tag>
639               <item>
640                 <p>
641                   When root privilege is required, invoke the command
642                   <var>root-command</var>.  <var>root-command</var>
643                   should invoke its first argument as a command, from
644                   the <prgn>PATH</prgn> if necessary, and pass its
645                   second and subsequent arguments to the command it
646                   calls.  If no <var>root-command</var> is supplied
647                   then <var>dpkg-buildpackage</var> will take no
648                   special action to gain root privilege, so that for
649                   most packages it will have to be invoked as root to
650                   start with.</p>
651               </item>
652               <tag><tt>-b</tt>, <tt>-B</tt></tag>
653               <item>
654                 <p>
655                   Two types of binary-only build and upload - see
656                   <manref name="dpkg-source" section="1">.
657                 </p>
658               </item>
659             </taglist>
660           </p>
661         </sect1>
662           
663         <sect1>
664           <heading>
665             <prgn>dpkg-gencontrol</prgn> - generates binary package
666             control files
667           </heading>
668
669           <p>       
670             This program is usually called from <tt>debian/rules</tt>
671             (see <ref id="sourcetree">) in the top level of the source
672             tree.
673           </p>
674
675           <p>       
676             This is usually done just before the files and directories in the
677             temporary directory tree where the package is being built have their
678             permissions and ownerships set and the package is constructed using
679             <prgn>dpkg-deb/</prgn>
680               <footnote>
681               <p>
682                 This is so that the control file which is produced has
683                 the right permissions
684               </p>
685             </footnote>.
686           </p>
687
688           <p>       
689             <prgn>dpkg-gencontrol</prgn> must be called after all the
690             files which are to go into the package have been placed in
691             the temporary build directory, so that its calculation of
692             the installed size of a package is correct.
693           </p>
694
695           <p>       
696             It is also necessary for <prgn>dpkg-gencontrol</prgn> to
697             be run after <prgn>dpkg-shlibdeps</prgn> so that the
698             variable substitutions created by
699             <prgn>dpkg-shlibdeps</prgn> in <tt>debian/substvars</tt>
700             are available.
701           </p>
702
703           <p>       
704             For a package which generates only one binary package, and
705             which builds it in <tt>debian/tmp</tt> relative to the top
706             of the source package, it is usually sufficient to call
707             <prgn>dpkg-gencontrol</prgn>.
708           </p>
709
710           <p>       
711             Sources which build several binaries will typically need
712             something like:
713             <example>
714   dpkg-gencontrol -Pdebian/tmp-<var>pkg</var> -p<var>package</var>
715             </example> The <tt>-P</tt> tells
716             <prgn>dpkg-gencontrol</prgn> that the package is being
717             built in a non-default directory, and the <tt>-p</tt>
718             tells it which package's control file should be generated.
719           </p>
720
721           <p>       
722             <prgn>dpkg-gencontrol</prgn> also adds information to the
723             list of files in <tt>debian/files</tt>, for the benefit of
724             (for example) a future invocation of
725             <prgn>dpkg-genchanges</prgn>.</p>
726         </sect1>
727           
728         <sect1>
729           <heading>
730             <prgn>dpkg-shlibdeps</prgn> - calculates shared library
731             dependencies
732           </heading>
733
734           <p>       
735             This program is usually called from <tt>debian/rules</tt>
736             just before <prgn>dpkg-gencontrol</prgn> (see <ref
737             id="sourcetree">), in the top level of the source tree.
738           </p>
739
740           <p>       
741             Its arguments are executables and libraries
742             <footnote>
743               <p>
744                 They may be specified either in the locations in the
745                 source tree where they are created or in the locations
746                 in the temporary build tree where they are installed
747                 prior to binary package creation.
748               </p>
749             </footnote> for which shared library dependencies should
750             be included in the binary package's control file.
751           </p>
752
753           <p>       
754             If some of the found shared libraries should only
755             warrant a <tt>Recommends</tt> or <tt>Suggests</tt>, or if
756             some warrant a <tt>Pre-Depends</tt>, this can be achieved
757             by using the <tt>-d<var>dependency-field</var></tt> option
758             before those executable(s).  (Each <tt>-d</tt> option
759             takes effect until the next <tt>-d</tt>.)
760           </p>
761
762           <p>       
763             <prgn>dpkg-shlibdeps</prgn> does not directly cause the
764             output control file to be modified.  Instead by default it
765             adds to the <tt>debian/substvars</tt> file variable
766             settings like <tt>shlibs:Depends</tt>.  These variable
767             settings must be referenced in dependency fields in the
768             appropriate per-binary-package sections of the source
769             control file.
770           </p>
771
772           <p>       
773             For example, the <prgn>procps</prgn> package generates two
774             kinds of binaries, simple C binaries like <prgn>ps</prgn>
775             which require a predependency and full-screen ncurses
776             binaries like <prgn>top</prgn> which require only a
777             recommendation.  It can say in its <tt>debian/rules</tt>:
778             <example>
779   dpkg-shlibdeps -dPre-Depends ps -dRecommends top
780             </example>
781             and then in its main control file <tt>debian/control</tt>:
782             <example>
783   <var>...</var>
784   Package: procps
785   Pre-Depends: ${shlibs:Pre-Depends}
786   Recommends: ${shlibs:Recommends}
787   <var>...</var>
788             </example>
789           </p>
790
791           <p>       
792             Sources which produce several binary packages with
793             different shared library dependency requirements can use
794             the <tt>-p<var>varnameprefix</var></tt> option to override
795             the default <tt>shlib:</tt> prefix (one invocation of
796             <prgn>dpkg-shlibdeps</prgn> per setting of this option).
797             They can thus produce several sets of dependency
798             variables, each of the form
799             <tt><var>varnameprefix</var>:<var>dependencyfield</var></tt>,
800             which can be referred to in the appropriate parts of the
801             binary package control files.
802           </p>
803         </sect1>
804           
805           
806         <sect1>
807           <heading>
808             <prgn>dpkg-distaddfile</prgn> - adds a file to
809             <tt>debian/files</tt>
810           </heading>
811
812           <p>       
813             Some packages' uploads need to include files other than
814             the source and binary package files.
815           </p>
816
817           <p>       
818             <prgn>dpkg-distaddfile</prgn> adds a file to the
819             <tt>debian/files</tt> file so that it will be included in
820             the <tt>.changes</tt> file when
821             <prgn>dpkg-genchanges</prgn> is run.
822           </p>
823
824           <p>       
825             It is usually invoked from the <prgn>binary</prgn> target of
826             <tt>debian/rules</tt>:
827             <example>
828   dpkg-distaddfile <var>filename</var> <var>section</var> <var>priority</var>
829             </example>
830             The <var>filename</var> is relative to the directory where
831             <prgn>dpkg-genchanges</prgn> will expect to find it - this
832             is usually the directory above the top level of the source
833             tree.  The <tt>debian/rules</tt> target should put the
834             file there just before or just after calling
835             <prgn>dpkg-distaddfile</prgn>.
836           </p>
837
838           <p>       
839             The <var>section</var> and <var>priority</var> are passed
840             unchanged into the resulting <tt>.changes</tt> file.  See
841             <ref id="f-classification">.
842           </p>
843         </sect1>
844           
845           
846         <sect1><heading><prgn>dpkg-genchanges</prgn> - generates a <tt>.changes</tt> upload
847             control file
848           </heading>
849
850           <p>       
851             This program is usually called by package-independent
852             automatic building scripts such as
853             <prgn>dpkg-buildpackage</prgn>, but it may also be called
854             by hand.
855           </p>
856
857           <p>       
858             It is usually called in the top level of a built source
859             tree, and when invoked with no arguments will print out a
860             straightforward <tt>.changes</tt> file based on the
861             information in the source package's changelog and control
862             file and the binary and source packages which should have
863             been built.
864           </p>
865         </sect1>
866           
867           
868         <sect1><heading><prgn>dpkg-parsechangelog</prgn> - produces parsed representation of
869             a changelog
870           </heading>
871
872           <p>       
873             This program is used internally by
874             <prgn>dpkg-source</prgn> et al.  It may also occasionally
875             be useful in <tt>debian/rules</tt> and elsewhere.  It
876             parses a changelog, <tt>debian/changelog</tt> by default,
877             and prints a control-file format representation of the
878             information in it to standard output.
879           </p>
880         </sect1>
881  
882         <sect1 id="dpkgarch"><heading><prgn>dpkg-architecture</prgn> -
883             information about the build and host system 
884           </heading>
885  
886           <p>
887             This program can be used manually, but is also invoked by
888             <tt>dpkg-buildpackage</tt> or <tt>debian/rules</tt> to set
889             to set environment or make variables which specify the build and
890             host architecture for the package building process.
891           </p>
892         </sect1>
893       </sect>
894         
895       <sect id="sourcetree"><heading>The Debianised source tree
896         </heading>
897
898         <p>       
899           The source archive scheme described later is intended to
900           allow a Debianised source tree with some associated control
901           information to be reproduced and transported easily.  The
902           Debianised source tree is a version of the original program
903           with certain files added for the benefit of the
904           Debianisation process, and with any other changes required
905           made to the rest of the source code and installation
906           scripts.
907         </p>
908
909         <p>       
910           The extra files created for Debian are in the subdirectory
911           <tt>debian</tt> of the top level of the Debianised source
912           tree.  They are described below.
913         </p>
914           
915         <sect1 id="debianrules"><heading><tt>debian/rules</tt> - the main building
916         script
917           </heading>
918
919           <p>       
920             This file is an executable makefile, and contains the
921             package-specific recipies for compiling the package and
922             building binary package(s) out of the source.
923           </p>
924
925           <p>       
926             It must start with the line <tt>#!/usr/bin/make -f</tt>,
927             so that it can be invoked by saying its name rather than
928             invoking <prgn>make</prgn> explicitly.
929           </p>
930
931           <p>
932             Since an interactive <tt>debian/rules</tt> script makes it
933             impossible to autocompile that package and also makes it
934             hard for other people to reproduce the same binary
935             package, all <strong>required targets</strong> have to be
936             non-interactive. At a minimul, required targets are the
937             ones called by <prgn>dpkg-buildpackage</prgn>, namely,
938             <em>clean</em>, <em>binary</em>, <em>binary-arch</em>, and
939             <em>build</em>. It also follows that any target that these
940             targets depend on must also be non-interactive.
941           </p>
942
943           <p>       
944             The targets which are required to be present are:       
945             <taglist>
946               <tag><tt>build</tt></tag>
947               <item>
948                 <p>
949                   This should perform all non-interactive
950                   configuration and compilation of the package.  If a
951                   package has an interactive pre-build configuration
952                   routine, the Debianised source package should be
953                   built after this has taken place, so that it can be
954                   built without rerunning the configuration.
955                 </p>
956
957                 <p>               
958                   For some packages, notably ones where the same
959                   source tree is compiled in different ways to produce
960                   two binary packages, the <prgn>build</prgn> target
961                   does not make much sense.  For these packages it is
962                   good enough to provide two (or more) targets
963                   (<tt>build-a</tt> and <tt>build-b</tt> or whatever)
964                   for each of the ways of building the package, and a
965                   <prgn>build</prgn> target that does nothing.  The
966                   <prgn>binary</prgn> target will have to build the
967                   package in each of the possible ways and make the
968                   binary package out of each.
969                 </p>
970
971                 <p>               
972                   The <prgn>build</prgn> target must not do anything
973                   that might require root privilege.
974                 </p>
975
976                 <p>               
977                   The <prgn>build</prgn> target may need to run
978                   <prgn>clean</prgn> first - see below.
979                 </p>
980
981                 <p>               
982                   When a package has a configuration routine that
983                   takes a long time, or when the makefiles are poorly
984                   designed, or when <prgn>build</prgn> needs to run
985                   <prgn>clean</prgn> first, it is a good idea to
986                   <tt>touch build</tt> when the build process is
987                   complete.  This will ensure that if <tt>debian/rules
988                     build</tt> is run again it will not rebuild the
989                     whole program.
990                 </p>
991               </item>
992                 
993               <tag><tt>binary</tt>, <tt>binary-arch</tt>,
994                 <tt>binary-indep</tt>
995               </tag> 
996               <item>
997                 <p>
998                   The <prgn>binary</prgn> target should be all that is
999                   necessary for the user to build the binary
1000                   package. All these targets are required to be
1001                   non-interactive.  It is split into two parts:
1002                   <prgn>binary-arch</prgn> builds the packages' output
1003                   files which are specific to a particular
1004                   architecture, and <prgn>binary-indep</prgn> builds
1005                   those which are not.
1006                 </p>
1007
1008                 <p>               
1009                   <prgn>binary</prgn> should usually be a target with
1010                   no commands which simply depends on
1011                   <prgn>binary-arch</prgn> and
1012                   <prgn>binary-indep</prgn>.
1013                 </p>
1014
1015                 <p>               
1016                   Both <prgn>binary-*</prgn> targets should depend on
1017                   the <prgn>build</prgn> target, above, so that the
1018                   package is built if it has not been already.  It
1019                   should then create the relevant binary package(s),
1020                   using <prgn>dpkg-gencontrol</prgn> to make their
1021                   control files and <prgn>dpkg-deb</prgn> to build
1022                   them and place them in the parent of the top level
1023                   directory.
1024                 </p>
1025
1026                 <p>               
1027                   If one of the <prgn>binary-*</prgn> targets has
1028                   nothing to do (this will be always be the case if
1029                   the source generates only a single binary package,
1030                   whether architecture-dependent or not) it
1031                   <em>must</em> still exist, but should always
1032                   succeed.
1033                 </p>
1034
1035                 <p>               
1036                   <ref id="binarypkg"> describes how to construct
1037                   binary packages.
1038                 </p>
1039
1040                 <p>               
1041                   The <prgn>binary</prgn> targets must be invoked as
1042                   root.
1043                 </p>
1044               </item>
1045                 
1046               <tag><tt>clean</tt></tag>
1047               <item>
1048                 
1049                 <p>
1050                   This should undo any effects that the
1051                   <prgn>build</prgn> and <prgn>binary</prgn> targets
1052                   may have had, except that it should leave alone any
1053                   output files created in the parent directory by a
1054                   run of <prgn>binary</prgn>. This target is required
1055                   to be non-interactive.
1056                 </p>
1057
1058                 <p>               
1059                   If a <prgn>build</prgn> file is touched at the end
1060                   of the <prgn>build</prgn> target, as suggested
1061                   above, it must be removed as the first thing that
1062                   <prgn>clean</prgn> does, so that running
1063                   <prgn>build</prgn> again after an interrupted
1064                   <prgn>clean</prgn> doesn't think that everything is
1065                   already done.
1066                 </p>
1067
1068                 <p>               
1069                   The <prgn>clean</prgn> target must be invoked as
1070                   root if <prgn>binary</prgn> has been invoked since
1071                   the last <prgn>clean</prgn>, or if
1072                   <prgn>build</prgn> has been invoked as root (since
1073                   <prgn>build</prgn> may create directories, for
1074                   example).
1075                 </p>
1076               </item>
1077                 
1078               <tag><tt>get-orig-source</tt> (optional)</tag>
1079               <item>
1080                 
1081                 <p>
1082                   This target fetches the most recent version of the
1083                   original source package from a canonical archive
1084                   site (via FTP or WWW, for example), does any
1085                   necessary rearrangement to turn it into the original
1086                   source tarfile format described below, and leaves it
1087                   in the current directory.
1088                 </p>
1089
1090                 <p>               
1091                   This target may be invoked in any directory, and
1092                   should take care to clean up any temporary files it
1093                   may have left.
1094                 </p>
1095
1096                 <p>               
1097                   This target is optional, but providing it if
1098                   possible is a good idea.
1099                 </p>
1100               </item>
1101             </taglist>
1102               
1103           <p>
1104             The <prgn>build</prgn>, <prgn>binary</prgn> and
1105             <prgn>clean</prgn> targets must be invoked with a current
1106             directory of the package's top-level directory.
1107           </p>
1108             
1109
1110           <p>       
1111             Additional targets may exist in <tt>debian/rules</tt>,
1112             either as published or undocumented interfaces or for the
1113             package's internal use.
1114           </p>
1115  
1116           <p>
1117             The architecture we build on and build for is determined by make
1118             variables via dpkg-architecture (see <ref id="dpkgarch">). You can
1119             get the Debian architecture and the GNU style architecture
1120             specification string for the build machine as well as the host
1121             machine. Here is a list of supported make variables:
1122             <list compact="compact">
1123               <item>
1124                 <p><tt>DEB_*_ARCH</tt> (the Debian architecture)</p>
1125               </item>
1126               <item>
1127                 <p><tt>DEB_*_GNU_TYPE</tt> (the GNU style architecture
1128                   specification string)</p> 
1129               </item>
1130               <item>
1131                 <p><tt>DEB_*_GNU_CPU</tt> (the CPU part of DEB_*_GNU_TYPE)</p>
1132               </item>
1133               <item>
1134                 <p><tt>DEB_*_GNU_SYSTEM</tt> (the System part of
1135                   DEB_*_GNU_TYPE)</p>
1136             </list>
1137           </p>
1138  
1139           <p>
1140             where <tt>*</tt> is either <tt>BUILD</tt> for specification of
1141             the build machine or <tt>HOST</tt> for specification of the machine
1142             we build for.
1143           </p>
1144           
1145           <p>
1146             Backward compatibility can be provided in the rules file
1147             by setting the needed variables to suitable default
1148             values, please refer to the documentation of
1149             dpkg-architecture for details.
1150           </p>
1151  
1152           <p>
1153             It is important to understand that the <tt>DEB_*_ARCH</tt>
1154             string does only determine which Debian architecture we
1155             build on resp. for. It should not be used to get the CPU
1156             or System information, the GNU style variables should be
1157             used for that.
1158           </p>
1159         </sect1>
1160           
1161           
1162         <sect1><heading><tt>debian/control</tt>
1163           </heading>
1164
1165           <p>       
1166             This file contains version-independent details about the
1167             source package and about the binary packages it creates.
1168           </p>
1169
1170           <p>       
1171             It is a series of sets of control fields, each
1172             syntactically similar to a binary package control file.
1173             The sets are separated by one or more blank lines.  The
1174             first set is information about the source package in
1175             general; each subsequent set describes one binary package
1176             that the source tree builds.
1177           </p>
1178
1179           <p>       
1180             The syntax and semantics of the fields are described below
1181             in <ref id="controlfields">.
1182           </p>
1183
1184           <p>       
1185             The general (binary-package-independent) fields are:
1186             <list compact="compact">
1187               <item>
1188                 <p><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</p>
1189               </item>
1190               <item>
1191                 <p><qref id="f-Maintainer"><tt>Maintainer</tt></qref></p>
1192               </item>
1193               <item>
1194                 <p>
1195                   <qref id="f-classification"><tt>Section</tt> and
1196                     <tt>Priority</tt></qref> 
1197                   (classification, mandatory)
1198                 </p>
1199               </item>
1200                <item>
1201                  <p>
1202                    <qref id="relationships"><tt>Build-Depends</tt> et
1203                      al.</qref> (source package interrelationships)
1204                  </p>
1205                </item>
1206               <item>
1207                 <p>
1208                   <qref id="f-Standards-Version"><tt>Standards-Version</tt></qref>
1209                 </p>
1210               </item> 
1211             </list>
1212
1213           <p>       
1214             The per-binary-package fields are:
1215             <list compact="compact">
1216               <item>
1217                 <p><qref id="f-Package"><tt>Package</tt></qref> (mandatory)</p>
1218               </item>
1219               <item>
1220                 <p>
1221                   <qref id="f-Architecture"><tt>Architecture</tt></qref>
1222                   (mandatory)</p>
1223               </item>
1224               <item>
1225                 <p><qref id="descriptions"><tt>Description</tt></qref></p>
1226               </item>
1227               <item>
1228                 <p>
1229                   <qref id="f-classification"><tt>Section</tt> and
1230                     <tt>Priority</tt></qref> (classification)</p>
1231               </item>
1232               <item>
1233                 <p><qref id="f-Essential"><tt>Essential</tt></qref></p>
1234               </item>
1235               <item>
1236                 <p>
1237                   <qref id="relationships"><tt>Depends</tt> et
1238                   al.</qref> (binary package interrelationships)
1239                 </p>
1240               </item>
1241             </list>
1242
1243           <p>       
1244             These fields are used by <prgn>dpkg-gencontrol</prgn> to
1245             generate control files for binary packages (see below), by
1246             <prgn>dpkg-genchanges</prgn> to generate the
1247             <tt>.changes</tt> file to accompany the upload, and by
1248             <prgn>dpkg-source</prgn> when it creates the <tt>.dsc</tt>
1249             source control file as part of a source archive.
1250           </p>
1251
1252           <p>       
1253             The fields here may contain variable references - their
1254             values will be substituted by
1255             <prgn>dpkg-gencontrol</prgn>, <prgn>dpkg-genchanges</prgn>
1256             or <prgn>dpkg-source</prgn> when they generate output
1257             control files.  See <ref id="srcsubstvars"> for details.
1258           </p>
1259
1260           <p> <sect2><heading>User-defined fields
1261             </heading>
1262
1263             <p>       
1264               Additional user-defined fields may be added to the
1265               source package control file.  Such fields will be
1266               ignored, and not copied to (for example) binary or
1267               source package control files or upload control files.
1268             </p>
1269
1270             <p>       
1271               If you wish to add additional unsupported fields to
1272               these output files you should use the mechanism
1273               described here.
1274             </p>
1275
1276             <p>       
1277               Fields in the main source control information file with
1278               names starting <tt>X</tt>, followed by one or more of
1279               the letters <tt>BCS</tt> and a hyphen <tt>-</tt>, will
1280               be copied to the output files.  Only the part of the
1281               field name after the hyphen will be used in the output
1282               file.  Where the letter <tt>B</tt> is used the field
1283               will appear in binary package control files, where the
1284               letter <tt>S</tt> is used in source package control
1285               files and where <tt>C</tt> is used in upload control
1286               (<tt>.changes</tt>) files.
1287             </p>
1288
1289             <p>       
1290               For example, if the main source information control file
1291               contains the field
1292               <example>
1293   XBS-Comment: I stand between the candle and the star.
1294               </example>
1295               then the binary and source package control files will contain the
1296               field
1297               <example>
1298   Comment: I stand between the candle and the star.
1299               </example>
1300             </p>
1301           </sect2>
1302         
1303         </sect1>
1304
1305         <sect1 id="dpkgchangelog"><heading><tt>debian/changelog</tt>
1306           </heading>
1307
1308           <p>       
1309             This file records the changes to the Debian-specific parts of the
1310             package
1311             <footnote>
1312               <p>
1313                 Though there is nothing stopping an author who is also
1314                 the Debian maintainer from using it for all their
1315                 changes, it will have to be renamed if the Debian and
1316                 upstream maintainers become different
1317                 people.
1318               </p>
1319             </footnote>.
1320           </p>
1321
1322           <p>       
1323             It has a special format which allows the package building
1324             tools to discover which version of the package is being
1325             built and find out other release-specific information.
1326           </p>
1327
1328           <p>
1329             That format is a series of entries like this:       
1330             <example>
1331   <var>package</var> (<var>version</var>) <var>distribution(s)</var>; urgency=<var>urgency</var>
1332
1333    * <var>change details</var>
1334    <var>more change details</var>
1335    * <var>even more change details</var>
1336               
1337   -- <var>maintainer name and email address</var>  <var>date</var>
1338             </example>
1339           </p>
1340
1341           <p>       
1342             <var>package</var> and <var>version</var> are the source
1343             package name and version number.
1344           </p> 
1345
1346           <p>       
1347             <var>distribution(s)</var> lists the distributions where
1348             this version should be installed when it is uploaded - it
1349             is copied to the <tt>Distribution</tt> field in the
1350             <tt>.changes</tt> file.  See <ref id="f-Distribution">.
1351           </p>
1352
1353           <p>       
1354             <var>urgency</var> is the value for the <tt>Urgency</tt>
1355             field in the <tt>.changes</tt> file for the upload.  See
1356             <ref id="f-Urgency">.  It is not possible to specify an
1357             urgency containing commas; commas are used to separate
1358             <tt><var>keyword</var>=<var>value</var></tt> settings in
1359             the <prgn>dpkg</prgn> changelog format (though there is
1360             currently only one useful <var>keyword</var>,
1361             <tt>urgency</tt>).
1362           </p>
1363
1364           <p>       
1365             The change details may in fact be any series of lines
1366             starting with at least two spaces, but conventionally each
1367             change starts with an asterisk and a separating space and
1368             continuation lines are indented so as to bring them in
1369             line with the start of the text above.  Blank lines may be
1370             used here to separate groups of changes, if desired.
1371           </p>
1372
1373           <p>       
1374             The maintainer name and email address should <em>not</em>
1375             necessarily be those of the usual package maintainer.
1376             They should be the details of the person doing
1377             <em>this</em> version.  The information here will be
1378             copied to the <tt>.changes</tt> file, and then later used
1379             to send an acknowledgement when the upload has been
1380             installed.
1381           </p>
1382
1383           <p>       
1384             The <var>date</var> should be in RFC822 format
1385             <footnote>
1386               <p>
1387                 This is generated by the <prgn>822-date</prgn>
1388                 program.
1389               </p>
1390             </footnote>; it should include the timezone specified
1391             numerically, with the timezone name or abbreviation
1392             optionally present as a comment.
1393           </p>
1394
1395           <p>       
1396             The first `title' line with the package name should start
1397             at the left hand margin; the `trailer' line with the
1398             maintainer and date details should be preceded by exactly
1399             one space.  The maintainer details and the date must be
1400             separated by exactly two spaces.
1401           </p>
1402
1403           <p>       
1404             An Emacs mode for editing this format is available: it is
1405             called <tt>debian-changelog-mode</tt>.  You can have this
1406             mode selected automatically when you edit a Debian
1407             changelog by adding a local variables clause to the end of
1408             the changelog.
1409           </p>
1410             
1411           <sect2><heading>Defining alternative changelog formats
1412             </heading>
1413
1414             <p>       
1415               It is possible to use a different format to the standard
1416               one, by providing a parser for the format you wish to
1417               use.
1418             </p>
1419
1420             <p>       
1421               In order to have <tt>dpkg-parsechangelog</tt> run your
1422               parser, you must include a line within the last 40 lines
1423               of your file matching the Perl regular expression:
1424               <tt>\schangelog-format:\s+([0-9a-z]+)\W</tt> The part in
1425               parentheses should be the name of the format.  For
1426               example, you might say:
1427               <example>
1428   @@@ changelog-format: joebloggs @@@
1429               </example>
1430               Changelog format names are non-empty strings of alphanumerics.
1431             </p>
1432
1433             <p>       
1434               If such a line exists then <tt>dpkg-parsechangelog</tt>
1435               will look for the parser as
1436               <tt>/usr/lib/dpkg/parsechangelog/<var>format-name</var></tt>
1437               or
1438               <tt>/usr/local/lib/dpkg/parsechangelog/<var>format-name</var></tt>;
1439               it is an error for it not to find it, or for it not to
1440               be an executable program.  The default changelog format
1441               is <tt>dpkg</tt>, and a parser for it is provided with
1442               the <tt>dpkg</tt> package.
1443             </p>
1444
1445             <p>       
1446               The parser will be invoked with the changelog open on
1447               standard input at the start of the file.  It should read
1448               the file (it may seek if it wishes) to determine the
1449               information required and return the parsed information
1450               to standard output in the form of a series of control
1451               fields in the standard format.  By default it should
1452               return information about only the most recent version in
1453               the changelog; it should accept a
1454               <tt>-v<var>version</var></tt> option to return changes
1455               information from all versions present <em>strictly
1456               after</em> <var>version</var>, and it should then be an
1457               error for <var>version</var> not to be present in the
1458               changelog.
1459             </p>
1460
1461             <p>       
1462               The fields are:
1463               <list compact="compact">
1464                 <item>
1465                   <p><qref id="f-Source"><tt>Source</tt></qref></p>
1466                 </item>
1467                 <item>
1468                   <p><qref id="versions"><tt>Version</tt></qref> (mandatory)</p>
1469                 </item>
1470                 <item>
1471                   <p>
1472                     <qref id="f-Distribution"><tt>Distribution</tt></qref>
1473                     (mandatory)
1474                   </p> 
1475                 </item>
1476                 <item>
1477                   <p><qref id="f-Urgency"><tt>Urgency</tt></qref> (mandatory)</p>
1478                 </item>
1479                 <item>
1480                   <p>
1481                     <qref id="f-Maintainer"><tt>Maintainer</tt></qref>
1482                     (mandatory)
1483                   </p>
1484                 </item>
1485                 <item>
1486                   <p><qref id="f-Date"><tt>Date</tt></qref></p>
1487                 </item>
1488                 <item>
1489                   <p>
1490                     <qref id="f-Changes"><tt>Changes</tt></qref>
1491                     (mandatory)
1492                   </p>
1493                 </item>
1494               </list>
1495
1496             <p>       
1497               If several versions are being returned (due to the use
1498               of <tt>-v</tt>), the urgency value should be of the
1499               highest urgency code listed at the start of any of the
1500               versions requested followed by the concatenated
1501               (space-separated) comments from all the versions
1502               requested; the maintainer, version, distribution and
1503               date should always be from the most recent version.
1504             </p>
1505
1506             <p>       
1507               For the format of the <tt>Changes</tt> field see <ref
1508               id="f-Changes">.
1509             </p>
1510
1511             <p>       
1512               If the changelog format which is being parsed always or
1513               almost always leaves a blank line between individual
1514               change notes these blank lines should be stripped out,
1515               so as to make the resulting output compact.
1516             </p>
1517
1518             <p>       
1519               If the changelog format does not contain date or package
1520               name information this information should be omitted from
1521               the output.  The parser should not attempt to synthesise
1522               it or find it from other sources.
1523             </p>
1524
1525             <p>       
1526               If the changelog does not have the expected format the
1527               parser should exit with a nonzero exit status, rather
1528               than trying to muddle through and possibly generating
1529               incorrect output.
1530             </p>
1531
1532             <p>       
1533               A changelog parser may not interact with the user at
1534               all.</p></sect2>
1535         </sect1>
1536           
1537         <sect1 id="srcsubstvars"><heading><tt>debian/substvars</tt>
1538         and variable substitutions
1539           </heading>
1540
1541           <p>       
1542             When <prgn>dpkg-gencontrol</prgn>,
1543             <prgn>dpkg-genchanges</prgn> and <prgn>dpkg-source</prgn>
1544             generate control files they do variable substitutions on
1545             their output just before writing it.  Variable
1546             substitutions have the form
1547             <tt>${<var>variable-name</var>}</tt>.  The optional file
1548             <tt>debian/substvars</tt> contains variable substitutions
1549             to be used; variables can also be set directly from
1550             <tt>debian/rules</tt> using the <tt>-V</tt> option to the
1551             source packaging commands, and certain predefined
1552             variables are available.
1553           </p>
1554
1555           <p>       
1556             The is usually generated and modified dynamically by
1557             <tt>debian/rules</tt> targets; in this case it must be
1558             removed by the <prgn>clean</prgn> target.
1559           </p>
1560
1561           <p>
1562             See <manref name="dpkg-source" section="1"> for full
1563             details about source variable substitutions, including the
1564             format of <tt>debian/substvars</tt>.</p>
1565         </sect1>
1566           
1567         <sect1><heading><tt>debian/files</tt>
1568           </heading>
1569
1570           <p>       
1571             This file is not a permanent part of the source tree; it
1572             is used while building packages to record which files are
1573             being generated.  <prgn>dpkg-genchanges</prgn> uses it
1574             when it generates a <tt>.changes</tt> file.
1575           </p>
1576
1577           <p>       
1578             It should not exist in a shipped source package, and so it
1579             (and any backup files or temporary files such as
1580             <tt>files.new</tt>
1581               <footnote>
1582                 <p>
1583                   <tt>files.new</tt> is used as a temporary file by
1584                   <prgn>dpkg-gencontrol</prgn> and
1585                   <prgn>dpkg-distaddfile</prgn> - they write a new
1586                   version of <tt>files</tt> here before renaming it,
1587                   to avoid leaving a corrupted copy if an error
1588                   occurs
1589                 </p>
1590               </footnote>) should be removed by the
1591               <prgn>clean</prgn> target.  It may also be wise to
1592               ensure a fresh start by emptying or removing it at the
1593               start of the <prgn>binary</prgn> target.
1594           </p>
1595
1596           <p>       
1597             <prgn>dpkg-gencontrol</prgn> adds an entry to this file
1598             for the <tt>.deb</tt> file that will be created by
1599             <prgn>dpkg-deb</prgn> from the control file that it
1600             generates, so for most packages all that needs to be done
1601             with this file is to delete it in <prgn>clean</prgn>.
1602           </p>
1603
1604           <p>       
1605             If a package upload includes files besides the source
1606             package and any binary packages whose control files were
1607             made with <prgn>dpkg-gencontrol</prgn> then they should be
1608             placed in the parent of the package's top-level directory
1609             and <prgn>dpkg-distaddfile</prgn> should be called to add
1610             the file to the list in <tt>debian/files</tt>.</p>
1611         </sect1>
1612           
1613         <sect1><heading><tt>debian/tmp</tt>
1614           </heading>
1615
1616           <p>       
1617             This is the canonical temporary location for the
1618             construction of binary packages by the <prgn>binary</prgn>
1619             target.  The directory <tt>tmp</tt> serves as the root of
1620             the filesystem tree as it is being constructed (for
1621             example, by using the package's upstream makefiles install
1622             targets and redirecting the output there), and it also
1623             contains the <tt>DEBIAN</tt> subdirectory.  See <ref
1624             id="bincreating">.
1625           </p>
1626
1627           <p>       
1628             If several binary packages are generated from the same
1629             source tree it is usual to use several
1630             <tt>debian/tmp<var>something</var></tt> directories, for
1631             example <tt>tmp-a</tt> or <tt>tmp-doc</tt>.
1632           </p>
1633
1634           <p>       
1635             Whatever <tt>tmp</tt> directories are created and used by
1636             <prgn>binary</prgn> must of course be removed by the
1637             <prgn>clean</prgn> target.</p></sect1>
1638       </sect>
1639         
1640         
1641       <sect id="sourcearchives"><heading>Source packages as archives
1642         </heading>
1643
1644         <p>       
1645           As it exists on the FTP site, a Debian source package
1646           consists of three related files.  You must have the right
1647           versions of all three to be able to use them.
1648         </p>
1649
1650         <p>       
1651           <taglist>
1652             <tag>Debian source control file - <tt>.dsc</tt></tag>
1653             <item>
1654               
1655               <p>
1656                 This file contains a series of fields, identified and
1657                 separated just like the fields in the control file of
1658                 a binary package.  The fields are listed below; their
1659                 syntax is described above, in <ref id="controlfields">.
1660                 <list compact="compact">
1661                   <item>
1662                     <p><qref id="f-Source"><tt>Source</tt></qref></p>
1663                   </item>
1664                   <item>
1665                     <p><qref id="versions"><tt>Version</tt></qref></p>
1666                   </item>
1667                   <item>
1668                     <p><qref id="f-Maintainer"><tt>Maintainer</tt></qref></p>
1669                   </item>
1670                   <item>
1671                     <p><qref id="f-Binary"><tt>Binary</tt></qref></p>
1672                   </item>
1673                   <item>
1674                     <p><qref id="f-Architecture"><tt>Architecture</tt></qref></p>
1675                   </item>
1676                   <item>
1677                      <p>
1678                        <qref id="relationships"><tt>Build-Depends</tt> et
1679                          al.</qref> (source package interrelationships)
1680                      </p>
1681                   </item>
1682                   <item>
1683                     <p>
1684                       <qref id="f-Standards-Version"><tt>Standards-Version</tt></qref></p>
1685                   </item>
1686                   <item>
1687                     <p><qref id="f-Files"><tt>Files</tt></qref></p>
1688                   </item>
1689                 </list>
1690
1691               <p>               
1692                 The source package control file is generated by
1693                 <prgn>dpkg-source</prgn> when it builds the source
1694                 archive, from other files in the source package,
1695                 described above.  When unpacking it is checked against
1696                 the files and directories in the other parts of the
1697                 source package, as described below.</p>
1698             </item>
1699               
1700             <tag>
1701               Original source archive -
1702               <tt>
1703                 <var>package</var>_<var>upstream-version</var>.orig.tar.gz
1704               </tt>
1705             </tag> 
1706
1707             <item>
1708               
1709               <p>
1710                 This is a compressed (with <tt>gzip -9</tt>)
1711                 <prgn>tar</prgn> file containing the source code from
1712                 the upstream authors of the program.  The tarfile
1713                 unpacks into a directory
1714                 <tt><var>package</var>-<var>upstream-version</var>.orig</tt>,
1715                 and does not contain files anywhere other than in
1716                 there or in its subdirectories.</p>
1717             </item>
1718               
1719             <tag>
1720               Debianisation diff -
1721               <tt>
1722                 <var>package</var>_<var>upstream_version-revision</var>.diff.gz
1723               </tt>
1724             </tag> 
1725             <item>
1726               
1727               <p>
1728                 This is a unified context diff (<tt>diff -u</tt>)
1729                 giving the changes which are required to turn the
1730                 original source into the Debian source.  These changes
1731                 may only include editing and creating plain files.
1732                 The permissions of files, the targets of symbolic
1733                 links and the characteristics of special files or
1734                 pipes may not be changed and no files may be removed
1735                 or renamed.
1736               </p>
1737
1738               <p>               
1739                 All the directories in the diff must exist, except the
1740                 <tt>debian</tt> subdirectory of the top of the source
1741                 tree, which will be created by
1742                 <prgn>dpkg-source</prgn> if necessary when unpacking.
1743               </p>
1744
1745               <p>               
1746                 The <prgn>dpkg-source</prgn> program will
1747                 automatically make the <tt>debian/rules</tt> file
1748                 executable (see below).</p></item>
1749           </taglist>
1750             
1751
1752         <p>       
1753           If there is no original source code - for example, if the
1754           package is specially prepared for Debian or the Debian
1755           maintainer is the same as the upstream maintainer - the
1756           format is slightly different: then there is no diff, and the
1757           tarfile is named
1758           <tt><var>package</var>_<var>version</var>.tar.gz</tt> and
1759           contains a directory
1760           <tt><var>package</var>-<var>version</var></tt>.
1761         </p>
1762       </sect>
1763         
1764       <sect><heading>Unpacking a Debian source package without
1765       <prgn>dpkg-source</prgn>
1766         </heading>
1767
1768         <p>       
1769           <tt>dpkg-source -x</tt> is the recommended way to unpack a
1770           Debian source package.  However, if it is not available it
1771           is possible to unpack a Debian source archive as follows:
1772         <enumlist compact="compact">
1773           <item> 
1774             <p>
1775               Untar the tarfile, which will create a <tt>.orig</tt>
1776               directory.</p>
1777           </item>
1778           <item>
1779             <p>Rename the <tt>.orig</tt> directory to
1780               <tt><var>package</var>-<var>version</var></tt>.</p>
1781           </item>
1782             <item>
1783             <p>
1784               Create the subdirectory <tt>debian</tt> at the top of
1785               the source tree.</p>
1786           </item>
1787           <item><p>Apply the diff using <tt>patch -p0</tt>.</p>
1788           </item>
1789           <item><p>Untar the tarfile again if you want a copy of the original
1790               source code alongside the Debianised version.</p>
1791           </item>
1792         </enumlist>
1793         
1794         <p>       
1795           It is not possible to generate a valid Debian source archive
1796           without using <prgn>dpkg-source</prgn>.  In particular,
1797           attempting to use <prgn>diff</prgn> directly to generate the
1798           <tt>.diff.gz</tt> file will not work.
1799         </p>
1800           
1801         <sect1><heading>Restrictions on objects in source packages
1802           </heading>
1803
1804           <p>       
1805             The source package may not contain any hard links
1806             <footnote>
1807               <p>
1808                 This is not currently detected when building source
1809                 packages, but only when extracting
1810                 them.
1811               </p>
1812             </footnote>
1813             <footnote>
1814               <p>
1815                 Hard links may be permitted at some point in the
1816                 future, but would require a fair amount of
1817                 work.
1818               </p>
1819             </footnote>, device special files, sockets or setuid or
1820             setgid files.
1821             <footnote>
1822               <p>
1823                 Setgid directories are allowed.
1824               </p>
1825             </footnote>
1826           </p>
1827
1828           <p>       
1829             The source packaging tools manage the changes between the
1830             original and Debianised source using <prgn>diff</prgn> and
1831             <prgn>patch</prgn>.  Turning the original source tree as
1832             included in the <tt>.orig.tar.gz</tt> into the debianised
1833             source must not involve any changes which cannot be
1834             handled by these tools.  Problematic changes which cause
1835             <prgn>dpkg-source</prgn> to halt with an error when
1836             building the source package are:
1837             <list compact="compact">
1838               <item><p>Adding or removing symbolic links, sockets or pipes.</p>
1839               </item>
1840               <item><p>Changing the targets of symbolic links.</p>
1841               </item>
1842               <item><p>Creating directories, other than <tt>debian</tt>.</p>
1843               </item>
1844               <item><p>Changes to the contents of binary files.</p></item>
1845             </list> Changes which cause <prgn>dpkg-source</prgn> to
1846             print a warning but continue anyway are:
1847             <list compact="compact">
1848               <item>
1849                 <p>
1850                   Removing files, directories or symlinks.
1851                   <footnote>
1852                     <p>
1853                       Renaming a file is not treated specially - it is
1854                       seen as the removal of the old file (which
1855                       generates a warning, but is otherwise ignored),
1856                       and the creation of the new
1857                       one.</p>
1858                   </footnote>
1859                 </p>
1860               </item>
1861               <item>
1862                 <p>
1863                   Changed text files which are missing the usual final
1864                   newline (either in the original or the modified
1865                   source tree).
1866                 </p>
1867               </item>
1868             </list>
1869             Changes which are not represented, but which are not detected by
1870             <prgn>dpkg-source</prgn>, are:
1871             <list compact="compact">
1872               <item><p>Changing the permissions of files (other than
1873                   <tt>debian/rules</tt>) and directories.</p></item>
1874             </list>
1875           </p>
1876
1877           <p>       
1878             The <tt>debian</tt> directory and <tt>debian/rules</tt>
1879             are handled specially by <prgn>dpkg-source</prgn> - before
1880             applying the changes it will create the <tt>debian</tt>
1881             directory, and afterwards it will make
1882             <tt>debian/rules</tt> world-exectuable.
1883           </p>
1884         </sect1>
1885       </sect>
1886     </chapt>
1887       
1888     <chapt id="controlfields"><heading>Control files and their fields
1889       </heading>
1890
1891       <p>       
1892         Many of the tools in the <prgn>dpkg</prgn> suite manipulate
1893         data in a common format, known as control files.  Binary and
1894         source packages have control data as do the <tt>.changes</tt>
1895         files which control the installation of uploaded files, and
1896         <prgn>dpkg</prgn>'s internal databases are in a similar
1897         format.
1898       </p>
1899         
1900       <sect><heading>Syntax of control files
1901         </heading>
1902
1903         <p>       
1904           A file consists of one or more paragraphs of fields.  The
1905           paragraphs are separated by blank lines.  Some control files
1906           only allow one paragraph; others allow several, in which
1907           case each paragraph often refers to a different package.
1908         </p>
1909
1910         <p>       
1911           Each paragraph is a series of fields and values; each field
1912           consists of a name, followed by a colon and the value.  It
1913           ends at the end of the line.  Horizontal whitespace (spaces
1914           and tabs) may occur before or after the value and is ignored
1915           there; it is conventional to put a single space after the
1916           colon.
1917         </p>
1918
1919         <p>       
1920           Some fields' values may span several lines; in this case
1921           each continuation line <em>must</em> start with a space or
1922           tab.  Any trailing spaces or tabs at the end of individual
1923           lines of a field value are ignored.
1924         </p>
1925
1926         <p>       
1927           Except where otherwise stated only a single line of data is
1928           allowed and whitespace is not significant in a field body.
1929           Whitespace may never appear inside names (of packages,
1930           architectures, files or anything else), version numbers or
1931           in between the characters of multi-character version
1932           relationships.
1933         </p>
1934
1935         <p>       
1936           Field names are not case-sensitive, but it is usual to
1937           capitalise the field names using mixed case as shown below.
1938         </p>
1939
1940         <p>       
1941           Blank lines, or lines consisting only of spaces and tabs,
1942           are not allowed within field values or between fields - that
1943           would mean a new paragraph.
1944         </p>
1945
1946         <p>       
1947           It is important to note that there are several fields which
1948           are optional as far as <prgn>dpkg</prgn> and the related
1949           tools are concerned, but which must appear in every Debian
1950           package, or whose omission may cause problems.  When writing
1951           the control files for Debian packages you <em>must</em> read
1952           the Debian policy manual in conjuction with the details
1953           below and the list of fields for the particular file.</p>
1954       </sect>
1955         
1956       <sect><heading>List of fields
1957         </heading>
1958           
1959         <sect1 id="f-Package"><heading><tt>Package</tt>
1960           </heading>
1961
1962           <p>       
1963             The name of the binary package.  Package names consist of
1964             the alphanumerics and <tt>+</tt> <tt>-</tt> <tt>.</tt>
1965             (plus, minus and full stop).
1966             <footnote>
1967               <p>
1968                 The characters <tt>@</tt> <tt>:</tt> <tt>=</tt>
1969                 <tt>%</tt> <tt>_</tt> (at, colon, equals, percent
1970                 and underscore) used to be legal and are still
1971                 accepted when found in a package file, but may not be
1972                 used in new packages
1973               </p>
1974             </footnote>
1975           </p>
1976
1977           <p>       
1978             They must be at least two characters and must start with
1979             an alphanumeric.  In current versions of dpkg they are
1980             sort of case-sensitive<footnote><p>This is a
1981             bug.</p></footnote>; use lowercase package names unless
1982             the package you're building (or referring to, in other
1983             fields) is already using uppercase.</p>
1984         </sect1>
1985           
1986         <sect1 id="f-Version"><heading><tt>Version</tt>
1987           </heading>
1988
1989           <p>       
1990             This lists the source or binary package's version number -
1991             see <ref id="versions">.
1992           </p>
1993
1994         </sect1>
1995           
1996         <sect1 id="f-Architecture"><heading><tt>Architecture</tt>
1997           </heading>
1998
1999           <p>       
2000             This is the architecture string; it is a single word for
2001             the Debian architecture.
2002           </p>
2003
2004           <p>       
2005             <prgn>dpkg</prgn> will check the declared architecture of
2006             a binary package against its own compiled-in value before
2007             it installs it.
2008           </p>
2009
2010           <p>       
2011             The special value <tt>all</tt> indicates that the package
2012             is architecture-independent.
2013           </p>
2014
2015           <p>       
2016             In the main <tt>debian/control</tt> file in the source
2017             package, or in the source package control file
2018             <tt>.dsc</tt>, a list of architectures (separated by
2019             spaces) is also allowed, as is the special value
2020             <tt>any</tt>.  A list indicates that the source will build
2021             an architecture-dependent package, and will only work
2022             correctly on the listed architectures.  <tt>any</tt>
2023             indicates that though the source package isn't dependent
2024             on any particular architecture and should compile fine on
2025             any one, the binary package(s) produced are not
2026             architecture-independent but will instead be specific to
2027             whatever the current build architecture is.
2028           </p>
2029
2030           <p>       
2031             In a <tt>.changes</tt> file the <tt>Architecture</tt>
2032             field lists the architecture(s) of the package(s)
2033             currently being uploaded.  This will be a list; if the
2034             source for the package is being uploaded too the special
2035             entry <tt>source</tt> is also present.
2036           </p>
2037
2038           <p>       
2039             See <ref id="debianrules"> for information how to get the
2040             architecture for the build process. 
2041           </p>
2042         </sect1>
2043           
2044         <sect1 id="f-Maintainer"><heading><tt>Maintainer</tt>
2045           </heading>
2046
2047           <p>       
2048             The package maintainer's name and email address.  The name
2049             should come first, then the email address inside angle
2050             brackets <tt>&lt;&gt</tt> (in RFC822 format).
2051           </p>
2052
2053           <p>       
2054             If the maintainer's name contains a full stop then the
2055             whole field will not work directly as an email address due
2056             to a misfeature in the syntax specified in RFC822; a
2057             program using this field as an address must check for this
2058             and correct the problem if necessary (for example by
2059             putting the name in round brackets and moving it to the
2060             end, and bringing the email address forward).
2061           </p>
2062
2063           <p>       
2064             In a <tt>.changes</tt> file or parsed changelog data this
2065             contains the name and email address of the person
2066             responsible for the particular version in question - this
2067             may not be the package's usual maintainer.
2068           </p>
2069
2070           <p>       
2071             This field is usually optional in as far as the
2072             <prgn>dpkg</prgn> are concerned, but its absence when
2073             building packages usually generates a warning.</p>
2074         </sect1>
2075           
2076         <sect1 id="f-Source"><heading><tt>Source</tt>
2077           </heading>
2078
2079           <p>       
2080             This field identifies the source package name.
2081           </p>
2082
2083           <p>       
2084             In a main source control information or a
2085             <tt>.changes</tt> or <tt>.dsc</tt> file or parsed
2086             changelog data this may contain only the name of the
2087             source package.
2088           </p>
2089
2090           <p>       
2091             In the control file of a binary package (or in a
2092             <tt>Packages</tt> file) it may be followed by a version
2093             number in parentheses.
2094             <footnote>
2095               <p>
2096                 It is usual to leave a space after the package name if
2097                 a version number is specified.
2098               </p>
2099             </footnote> This version number may be omitted (and is, by
2100             <prgn>dpkg-gencontrol</prgn>) if it has the same value as
2101             the <tt>Version</tt> field of the binary package in
2102             question.  The field itself may be omitted from a binary
2103             package control file when the source package has the same
2104             name and version as the binary package.
2105           </p>
2106         </sect1>
2107           
2108         <sect1><heading>Package interrelationship fields:
2109             <tt>Depends</tt>, <tt>Pre-Depends</tt>,
2110             <tt>Recommends</tt> <tt>Suggests</tt>, <tt>Conflicts</tt>,
2111             <tt>Provides</tt>, <tt>Replaces</tt>
2112           </heading>
2113
2114           <p>       
2115             These fields describe the package's relationships with
2116             other packages.  Their syntax and semantics are described
2117             in <ref id="relationships">.</p>
2118         </sect1>
2119           
2120         <sect1 id="f-Description"><heading><tt>Description</tt>
2121           </heading>
2122
2123           <p>       
2124             In a binary package <tt>Packages</tt> file or main source
2125             control file this field contains a description of the
2126             binary package, in a special format.  See <ref
2127             id="descriptions"> for details.
2128           </p>
2129
2130           <p>       
2131             In a <tt>.changes</tt> file it contains a summary of the
2132             descriptions for the packages being uploaded.  The part of
2133             the field before the first newline is empty; thereafter
2134             each line has the name of a binary package and the summary
2135             description line from that binary package.  Each line is
2136             indented by one space.</p>
2137         </sect1>
2138           
2139         <sect1 id="f-Essential"><heading><tt>Essential</tt>
2140           </heading>
2141
2142           <p>       
2143             This is a boolean field which may occur only in the
2144             control file of a binary package (or in the
2145             <tt>Packages</tt> file) or in a per-package fields
2146             paragraph of a main source control data file.
2147           </p>
2148
2149           <p>       
2150             If set to <tt>yes</tt> then <prgn>dpkg</prgn> and
2151             <prgn>dselect</prgn> will refuse to remove the package
2152             (though it can be upgraded and/or replaced).  The other
2153             possible value is <tt>no</tt>, which is the same as not
2154             having the field at all.</p>
2155         </sect1>
2156           
2157         <sect1 id="f-classification"><heading><tt>Section</tt> and
2158         <tt>Priority</tt>
2159           </heading>
2160
2161           <p>       
2162             These two fields classify the package.  The
2163             <tt>Priority</tt> represents how important that it is that
2164             the user have it installed; the <tt>Section</tt>
2165             represents an application area into which the package has
2166             been classified.
2167           </p>
2168
2169           <p>       
2170             When they appear in the <tt>debian/control</tt> file these
2171             fields give values for the section and priority subfields
2172             of the <tt>Files</tt> field of the <tt>.changes</tt> file,
2173             and give defaults for the section and priority of the
2174             binary packages.
2175           </p>
2176
2177           <p>       
2178             The section and priority are represented, though not as
2179             separate fields, in the information for each file in the
2180             <qref id="f-Files"><tt>-File</tt></qref>field of a
2181             <tt>.changes</tt> file.  The section value in a
2182             <tt>.changes</tt> file is used to decide where to install
2183             a package in the FTP archive.
2184           </p>
2185
2186           <p>       
2187             These fields are not used by by <prgn>dpkg</prgn> proper,
2188             but by <prgn>dselect</prgn> when it sorts packages and
2189             selects defaults.  See the Debian policy manual for the
2190             priorities in use and the criteria for selecting the
2191             priority for a Debian package, and look at the Debian FTP
2192             archive for a list of currently in-use priorities.
2193           </p>
2194
2195           <p>       
2196             These fields may appear in binary package control files,
2197             in which case they provide a default value in case the
2198             <tt>Packages</tt> files are missing the information.
2199             <prgn>dpkg</prgn> and <prgn>dselect</prgn> will only use
2200             the value from a <tt>.deb</tt> file if they have no other
2201             information; a value listed in a <tt>Packages</tt> file
2202             will always take precedence.  By default
2203             <prgn>dpkg-gencontrol</prgn> does not include the section
2204             and priority in the control file of a binary package - use
2205             the <tt>-isp</tt>, <tt>-is</tt> or <tt>-ip</tt> options to
2206             achieve this effect.</p>
2207         </sect1>
2208           
2209         <sect1 id="f-Binary"><heading><tt>Binary</tt>
2210           </heading>
2211
2212           <p>       
2213             This field is a list of binary packages.
2214           </p>
2215
2216           <p>       
2217             When it appears in the <tt>.dsc</tt> file it is the list
2218             of binary packages which a source package can produce.  It
2219             does not necessarily produce all of these binary packages
2220             for every architecture.  The source control file doesn't
2221             contain details of which architectures are appropriate for
2222             which of the binary packages.
2223           </p>
2224
2225           <p>       
2226             When it appears in a <tt>.changes</tt> file it lists the
2227             names of the binary packages actually being uploaded.
2228           </p>
2229
2230           <p>       
2231             The syntax is a list of binary packages separated by
2232             commas.
2233             <footnote>
2234               <p>
2235                 A space after each comma is conventional.
2236               </p>
2237             </footnote> Currently the packages must be separated using
2238             only spaces in the <tt>.changes</tt> file.</p>
2239         </sect1>
2240           
2241         <sect1 id="f-Installed-Size"><heading><tt>Installed-Size</tt>
2242           </heading>
2243
2244           <p>       
2245             This field appears in the control files of binary
2246             packages, and in the <tt>Packages</tt> files.  It gives
2247             the total amount of disk space required to install the
2248             named package.
2249           </p>
2250
2251           <p>       
2252             The disk space is represented in kilobytes as a simple
2253             decimal number.</p>
2254         </sect1>
2255           
2256         <sect1 id="f-Files"><heading><tt>Files</tt>
2257           </heading>
2258
2259           <p>       
2260             This field contains a list of files with information about
2261             each one.  The exact information and syntax varies with
2262             the context.  In all cases the the part of the field
2263             contents on the same line as the field name is empty.  The
2264             remainder of the field is one line per file, each line
2265             being indented by one space and containing a number of
2266             sub-fields separated by spaces.
2267           </p>
2268
2269           <p>       
2270             In the <tt>.dsc</tt> (Debian source control) file each
2271             line contains the MD5 checksum, size and filename of the
2272             tarfile and (if applicable) diff file which make up the
2273             remainder of the source package.
2274             <footnote>
2275               <p>
2276                 That is, the parts which are not the
2277                 <tt>.dsc</tt>.
2278               </p>
2279             </footnote> The exact forms of the filenames are described
2280             in <ref id="sourcearchives">.
2281           </p>
2282
2283           <p>       
2284             In the <tt>.changes</tt> file this contains one line per
2285             file being uploaded.  Each line contains the MD5 checksum,
2286             size, section and priority and the filename.  The section
2287             and priority are the values of the corresponding fields in
2288             the main source control file - see <ref
2289             id="f-classification">.  If no section or priority is
2290             specified then <tt>-</tt> should be used, though section
2291             and priority values must be specified for new packages to
2292             be installed properly.
2293           </p>
2294
2295           <p>       
2296             The special value <tt>byhand</tt> for the section in a
2297             <tt>.changes</tt> file indicates that the file in question
2298             is not an ordinary package file and must by installed by
2299             hand by the distribution maintainers.  If the section is
2300             <tt>byhand</tt> the priority should be <tt>-</tt>.
2301           </p>
2302
2303           <p>       
2304             If a new Debian revision of a package is being shipped and
2305             no new original source archive is being distributed the
2306             <tt>.dsc</tt> must still contain the <tt>Files</tt> field
2307             entry for the original source archive
2308             <tt><var>package</var>-<var>upstream-version</var>.orig.tar.gz</tt>,
2309             but the <tt>.changes</tt> file should leave it out.  In
2310             this case the original source archive on the distribution
2311             site must match exactly, byte-for-byte, the original
2312             source archive which was used to generate the
2313             <tt>.dsc</tt> file and diff which are being uploaded.</p>
2314         </sect1>
2315           
2316           
2317         <sect1
2318         id="f-Standards-Version"><heading><tt>Standards-Version</tt>
2319           </heading>
2320
2321           <p>       
2322             The most recent version of the standards (the
2323             <prgn>dpkg</prgn> programmers' and policy manuals and
2324             associated texts) with which the package complies.  This
2325             is updated manually when editing the source package to
2326             conform to newer standards; it can sometimes be used to
2327             tell when a package needs attention.
2328           </p>
2329
2330           <p>       
2331             Its format is the same as that of a version number except
2332             that no epoch or Debian revision is allowed - see <ref
2333             id="versions">.</p>
2334         </sect1>
2335           
2336           
2337         <sect1 id="f-Distribution"><heading><tt>Distribution</tt>
2338           </heading>
2339
2340           <p>       
2341             In a <tt>.changes</tt> file or parsed changelog output
2342             this contains the (space-separated) name(s) of the
2343             distribution(s) where this version of the package should
2344             be or was installed.  Distribution names follow the rules
2345             for package names.  (See <ref id="f-Package">).
2346           </p>
2347
2348           <p>       
2349             Current distribution values are:
2350           <taglist>
2351             <tag><em>stable</em></tag>
2352             <item>
2353               <p> 
2354                 This is the current `released' version of Debian
2355                 GNU/Linux.  A new version is released approximately
2356                 every 3 months after the <em>development</em> code has
2357                 been <em>frozen</em> for a month of testing.  Once the
2358                 distribution is <em>stable</em> only major bug fixes
2359                 are allowed. When changes are made to this
2360                 distribution, the release number is increased
2361                 (for example: 1.2r1 becomes 1.2r2 then 1.2r3, etc).
2362               </p>
2363             </item>
2364                 
2365             <tag><em>unstable</em></tag>
2366             <item>
2367               <p>
2368                 This distribution value refers to the
2369                 <em>developmental</em> part of the Debian distribution
2370                 tree. New packages, new upstream versions of packages
2371                 and bug fixes go into the <em>unstable</em> directory
2372                 tree. Download from this distribution at your own
2373                 risk.</p>
2374             </item>
2375             
2376             <tag><em>contrib</em></tag>
2377             <item>
2378               <p>
2379                 The packages with this distribution value do not meet
2380                 the criteria for inclusion in the main Debian
2381                 distribution as defined by the Policy Manual, but meet
2382                 the criteria for the <em>contrib</em>
2383                 Distribution. There is currently no distinction
2384                 between stable and unstable packages in the
2385                 <em>contrib</em> or <em>non-free</em>
2386                 distributions. Use your best judgement in downloading
2387                 from this Distribution.</p>
2388             </item>
2389                 
2390             <tag><em>non-free</em></tag>
2391             <item>
2392               <p>
2393                 Like the packages in the <em>contrib</em> seciton,
2394                 the packages in <em>non-free</em> do not meet the
2395                 criteria for inclusion in the main Debian distribution
2396                 as defined by the Policy Manual. Again, use your best
2397                 judgement in downloading from this Distribution.</p>
2398               
2399             <tag><em>experimental</em></tag>
2400             <item>
2401               <p>
2402                 The packages with this distribution value are deemed
2403                 by their maintainers to be high risk. Oftentimes they
2404                 represent early beta or developmental packages from
2405                 various sources that the maintainers want people to
2406                 try, but are not ready to be a part of the other parts
2407                 of the Debian distribution tree. Download at your own
2408                 risk.</p>
2409             </item>
2410                 
2411             <tag><em>frozen</em></tag>
2412             <item>
2413               <p>
2414                 From time to time, (currently, every 3 months) the
2415                 <em>unstable</em> distribution enters a state of
2416                 `code-freeze' in anticipation of release as a
2417                 <em>stable</em> version. During this period of testing
2418                 (usually 4 weeks) only fixes for existing or
2419                 newly-discovered bugs will be allowed.
2420               </p>
2421             </item>
2422           </taglist> You should list <em>all</em> distributions that
2423           the package should be installed into. Except in unusual
2424           circumstances, installations to <em>stable</em> should also
2425           go into <em>frozen</em> (if it exists) and
2426           <em>unstable</em>. Likewise, installations into
2427           <em>frozen</em> should also go into <em>unstable</em>.</p>
2428         </sect1>
2429           
2430         <sect1 id="f-Urgency"><heading><tt>Urgency</tt>
2431           </heading>
2432
2433           <p>       
2434             This is a description of how important it is to upgrade to
2435             this version from previous ones.  It consists of a single
2436             keyword usually taking one of the values <tt>LOW</tt>,
2437             <tt>MEDIUM</tt> or <tt>HIGH</tt>) followed by an optional
2438             commentary (separated by a space) which is usually in
2439             parentheses.  For example:
2440             <example>
2441   Urgency: LOW (HIGH for diversions users)
2442             </example>
2443           </p>
2444
2445           <p>       
2446             This field appears in the <tt>.changes</tt> file and in
2447             parsed changelogs; its value appears as the value of the
2448             <tt>urgency</tt> attribute in a <prgn>dpkg</prgn>-style
2449             changelog (see <ref id="dpkgchangelog">).
2450           </p>
2451
2452           <p>       
2453             Urgency keywords are not case-sensitive.</p>
2454         </sect1>
2455           
2456         <sect1 id="f-Date"><heading><tt>Date</tt>
2457           </heading>
2458
2459           <p>       
2460             In <tt>.changes</tt> files and parsed changelogs, this
2461             gives the date the package was built or last edited.</p>
2462         </sect1>
2463           
2464         <sect1 id="f-Format"><heading><tt>Format</tt>
2465           </heading>
2466
2467           <p>       
2468             This field occurs in <tt>.changes</tt> files, and
2469             specifies a format revision for the file.  The format
2470             described here is version <tt>1.5</tt>.  The syntax of the
2471             format value is the same as that of a package version
2472             number except that no epoch or Debian revision is allowed
2473             - see <ref id="versions">.</p>
2474         </sect1>
2475           
2476         <sect1 id="f-Changes"><heading><tt>Changes</tt>
2477           </heading>
2478
2479           <p>       
2480             In a <tt>.changes</tt> file or parsed changelog this field
2481             contains the human-readable changes data, describing the
2482             differences between the last version and the current one.
2483           </p>
2484
2485           <p>       
2486             There should be nothing in this field before the first
2487             newline; all the subsequent lines must be indented by at
2488             least one space; blank lines must be represented by a line
2489             consiting only of a space and a full stop.
2490           </p>
2491
2492           <p>       
2493             Each version's change information should be preceded by a
2494             `title' line giving at least the version, distribution(s)
2495             and urgency, in a human-readable way.
2496           </p>
2497
2498           <p>       
2499             If data from several versions is being returned the entry
2500             for the most recent version should be returned first, and
2501             entries should be separated by the representation of a
2502             blank line (the `title' line may also be followed by the
2503             representation of blank line).</p>
2504         </sect1>
2505           
2506         <sect1 id="f-Filename"><heading><tt>Filename</tt> and
2507         <tt>MSDOS-Filename</tt>
2508           </heading>
2509
2510           <p>       
2511             These fields in <tt>Packages</tt> files give the
2512             filename(s) of (the parts of) a package in the
2513             distribution directories, relative to the root of the
2514             Debian hierarchy.  If the package has been split into
2515             several parts the parts are all listed in order, separated
2516             by spaces.</p>
2517         </sect1>
2518           
2519         <sect1 id="f-Size"><heading><tt>Size</tt> and <tt>MD5sum</tt>
2520           </heading>
2521
2522           <p>       
2523             These fields in <tt>Packages</tt> files give the size (in
2524             bytes, expressed in decimal) and MD5 checksum of the
2525             file(s) which make(s) up a binary package in the
2526             distribution.  If the package is split into several parts
2527             the values for the parts are listed in order, separated by
2528             spaces.</p>
2529         </sect1>
2530           
2531         <sect1 id="f-Status"><heading><tt>Status</tt>
2532           </heading>
2533
2534           <p>       
2535             This field in <prgn>dpkg</prgn>'s status file records
2536             whether the user wants a package installed, removed or
2537             left alone, whether it is broken (requiring
2538             reinstallation) or not and what its current state on the
2539             system is.  Each of these pieces of information is a
2540             single word.</p>
2541         </sect1>
2542           
2543         <sect1 id="f-Config-Version"><heading><tt>Config-Version</tt>
2544           </heading>
2545
2546           <p>       
2547             If a package is not installed or not configured, this
2548             field in <prgn>dpkg</prgn>'s status file records the last
2549             version of the package which was successfully
2550             configured.</p>
2551         </sect1>
2552           
2553         <sect1 id="f-Conffiles"><heading><tt>Conffiles</tt>
2554           </heading>
2555
2556           <p>       
2557             This field in <prgn>dpkg</prgn>'s status file contains
2558             information about the automatically-managed configuration
2559             files held by a package.  This field should <em>not</em>
2560             appear anywhere in a package!</p>
2561         </sect1>
2562           
2563         <sect1><heading>Obsolete fields
2564           </heading>
2565
2566           <p>       
2567             These are still recognised by <prgn>dpkg</prgn> but should
2568             not appear anywhere any more.
2569             <taglist compact="compact">
2570               
2571               <tag><tt>Revision</tt></tag>
2572               <tag><tt>Package-Revision</tt></tag>
2573               <tag><tt>Package_Revision</tt></tag>
2574               <item>
2575                 <p>
2576                   The Debian revision part of the package version was
2577                   at one point in a separate control file field.  This
2578                   field went through several names.</p>
2579               </item>
2580                   
2581               <tag><tt>Recommended</tt></tag>
2582               <item><p>Old name for <tt>Recommends</tt></p>
2583               </item>
2584                 
2585               <tag><tt>Optional</tt></tag>
2586               <item><p>Old name for <tt>Suggests</tt>.</p>
2587               </item>
2588               <tag><tt>Class</tt></tag>
2589               <item><p>Old name for <tt>Priority</tt>.</p>
2590               </item>
2591             </taglist>
2592           </p>
2593         </sect1>
2594       </sect>
2595     </chapt>
2596
2597     <chapt id="versions"><heading>Version numbering
2598       </heading>
2599
2600       <p>       
2601         Every package has a version number, in its <tt>Version</tt>
2602         control file field.
2603       </p>
2604
2605       <p>       
2606         <prgn>dpkg</prgn> imposes an ordering on version numbers, so
2607         that it can tell whether packages are being up- or downgraded
2608         and so that <prgn>dselect</prgn> can tell whether a package it
2609         finds available is newer than the one installed on the system.
2610         The version number format has the most significant parts (as
2611         far as comparison is concerned) at the beginning.
2612       </p>
2613
2614       <p>       
2615         The version number format is:
2616         &lsqb<var>epoch/<tt>:</tt>&rsqb;<var>upstream-version</var>&lsqb;<tt>-/<var>debian-revision</var>&rsqb;.</tt></var>
2617       </p>
2618
2619       <p>       
2620         The three components here are:
2621         <taglist>
2622           <tag><var>epoch</var></tag>
2623           <item>
2624             
2625             <p>
2626               This is a single unsigned integer, which should usually
2627               be small.  It may be omitted, in which case zero is
2628               assumed.  If it is omitted then the
2629               <var>upstream-version</var> may not contain any colons.
2630             </p>
2631
2632             <p>       
2633               It is provided to allow mistakes in the version numbers
2634               of older versions of a package, and also a package's
2635               previous version numbering schemes, to be left behind.
2636             </p>
2637
2638             <p>       
2639               <prgn>dpkg</prgn> will not usually display the epoch
2640               unless it is essential (non-zero, or if the
2641               <var>upstream-version</var> contains a colon);
2642               <prgn>dselect</prgn> does not display epochs at all in
2643               the main part of the package selection display.</p>
2644           </item>
2645             
2646           <tag><var>upstream-version</var></tag>
2647           <item>
2648             
2649             <p>
2650               This is the main part of the version.  It is usually
2651               version number of the original (`upstream') package of
2652               which the <tt>.deb</tt> file has been made, if this is
2653               applicable.  Usually this will be in the same format as
2654               that specified by the upstream author(s); however, it
2655               may need to be reformatted to fit into
2656               <prgn>dpkg</prgn>'s format and comparison scheme.
2657             </p>
2658
2659             <p>       
2660               The comparison behaviour of <prgn>dpkg</prgn> with
2661               respect to the <var>upstream-version</var> is described
2662               below.  The <var>upstream-version</var> portion of the
2663               version number is mandatory.
2664             </p>
2665
2666             <p>       
2667               The <var>upstream-version</var> may contain only
2668               alphanumerics and the characters <tt>.</tt> <tt>+</tt>
2669               <tt>-</tt> <tt>:</tt> (full stop, plus, hyphen, colon)
2670               and should start with a digit.  If there is no
2671               <var>debian-revision</var> then hyphens are not allowed;
2672               if there is no <var>epoch</var> then colons are not
2673               allowed.</p>
2674           </item>
2675             
2676           <tag><var>debian-revision</var></tag>
2677           <item>
2678             
2679             <p>
2680               This part of the version represents the version of the
2681               modifications that were made to the package to make it a
2682               Debian binary package.  It is in the same format as the
2683               <var>upstream-version</var> and <prgn>dpkg</prgn>
2684               compares it in the same way.
2685             </p>
2686
2687             <p>       
2688               It is optional; if it isn't present then the
2689               <var>upstream-version</var> may not contain a hyphen.
2690               This format represents the case where a piece of
2691               software was written specifically to be turned into a
2692               Debian binary package, and so there is only one
2693               `debianization' of it and therefore no revision
2694               indication is required.
2695             </p>
2696
2697             <p>       
2698               It is conventional to restart the
2699               <var>debian-revision</var> at <tt>1</tt> each time the
2700               <var>upstream-version</var> is increased.
2701             </p>
2702
2703             <p>       
2704               <prgn>dpkg</prgn> will break the
2705               <var>upstream-version</var> and
2706               <var>debian-revision</var> apart at the last hyphen in
2707               the string.  The absence of a <var>debian-revision</var>
2708               compares earlier than the presence of one (but note that
2709               the <var>debian-revision</var> is the least significant
2710               part of the version number).
2711             </p>
2712
2713             <p>       
2714               The <var>debian-revision</var> may contain only
2715               alphanumerics and the characters <tt>+</tt> and
2716               <tt>.</tt> (plus and full stop).
2717             </p>
2718           </item>
2719         </taglist>
2720         The <var>upstream-version</var> and <var>debian-revision</var> parts are
2721         compared by <prgn>dpkg</prgn> using the same algorithm:
2722       </p>
2723
2724       <p>       
2725         The strings are compared from left to right.
2726       </p>
2727
2728       <p>       
2729         First the initial part of each string consisting entirely of
2730         non-digit characters is determined.  These two parts (one of
2731         which may be empty) are compared lexically.  If a difference
2732         is found it is returned.  The lexical comparison is a
2733         comparison of ASCII values modified so that all the letters
2734         sort earlier than all the non-letters.
2735       </p>
2736
2737       <p>       
2738         Then the initial part of the remainder of each string which
2739         consists entirely of digit characters is determined.  The
2740         numerical values of these two parts are compared, and any
2741         difference found is returned as the result of the comparison.
2742         For these purposes an empty string (which can only occur at
2743         the end of one or both version strings being compared) counts
2744         as zero.
2745       </p>
2746
2747       <p>       
2748         These two steps are repeated (chopping initial non-digit
2749         strings and initial digit strings off from the start) until a
2750         difference is found or both strings are exhausted.
2751       </p>
2752
2753       <p>       
2754         Note that the purpose of epochs is to allow us to leave behind
2755         mistakes in version numbering, and to cope with situations
2756         where the version numbering changes.  It is <em>not</em> there
2757         to cope with version numbers containing strings of letters
2758         which <prgn>dpkg</prgn> cannot interpret (such as
2759         <tt>ALPHA</tt> or <tt>pre-</tt>), or with silly orderings (the
2760         author of this manual has heard of a package whose versions
2761         went <tt>1.1</tt>, <tt>1.2</tt>, <tt>1.3</tt>, <tt>1</tt>,
2762         <tt>2.1</tt>, <tt>2.2</tt>, <tt>2</tt> and so forth).
2763       </p>
2764
2765       <p>       
2766         If an upstream package has problematic version numbers they
2767         should be converted to a sane form for use in the
2768         <tt>Version</tt> field.
2769       </p>
2770
2771       <p>       
2772         If you need to compare version numbers in a script, you may use
2773         <tt>dpkg --compare-versions ...</tt>. Type <tt>dpkg
2774         --help</tt> for details on arguments.
2775       </p>
2776
2777       <sect>
2778         <heading>Version numbers based on dates</heading>
2779         <p>
2780           In general, Debian packages should use the same version
2781           numbers as the upstream sources.</p>
2782
2783         <p>
2784           However, in some cases where the upstream version number is
2785           based on a date (e.g., a development `snapshot' release)
2786           dpkg cannot handle these version numbers currently, without
2787           epochs. For example, dpkg will consider `96May01' to be
2788           greater than `96Dec24'.</p>
2789
2790         <p>
2791           To prevent having to use epochs for every new upstream
2792           version, the version number should be changed to the
2793           following format in such cases: `19960501', `19961224'. It
2794           is up to the maintainer whether he/she wants to bother the
2795           upstream maintainer to change the version numbers upstream,
2796           too.</p>
2797
2798         <p>
2799           Note, that other version formats based on dates which are
2800           parsed correctly by dpkg should <em>not</em> be changed.</p>
2801
2802         <p>
2803           Native Debian packages (i.e., packages which have been
2804           written especially for Debian) whose version numbers include
2805           dates should always use the `YYYYMMDD' format.</p>
2806       </sect>
2807     </chapt>
2808       
2809     <chapt id="maintainerscripts"><heading>Package maintainer scripts
2810         and installation procedure
2811       </heading>
2812
2813       <sect><heading>Introduction to package maintainer scripts
2814         </heading>
2815
2816         <p>       
2817           It is possible to supply scripts as part of a package which
2818           <prgn>dpkg</prgn> will run for you when your package is
2819           installed, upgraded or removed.
2820         </p>
2821
2822         <p>       
2823           These scripts should be the files <tt>preinst</tt>,
2824           <tt>postinst</tt>, <tt>prerm</tt> and <tt>postrm</tt> in the
2825           control area of the package.  They must be proper exectuable
2826           files; if they are scripts (which is recommended) they must
2827           start with the usual <tt>#!</tt> convention.  They should be
2828           readable and executable to anyone, and not world-writeable.
2829         </p>
2830
2831         <p>       
2832           <prgn>dpkg</prgn> looks at the exit status from these
2833           scripts.  It is important that they exit with a non-zero
2834           status if there is an error, so that <prgn>dpkg</prgn> can
2835           stop its processing.  For shell scripts this means that you
2836           <em>almost always</em> need to use <tt>set -e</tt> (this is
2837           usually true when writing shell scripts, in fact).  It is
2838           also important, of course, that they don't exit with a
2839           non-zero status if everything went well.
2840         </p>
2841
2842         <p>       
2843           It is necessary for the error recovery procedures that the
2844           scripts be idempotent: ie, invoking the same script several
2845           times in the same situation should do no harm.  If the first
2846           call failed, or aborted half way through for some reason,
2847           the second call should merely do the things that were left
2848           undone the first time, if any, and exit with a success
2849           status.
2850         </p>
2851
2852         <p>       
2853           When a package is upgraded a combination of the scripts from
2854           the old and new packages is called in amongst the other
2855           steps of the upgrade procedure.  If your scripts are going
2856           to be at all complicated you need to be aware of this, and
2857           may need to check the arguments to your scripts.
2858         </p>
2859
2860         <p>       
2861           Broadly speaking the <prgn>preinst</prgn> is called before
2862           (a particular version of) a package is installed, and the
2863           <prgn>postinst</prgn> afterwards; the <prgn>prerm</prgn>
2864           before (a version of) a package is removed and the
2865           <prgn>postrm</prgn> afterwards.       
2866         </p>
2867           <!--
2868           next paragraph by Guy Maor to close bug #2481
2869           -->
2870  
2871           <p> Programs called from maintainer scripts should not
2872           normally have a path prepended to them. Before installation
2873           is started <prgn>dpkg</prgn> checks to see if the programs
2874           <prgn>ldconfig</prgn>, <prgn>start-stop-daemon</prgn>,
2875           <prgn>install-info</prgn>, and <prgn>update-rc.d</prgn> can
2876           be found via the <tt>PATH</tt> environment variable. Those
2877           programs, and any other program that one would expect to on
2878           the <tt>PATH</tt>, should thus be invoked without an
2879           absolute pathname. Maintainer scripts should also not reset
2880           the <tt>PATH</tt>, though they might choose to modify it by
2881           pre- or appending package-specific directories. These
2882           considerations really apply to all shell scripts.</p>
2883       </sect>
2884         
2885       <sect id="mscriptsinstact"><heading>Summary of ways maintainer
2886       scripts are called
2887         </heading>
2888
2889         <p>       
2890           <list compact="compact">
2891             <item>
2892               <p><var>new-preinst</var> <tt>install</tt></p>
2893             </item>
2894             <item>
2895               <p><var>new-preinst</var> <tt>install</tt>
2896               <var>old-version</var></p>
2897             </item>
2898             <item>
2899               <p><var>new-preinst</var> <tt>upgrade</tt>
2900               <var>old-version</var></p>
2901             </item>
2902             <item>
2903               <p><var>old-preinst</var> <tt>abort-upgrade</tt>
2904               <var>new-version</var>
2905               </p>
2906             </item> 
2907           </list>
2908
2909         <p>       
2910           <list compact="compact">
2911             <item>
2912               <p><var>postinst</var> <tt>configure</tt>
2913                 <var>most-recently-configured-version</var></p>
2914             </item>
2915             <item>
2916               <p><var>old-postinst</var> <tt>abort-upgrade</tt>
2917               <var>new version</var></p>
2918             </item>
2919             <item>
2920               <p><var>conflictor's-postinst</var> <tt>abort-remove</tt>
2921                 <tt>in-favour</tt> <var>package</var>
2922                 <var>new-version</var></p>
2923             </item>
2924             <item>
2925               <p>
2926                 <var>deconfigured's-postinst</var>
2927                 <tt>abort-deconfigure</tt> <tt>in-favour</tt>
2928                 <var>failed-install-package</var> <var>version</var>
2929                 <tt>removing</tt> <var>conflicting-package</var>
2930                 <var>version</var>
2931               </p>
2932             </item>
2933           </list>
2934
2935         <p>       
2936           <list compact="compact">
2937             <item>
2938               <p><var>prerm</var> <tt>remove</tt></p>
2939             </item>
2940             <item>
2941               <p><var>old-prerm</var> <tt>upgrade</tt>
2942                 <var>new-version</var></p>
2943             </item>
2944             <item>
2945               <p><var>new-prerm</var> <tt>failed-upgrade</tt>
2946                 <var>old-version</var></p>
2947             </item>
2948             <item>
2949               <p><var>conflictor's-prerm</var> <tt>remove</tt>
2950                 <tt>in-favour</tt> <var>package</var>
2951                 <var>new-version</var></p>
2952             </item>
2953             <item>
2954               <p>
2955                 <var>deconfigured's-prerm</var> <tt>deconfigure</tt>
2956                 <tt>in-favour</tt> <var>package-being-installed</var>
2957                 <var>version</var> <tt>removing</tt>
2958                 <var>conflicting-package</var>
2959                 <var>version</var>
2960               </p>
2961             </item>
2962           </list>
2963
2964         <p>       
2965           <list compact="compact">
2966             <item>
2967               <p><var>postrm</var> <tt>remove</tt></p>
2968             </item>
2969             <item>
2970               <p><var>postrm</var> <tt>purge</tt></p>
2971             </item>
2972             <item>
2973               <p>
2974                 <var>old-postrm</var> <tt>upgrade</tt>
2975                 <var>new-version</var></p>
2976             </item>
2977             <item>
2978               <p><var>new-postrm</var> <tt>failed-upgrade</tt>
2979                 <var>old-version</var></p>
2980             </item>
2981             <item>
2982               <p><var>new-postrm</var> <tt>abort-install</tt></p>
2983             </item>
2984             <item>
2985               <p><var>new-postrm</var> <tt>abort-install</tt>
2986                 <var>old-version</var></p>
2987             </item>
2988             <item>
2989               <p><var>new-postrm</var> <tt>abort-upgrade</tt>
2990                 <var>old-version</var></p>
2991             </item>
2992             <item>
2993               <p>
2994                 <var>disappearer's-postrm</var> <tt>disappear</tt>
2995                 <var>overwriter</var>
2996                 <var>overwriter-version</var></p></item>
2997           </list>
2998         </p>
2999         
3000         
3001       <sect id="unpackphase"><heading>Details of unpack phase of
3002       installation or upgrade
3003         </heading>
3004
3005         <p>       
3006           The procedure on installation/upgrade/overwrite/disappear
3007           (ie, when running <tt>dpkg --unpack</tt>, or the unpack
3008           stage of <tt>dpkg
3009             --install</tt>) is as follows.  In each case if an error occurs the
3010           actions in are general run backwards - this means that the maintainer
3011           scripts are run with different arguments in reverse order.  These are
3012           the `error unwind' calls listed below.
3013           
3014           <enumlist>
3015             <item>
3016               <p>
3017                 <enumlist>
3018                   <item>
3019                     <p>If a version the package is already
3020                       installed, call
3021                       <example>
3022   <var>old-prerm</var> upgrade <var>new-version</var>
3023                       </example></p>
3024                   </item>
3025                   <item>
3026                     <p>
3027                       If this gives an error (ie, a non-zero exit
3028                       status), dpkg will attempt instead:
3029                       <example>
3030   <var>new-prerm</var> failed-upgrade <var>old-version</var>
3031                       </example>
3032                       Error unwind, for both the above cases:
3033                       <example>
3034   <var>old-postinst</var> abort-upgrade <var>new-version</var>
3035                       </example>
3036                     </p>
3037                   </item>
3038                 </enumlist>
3039               </p>
3040             </item>
3041             <item>
3042               <p>If a `conflicting' package is being removed at the same time:
3043                 <enumlist>
3044                   <item>
3045                     <p>
3046                       If any packages depended on that conflicting
3047                       package and <tt>--auto-deconfigure</tt> is
3048                       specified, call, for each such package:
3049                       <example>
3050   <var>deconfigured's-prerm</var> deconfigure \
3051    in-favour <var>package-being-installed</var> <var>version</var> \
3052     removing <var>conflicting-package</var> <var>version</var>
3053                       </example>
3054                       Error unwind:
3055                       <example>
3056   <var>deconfigured's-postinst</var> abort-deconfigure \
3057     in-favour <var>package-being-installed-but-failed</var> <var>version</var> \
3058       removing <var>conflicting-package</var> <var>version</var>
3059                       </example> 
3060                       The deconfigured packages are marked as
3061                       requiring configuration, so that if
3062                       <tt>--install</tt> is used they will be
3063                       configured again if possible.</p>
3064                   </item>
3065                   <item>
3066                     <p>To prepare for removal of the conflicting package, call:
3067                       <example>
3068   <var>conflictor's-prerm</var> remove in-favour <var>package</var> <var>new-version</var>
3069                       </example>
3070                       Error unwind:
3071                       <example>
3072   <var>conflictor's-postinst</var> abort-remove \
3073     in-favour <var>package</var> <var>new-version</var>
3074                       </example>
3075                     </p>
3076                   </item>
3077                 </enumlist>
3078               </p>
3079             </item>
3080             <item>
3081               <p>
3082                 <enumlist>
3083                   <item>
3084                     <p>If the package is being upgraded, call:
3085                       <example>
3086   <var>new-preinst</var> upgrade <var>old-version</var>
3087                       </example></p>
3088                   </item>
3089                   <item>
3090                     <p>
3091                       Otherwise, if the package had some configuration
3092                       files from a previous version installed (ie, it
3093                       is in the `configuration files only' state):
3094                       <example>
3095   <var>new-preinst</var> install <var>old-version</var>
3096                       </example></p>
3097                     
3098                   <item>
3099                     <p>Otherwise (ie, the package was completely purged):
3100                       <example>
3101   <var>new-preinst</var> install
3102                       </example>
3103                       Error unwind versions, respectively:
3104                       <example>
3105   <var>new-postrm</var> abort-upgrade <var>old-version</var>
3106     <var>new-postrm</var> abort-install <var>old-version</var>
3107       <var>new-postrm</var> abort-install
3108                       </example>
3109                     </p>
3110                   </item>
3111                 </enumlist>
3112               </p>
3113             </item>
3114             <item>
3115
3116               <p>
3117                 The new package's files are unpacked, overwriting any
3118                 that may be on the system already, for example any
3119                 from the old version of the same package or from
3120                 another package (backups of the old files are left
3121                 around, and if anything goes wrong dpkg will attempt
3122                 to put them back as part of the error unwind).
3123               </p>
3124
3125               <p>               
3126                 It is an error for a package to contains files which
3127                 are on the system in another package, unless
3128                 <tt>Replaces</tt> is used (see <ref id="replaces">).
3129                 Currently the <tt>--force-overwrite</tt> flag is
3130                 enabled, downgrading it to a warning, but this may not
3131                 always be the case.
3132               </p>
3133
3134               <p>               
3135                 It is a more serious error for a package to contain a
3136                 plain file or other kind of nondirectory where another
3137                 package has a directory (again, unless
3138                 <tt>Replaces</tt> is used).  This error can be
3139                 overridden if desired using
3140                 <tt>--force-overwrite-dir</tt>, but this is not
3141                 advisable.
3142               </p>
3143
3144               <p>               
3145                 Packages which overwrite each other's files produce
3146                 behaviour which though deterministic is hard for the
3147                 system administrator to understand.  It can easily
3148                 lead to `missing' programs if, for example, a package
3149                 is installed which overwrites a file from another
3150                 package, and is then removed again.
3151                 <footnote>
3152                   <p>
3153                     Part of the problem is due to what is arguably a
3154                     bug in <prgn>dpkg</prgn>.
3155                   </p>
3156                 </footnote>
3157               </p>
3158
3159               <p>               
3160                 A directory will never be replaced by a symbolic links
3161                 to a directory or vice versa; instead, the existing
3162                 state (symlink or not) will be left alone and
3163                 <prgn>dpkg</prgn> will follow the symlink if there is
3164                 one.</p>
3165             </item>
3166               
3167             <item>
3168               
3169               <p><enumlist>
3170                   <item>
3171                     <p>If the package is being upgraded, call
3172                       <example>
3173   <var>old-postrm</var> upgrade <var>new-version</var>
3174                       </example></p>
3175                   </item>
3176                   <item>
3177                     <p>If this fails, <prgn>dpkg</prgn> will attempt:
3178                       <example>
3179   <var>new-postrm</var> failed-upgrade <var>old-version</var>
3180                       </example>
3181                       Error unwind, for both cases:
3182                       <example>
3183   <var>old-preinst</var> abort-upgrade <var>new-version</var>
3184                       </example>
3185                     </p>
3186                   </item>
3187                 </enumlist>
3188                 This is the point of no return - if <prgn>dpkg</prgn>
3189                 gets this far, it won't back off past this point if an
3190                 error occurs.  This will leave the package in a fairly
3191                 bad state, which will require a successful
3192                 reinstallation to clear up, but it's when
3193                 <prgn>dpkg</prgn> starts doing things that are
3194                 irreversible.</p>
3195             </item>
3196             <item>
3197               <p>               
3198                 Any files which were in the old version of the package
3199                 but not in the new are removed.</p>
3200             </item>
3201             <item>
3202                 <p>The new file list replaces the old.</p>
3203             </item>
3204             <item>
3205                 <p>The new maintainer scripts replace the old.</p>
3206             </item>
3207                 
3208             <item>
3209               <p>Any packages all of whose files have been overwritten during the
3210                 installation, and which aren't required for
3211                 dependencies, are considered to have been removed.
3212                 For each such package,
3213                 <enumlist>
3214                   <item>
3215                     <p><prgn>dpkg</prgn> calls:
3216                       <example>
3217   <var>disappearer's-postrm</var> disappear \
3218     <var>overwriter</var> <var>overwriter-version</var>
3219                       </example>
3220                     </p>
3221                   </item>
3222                   <item>
3223                       <p>The package's maintainer scripts are removed.
3224                     </p>
3225                   </item>
3226                   <item>
3227                     <p>
3228                       It is noted in the status database as being in a
3229                       sane state, namely not installed (any conffiles
3230                       it may have are ignored, rather than being
3231                       removed by <prgn>dpkg</prgn>).  Note that
3232                       disappearing packages do not have their prerm
3233                       called, because <prgn>dpkg</prgn> doesn't know
3234                       in advance that the package is going to
3235                       vanish.
3236                     </p>
3237                   </item>
3238                 </enumlist>
3239               </p>
3240             </item>
3241             <item>
3242               <p>
3243                 Any files in the package we're unpacking that are also
3244                 listed in the file lists of other packages are removed
3245                 from those lists.  (This will lobotomise the file list
3246                 of the `conflicting' package if there is one.)
3247               </p>
3248             </item>
3249             <item>
3250               <p>
3251                 The backup files made during installation, above, are
3252                 deleted.
3253               </p>
3254             </item>
3255                 
3256             <item>
3257               <p>
3258                 The new package's status is now sane, and recorded as
3259                 `unpacked'.  Here is another point of no return - if
3260                 the conflicting package's removal fails we do not
3261                 unwind the rest of the installation; the conflicting
3262                 package is left in a half-removed limbo.
3263               </p>
3264             </item>
3265             <item>
3266               <p>
3267                 If there was a conflicting package we go and do the
3268                 removal actions (described below), starting with the
3269                 removal of the conflicting package's files (any that
3270                 are also in the package being installed have already
3271                 been removed from the conflicting package's file list,
3272                 and so do not get removed now).
3273               </p>
3274             </item>
3275           </enumlist>
3276         </p>
3277       </sect>
3278
3279       <sect><heading>Details of configuration
3280         </heading>
3281
3282         <p>       
3283           When we configure a package (this happens with <tt>dpkg
3284           --install</tt>, or with <tt>--configure</tt>), we first
3285           update the conffiles and then call:
3286           <example>
3287   <var>postinst</var> configure <var>most-recently-configured-version</var>
3288           </example>
3289         </p>
3290
3291         <p>       
3292           No attempt is made to unwind after errors during
3293           configuration.
3294         </p>
3295
3296         <p>       
3297           If there is no most recently configured version
3298           <prgn>dpkg</prgn> will pass a null argument; older versions
3299           of dpkg may pass <tt>&lt;unknown&gt;</tt> (including the
3300           angle brackets) in this case.  Even older ones do not pass a
3301           second argument at all, under any circumstances.
3302         </p>
3303       </sect>
3304         
3305       <sect><heading>Details of removal and/or configuration purging
3306         </heading>
3307
3308         <p>       
3309           <enumlist>
3310             <item>
3311               <p>
3312                 <example>
3313   <var>prerm</var> remove
3314                 </example>
3315               </p>
3316             </item>
3317             <item>
3318               <p>
3319                 The package's files are removed (except conffiles).
3320               </p>
3321             </item>
3322             <item>
3323               <p><example>
3324   <var>postrm</var> remove
3325                 </example></p>
3326             </item>
3327             <item>
3328               <p>All the maintainer scripts except the postrm are removed.
3329               </p>
3330
3331               <p>               
3332                 If we aren't purging the package we stop here.  Note
3333                 that packages which have no postrm and no conffiles
3334                 are automatically purged when removed, as there is no
3335                 difference except for the <prgn>dpkg</prgn>
3336                 status.</p>
3337             </item>
3338             <item>
3339               <p>
3340                 The conffiles and any backup files (<tt>~</tt>-files,
3341                 <tt>#*#</tt> files, <tt>%</tt>-files,
3342                 <tt>.dpkg-{old,new,tmp}</tt>, etc.) are removed.</p>
3343             </item>
3344             <item>
3345               <p><example>
3346   <var>postrm</var> purge
3347                 </example></p>
3348             </item>
3349             <item>
3350                 <p>The package's file list is removed.</p>
3351             </item>
3352           </enumlist>
3353           No attempt is made to unwind after errors during
3354           removal.</p>
3355       </sect>
3356     </chapt>
3357       
3358     <chapt id="descriptions"><heading>Descriptions of packages - the
3359         <tt>Description</tt> field
3360       </heading>
3361
3362       <p>       
3363         The <tt>Description</tt> control file field is used by
3364         <prgn>dselect</prgn> when the user is selecting which packages
3365         to install and by <prgn>dpkg</prgn> when it displays
3366         information about the status of packages and so forth.  It is
3367         included on the FTP site in the <prgn>Packages</prgn> files,
3368         and may also be used by the Debian WWW pages.
3369       </p>
3370
3371       <p>       
3372         The description is intended to describe the program to a user
3373         who has never met it before so that they know whether they
3374         want to install it.  It should also give information about the
3375         significant dependencies and conflicts between this package
3376         and others, so that the user knows why these dependencies and
3377         conflicts have been declared.
3378       </p>
3379
3380       <p>       
3381         The field's format is as follows:
3382         <example>
3383   Description: <var>single line synopsis</var>
3384   <var>extended description over several lines</var>
3385         </example>
3386       </p>
3387
3388       <p>       
3389         The synopsis is often printed in lists of packages and so
3390         forth, and should be as informative as possible.  Every
3391         package should also have an extended description.
3392       </p>
3393
3394       <sect><heading>Types of formatting line in the extended
3395           description
3396         </heading>
3397
3398         <p>       
3399           <list>
3400             <item>
3401               <p>
3402                 Those starting with a single space are part of a
3403                 paragraph.  Successive lines of this form will be
3404                 word-wrapped when displayed.  The leading space will
3405                 usually be stripped off.
3406               </p>
3407             </item>
3408                 
3409             <item>
3410               <p>
3411                 Those starting with two or more spaces.  These will be
3412                 displayed verbatim.  If the display cannot be panned
3413                 horizontally the displaying program will linewrap them
3414                 `hard' (ie, without taking account of word breaks).
3415                 If it can they will be allowed to trail off to the
3416                 right.  None, one or two initial spaces may be
3417                 deleted, but the number of spaces deleted from each
3418                 line will be the same (so that you can have indenting
3419                 work correctly, for example).
3420               </p>
3421             </item>
3422                 
3423             <item>
3424               <p>Those containing a single space followed by a single full stop
3425                 character.  These are rendered as blank lines.  This
3426                 is the <em>only</em> way to get a blank line - see
3427                 below.</p>
3428             </item>
3429               
3430             <item>
3431               <p>
3432                 Those containing a space, a full stop and some more
3433                 characters.  These are for future expansion.  Do not
3434                 use them.</p>
3435             </item>
3436           </list>
3437         </p>
3438       </sect>
3439
3440       <sect><heading>Notes about writing descriptions
3441         </heading>
3442
3443         <p>       
3444           <em>Always</em> start extended description lines with at least one
3445           whitespace character.  Fields in the control file and in the Packages
3446           file are separated by field names starting in the first column, just
3447           as message header fields are in RFC822.  Forgetting the whitespace
3448           will cause <prgn>dpkg-deb</prgn>
3449           <footnote>
3450             <p>
3451               Version 0.93.23 or later.
3452             </p>
3453           </footnote> to produce a syntax error when trying to build
3454           the package.  If you force it to build anyway
3455           <prgn>dpkg</prgn> will refuse to install the resulting
3456           mess.
3457         </p>
3458
3459         <p>       
3460           <em>Do not</em> include any completely <em>empty</em>
3461           lines. These separate different records in the Packages file
3462           and different packages in the <tt>debian/control</tt> file,
3463           and are forbidden in package control files.  See the
3464           previous paragraph for what happens if you get this wrong.
3465         </p>
3466
3467         <p>       
3468           The single line synopsis should be kept brief - certainly
3469           under 80 characters.  <prgn>dselect</prgn> displays between
3470           25 and 49 characters without panning if you're using an
3471           80-column terminal, depending on what display options are in
3472           effect.
3473         </p>
3474
3475         <p>       
3476           Do not include the package name in the synopsis line.  The
3477           display software knows how to display this already, and you
3478           do not need to state it.  Remember that in many situations
3479           the user may only see the synopsis line - make it as
3480           informative as you can.
3481         </p>
3482
3483         <p>       
3484           The extended description should describe what the package
3485           does and how it relates to the rest of the system (in terms
3486           of, for example, which subsystem it is which part of).
3487         </p>
3488
3489         <p>       
3490           The blurb that comes with a program in its announcements
3491           and/or <prgn>README</prgn> files is rarely suitable for use
3492           in a description.  It is usually aimed at people who are
3493           already in the community where the package is used.  The
3494           description field needs to make sense to anyone, even people
3495           who have no idea about any of the things the package deals
3496           with.
3497         </p>
3498
3499         <p>       
3500           Put important information first, both in the synopis and
3501           extended description.  Sometimes only the first part of the
3502           synopsis or of the description will be displayed.  You can
3503           assume that there will usually be a way to see the whole
3504           extended description.
3505         </p>
3506
3507         <p>       
3508           You may include information about dependencies and so forth
3509           in the extended description, if you wish.
3510         </p>
3511
3512         <p>       
3513           Do not use tab characters.  Their effect is not predictable.
3514         </p>
3515
3516         <p>       
3517           Do not try to linewrap the summary (the part on the same
3518           line as the field name <tt>Description</tt>) into the
3519           extended description.  This will not work correctly when the
3520           full description is displayed, and makes no sense where only
3521           the summary is available.</p>
3522       </sect>
3523         
3524       <sect><heading>Example description in control file for Smail
3525         </heading>
3526
3527         <p>       
3528           <example>
3529   Package: smail
3530   Version: 3.1.29.1-13
3531   Maintainer: Ian Jackson &lt;iwj10@cus.cam.ac.uk&gt;
3532   Recommends: pine | mailx | elm | emacs | mail-user-agent
3533   Suggests: metamail
3534   Depends: cron, libc5
3535   Conflicts: sendmail
3536   Provides: mail-transport-agent
3537   Description: Electronic mail transport system.
3538   Smail is the recommended mail transport agent (MTA) for Debian.
3539   .
3540   An MTA is the innards of the mail system - it takes messages from
3541   user-friendly mailer programs and arranges for them to be delivered
3542   locally or passed on to other systems as required.
3543   .
3544   In order to make use of it you must have one or more user level
3545   mailreader programs such as elm, pine, mailx or Emacs (which has Rmail
3546   and VM as mailreaders) installed.  If you wish to send messages other
3547   than just to other users of your system you must also have appropriate
3548   networking support, in the form of IP or UUCP.
3549           </example>
3550         </p>
3551       </sect>
3552     </chapt>
3553
3554     <chapt id="relationships"><heading>Declaring relationships between
3555     packages
3556       </heading>
3557
3558       <p>       
3559         Packages can declare in their control file that they have
3560         certain relationships to other packages - for example, that
3561         they may not be installed at the same time as certain other
3562         packages, and/or that they depend on the presence of others,
3563         or that they should overwrite files in certain other packages
3564         if present.
3565       </p>
3566
3567       <p>       
3568         This is done using the <tt>Depends</tt>, <tt>Recommends</tt>,
3569         <tt>Suggests</tt>, <tt>Conflicts</tt>, <tt>Provides</tt> and
3570         <tt>Replaces</tt> control file fields.
3571       </p>
3572
3573       <p>
3574         Source packages may declare relationships to binary packages,
3575         saying that they require certain binary packages being
3576         installed or absent at the time of building the package.
3577       </p>
3578         
3579       <p>
3580         This is done using the <tt>Build-Depends</tt>,
3581         <tt>Build-Depends-Indep</tt>, <tt>Build-Conflicts</tt>, and
3582         <tt>Build-Conflicts-Indep</tt> control file fields.
3583       </p>
3584
3585       <sect id="depsyntax"><heading>Syntax of relationship fields
3586         </heading>
3587
3588         <p>       
3589           These fields all have a uniform syntax.  They are a list of
3590           package names separated by commas.
3591         </p>
3592
3593         <p>
3594           In <tt>Depends</tt>, <tt>Recommends</tt>, <tt>Suggests</tt>,
3595           <tt>Pre-Depends</tt>, <tt>Build-Depends</tt> and
3596           <tt>Build-Depends-Indep</tt>(the fields which declare
3597           dependencies of the package in which they occur on other
3598           packages) these package names may also be lists of
3599           alternative package names, separated by vertical bar symbols
3600           <tt>|</tt> (pipe symbols).
3601         </p>
3602
3603         <p>       
3604           All the fields except <tt>Provides</tt> may restrict their
3605           applicability to particular versions of each named package.
3606           This is done in parentheses after each individual package
3607           name; the parentheses should contain a relation from the
3608           list below followed by a version number, in the format
3609           described in <ref id="versions">.
3610         </p>
3611
3612         <p>       
3613           The relations allowed are <tt>&lt;&lt;</tt>, <tt>&lt;=</tt>,
3614           <tt>=</tt>, <tt>&gt;=</tt> and <tt>&gt;&gt;</tt> for
3615           strictly earlier, earlier or equal, exactly equal, later or
3616           equal and strictly later, respectively.  The forms
3617           <tt>&lt;</tt> and <tt>&gt;</tt> were used to mean
3618           earlier/later or equal, rather than strictly earlier/later,
3619           so they should not appear in new packages (though
3620           <prgn>dpkg</prgn> still supports them).
3621         </p>
3622
3623         <p>       
3624           Whitespace may appear at any point in the version
3625           specification, and must appear where it's necessary to
3626           disambiguate; it is not otherwise significant.  For
3627           consistency and in case of future changes to
3628           <prgn>dpkg</prgn> it is recommended that a single space be
3629           used after a version relationship and before a version
3630           number; it is usual also to put a single space after each
3631           comma, on either side of each vertical bar, and before each
3632           open parenthesis.
3633         </p>
3634
3635         <p>       
3636           For example:
3637           <example>
3638   Package: metamail
3639   Version: 2.7-3
3640   Depends: libc5 (>= 5.2.18-4), mime-support, csh | tcsh
3641           </example>
3642         </p>
3643  
3644         <p>
3645           All fields that specify build-time relationships
3646           (<tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
3647           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt>)
3648           may be restricted to a certain set of architectures.  This
3649           is done in brackets after each individual package name and
3650           the optional version specification.  The brackets enclose a
3651           list of Debian architecture names separated by whitespace.
3652           An exclamation mark may be prepended to each name. If the
3653           current Debian host architecture is not in this list and
3654           there are no exclamation marks in the list, or it is in the
3655           list with a prepended exclamation mark, the package name and
3656           the associated version specification are ignored completely
3657           for the purposes of defining the relationships.
3658          </p>
3659  
3660          <p>
3661            For example:
3662            <example>
3663    Source: glibc
3664    Build-Depends-Indep: texinfo
3665    Build-Depends: kernel-headers-2.2.10 [!hurd-i386],
3666                   hurd-dev [hurd-i386], gnumach-dev [hurd-i386]
3667            </example>
3668          </p> 
3669       </sect>
3670   
3671       <sect>
3672         <heading>Binary Dependencies - <tt>Depends</tt>,
3673           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Pre-Depends</tt>
3674         </heading>
3675
3676         <p>       
3677           These four fields are used to declare a dependency by one
3678           package on another.  They appear in the depending package's
3679           control file.
3680         </p>
3681
3682         <p>       
3683           All but <tt>Pre-Depends</tt> (discussed below) take effect
3684           <em>only</em> when a package is to be configured.  They do
3685           not prevent a package being on the system in an unconfigured
3686           state while its dependencies are unsatisfied, and it is
3687           possible to replace a package whose dependencies are
3688           satisfied and which is properly installed with a different
3689           version whose dependencies are not and cannot be satisfied;
3690           when this is done the depending package will be left
3691           unconfigured (since attempts to configure it will give
3692           errors) and will not function properly.
3693         </p>
3694
3695         <p>       
3696           For this reason packages in an installation run are usually
3697           all unpacked first and all configured later; this gives
3698           later versions of packages with dependencies on later
3699           versions of other packages the opportunity to have their
3700           dependencies satisfied.
3701         </p>
3702
3703         <p>       
3704           Thus <tt>Depends</tt> allows package maintainers to impose
3705           an order in which packages should be configured.
3706           <taglist>
3707             <tag><tt>Depends</tt></tag>
3708             <item>
3709               
3710               <p>This declares an absolute dependency.
3711               </p>
3712
3713               <p>               
3714                 <prgn>dpkg</prgn> will not configure packages whose
3715                 dependencies aren't satisfied.  If it is asked to make
3716                 an installation which would cause an installed
3717                 package's dependencies to become unsatisfied it will
3718                 complain
3719                 <footnote>
3720                   <p>
3721                     Current versions (1.2.4) of <prgn>dpkg</prgn> have
3722                     a bug in this area which will cause some of these
3723                     problems to be ignored.
3724                   </p>
3725                 </footnote>, unless <tt>--auto-deconfigure</tt> is
3726                 specified, in which case those packages will be
3727                 deconfigured before the installation proceeds.
3728               </p>
3729
3730               <p>               
3731                 <prgn>dselect</prgn> makes it hard for the user to
3732                 select packages for installation, removal or upgrade
3733                 in a way that would mean that packages'
3734                 <prgn>Depends</prgn> fields would be unsatisfied.  The
3735                 user can override this if they wish, for example if
3736                 they know that <prgn>dselect</prgn> has an out-of-date
3737                 view of the real package relationships.
3738               </p>
3739
3740               <p>               
3741                 The <tt>Depends</tt> field should be used if the
3742                 depended-on package is required for the depending
3743                 package to provide a significant amount of
3744                 functionality.</p>
3745             </item>
3746               
3747             <tag><tt>Recommends</tt></tag>
3748             <item>
3749               <p>This declares a strong, but not absolute, dependency.
3750               </p>
3751
3752               <p>               
3753                 <tt>Recommends</tt> is ignored by <prgn>dpkg</prgn>,
3754                 so that users using the command-line (who are presumed
3755                 to know what they're doing) will not be impeded.
3756               </p>
3757
3758               <p>               
3759                 It is treated by <prgn>dselect</prgn> exactly as
3760                 <tt>Depends</tt> is; this makes it hard for the user
3761                 to select things so as to leave <tt>Recommends</tt>
3762                 fields unsatisfied, but they are able to do so by
3763                 being persistent.
3764               </p>
3765
3766               <p>               
3767                 The <tt>Recommends</tt> field should list packages
3768                 that would be found together with this one in all but
3769                 unusual installations.</p>
3770             </item>
3771               
3772             <tag><tt>Suggests</tt></tag>
3773             <item>
3774               
3775               <p>
3776                 This is used to declare that one package may be more
3777                 useful with one or more others.  Using this field
3778                 tells the packaging system and the user that the
3779                 listed packages are related to this one and can
3780                 perhaps enhance its usefulness, but that installing
3781                 this one without them is perfectly reasonable.
3782               </p>
3783
3784               <p>               
3785                 <prgn>dselect</prgn> will offer suggsted packages to
3786                 the system administrator when they select the
3787                 suggesting package, but the default is not to install
3788                 the suggested package.</p>
3789             </item>
3790               
3791             <tag><tt>Pre-Depends</tt></tag>
3792             <item>
3793               
3794               <p>This field is like <tt>Depends</tt>, except that it also forces
3795                 <prgn>dpkg</prgn> to complete installation of the
3796                 packages named before even starting the installation
3797                 of the package which declares the predependency.
3798               </p>
3799
3800               <p>               
3801                 <prgn>dselect</prgn> checks for predependencies when
3802                 it is doing an installation run, and will attempt to
3803                 find the packages which are required to be installed
3804                 first and do so in the right order.
3805               </p>
3806
3807               <p>               
3808                 However, this process is slow (because it requires
3809                 repeated invocations of <prgn>dpkg</prgn>) and
3810                 troublesome (because it requires guessing where to
3811                 find the appropriate files).
3812               </p>
3813
3814               <p>               
3815                 For these reasons, and because this field imposes
3816                 restrictions on the order in which packages may be
3817                 unpacked (which can be difficult for installations
3818                 from multipart media, for example),
3819                 <tt>Pre-Depends</tt> should be used sparingly,
3820                 preferably only by packages whose premature upgrade or
3821                 installation would hamper the ability of the system to
3822                 continue with any upgrade that might be in progress.
3823               </p>
3824
3825               <p>               
3826                 When the package declaring it is being configured, a
3827                 <tt>Pre-Dependency</tt> will be considered satisfied
3828                 only if the depending package has been correctly
3829                 configured, just as if an ordinary <tt>Depends</tt>
3830                 had been used.
3831               </p>
3832
3833               <p>               
3834                 However, when a package declaring a predependency is
3835                 being unpacked the predependency can be satisfied even
3836                 if the depended-on package(s) are only unpacked or
3837                 half-configured, provided that they have been
3838                 configured correctly at some point in the past (and
3839                 not removed or partially removed since).  In this case
3840                 both the previously-configured and currently unpacked
3841                 or half-configured versions must satisfy any version
3842                 clause in the <tt>Pre-Depends</tt> field.
3843               </p>
3844             </item>
3845           </taglist>
3846         </p>
3847         <p> 
3848           When selecting which level of dependency to use you should
3849           consider how important the depended-on package is to the
3850           functionality of the one declaring the dependency.  Some
3851           packages are composed of components of varying degrees of
3852           importance.  Such a package should list using
3853           <tt>Depends</tt> the package(s) which are required by the
3854           more important components.  The other components'
3855           requirements may be mentioned as Suggestions or
3856           Recommendations, as appropriate to the components' relative
3857           importance.
3858         </p>
3859
3860       <sect1><heading>Dependencies on shared libraries
3861         </heading>
3862         
3863         <p>         
3864             The dependency fields listed above are used by packages
3865             which need shared libraries to declare dependencies on the
3866             appropriate packages.
3867         </p>
3868
3869         <p>         
3870           These dependencies are usually determined automatically
3871           using <prgn>dpkg-shlibdeps</prgn> and inserted in the
3872           package control file using the control file substitution
3873           variables mechanism; see <ref id="srcsubstvars"> and 
3874           <ref id="sourcetools">.
3875         </p>
3876       </sect1>
3877           
3878       <sect1><heading>Deconfiguration due to removal during bulk
3879       installations
3880         </heading>
3881           
3882         <p>         
3883           If <prgn>dpkg</prgn> would like to remove a package due to a
3884           conflict, as described above, but this would violate a
3885           dependency of some other package on the system,
3886           <prgn>dpkg</prgn> will usually not remove the conflicting
3887           package and halt with an error.
3888         </p>
3889           
3890         <p>         
3891           However, if the <tt>--auto-deconfigure</tt> (<tt>-B</tt>)
3892           option is used <prgn>dpkg</prgn> will automatically
3893           `deconfigure' the package with the problematic dependency,
3894           so that the conflicting package can be removed and the
3895           package we're trying to install can be installed.  If
3896           <prgn>dpkg</prgn> is being asked to install packages (rather
3897           than just unpacking them) it will try to reconfigure the
3898           package when it has unpacked all its arguments, in the hope
3899           that one of the other packages it is installing will satisfy
3900           the problematic dependency.
3901         </p>
3902
3903           <p>       
3904             <prgn>dselect</prgn> supplies this argument to
3905             <prgn>dpkg</prgn> when it invokes it, so that bulk
3906             installations proceed smoothly.
3907         </p>
3908       </sect1>
3909
3910       <sect id="conflicts"><heading>Alternative binary packages -
3911           <tt>Conflicts</tt> and <tt>Replaces</tt>
3912         </heading>
3913
3914         <p>       
3915           When one binary package declares a conflict with another
3916           <prgn>dpkg</prgn> will refuse to allow them to be installed
3917           on the system at the same time.
3918         </p>
3919
3920         <p>       
3921           If one package is to be installed, the other must be removed
3922           first - if the package being installed is marked as
3923           replacing (<ref id="replaces">) the one on the system, or
3924           the one on the system is marked as deselected, or both
3925           packages are marked <tt>Essential</tt>, then
3926           <prgn>dpkg</prgn> will automatically remove the package
3927           which is causing the conflict, otherwise it will halt the
3928           installation of the new package with an error. This
3929           mechanism specifically doesn't work when the installed
3930           package is <tt>Essential</tt>, but the new package is not.
3931         </p>
3932
3933         <p>       
3934           <prgn>dselect</prgn> makes it hard to select conflicting
3935           packages, though the user can override this if they wish.
3936           If they do not override it then <prgn>dselect</prgn> will
3937           select one of the packages for removal, and the user must
3938           make sure it is the right one.  In the future
3939           <prgn>dselect</prgn> will look for the presence of a
3940           <tt>Replaces</tt> field to help decide which package should
3941           be installed and which removed.
3942         </p>
3943
3944         <p>       
3945           A package will not cause a conflict merely because its
3946           configuration files are still installed; it must be at least
3947           half-installed.
3948         </p>
3949
3950         <p>       
3951           A special exception is made for packages which declare a
3952           conflict with their own package name, or with a virtual
3953           package which they provide (see below): this does not
3954           prevent their installation, and allows a package to conflict
3955           with others providing a replacement for it.  You use this
3956           feature when you want the package in question to be the only
3957           package providing something.
3958         </p>
3959
3960         <p>       
3961           A <tt>Conflicts</tt> entry should almost never have an
3962           `earlier than' version clause.  This would prevent
3963           <prgn>dpkg</prgn> from upgrading or installing the package
3964           which declared such a conflict until the upgrade or removal
3965           of the conflicted-with package had been completed.  This
3966           aspect of installation ordering is not handled by
3967           <prgn>dselect</prgn>, so that the use <tt>Conflicts</tt> in
3968           this way is likely to cause problems for `bulk run' upgrades
3969           and installations.
3970         </p>
3971       </sect>
3972         
3973       <sect id="virtual"><heading>Virtual packages - <tt>Provides</tt>
3974         </heading>
3975
3976         <p> 
3977            As well as the names of actual (`concrete') packages, the
3978            package relationship fields <tt>Depends</tt>,
3979            <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
3980            <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Conflicts</tt>,
3981            <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt> may
3982            mention virtual packages.
3983         </p>
3984
3985         <p>       
3986           A virtual package is one which appears in the
3987           <tt>Provides</tt> control file field of another package.
3988           The effect is as if the package(s) which provide a
3989           particular virtual package name had been listed by name
3990           everywhere the virtual package name appears.
3991         </p>
3992
3993         <p>       
3994           If there are both a real and a virtual package of the same
3995           name then the dependency may be satisfied (or the conflict
3996           caused) by either the real package or any of the virtual
3997           packages which provide it.  This is so that, for example,
3998           supposing we have
3999           <example>
4000   Package: vm
4001   Depends: emacs
4002           </example>
4003           and someone else releases an xemacs package they can say
4004           <example>
4005   Package: xemacs
4006   Provides: emacs
4007           </example> and all will work in the interim (until a purely
4008           virtual package name is decided on and the <tt>emacs</tt>
4009           and <tt>vm</tt> packages are changed to use it).
4010         </p>
4011
4012         <p>       
4013           If a dependency or a conflict has a version number attached
4014           then only real packages will be considered to see whether
4015           the relationship is satisfied (or the prohibition violated,
4016           for a conflict) - it is assumed that a real package which
4017           provides virtual package is not of the `right' version.  So,
4018           a <tt>Provides</tt> field may not contain version numbers,
4019           and the version number of the concrete package which
4020           provides a particular virtual package will not be looked at
4021           when considering a dependency on or conflict with the
4022           virtual package name.
4023         </p>
4024
4025         <p>       
4026           It is likely that the ability will be added in a future
4027           release of <prgn>dpkg</prgn> to specify a version number for
4028           each virtual package it provides.  This feature is not yet
4029           present, however, and is expected to be used only
4030           infrequently.
4031         </p>
4032
4033         <p>       
4034           If you want to specify which of a set of real packages should be the
4035           default to satisfy a particular dependency on a virtual package, you
4036           should list the real package as an alternative before the virtual.
4037         </p>
4038       </sect>
4039         
4040         
4041       <sect id="replaces"><heading><tt>Replaces</tt> - overwriting
4042       files and replacing packages
4043         </heading>
4044
4045         <p>       
4046           The <tt>Replaces</tt> control file field has two purposes,
4047           which come into play in different situations.
4048         </p>
4049
4050         <p>       
4051           Virtual packages (<ref id="virtual">) are not considered
4052           when looking at a <tt>Replaces</tt> field - the packages
4053           declared as being replaced must be mentioned by their real
4054           names.
4055         </p>
4056           
4057         <sect1><heading>Overwriting files in other packages
4058           </heading>
4059
4060           <p>       
4061             Firstly, as mentioned before, it is usually an error for a
4062             package to contains files which are on the system in
4063             another package, though currently the
4064             <tt>--force-overwrite</tt> flag is enabled by default,
4065             downgrading the error to a warning,
4066           </p>
4067
4068           <p>       
4069             If the overwriting package declares that it replaces the
4070             one containing the file being overwritten then
4071             <prgn>dpkg</prgn> will proceed, and replace the file from
4072             the old package with that from the new.  The file will no
4073             longer be listed as `owned' by the old package.
4074           </p>
4075
4076           <p>       
4077             If a package is completely replaced in this way, so that
4078             <prgn>dpkg</prgn> does not know of any files it still
4079             contains, it is considered to have disappeared.  It will
4080             be marked as not wanted on the system (selected for
4081             removal) and not installed.  Any conffiles details noted
4082             in the package will be ignored, as they will have been
4083             taken over by the replacing package(s).  The package's
4084             <prgn>postrm</prgn> script will be run to allow the
4085             package to do any final cleanup required.  See <ref
4086             id="mscriptsinstact">.
4087           </p>
4088
4089           <p>       
4090             In the future <prgn>dpkg</prgn> will discard files which
4091             overwrite those from another package which declares that
4092             it replaces the one being installed (so that you can
4093             install an older version of a package without problems).
4094           </p>
4095
4096           <p>       
4097             This usage of <tt>Replaces</tt> only takes effect when
4098             both packages are at least partially on the system at
4099             once, so that it can only happen if they do not conflict
4100             or if the conflict has been overridden.</p>
4101         </sect1>
4102           
4103         <sect1><heading>Replacing whole packages, forcing their
4104         removal
4105           </heading>
4106
4107           <p>       
4108             Secondly, <tt>Replaces</tt> allows <prgn>dpkg</prgn> and
4109             <prgn>dselect</prgn> to resolve which package should be
4110             removed when there is a conflict - see <ref id="conflicts">.  This
4111             usage only takes effect when the two packages <em>do</em>
4112             conflict, so that the two effects do not interfere with
4113             each other.
4114           </p>
4115         </sect1>
4116       </sect>
4117         
4118       <sect><heading>Defaults for satisfying dependencies - ordering
4119         </heading>
4120
4121         <p>       
4122           Ordering is significant in dependency fields.
4123         </p>
4124
4125         <p>       
4126           Usually dselect will suggest to the user that they select
4127           the package with the most `fundamental' class (eg, it will
4128           prefer Base packages to Optional ones), or the one that they
4129           `most wanted' to select in some sense.
4130         </p>
4131
4132         <p>       
4133           In the absence of other information <prgn>dselect</prgn>
4134           will offer a default selection of the first named package in
4135           a list of alternatives.
4136         </p>
4137
4138         <p>       
4139           However, there is no way to specify the `order' of several
4140           packages which all provide the same thing, when that thing
4141           is listed as a dependency.
4142         </p>
4143
4144         <p>       
4145           Therefore a dependency on a virtual package should contain a
4146           concrete package name as the first alternative, so that this
4147           is the default.
4148         </p>
4149
4150         <p>       
4151           For example, consider the set of packages:
4152           <example>
4153   Package: glibcdoc
4154   Recommends: info-browser
4155   
4156   Package: info
4157   Provides: info-browser
4158   
4159   Package: emacs
4160   Provides: info-browser
4161           </example>
4162         </p>
4163
4164         <p>       
4165           If <prgn>emacs</prgn> and <prgn>info</prgn> both have the
4166           same priority then <prgn>dselect</prgn>'s choice is
4167           essentially random.  Better would be
4168           <example>
4169   Package: glibcdoc
4170   Recommends: info | info-browser
4171           </example>
4172           so that <prgn>dselect</prgn> defaults to selecting the
4173           lightweight standalone info browser.
4174         </p>
4175       </sect>
4176       
4177   
4178       <sect><heading>Relationships between source and binary packages -
4179               <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4180               <tt>Build-Conflicts</tt>, <tt>Build-Conflicts-Indep</tt>
4181         </heading>
4182
4183         <p>
4184           A source package may declare a dependency or a conflict on a
4185           binary package.  This is done with the control file fields
4186           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4187           <tt>Build-Conflicts</tt>, and <tt>Build-Conflicts-Indep</tt>.  Their
4188           semantics is that the dependencies and conflicts they define
4189           must be satisfied (as defined earlier for binary packages),
4190           when one of the targets in <tt>debian/rules</tt> that the
4191           particular field applies to is invoked.
4192
4193           <taglist>
4194             <tag><tt>Build-Depends</tt>, <tt>Build-Conflicts</tt></tag>
4195             <item>
4196               <p>
4197                 The <tt>Build-Depends</tt> and
4198                 <tt>Build-Conflicts</tt> fields apply to the targets
4199                 <tt>build</tt>, <tt>binary</tt>, <tt>binary-arch</tt>
4200                 and <tt>binary-indep</tt>.
4201               </p>
4202             </item>
4203             <tag><tt>Build-Depends-Indep</tt>, <tt>Build-Conflicts-Indep</tt></tag>
4204             <item>
4205               <p>
4206                 The <tt>Build-Depends-Indep</tt> and
4207                 <tt>Build-Conflicts-Indep</tt> fields apply to the
4208                 targets <tt>binary</tt> and <tt>binary-indep</tt>.
4209               </p>
4210             </item>
4211           </taglist>
4212
4213         </p>
4214
4215       </sect>
4216     </chapt>
4217
4218
4219     <chapt id="conffiles"><heading>Configuration file handling
4220       </heading>
4221
4222       <p>       
4223         <prgn>dpkg</prgn> can do a certain amount of automatic
4224         handling of package configuration files.
4225       </p>
4226
4227       <p>       
4228         Whether this mechanism is appropriate depends on a number of
4229         factors, but basically there are two approaches to any
4230         particular configuration file.
4231       </p>
4232
4233       <p>       
4234         The easy method is to ship a best-effort configuration in the
4235         package, and use <prgn>dpkg</prgn>'s conffile mechanism to
4236         handle updates.  If the user is unlikely to want to edit the
4237         file, but you need them to be able to without losing their
4238         changes, and a new package with a changed version of the file
4239         is only released infrequently, this is a good approach.
4240       </p>
4241
4242       <p>       
4243         The hard method is to build the configuration file from
4244         scratch in the <prgn>postinst</prgn> script, and to take the
4245         responsibility for fixing any mistakes made in earlier
4246         versions of the package automatically.  This will be
4247         appropriate if the file is likely to need to be different on
4248         each system.
4249       </p>
4250         
4251       <sect><heading>Automatic handling of configuration files by
4252       <prgn>dpkg</prgn>
4253         </heading>
4254
4255         <p>       
4256           A package may contain a control area file called
4257           <tt>conffiles</tt>.  This file should be a list of filenames
4258           of configuration files needing automatic handling, separated
4259           by newlines.  The filenames should be absolute pathnames,
4260           and the files referred to should actually exist in the
4261           package.
4262         </p>
4263
4264         <p>       
4265           When a package is upgraded <prgn>dpkg</prgn> will process
4266           the configuration files during the configuration stage,
4267           shortly before it runs the package's <prgn>postinst</prgn>
4268           script,
4269         </p>
4270
4271         <p>       
4272           For each file it checks to see whether the version of the
4273           file included in the package is the same as the one that was
4274           included in the last version of the package (the one that is
4275           being upgraded from); it also compares the version currently
4276           installed on the system with the one shipped with the last
4277           version.
4278         </p>
4279
4280         <p>       
4281           If neither the user nor the package maintainer has changed
4282           the file, it is left alone.  If one or the other has changed
4283           their version, then the changed version is preferred - i.e.,
4284           if the user edits their file, but the package maintainer
4285           doesn't ship a different version, the user's changes will
4286           stay, silently, but if the maintainer ships a new version
4287           and the user hasn't edited it the new version will be
4288           installed (with an informative message).  If both have
4289           changed their version the user is prompted about the problem
4290           and must resolve the differences themselves.
4291         </p>
4292
4293         <p>       
4294           The comparisons are done by calculating the MD5 message
4295           digests of the files, and storing the MD5 of the file as it
4296           was included in the most recent version of the package.
4297         </p>
4298
4299         <p>       
4300           When a package is installed for the first time
4301           <prgn>dpkg</prgn> will install the file that comes with it,
4302           unless that would mean overwriting a file already on the
4303           filesystem.
4304         </p>
4305
4306         <p>       
4307           However, note that <prgn>dpkg</prgn> will <em>not</em>
4308           replace a conffile that was removed by the user (or by a
4309           script).  This is necessary because with some programs a
4310           missing file produces an effect hard or impossible to
4311           achieve in another way, so that a missing file needs to be
4312           kept that way if the user did it.
4313         </p>
4314
4315         <p>       
4316           Note that a package should <em>not</em> modify a
4317           <prgn>dpkg</prgn>-handled conffile in its maintainer
4318           scripts.  Doing this will lead to <prgn>dpkg</prgn> giving
4319           the user confusing and possibly dangerous options for
4320           conffile update when the package is upgraded.</p>
4321       </sect>
4322         
4323       <sect><heading>Fully-featured maintainer script configuration
4324       handling
4325         </heading>
4326
4327         <p>       
4328           For files which contain site-specific information such as
4329           the hostname and networking details and so forth, it is
4330           better to create the file in the package's
4331           <prgn>postinst</prgn> script.
4332         </p>
4333
4334         <p>       
4335           This will typically involve examining the state of the rest
4336           of the system to determine values and other information, and
4337           may involve prompting the user for some information which
4338           can't be obtained some other way.
4339         </p>
4340
4341         <p>       
4342           When using this method there are a couple of important
4343           issues which should be considered:
4344         </p>
4345
4346         <p>       
4347           If you discover a bug in the program which generates the
4348           configuration file, or if the format of the file changes
4349           from one version to the next, you will have to arrange for
4350           the postinst script to do something sensible - usually this
4351           will mean editing the installed configuration file to remove
4352           the problem or change the syntax.  You will have to do this
4353           very carefully, since the user may have changed the file,
4354           perhaps to fix the very problem that your script is trying
4355           to deal with - you will have to detect these situations and
4356           deal with them correctly.
4357         </p>
4358
4359         <p>       
4360           If you do go down this route it's probably a good idea to
4361           make the program that generates the configuration file(s) a
4362           separate program in <tt>/usr/sbin</tt>, by convention called
4363           <tt><var>package</var>config</tt> and then run that if
4364           appropriate from the post-installation script.  The
4365           <tt><var>package</var>config</tt> program should not
4366           unquestioningly overwrite an existing configuration - if its
4367           mode of operation is geared towards setting up a package for
4368           the first time (rather than any arbitrary reconfiguration
4369           later) you should have it check whether the configuration
4370           already exists, and require a <tt>--force</tt> flag to
4371           overwrite it.</p></sect>
4372     </chapt>
4373       
4374       
4375       
4376     <chapt id="alternatives"><heading>Alternative versions of an interface -
4377         <prgn>update-alternatives</prgn>
4378       </heading>
4379
4380       <p>       
4381         When several packages all provide different versions of the
4382         same program or file it is useful to have the system select a
4383         default, but to allow the system administrator to change it
4384         and have their decisions respected.
4385       </p>
4386
4387       <p>       
4388         For example, there are several versions of the <prgn>vi</prgn>
4389         editor, and there is no reason to prevent all of them from
4390         being installed at once, each under their own name
4391         (<prgn>nvi</prgn>, <prgn>vim</prgn> or whatever).
4392         Nevertheless it is desirable to have the name <tt>vi</tt>
4393         refer to something, at least by default.
4394       </p>
4395
4396       <p>       
4397         If all the packages involved cooperate, this can be done with
4398         <prgn>update-alternatives</prgn>.
4399       </p>
4400
4401       <p>       
4402         Each package provides its own version under its own name, and
4403         calls <prgn>update-alternatives</prgn> in its postinst to
4404         register its version (and again in its prerm to deregister
4405         it).
4406       </p>
4407
4408       <p>       
4409         See the manpage <manref name="update-alternatives"
4410         section="8"> for details.
4411       </p>
4412
4413       <p>       
4414         If <prgn>update-alternatives</prgn> does not seem appropriate
4415         you may wish to consider using diversions instead.</p>
4416     </chapt>
4417       
4418       
4419     <chapt id="diversions"><heading>Diversions - overriding a
4420     package's version of a file
4421       </heading>
4422
4423       <p>       
4424         It is possible to have <prgn>dpkg</prgn> not overwrite a file
4425         when it reinstalls the package it belongs to, and to have it
4426         put the file from the package somewhere else instead.
4427       </p>
4428
4429       <p>       
4430         This can be used locally to override a package's version of a
4431         file, or by one package to override another's version (or
4432         provide a wrapper for it).
4433       </p>
4434
4435       <p>       
4436         Before deciding to use a diversion, read <ref
4437         id="alternatives"> to see if you really want a diversion
4438         rather than several alternative versions of a program.
4439       </p>
4440
4441       <p>       
4442         There is a diversion list, which is read by <prgn>dpkg</prgn>,
4443         and updated by a special program <prgn>dpkg-divert</prgn>.
4444         Please see <manref name="dpkg-divert" section="8"> for full
4445         details of its operation.
4446       </p>
4447
4448       <p>       
4449         When a package wishes to divert a file from another, it should
4450         call <prgn>dpkg-divert</prgn> in its preinst to add the
4451         diversion and rename the existing file.  For example,
4452         supposing that a <prgn>smailwrapper</prgn> package wishes to
4453         install a wrapper around <tt>/usr/sbin/smail</tt>:
4454         <example>
4455   if [ install = "$1" -o upgrade = "$1" ]; then
4456      dpkg-divert --package smailwrapper --add --rename \
4457         --divert /usr/sbin/smail.real /usr/sbin/smail
4458   fi
4459         </example> Testing <tt>$1</tt> is necessary so that the script
4460         doesn't try to add the diversion again when
4461         <prgn>smailwrapper</prgn> is upgraded.  The <tt>--package
4462         smailwrapper</tt> ensures that <prgn>smailwrapper</prgn>'s
4463         copy of <tt>/usr/sbin/smail</tt> can bypass the diversion and
4464         get installed as the true version.
4465       </p>
4466
4467       <p>       
4468         The postrm has to do the reverse:
4469         <example>
4470   if [ remove = "$1" ]; then
4471      dpkg-divert --package smailwrapper --remove --rename \
4472         --divert /usr/sbin/smail.real /usr/sbin/smail
4473   fi
4474         </example>
4475       </p>
4476
4477       <p>       
4478         Do not attempt to divert a file which is vitally important for
4479         the system's operation - when using <prgn>dpkg-divert</prgn>
4480         there is a time, after it has been diverted but before
4481         <prgn>dpkg</prgn> has installed the new version, when the file
4482         does not exist.</p>
4483     </chapt>
4484       
4485       
4486     <chapt id="sharedlibs"><heading>Shared libraries
4487       </heading>
4488
4489       <p>       
4490         Packages containing shared libraries must be constructed with
4491         a little care to make sure that the shared library is always
4492         available.  This is especially important for packages whose
4493         shared libraries are vitally important, such as the libc.
4494       </p>
4495
4496       <p>       
4497         Firstly, your package should install the shared libraries
4498         under their normal names.  For example, the
4499         <prgn>libgdbm1</prgn> package should install
4500         <tt>libgdbm.so.1.7.3</tt> as
4501         <tt>/usr/lib/libgdbm.so.1.7.3</tt>.  The files should not be
4502         renamed or relinked by any prerm or postrm scripts;
4503         <prgn>dpkg</prgn> will take care of renaming things safely
4504         without affecting running programs, and attempts to interfere
4505         with this are likely to lead to problems.
4506       </p>
4507
4508       <p>       
4509         Secondly, your package should include the symlink that
4510         <prgn>ldconfig</prgn> would create for the shared libraries.
4511         For example, the <prgn>libgdbm1</prgn> package should include
4512         a symlink from <tt>/usr/lib/libgdbm.so.1</tt> to
4513         <tt>libgdbm.so.1.7.3</tt>.  This is needed so that
4514         <prgn>ld.so</prgn> can find the library in between the time
4515         <prgn>dpkg</prgn> installs it and <prgn>ldconfig</prgn> is run
4516         in the <prgn>postinst</prgn> script.  Futhermore, older
4517         versions of the package management system required the library
4518         must be placed before the symlink pointing to it in the
4519         <tt>.deb</tt> file.  This is so that by the time
4520         <prgn>dpkg</prgn> comes to install the symlink (overwriting
4521         the previous symlink pointing at an older version of the
4522         library) the new shared library is already in place.
4523         Unfortunately, this was not not always possible, since it
4524         highly depends on the behaviour of the filesystem. Some
4525         filesystems (such as reisefs) will reorder the files so it
4526         doesn't matter in what order you create them. In newer
4527         versions of <prgn>dpkg</prgn>, this is handled automatically. 
4528       </p>
4529
4530         <!--
4531         next Paragraph added to close Bug #5299, Guy Maor
4532         -->
4533         
4534       <p>       
4535         Thirdly, the development package should contain a symlink for
4536         the shared library without a version number.  For example, the
4537         <tt>libgdbm1-dev</tt> package should include a symlink from
4538         <tt>/usr/lib/libgdm.so</tt> to <tt>libgdm.so.1.7.3</tt>.  This
4539         symlink is needed by <prgn>ld</prgn> when compiling packages
4540         as it will only look for <tt>libgdm.so</tt> and
4541         <tt>libgdm.a</tt> when compiling dynamically or statically,
4542         respectively.
4543       </p>
4544
4545         <!--
4546         next paragraph changed by Christian Schwarz (see policy weekly #6)
4547         -->
4548         
4549       <p>       
4550         Any package installing shared libraries in a directory that's listed
4551         in <tt>/etc/ld.so.conf</tt> or in one of the default library
4552         directories of <prgn>ld.so</prgn> (currently, these are <tt>/usr/lib</tt>
4553         and <tt>/lib</tt>) must call <prgn>ldconfig</prgn> in its <prgn>postinst</prgn>
4554         script if and only if the first argument is `configure'. However, it
4555         is important not to call <prgn>ldconfig</prgn> in the postrm or preinst
4556         scripts in the case where the package is being upgraded (see <ref
4557                                                                           id="unpackphase">), as <prgn>ldconfig</prgn> will see the temporary names
4558         that <prgn>dpkg</prgn> uses for the files while it is
4559         installing them and will make the shared library links point
4560         to them, just before <prgn>dpkg</prgn> continues the
4561         installation and removes the links!
4562       </p>
4563
4564         <!-- 
4565         moved from section 2.2 , DMorris 
4566         -->
4567         
4568       <sect id="shlibs"><heading>The <tt>shlibs</tt> File Format
4569         </heading>
4570
4571         <p>       
4572           This file is for use by <prgn>dpkg-shlibdeps</prgn> and is
4573           required when your package provides shared libraries.
4574         </p>
4575
4576         <p>       
4577           Each line is of the form:
4578           <example>
4579  <var>library-name</var> <var>version-or-soname</var> <var>dependencies ...</var>
4580           </example>
4581         </p>
4582
4583         <p>       
4584           <var>library-name</var> is the name of the shared library,
4585           for example <tt>libc5</tt>.
4586         </p>
4587
4588         <p>       
4589           <var>version-or-soname</var> is the soname of the library -
4590           ie, the thing that must exactly match for the library to be
4591           recognised by <prgn>ld.so</prgn>.  Usually this is major
4592           version number of the library.
4593         </p>
4594
4595         <p>       
4596           <var>dependencies</var> has the same syntax as a dependency
4597           field in a binary package control file.  It should give
4598           details of which package(s) are required to satisfy a binary
4599           built against the version of the library contained in the
4600           package.  See <ref id="depsyntax">.
4601         </p>
4602
4603         <p>       
4604           For example, if the package <tt>foo</tt> contains
4605           <tt>libfoo.so.1.2.3</tt>, where the soname of the library is
4606           <tt>libfoo.so.1</tt>, and the first version of the package
4607           which contained a minor number of at least <tt>2.3</tt> was
4608           <var>1.2.3-1</var>, then the package's <var>shlibs</var>
4609           could say:
4610           <example>
4611   libfoo 1      foo (>= 1.2.3-1)
4612           </example>
4613         </p>
4614
4615         <p>       
4616           The version-specific dependency is to avoid warnings from
4617           <prgn>ld.so</prgn> about using older shared libraries with
4618           newer binaries.</p>
4619       </sect>
4620         
4621       <sect><heading>Further Technical information on
4622           <tt>shlibs</tt></heading>
4623
4624         
4625         <!-- 
4626         following section mostly provided by Heiko Schlittermann
4627         edited by DMorris
4628         -->
4629         
4630         <sect1><heading><em>What</em> are the <tt>shlibs</tt> files?
4631           </heading>
4632
4633           <p>       
4634             The <tt>debian/shlibs</tt> file provides a way of checking
4635             for shared library dependencies on packaged binaries.
4636             They are intended to be used by package maintainers to
4637             make their lives easier.
4638           </p>
4639
4640           <p>       
4641             Other <tt>shlibs</tt> files that exist on a Debian system are
4642             <list>
4643               <item> <p><tt>/etc/dpkg/shlibs.default</tt></p></item>
4644               <item> <p><tt>/etc/dpkg/shlibs.override</tt></p></item>
4645               <item> <p><tt>/var/lib/dpkg/info/*.shlibs</tt></p></item>
4646               <item> <p><tt>debian/shlibs.local</tt></p></item>
4647             </list> 
4648             These files are used by <prgn>dpkg-shlibdeps</prgn> when
4649             creating a binary package.</p>
4650         </sect1>
4651           
4652         <sect1><heading><em>How</em> does <prgn>dpkg-shlibdeps</prgn>
4653         work?
4654           </heading>
4655           <p>       
4656             <prgn>dpkg-shlibdeps</prgn> calls <prgn>objdump</prgn> to
4657            determine the shared libraries directly
4658            <footnote> a binary <tt>foo</tt> directly use a library
4659            <tt>libbar</tt> if it is linked with that library. Other
4660            libraries that are needed by <tt>libbar</tt> are linked
4661            indirectly to <tt>foo</tt>, and the dynamic linker will load
4662            the automatically when it loads <tt>libbar</tt>.
4663            </footnote> used by the compiled binaries and libraries
4664            passed through its command line.
4665           </p>
4666
4667           <p>       
4668             For each shared library, <prgn>dpkg-shlibdeps</prgn> needs to know 
4669             <list compact="compact">
4670               <item><p>the package containing the library, and</p></item>
4671               <item><p>the library version number,</p></item>
4672
4673             </list>       <p>
4674             it scans the following files in this order.
4675             <enumlist compact="compact">
4676               <item><p><tt>debian/shlibs.local</tt></p></item>
4677               <item><p><tt>/etc/dpkg/shlibs.override</tt></p></item>
4678               <item><p><tt>/var/lib/dpkg/info/*.shlibs</tt></p></item>
4679               <item><p><tt>/etc/dpkg/shlibs.default</tt></p></item>
4680             </enumlist></p>
4681         </sect1>
4682           
4683         <sect1><heading><em>Who</em> maintains the various
4684         <tt>shlibs</tt> files?
4685           </heading>
4686
4687           <p>       
4688             <list compact="compact">
4689               <item>
4690                 <p><tt>/etc/dpkg/shlibs.default</tt> - the maintainer
4691                   of dpkg</p>
4692               </item>
4693               <item>
4694                 <p>
4695                   <tt>/var/lib/dpkg/info/<var>package</var>.shlibs</tt>
4696                   - the maintainer of each package</p>
4697               </item>
4698               <item>
4699                 <p>
4700                   <tt>/etc/dpkg/shlibs.override</tt> - the local
4701                   system administrator</p>
4702               </item>
4703               <item>
4704                 <p><tt>debian/shlibs.local</tt> - the maintainer of
4705                 the package
4706                 </p>
4707               </item> 
4708             </list> 
4709             The <tt>shlibs.default</tt> file is managed by
4710             <prgn>dpkg</prgn>. The entries in <tt>shlibs.default</tt>
4711             that are provided by <prgn>dpkg</prgn> are just there to
4712             fix things until the shared library packages all have
4713             <tt>shlibs</tt> files.
4714           </p>
4715         </sect1>
4716
4717         <sect1><heading><em>How</em> to use <prgn>dpkg-shlibdeps</prgn> and
4718             the <tt>shlibs</tt> files?
4719           </heading>
4720             
4721           <sect2><heading>If your package doesn't provide a shared
4722           library
4723             </heading>
4724
4725             <p>       
4726               Put a call to <prgn>dpkg-shlibdeps</prgn> into your
4727               <tt>debian/rules</tt> file.  If your package contains
4728               only binaries (e.g. no scripts) use:
4729               <example>
4730   dpkg-shlibdeps debian/tmp/usr/bin/* debian/tmp/usr/sbin/*
4731               </example>
4732               If <prgn>dpkg-shlibdeps</prgn> doesn't complain, you're
4733               done. If it does complain you might need to create your
4734               own <tt>debian/shlibs.local</tt> file.</p>
4735           </sect2>
4736
4737           <sect2><heading>If your package provides a shared library
4738             </heading>
4739
4740             <p>       
4741               Create a <tt>debian/shlibs</tt> file and let
4742               <tt>debian/rules</tt> install it in the control area:           
4743               <example>
4744   install -m644 debian/shlibs debian/tmp/DEBIAN
4745               </example>
4746               If your package contains additional binaries see above.
4747             </p>
4748           </sect2>
4749         </sect1>
4750
4751         <sect1><heading><em>How</em> to write
4752         <tt>debian/shlibs.local</tt>
4753           </heading>
4754
4755           <p>       
4756             This file is intended only as a <em>temporary</em> fix if
4757             your binaries depend on a library which doesn't provide
4758             its own <tt>/var/lib/dpkg/info/*.shlibs</tt> file yet.
4759           </p>
4760
4761           <p>       
4762             Let's assume you are packaging a binary <tt>foo</tt>. Your
4763             output in building the package might look like this.            
4764             <example>
4765   $ ldd foo
4766   libbar.so.1 => /usr/X11R6/lib/libbar.so.1.0
4767   libc.so.5 => /lib/libc.so.5.2.18
4768   libX11.so.6 => /usr/X11R6/lib/libX11.so.6.0
4769             </example>
4770             And when you ran <prgn>dpkg-shlibdeps</prgn>
4771             <example>
4772   $ dpkg-shlibdeps -o foo
4773   dpkg-shlibdeps: warning: unable to find dependency information 
4774   for shared library libbar 
4775   (soname 1, path /usr/X11R6/lib/libbar.so.1.0, dependency field Depends)
4776   shlibs:Depends=elf-x11r6lib, libc5 (>= 5.2.18)
4777             </example>
4778             The <prgn>foo</prgn> binary depends on the
4779             <prgn>libbar</prgn> shared library, but no package seems
4780             to provide a <tt>*.shlibs</tt> file in
4781             <tt></tt>var/lib/dpkg/info/.  Let's determine the package
4782             responsible:
4783           </p>
4784
4785           <p>
4786             <example>
4787   $ dpkg -S /usr/X11R6/lib/libbar.so.1.0
4788   bar1: /usr/X11R6/lib/libbar.so.1.0
4789   $ dpkg -s bar1 | grep Version
4790   Version: 1.0-1
4791             </example>
4792             This tells us that the <prgn>bar1</prgn> package, version
4793             1.0-1 is the one we are using. Now we can create our own
4794             <tt>debian/shlibs.local</tt> to temporarly fix the above
4795             problem. Include the following line into your
4796             <tt>debian/shlibs.local</tt> file.
4797             <example>
4798   libbar 1 bar1 (>= 1.0-1)
4799             </example>
4800             Now your package build should work. As soon as the
4801             maintainer of <prgn>libbar1</prgn> provides a
4802             <tt>shlibs</tt> file, you can remove your
4803             <tt>debian/shlibs.local</tt> file.
4804           </p>
4805         </sect1>
4806       </sect>
4807     </chapt>
4808
4809     <chapt id="methif"><heading><prgn>dselect</prgn>'s interface to
4810     its installation methods
4811       </heading>
4812
4813       <p>       
4814         <prgn>dselect</prgn> calls scripts from its installation
4815         methods when it needs to actually access data from the
4816         distribution.  The core program <prgn>dselect</prgn> itself
4817         just calls these scripts and provides the package and access
4818         method selection interfaces.  The installation methods are
4819         responsible for invoking <prgn>dpkg</prgn> as appropriate.
4820       </p>
4821
4822       <p>       
4823         Each installation method has three scripts:
4824         <list compact="compact">
4825           <item><p>Setup installation parameters.</p></item>
4826           <item><p>Update list of available packages.</p></item>
4827           <item><p>Install.</p></item>
4828         </list>
4829
4830       <p>       
4831         <prgn>dselect</prgn> searches for methods in
4832         <tt>/usr/lib/dpkg/methods</tt> and
4833         <tt>/usr/local/lib/dpkg/methods</tt>.
4834       </p>
4835         
4836       <sect><heading>Functions of the method scripts
4837         </heading>
4838
4839         <p>       
4840           The setup script is run just after the user has chosen an
4841           installation method.  It should prompt the user for
4842           parameters like the site to NFS-mount or FTP from, the
4843           directory to use, or the directory or filesystem where the
4844           <tt>.deb</tt> files can be found, or the tape or floppy
4845           device to install from.  It should store the responses under
4846           <tt>/var/lib/dpkg/methods</tt> - see below.  If no available
4847           packages list is available it should perhaps offer to scan
4848           the available packages.
4849         </p>
4850
4851         <p>       
4852           The update script should obtain a list of available packages
4853           if possible, and run <tt>dpkg --update-avail</tt>, <tt>dpkg
4854           --merge-avail</tt> and/or <tt>dpkg --forget-old-unavail</tt>
4855           to load it into <prgn>dpkg</prgn> and <prgn>dselect</prgn>'s
4856           database of available packages.  If no packages list was
4857           available and the user was offered and accepted the option
4858           of scanning the actual files available this scan should be
4859           done here, using <tt>dpkg --record-avail</tt>.
4860         </p>
4861
4862         <p>       
4863           The install script should feed all the available
4864           <tt>.deb</tt> files to <tt>dpkg --iGOEB</tt> (this is
4865           equivalent to <tt>dpkg --install
4866             --refuse-downgrade --selected-only --skip-same-version
4867             --auto-deconfigure</tt>).  The <tt>-R</tt>
4868           (<tt>--recursive</tt>) option for traversing subdirectories
4869           may also be useful here).
4870         </p>
4871
4872         <p>       
4873           If any of these scripts needs to display a message for the
4874           user, it should wait for the user to hit `return' before
4875           exiting so that dselect doesn't immediately rewrite the
4876           screen.
4877         </p>
4878
4879         <p>       
4880           If a method script succeeds (returns a zero exit status)
4881           <prgn>dselect</prgn> will return immediately to the main
4882           menu, with the `next' option highlighted ready for the user
4883           to select it.  If it fails <prgn>dselect</prgn> will display
4884           a message and wait for the user to hit return.</p>
4885       </sect>
4886         
4887       <sect><heading>Location and arguments of the method scripts
4888         </heading>
4889
4890         <p>       
4891           A set of scripts (henceforth known as a group) may provide
4892           several methods on the `main menu' with different behaviour.
4893           For example, there might be a generic get-packages-by-FTP
4894           group which might provide methods in the main menu for
4895           installation directly from one of the Debian mirror sites as
4896           well as for installation from a user-specified site.
4897         </p>
4898
4899         <p>       
4900           Each group of methods implemented by the same set of scripts
4901           should have a subdirectory
4902           <tt>/usr/lib/dpkg/methods/<var>group</var></tt> or
4903           <tt>/usr/local/lib/dpkg/methods/<var>group</var></tt>,
4904           containing:
4905           <taglist compact="compact">
4906             <tag><tt>names</tt></tag>
4907             <item><p>a list of user-visible methods provided by these scripts.</p>
4908             </item>
4909             <tag><tt>setup</tt></tag>
4910             <tag><tt>update</tt></tag>
4911             <tag><tt>install</tt></tag>
4912             <item><p>executable programs, the scripts themselves.</p>
4913             </item>
4914             <tag><tt>desc.<var>option</var></tt></tag>
4915             <item><p>description file.</p></item>
4916           </taglist>
4917         </p>
4918
4919         <p>       
4920           <tt>names</tt> will be formatted as a list of lines, each containing:
4921           <example>
4922  <var>sequence</var> <var>method</var> <var>summary</var>
4923           </example>
4924         </p>
4925         <p>       
4926           <var>sequence</var> is a two-digit number that will be used
4927           much like <tt>rc.d</tt> prefixes to control the order in the
4928           main menu.  If in doubt use 50.
4929         </p>
4930
4931         <p>       
4932           <var>method</var> is a name which is displayed by
4933           <prgn>dselect</prgn> as the name of the method, and which
4934           will be passed to <tt>setup</tt>, <tt>update</tt> and
4935           <tt>unpack</tt> as their first argument.
4936         </p>
4937
4938         <p>       
4939           <var>summary</var> is the brief description string for
4940           <prgn>dselect</prgn>'s menu.
4941         </p>
4942
4943         <p>       
4944           Each of the three scripts gets the same three arguments:
4945           <var>vardir</var>, <var>group</var> and <var>method</var>.
4946           <var>vardir</var> is the base directory for storing
4947           <prgn>dpkg</prgn> and <prgn>dselect</prgn>'s state, usually
4948           <tt>/var/lib/dpkg</tt>; this is passed in so that the
4949           <tt>--admindir</tt> option to <prgn>dselect</prgn> is
4950           honoured).
4951         </p>
4952
4953         <p>       
4954           Each option may have an extended description in
4955           <tt>desc.<var>option</var></tt>.  This should be formatted
4956           like the extended description part of a <tt>Description</tt>
4957           field entry <em>shifted one character to the left</em>.
4958         </p>
4959
4960         <p>       
4961           <tt><var>vardir</var>/methods</tt> will exist, and a method
4962           group may use a
4963           <tt><var>vardir</var>/methods/<var>group</var></tt>
4964           directory to store its state.
4965         </p>
4966
4967         <p>       
4968           The group name and method name must follow the rules for C
4969           identifiers.
4970         </p>
4971       </sect>
4972     </chapt>
4973       
4974     <chapt id="conversion"><heading>Conversion procedure from old
4975     source packages
4976       </heading>
4977
4978       <p>       
4979         This is a brief summary of the procedure for converting a
4980         pre-2.0.0.0-format source package into the new format.
4981       </p>
4982
4983       <p>       
4984         You are strongly advised to download and examine the <prgn>hello</prgn>
4985         package, and to read the section in the <prgn>dpkg</prgn> programmers'
4986         manual describing the source packaging tools.  More detail about the
4987         exact functionality of these tools is available in 
4988         <manref name="dpkg-source"  section="1">.
4989       </p>
4990
4991       <p>       
4992         <list>
4993           <item>
4994             <p>
4995               Download the original source code from wherever it can
4996               be found and do any rearrangement required to make it
4997               look like the original tree of the Debian source.  Put
4998               it in
4999               <tt><var>package</var>-<var>upstream-version</var>.orig/</tt>
5000               or
5001               <tt><var>package</var>_<var>upstream-version</var>.orig.tar.gz</tt>.
5002             </p>
5003           </item>
5004           
5005           <item>
5006             <p>
5007               Rename all files <tt>debian.*</tt> to <tt>debian/*</tt>.
5008               There may be some exceptions to this, but this is a good
5009               start.</p>
5010           </item>
5011
5012           <item>
5013             <p>
5014               Edit the <tt>debian/changelog</tt> - create or rename it
5015               if necessary.  Add a new revision to the top with the
5016               appropriate details, and a local variables entry to the
5017               bottom to set Emacs to the right mode:
5018               <example>
5019   Local variables:
5020   mode: debian-changelog
5021   End:
5022               </example>
5023             </p>
5024           </item>
5025           
5026           <item>
5027             <p>
5028               Edit/create <tt>debian/control</tt>:
5029               <list compact="compact">
5030                 <item>
5031                   <p>
5032                     Remove the <tt>Version</tt> field.  If it is
5033                     generated unusually (not equal to the source
5034                     version) you must use the -v option to
5035                     dpkg-gencontrol (see below).  <tt>Section</tt>,
5036                     <tt>Priority</tt>, <tt>Maintainer</tt> go above
5037                     the first blank line, most of the rest
5038                     below.
5039                   </p>
5040                 </item>
5041                 
5042                 <item>
5043                   <p>
5044                     Reorder the fields and add a blank line at an
5045                     appropriate point, separating the source package
5046                     fields from the binary package fields.
5047                   </p>
5048                 </item>
5049                 
5050                 <item>
5051                   <p>Add the <tt>Source</tt> field.</p></item>
5052                 
5053                 <item>
5054                   <p>
5055                     Add the <tt>Standards-Version</tt> field.  (Please
5056                     check out the Debian Policy Manual for details
5057                     about this field.)</p>
5058                 </item>
5059                 
5060                 <item>
5061                   <p>
5062                     Change the <tt>Architecture</tt> field for each
5063                     package to <tt>any</tt>, <tt>all</tt> or whatever.
5064                     If there isn't an <tt>Architecture</tt> field add
5065                     one.</p>
5066                 </item>
5067                 
5068                 <item>
5069                   <p>
5070                     If any other use of sed or things used to happen
5071                     to make the binary control files use
5072                     <prgn>dpkg-gencontrol</prgn>'s variable
5073                     substitution features to achieve the same effect.
5074                     Use <tt>debian/substvars</tt> if you need to put
5075                     unusally-generated information (apart from details
5076                     of <tt>.deb</tt> files) in the <tt>.changes</tt>
5077                     file too.</p>
5078                 </item>
5079               </list>
5080             </p>
5081           </item>
5082           
5083           <item>
5084             <p>Edit the <tt>debian/rules</tt>:
5085               <list compact="compact">
5086                 <item>
5087                   <p>
5088                     Remove the <prgn>source</prgn> and
5089                     <prgn>diff</prgn> and any <prgn>changes</prgn> and
5090                     <prgn>dist</prgn> targets.  These things now
5091                     happen in a package-independent way and are not
5092                     done by <tt>debian/rules</tt>.</p>
5093                 </item>
5094                 <item>
5095                   <p>
5096                     Split the <prgn>binary</prgn> target into
5097                     <prgn>binary-arch</prgn> and
5098                     <prgn>binary-indep</prgn>; in many cases all of
5099                     <prgn>binary</prgn> should go into
5100                     <prgn>binary-arch</prgn>.  Create the
5101                     <prgn>binary</prgn> target and the unused of the
5102                     two other <prgn>binary-*</prgn> targets if there
5103                     is one - you can copy the ones from the
5104                     <prgn>hello</prgn> package.</p>
5105                 </item>
5106                 <item>
5107                   <p>
5108                     Change the <prgn>binary</prgn> target to use
5109                     <prgn>dpkg-gencontrol</prgn> to make the package
5110                     control file(s).  Move it to after all the files
5111                     have been installed but just before the last
5112                     <prgn>chown</prgn> and <prgn>chmod</prgn> in the
5113                     target.</p>
5114                 </item>
5115                 <item>
5116                   <p>
5117                     Change occurrences of <tt>debian-tmp</tt> to
5118                     <tt>debian/tmp</tt>.</p>
5119                 </item>
5120                 <item>
5121                   <p>
5122                     Change occurrences of
5123                     <tt>debian.{post,pre}{inst,rm}</tt> to
5124                     <tt>debian/*</tt>.</p>
5125                 </item>
5126                 <item>
5127                   <p>
5128                     Remove the version number setting at the top, if
5129                     there is one.</p>
5130                 </item>
5131                 <item>
5132                   <p>
5133                     Ensure that the package's Debian-specific and
5134                     upstream changelogs are installed.</p>
5135                 </item>
5136               </list>
5137             </p>
5138           </item>
5139           
5140           <item>
5141             <p>
5142               Change the package to use <prgn>dpkg-shlibdeps</prgn> to
5143               determine its shared library dependencies and substitute
5144               them in.  Shared library dependencies should no longer
5145               be hardwired in the source package.</p>
5146           </item>
5147           
5148           <item>
5149             <p>
5150               Check that the <tt>debian/README</tt> is really the
5151               copyright file, and if so rename it to
5152               <tt>debian/copyright</tt> and edit <tt>debian/rules</tt>
5153               to cope with this and to change the installation of the
5154               copyright file from
5155               <tt>/usr/doc/<var>package</var>/copyright</tt> to
5156               <tt>/usr/doc/copyright/<var>package</var></tt>.  If it
5157               isn't then find <tt>debian/copyright</tt> and decide
5158               what to do with the <tt>README</tt>.</p>
5159           </item>
5160           
5161           <item>
5162             <p>Check for various other anachronisms and problems:
5163               <list compact="compact">
5164                 <item>
5165                   <p>
5166                     Remove any <tt>Package_Revision</tt>,
5167                     <tt>Package-Revision</tt> or <tt>Revision</tt>
5168                     fields.</p>
5169                 </item>
5170                 <item>
5171                   <p>
5172                     Rename <tt>Optional</tt> to <tt>Suggests</tt>,
5173                     <tt>Recommended</tt> to
5174                     <tt>Recommends</tt>.</p>
5175                 </item>
5176                 <item>
5177                   <p>
5178                     Change
5179                     <tt>/usr/doc/examples/<var>package</var></tt> to
5180                     <tt>/usr/doc/<var>package</var>/examples</tt>.</p>
5181                 </item>
5182                 <item>
5183                   <p>
5184                     Make sure that manpages are installed
5185                     compressed.</p>
5186                 </item>
5187                 <item>
5188                   <p>
5189                     Check that the description has an extended
5190                     description, is well-formatted and meaningful and
5191                     helpful to people wanting to know whether to
5192                     install a package.</p>
5193                 </item>
5194               </list>
5195             </p>
5196           </item>
5197           
5198           <item>
5199             <p>Look everything over.</p></item>
5200           
5201           <item>
5202             <p>
5203               Do a test build using <tt>dpkg-buildpackage -us -uc -sa
5204                 -r<var>whatever</var></tt>.  Check the permissions and
5205               locations of files in the resulting package by examining
5206               the output of <tt>dpkg-deb --contents</tt>, and check
5207               that the source build happened OK.  Test install the
5208               binary package(s) and test extract the source
5209               package(s).</p>
5210           </item>
5211           
5212           <item>
5213             <p>
5214               Sign the release: either rebuild everything with
5215               <tt>dpkg-buildpackage -sa</tt>, or PGP-sign the
5216               <tt>.dsc</tt>, rebuild the <tt>.changes</tt> using
5217               <tt>dpkg-genchanges -sa</tt>, and then PGP-sign the
5218               <tt>.changes</tt>.</p>
5219           </item>
5220           
5221         </list>
5222       </p>
5223
5224       <p>       
5225         The use of <tt>-sa</tt> on <prgn>dpkg-buildpackage</prgn> and
5226         <prgn>dpkg-genchanges</prgn> is important when doing the first
5227         build/uploading of a new-format source package.  Unless this
5228         happens to be Debian revision <tt>0</tt> or <tt>1</tt> by
5229         default the original source tarfile will not be included in
5230         the uploaded files listed in the <tt>.changes</tt> file, and
5231         so it won't be installed on the FTP site.  <tt>-sa</tt>
5232         requests that the original source be included
5233         regardless.</p>
5234     </chapt>
5235     
5236   </book>
5237 </debiandoc>