]> git.donarmstrong.com Git - debian/debian-policy.git/blob - policy.sgml
Tweak the wording of mailbox permissions further
[debian/debian-policy.git] / policy.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 <debiandoc>
7
8   <book>
9     <titlepag>
10       <title>Debian Policy Manual</title>
11       <author><qref id="authors">The Debian Policy Mailing List</qref></author>
12       <version>version &version;, &date;</version>
13
14       <abstract>
15         This manual describes the policy requirements for the Debian
16         GNU/Linux distribution.  This includes the structure and
17         contents of the Debian archive and several design issues of
18         the operating system, as well as technical requirements that
19         each package must satisfy to be included in the distribution.
20       </abstract>
21
22       <copyright>
23         <copyrightsummary>
24           Copyright &copy; 1996,1997,1998 Ian Jackson
25           and Christian Schwarz.
26         </copyrightsummary>
27         <p>
28           This manual is free software; you may redistribute it and/or
29           modify it under the terms of the GNU General Public License
30           as published by the Free Software Foundation; either version
31           2, or (at your option) any later version.
32         </p>
33
34         <p>
35           This is distributed in the hope that it will be useful, but
36           <em>without any warranty</em>; without even the implied
37           warranty of merchantability or fitness for a particular
38           purpose.  See the GNU General Public License for more
39           details.
40         </p>
41
42         <p>
43           A copy of the GNU General Public License is available as
44           <file>/usr/share/common-licenses/GPL</file> in the Debian GNU/Linux
45           distribution or on the World Wide Web at
46           <url id="http://www.gnu.org/copyleft/gpl.html"
47                name="the GNU General Public Licence">. You can also
48           obtain it by writing to the Free Software Foundation, Inc.,
49           51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
50         </p>
51       </copyright>
52     </titlepag>
53
54     <toc detail="sect1">
55
56     <chapt id="scope">
57       <heading>About this manual</heading>
58       <sect>
59         <heading>Scope</heading>
60         <p>
61           This manual describes the policy requirements for the Debian
62           GNU/Linux distribution. This includes the structure and
63           contents of the Debian archive and several design issues of the
64           operating system, as well as technical requirements that
65           each package must satisfy to be included in the
66           distribution.
67         </p>
68
69         <p>
70           This manual also describes Debian policy as it relates to
71           creating Debian packages. It is not a tutorial on how to build
72           packages, nor is it exhaustive where it comes to describing
73           the behavior of the packaging system. Instead, this manual
74           attempts to define the interface to the package management
75           system that the developers have to be conversant with.<footnote>
76               Informally, the criteria used for inclusion is that the
77               material meet one of the following requirements:
78               <taglist compact="compact">
79                 <tag>Standard interfaces</tag>
80                 <item>
81                     The material presented represents an interface to
82                     the packaging system that is mandated for use, and
83                     is used by, a significant number of packages, and
84                     therefore should not be changed without peer
85                     review. Package maintainers can then rely on this
86                     interfaces not changing, and the package
87                     management software authors need to ensure
88                     compatibility with these interface
89                     definitions. (Control file and changelog file
90                     formats are examples.)
91                 </item>
92                 <tag>Chosen Convention</tag>
93                 <item>
94                     If there are a number of technically viable choices
95                     that can be made, but one needs to select one of
96                     these options for inter-operability. The version
97                     number format is one example.
98                 </item>
99               </taglist>
100               Please note that these are not mutually exclusive;
101               selected conventions often become parts of standard
102               interfaces.
103           </footnote>
104         </p>
105
106         <p>
107           The footnotes present in this manual are
108           merely informative, and are not part of Debian policy itself.
109         </p>
110
111         <p>
112           The appendices to this manual are not necessarily normative,
113           either. Please see <ref id="pkg-scope"> for more information.
114         </p>
115
116         <p>
117           In the normative part of this manual,
118           the words <em>must</em>, <em>should</em> and
119           <em>may</em>, and the adjectives <em>required</em>,
120           <em>recommended</em> and <em>optional</em>, are used to
121           distinguish the significance of the various guidelines in
122           this policy document. Packages that do not conform to the
123           guidelines denoted by <em>must</em> (or <em>required</em>)
124           will generally not be considered acceptable for the Debian
125           distribution. Non-conformance with guidelines denoted by
126           <em>should</em> (or <em>recommended</em>) will generally be
127           considered a bug, but will not necessarily render a package
128           unsuitable for distribution. Guidelines denoted by
129           <em>may</em> (or <em>optional</em>) are truly optional and
130           adherence is left to the maintainer's discretion.
131         </p>
132
133         <p>
134           These classifications are roughly equivalent to the bug
135           severities <em>serious</em> (for <em>must</em> or
136           <em>required</em> directive violations), <em>minor</em>,
137           <em>normal</em> or <em>important</em>
138           (for <em>should</em> or <em>recommended</em> directive
139           violations) and <em>wishlist</em> (for <em>optional</em>
140           items).
141           <footnote>
142                 Compare RFC 2119.  Note, however, that these words are
143                 used in a different way in this document.
144           </footnote>
145         </p>
146
147         <p>
148           Much of the information presented in this manual will be
149           useful even when building a package which is to be
150           distributed in some other way or is intended for local use
151           only.
152         </p>
153       </sect>
154
155       <sect>
156         <heading>New versions of this document</heading>
157
158         <p>
159           This manual is distributed via the Debian package
160           <package><url name="debian-policy"
161               id="http://packages.debian.org/debian-policy"></package> 
162           (<httpsite>packages.debian.org</httpsite> 
163           <httppath>/debian-policy</httppath>).
164         </p>
165
166         <p>
167           The current version of this document is also available from
168           the Debian web mirrors at
169           <tt><url name="/doc/debian-policy/"
170                 id="http://www.debian.org/doc/debian-policy/"></tt>.
171           (
172           <httpsite>www.debian.org</httpsite>
173           <httppath>/doc/debian-policy/</httppath>)
174           Also available from the same directory are several other
175           formats: <file>policy.html.tar.gz</file>
176           (<httppath>/doc/debian-policy/policy.html.tar.gz</httppath>),
177           <file>policy.pdf.gz</file> 
178           (<httppath>/doc/debian-policy/policy.pdf.gz</httppath>)
179           and <file>policy.ps.gz</file>
180           (<httppath>/doc/debian-policy/policy.ps.gz</httppath>).
181         </p>
182
183         <p>
184           The <package>debian-policy</package> package also includes the file
185           <file>upgrading-checklist.txt.gz</file> which indicates policy
186           changes between versions of this document.
187         </p>
188       </sect>
189
190       <sect id="authors">
191         <heading>Authors and Maintainers</heading>
192
193         <p>
194           Originally called "Debian GNU/Linux Policy Manual", this
195           manual was initially written in 1996 by Ian Jackson.
196           It was revised on November 27th, 1996 by David A. Morris.
197           Christian Schwarz added new sections on March 15th, 1997,
198           and reworked/restructured it in April-July 1997.
199           Christoph Lameter contributed the "Web Standard".
200           Julian Gilbey largely restructured it in 2001.
201         </p>
202
203         <p>
204           Since September 1998, the responsibility for the contents of
205           this document lies on the <url name="debian-policy mailing list"
206           id="mailto:debian-policy@lists.debian.org">. Proposals
207           are discussed there and inserted into policy after a certain
208           consensus is established.
209           <!-- insert shameless policy-process plug here eventually -->
210           The actual editing is done by a group of maintainers that have
211           no editorial powers. These are the current maintainers:
212
213           <enumlist>
214             <item>Julian Gilbey</item>
215             <item>Branden Robinson</item>
216             <item>Josip Rodin</item>
217             <item>Manoj Srivastava</item>
218           </enumlist>
219         </p>
220
221         <p>
222           While the authors of this document have tried hard to avoid
223           typos and other errors, these do still occur. If you discover
224           an error in this manual or if you want to give any
225           comments, suggestions, or criticisms please send an email to
226           the Debian Policy List,
227           <email>debian-policy@lists.debian.org</email>, or submit a
228           bug report against the <tt>debian-policy</tt> package.
229         </p>
230
231         <p>
232           Please do not try to reach the individual authors or maintainers
233           of the Policy Manual regarding changes to the Policy.
234         </p>
235       </sect>
236
237       <sect id="related">
238         <heading>Related documents</heading>
239
240         <p>
241           There are several other documents other than this Policy Manual
242           that are necessary to fully understand some Debian policies and
243           procedures.
244         </p>
245
246         <p>
247           The external "sub-policy" documents are referred to in:
248           <list compact="compact">
249             <item><ref id="fhs"></item>
250             <item><ref id="virtual_pkg"></item>
251             <item><ref id="menus"></item>
252             <item><ref id="mime"></item>
253             <item><ref id="perl"></item>
254             <item><ref id="maintscriptprompt"></item>
255             <item><ref id="emacs"></item>
256           </list>
257         </p>
258
259         <p>
260           In addition to those, which carry the weight of policy, there
261           is the Debian Developer's Reference. This document describes
262           procedures and resources for Debian developers, but it is
263           <em>not</em> normative; rather, it includes things that don't
264           belong in the Policy, such as best practices for developers.
265         </p>
266
267         <p>
268           The Developer's Reference is available in the
269           <package>developers-reference</package> package.
270           It's also available from the Debian web mirrors at
271           <tt><url name="/doc/developers-reference/"
272                 id="http://www.debian.org/doc/developers-reference/"></tt>.
273         </p>
274       </sect>
275
276       <sect id="definitions">
277         <heading>Definitions</heading>
278
279         <p>
280           The following terms are used in this Policy Manual:
281           <taglist>
282             <tag>ASCII</tag>
283             <item>
284               The character encoding specified by ANSI X3.4-1986 and its
285               predecessor standards, referred to in MIME as US-ASCII, and
286               corresponding to an encoding in eight bits per character of
287               the first 128 <url id="http://www.unicode.org/"
288               name="Unicode"> characters, with the eighth bit always zero.
289             </item>
290             <tag>UTF-8</tag>
291             <item>
292               The transformation format (sometimes called encoding) of
293               <url id="http://www.unicode.org/" name="Unicode"> defined by
294               <url id="http://www.rfc-editor.org/rfc/rfc3629.txt"
295               name="RFC 3629">.  UTF-8 has the useful property of having
296               ASCII as a subset, so any text encoded in ASCII is trivially
297               also valid UTF-8.
298             </item>
299           </taglist>
300         </p>
301       </sect>
302     </chapt>
303
304
305     <chapt id="archive">
306       <heading>The Debian Archive</heading>
307
308       <p>
309         The Debian GNU/Linux system is maintained and distributed as a
310         collection of <em>packages</em>. Since there are so many of
311         them (currently well over 15000), they are split into
312         <em>sections</em> and given <em>priorities</em> to simplify
313         the handling of them.
314       </p>
315
316       <p>
317         The effort of the Debian project is to build a free operating
318         system, but not every package we want to make accessible is
319         <em>free</em> in our sense (see the Debian Free Software
320         Guidelines, below), or may be imported/exported without
321         restrictions. Thus, the archive is split into the distribution
322         areas or categories based on their licenses and other restrictions.
323       </p>
324
325       <p>
326         The aims of this are:
327
328         <list compact="compact">
329           <item>to allow us to make as much software available as we can</item>
330           <item>to allow us to encourage everyone to write free software,
331                 and</item>
332           <item>to allow us to make it easy for people to produce
333                 CD-ROMs of our system without violating any licenses,
334                 import/export restrictions, or any other laws.</item>
335         </list>
336       </p>
337
338       <p>
339         The <em>main</em> category  forms the
340         <em>Debian GNU/Linux distribution</em>.
341       </p>
342
343       <p>
344         Packages in the other distribution areas (<tt>contrib</tt>,
345         <tt>non-free</tt>) are not considered to be part of the Debian
346         distribution, although we support their use and provide
347         infrastructure for them (such as our bug-tracking system and
348         mailing lists). This Debian Policy Manual applies to these
349         packages as well.
350       </p>
351
352       <sect id="dfsg">
353         <heading>The Debian Free Software Guidelines</heading>
354         <p>
355           The Debian Free Software Guidelines (DFSG) form our
356           definition of "free software".  These are:
357             <taglist>
358               <tag>Free Redistribution
359               </tag>
360               <item>
361                   The license of a Debian component may not restrict any
362                   party from selling or giving away the software as a
363                   component of an aggregate software distribution
364                   containing programs from several different
365                   sources. The license may not require a royalty or
366                   other fee for such sale.
367               </item>
368               <tag>Source Code
369               </tag>
370               <item>
371                   The program must include source code, and must allow
372                   distribution in source code as well as compiled form.
373               </item>
374               <tag>Derived Works
375               </tag>
376               <item>
377                   The license must allow modifications and derived
378                   works, and must allow them to be distributed under the
379                   same terms as the license of the original software.
380               </item>
381               <tag>Integrity of The Author's Source Code
382               </tag>
383               <item>
384                   The license may restrict source-code from being
385                   distributed in modified form <em>only</em> if the
386                   license allows the distribution of "patch files"
387                   with the source code for the purpose of modifying the
388                   program at build time. The license must explicitly
389                   permit distribution of software built from modified
390                   source code. The license may require derived works to
391                   carry a different name or version number from the
392                   original software.  (This is a compromise. The Debian
393                   Project encourages all authors to not restrict any
394                   files, source or binary, from being modified.)
395               </item>
396               <tag>No Discrimination Against Persons or Groups
397               </tag>
398               <item>
399                   The license must not discriminate against any person
400                   or group of persons.
401               </item>
402               <tag>No Discrimination Against Fields of Endeavor
403               </tag>
404               <item>
405                   The license must not restrict anyone from making use
406                   of the program in a specific field of endeavor. For
407                   example, it may not restrict the program from being
408                   used in a business, or from being used for genetic
409                   research.
410               </item>
411               <tag>Distribution of License
412               </tag>
413               <item>
414                   The rights attached to the program must apply to all
415                   to whom the program is redistributed without the need
416                   for execution of an additional license by those
417                   parties.
418               </item>
419               <tag>License Must Not Be Specific to Debian
420               </tag>
421               <item>
422                   The rights attached to the program must not depend on
423                   the program's being part of a Debian system. If the
424                   program is extracted from Debian and used or
425                   distributed without Debian but otherwise within the
426                   terms of the program's license, all parties to whom
427                   the program is redistributed must have the same
428                   rights as those that are granted in conjunction with
429                   the Debian system.
430               </item>
431               <tag>License Must Not Contaminate Other Software
432               </tag>
433               <item>
434                   The license must not place restrictions on other
435                   software that is distributed along with the licensed
436                   software. For example, the license must not insist
437                   that all other programs distributed on the same medium
438                   must be free software.
439               </item>
440               <tag>Example Licenses
441               </tag>
442               <item>
443                   The "GPL," "BSD," and "Artistic" licenses are examples of
444                   licenses that we consider <em>free</em>.
445               </item>
446             </taglist>
447         </p>
448       </sect>
449
450       <sect id="sections">
451         <heading>Categories</heading>
452
453         <sect1 id="main">
454           <heading>The main category</heading>
455
456           <p>
457             Every package in <em>main</em> must comply with the DFSG
458             (Debian Free Software Guidelines).
459           </p>
460
461           <p>
462             In addition, the packages in <em>main</em>
463             <list compact="compact">
464               <item>
465                   must not require a package outside of <em>main</em>
466                   for compilation or execution (thus, the package must
467                   not declare a "Depends", "Recommends", or
468                   "Build-Depends" relationship on a non-<em>main</em>
469                   package),
470               </item>
471               <item>
472                   must not be so buggy that we refuse to support them,
473                   and
474               </item>
475               <item>
476                   must meet all policy requirements presented in this
477                   manual.
478               </item>
479             </list>
480           </p>
481
482         </sect1>
483
484         <sect1 id="contrib">
485           <heading>The contrib category</heading>
486
487           <p>
488             Every package in <em>contrib</em> must comply with the DFSG.
489           </p>
490
491           <p>
492             In addition, the packages in <em>contrib</em>
493             <list compact="compact">
494               <item>
495                   must not be so buggy that we refuse to support them,
496                   and
497               </item>
498               <item>
499                   must meet all policy requirements presented in this
500                   manual.
501               </item>
502             </list>
503           </p>
504
505
506           <p>
507             Examples of packages which would be included in
508             <em>contrib</em> are:
509             <list compact="compact">
510               <item>
511                   free packages which require <em>contrib</em>,
512                   <em>non-free</em> packages or packages which are not
513                   in our archive at all for compilation or execution,
514                   and
515               </item>
516               <item>
517                   wrapper packages or other sorts of free accessories for
518                   non-free programs.
519               </item>
520             </list>
521           </p>
522         </sect1>
523
524         <sect1 id="non-free">
525           <heading>The non-free category</heading>
526
527           <p>
528             Packages must be placed in <em>non-free</em> if they are
529             not compliant with the DFSG or are encumbered by patents
530             or other legal issues that make their distribution
531             problematic.
532           </p>
533
534           <p>
535             In addition, the packages in <em>non-free</em>
536             <list compact="compact">
537               <item>
538                   must not be so buggy that we refuse to support them,
539                   and
540               </item>
541               <item>
542                   must meet all policy requirements presented in this
543                   manual that it is possible for them to meet.
544                   <footnote>
545                       It is possible that there are policy
546                       requirements which the package is unable to
547                       meet, for example, if the source is
548                       unavailable.  These situations will need to be
549                       handled on a case-by-case basis.
550                   </footnote>
551               </item>
552             </list>
553           </p>
554         </sect1>
555
556       </sect>
557
558       <sect id="pkgcopyright">
559         <heading>Copyright considerations</heading>
560
561         <p>
562           Every package must be accompanied by a verbatim copy of
563           its copyright and distribution license in the file
564           <file>/usr/share/doc/<var>package</var>/copyright</file>
565           (see <ref id="copyrightfile"> for further details).
566         </p>
567
568         <p>
569           We reserve the right to restrict files from being included
570           anywhere in our archives if
571           <list compact="compact">
572             <item>
573                   their use or distribution would break a law,
574             </item>
575             <item>
576                   there is an ethical conflict in their distribution or
577                   use,
578             </item>
579             <item>
580                   we would have to sign a license for them, or
581             </item>
582             <item>
583                   their distribution would conflict with other project
584                   policies.
585             </item>
586           </list>
587         </p>
588
589         <p>
590           Programs whose authors encourage the user to make
591           donations are fine for the main distribution, provided
592           that the authors do not claim that not donating is
593           immoral, unethical, illegal or something similar; in such
594           a case they must go in <em>non-free</em>.
595         </p>
596
597         <p>
598           Packages whose copyright permission notices (or patent
599           problems) do not even allow redistribution of binaries
600           only, and where no special permission has been obtained,
601           must not be placed on the Debian FTP site and its mirrors
602           at all.
603         </p>
604
605         <p>
606           Note that under international copyright law (this applies
607           in the United States, too), <em>no</em> distribution or
608           modification of a work is allowed without an explicit
609           notice saying so.  Therefore a program without a copyright
610           notice <em>is</em> copyrighted and you may not do anything
611           to it without risking being sued! Likewise if a program
612           has a copyright notice but no statement saying what is
613           permitted then nothing is permitted.
614         </p>
615
616         <p>
617           Many authors are unaware of the problems that restrictive
618           copyrights (or lack of copyright notices) can cause for
619           the users of their supposedly-free software.  It is often
620           worthwhile contacting such authors diplomatically to ask
621           them to modify their license terms. However, this can be a
622           politically difficult thing to do and you should ask for
623           advice on the <tt>debian-legal</tt> mailing list first, as
624           explained below.
625         </p>
626
627         <p>
628           When in doubt about a copyright, send mail to
629           <email>debian-legal@lists.debian.org</email>.  Be prepared
630           to provide us with the copyright statement.  Software
631           covered by the GPL, public domain software and BSD-like
632           copyrights are safe; be wary of the phrases "commercial
633           use prohibited" and "distribution restricted".
634         </p>
635       </sect>
636
637       <sect id="subsections">
638         <heading>Sections</heading>
639
640         <p>
641           The packages in the categories <em>main</em>,
642           <em>contrib</em> and <em>non-free</em> are grouped further
643           into <em>sections</em> to simplify handling.
644         </p>
645
646         <p>
647           The category and section for each package should be
648           specified in the package's <tt>Section</tt> control record
649           (see <ref id="f-Section">).  However, the maintainer of the
650           Debian archive may override this selection to ensure the
651           consistency of the Debian distribution.  The
652           <tt>Section</tt> field should be of the form:
653           <list compact="compact">
654             <item>
655                   <em>section</em> if the package is in the
656                   <em>main</em> category,
657             </item>
658             <item>
659                   <em>segment/section</em> if the package is in
660                   the <em>contrib</em> or <em>non-free</em>
661                   distribution areas.
662             </item>
663           </list>
664         </p>
665
666         <p>
667           The Debian archive maintainers provide the authoritative
668           list of sections.  At present, they are:
669           <em>admin</em>, <em>comm</em>,
670           <em>devel</em>, <em>doc</em>,
671           <em>editors</em>, <em>electronics</em>, <em>embedded</em>,
672           <em>games</em>, <em>gnome</em>, <em>graphics</em>,
673           <em>hamradio</em>, <em>interpreters</em>, <em>kde</em>,
674           <em>libs</em>, <em>libdevel</em>, <em>mail</em>,
675           <em>math</em>, <em>misc</em>, <em>net</em>, <em>news</em>,
676           <em>oldlibs</em>,
677           <em>otherosfs</em>, <em>perl</em>, <em>python</em>,
678           <em>science</em>, <em>shells</em>,
679           <em>sound</em>, <em>tex</em>, <em>text</em>,
680           <em>utils</em>, <em>web</em>, <em>x11</em>.
681         </p>
682       </sect>
683
684       <sect id="priorities">
685         <heading>Priorities</heading>
686
687         <p>
688           Each package should have a <em>priority</em> value, which is
689           included in the package's <em>control record</em>
690           (see <ref id="f-Priority">).
691           This information is used by the Debian package management tools to
692           separate high-priority packages from less-important packages.
693         </p>
694
695         <p>
696           The following <em>priority levels</em> are recognized by the
697           Debian package management tools.
698           <taglist>
699             <tag><tt>required</tt></tag>
700             <item>
701                 Packages which are necessary for the proper
702                 functioning of the system (usually, this means that
703                 dpkg functionality depends on these packages).
704                 Removing a <tt>required</tt> package may cause your
705                 system to become totally broken and you may not even
706                 be able to use <prgn>dpkg</prgn> to put things back,
707                 so only do so if you know what you are doing.  Systems
708                 with only the <tt>required</tt> packages are probably
709                 unusable, but they do have enough functionality to
710                 allow the sysadmin to boot and install more software.
711             </item>
712             <tag><tt>important</tt></tag>
713             <item>
714                 Important programs, including those which one would
715                 expect to find on any Unix-like system.  If the
716                 expectation is that an experienced Unix person who
717                 found it missing would say "What on earth is going on,
718                 where is <prgn>foo</prgn>?", it must be an
719                 <tt>important</tt> package.<footnote>
720                     This is an important criterion because we are
721                     trying to produce, amongst other things, a free
722                     Unix.
723                 </footnote>
724                 Other packages without which the system will not run
725                 well or be usable must also have priority
726                 <tt>important</tt>.  This does
727                 <em>not</em> include Emacs, the X Window System, TeX
728                 or any other large applications.  The
729                 <tt>important</tt> packages are just a bare minimum of
730                 commonly-expected and necessary tools.
731             </item>
732             <tag><tt>standard</tt></tag>
733             <item>
734                 These packages provide a reasonably small but not too
735                 limited character-mode system.  This is what will be
736                 installed by default if the user doesn't select anything
737                 else.  It doesn't include many large applications.
738             </item>
739             <tag><tt>optional</tt></tag>
740             <item>
741                 (In a sense everything that isn't required is
742                 optional, but that's not what is meant here.) This is
743                 all the software that you might reasonably want to
744                 install if you didn't know what it was and don't have
745                 specialized requirements. This is a much larger system
746                 and includes the X Window System, a full TeX
747                 distribution, and many applications. Note that
748                 optional packages should not conflict with each other.
749             </item>
750             <tag><tt>extra</tt></tag>
751             <item>
752                 This contains all packages that conflict with others
753                 with required, important, standard or optional
754                 priorities, or are only likely to be useful if you
755                 already know what they are or have specialized
756                 requirements.
757             </item>
758           </taglist>
759         </p>
760
761         <p>
762           Packages must not depend on packages with lower priority
763           values (excluding build-time dependencies).  In order to
764           ensure this, the priorities of one or more packages may need
765           to be adjusted.
766         </p>
767       </sect>
768
769     </chapt>
770
771
772     <chapt id="binary">
773       <heading>Binary packages</heading>
774
775       <p>
776         The Debian GNU/Linux distribution is based on the Debian
777         package management system, called <prgn>dpkg</prgn>. Thus,
778         all packages in the Debian distribution must be provided
779         in the <tt>.deb</tt> file format.
780       </p>
781
782       <sect>
783         <heading>The package name</heading>
784
785         <p>
786           Every package must have a name that's unique within the Debian
787           archive.
788         </p>
789
790         <p>
791           The package name is included in the control field
792           <tt>Package</tt>, the format of which is described
793           in <ref id="f-Package">.
794           The package name is also included as a part of the file name
795           of the <tt>.deb</tt> file.
796         </p>
797       </sect>
798
799       <sect id="versions">
800         <heading>The version of a package</heading>
801
802         <p>
803           Every package has a version number recorded in its
804           <tt>Version</tt> control file field, described in
805           <ref id="f-Version">.
806         </p>
807
808         <p>
809           The package management system imposes an ordering on version
810           numbers, so that it can tell whether packages are being up- or
811           downgraded and so that package system front end applications
812           can tell whether a package it finds available is newer than
813           the one installed on the system.  The version number format
814           has the most significant parts (as far as comparison is
815           concerned) at the beginning.
816         </p>
817
818         <p>
819           If an upstream package has problematic version numbers they
820           should be converted to a sane form for use in the
821           <tt>Version</tt> field.
822         </p>
823
824         <sect1>
825           <heading>Version numbers based on dates</heading>
826
827           <p>
828             In general, Debian packages should use the same version
829             numbers as the upstream sources.
830           </p>
831
832           <p>
833             However, in some cases where the upstream version number is
834             based on a date (e.g., a development "snapshot" release) the
835             package management system cannot handle these version
836             numbers without epochs. For example, dpkg will consider
837             "96May01" to be greater than "96Dec24".
838           </p>
839
840           <p>
841             To prevent having to use epochs for every new upstream
842             version, the date based portion of the version number
843             should be changed to the following format in such cases:
844             "19960501", "19961224". It is up to the maintainer whether
845             they want to bother the upstream maintainer to change
846             the version numbers upstream, too.
847           </p>
848
849           <p>
850             Note that other version formats based on dates which are
851             parsed correctly by the package management system should
852             <em>not</em> be changed.
853           </p>
854
855           <p>
856             Native Debian packages (i.e., packages which have been
857             written especially for Debian) whose version numbers include
858             dates should always use the "YYYYMMDD" format.
859           </p>
860         </sect1>
861
862       </sect>
863
864       <sect>
865         <heading>The maintainer of a package</heading>
866
867         <p>
868           Every package must have a Debian maintainer (the
869           maintainer may be one person or a group of people
870           reachable from a common email address, such as a mailing
871           list).  The maintainer is responsible for ensuring that
872           the package is placed in the appropriate distributions.
873         </p>
874
875         <p>
876           The maintainer must be specified in the
877           <tt>Maintainer</tt> control field with their correct name
878           and a working email address.  If one person maintains
879           several packages, they should try to avoid having
880           different forms of their name and email address in
881           the <tt>Maintainer</tt> fields of those packages.
882         </p>
883
884         <p>
885           The format of the <tt>Maintainer</tt> control field is
886           described in <ref id="f-Maintainer">.
887         </p>
888
889         <p>
890           If the maintainer of a package quits from the Debian
891           project, "Debian QA Group"
892           <email>packages@qa.debian.org</email> takes over the
893           maintainer-ship of the package until someone else
894           volunteers for that task. These packages are called
895           <em>orphaned packages</em>.<footnote>
896                 The detailed procedure for doing this gracefully can
897                 be found in the Debian Developer's Reference,
898                 see <ref id="related">.
899           </footnote>
900         </p>
901       </sect>
902
903       <sect id="descriptions">
904         <heading>The description of a package</heading>
905
906         <p>
907           Every Debian package must have an extended description
908           stored in the appropriate field of the control record.
909           The technical information about the format of the
910           <tt>Description</tt> field is in <ref id="f-Description">.
911         </p>
912
913         <p>
914           The description should describe the package (the program) to a
915           user (system administrator) who has never met it before so that
916           they have enough information to decide whether they want to
917           install it. This description should not just be copied verbatim
918           from the program's documentation.
919         </p>
920
921         <p>
922           Put important information first, both in the synopsis and
923           extended description.  Sometimes only the first part of the
924           synopsis or of the description will be displayed.  You can
925           assume that there will usually be a way to see the whole
926           extended description.
927         </p>
928
929         <p>
930           The description should also give information about the
931           significant dependencies and conflicts between this package
932           and others, so that the user knows why these dependencies and
933           conflicts have been declared.
934         </p>
935
936         <p>
937           Instructions for configuring or using the package should
938           not be included (that is what installation scripts,
939           manual pages, info files, etc., are for).  Copyright
940           statements and other administrivia should not be included
941           either (that is what the copyright file is for).
942         </p>
943
944         <sect1 id="synopsis"><heading>The single line synopsis</heading>
945
946           <p>
947             The single line synopsis should be kept brief - certainly
948             under 80 characters.
949           </p>
950
951           <p>
952             Do not include the package name in the synopsis line.  The
953             display software knows how to display this already, and you
954             do not need to state it.  Remember that in many situations
955             the user may only see the synopsis line - make it as
956             informative as you can.
957           </p>
958
959         </sect1>
960
961         <sect1 id="extendeddesc"><heading>The extended description</heading>
962
963           <p>
964             Do not try to continue the single line synopsis into the
965             extended description.  This will not work correctly when
966             the full description is displayed, and makes no sense
967             where only the summary (the single line synopsis) is
968             available.
969           </p>
970
971           <p>
972             The extended description should describe what the package
973             does and how it relates to the rest of the system (in terms
974             of, for example, which subsystem it is which part of).
975           </p>
976
977           <p>
978             The description field needs to make sense to anyone, even
979             people who have no idea about any of the things the
980             package deals with.<footnote>
981                 The blurb that comes with a program in its
982                 announcements and/or <prgn>README</prgn> files is
983                 rarely suitable for use in a description.  It is
984                 usually aimed at people who are already in the
985                 community where the package is used.
986             </footnote>
987           </p>
988
989         </sect1>
990
991       </sect>
992
993       <sect>
994         <heading>Dependencies</heading>
995
996         <p>
997           Every package must specify the dependency information
998           about other packages that are required for the first to
999           work correctly.
1000         </p>
1001
1002         <p>
1003           For example, a dependency entry must be provided for any
1004           shared libraries required by a dynamically-linked executable
1005           binary in a package.
1006         </p>
1007
1008         <p>
1009           Packages are not required to declare any dependencies they
1010           have on other packages which are marked <tt>Essential</tt>
1011           (see below), and should not do so unless they depend on a
1012           particular version of that package.<footnote>
1013             <p>
1014               Essential is defined as the minimal set of functionality
1015               that must be available and usable on the system even
1016               when packages are in an unconfigured (but unpacked)
1017               state.  This is needed to avoid unresolvable dependency
1018               loops on upgrade.  If packages add unnecessary
1019               dependencies on packages in this set, the chances that
1020               there <strong>will</strong> be an unresolvable
1021               dependency loop caused by forcing these Essential
1022               packages to be configured first before they need to be
1023               is greatly increased.  It also increases the chances
1024               that frontends will be unable to
1025               <strong>calculate</strong> an upgrade path, even if one
1026               exists.
1027             </p>
1028             <p>
1029               Also, it's pretty unlikely that functionality from
1030               Essential shall ever be removed (which is one reason why
1031               care must be taken before adding to the Essential
1032               packages set), but <em>packages</em> have been removed
1033               from the Essential set when the functionality moved to a
1034               different package. So depending on these packages
1035               <em>just in case</em> they stop being essential does way
1036               more harm than good.
1037             </p>
1038           </footnote>
1039         </p>
1040
1041         <p>
1042           Sometimes, a package requires another package to be installed
1043           <em>and</em> configured before it can be installed. In this
1044           case, you must specify a <tt>Pre-Depends</tt> entry for
1045           the package.
1046         </p>
1047
1048         <p>
1049           You should not specify a <tt>Pre-Depends</tt> entry for a
1050           package before this has been discussed on the
1051           <tt>debian-devel</tt> mailing list and a consensus about
1052           doing that has been reached.
1053         </p>
1054
1055         <p>
1056           The format of the package interrelationship control fields is
1057           described in <ref id="relationships">.
1058         </p>
1059       </sect>
1060
1061       <sect id="virtual_pkg">
1062         <heading>Virtual packages</heading>
1063
1064         <p>
1065           Sometimes, there are several packages which offer
1066           more-or-less the same functionality. In this case, it's
1067           useful to define a <em>virtual package</em> whose name
1068           describes that common functionality.  (The virtual
1069           packages only exist logically, not physically; that's why
1070           they are called <em>virtual</em>.) The packages with this
1071           particular function will then <em>provide</em> the virtual
1072           package. Thus, any other package requiring that function
1073           can simply depend on the virtual package without having to
1074           specify all possible packages individually.
1075         </p>
1076
1077         <p>
1078           All packages should use virtual package names where
1079           appropriate, and arrange to create new ones if necessary.
1080           They should not use virtual package names (except privately,
1081           amongst a cooperating group of packages) unless they have
1082           been agreed upon and appear in the list of virtual package
1083           names. (See also <ref id="virtual">)
1084         </p>
1085
1086         <p>
1087           The latest version of the authoritative list of virtual
1088           package names can be found in the <tt>debian-policy</tt> package.
1089           It is also available from the Debian web mirrors at
1090           <tt><url name="/doc/packaging-manuals/virtual-package-names-list.txt"
1091                 id="http://www.debian.org/doc/packaging-manuals/virtual-package-names-list.txt"></tt>.
1092         </p>
1093
1094         <p>
1095           The procedure for updating the list is described in the preface
1096           to the list.
1097         </p>
1098
1099       </sect>
1100
1101       <sect>
1102         <heading>Base system</heading>
1103
1104         <p>
1105           The <tt>base system</tt> is a minimum subset of the Debian
1106           GNU/Linux system that is installed before everything else
1107           on a new system. Only very few packages are allowed to form
1108           part of the base system, in order to keep the required disk
1109           usage very small.
1110         </p>
1111
1112         <p>
1113           The base system consists of all those packages with priority
1114           <tt>required</tt> or <tt>important</tt>. Many of them will
1115           be tagged <tt>essential</tt> (see below).
1116         </p>
1117       </sect>
1118
1119       <sect>
1120         <heading>Essential packages</heading>
1121
1122         <p>
1123           Some packages are tagged <tt>essential</tt> for a system
1124           using the <tt>Essential</tt> control file field.
1125           The format of the <tt>Essential</tt> control field is
1126           described in <ref id="f-Essential">.
1127         </p>
1128
1129         <p>
1130           Since these packages cannot be easily removed (one has to
1131           specify an extra <em>force option</em> to
1132           <prgn>dpkg</prgn> to do so), this flag must not be used
1133           unless absolutely necessary.  A shared library package
1134           must not be tagged <tt>essential</tt>; dependencies will
1135           prevent its premature removal, and we need to be able to
1136           remove it when it has been superseded.
1137         </p>
1138
1139         <p>
1140           Since dpkg will not prevent upgrading of other packages
1141           while an <tt>essential</tt> package is in an unconfigured
1142             state, all <tt>essential</tt> packages must supply all of
1143             their core functionality even when unconfigured. If the
1144             package cannot satisfy this requirement it must not be
1145             tagged as essential, and any packages depending on this
1146             package must instead have explicit dependency fields as
1147             appropriate.
1148         </p>
1149
1150         <p>
1151           You must not tag any packages <tt>essential</tt> before
1152           this has been discussed on the <tt>debian-devel</tt>
1153           mailing list and a consensus about doing that has been
1154           reached.
1155         </p>
1156       </sect>
1157
1158       <sect id="maintscripts">
1159         <heading>Maintainer Scripts</heading>
1160
1161         <p>
1162           The package installation scripts should avoid producing
1163           output which is unnecessary for the user to see and
1164           should rely on <prgn>dpkg</prgn> to stave off boredom on
1165           the part of a user installing many packages.  This means,
1166           amongst other things, using the <tt>--quiet</tt> option on
1167           <prgn>install-info</prgn>.
1168         </p>
1169
1170         <p>
1171           Errors which occur during the execution of an installation
1172           script must be checked and the installation must not
1173           continue after an error.
1174         </p>
1175
1176         <p>
1177           Note that in general <ref id="scripts"> applies to package
1178           maintainer scripts, too.
1179         </p>
1180
1181         <p>
1182           You should not use <prgn>dpkg-divert</prgn> on a file
1183           belonging to another package without consulting the
1184           maintainer of that package first.
1185         </p>
1186
1187         <p>
1188           All packages which supply an instance of a common command
1189           name (or, in general, filename) should generally use
1190           <prgn>update-alternatives</prgn>, so that they may be
1191           installed together.  If <prgn>update-alternatives</prgn>
1192           is not used, then each package must use
1193           <tt>Conflicts</tt> to ensure that other packages are
1194           de-installed.  (In this case, it may be appropriate to
1195           specify a conflict against earlier versions of something
1196           that previously did not use
1197           <prgn>update-alternatives</prgn>; this is an exception to
1198           the usual rule that versioned conflicts should be
1199           avoided.)
1200         </p>
1201
1202         <sect1 id="maintscriptprompt">
1203           <heading>Prompting in maintainer scripts</heading>
1204           <p>
1205             Package maintainer scripts may prompt the user if
1206             necessary. Prompting should be done by communicating
1207             through a program, such as <prgn>debconf</prgn>, which
1208             conforms to the Debian Configuration management
1209             specification, version 2 or higher.  Prompting the user by
1210             other means, such as by hand<footnote>
1211                 From the Jargon file: by hand 2. By extension,
1212                 writing code which does something in an explicit or
1213                 low-level way for which a presupplied library
1214                 (<em>debconf, in this instance</em>) routine ought
1215                 to have been available.
1216             </footnote>, is now deprecated.
1217           </p>
1218
1219           <p>
1220             The Debian Configuration management specification is included
1221             in the <file>debconf_specification</file> files in the
1222             <package>debian-policy</package> package.
1223             It is also available from the Debian web mirrors at
1224             <tt><url name="/doc/packaging-manuals/debconf_specification.html"
1225                 id="http://www.debian.org/doc/packaging-manuals/debconf_specification.html"></tt>.
1226           </p>
1227
1228           <p>
1229             Packages which use the Debian Configuration management
1230             specification may contain an additional
1231             <prgn>config</prgn> script and a <tt>templates</tt>
1232             file in their control archive<footnote>
1233                 The control.tar.gz inside the .deb.
1234                 See <manref name="deb" section="5">.
1235             </footnote>.
1236             The <prgn>config</prgn> script might be run before the
1237             <prgn>preinst</prgn> script, and before the package is unpacked
1238             or any of its dependencies or pre-dependencies are satisfied.
1239             Therefore it must work using only the tools present in
1240             <em>essential</em> packages.<footnote>
1241                   <package>Debconf</package> or another tool that
1242                   implements the Debian Configuration management
1243                   specification will also be installed, and any
1244                   versioned dependencies on it will be satisfied
1245                   before preconfiguration begins.
1246             </footnote>
1247           </p>
1248
1249           <p>
1250             Packages which use the Debian Configuration management
1251             specification must allow for translation of their messages
1252             by using a gettext-based system such as the one provided by
1253             the <package>po-debconf</package> package.
1254           </p>
1255
1256           <p>
1257             Packages should try to minimize the amount of prompting
1258             they need to do, and they should ensure that the user
1259             will only ever be asked each question once.  This means
1260             that packages should try to use appropriate shared
1261             configuration files (such as <file>/etc/papersize</file> and
1262             <file>/etc/news/server</file>), and shared
1263             <package>debconf</package> variables rather than each
1264             prompting for their own list of required pieces of
1265             information.
1266           </p>
1267
1268           <p>
1269             It also means that an upgrade should not ask the same
1270             questions again, unless the user has used
1271             <tt>dpkg --purge</tt> to remove the package's configuration.
1272             The answers to configuration questions should be stored in an
1273             appropriate place in <file>/etc</file> so that the user can
1274             modify them, and how this has been done should be
1275             documented.
1276           </p>
1277
1278           <p>
1279             If a package has a vitally important piece of
1280             information to pass to the user (such as "don't run me
1281             as I am, you must edit the following configuration files
1282             first or you risk your system emitting badly-formatted
1283             messages"), it should display this in the
1284             <prgn>config</prgn> or <prgn>postinst</prgn> script and
1285             prompt the user to hit return to acknowledge the
1286             message.  Copyright messages do not count as vitally
1287             important (they belong in
1288             <file>/usr/share/doc/<var>package</var>/copyright</file>);
1289             neither do instructions on how to use a program (these
1290             should be in on-line documentation, where all the users
1291             can see them).
1292           </p>
1293
1294           <p>
1295             Any necessary prompting should almost always be confined
1296             to the <prgn>config</prgn> or <prgn>postinst</prgn>
1297             script. If it is done in the <prgn>postinst</prgn>, it
1298             should be protected with a conditional so that
1299             unnecessary prompting doesn't happen if a package's
1300             installation fails and the <prgn>postinst</prgn> is
1301             called with <tt>abort-upgrade</tt>,
1302             <tt>abort-remove</tt> or <tt>abort-deconfigure</tt>.
1303           </p>
1304         </sect1>
1305
1306       </sect>
1307
1308     </chapt>
1309
1310
1311     <chapt id="source">
1312       <heading>Source packages</heading>
1313
1314       <sect id="standardsversion">
1315         <heading>Standards conformance</heading>
1316
1317         <p>
1318           Source packages should specify the most recent version number
1319           of this policy document with which your package complied
1320           when it was last updated.
1321         </p>
1322
1323         <p>
1324           This information may be used to file bug reports
1325           automatically if your package becomes too much out of date.
1326         </p>
1327
1328         <p>
1329           The version is specified in the <tt>Standards-Version</tt>
1330           control field.
1331           The format of the <tt>Standards-Version</tt> field is
1332           described in <ref id="f-Standards-Version">.
1333         </p>
1334
1335         <p>
1336           You should regularly, and especially if your package has
1337           become out of date, check for the newest Policy Manual
1338           available and update your package, if necessary. When your
1339           package complies with the new standards you should update the
1340           <tt>Standards-Version</tt> source package field and
1341           release it.<footnote>
1342                 See the file <file>upgrading-checklist</file> for
1343                 information about policy which has changed between
1344                 different versions of this document.
1345           </footnote>
1346         </p>
1347
1348       </sect>
1349
1350       <sect id="pkg-relations">
1351         <heading>Package relationships</heading>
1352
1353         <p>
1354           Source packages should specify which binary packages they
1355           require to be installed or not to be installed in order to
1356           build correctly.  For example, if building a package
1357           requires a certain compiler, then the compiler should be
1358           specified as a build-time dependency.
1359         </p>
1360
1361         <p>
1362           It is not necessary to explicitly specify build-time
1363           relationships on a minimal set of packages that are always
1364           needed to compile, link and put in a Debian package a
1365           standard "Hello World!" program written in C or C++.  The
1366           required packages are called <em>build-essential</em>, and
1367           an informational list can be found in
1368           <file>/usr/share/doc/build-essential/list</file> (which is
1369           contained in the <tt>build-essential</tt>
1370           package).<footnote>
1371             Rationale:
1372                 <list compact="compact">
1373                   <item>
1374                       This allows maintaining the list separately
1375                       from the policy documents (the list does not
1376                       need the kind of control that the policy
1377                       documents do).
1378                   </item>
1379                   <item>
1380                       Having a separate package allows one to install
1381                       the build-essential packages on a machine, as
1382                       well as allowing other packages such as tasks to
1383                       require installation of the build-essential
1384                       packages using the depends relation.
1385                   </item>
1386                   <item>
1387                       The separate package allows bug reports against
1388                       the list to be categorized separately from
1389                       the policy management process in the BTS.
1390                   </item>
1391                 </list>
1392           </footnote>
1393         </p>
1394
1395         <p>
1396           When specifying the set of build-time dependencies, one
1397           should list only those packages explicitly required by the
1398           build.  It is not necessary to list packages which are
1399           required merely because some other package in the list of
1400           build-time dependencies depends on them.<footnote>
1401                 The reason for this is that dependencies change, and
1402                 you should list all those packages, and <em>only</em>
1403                 those packages that <em>you</em> need directly.  What
1404                 others need is their business.  For example, if you
1405                 only link against <file>libimlib</file>, you will need to
1406                 build-depend on <package>libimlib2-dev</package> but
1407                 not against any <tt>libjpeg*</tt> packages, even
1408                 though <tt>libimlib2-dev</tt> currently depends on
1409                 them: installation of <package>libimlib2-dev</package>
1410                 will automatically ensure that all of its run-time
1411                 dependencies are satisfied.
1412           </footnote>
1413         </p>
1414
1415         <p>
1416           If build-time dependencies are specified, it must be
1417           possible to build the package and produce working binaries
1418           on a system with only essential and build-essential
1419           packages installed and also those required to satisfy the
1420           build-time relationships (including any implied
1421           relationships).  In particular, this means that version
1422           clauses should be used rigorously in build-time
1423           relationships so that one cannot produce bad or
1424           inconsistently configured packages when the relationships
1425           are properly satisfied.
1426         </p>
1427
1428         <p>
1429           <ref id="relationships"> explains the technical details.
1430         </p>
1431       </sect>
1432
1433       <sect>
1434         <heading>Changes to the upstream sources</heading>
1435
1436         <p>
1437           If changes to the source code are made that are not
1438           specific to the needs of the Debian system, they should be
1439           sent to the upstream authors in whatever form they prefer
1440           so as to be included in the upstream version of the
1441           package.
1442         </p>
1443
1444         <p>
1445           If you need to configure the package differently for
1446           Debian or for Linux, and the upstream source doesn't
1447           provide a way to do so, you should add such configuration
1448           facilities (for example, a new <prgn>autoconf</prgn> test
1449           or <tt>#define</tt>) and send the patch to the upstream
1450           authors, with the default set to the way they originally
1451           had it.  You can then easily override the default in your
1452           <file>debian/rules</file> or wherever is appropriate.
1453         </p>
1454
1455         <p>
1456           You should make sure that the <prgn>configure</prgn> utility
1457           detects the correct architecture specification string
1458           (refer to <ref id="arch-spec"> for details).
1459         </p>
1460
1461         <p>
1462           If you need to edit a <prgn>Makefile</prgn> where GNU-style
1463           <prgn>configure</prgn> scripts are used, you should edit the
1464           <file>.in</file> files rather than editing the
1465           <prgn>Makefile</prgn> directly.  This allows the user to
1466           reconfigure the package if necessary.  You should
1467           <em>not</em> configure the package and edit the generated
1468           <prgn>Makefile</prgn>!  This makes it impossible for someone
1469           else to later reconfigure the package without losing the
1470           changes you made.
1471         </p>
1472
1473       </sect>
1474
1475       <sect id="dpkgchangelog">
1476         <heading>Debian changelog: <file>debian/changelog</file></heading>
1477
1478         <p>
1479           Changes in the Debian version of the package should be
1480           briefly explained in the Debian changelog file
1481           <file>debian/changelog</file>.<footnote>
1482             <p>
1483               Mistakes in changelogs are usually best rectified by
1484               making a new changelog entry rather than "rewriting
1485               history" by editing old changelog entries.
1486             </p>
1487           </footnote>
1488           This includes modifications
1489           made in the Debian package compared to the upstream one
1490           as well as other changes and updates to the package.
1491           <footnote>
1492               Although there is nothing stopping an author who is also
1493               the Debian maintainer from using this changelog for all
1494               their changes, it will have to be renamed if the Debian
1495               and upstream maintainers become different people. In such
1496               a case, however, it might be better to maintain the package
1497               as a non-native package.
1498           </footnote>
1499         </p>
1500
1501         <p>
1502           The format of the <file>debian/changelog</file> allows the
1503           package building tools to discover which version of the package
1504           is being built and find out other release-specific information.
1505         </p>
1506
1507         <p>
1508           That format is a series of entries like this:
1509
1510 <example compact="compact">
1511 <var>package</var> (<var>version</var>) <var>distribution(s)</var>; urgency=<var>urgency</var>
1512             <var>
1513               [optional blank line(s), stripped]
1514             </var>
1515   * <var>change details</var>
1516     <var>more change details</var>
1517             <var>
1518               [blank line(s), included in output of dpkg-parsechangelog]
1519             </var>
1520   * <var>even more change details</var>
1521             <var>
1522               [optional blank line(s), stripped]
1523             </var>
1524  -- <var>maintainer name</var> &lt;<var>email address</var>&gt;<var>[two spaces]</var>  <var>date</var>
1525 </example>
1526         </p>
1527
1528         <p>
1529           <var>package</var> and <var>version</var> are the source
1530           package name and version number.
1531         </p>
1532
1533         <p>
1534           <var>distribution(s)</var> lists the distributions where
1535           this version should be installed when it is uploaded - it
1536           is copied to the <tt>Distribution</tt> field in the
1537           <file>.changes</file> file.  See <ref id="f-Distribution">.
1538         </p>
1539
1540         <p>
1541           <var>urgency</var> is the value for the <tt>Urgency</tt>
1542           field in the <file>.changes</file> file for the upload
1543           (see <ref id="f-Urgency">). It is not possible to specify
1544           an urgency containing commas; commas are used to separate
1545           <tt><var>keyword</var>=<var>value</var></tt> settings in the
1546           <prgn>dpkg</prgn> changelog format (though there is
1547           currently only one useful <var>keyword</var>,
1548           <tt>urgency</tt>).
1549         </p>
1550
1551         <p>
1552           The change details may in fact be any series of lines
1553           starting with at least two spaces, but conventionally each
1554           change starts with an asterisk and a separating space and
1555           continuation lines are indented so as to bring them in
1556           line with the start of the text above.  Blank lines may be
1557           used here to separate groups of changes, if desired.
1558         </p>
1559
1560         <p>
1561           If this upload resolves bugs recorded in the Bug Tracking
1562           System (BTS), they may be automatically closed on the
1563           inclusion of this package into the Debian archive by
1564           including the string: <tt>closes: Bug#<var>nnnnn</var></tt>
1565           in the change details.<footnote>
1566               To be precise, the string should match the following
1567               Perl regular expression:
1568               <example>
1569 /closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*/i
1570               </example>
1571               Then all of the bug numbers listed will be closed by the
1572               archive maintenance script (<prgn>katie</prgn>) using the
1573               <var>version</var> of the changelog entry.
1574           </footnote>
1575           This information is conveyed via the <tt>Closes</tt> field
1576           in the <tt>.changes</tt> file (see <ref id="f-Closes">).
1577         </p>
1578
1579         <p>
1580           The maintainer name and email address used in the changelog
1581           should be the details of the person uploading <em>this</em>
1582           version.  They are <em>not</em> necessarily those of the
1583           usual package maintainer.  The information here will be
1584           copied to the <tt>Changed-By</tt> field in the
1585           <tt>.changes</tt> file (see <ref id="f-Changed-By">),
1586           and then later used to send an acknowledgement when the
1587           upload has been installed.
1588         </p>
1589
1590         <p>
1591           The <var>date</var> must be in RFC822 format<footnote>
1592               This is generated by <tt>date -R</tt>.
1593           </footnote>; it must include the time zone specified
1594           numerically, with the time zone name or abbreviation
1595           optionally present as a comment in parentheses.
1596         </p>
1597
1598         <p>
1599           The first "title" line with the package name must start
1600           at the left hand margin.  The "trailer" line with the
1601           maintainer and date details must be preceded by exactly
1602           one space.  The maintainer details and the date must be
1603           separated by exactly two spaces.
1604         </p>
1605
1606         <p>
1607           The entire changelog must be encoded in UTF-8.
1608         </p>
1609
1610         <p>
1611           For more information on placement of the changelog files
1612           within binary packages, please see <ref id="changelogs">.
1613         </p>
1614       </sect>
1615
1616       <sect id="dpkgcopyright">
1617         <heading>Copyright: <file>debian/copyright</file></heading>
1618         <p>
1619           Every package must be accompanied by a verbatim copy of
1620           its copyright and distribution license in the file
1621           <file>/usr/share/doc/<var>package</var>/copyright</file>
1622           (see <ref id="copyrightfile"> for further details). Also see
1623           <ref id="pkgcopyright"> for further considerations relayed
1624           to copyrights for packages.
1625         </p>
1626       </sect>
1627       <sect>
1628         <heading>Error trapping in makefiles</heading>
1629
1630         <p>
1631           When <prgn>make</prgn> invokes a command in a makefile
1632           (including your package's upstream makefiles and
1633           <file>debian/rules</file>), it does so using <prgn>sh</prgn>.  This
1634           means that <prgn>sh</prgn>'s usual bad error handling
1635           properties apply: if you include a miniature script as one
1636           of the commands in your makefile you'll find that if you
1637           don't do anything about it then errors are not detected
1638           and <prgn>make</prgn> will blithely continue after
1639           problems.
1640         </p>
1641
1642         <p>
1643           Every time you put more than one shell command (this
1644           includes using a loop) in a makefile command you
1645           must make sure that errors are trapped.  For
1646           simple compound commands, such as changing directory and
1647           then running a program, using <tt>&amp;&amp;</tt> rather
1648           than semicolon as a command separator is sufficient.  For
1649           more complex commands including most loops and
1650           conditionals you should include a separate <tt>set -e</tt>
1651           command at the start of every makefile command that's
1652           actually one of these miniature shell scripts.
1653         </p>
1654       </sect>
1655
1656       <sect id="timestamps">
1657         <heading>Time Stamps</heading>
1658         <p>
1659           Maintainers should preserve the modification times of the
1660           upstream source files in a package, as far as is reasonably
1661           possible.<footnote>
1662               The rationale is that there is some information conveyed
1663               by knowing the age of the file, for example, you could
1664               recognize that some documentation is very old by looking
1665               at the modification time, so it would be nice if the
1666               modification time of the upstream source would be
1667               preserved.
1668           </footnote>
1669         </p>
1670       </sect>
1671
1672       <sect id="restrictions">
1673         <heading>Restrictions on objects in source packages</heading>
1674
1675         <p>
1676           The source package may not contain any hard links<footnote>
1677             <p>
1678               This is not currently detected when building source
1679               packages, but only when extracting
1680               them.
1681             </p>
1682             <p>
1683               Hard links may be permitted at some point in the
1684               future, but would require a fair amount of
1685               work.
1686             </p>
1687           </footnote>, device special files, sockets or setuid or
1688           setgid files.<footnote>
1689               Setgid directories are allowed.
1690           </footnote>
1691         </p>
1692       </sect>
1693
1694       <sect id="debianrules">
1695         <heading>Main building script: <file>debian/rules</file></heading>
1696
1697         <p>
1698           This file must be an executable makefile, and contains the
1699           package-specific recipes for compiling the package and
1700           building binary package(s) from the source.
1701         </p>
1702
1703         <p>
1704           It must start with the line <tt>#!/usr/bin/make -f</tt>,
1705           so that it can be invoked by saying its name rather than
1706           invoking <prgn>make</prgn> explicitly.
1707         </p>
1708
1709         <p>
1710           Since an interactive <file>debian/rules</file> script makes it
1711           impossible to auto-compile that package and also makes it
1712           hard for other people to reproduce the same binary
1713           package, all <em>required targets</em> MUST be
1714           non-interactive. At a minimum, required targets are the
1715           ones called by <prgn>dpkg-buildpackage</prgn>, namely,
1716           <em>clean</em>, <em>binary</em>, <em>binary-arch</em>,
1717           <em>binary-indep</em>, and <em>build</em>. It also follows
1718           that any target that these targets depend on must also be
1719           non-interactive.
1720         </p>
1721
1722         <p>
1723           The targets are as follows (required unless stated otherwise):
1724           <taglist>
1725             <tag><tt>build</tt></tag>
1726             <item>
1727               <p>
1728                 The <tt>build</tt> target should perform all the
1729                 configuration and compilation of the package.
1730                 If a package has an interactive pre-build
1731                 configuration routine, the Debianized source package
1732                 must either be built after this has taken place (so
1733                 that the binary package can be built without rerunning
1734                 the configuration) or the configuration routine
1735                 modified to become non-interactive.  (The latter is
1736                 preferable if there are architecture-specific features
1737                 detected by the configuration routine.)
1738               </p>
1739
1740               <p>
1741                 For some packages, notably ones where the same
1742                 source tree is compiled in different ways to produce
1743                 two binary packages, the <tt>build</tt> target
1744                 does not make much sense.  For these packages it is
1745                 good enough to provide two (or more) targets
1746                 (<tt>build-a</tt> and <tt>build-b</tt> or whatever)
1747                 for each of the ways of building the package, and a
1748                 <tt>build</tt> target that does nothing.  The
1749                 <tt>binary</tt> target will have to build the
1750                 package in each of the possible ways and make the
1751                 binary package out of each.
1752               </p>
1753
1754               <p>
1755                 The <tt>build</tt> target must not do anything
1756                 that might require root privilege.
1757               </p>
1758
1759               <p>
1760                 The <tt>build</tt> target may need to run the
1761                 <tt>clean</tt> target first - see below.
1762               </p>
1763
1764               <p>
1765                 When a package has a configuration and build routine
1766                 which takes a long time, or when the makefiles are
1767                 poorly designed, or when <tt>build</tt> needs to
1768                 run <tt>clean</tt> first, it is a good idea to
1769                 <tt>touch build</tt> when the build process is
1770                 complete.  This will ensure that if <tt>debian/rules
1771                 build</tt> is run again it will not rebuild the whole
1772                 program.<footnote>
1773                     Another common way to do this is for <tt>build</tt>
1774                     to depend on <prgn>build-stamp</prgn> and to do
1775                     nothing else, and for the <prgn>build-stamp</prgn>
1776                     target to do the building and to <tt>touch
1777                     build-stamp</tt> on completion.  This is
1778                     especially useful if the build routine creates a
1779                     file or directory called <tt>build</tt>; in such a
1780                     case, <tt>build</tt> will need to be listed as
1781                     a phony target (i.e., as a dependency of the
1782                     <tt>.PHONY</tt> target).  See the documentation of
1783                     <prgn>make</prgn> for more information on phony
1784                     targets.
1785                 </footnote>
1786               </p>
1787             </item>
1788
1789             <tag><tt>build-arch</tt> (optional),
1790                  <tt>build-indep</tt> (optional)
1791             </tag>
1792             <item>
1793               <p>
1794                 A package may also provide both of the targets
1795                 <tt>build-arch</tt> and <tt>build-indep</tt>.
1796                 The <tt>build-arch</tt> target, if provided, should
1797                 perform all the configuration and compilation required
1798                 for producing all architecture-dependant binary packages
1799                 (those packages for which the body of the
1800                 <tt>Architecture</tt> field in <tt>debian/control</tt>
1801                 is not <tt>all</tt>).
1802                 Similarly, the <tt>build-indep</tt> target, if
1803                 provided, should perform all the configuration and
1804                 compilation required for producing all
1805                 architecture-independent binary packages
1806                 (those packages for which the body of the
1807                 <tt>Architecture</tt> field in <tt>debian/control</tt>
1808                 is <tt>all</tt>).
1809                 The <tt>build</tt> target should depend on those of the
1810                 targets <tt>build-arch</tt> and <tt>build-indep</tt> that
1811                 are provided in the rules file.
1812               </p>
1813
1814               <p>
1815                 If one or both of the targets <tt>build-arch</tt> and
1816                 <tt>build-indep</tt> are not provided, then invoking
1817                 <file>debian/rules</file> with one of the not-provided
1818                 targets as arguments should produce a exit status code
1819                 of 2.  Usually this is provided automatically by make
1820                 if the target is missing.
1821               </p>
1822
1823               <p>
1824                 The <tt>build-arch</tt> and <tt>build-indep</tt> targets
1825                 must not do anything that might require root privilege.
1826               </p>
1827             </item>
1828
1829             <tag><tt>binary</tt>, <tt>binary-arch</tt>,
1830               <tt>binary-indep</tt>
1831             </tag>
1832             <item>
1833               <p>
1834                 The <tt>binary</tt> target must be all that is
1835                 necessary for the user to build the binary package(s)
1836                 produced from this source package.  It is
1837                 split into two parts: <prgn>binary-arch</prgn> builds
1838                 the binary packages which are specific to a particular
1839                 architecture, and <tt>binary-indep</tt> builds
1840                 those which are not.
1841               </p>
1842               <p>
1843                 <tt>binary</tt> may be (and commonly is) a target with
1844                 no commands which simply depends on
1845                 <tt>binary-arch</tt> and <tt>binary-indep</tt>.
1846               </p>
1847               <p>
1848                 Both <tt>binary-*</tt> targets should depend on the
1849                 <tt>build</tt> target, or on the appropriate
1850                 <tt>build-arch</tt> or <tt>build-indep</tt> target, if
1851                 provided, so that the package is built if it has not
1852                 been already.  It should then create the relevant
1853                 binary package(s), using <prgn>dpkg-gencontrol</prgn> to
1854                 make their control files and <prgn>dpkg-deb</prgn> to
1855                 build them and place them in the parent of the top
1856                 level directory.
1857               </p>
1858
1859               <p>
1860                 Both the <tt>binary-arch</tt> and
1861                 <tt>binary-indep</tt> targets <em>must</em> exist.
1862                 If one of them has nothing to do (which will always be
1863                 the case if the source generates only a single binary
1864                 package, whether architecture-dependent or not), it
1865                 must still exist and must always succeed.
1866               </p>
1867
1868               <p>
1869                 The <tt>binary</tt> targets must be invoked as
1870                 root.<footnote>
1871                     The <prgn>fakeroot</prgn> package often allows one
1872                     to build a package correctly even without being
1873                     root.
1874                 </footnote>
1875               </p>
1876             </item>
1877
1878             <tag><tt>clean</tt></tag>
1879             <item>
1880               <p>
1881                 This must undo any effects that the <tt>build</tt>
1882                 and <tt>binary</tt> targets may have had, except
1883                 that it should leave alone any output files created in
1884                 the parent directory by a run of a <tt>binary</tt>
1885                 target.
1886               </p>
1887
1888               <p>
1889                 If a <tt>build</tt> file is touched at the end of
1890                 the <tt>build</tt> target, as suggested above, it
1891                 should be removed as the first action that
1892                 <tt>clean</tt> performs, so that running
1893                 <tt>build</tt> again after an interrupted
1894                 <tt>clean</tt> doesn't think that everything is
1895                 already done.
1896               </p>
1897
1898               <p>
1899                 The <tt>clean</tt> target may need to be
1900                 invoked as root if <tt>binary</tt> has been
1901                 invoked since the last <tt>clean</tt>, or if
1902                 <tt>build</tt> has been invoked as root (since
1903                 <tt>build</tt> may create directories, for
1904                 example).
1905               </p>
1906             </item>
1907
1908             <tag><tt>get-orig-source</tt> (optional)</tag>
1909             <item>
1910               <p>
1911                 This target fetches the most recent version of the
1912                 original source package from a canonical archive site
1913                 (via FTP or WWW, for example), does any necessary
1914                 rearrangement to turn it into the original source
1915                 tar file format described below, and leaves it in the
1916                 current directory.
1917               </p>
1918
1919               <p>
1920                 This target may be invoked in any directory, and
1921                 should take care to clean up any temporary files it
1922                 may have left.
1923               </p>
1924
1925               <p>
1926                 This target is optional, but providing it if
1927                 possible is a good idea.
1928               </p>
1929             </item>
1930
1931             <tag><tt>patch</tt> (optional)</tag>
1932             <item>
1933               <p>
1934                 This target performs whatever additional actions are
1935                 required to make the source ready for editing (unpacking
1936                 additional upstream archives, applying patches, etc.).
1937                 It is recommended to be implemented for any package where
1938                 <tt>dpkg-source -x</tt> does not result in source ready
1939                 for additional modification.  See
1940                 <ref id="readmesource">.
1941               </p>
1942             </item>
1943           </taglist>
1944
1945         <p>
1946           The <tt>build</tt>, <tt>binary</tt> and
1947           <tt>clean</tt> targets must be invoked with the current
1948           directory being the package's top-level directory.
1949         </p>
1950
1951
1952         <p>
1953           Additional targets may exist in <file>debian/rules</file>,
1954           either as published or undocumented interfaces or for the
1955           package's internal use.
1956         </p>
1957
1958         <p>
1959           The architectures we build on and build for are determined
1960           by <prgn>make</prgn> variables using the utility
1961           <qref id="pkg-dpkg-architecture"><prgn>dpkg-architecture</prgn></qref>.
1962           You can determine the
1963           Debian architecture and the GNU style architecture
1964           specification string for the build machine (the machine type
1965           we are building on) as well as for the host machine (the
1966           machine type we are building for).  Here is a list of
1967           supported <prgn>make</prgn> variables:
1968           <list compact="compact">
1969             <item>
1970                 <tt>DEB_*_ARCH</tt> (the Debian architecture)
1971             </item>
1972             <item>
1973                 <tt>DEB_*_GNU_TYPE</tt> (the GNU style architecture
1974                 specification string)
1975             </item>
1976             <item>
1977                 <tt>DEB_*_GNU_CPU</tt> (the CPU part of
1978                 <tt>DEB_*_GNU_TYPE</tt>)
1979             </item>
1980             <item>
1981                 <tt>DEB_*_GNU_SYSTEM</tt> (the System part of
1982                 <tt>DEB_*_GNU_TYPE</tt>)
1983           </list>
1984           where <tt>*</tt> is either <tt>BUILD</tt> for specification of
1985           the build machine or <tt>HOST</tt> for specification of the
1986           host machine.
1987         </p>
1988
1989         <p>
1990           Backward compatibility can be provided in the rules file
1991           by setting the needed variables to suitable default
1992           values; please refer to the documentation of
1993           <prgn>dpkg-architecture</prgn> for details.
1994         </p>
1995
1996         <p>
1997           It is important to understand that the <tt>DEB_*_ARCH</tt>
1998           string only determines which Debian architecture we are
1999           building on or for. It should not be used to get the CPU
2000           or system information; the GNU style variables should be
2001           used for that.
2002         </p>
2003
2004         <sect1 id="debianrules-options">
2005           <heading><file>debian/rules</file> and
2006             <tt>DEB_BUILD_OPTIONS</tt></heading>
2007
2008           <p>
2009             Supporting the standardized environment variable
2010             <tt>DEB_BUILD_OPTIONS</tt> is recommended.  This variable can
2011             contain several flags to change how a package is compiled and
2012             built.  Each flag must be in the form <var>flag</var> or
2013             <var>flag</var>=<var>options</var>.  If multiple flags are
2014             given, they must be separated by whitespace.<footnote>
2015               Some packages support any delimiter, but whitespace is the
2016               easiest to parse inside a makefile and avoids ambiguity with
2017               flag values that contain commas.
2018             </footnote>
2019             <var>flag</var> must start with a lowercase letter
2020             (<tt>a-z</tt>) and consist only of lowercase letters,
2021             numbers (<tt>0-9</tt>), and the characters
2022             <tt>-</tt> and <tt>_</tt> (hyphen and underscore).
2023             <var>options</var> must not contain whitespace.  The same
2024             tag should not be given multiple times with conflicting
2025             values.  Package maintainers may assume that
2026             <tt>DEB_BUILD_OPTIONS</tt> will not contain conflicting tags.
2027           </p>
2028
2029           <p>
2030             The meaning of the following tags has been standardized:
2031             <taglist>
2032               <tag>nocheck</tag>
2033               <item>
2034                   This tag says to not run any build-time test suite
2035                   provided by the package.
2036               </item>
2037               <tag>noopt</tag>
2038               <item>
2039                   The presence of this tag means that the package should
2040                   be compiled with a minimum of optimization.  For C
2041                   programs, it is best to add <tt>-O0</tt> to
2042                   <tt>CFLAGS</tt> (although this is usually the default).
2043                   Some programs might fail to build or run at this level
2044                   of optimization; it may be necessary to use
2045                   <tt>-O1</tt>, for example.
2046               </item>
2047               <tag>nostrip</tag>
2048               <item>
2049                   This tag means that the debugging symbols should not be
2050                   stripped from the binary during installation, so that
2051                   debugging information may be included in the package.
2052               </item>
2053               <tag>parallel=n</tag>
2054               <item>
2055                   This tag means that the package should be built using up
2056                   to <tt>n</tt> parallel processes if the package build
2057                   system supports this.<footnote>
2058                       Packages built with <tt>make</tt> can often implement
2059                       this by passing the <tt>-j</tt><var>n</var> option to
2060                       <tt>make</tt>.
2061                   </footnote>
2062                   If the package build system does not support parallel
2063                   builds, this string must be ignored.  If the package
2064                   build system only supports a lower level of concurrency
2065                   than <var>n</var>, the package should be built using as
2066                   many parallel processes as the package build system
2067                   supports.  It is up to the package maintainer to decide
2068                   whether the package build times are long enough and the
2069                   package build system is robust enough to make supporting
2070                   parallel builds worthwhile.
2071                </item>
2072             </taglist>
2073           </p>
2074
2075           <p>
2076             Unknown flags must be ignored by <file>debian/rules</file>.
2077           </p>
2078
2079           <p>
2080             The following makefile snippet is an example of how one may
2081             implement the build options; you will probably have to
2082             massage this example in order to make it work for your
2083             package.
2084             <example compact="compact">
2085 CFLAGS = -Wall -g
2086 INSTALL = install
2087 INSTALL_FILE    = $(INSTALL) -p    -o root -g root  -m  644
2088 INSTALL_PROGRAM = $(INSTALL) -p    -o root -g root  -m  755
2089 INSTALL_SCRIPT  = $(INSTALL) -p    -o root -g root  -m  755
2090 INSTALL_DIR     = $(INSTALL) -p -d -o root -g root  -m  755
2091
2092 ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
2093     CFLAGS += -O0
2094 else
2095     CFLAGS += -O2
2096 endif
2097 ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
2098     INSTALL_PROGRAM += -s
2099 endif
2100 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
2101     NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
2102     MAKEFLAGS += -j$(NUMJOBS)
2103 endif
2104
2105 build:
2106         # ...
2107 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
2108         # Code to run the package test suite.
2109 endif
2110             </example>
2111           </p>
2112         </sect1>
2113       </sect>
2114
2115 <!-- FIXME: section pkg-srcsubstvars is the same as substvars -->
2116       <sect id="substvars">
2117         <heading>Variable substitutions: <file>debian/substvars</file></heading>
2118
2119         <p>
2120           When <prgn>dpkg-gencontrol</prgn>,
2121           <prgn>dpkg-genchanges</prgn> and <prgn>dpkg-source</prgn>
2122           generate control files they perform variable substitutions
2123           on their output just before writing it.  Variable
2124           substitutions have the form <tt>${<var>variable</var>}</tt>.
2125           The optional file <file>debian/substvars</file> contains
2126           variable substitutions to be used; variables can also be set
2127           directly from <file>debian/rules</file> using the <tt>-V</tt>
2128           option to the source packaging commands, and certain
2129           predefined variables are also available.
2130         </p>
2131
2132         <p>
2133           The <file>debian/substvars</file> file is usually generated and
2134           modified dynamically by <file>debian/rules</file> targets, in
2135           which case it must be removed by the <tt>clean</tt> target.
2136         </p>
2137
2138         <p>
2139           See <manref name="deb-substvars" section="5"> for full
2140           details about source variable substitutions, including the
2141           format of <file>debian/substvars</file>.</p>
2142       </sect>
2143
2144       <sect id="debianwatch">
2145         <heading>Optional upstream source location: <file>debian/watch</file></heading>
2146
2147         <p>
2148           This is an optional, recommended control file for the
2149           <tt>uscan</tt> utility which defines how to automatically
2150           scan ftp or http sites for newly available updates of the
2151           package. This is used by <url id="
2152           http://dehs.alioth.debian.org/"> and other Debian QA tools
2153           to help with quality control and maintenance of the
2154           distribution as a whole.
2155         </p>
2156
2157       </sect>
2158
2159       <sect id="debianfiles">
2160         <heading>Generated files list: <file>debian/files</file></heading>
2161
2162         <p>
2163           This file is not a permanent part of the source tree; it
2164           is used while building packages to record which files are
2165           being generated.  <prgn>dpkg-genchanges</prgn> uses it
2166           when it generates a <file>.changes</file> file.
2167         </p>
2168
2169         <p>
2170           It should not exist in a shipped source package, and so it
2171           (and any backup files or temporary files such as
2172           <file>files.new</file><footnote>
2173               <file>files.new</file> is used as a temporary file by
2174               <prgn>dpkg-gencontrol</prgn> and
2175               <prgn>dpkg-distaddfile</prgn> - they write a new
2176               version of <tt>files</tt> here before renaming it,
2177               to avoid leaving a corrupted copy if an error
2178               occurs.
2179           </footnote>) should be removed by the
2180           <tt>clean</tt> target.  It may also be wise to
2181           ensure a fresh start by emptying or removing it at the
2182           start of the <tt>binary</tt> target.
2183         </p>
2184
2185         <p>
2186           When <prgn>dpkg-gencontrol</prgn> is run for a binary
2187           package, it adds an entry to <file>debian/files</file> for the
2188           <file>.deb</file> file that will be created when <tt>dpkg-deb
2189           --build</tt> is run for that binary package.  So for most
2190           packages all that needs to be done with this file is to
2191           delete it in the <tt>clean</tt> target.
2192         </p>
2193
2194         <p>
2195           If a package upload includes files besides the source
2196           package and any binary packages whose control files were
2197           made with <prgn>dpkg-gencontrol</prgn> then they should be
2198           placed in the parent of the package's top-level directory
2199           and <prgn>dpkg-distaddfile</prgn> should be called to add
2200           the file to the list in <file>debian/files</file>.</p>
2201       </sect>
2202
2203       <sect id="embeddedfiles">
2204         <heading>Convenience copies of code</heading>
2205
2206         <p>
2207           Some software packages include in their distribution convenience
2208           copies of code from other software packages, generally so that
2209           users compiling from source don't have to download multiple
2210           packages.  Debian packages should not make use of these
2211           convenience copies unless the included package is explicitly
2212           intended to be used in this way.<footnote>
2213             For example, parts of the GNU build system work like this.
2214           </footnote>
2215           If the included code is already in the Debian archive in the
2216           form of a library, the Debian packaging should ensure that
2217           binary packages reference the libraries already in Debian and
2218           the convenience copy is not used.  If the included code is not
2219           already in Debian, it should be packaged separately as a
2220           prerequisite if possible.
2221           <footnote>
2222             Having multiple copies of the same code in Debian is
2223             inefficient, often creates either static linking or shared
2224             library conflicts, and, most importantly, increases the
2225             difficulty of handling security vulnerabilities in the
2226             duplicated code.
2227           </footnote>
2228         </p>
2229       </sect>
2230
2231       <sect id="readmesource">
2232         <heading>Source package handling:
2233           <file>debian/README.source</file></heading>
2234
2235         <p>
2236           If running <prgn>dpkg-source -x</prgn> on a source package
2237           doesn't produce the source of the package, ready for editing,
2238           and allow one to make changes and run
2239           <prgn>dpkg-buildpackage</prgn> to produce a modified package
2240           without taking any additional steps, creating a
2241           <file>debian/README.source</file> documentation file is
2242           recommended.  This file should explain how to do all of the
2243           following:
2244             <enumlist>
2245               <item>Generate the fully patched source, in a form ready for
2246               editing, that would be built to create Debian
2247               packages.  Doing this with a <tt>patch</tt> target in
2248               <file>debian/rules</file> is recommended; see
2249               <ref id="debianrules">.</item>
2250               <item>Modify the source and save those modifications so that
2251               they will be applied when building the package.</item>
2252               <item>Remove source modifications that are currently being
2253               applied when building the package.</item>
2254               <item>Optionally, document what steps are necessary to
2255               upgrade the Debian source package to a new upstream version,
2256               if applicable.</item>
2257             </enumlist>
2258           This explanation should include specific commands and mention
2259           any additional required Debian packages.  It should not assume
2260           familiarity with any specific Debian packaging system or patch
2261           management tools.
2262         </p>
2263
2264         <p>
2265           This explanation may refer to a documentation file installed by
2266           one of the package's build dependencies provided that the
2267           referenced documentation clearly explains these tasks and is not
2268           a general reference manual.
2269         </p>
2270
2271         <p>
2272           <file>debian/README.source</file> may also include any other
2273           information that would be helpful to someone modifying the
2274           source package.  Even if the package doesn't fit the above
2275           description, maintainers are encouraged to document in a
2276           <file>debian/README.source</file> file any source package with a
2277           particularly complex or unintuitive source layout or build
2278           system (for example, a package that builds the same source
2279           multiple times to generate different binary packages).
2280         </p>
2281       </sect>
2282     </chapt>
2283
2284
2285     <chapt id="controlfields">
2286       <heading>Control files and their fields</heading>
2287
2288       <p>
2289         The package management system manipulates data represented in
2290         a common format, known as <em>control data</em>, stored in
2291         <em>control files</em>.
2292         Control files are used for source packages, binary packages and
2293         the <file>.changes</file> files which control the installation
2294         of uploaded files<footnote>
2295             <prgn>dpkg</prgn>'s internal databases are in a similar
2296             format.
2297         </footnote>.
2298       </p>
2299
2300       <sect id="controlsyntax">
2301         <heading>Syntax of control files</heading>
2302
2303         <p>
2304           A control file consists of one or more paragraphs of
2305           fields<footnote>
2306                 The paragraphs are also sometimes referred to as stanzas.
2307           </footnote>.
2308           The paragraphs are separated by blank lines.  Some control
2309           files allow only one paragraph; others allow several, in
2310           which case each paragraph usually refers to a different
2311           package.  (For example, in source packages, the first
2312           paragraph refers to the source package, and later paragraphs
2313           refer to binary packages generated from the source.)
2314         </p>
2315
2316         <p>
2317           Each paragraph consists of a series of data fields; each
2318           field consists of the field name, followed by a colon and
2319           then the data/value associated with that field.  It ends at
2320           the end of the (logical) line.  Horizontal whitespace
2321           (spaces and tabs) may occur immediately before or after the
2322           value and is ignored there; it is conventional to put a
2323           single space after the colon.  For example, a field might
2324           be:
2325           <example compact="compact">
2326 Package: libc6
2327           </example>
2328           the field name is <tt>Package</tt> and the field value
2329           <tt>libc6</tt>.
2330         </p>
2331
2332         <p>
2333           Many fields' values may span several lines; in this case
2334           each continuation line must start with a space or a tab.
2335           Any trailing spaces or tabs at the end of individual
2336           lines of a field value are ignored. 
2337         </p>
2338
2339         <p>
2340           In fields where it is specified that lines may not wrap,
2341           only a single line of data is allowed and whitespace is not
2342           significant in a field body. Whitespace must not appear
2343           inside names (of packages, architectures, files or anything
2344           else) or version numbers, or between the characters of
2345           multi-character version relationships.
2346         </p>
2347
2348         <p>
2349           Field names are not case-sensitive, but it is usual to
2350           capitalize the field names using mixed case as shown below.
2351         </p>
2352
2353         <p>
2354           Blank lines, or lines consisting only of spaces and tabs,
2355           are not allowed within field values or between fields - that
2356           would mean a new paragraph.
2357         </p>
2358
2359         <p>
2360           All control files must be encoded in UTF-8.
2361         </p>
2362       </sect>
2363
2364       <sect id="sourcecontrolfiles">
2365         <heading>Source package control files -- <file>debian/control</file></heading>
2366
2367         <p>
2368           The <file>debian/control</file> file contains the most vital
2369           (and version-independent) information about the source package
2370           and about the binary packages it creates.
2371         </p>
2372
2373         <p>
2374           The first paragraph of the control file contains information about
2375           the source package in general. The subsequent sets each describe a
2376           binary package that the source tree builds.
2377         </p>
2378
2379         <p>
2380           The fields in the general paragraph (the first one, for the source
2381           package) are:
2382
2383           <list compact="compact">
2384             <item><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</item>
2385             <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2386             <item><qref id="f-Uploaders"><tt>Uploaders</tt></qref></item>
2387             <item><qref id="f-Section"><tt>Section</tt></qref> (recommended)</item>
2388             <item><qref id="f-Priority"><tt>Priority</tt></qref> (recommended)</item>
2389             <item><qref id="sourcebinarydeps"><tt>Build-Depends</tt> et al</qref></item>
2390             <item><qref id="f-Standards-Version"><tt>Standards-Version</tt></qref> (recommended)</item>
2391             <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2392           </list>
2393         </p>
2394
2395         <p>
2396           The fields in the binary package paragraphs are:
2397
2398           <list compact="compact">
2399             <item><qref id="f-Package"><tt>Package</tt></qref> (mandatory)</item>
2400             <item><qref id="f-Architecture"><tt>Architecture</tt></qref> (mandatory)</item>
2401             <item><qref id="f-Section"><tt>Section</tt></qref> (recommended)</item>
2402             <item><qref id="f-Priority"><tt>Priority</tt></qref> (recommended)</item>
2403             <item><qref id="f-Essential"><tt>Essential</tt></qref></item>
2404             <item><qref id="binarydeps"><tt>Depends</tt> et al</qref></item>
2405             <item><qref id="f-Description"><tt>Description</tt></qref> (mandatory)</item>
2406             <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2407           </list>
2408         </p>
2409
2410         <p>
2411           The syntax and semantics of the fields are described below.
2412         </p>
2413
2414 <!-- stuff -->
2415
2416         <p>
2417           These fields are used by <prgn>dpkg-gencontrol</prgn> to
2418           generate control files for binary packages (see below), by
2419           <prgn>dpkg-genchanges</prgn> to generate the
2420           <tt>.changes</tt> file to accompany the upload, and by
2421           <prgn>dpkg-source</prgn> when it creates the
2422           <file>.dsc</file> source control file as part of a source
2423           archive. Many fields are permitted to span multiple lines in
2424           <file>debian/control</file> but not in any other control
2425           file. These tools are responsible for removing the line
2426           breaks from such fields when using fields from
2427           <file>debian/control</file> to generate other control files.
2428         </p>
2429
2430         <p>
2431           The fields here may contain variable references - their
2432           values will be substituted by <prgn>dpkg-gencontrol</prgn>,
2433           <prgn>dpkg-genchanges</prgn> or <prgn>dpkg-source</prgn>
2434           when they generate output control files.
2435           See <ref id="substvars"> for details.
2436         </p>
2437
2438       </sect>
2439
2440       <sect id="binarycontrolfiles">
2441         <heading>Binary package control files -- <file>DEBIAN/control</file></heading>
2442
2443         <p>
2444           The <file>DEBIAN/control</file> file contains the most vital
2445           (and version-dependent) information about a binary package.
2446         </p>
2447
2448         <p>
2449           The fields in this file are:
2450
2451           <list compact="compact">
2452             <item><qref id="f-Package"><tt>Package</tt></qref> (mandatory)</item>
2453             <item><qref id="f-Source"><tt>Source</tt></qref></item>
2454             <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
2455             <item><qref id="f-Section"><tt>Section</tt></qref> (recommended)</item>
2456             <item><qref id="f-Priority"><tt>Priority</tt></qref> (recommended)</item>
2457             <item><qref id="f-Architecture"><tt>Architecture</tt></qref> (mandatory)</item>
2458             <item><qref id="f-Essential"><tt>Essential</tt></qref></item>
2459             <item><qref id="binarydeps"><tt>Depends</tt> et al</qref></item>
2460             <item><qref id="f-Installed-Size"><tt>Installed-Size</tt></qref></item>
2461             <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2462             <item><qref id="f-Description"><tt>Description</tt></qref> (mandatory)</item>
2463             <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2464           </list>
2465         </p>
2466       </sect>
2467
2468       <sect id="debiansourcecontrolfiles">
2469         <heading>Debian source control files -- <tt>.dsc</tt></heading>
2470
2471         <p>
2472           This file contains a series of fields, identified and
2473           separated just like the fields in the control file of
2474           a binary package.  The fields are listed below; their
2475           syntax is described above, in <ref id="pkg-controlfields">.
2476
2477         <list compact="compact">
2478           <item><qref id="f-Format"><tt>Format</tt></qref> (mandatory)</item>
2479           <item><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</item>
2480           <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
2481           <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2482           <item><qref id="f-Uploaders"><tt>Uploaders</tt></qref></item>
2483           <item><qref id="f-Binary"><tt>Binary</tt></qref></item>
2484           <item><qref id="f-Architecture"><tt>Architecture</tt></qref></item>
2485           <item><qref id="sourcebinarydeps"><tt>Build-Depends</tt> et al</qref></item>
2486           <item><qref id="f-Standards-Version"><tt>Standards-Version</tt></qref> (recommended)</item>
2487           <item><qref id="f-Files"><tt>Files</tt></qref> (mandatory)</item>
2488           <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2489         </list>
2490         </p>
2491
2492         <p>
2493           The source package control file is generated by
2494           <prgn>dpkg-source</prgn> when it builds the source
2495           archive, from other files in the source package,
2496           described above.  When unpacking, it is checked against
2497           the files and directories in the other parts of the
2498           source package.
2499         </p>
2500
2501       </sect>
2502
2503       <sect id="debianchangesfiles">
2504         <heading>Debian changes files -- <file>.changes</file></heading>
2505
2506         <p>
2507           The .changes files are used by the Debian archive maintenance
2508           software to process updates to packages. They contain one
2509           paragraph which contains information from the
2510           <tt>debian/control</tt> file and other data about the
2511           source package gathered via <tt>debian/changelog</tt>
2512           and <tt>debian/rules</tt>.
2513         </p>
2514
2515         <p>
2516           The fields in this file are:
2517
2518           <list compact="compact">
2519             <item><qref id="f-Format"><tt>Format</tt></qref> (mandatory)</item>
2520             <item><qref id="f-Date"><tt>Date</tt></qref> (mandatory)</item>
2521             <item><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</item>
2522             <item><qref id="f-Binary"><tt>Binary</tt></qref> (mandatory)</item>
2523             <item><qref id="f-Architecture"><tt>Architecture</tt></qref> (mandatory)</item>
2524             <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
2525             <item><qref id="f-Distribution"><tt>Distribution</tt></qref> (mandatory)</item>
2526             <item><qref id="f-Urgency"><tt>Urgency</tt></qref> (recommended)</item>
2527             <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2528             <item><qref id="f-Changed-By"><tt>Changed-By</tt></qref></item>
2529             <item><qref id="f-Description"><tt>Description</tt></qref> (mandatory)</item>
2530             <item><qref id="f-Closes"><tt>Closes</tt></qref></item>
2531             <item><qref id="f-Changes"><tt>Changes</tt></qref> (mandatory)</item>
2532             <item><qref id="f-Files"><tt>Files</tt></qref> (mandatory)</item>
2533           </list>
2534         </p>
2535       </sect>
2536
2537       <sect id="controlfieldslist">
2538         <heading>List of fields</heading>
2539
2540         <sect1 id="f-Source">
2541           <heading><tt>Source</tt></heading>
2542
2543           <p>
2544             This field identifies the source package name.
2545           </p>
2546
2547           <p>
2548             In <file>debian/control</file> or a <file>.dsc</file> file,
2549             this field must contain only the name of the source package.
2550           </p>
2551
2552           <p>
2553             In a binary package control file or a <file>.changes</file>
2554             file, the source package name may be followed by a version
2555             number in parentheses<footnote>
2556                 It is customary to leave a space after the package name
2557                 if a version number is specified.
2558             </footnote>.
2559             This version number may be omitted (and is, by
2560             <prgn>dpkg-gencontrol</prgn>) if it has the same value as
2561             the <tt>Version</tt> field of the binary package in
2562             question.  The field itself may be omitted from a binary
2563             package control file when the source package has the same
2564             name and version as the binary package.
2565           </p>
2566         </sect1>
2567
2568         <sect1 id="f-Maintainer">
2569           <heading><tt>Maintainer</tt></heading>
2570
2571           <p>
2572             The package maintainer's name and email address.  The name
2573             should come first, then the email address inside angle
2574             brackets <tt>&lt;&gt</tt> (in RFC822 format).
2575           </p>
2576
2577           <p>
2578             If the maintainer's name contains a full stop then the
2579             whole field will not work directly as an email address due
2580             to a misfeature in the syntax specified in RFC822; a
2581             program using this field as an address must check for this
2582             and correct the problem if necessary (for example by
2583             putting the name in round brackets and moving it to the
2584             end, and bringing the email address forward).
2585           </p>
2586         </sect1>
2587
2588         <sect1 id="f-Uploaders">
2589           <heading><tt>Uploaders</tt></heading>
2590
2591           <p>
2592             List of the names and email addresses of co-maintainers of
2593             the package, if any. If the package has other maintainers
2594             beside the one named in the 
2595             <qref id="f-Maintainer">Maintainer field</qref>, their
2596             names and email addresses should be listed here. The
2597             format is the same as that of the Maintainer tag, and
2598             multiple entries should be comma separated. Currently,
2599             this field is restricted to a single line of data.  This
2600             is an optional field.
2601           </p>
2602           <p>
2603             Any parser that interprets the Uploaders field in
2604             <file>debian/control</file> must permit it to span multiple
2605             lines.  Line breaks in an Uploaders field that spans multiple
2606             lines are not significant and the semantics of the field are
2607             the same as if the line breaks had not been present.
2608           </p>
2609         </sect1>
2610
2611         <sect1 id="f-Changed-By">
2612           <heading><tt>Changed-By</tt></heading>
2613
2614           <p>
2615             The name and email address of the person who changed the
2616             said package. Usually the name of the maintainer.
2617             All the rules for the Maintainer field apply here, too.
2618           </p>
2619         </sect1>
2620
2621         <sect1 id="f-Section">
2622           <heading><tt>Section</tt></heading>
2623
2624           <p>
2625             This field specifies an application area into which the package
2626             has been classified. See <ref id="subsections">.
2627           </p>
2628
2629           <p>
2630             When it appears in the <file>debian/control</file> file,
2631             it gives the value for the subfield of the same name in
2632             the <tt>Files</tt> field of the <file>.changes</file> file.
2633             It also gives the default for the same field in the binary
2634             packages.
2635           </p>
2636         </sect1>
2637
2638         <sect1 id="f-Priority">
2639           <heading><tt>Priority</tt></heading>
2640
2641           <p>
2642             This field represents how important that it is that the user
2643             have the package installed. See <ref id="priorities">.
2644           </p>
2645
2646           <p>
2647             When it appears in the <file>debian/control</file> file,
2648             it gives the value for the subfield of the same name in
2649             the <tt>Files</tt> field of the <file>.changes</file> file.
2650             It also gives the default for the same field in the binary
2651             packages.
2652           </p>
2653         </sect1>
2654
2655         <sect1 id="f-Package">
2656           <heading><tt>Package</tt></heading>
2657
2658           <p>
2659             The name of the binary package.
2660           </p>
2661
2662           <p>
2663             Package names must consist only of lower case letters
2664             (<tt>a-z</tt>), digits (<tt>0-9</tt>), plus (<tt>+</tt>)
2665             and minus (<tt>-</tt>) signs, and periods (<tt>.</tt>).
2666             They must be at least two characters long and must start
2667             with an alphanumeric character.
2668           </p>
2669         </sect1>
2670
2671         <sect1 id="f-Architecture">
2672           <heading><tt>Architecture</tt></heading>
2673
2674           <p>
2675             Depending on context and the control file used, the
2676             <tt>Architecture</tt> field can include the following sets of
2677             values:
2678             <list>
2679                 <item>A unique single word identifying a Debian machine
2680                       architecture, see <ref id="arch-spec">.
2681                 <item><tt>all</tt>, which indicates an
2682                       architecture-independent package.
2683                 <item><tt>any</tt>, which indicates a package available
2684                       for building on any architecture.
2685                 <item><tt>source</tt>, which indicates a source package.
2686             </list>
2687           </p>
2688
2689           <p>
2690             In the main <file>debian/control</file> file in the source
2691             package, or in the source package control file
2692             <file>.dsc</file>, one may specify a list of architectures
2693             separated by spaces, or the special values <tt>any</tt> or
2694             <tt>all</tt>.
2695           </p>
2696
2697           <p>
2698             Specifying <tt>any</tt> indicates that the source package
2699             isn't dependent on any particular architecture and should
2700             compile fine on any one. The produced binary package(s)
2701             will be specific to whatever the current build architecture
2702             is.<footnote>
2703                 This is the most often used setting, and is recommended
2704                 for new packages that aren't <tt>Architecture: all</tt>.
2705             </footnote>
2706           </p>
2707
2708           <p>
2709             Specifying a list of architectures indicates that the source
2710             will build an architecture-dependent package, and will only
2711             work correctly on the listed architectures.<footnote>
2712                 This is a setting used for a minority of cases where the
2713                 program is not portable. Generally, it should not be used
2714                 for new packages.
2715             </footnote>
2716           </p>
2717
2718           <p>
2719             In a <file>.changes</file> file, the <tt>Architecture</tt>
2720             field lists the architecture(s) of the package(s)
2721             currently being uploaded.  This will be a list; if the
2722             source for the package is also being uploaded, the special
2723             entry <tt>source</tt> is also present.
2724           </p>
2725
2726           <p>
2727             See <ref id="debianrules"> for information how to get the
2728             architecture for the build process.
2729           </p>
2730         </sect1>
2731
2732         <sect1 id="f-Essential">
2733           <heading><tt>Essential</tt></heading>
2734
2735           <p>
2736             This is a boolean field which may occur only in the
2737             control file of a binary package or in a per-package fields
2738             paragraph of a main source control data file.
2739           </p>
2740
2741           <p>
2742             If set to <tt>yes</tt> then the package management system
2743             will refuse to remove the package (upgrading and replacing
2744             it is still possible). The other possible value is <tt>no</tt>,
2745             which is the same as not having the field at all.
2746           </p>
2747         </sect1>
2748
2749         <sect1>
2750           <heading>Package interrelationship fields:
2751             <tt>Depends</tt>, <tt>Pre-Depends</tt>,
2752             <tt>Recommends</tt>, <tt>Suggests</tt>,
2753             <tt>Breaks</tt>, <tt>Conflicts</tt>,
2754             <tt>Provides</tt>, <tt>Replaces</tt>, <tt>Enhances</tt>
2755           </heading>
2756
2757           <p>
2758             These fields describe the package's relationships with
2759             other packages.  Their syntax and semantics are described
2760             in <ref id="relationships">.</p>
2761         </sect1>
2762
2763         <sect1 id="f-Standards-Version">
2764           <heading><tt>Standards-Version</tt></heading>
2765
2766           <p>
2767             The most recent version of the standards (the policy
2768             manual and associated texts) with which the package
2769             complies.
2770           </p>
2771
2772           <p>
2773             The version number has four components: major and minor
2774             version number and major and minor patch level.  When the
2775             standards change in a way that requires every package to
2776             change the major number will be changed.  Significant
2777             changes that will require work in many packages will be
2778             signaled by a change to the minor number.  The major patch
2779             level will be changed for any change to the meaning of the
2780             standards, however small; the minor patch level will be
2781             changed when only cosmetic, typographical or other edits
2782             are made which neither change the meaning of the document
2783             nor affect the contents of packages.
2784           </p>
2785
2786           <p>
2787             Thus only the first three components of the policy version
2788             are significant in the <em>Standards-Version</em> control
2789             field, and so either these three components or the all
2790             four components may be specified.<footnote>
2791                 In the past, people specified the full version number
2792                 in the Standards-Version field, for example "2.3.0.0".
2793                 Since minor patch-level changes don't introduce new
2794                 policy, it was thought it would be better to relax
2795                 policy and only require the first 3 components to be
2796                 specified, in this example "2.3.0".  All four
2797                 components may still be used if someone wishes to do so.
2798             </footnote>
2799           </p>
2800
2801         </sect1>
2802
2803         <sect1 id="f-Version">
2804           <heading><tt>Version</tt></heading>
2805
2806           <p>
2807             The version number of a package. The format is:
2808             [<var>epoch</var><tt>:</tt>]<var>upstream_version</var>[<tt>-</tt><var>debian_revision</var>]
2809           </p>
2810
2811           <p>
2812             The three components here are:
2813             <taglist>
2814               <tag><var>epoch</var></tag>
2815               <item>
2816                 <p>
2817                   This is a single (generally small) unsigned integer.  It
2818                   may be omitted, in which case zero is assumed.  If it is
2819                   omitted then the <var>upstream_version</var> may not
2820                   contain any colons.
2821                 </p>
2822
2823                 <p>
2824                   It is provided to allow mistakes in the version numbers
2825                   of older versions of a package, and also a package's
2826                   previous version numbering schemes, to be left behind.
2827                 </p>
2828               </item>
2829
2830               <tag><var>upstream_version</var></tag>
2831               <item>
2832                 <p>
2833                   This is the main part of the version number.  It is
2834                   usually the version number of the original ("upstream")
2835                   package from which the <file>.deb</file> file has been made,
2836                   if this is applicable.  Usually this will be in the same
2837                   format as that specified by the upstream author(s);
2838                   however, it may need to be reformatted to fit into the
2839                   package management system's format and comparison
2840                   scheme.
2841                 </p>
2842
2843                 <p>
2844                   The comparison behavior of the package management system
2845                   with respect to the <var>upstream_version</var> is
2846                   described below.  The <var>upstream_version</var>
2847                   portion of the version number is mandatory.
2848                 </p>
2849
2850                 <p>
2851                   The <var>upstream_version</var> may contain only
2852                   alphanumerics<footnote>
2853                         Alphanumerics are <tt>A-Za-z0-9</tt> only.
2854                   </footnote>
2855                   and the characters <tt>.</tt> <tt>+</tt> <tt>-</tt>
2856                   <tt>:</tt> <tt>~</tt> (full stop, plus, hyphen, colon,
2857                   tilde) and should start with a digit.  If there is no
2858                   <var>debian_revision</var> then hyphens are not allowed;
2859                   if there is no <var>epoch</var> then colons are not
2860                   allowed.
2861                 </p>
2862               </item>
2863
2864               <tag><var>debian_revision</var></tag>
2865               <item>
2866                 <p>
2867                   This part of the version number specifies the version of
2868                   the Debian package based on the upstream version.  It
2869                   may contain only alphanumerics and the characters
2870                   <tt>+</tt> <tt>.</tt> <tt>~</tt> (plus, full stop,
2871                   tilde) and is compared in the same way as the
2872                   <var>upstream_version</var> is.
2873                 </p>
2874
2875                 <p>
2876                   It is optional; if it isn't present then the
2877                   <var>upstream_version</var> may not contain a hyphen.
2878                   This format represents the case where a piece of
2879                   software was written specifically to be turned into a
2880                   Debian package, and so there is only one "debianisation"
2881                   of it and therefore no revision indication is required.
2882                 </p>
2883
2884                 <p>
2885                   It is conventional to restart the
2886                   <var>debian_revision</var> at <tt>1</tt> each time the
2887                   <var>upstream_version</var> is increased.
2888                 </p>
2889
2890                 <p>
2891                   The package management system will break the version
2892                   number apart at the last hyphen in the string (if there
2893                   is one) to determine the <var>upstream_version</var> and
2894                   <var>debian_revision</var>.  The absence of a
2895                   <var>debian_revision</var> is equivalent to a
2896                   <var>debian_revision</var> of <tt>0</tt>.
2897                 </p>
2898               </item>
2899             </taglist>
2900           </p>
2901
2902           <p>
2903             When comparing two version numbers, first the <var>epoch</var>
2904             of each are compared, then the <var>upstream_version</var> if
2905             <var>epoch</var> is equal, and then <var>debian_revision</var>
2906             if <var>upstream_version</var> is also equal.
2907             <var>epoch</var> is compared numerically.  The
2908             <var>upstream_version</var> and <var>debian_revision</var>
2909             parts are compared by the package management system using the
2910             following algorithm:
2911           </p>
2912
2913           <p>
2914             The strings are compared from left to right.
2915           </p>
2916
2917           <p>
2918             First the initial part of each string consisting entirely of
2919             non-digit characters is determined.  These two parts (one of
2920             which may be empty) are compared lexically.  If a difference
2921             is found it is returned.  The lexical comparison is a
2922             comparison of ASCII values modified so that all the letters
2923             sort earlier than all the non-letters and so that a tilde
2924             sorts before anything, even the end of a part.  For example,
2925             the following parts are in sorted order from earliest to
2926             latest: <tt>~~</tt>, <tt>~~a</tt>, <tt>~</tt>, the empty part,
2927             <tt>a</tt>.<footnote>
2928               One common use of <tt>~</tt> is for upstream pre-releases.
2929               For example, <tt>1.0~beta1~svn1245</tt> sorts earlier than
2930               <tt>1.0~beta1</tt>, which sorts earlier than <tt>1.0</tt>.
2931             </footnote>
2932           </p>
2933
2934           <p>
2935             Then the initial part of the remainder of each string which
2936             consists entirely of digit characters is determined.  The
2937             numerical values of these two parts are compared, and any
2938             difference found is returned as the result of the comparison.
2939             For these purposes an empty string (which can only occur at
2940             the end of one or both version strings being compared) counts
2941             as zero.
2942           </p>
2943
2944           <p>
2945             These two steps (comparing and removing initial non-digit
2946             strings and initial digit strings) are repeated until a
2947             difference is found or both strings are exhausted.
2948           </p>
2949
2950           <p>
2951             Note that the purpose of epochs is to allow us to leave behind
2952             mistakes in version numbering, and to cope with situations
2953             where the version numbering scheme changes.  It is
2954             <em>not</em> intended to cope with version numbers containing
2955             strings of letters which the package management system cannot
2956             interpret (such as <tt>ALPHA</tt> or <tt>pre-</tt>), or with
2957             silly orderings (the author of this manual has heard of a
2958             package whose versions went <tt>1.1</tt>, <tt>1.2</tt>,
2959             <tt>1.3</tt>, <tt>1</tt>, <tt>2.1</tt>, <tt>2.2</tt>,
2960             <tt>2</tt> and so forth).
2961           </p>
2962         </sect1>
2963
2964         <sect1 id="f-Description">
2965           <heading><tt>Description</tt></heading>
2966
2967           <p>
2968             In a source or binary control file, the <tt>Description</tt>
2969             field contains a description of the binary package, consisting
2970             of two parts, the synopsis or the short description, and the
2971             long description. The field's format is as follows:
2972           </p>
2973
2974           <p>
2975 <example>
2976         Description: &lt;single line synopsis&gt;
2977          &lt;extended description over several lines&gt;
2978 </example>
2979           </p>
2980
2981           <p>
2982             The lines in the extended description can have these formats:
2983           </p>
2984
2985           <p><list>
2986
2987             <item>
2988               Those starting with a single space are part of a paragraph.
2989               Successive lines of this form will be word-wrapped when
2990               displayed. The leading space will usually be stripped off.
2991             </item>
2992
2993             <item>
2994               Those starting with two or more spaces. These will be
2995               displayed verbatim. If the display cannot be panned
2996               horizontally, the displaying program will line wrap them "hard"
2997               (i.e., without taking account of word breaks). If it can they
2998               will be allowed to trail off to the right. None, one or two
2999               initial spaces may be deleted, but the number of spaces
3000               deleted from each line will be the same (so that you can have
3001               indenting work correctly, for example).
3002             </item>
3003
3004             <item>
3005               Those containing a single space followed by a single full stop
3006               character. These are rendered as blank lines. This is the
3007               <em>only</em> way to get a blank line<footnote>
3008                 Completely empty lines will not be rendered as blank lines.
3009                 Instead, they will cause the parser to think you're starting
3010                 a whole new record in the control file, and will therefore
3011                 likely abort with an error.
3012               </footnote>.
3013             </item>
3014
3015             <item>
3016               Those containing a space, a full stop and some more characters.
3017               These are for future expansion. Do not use them.
3018             </item>
3019
3020           </list></p>
3021
3022           <p>
3023             Do not use tab characters.  Their effect is not predictable.
3024           </p>
3025
3026           <p>
3027             See <ref id="descriptions"> for further information on this.
3028           </p>
3029
3030           <p>
3031             In a <file>.changes</file> file, the <tt>Description</tt> field
3032             contains a summary of the descriptions for the packages being
3033             uploaded.
3034           </p>
3035
3036           <p>
3037             The part of the field before the first newline is empty;
3038             thereafter each line has the name of a binary package and
3039             the summary description line from that binary package.
3040             Each line is indented by one space.
3041           </p>
3042
3043         </sect1>
3044
3045         <sect1 id="f-Distribution">
3046           <heading><tt>Distribution</tt></heading>
3047
3048           <p>
3049             In a <file>.changes</file> file or parsed changelog output
3050             this contains the (space-separated) name(s) of the
3051             distribution(s) where this version of the package should
3052             be installed.  Valid distributions are determined by the
3053             archive maintainers.<footnote>
3054                 Current distribution names are:
3055                 <taglist compact="compact">
3056                   <tag><em>stable</em></tag>
3057                   <item>
3058                       This is the current "released" version of Debian
3059                       GNU/Linux.  Once the distribution is
3060                       <em>stable</em> only security fixes and other
3061                       major bug fixes are allowed. When changes are
3062                       made to this distribution, the release number is
3063                       increased (for example: 2.2r1 becomes 2.2r2 then
3064                       2.2r3, etc).
3065                   </item>
3066
3067                   <tag><em>unstable</em></tag>
3068                   <item>
3069                       This distribution value refers to the
3070                       <em>developmental</em> part of the Debian
3071                       distribution tree. New packages, new upstream
3072                       versions of packages and bug fixes go into the
3073                       <em>unstable</em> directory tree. Download from
3074                       this distribution at your own risk.
3075                   </item>
3076
3077                   <tag><em>testing</em></tag>
3078                   <item>
3079                       This distribution value refers to the
3080                       <em>testing</em> part of the Debian distribution
3081                       tree.  It receives its packages from the
3082                       unstable distribution after a short time lag to
3083                       ensure that there are no major issues with the
3084                       unstable packages.  It is less prone to breakage
3085                       than unstable, but still risky.  It is not
3086                       possible to upload packages directly to
3087                       <em>testing</em>.
3088                   </item>
3089
3090                   <tag><em>frozen</em></tag>
3091                   <item>
3092                       From time to time, the <em>testing</em>
3093                       distribution enters a state of "code-freeze" in
3094                       anticipation of release as a <em>stable</em>
3095                       version. During this period of testing only
3096                       fixes for existing or newly-discovered bugs will
3097                       be allowed.  The exact details of this stage are
3098                       determined by the Release Manager.
3099                   </item>
3100
3101                   <tag><em>experimental</em></tag>
3102                   <item>
3103                       The packages with this distribution value are
3104                       deemed by their maintainers to be high
3105                       risk. Oftentimes they represent early beta or
3106                       developmental packages from various sources that
3107                       the maintainers want people to try, but are not
3108                       ready to be a part of the other parts of the
3109                       Debian distribution tree. Download at your own
3110                       risk.
3111                   </item>
3112                 </taglist>
3113
3114                 <p>
3115                   You should list <em>all</em> distributions that the
3116                   package should be installed into.
3117                 </p>
3118
3119                 <p>
3120                   More information is available in the Debian Developer's
3121                   Reference, section "The Debian archive".
3122                 </p>
3123             </footnote>
3124           </p>
3125         </sect1>
3126
3127         <sect1 id="f-Date">
3128           <heading><tt>Date</tt></heading>
3129
3130           <p>
3131             This field includes the date the package was built or last edited.
3132           </p>
3133
3134           <p>
3135             The value of this field is usually extracted from the
3136             <file>debian/changelog</file> file - see
3137             <ref id="dpkgchangelog">).
3138           </p>
3139         </sect1>
3140
3141         <sect1 id="f-Format">
3142           <heading><tt>Format</tt></heading>
3143
3144           <p>
3145             This field specifies a format revision for the file.
3146             The most current format described in the Policy Manual
3147             is version <strong>1.5</strong>.  The syntax of the
3148             format value is the same as that of a package version
3149             number except that no epoch or Debian revision is allowed
3150             - see <ref id="f-Version">.
3151           </p>
3152         </sect1>
3153
3154         <sect1 id="f-Urgency">
3155           <heading><tt>Urgency</tt></heading>
3156
3157           <p>
3158             This is a description of how important it is to upgrade to
3159             this version from previous ones.  It consists of a single
3160             keyword taking one of the values <tt>low</tt>,
3161             <tt>medium</tt>, <tt>high</tt>, <tt>emergency</tt>, or
3162             <tt>critical</tt><footnote>
3163               Other urgency values are supported with configuration
3164               changes in the archive software but are not used in Debian.
3165               The urgency affects how quickly a package will be considered
3166               for inclusion into the <tt>testing</tt> distribution and
3167               gives an indication of the importance of any fixes included
3168               in the upload.  <tt>Emergency</tt> and <tt>critical</tt> are
3169               treated as synonymous.
3170             </footnote> (not case-sensitive) followed by an optional
3171             commentary (separated by a space) which is usually in
3172             parentheses.  For example:
3173
3174             <example>
3175   Urgency: low (HIGH for users of diversions)
3176             </example>
3177
3178           </p>
3179
3180           <p>
3181             The value of this field is usually extracted from the
3182             <file>debian/changelog</file> file - see
3183             <ref id="dpkgchangelog">.
3184           </p>
3185         </sect1>
3186
3187         <sect1 id="f-Changes">
3188           <heading><tt>Changes</tt></heading>
3189
3190           <p>
3191             This field contains the human-readable changes data, describing
3192             the differences between the last version and the current one.
3193           </p>
3194
3195           <p>
3196             There should be nothing in this field before the first
3197             newline; all the subsequent lines must be indented by at
3198             least one space; blank lines must be represented by a line
3199             consisting only of a space and a full stop.
3200           </p>
3201
3202           <p>
3203             The value of this field is usually extracted from the
3204             <file>debian/changelog</file> file - see
3205             <ref id="dpkgchangelog">).
3206           </p>
3207
3208           <p>
3209             Each version's change information should be preceded by a
3210             "title" line giving at least the version, distribution(s)
3211             and urgency, in a human-readable way.
3212           </p>
3213
3214           <p>
3215             If data from several versions is being returned the entry
3216             for the most recent version should be returned first, and
3217             entries should be separated by the representation of a
3218             blank line (the "title" line may also be followed by the
3219             representation of blank line).
3220           </p>
3221         </sect1>
3222
3223         <sect1 id="f-Binary">
3224           <heading><tt>Binary</tt></heading>
3225
3226           <p>
3227             This field is a list of binary packages.
3228           </p>
3229
3230           <p>
3231             When it appears in the <file>.dsc</file> file it is the list
3232             of binary packages which a source package can produce.  It
3233             does not necessarily produce all of these binary packages
3234             for every architecture.  The source control file doesn't
3235             contain details of which architectures are appropriate for
3236             which of the binary packages.
3237           </p>
3238
3239           <p>
3240             When it appears in a <file>.changes</file> file it lists the
3241             names of the binary packages actually being uploaded.
3242           </p>
3243
3244           <p>
3245             The syntax is a list of binary packages separated by
3246             commas<footnote>
3247                 A space after each comma is conventional.
3248             </footnote>. Currently the packages must be separated using
3249             only spaces in the <file>.changes</file> file.
3250           </p>
3251         </sect1>
3252
3253         <sect1 id="f-Installed-Size">
3254           <heading><tt>Installed-Size</tt></heading>
3255
3256           <p>
3257             This field appears in the control files of binary
3258             packages, and in the <file>Packages</file> files.  It gives
3259             the total amount of disk space required to install the
3260             named package.
3261           </p>
3262
3263           <p>
3264             The disk space is represented in kilobytes as a simple
3265             decimal number.
3266           </p>
3267         </sect1>
3268
3269         <sect1 id="f-Files">
3270           <heading><tt>Files</tt></heading>
3271
3272           <p>
3273             This field contains a list of files with information about
3274             each one.  The exact information and syntax varies with
3275             the context.  In all cases the part of the field
3276             contents on the same line as the field name is empty.  The
3277             remainder of the field is one line per file, each line
3278             being indented by one space and containing a number of
3279             sub-fields separated by spaces.
3280           </p>
3281
3282           <p>
3283             In the <file>.dsc</file> file, each line contains the MD5
3284             checksum, size and filename of the tar file and (if applicable)
3285             diff file which make up the remainder of the source
3286             package<footnote>
3287                 That is, the parts which are not the <tt>.dsc</tt>.
3288             </footnote>.
3289             The exact forms of the filenames are described
3290             in <ref id="pkg-sourcearchives">.
3291           </p>
3292
3293           <p>
3294             In the <file>.changes</file> file this contains one line per
3295             file being uploaded.  Each line contains the MD5 checksum,
3296             size, section and priority and the filename.
3297             The <qref id="f-Section">section</qref>
3298             and <qref id="f-Priority">priority</qref>
3299             are the values of the corresponding fields in
3300             the main source control file.  If no section or priority is
3301             specified then <tt>-</tt> should be used, though section
3302             and priority values must be specified for new packages to
3303             be installed properly.
3304           </p>
3305
3306           <p>
3307             The special value <tt>byhand</tt> for the section in a
3308             <tt>.changes</tt> file indicates that the file in question
3309             is not an ordinary package file and must by installed by
3310             hand by the distribution maintainers.  If the section is
3311             <tt>byhand</tt> the priority should be <tt>-</tt>.
3312           </p>
3313
3314           <p>
3315             If a new Debian revision of a package is being shipped and
3316             no new original source archive is being distributed the
3317             <tt>.dsc</tt> must still contain the <tt>Files</tt> field
3318             entry for the original source archive
3319             <file><var>package</var>-<var>upstream-version</var>.orig.tar.gz</file>,
3320             but the <file>.changes</file> file should leave it out.  In
3321             this case the original source archive on the distribution
3322             site must match exactly, byte-for-byte, the original
3323             source archive which was used to generate the
3324             <file>.dsc</file> file and diff which are being uploaded.</p>
3325         </sect1>
3326
3327         <sect1 id="f-Closes">
3328           <heading><tt>Closes</tt></heading>
3329
3330           <p>
3331             A space-separated list of bug report numbers that the upload
3332             governed by the .changes file closes.
3333           </p>
3334         </sect1>
3335
3336         <sect1 id="f-Homepage">
3337           <heading><tt>Homepage</tt></heading>
3338
3339           <p>
3340             The URL of the web site for this package, preferably (when
3341             applicable) the site from which the original source can be
3342             obtained and any additional upstream documentation or
3343             information may be found.  The content of this field is a
3344             simple URL without any surrounding characters such as
3345             <tt>&lt;&gt;</tt>.
3346           </p>
3347         </sect1>
3348
3349       </sect>
3350
3351       <sect>
3352         <heading>User-defined fields</heading>
3353
3354         <p>
3355           Additional user-defined fields may be added to the
3356           source package control file.  Such fields will be
3357           ignored, and not copied to (for example) binary or
3358           source package control files or upload control files.
3359         </p>
3360
3361         <p>
3362           If you wish to add additional unsupported fields to
3363           these output files you should use the mechanism
3364           described here.
3365         </p>
3366
3367         <p>
3368           Fields in the main source control information file with
3369           names starting <tt>X</tt>, followed by one or more of
3370           the letters <tt>BCS</tt> and a hyphen <tt>-</tt>, will
3371           be copied to the output files.  Only the part of the
3372           field name after the hyphen will be used in the output
3373           file.  Where the letter <tt>B</tt> is used the field
3374           will appear in binary package control files, where the
3375           letter <tt>S</tt> is used in source package control
3376           files and where <tt>C</tt> is used in upload control
3377           (<tt>.changes</tt>) files.
3378         </p>
3379
3380         <p>
3381           For example, if the main source information control file
3382           contains the field
3383           <example>
3384   XBS-Comment: I stand between the candle and the star.
3385           </example>
3386           then the binary and source package control files will contain the
3387           field
3388           <example>
3389   Comment: I stand between the candle and the star.
3390           </example>
3391         </p>
3392
3393       </sect>
3394
3395     </chapt>
3396
3397
3398     <chapt id="maintainerscripts">
3399       <heading>Package maintainer scripts and installation procedure</heading>
3400
3401       <sect>
3402         <heading>Introduction to package maintainer scripts</heading>
3403
3404         <p>
3405           It is possible to supply scripts as part of a package which
3406           the package management system will run for you when your
3407           package is installed, upgraded or removed.
3408         </p>
3409
3410         <p>
3411           These scripts are the files <prgn>preinst</prgn>,
3412           <prgn>postinst</prgn>, <prgn>prerm</prgn> and
3413           <prgn>postrm</prgn> in the control area of the package.
3414           They must be proper executable files; if they are scripts
3415           (which is recommended), they must start with the usual
3416           <tt>#!</tt> convention.  They should be readable and
3417           executable by anyone, and must not be world-writable.
3418         </p>
3419
3420         <p>
3421           The package management system looks at the exit status from
3422           these scripts.  It is important that they exit with a
3423           non-zero status if there is an error, so that the package
3424           management system can stop its processing.  For shell
3425           scripts this means that you <em>almost always</em> need to
3426           use <tt>set -e</tt> (this is usually true when writing shell
3427           scripts, in fact).  It is also important, of course, that
3428           they don't exit with a non-zero status if everything went
3429           well.
3430         </p>
3431
3432         <p>
3433           Additionally, packages interacting with users using
3434           <tt>debconf</tt> in the <prgn>postinst</prgn> script should
3435           install a <prgn>config</prgn> script  in the control area,
3436           see <ref id="maintscriptprompt"> for details.
3437         </p>
3438
3439         <p>
3440           When a package is upgraded a combination of the scripts from
3441           the old and new packages is called during the upgrade
3442           procedure.  If your scripts are going to be at all
3443           complicated you need to be aware of this, and may need to
3444           check the arguments to your scripts.
3445         </p>
3446
3447         <p>
3448           Broadly speaking the <prgn>preinst</prgn> is called before
3449           (a particular version of) a package is installed, and the
3450           <prgn>postinst</prgn> afterwards; the <prgn>prerm</prgn>
3451           before (a version of) a package is removed and the
3452           <prgn>postrm</prgn> afterwards.
3453         </p>
3454
3455         <p>
3456           Programs called from maintainer scripts should not normally
3457           have a path prepended to them. Before installation is
3458           started, the package management system checks to see if the
3459           programs <prgn>ldconfig</prgn>,
3460           <prgn>start-stop-daemon</prgn>, <prgn>install-info</prgn>,
3461           and <prgn>update-rc.d</prgn> can be found via the
3462           <tt>PATH</tt> environment variable. Those programs, and any
3463           other program that one would expect to be in the
3464           <tt>PATH</tt>, should thus be invoked without an absolute
3465           pathname. Maintainer scripts should also not reset the
3466           <tt>PATH</tt>, though they might choose to modify it by
3467           prepending or appending package-specific directories. These
3468           considerations really apply to all shell scripts.</p>
3469       </sect>
3470
3471       <sect id="idempotency">
3472         <heading>Maintainer scripts idempotency</heading>
3473
3474         <p>
3475           It is necessary for the error recovery procedures that the
3476           scripts be idempotent.  This means that if it is run
3477           successfully, and then it is called again, it doesn't bomb
3478           out or cause any harm, but just ensures that everything is
3479           the way it ought to be.  If the first call failed, or
3480           aborted half way through for some reason, the second call
3481           should merely do the things that were left undone the first
3482           time, if any, and exit with a success status if everything
3483           is OK.<footnote>
3484               This is so that if an error occurs, the user interrupts
3485               <prgn>dpkg</prgn> or some other unforeseen circumstance
3486               happens you don't leave the user with a badly-broken
3487               package when <prgn>dpkg</prgn> attempts to repeat the
3488               action.
3489           </footnote>
3490         </p>
3491       </sect>
3492
3493       <sect id="controllingterminal">
3494         <heading>Controlling terminal for maintainer scripts</heading>
3495
3496         <p>
3497           The maintainer scripts are guaranteed to run with a
3498           controlling terminal and can interact with the user.
3499           Because these scripts may be executed with standard output
3500           redirected into a pipe for logging purposes, Perl scripts
3501           should set unbuffered output by setting <tt>$|=1</tt> so
3502           that the output is printed immediately rather than being
3503           buffered.
3504         </p>
3505       </sect>
3506       <sect id="exitstatus">
3507         <heading>Exit status</heading>
3508
3509         <p>
3510           Each script must return a zero exit status for
3511           success, or a nonzero one for failure, since the package
3512           management system looks for the exit status of these scripts
3513           and determines what action to take next based on that datum.
3514         </p>
3515       </sect>
3516
3517       <sect id="mscriptsinstact"><heading>Summary of ways maintainer
3518           scripts are called
3519         </heading>
3520
3521         <p>
3522           <list compact="compact">
3523             <item>
3524               <var>new-preinst</var> <tt>install</tt>
3525             </item>
3526             <item>
3527               <var>new-preinst</var> <tt>install</tt> <var>old-version</var>
3528             </item>
3529             <item>
3530                 <var>new-preinst</var> <tt>upgrade</tt> <var>old-version</var>
3531             </item>
3532             <item>
3533                 <var>old-preinst</var> <tt>abort-upgrade</tt>
3534                 <var>new-version</var>
3535             </item>
3536           </list>
3537
3538         <p>
3539           <list compact="compact">
3540             <item>
3541                 <var>postinst</var> <tt>configure</tt>
3542                 <var>most-recently-configured-version</var>
3543             </item>
3544             <item>
3545                 <var>old-postinst</var> <tt>abort-upgrade</tt>
3546                 <var>new-version</var>
3547             </item>
3548             <item>
3549                 <var>conflictor's-postinst</var> <tt>abort-remove</tt>
3550                 <tt>in-favour</tt> <var>package</var>
3551                 <var>new-version</var>
3552             </item>
3553             <item>
3554                 <var>postinst</var> <tt>abort-remove</tt>
3555             </item>
3556             <item>
3557                 <var>deconfigured's-postinst</var>
3558                 <tt>abort-deconfigure</tt> <tt>in-favour</tt>
3559                 <var>failed-install-package</var> <var>version</var>
3560                 [<tt>removing</tt> <var>conflicting-package</var>
3561                 <var>version</var>]
3562             </item>
3563           </list>
3564
3565         <p>
3566           <list compact="compact">
3567             <item>
3568                 <var>prerm</var> <tt>remove</tt>
3569             </item>
3570             <item>
3571                 <var>old-prerm</var> <tt>upgrade</tt>
3572                 <var>new-version</var>
3573             </item>
3574             <item>
3575                 <var>new-prerm</var> <tt>failed-upgrade</tt>
3576                 <var>old-version</var>
3577             </item>
3578             <item>
3579                 <var>conflictor's-prerm</var> <tt>remove</tt>
3580                 <tt>in-favour</tt> <var>package</var>
3581                 <var>new-version</var>
3582             </item>
3583             <item>
3584                 <var>deconfigured's-prerm</var> <tt>deconfigure</tt>
3585                 <tt>in-favour</tt> <var>package-being-installed</var>
3586                 <var>version</var> [<tt>removing</tt>
3587                 <var>conflicting-package</var>
3588                 <var>version</var>]
3589             </item>
3590           </list>
3591
3592         <p>
3593           <list compact="compact">
3594             <item>
3595                 <var>postrm</var> <tt>remove</tt>
3596             </item>
3597             <item>
3598                 <var>postrm</var> <tt>purge</tt>
3599             </item>
3600             <item>
3601                 <var>old-postrm</var> <tt>upgrade</tt>
3602                 <var>new-version</var>
3603             </item>
3604             <item>
3605                 <var>new-postrm</var> <tt>failed-upgrade</tt>
3606                 <var>old-version</var>
3607             </item>
3608             <item>
3609                 <var>new-postrm</var> <tt>abort-install</tt>
3610             </item>
3611             <item>
3612                 <var>new-postrm</var> <tt>abort-install</tt>
3613                 <var>old-version</var>
3614             </item>
3615             <item>
3616                 <var>new-postrm</var> <tt>abort-upgrade</tt>
3617                 <var>old-version</var>
3618             </item>
3619             <item>
3620                 <var>disappearer's-postrm</var> <tt>disappear</tt>
3621                 <var>overwriter</var>
3622                 <var>overwriter-version</var>
3623             </item>
3624           </list>
3625         </p>
3626
3627
3628       <sect id="unpackphase">
3629         <heading>Details of unpack phase of installation or upgrade</heading>
3630
3631         <p>
3632           The procedure on installation/upgrade/overwrite/disappear
3633           (i.e., when running <tt>dpkg --unpack</tt>, or the unpack
3634           stage of <tt>dpkg --install</tt>) is as follows.  In each
3635           case, if a major error occurs (unless listed below) the
3636           actions are, in general, run backwards - this means that the
3637           maintainer scripts are run with different arguments in
3638           reverse order.  These are the "error unwind" calls listed
3639           below.
3640
3641           <enumlist>
3642             <item>
3643                 <enumlist>
3644                   <item>
3645                       If a version of the package is already installed, call
3646                       <example compact="compact">
3647 <var>old-prerm</var> upgrade <var>new-version</var>
3648                       </example>
3649                   </item>
3650                   <item>
3651                       If the script runs but exits with a non-zero
3652                       exit status, <prgn>dpkg</prgn> will attempt:
3653                       <example compact="compact">
3654 <var>new-prerm</var> failed-upgrade <var>old-version</var>
3655                       </example>
3656                       If this works, the upgrade continues. If this
3657                       does not work, the error unwind:
3658                       <example compact="compact">
3659 <var>old-postinst</var> abort-upgrade <var>new-version</var>
3660                       </example>
3661                       If this works, then the old-version is
3662                       "Installed", if not, the old version is in a
3663                       "Failed-Config" state.
3664                   </item>
3665                 </enumlist>
3666             </item>
3667
3668             <item>
3669                 If a "conflicting" package is being removed at the same time,
3670                 or if any package will be broken (due to <tt>Breaks</tt>):
3671                 <enumlist>
3672                   <item>
3673                       If <tt>--auto-deconfigure</tt> is
3674                       specified, call, for each package to be deconfigured
3675                       due to <tt>Breaks</tt>:
3676                       <example compact="compact">
3677 <var>deconfigured's-prerm</var> deconfigure \
3678   in-favour <var>package-being-installed</var> <var>version</var>
3679                       </example>
3680                       Error unwind:
3681                       <example compact="compact">
3682 <var>deconfigured's-postinst</var> abort-deconfigure \
3683   in-favour <var>package-being-installed-but-failed</var> <var>version</var>
3684                       </example>
3685                       The deconfigured packages are marked as
3686                       requiring configuration, so that if
3687                       <tt>--install</tt> is used they will be
3688                       configured again if possible.
3689                   </item>
3690                   <item>
3691                       If any packages depended on a conflicting
3692                       package being removed and <tt>--auto-deconfigure</tt> is
3693                       specified, call, for each such package:
3694                       <example compact="compact">
3695 <var>deconfigured's-prerm</var> deconfigure \
3696   in-favour <var>package-being-installed</var> <var>version</var> \
3697     removing <var>conflicting-package</var> <var>version</var>
3698                       </example>
3699                       Error unwind:
3700                       <example compact="compact">
3701 <var>deconfigured's-postinst</var> abort-deconfigure \
3702   in-favour <var>package-being-installed-but-failed</var> <var>version</var> \
3703     removing <var>conflicting-package</var> <var>version</var>
3704                       </example>
3705                       The deconfigured packages are marked as
3706                       requiring configuration, so that if
3707                       <tt>--install</tt> is used they will be
3708                       configured again if possible.
3709                   </item>
3710                   <item>
3711                       To prepare for removal of each conflicting package, call:
3712                       <example compact="compact">
3713 <var>conflictor's-prerm</var> remove \
3714   in-favour <var>package</var> <var>new-version</var>
3715                       </example>
3716                       Error unwind:
3717                       <example compact="compact">
3718 <var>conflictor's-postinst</var> abort-remove \
3719   in-favour <var>package</var> <var>new-version</var>
3720                       </example>
3721                   </item>
3722                 </enumlist>
3723             </item>
3724
3725             <item>
3726                 <enumlist>
3727                   <item>
3728                       If the package is being upgraded, call:
3729                       <example compact="compact">
3730 <var>new-preinst</var> upgrade <var>old-version</var>
3731                       </example>
3732                       If this fails, we call:
3733                       <example>
3734 <var>new-postrm</var> abort-upgrade <var>old-version</var>
3735                       </example>
3736                       <enumlist>
3737                         <item>
3738                           <p>
3739                             If that works, then
3740                             <example>
3741 <var>old-postinst</var> abort-upgrade <var>new-version</var>
3742                             </example>
3743                             is called. If this works, then the old version
3744                             is in an "Installed" state, or else it is left
3745                             in an "Unpacked" state.
3746                           </p>
3747                         </item>
3748                         <item>
3749                           <p>
3750                             If it fails, then the old version is left
3751                             in an "Half-Installed" state.
3752                           </p>
3753                         </item>
3754                       </enumlist>
3755                       
3756                   </item>
3757                   <item>
3758                       Otherwise, if the package had some configuration
3759                       files from a previous version installed (i.e., it
3760                       is in the "configuration files only" state):
3761                       <example compact="compact">
3762 <var>new-preinst</var> install <var>old-version</var>
3763                       </example>
3764                       Error unwind:
3765                       <example>
3766 <var>new-postrm</var> abort-install <var>old-version</var>
3767                       </example>
3768                       If this fails, the package is left in a
3769                       "Half-Installed" state, which requires a
3770                       reinstall. If it works, the packages is left in
3771                       a "Config Files" state.
3772                   </item>
3773                   <item>
3774                       Otherwise (i.e., the package was completely purged):
3775                       <example compact="compact">
3776 <var>new-preinst</var> install
3777                       </example>
3778                       Error unwind:
3779                       <example compact="compact">
3780 <var>new-postrm</var> abort-install
3781                       </example>
3782                       If the error-unwind fails, the package is in a
3783                       "Half Installed" phase, and requires a
3784                       reinstall. If the error unwind works, the
3785                       package is in a not installed state.
3786                   </item>
3787                 </enumlist>
3788             </item>
3789
3790             <item>
3791               <p>
3792                 The new package's files are unpacked, overwriting any
3793                 that may be on the system already, for example any
3794                 from the old version of the same package or from
3795                 another package.  Backups of the old files are kept
3796                 temporarily, and if anything goes wrong the package
3797                 management system will attempt to put them back as
3798                 part of the error unwind.
3799               </p>
3800
3801               <p>
3802                 It is an error for a package to contain files which
3803                 are on the system in another package, unless
3804                 <tt>Replaces</tt> is used (see <ref id="replaces">).
3805                 <!--
3806                 The following paragraph is not currently the case:
3807                 Currently the <tt>- - force-overwrite</tt> flag is
3808                 enabled, downgrading it to a warning, but this may not
3809                 always be the case.
3810                 -->
3811               </p>
3812
3813               <p>
3814                 It is a more serious error for a package to contain a
3815                 plain file or other kind of non-directory where another
3816                 package has a directory (again, unless
3817                 <tt>Replaces</tt> is used).  This error can be
3818                 overridden if desired using
3819                 <tt>--force-overwrite-dir</tt>, but this is not
3820                 advisable.
3821               </p>
3822
3823               <p>
3824                 Packages which overwrite each other's files produce
3825                 behavior which, though deterministic, is hard for the
3826                 system administrator to understand.  It can easily
3827                 lead to "missing" programs if, for example, a package
3828                 is installed which overwrites a file from another
3829                 package, and is then removed again.<footnote>
3830                     Part of the problem is due to what is arguably a
3831                     bug in <prgn>dpkg</prgn>.
3832                 </footnote>
3833               </p>
3834
3835               <p>
3836                 A directory will never be replaced by a symbolic link
3837                 to a directory or vice versa; instead, the existing
3838                 state (symlink or not) will be left alone and
3839                 <prgn>dpkg</prgn> will follow the symlink if there is
3840                 one.
3841               </p>
3842             </item>
3843
3844             <item>
3845               <p>
3846                 <enumlist>
3847                   <item>
3848                       If the package is being upgraded, call
3849                       <example compact="compact">
3850 <var>old-postrm</var> upgrade <var>new-version</var>
3851                       </example>
3852                   </item>
3853                   <item>
3854                       If this fails, <prgn>dpkg</prgn> will attempt:
3855                       <example compact="compact">
3856 <var>new-postrm</var> failed-upgrade <var>old-version</var>
3857                       </example>
3858                       If this works, installation continues. If not, 
3859                       Error unwind:
3860                       <example compact="compact">
3861 <var>old-preinst</var> abort-upgrade <var>new-version</var>
3862                       </example>
3863                       If this fails, the old version is left in an
3864                       "Half Installed" state. If it works, dpkg now
3865                       calls:
3866                       <example compact="compact">
3867 <var>new-postrm</var> abort-upgrade <var>old-version</var>
3868                       </example>
3869                       If this fails, the old version is left in an
3870                       "Half Installed" state. If it works, dpkg now
3871                       calls:
3872                       <example compact="compact">
3873 <var>old-postinst</var> abort-upgrade <var>new-version</var>
3874                       </example>
3875                       If this fails, the old version is in an
3876                       "Unpacked" state.
3877                   </item>
3878                 </enumlist>
3879               </p>
3880
3881               <p>
3882                 This is the point of no return - if
3883                 <prgn>dpkg</prgn> gets this far, it won't back off
3884                 past this point if an error occurs.  This will
3885                 leave the package in a fairly bad state, which
3886                 will require a successful re-installation to clear
3887                 up, but it's when <prgn>dpkg</prgn> starts doing
3888                 things that are irreversible.
3889               </p>
3890             </item>
3891
3892             <item>
3893                 Any files which were in the old version of the package
3894                 but not in the new are removed.
3895             </item>
3896
3897             <item>
3898                 The new file list replaces the old.
3899             </item>
3900
3901             <item>
3902                 The new maintainer scripts replace the old.
3903             </item>
3904
3905             <item>
3906                 Any packages all of whose files have been overwritten
3907                 during the installation, and which aren't required for
3908                 dependencies, are considered to have been removed.
3909                 For each such package
3910                 <enumlist>
3911                   <item>
3912                       <prgn>dpkg</prgn> calls:
3913                       <example compact="compact">
3914 <var>disappearer's-postrm</var> disappear \
3915   <var>overwriter</var> <var>overwriter-version</var>
3916                       </example>
3917                   </item>
3918                   <item>
3919                       The package's maintainer scripts are removed.
3920                   </item>
3921                   <item>
3922                       It is noted in the status database as being in a
3923                       sane state, namely not installed (any conffiles
3924                       it may have are ignored, rather than being
3925                       removed by <prgn>dpkg</prgn>).  Note that
3926                       disappearing packages do not have their prerm
3927                       called, because <prgn>dpkg</prgn> doesn't know
3928                       in advance that the package is going to
3929                       vanish.
3930                   </item>
3931                 </enumlist>
3932             </item>
3933
3934             <item>
3935                 Any files in the package we're unpacking that are also
3936                 listed in the file lists of other packages are removed
3937                 from those lists.  (This will lobotomize the file list
3938                 of the "conflicting" package if there is one.)
3939             </item>
3940
3941             <item>
3942                 The backup files made during installation, above, are
3943                 deleted.
3944             </item>
3945
3946             <item>
3947               <p>
3948                 The new package's status is now sane, and recorded as
3949                 "unpacked".
3950               </p>
3951
3952               <p>
3953                 Here is another point of no return - if the
3954                 conflicting package's removal fails we do not unwind
3955                 the rest of the installation; the conflicting package
3956                 is left in a half-removed limbo.
3957               </p>
3958             </item>
3959
3960             <item>
3961                 If there was a conflicting package we go and do the
3962                 removal actions (described below), starting with the
3963                 removal of the conflicting package's files (any that
3964                 are also in the package being installed have already
3965                 been removed from the conflicting package's file list,
3966                 and so do not get removed now).
3967             </item>
3968           </enumlist>
3969         </p>
3970       </sect>
3971
3972       <sect id="configdetails"><heading>Details of configuration</heading>
3973
3974         <p>
3975           When we configure a package (this happens with <tt>dpkg
3976             --install</tt> and <tt>dpkg --configure</tt>), we first
3977           update any <tt>conffile</tt>s and then call:
3978           <example compact="compact">
3979 <var>postinst</var> configure <var>most-recently-configured-version</var>
3980           </example>
3981         </p>
3982
3983         <p>
3984           No attempt is made to unwind after errors during
3985           configuration. If the configuration fails, the package is in
3986           a "Failed Config" state, and an error message is generated.
3987         </p>
3988
3989         <p>
3990           If there is no most recently configured version
3991           <prgn>dpkg</prgn> will pass a null argument.
3992           <footnote>
3993             <p>
3994               Historical note: Truly ancient (pre-1997) versions of
3995               <prgn>dpkg</prgn> passed <tt>&lt;unknown&gt;</tt>
3996               (including the angle brackets) in this case.  Even older
3997               ones did not pass a second argument at all, under any
3998               circumstance.  Note that upgrades using such an old dpkg
3999               version are unlikely to work for other reasons, even if
4000               this old argument behavior is handled by your postinst script.
4001             </p>
4002           </footnote>     
4003         </p>
4004       </sect>
4005
4006       <sect id="removedetails"><heading>Details of removal and/or
4007       configuration purging</heading>
4008
4009         <p>
4010           <enumlist>
4011             <item>
4012               <p>
4013                 <example compact="compact">
4014 <var>prerm</var> remove
4015                 </example>
4016               </p>
4017               <p>
4018                 If prerm fails during replacement due to conflict
4019                 <example>
4020 <var>conflictor's-postinst</var> abort-remove \
4021   in-favour <var>package</var> <var>new-version</var>
4022                 </example>
4023                 Or else we call:
4024                 <example>
4025 <var>postinst</var> abort-remove
4026                 </example>
4027               </p>
4028               <p>
4029                 If this fails, the package is in a "Failed-Config"
4030                 state, or else it remains "Installed".
4031               </p>
4032             </item>
4033             <item>
4034                 The package's files are removed (except <tt>conffile</tt>s).
4035             </item>
4036             <item>
4037                 <example compact="compact">
4038 <var>postrm</var> remove
4039                 </example>
4040
4041               <p>
4042                 If it fails, there's no error unwind, and the package is in
4043                 an "Half-Installed" state.
4044               </p>
4045             </item>
4046             <item>
4047               <p>
4048                 All the maintainer scripts except the <prgn>postrm</prgn>
4049                 are removed.
4050               </p>
4051
4052               <p>
4053                 If we aren't purging the package we stop here.  Note
4054                 that packages which have no <prgn>postrm</prgn> and no
4055                 <tt>conffile</tt>s are automatically purged when
4056                 removed, as there is no difference except for the
4057                 <prgn>dpkg</prgn> status.
4058               </p>
4059             </item>
4060             <item>
4061                 The <tt>conffile</tt>s and any backup files
4062                 (<tt>~</tt>-files, <tt>#*#</tt> files,
4063                 <tt>%</tt>-files, <tt>.dpkg-{old,new,tmp}</tt>, etc.)
4064                 are removed.
4065             </item>
4066             <item>
4067               <p>
4068                 <example compact="compact">
4069 <var>postrm</var> purge
4070                 </example>
4071               </p>
4072               <p>
4073                 If this fails, the package remains in a "Config-Files"
4074                 state.
4075               </p>
4076             </item>
4077             <item>
4078                 The package's file list is removed.
4079             </item>
4080           </enumlist>
4081
4082         </p>
4083       </sect>
4084     </chapt>
4085
4086
4087     <chapt id="relationships">
4088       <heading>Declaring relationships between packages</heading>
4089
4090       <sect id="depsyntax">
4091         <heading>Syntax of relationship fields</heading>
4092
4093         <p>
4094           These fields all have a uniform syntax.  They are a list of
4095           package names separated by commas.
4096         </p>
4097
4098         <p>
4099           In the <tt>Depends</tt>, <tt>Recommends</tt>,
4100           <tt>Suggests</tt>, <tt>Pre-Depends</tt>,
4101           <tt>Build-Depends</tt> and <tt>Build-Depends-Indep</tt>
4102           control file fields of the package, which declare
4103           dependencies on other packages, the package names listed may
4104           also include lists of alternative package names, separated
4105           by vertical bar (pipe) symbols <tt>|</tt>.  In such a case,
4106           if any one of the alternative packages is installed, that
4107           part of the dependency is considered to be satisfied.
4108         </p>
4109
4110         <p>
4111           All of the fields except for <tt>Provides</tt> may restrict
4112           their applicability to particular versions of each named
4113           package.  This is done in parentheses after each individual
4114           package name; the parentheses should contain a relation from
4115           the list below followed by a version number, in the format
4116           described in <ref id="f-Version">.
4117         </p>
4118
4119         <p>
4120           The relations allowed are <tt>&lt;&lt;</tt>, <tt>&lt;=</tt>,
4121           <tt>=</tt>, <tt>&gt;=</tt> and <tt>&gt;&gt;</tt> for
4122           strictly earlier, earlier or equal, exactly equal, later or
4123           equal and strictly later, respectively.  The deprecated
4124           forms <tt>&lt;</tt> and <tt>&gt;</tt> were used to mean
4125           earlier/later or equal, rather than strictly earlier/later,
4126           so they should not appear in new packages (though
4127           <prgn>dpkg</prgn> still supports them).
4128         </p>
4129
4130         <p>
4131           Whitespace may appear at any point in the version
4132           specification subject to the rules in <ref
4133           id="controlsyntax">, and must appear where it's necessary to
4134           disambiguate; it is not otherwise significant.  All of the
4135           relationship fields may span multiple lines.  For
4136           consistency and in case of future changes to
4137           <prgn>dpkg</prgn> it is recommended that a single space be
4138           used after a version relationship and before a version
4139           number; it is also conventional to put a single space after
4140           each comma, on either side of each vertical bar, and before
4141           each open parenthesis.  When wrapping a relationship field, it
4142           is conventional to do so after a comma and before the space
4143           following that comma.
4144         </p>
4145
4146         <p>
4147           For example, a list of dependencies might appear as:
4148           <example compact="compact">
4149 Package: mutt
4150 Version: 1.3.17-1
4151 Depends: libc6 (>= 2.2.1), exim | mail-transport-agent
4152           </example>
4153         </p>
4154
4155         <p>
4156           All fields that specify build-time relationships
4157           (<tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4158           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt>)
4159           may be restricted to a certain set of architectures.  This
4160           is indicated in brackets after each individual package name and
4161           the optional version specification.  The brackets enclose a
4162           list of Debian architecture names separated by whitespace.
4163           Exclamation marks may be prepended to each of the names.
4164           (It is not permitted for some names to be prepended with
4165           exclamation marks while others aren't.) If the current Debian
4166           host architecture is not in this list and there are no
4167           exclamation marks in the list, or it is in the list with a
4168           prepended exclamation mark, the package name and the
4169           associated version specification are ignored completely for
4170           the purposes of defining the relationships.
4171         </p>
4172
4173         <p>
4174           For example:
4175           <example compact="compact">
4176 Source: glibc
4177 Build-Depends-Indep: texinfo
4178 Build-Depends: kernel-headers-2.2.10 [!hurd-i386],
4179   hurd-dev [hurd-i386], gnumach-dev [hurd-i386]
4180           </example>
4181         </p>
4182
4183         <p>
4184           Note that the binary package relationship fields such as
4185           <tt>Depends</tt> appear in one of the binary package
4186           sections of the control file, whereas the build-time
4187           relationships such as <tt>Build-Depends</tt> appear in the
4188           source package section of the control file (which is the
4189           first section).
4190         </p>
4191       </sect>
4192
4193       <sect id="binarydeps">
4194         <heading>Binary Dependencies - <tt>Depends</tt>,
4195           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
4196           <tt>Pre-Depends</tt>
4197         </heading>
4198
4199         <p>
4200           Packages can declare in their control file that they have
4201           certain relationships to other packages - for example, that
4202           they may not be installed at the same time as certain other
4203           packages, and/or that they depend on the presence of others.
4204         </p>
4205
4206         <p>
4207           This is done using the <tt>Depends</tt>, <tt>Pre-Depends</tt>,
4208           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
4209           <tt>Breaks</tt> and <tt>Conflicts</tt> control file fields.
4210         </p>
4211
4212         <p>
4213           These seven fields are used to declare a dependency
4214           relationship by one package on another.  Except for
4215           <tt>Enhances</tt> and <tt>Breaks</tt>, they appear in the
4216           depending (binary) package's control file.
4217           (<tt>Enhances</tt> appears in the recommending package's
4218           control file, and <tt>Breaks</tt> appears in the version of
4219           depended-on package which causes the named package to
4220           break).
4221         </p>
4222
4223         <p>
4224           A <tt>Depends</tt> field takes effect <em>only</em> when a
4225           package is to be configured.  It does not prevent a package
4226           being on the system in an unconfigured state while its
4227           dependencies are unsatisfied, and it is possible to replace
4228           a package whose dependencies are satisfied and which is
4229           properly installed with a different version whose
4230           dependencies are not and cannot be satisfied; when this is
4231           done the depending package will be left unconfigured (since
4232           attempts to configure it will give errors) and will not
4233           function properly.  If it is necessary, a
4234           <tt>Pre-Depends</tt> field can be used, which has a partial
4235           effect even when a package is being unpacked, as explained
4236           in detail below.  (The other three dependency fields,
4237           <tt>Recommends</tt>, <tt>Suggests</tt> and
4238           <tt>Enhances</tt>, are only used by the various front-ends
4239           to <prgn>dpkg</prgn> such as <prgn>apt-get</prgn>,
4240           <prgn>aptitude</prgn>, and <prgn>dselect</prgn>.)
4241         </p>
4242
4243         <p>
4244           For this reason packages in an installation run are usually
4245           all unpacked first and all configured later; this gives
4246           later versions of packages with dependencies on later
4247           versions of other packages the opportunity to have their
4248           dependencies satisfied.
4249         </p>
4250
4251         <p>
4252           In case of circular dependencies, since installation or
4253           removal order honoring the dependency order can't be
4254           established, dependency loops are broken at some point
4255           (based on rules below), and some packages may not be able to
4256           rely on their dependencies being present when being
4257           installed or removed, depending on which side of the break
4258           of the circular dependency loop they happen to be on.  If one
4259           of the packages in the loop has no postinst script, then the
4260           cycle will be broken at that package, so as to ensure that
4261           all postinst scripts run with the dependencies properly
4262           configured if this is possible. Otherwise the breaking point
4263           is arbitrary.
4264         </p>
4265
4266         <p>
4267           The <tt>Depends</tt> field thus allows package maintainers
4268           to impose an order in which packages should be configured.
4269         </p>
4270
4271         <p>
4272           The meaning of the five dependency fields is as follows:
4273           <taglist>
4274             <tag><tt>Depends</tt></tag>
4275             <item>
4276               <p>
4277                 This declares an absolute dependency.  A package will
4278                 not be configured unless all of the packages listed in
4279                 its <tt>Depends</tt> field have been correctly
4280                 configured.
4281               </p>
4282
4283               <p>
4284                 The <tt>Depends</tt> field should be used if the
4285                 depended-on package is required for the depending
4286                 package to provide a significant amount of
4287                 functionality.
4288               </p>
4289
4290               <p>
4291                 The <tt>Depends</tt> field should also be used if the
4292                 <prgn>postinst</prgn>, <prgn>prerm</prgn> or
4293                 <prgn>postrm</prgn> scripts require the package to be
4294                 present in order to run.  Note, however, that the
4295                 <prgn>postrm</prgn> cannot rely on any non-essential
4296                 packages to be present during the <tt>purge</tt>
4297                 phase.
4298             </item>
4299
4300             <tag><tt>Recommends</tt></tag>
4301             <item>
4302               <p>
4303                 This declares a strong, but not absolute, dependency.
4304               </p>
4305
4306               <p>
4307                 The <tt>Recommends</tt> field should list packages
4308                 that would be found together with this one in all but
4309                 unusual installations.
4310               </p>
4311             </item>
4312
4313             <tag><tt>Suggests</tt></tag>
4314             <item>
4315                 This is used to declare that one package may be more
4316                 useful with one or more others.  Using this field
4317                 tells the packaging system and the user that the
4318                 listed packages are related to this one and can
4319                 perhaps enhance its usefulness, but that installing
4320                 this one without them is perfectly reasonable.
4321             </item>
4322
4323             <tag><tt>Enhances</tt></tag>
4324             <item>
4325                 This field is similar to Suggests but works in the
4326                 opposite direction. It is used to declare that a
4327                 package can enhance the functionality of another
4328                 package.
4329             </item>
4330
4331             <tag><tt>Pre-Depends</tt></tag>
4332             <item>
4333               <p>
4334                 This field is like <tt>Depends</tt>, except that it
4335                 also forces <prgn>dpkg</prgn> to complete installation
4336                 of the packages named before even starting the
4337                 installation of the package which declares the
4338                 pre-dependency, as follows:
4339               </p>
4340
4341               <p>
4342                 When a package declaring a pre-dependency is about to
4343                 be <em>unpacked</em> the pre-dependency can be
4344                 satisfied if the depended-on package is either fully
4345                 configured, <em>or even if</em> the depended-on
4346                 package(s) are only unpacked or half-configured,
4347                 provided that they have been configured correctly at
4348                 some point in the past (and not removed or partially
4349                 removed since).  In this case, both the
4350                 previously-configured and currently unpacked or
4351                 half-configured versions must satisfy any version
4352                 clause in the <tt>Pre-Depends</tt> field.
4353               </p>
4354
4355               <p>
4356                 When the package declaring a pre-dependency is about
4357                 to be <em>configured</em>, the pre-dependency will be
4358                 treated as a normal <tt>Depends</tt>, that is, it will
4359                 be considered satisfied only if the depended-on
4360                 package has been correctly configured.
4361               </p>
4362
4363               <p>
4364                 <tt>Pre-Depends</tt> should be used sparingly,
4365                 preferably only by packages whose premature upgrade or
4366                 installation would hamper the ability of the system to
4367                 continue with any upgrade that might be in progress.
4368               </p>
4369
4370               <p>
4371                 <tt>Pre-Depends</tt> are also required if the
4372                 <prgn>preinst</prgn> script depends on the named
4373                 package.  It is best to avoid this situation if
4374                 possible.
4375               </p>
4376             </item>
4377           </taglist>
4378         </p>
4379
4380         <p>
4381           When selecting which level of dependency to use you should
4382           consider how important the depended-on package is to the
4383           functionality of the one declaring the dependency.  Some
4384           packages are composed of components of varying degrees of
4385           importance.  Such a package should list using
4386           <tt>Depends</tt> the package(s) which are required by the
4387           more important components.  The other components'
4388           requirements may be mentioned as Suggestions or
4389           Recommendations, as appropriate to the components' relative
4390           importance.
4391         </p>
4392       </sect>
4393
4394       <sect id="breaks">
4395         <heading>Packages which break other packages - <tt>Breaks</tt></heading>
4396
4397         <p>
4398           Using <tt>Breaks</tt> may cause problems for upgrades from older
4399           versions of Debian and should not be used until the stable
4400           release of Debian supports <tt>Breaks</tt>.
4401         </p>
4402
4403         <p>
4404           When one binary package declares that it breaks another,
4405           <prgn>dpkg</prgn> will refuse to allow the package which
4406           declares <tt>Breaks</tt> be installed unless the broken
4407           package is deconfigured first, and it will refuse to
4408           allow the broken package to be reconfigured.
4409         </p>
4410
4411         <p>
4412           A package will not be regarded as causing breakage merely
4413           because its configuration files are still installed; it must
4414           be at least half-installed.
4415         </p>
4416
4417         <p>
4418           A special exception is made for packages which declare that
4419           they break their own package name or a virtual package which
4420           they provide (see below): this does not count as a real
4421           breakage.
4422         </p>
4423
4424         <p>
4425           Normally a <tt>Breaks</tt> entry will have an "earlier than"
4426           version clause; such a <tt>Breaks</tt> is introduced in the
4427           version of an (implicit or explicit) dependency which
4428           violates an assumption or reveals a bug in earlier versions
4429           of the broken package.  This use of <tt>Breaks</tt> will
4430           inform higher-level package management tools that broken
4431           package must be upgraded before the new one.
4432         </p>
4433
4434         <p>
4435           If the breaking package also overwrites some files from the
4436           older package, it should use <tt>Replaces</tt> (not
4437           <tt>Conflicts</tt>) to ensure this goes smoothly.
4438         </p>
4439       </sect>
4440
4441       <sect id="conflicts">
4442         <heading>Conflicting binary packages - <tt>Conflicts</tt></heading>
4443
4444         <p>
4445           When one binary package declares a conflict with another
4446           using a <tt>Conflicts</tt> field, <prgn>dpkg</prgn> will
4447           refuse to allow them to be installed on the system at the
4448           same time.
4449         </p>
4450
4451         <p>
4452           If one package is to be installed, the other must be removed
4453           first - if the package being installed is marked as
4454           replacing (see <ref id="replaces">) the one on the system,
4455           or the one on the system is marked as deselected, or both
4456           packages are marked <tt>Essential</tt>, then
4457           <prgn>dpkg</prgn> will automatically remove the package
4458           which is causing the conflict, otherwise it will halt the
4459           installation of the new package with an error.  This
4460           mechanism is specifically designed to produce an error when
4461           the installed package is <tt>Essential</tt>, but the new
4462           package is not.
4463         </p>
4464
4465         <p>
4466           A package will not cause a conflict merely because its
4467           configuration files are still installed; it must be at least
4468           half-installed.
4469         </p>
4470
4471         <p>
4472           A special exception is made for packages which declare a
4473           conflict with their own package name, or with a virtual
4474           package which they provide (see below): this does not
4475           prevent their installation, and allows a package to conflict
4476           with others providing a replacement for it.  You use this
4477           feature when you want the package in question to be the only
4478           package providing some feature.
4479         </p>
4480
4481         <p>
4482           A <tt>Conflicts</tt> entry should almost never have an
4483           "earlier than" version clause.  This would prevent
4484           <prgn>dpkg</prgn> from upgrading or installing the package
4485           which declared such a conflict until the upgrade or removal
4486           of the conflicted-with package had been completed.  Instead,
4487           <tt>Breaks</tt> may be used (once <tt>Breaks</tt> is supported
4488           by the stable release of Debian).
4489         </p>
4490       </sect>
4491
4492       <sect id="virtual"><heading>Virtual packages - <tt>Provides</tt>
4493         </heading>
4494
4495         <p>
4496           As well as the names of actual ("concrete") packages, the
4497           package relationship fields <tt>Depends</tt>,
4498           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
4499           <tt>Pre-Depends</tt>, <tt>Breaks</tt>, <tt>Conflicts</tt>,
4500           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4501           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt>
4502           may mention "virtual packages".
4503         </p>
4504
4505         <p>
4506           A <em>virtual package</em> is one which appears in the
4507           <tt>Provides</tt> control file field of another package.
4508           The effect is as if the package(s) which provide a
4509           particular virtual package name had been listed by name
4510           everywhere the virtual package name appears. (See also <ref
4511             id="virtual_pkg">)
4512         </p>
4513
4514         <p>
4515           If there are both concrete and virtual packages of the same
4516           name, then the dependency may be satisfied (or the conflict
4517           caused) by either the concrete package with the name in
4518           question or any other concrete package which provides the
4519           virtual package with the name in question.  This is so that,
4520           for example, supposing we have
4521           <example compact="compact">
4522 Package: foo
4523 Depends: bar
4524           </example> and someone else releases an enhanced version of
4525           the <tt>bar</tt> package they can say:
4526           <example compact="compact">
4527 Package: bar-plus
4528 Provides: bar
4529           </example>
4530           and the <tt>bar-plus</tt> package will now also satisfy the
4531           dependency for the <tt>foo</tt> package.
4532         </p>
4533
4534         <p>
4535           If a relationship field has a version number attached
4536           then only real packages will be considered to see whether
4537           the relationship is satisfied (or the prohibition violated,
4538           for a conflict or breakage) - it is assumed that a real
4539           package which provides the virtual package is not of the
4540           "right" version.  So, a <tt>Provides</tt> field may not
4541           contain version numbers, and the version number of the
4542           concrete package which provides a particular virtual package
4543           will not be looked at when considering a dependency on or
4544           conflict with the virtual package name.
4545         </p>
4546
4547         <p>
4548           It is likely that the ability will be added in a future
4549           release of <prgn>dpkg</prgn> to specify a version number for
4550           each virtual package it provides.  This feature is not yet
4551           present, however, and is expected to be used only
4552           infrequently.
4553         </p>
4554
4555         <p>
4556           If you want to specify which of a set of real packages
4557           should be the default to satisfy a particular dependency on
4558           a virtual package, you should list the real package as an
4559           alternative before the virtual one.
4560         </p>
4561       </sect>
4562
4563
4564       <sect id="replaces"><heading>Overwriting files and replacing
4565           packages - <tt>Replaces</tt></heading>
4566
4567         <p>
4568           Packages can declare in their control file that they should
4569           overwrite files in certain other packages, or completely
4570           replace other packages. The <tt>Replaces</tt> control file
4571           field has these two distinct purposes.
4572         </p>
4573
4574         <sect1><heading>Overwriting files in other packages</heading>
4575
4576           <p>
4577             Firstly, as mentioned before, it is usually an error for a
4578             package to contain files which are on the system in
4579             another package.
4580           </p>
4581
4582           <p>
4583             However, if the overwriting package declares that it
4584             <tt>Replaces</tt> the one containing the file being
4585             overwritten, then <prgn>dpkg</prgn> will replace the file
4586             from the old package with that from the new.  The file
4587             will no longer be listed as "owned" by the old package.
4588           </p>
4589
4590           <p>
4591             If a package is completely replaced in this way, so that
4592             <prgn>dpkg</prgn> does not know of any files it still
4593             contains, it is considered to have "disappeared".  It will
4594             be marked as not wanted on the system (selected for
4595             removal) and not installed.  Any <tt>conffile</tt>s
4596             details noted for the package will be ignored, as they
4597             will have been taken over by the overwriting package.  The
4598             package's <prgn>postrm</prgn> script will be run with a
4599             special argument to allow the package to do any final
4600             cleanup required.  See <ref id="mscriptsinstact">.
4601             <footnote>
4602               <p>
4603                 Replaces is a one way relationship -- you have to              
4604                 install the replacing package after the replaced
4605                 package.
4606               </p>
4607             </footnote>
4608           </p>
4609
4610           <p>
4611             For this usage of <tt>Replaces</tt>, virtual packages (see
4612             <ref id="virtual">) are not considered when looking at a
4613             <tt>Replaces</tt> field - the packages declared as being
4614             replaced must be mentioned by their real names.
4615           </p>
4616
4617           <p>
4618             Furthermore, this usage of <tt>Replaces</tt> only takes
4619             effect when both packages are at least partially on the
4620             system at once, so that it can only happen if they do not
4621             conflict or if the conflict has been overridden.
4622           </p>
4623
4624         </sect1>
4625
4626         <sect1><heading>Replacing whole packages, forcing their
4627             removal</heading>
4628
4629           <p>
4630             Secondly, <tt>Replaces</tt> allows the packaging system to
4631             resolve which package should be removed when there is a
4632             conflict - see <ref id="conflicts">.  This usage only
4633             takes effect when the two packages <em>do</em> conflict,
4634             so that the two usages of this field do not interfere with
4635             each other.
4636           </p>
4637
4638           <p>
4639             In this situation, the package declared as being replaced
4640             can be a virtual package, so for example, all mail
4641             transport agents (MTAs) would have the following fields in
4642             their control files:
4643             <example compact="compact">
4644 Provides: mail-transport-agent
4645 Conflicts: mail-transport-agent
4646 Replaces: mail-transport-agent
4647             </example>
4648             ensuring that only one MTA can be installed at any one
4649             time.
4650         </sect1>
4651       </sect>
4652
4653       <sect id="sourcebinarydeps">
4654         <heading>Relationships between source and binary packages -
4655           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4656           <tt>Build-Conflicts</tt>, <tt>Build-Conflicts-Indep</tt>
4657         </heading>
4658
4659         <p>
4660           Source packages that require certain binary packages to be
4661           installed or absent at the time of building the package
4662           can declare relationships to those binary packages.
4663         </p>
4664
4665         <p>
4666           This is done using the <tt>Build-Depends</tt>,
4667           <tt>Build-Depends-Indep</tt>, <tt>Build-Conflicts</tt> and
4668           <tt>Build-Conflicts-Indep</tt> control file fields.
4669         </p>
4670
4671         <p>
4672           Build-dependencies on "build-essential" binary packages can be
4673           omitted. Please see <ref id="pkg-relations"> for more information.
4674         </p>
4675
4676         <p>
4677           The dependencies and conflicts they define must be satisfied
4678           (as defined earlier for binary packages) in order to invoke
4679           the targets in <tt>debian/rules</tt>, as follows:<footnote>
4680             <p>
4681               If you make "build-arch" or "binary-arch", you need
4682               Build-Depends.  If you make "build-indep" or
4683               "binary-indep", you need Build-Depends and
4684               Build-Depends-Indep.  If you make "build" or "binary",
4685               you need both.
4686             </p>
4687             <p>
4688               There is no Build-Depends-Arch; this role is essentially
4689               met with Build-Depends.  Anyone building the
4690               <tt>build-indep</tt> and binary-indep<tt></tt> targets
4691               is basically assumed to be building the whole package
4692               anyway and so installs all build dependencies.  The
4693               autobuilders use <tt>dpkg-buildpackage -B</tt>, which
4694               calls <tt>build</tt> (not <tt>build-arch</tt>, since it
4695               does not yet know how to check for its existence) and
4696               <tt>binary-arch</tt>.
4697             </p>
4698             <p>
4699               The purpose of the original split, I recall, was so that
4700               the autobuilders wouldn't need to install extra packages
4701               needed only for the binary-indep targets.  But without a
4702               build-arch/build-indep split, this didn't work, since
4703               most of the work is done in the build target, not in the
4704               binary target.
4705             </p>
4706           </footnote>
4707
4708           <taglist>
4709             <tag><tt>Build-Depends</tt>, <tt>Build-Conflicts</tt></tag>
4710             <item>
4711                 The <tt>Build-Depends</tt> and
4712                 <tt>Build-Conflicts</tt> fields must be satisfied when
4713                 any of the following targets is invoked:
4714                 <tt>build</tt>, <tt>clean</tt>, <tt>binary</tt>,
4715                 <tt>binary-arch</tt>, <tt>build-arch</tt>,
4716                 <tt>build-indep</tt> and <tt>binary-indep</tt>.
4717             </item>
4718             <tag><tt>Build-Depends-Indep</tt>,
4719               <tt>Build-Conflicts-Indep</tt></tag>
4720             <item>
4721                 The <tt>Build-Depends-Indep</tt> and
4722                 <tt>Build-Conflicts-Indep</tt> fields must be
4723                 satisfied when any of the following targets is
4724                 invoked: <tt>build</tt>, <tt>build-indep</tt>,
4725                 <tt>binary</tt> and <tt>binary-indep</tt>.
4726             </item>
4727           </taglist>
4728         </p>
4729
4730       </sect>
4731
4732     </chapt>
4733
4734
4735     <chapt id="sharedlibs"><heading>Shared libraries</heading>
4736
4737       <p>
4738         Packages containing shared libraries must be constructed with
4739         a little care to make sure that the shared library is always
4740         available.  This is especially important for packages whose
4741         shared libraries are vitally important, such as the C library
4742         (currently <tt>libc6</tt>).
4743       </p>
4744
4745       <p>
4746         Packages involving shared libraries should be split up into
4747         several binary packages. This section mostly deals with how
4748         this separation is to be accomplished; rules for files within
4749         the shared library packages are in <ref id="libraries"> instead.
4750       </p>
4751
4752       <sect id="sharedlibs-runtime">
4753         <heading>Run-time shared libraries</heading>
4754
4755       <p>
4756         The run-time shared library needs to be placed in a package
4757         whose name changes whenever the shared object version
4758         changes.<footnote>
4759             <p>
4760               Since it is common place to install several versions of a
4761               package that just provides shared libraries, it is a
4762               good idea that the library package should not
4763               contain any extraneous non-versioned files, unless they
4764               happen to be in versioned directories.</p>
4765           </footnote>
4766           The most common mechanism is to place it in a package
4767         called
4768         <package><var>libraryname</var><var>soversion</var></package>,
4769         where <file><var>soversion</var></file> is the version number
4770         in the soname of the shared library<footnote>
4771               The soname is the shared object name: it's the thing
4772               that has to match exactly between building an executable
4773               and running it for the dynamic linker to be able run the
4774               program.  For example, if the soname of the library is
4775               <file>libfoo.so.6</file>, the library package would be
4776               called <file>libfoo6</file>.
4777           </footnote>.
4778         Alternatively, if it would be confusing to directly append
4779         <var>soversion</var> to <var>libraryname</var> (e.g. because
4780         <var>libraryname</var> itself ends in a number), you may use
4781         <package><var>libraryname</var>-<var>soversion</var></package> and
4782         <package><var>libraryname</var>-<var>soversion</var>-dev</package>
4783         instead.
4784       </p>
4785
4786       <p>
4787         If you have several shared libraries built from the same
4788         source tree you may lump them all together into a single
4789         shared library package, provided that you change all of
4790         their sonames at once (so that you don't get filename
4791         clashes if you try to install different versions of the
4792         combined shared libraries package).
4793       </p>
4794
4795       <p>
4796         The package should install the shared libraries under
4797         their normal names.  For example, the <package>libgdbm3</package>
4798         package should install <file>libgdbm.so.3.0.0</file> as
4799         <file>/usr/lib/libgdbm.so.3.0.0</file>.  The files should not be
4800         renamed or re-linked by any <prgn>prerm</prgn> or
4801         <prgn>postrm</prgn> scripts; <prgn>dpkg</prgn> will take care
4802         of renaming things safely without affecting running programs,
4803         and attempts to interfere with this are likely to lead to
4804         problems.
4805       </p>
4806
4807       <p>
4808         Shared libraries should not be installed executable, since
4809         the dynamic linker does not require this and trying to
4810         execute a shared library usually results in a core dump.
4811       </p>
4812
4813       <p>
4814         The run-time library package should include the symbolic link that
4815         <prgn>ldconfig</prgn> would create for the shared libraries.
4816         For example, the <package>libgdbm3</package> package should include
4817         a symbolic link from <file>/usr/lib/libgdbm.so.3</file> to
4818         <file>libgdbm.so.3.0.0</file>.  This is needed so that the dynamic
4819         linker (for example <prgn>ld.so</prgn> or
4820         <prgn>ld-linux.so.*</prgn>) can find the library between the
4821         time that <prgn>dpkg</prgn> installs it and the time that
4822         <prgn>ldconfig</prgn> is run in the <prgn>postinst</prgn>
4823         script.<footnote>
4824             The package management system requires the library to be
4825             placed before the symbolic link pointing to it in the
4826             <file>.deb</file> file.  This is so that when
4827             <prgn>dpkg</prgn> comes to install the symlink
4828             (overwriting the previous symlink pointing at an older
4829             version of the library), the new shared library is already
4830             in place.  In the past, this was achieved by creating the
4831             library in the temporary packaging directory before
4832             creating the symlink.  Unfortunately, this was not always
4833             effective, since the building of the tar file in the
4834             <file>.deb</file> depended on the behavior of the underlying
4835             file system.  Some file systems (such as reiserfs) reorder
4836             the files so that the order of creation is forgotten.
4837             Since version 1.7.0, <prgn>dpkg</prgn>
4838             reorders the files itself as necessary when building a
4839             package.  Thus it is no longer important to concern
4840             oneself with the order of file creation.
4841         </footnote>
4842       </p>
4843
4844         <sect1 id="ldconfig">
4845           <heading><tt>ldconfig</tt></heading>
4846
4847         <p>
4848           Any package installing shared libraries in one of the default
4849           library directories of the dynamic linker (which are currently
4850           <file>/usr/lib</file> and <file>/lib</file>) or a directory that is
4851           listed in <file>/etc/ld.so.conf</file><footnote>
4852             These are currently
4853             <list compact="compact">
4854               <item>/usr/local/lib</item>
4855               <item>/usr/lib/libc5-compat</item>
4856               <item>/lib/libc5-compat</item>
4857             </list>
4858           </footnote>
4859           must use <prgn>ldconfig</prgn> to update the shared library
4860           system.
4861         </p>
4862
4863         <p>
4864             The package maintainer scripts must only call
4865             <prgn>ldconfig</prgn> under these circumstances:
4866             <list compact="compact">
4867               <item>When the <prgn>postinst</prgn> script is run with a
4868                   first argument of <tt>configure</tt>, the script must call
4869                   <prgn>ldconfig</prgn>, and may optionally invoke
4870                   <prgn>ldconfig</prgn> at other times.
4871               </item>
4872               <item>When the <prgn>postrm</prgn> script is run with a
4873                   first argument of <tt>remove</tt>, the script should call
4874                   <prgn>ldconfig</prgn>.
4875               </item>
4876             </list>
4877          <footnote>
4878             <p>
4879               During install or upgrade, the preinst is called before
4880               the new files are installed, so calling "ldconfig" is
4881               pointless.  The preinst of an existing package can also be
4882               called if an upgrade fails.  However, this happens during
4883               the critical time when a shared libs may exist on-disk
4884               under a temporary name.  Thus, it is dangerous and
4885               forbidden by current policy to call "ldconfig" at this
4886               time.
4887             </p>
4888
4889             <p>
4890               When a package is installed or upgraded, "postinst
4891               configure" runs after the new files are safely on-disk.
4892               Since it is perfectly safe to invoke ldconfig
4893               unconditionally in a postinst, it is OK for a package to
4894               simply put ldconfig in its postinst without checking the
4895               argument.  The postinst can also be called to recover from
4896               a failed upgrade.  This happens before any new files are
4897               unpacked, so there is no reason to call "ldconfig" at this
4898               point.
4899             </p>
4900
4901             <p>
4902               For a package that is being removed, prerm is
4903               called with all the files intact, so calling ldconfig is
4904               useless.  The other calls to "prerm" happen in the case of
4905               upgrade at a time when all the files of the old package
4906               are on-disk, so again calling "ldconfig" is pointless.
4907             </p>
4908
4909             <p>
4910               postrm, on the other hand, is called with the "remove"
4911               argument just after the files are removed, so this is
4912               the proper time to call "ldconfig" to notify the system
4913               of the fact that the shared libraries from the package
4914               are removed.  The postrm can be called at several other
4915               times.  At the time of "postrm purge", "postrm
4916               abort-install", or "postrm abort-upgrade", calling
4917               "ldconfig" is useless because the shared lib files are
4918               not on-disk.  However, when "postrm" is invoked with
4919               arguments "upgrade", "failed-upgrade", or "disappear", a
4920               shared lib may exist on-disk under a temporary filename.
4921             </p>
4922           </footnote>
4923         </p>
4924         </sect1>
4925
4926       </sect>
4927
4928       <sect id="sharedlibs-support-files">
4929         <heading>Shared library support files</heading>
4930
4931         <p>
4932           If your package contains files whose names do not change with
4933           each change in the library shared object version, you must not
4934           put them in the shared library package.  Otherwise, several
4935           versions of the shared library cannot be installed at the same
4936           time without filename clashes, making upgrades and transitions
4937           unnecessarily difficult.
4938         </p>
4939
4940         <p>
4941           It is recommended that supporting files and run-time support
4942           programs that do not need to be invoked manually by users, but
4943           are nevertheless required for the package to function, be placed
4944           (if they are binary) in a subdirectory of <file>/usr/lib</file>,
4945           preferably under <file>/usr/lib/</file><var>package-name</var>.
4946           If the program or file is architecture independent, the
4947           recommendation is for it to be placed in a subdirectory of
4948           <file>/usr/share</file> instead, preferably under
4949           <file>/usr/share/</file><var>package-name</var>.  Following the
4950           <var>package-name</var> naming convention ensures that the file
4951           names change when the shared object version changes.
4952         </p>
4953
4954         <p>
4955           Run-time support programs that use the shared library but are
4956           not required for the library to function or files used by the
4957           shared library that can be used by any version of the shared
4958           library package should instead be put in a separate package.
4959           This package might typically be named
4960           <package><var>libraryname</var>-tools</package>; note the
4961           absence of the <var>soversion</var> in the package name.
4962         </p>
4963
4964         <p>
4965           Files and support programs only useful when compiling software
4966           against the library should be included in the development
4967           package for the library.<footnote>
4968             For example, a <file><var>package-name</var>-config</file>
4969             script or <package>pkg-config</package> configuration files.
4970           </footnote>
4971         </p>
4972       </sect>
4973
4974       <sect id="sharedlibs-static">
4975         <heading>Static libraries</heading>
4976
4977       <p>
4978         The static library (<file><var>libraryname.a</var></file>)
4979         is usually provided in addition to the shared version.
4980         It is placed into the development package (see below).
4981       </p>
4982
4983       <p>
4984         In some cases, it is acceptable for a library to be
4985         available in static form only; these cases include:
4986         <list>
4987           <item>libraries for languages whose shared library support
4988                 is immature or unstable</item>
4989           <item>libraries whose interfaces are in flux or under
4990                 development (commonly the case when the library's
4991                 major version number is zero, or where the ABI breaks
4992                 across patchlevels)</item>
4993           <item>libraries which are explicitly intended to be
4994                 available only in static form by their upstream
4995                 author(s)</item>
4996         </list>
4997       </p>
4998
4999       <sect id="sharedlibs-dev">
5000         <heading>Development files</heading>
5001
5002       <p>
5003         The development files associated to a shared library need to be
5004         placed in a package called
5005         <package><var>libraryname</var><var>soversion</var>-dev</package>,
5006         or if you prefer only to support one development version at a
5007         time, <package><var>libraryname</var>-dev</package>.
5008       </p>
5009
5010       <p>
5011         In case several development versions of a library exist, you may
5012         need to use <prgn>dpkg</prgn>'s Conflicts mechanism (see
5013         <ref id="conflicts">) to ensure that the user only installs one
5014         development version at a time (as different development versions are
5015         likely to have the same header files in them, which would cause a
5016         filename clash if both were installed).
5017       </p>
5018
5019       <p>
5020         The development package should contain a symlink for the associated
5021         shared library without a version number. For example, the
5022         <package>libgdbm-dev</package> package should include a symlink
5023         from <file>/usr/lib/libgdbm.so</file> to
5024         <file>libgdbm.so.3.0.0</file>.  This symlink is needed by the linker
5025         (<prgn>ld</prgn>) when compiling packages, as it will only look for
5026         <file>libgdbm.so</file> when compiling dynamically.
5027       </p>
5028       </sect>
5029
5030       <sect id="sharedlibs-intradeps">
5031         <heading>Dependencies between the packages of the same library</heading>
5032
5033         <p>
5034           Typically the development version should have an exact
5035           version dependency on the runtime library, to make sure that
5036           compilation and linking happens correctly.  The
5037           <tt>${binary:Version}</tt> substitution variable can be
5038           useful for this purpose.
5039           <footnote>
5040             Previously, <tt>${Source-Version}</tt> was used, but its name
5041             was confusing and it has been deprecated since dpkg 1.13.19.
5042           </footnote>
5043         </p>
5044       </sect>
5045
5046       <sect id="sharedlibs-shlibdeps">
5047         <heading>Dependencies between the library and other packages -
5048         the <tt>shlibs</tt> system</heading>
5049
5050         <p>
5051           If a package contains a binary or library which links to a
5052           shared library, we must ensure that when the package is
5053           installed on the system, all of the libraries needed are
5054           also installed.  This requirement led to the creation of the
5055           <tt>shlibs</tt> system, which is very simple in its design:
5056           any package which <em>provides</em> a shared library also
5057           provides information on the package dependencies required to
5058           ensure the presence of this library, and any package which
5059           <em>uses</em> a shared library uses this information to
5060           determine the dependencies it requires.  The files which
5061           contain the mapping from shared libraries to the necessary
5062           dependency information are called <file>shlibs</file> files.
5063         </p>
5064
5065         <p>
5066           Thus, when a package is built which contains any shared
5067           libraries, it must provide a <file>shlibs</file> file for other
5068           packages to use, and when a package is built which contains
5069           any shared libraries or compiled binaries, it must run
5070           <qref id="pkg-dpkg-shlibdeps"><prgn>dpkg-shlibdeps</prgn></qref>
5071           on these to determine the libraries used and hence the
5072           dependencies needed by this package.<footnote>
5073             <p>
5074               In the past, the shared libraries linked to were
5075               determined by calling <prgn>ldd</prgn>, but now
5076               <prgn>objdump</prgn> is used to do this.  The only
5077               change this makes to package building is that
5078               <prgn>dpkg-shlibdeps</prgn> must also be run on shared
5079               libraries, whereas in the past this was unnecessary.
5080               The rest of this footnote explains the advantage that
5081               this method gives.
5082             </p>
5083
5084             <p>
5085               We say that a binary <tt>foo</tt> <em>directly</em> uses
5086               a library <tt>libbar</tt> if it is explicitly linked
5087               with that library (that is, it uses the flag
5088               <tt>-lbar</tt> during the linking stage).  Other
5089               libraries that are needed by <tt>libbar</tt> are linked
5090               <em>indirectly</em> to <tt>foo</tt>, and the dynamic
5091               linker will load them automatically when it loads
5092               <tt>libbar</tt>.  A package should depend on
5093               the libraries it directly uses, and the dependencies for
5094               those libraries should automatically pull in the other
5095               libraries.
5096             </p>
5097
5098             <p>
5099               Unfortunately, the <prgn>ldd</prgn> program shows both
5100               the directly and indirectly used libraries, meaning that
5101               the dependencies determined included both direct and
5102               indirect dependencies.  The use of <prgn>objdump</prgn>
5103               avoids this problem by determining only the directly
5104               used libraries.
5105             </p>
5106
5107             <p>
5108               A good example of where this helps is the following.  We
5109               could update <tt>libimlib</tt> with a new version that
5110               supports a new graphics format called dgf (but retaining
5111               the same major version number).  If we used the old
5112               <prgn>ldd</prgn> method, every package that uses
5113               <tt>libimlib</tt> would need to be recompiled so it
5114               would also depend on <tt>libdgf</tt> or it wouldn't run
5115               due to missing symbols.  However with the new system,
5116               packages using <tt>libimlib</tt> can rely on
5117               <tt>libimlib</tt> itself having the dependency on
5118               <tt>libdgf</tt> and so they would not need rebuilding.
5119             </p>
5120           </footnote>
5121         </p>
5122
5123         <p>
5124           In the following sections, we will first describe where the
5125           various <tt>shlibs</tt> files are to be found, then how to
5126           use <prgn>dpkg-shlibdeps</prgn>, and finally the <tt>shlibs</tt>
5127           file format and how to create them if your package contains a
5128           shared library.
5129         </p>
5130
5131       <sect1>
5132         <heading>The <tt>shlibs</tt> files present on the system</heading>
5133
5134         <p>
5135           There are several places where <tt>shlibs</tt> files are
5136           found.  The following list gives them in the order in which
5137           they are read by
5138           <qref id="pkg-dpkg-shlibdeps"><prgn>dpkg-shlibdeps</prgn></qref>.
5139           (The first one which gives the required information is used.)
5140         </p>
5141
5142         <p>
5143           <list>
5144             <item>
5145               <p><file>debian/shlibs.local</file></p>
5146
5147               <p>
5148                 This lists overrides for this package.  Its use is
5149                 described below (see <ref id="shlibslocal">).
5150               </p>
5151             </item>
5152
5153             <item>
5154               <p><file>/etc/dpkg/shlibs.override</file></p>
5155
5156               <p>
5157                 This lists global overrides.  This list is normally
5158                 empty.  It is maintained by the local system
5159                 administrator.
5160               </p>
5161             </item>
5162
5163             <item>
5164               <p><file>DEBIAN/shlibs</file> files in the "build directory"</p>
5165
5166               <p>
5167                 When packages are being built, any
5168                 <file>debian/shlibs</file> files are copied into the
5169                 control file area of the temporary build directory and
5170                 given the name <file>shlibs</file>.  These files give
5171                 details of any shared libraries included in the
5172                 package.<footnote>
5173                     An example may help here.  Let us say that the
5174                     source package <tt>foo</tt> generates two binary
5175                     packages, <tt>libfoo2</tt> and
5176                     <tt>foo-runtime</tt>.  When building the binary
5177                     packages, the two packages are created in the
5178                     directories <file>debian/libfoo2</file> and
5179                     <file>debian/foo-runtime</file> respectively.
5180                     (<file>debian/tmp</file> could be used instead of one
5181                     of these.)  Since <tt>libfoo2</tt> provides the
5182                     <tt>libfoo</tt> shared library, it will require a
5183                     <tt>shlibs</tt> file, which will be installed in
5184                     <file>debian/libfoo2/DEBIAN/shlibs</file>, eventually
5185                     to become
5186                     <file>/var/lib/dpkg/info/libfoo2.shlibs</file>.  Then
5187                     when <prgn>dpkg-shlibdeps</prgn> is run on the
5188                     executable
5189                     <file>debian/foo-runtime/usr/bin/foo-prog</file>, it
5190                     will examine the
5191                     <file>debian/libfoo2/DEBIAN/shlibs</file> file to
5192                     determine whether <tt>foo-prog</tt>'s library
5193                     dependencies are satisfied by any of the libraries
5194                     provided by <tt>libfoo2</tt>.  For this reason,
5195                     <prgn>dpkg-shlibdeps</prgn> must only be run once
5196                     all of the individual binary packages'
5197                     <tt>shlibs</tt> files have been installed into the
5198                     build directory.
5199                 </footnote>
5200               </p>
5201             </item>
5202
5203             <item>
5204               <p><file>/var/lib/dpkg/info/*.shlibs</file></p>
5205
5206               <p>
5207                 These are the <file>shlibs</file> files corresponding to
5208                 all of the packages installed on the system, and are
5209                 maintained by the relevant package maintainers.
5210               </p>
5211             </item>
5212
5213             <item>
5214               <p><file>/etc/dpkg/shlibs.default</file></p>
5215
5216               <p>
5217                 This file lists any shared libraries whose packages
5218                 have failed to provide correct <file>shlibs</file> files.
5219                 It was used when the <file>shlibs</file> setup was first
5220                 introduced, but it is now normally empty.  It is
5221                 maintained by the <tt>dpkg</tt> maintainer.
5222               </p>
5223             </item>
5224           </list>
5225         </p>
5226       </sect1>
5227
5228       <sect1>
5229         <heading>How to use <prgn>dpkg-shlibdeps</prgn> and the
5230             <file>shlibs</file> files</heading>
5231
5232         <p>
5233           Put a call to
5234           <qref id="pkg-dpkg-shlibdeps"><prgn>dpkg-shlibdeps</prgn></qref>
5235           into your <file>debian/rules</file> file.  If your package
5236           contains only compiled binaries and libraries (but no scripts),
5237           you can use a command such as:
5238           <example compact="compact">
5239 dpkg-shlibdeps debian/tmp/usr/bin/* debian/tmp/usr/sbin/* \
5240   debian/tmp/usr/lib/*
5241           </example>
5242           Otherwise, you will need to explicitly list the compiled
5243           binaries and libraries.<footnote>
5244               If you are using <tt>debhelper</tt>, the
5245               <prgn>dh_shlibdeps</prgn> program will do this work for
5246               you.  It will also correctly handle multi-binary
5247               packages.
5248           </footnote>
5249         </p>
5250
5251         <p>
5252           This command puts the dependency information into the
5253           <file>debian/substvars</file> file, which is then used by
5254           <prgn>dpkg-gencontrol</prgn>.  You will need to place a
5255           <tt>${shlibs:Depends}</tt> variable in the <tt>Depends</tt>
5256           field in the control file for this to work.
5257         </p>
5258
5259         <p>
5260           If <prgn>dpkg-shlibdeps</prgn> doesn't complain, you're
5261           done.  If it does complain you might need to create your own
5262           <file>debian/shlibs.local</file> file, as explained below (see
5263           <ref id="shlibslocal">).
5264         </p>
5265
5266         <p>
5267           If you have multiple binary packages, you will need to call
5268           <prgn>dpkg-shlibdeps</prgn> on each one which contains
5269           compiled libraries or binaries.  In such a case, you will
5270           need to use the <tt>-T</tt> option to the <tt>dpkg</tt>
5271           utilities to specify a different <file>substvars</file> file.
5272         </p>
5273
5274         <p>
5275           If you are creating a udeb for use in the Debian Installer, you
5276           will need to specify that <prgn>dpkg-shlibdeps</prgn> should use
5277           the dependency line of type <tt>udeb</tt> by adding
5278           <tt>-tudeb</tt> as option<footnote>
5279               <prgn>dh_shlibdeps</prgn> from the <tt>debhelper</tt> suite
5280               will automatically add this option if it knows it is
5281               processing a udeb.
5282           </footnote>. If there is no dependency line of type <tt>udeb</tt>
5283           in the <file>shlibs</file> file, <prgn>dpkg-shlibdeps</prgn> will
5284           fall back to the regular dependency line.
5285         </p>
5286
5287         <p>
5288           For more details on dpkg-shlibdeps, please see
5289           <ref id="pkg-dpkg-shlibdeps"> and
5290           <manref name="dpkg-shlibdeps" section="1">.
5291         </p>
5292       </sect1>
5293
5294       <sect1 id="shlibs">
5295         <heading>The <file>shlibs</file> File Format</heading>
5296
5297         <p>
5298           Each <file>shlibs</file> file has the same format.  Lines
5299           beginning with <tt>#</tt> are considered to be comments and
5300           are ignored.  Each line is of the form:
5301           <example compact="compact">
5302 [<var>type</var>: ]<var>library-name</var> <var>soname-version</var> <var>dependencies ...</var>
5303           </example>
5304         </p>
5305
5306         <p>
5307           We will explain this by reference to the example of the
5308           <tt>zlib1g</tt> package, which (at the time of writing)
5309           installs the shared library <file>/usr/lib/libz.so.1.1.3</file>.
5310         </p>
5311
5312         <p>
5313           <var>type</var> is an optional element that indicates the type
5314           of package for which the line is valid. The only type currently
5315           in use is <tt>udeb</tt>. The colon and space after the type are
5316           required.
5317         </p>
5318
5319         <p>
5320           <var>library-name</var> is the name of the shared library,
5321           in this case <tt>libz</tt>.  (This must match the name part
5322           of the soname, see below.)
5323         </p>
5324
5325         <p>
5326           <var>soname-version</var> is the version part of the soname of
5327           the library.  The soname is the thing that must exactly match
5328           for the library to be recognized by the dynamic linker, and is
5329           usually of the form
5330           <tt><var>name</var>.so.<var>major-version</var></tt>, in our
5331           example, <tt>libz.so.1</tt>.<footnote>
5332               This can be determined using the command
5333               <example compact="compact">
5334 objdump -p /usr/lib/libz.so.1.1.3 | grep SONAME
5335               </example>
5336           </footnote>
5337           The version part is the part which comes after
5338           <tt>.so.</tt>, so in our case, it is <tt>1</tt>.
5339         </p>
5340
5341         <p>
5342           <var>dependencies</var> has the same syntax as a dependency
5343           field in a binary package control file.  It should give
5344           details of which packages are required to satisfy a binary
5345           built against the version of the library contained in the
5346           package.  See <ref id="depsyntax"> for details.
5347         </p>
5348
5349         <p>
5350           In our example, if the first version of the <tt>zlib1g</tt>
5351           package which contained a minor number of at least
5352           <tt>1.3</tt> was <var>1:1.1.3-1</var>, then the
5353           <tt>shlibs</tt> entry for this library could say:
5354           <example compact="compact">
5355 libz 1 zlib1g (>= 1:1.1.3)
5356           </example>
5357           The version-specific dependency is to avoid warnings from
5358           the dynamic linker about using older shared libraries with
5359           newer binaries.
5360         </p>
5361
5362         <p>
5363           As zlib1g also provides a udeb containing the shared library,
5364           there would also be a second line:
5365           <example compact="compact">
5366 udeb: libz 1 zlib1g-udeb (>= 1:1.1.3)
5367           </example>
5368         </p>
5369       </sect1>
5370
5371       <sect1>
5372         <heading>Providing a <file>shlibs</file> file</heading>
5373
5374         <p>
5375           If your package provides a shared library, you need to create
5376           a <file>shlibs</file> file following the format described above.
5377           It is usual to call this file <file>debian/shlibs</file> (but if
5378           you have multiple binary packages, you might want to call it
5379           <file>debian/shlibs.<var>package</var></file> instead).  Then
5380           let <file>debian/rules</file> install it in the control area:
5381           <example compact="compact">
5382 install -m644 debian/shlibs debian/tmp/DEBIAN
5383           </example>
5384           or, in the case of a multi-binary package:
5385           <example compact="compact">
5386 install -m644 debian/shlibs.<var>package</var> debian/<var>package</var>/DEBIAN/shlibs
5387           </example>
5388           An alternative way of doing this is to create the
5389           <file>shlibs</file> file in the control area directly from
5390           <file>debian/rules</file> without using a <file>debian/shlibs</file>
5391           file at all,<footnote>
5392               This is what <prgn>dh_makeshlibs</prgn> in the
5393               <tt>debhelper</tt> suite does. If your package also has a udeb
5394               that provides a shared library, <prgn>dh_makeshlibs</prgn> can
5395               automatically generate the <tt>udeb:</tt> lines if you specify
5396               the name of the udeb with the <tt>--add-udeb</tt> option.
5397           </footnote>
5398           since the <file>debian/shlibs</file> file itself is ignored by
5399           <prgn>dpkg-shlibdeps</prgn>.
5400         </p>
5401
5402         <p>
5403           As <prgn>dpkg-shlibdeps</prgn> reads the
5404           <file>DEBIAN/shlibs</file> files in all of the binary packages
5405           being built from this source package, all of the
5406           <file>DEBIAN/shlibs</file> files should be installed before
5407           <prgn>dpkg-shlibdeps</prgn> is called on any of the binary
5408           packages.
5409         </p>
5410       </sect1>
5411
5412       <sect1 id="shlibslocal">
5413         <heading>Writing the <file>debian/shlibs.local</file> file</heading>
5414
5415         <p>
5416           This file is intended only as a <em>temporary</em> fix if
5417           your binaries or libraries depend on a library whose package
5418           does not yet provide a correct <file>shlibs</file> file.
5419         </p>
5420
5421         <p>
5422           We will assume that you are trying to package a binary
5423           <tt>foo</tt>.  When you try running
5424           <prgn>dpkg-shlibdeps</prgn> you get the following error
5425           message (<tt>-O</tt> displays the dependency information on
5426           <tt>stdout</tt> instead of writing it to
5427           <tt>debian/substvars</tt>, and the lines have been wrapped
5428           for ease of reading):
5429           <example compact="compact">
5430 $ dpkg-shlibdeps -O debian/tmp/usr/bin/foo
5431 dpkg-shlibdeps: warning: unable to find dependency
5432   information for shared library libbar (soname 1,
5433   path /usr/lib/libbar.so.1, dependency field Depends)
5434 shlibs:Depends=libc6 (>= 2.2.2-2)
5435           </example>
5436           You can then run <prgn>ldd</prgn> on the binary to find the
5437           full location of the library concerned:
5438           <example compact="compact">
5439 $ ldd foo
5440 libbar.so.1 => /usr/lib/libbar.so.1 (0x4001e000)
5441 libc.so.6 => /lib/libc.so.6 (0x40032000)
5442 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
5443           </example>
5444           So the <prgn>foo</prgn> binary depends on the
5445           <prgn>libbar</prgn> shared library, but no package seems to
5446           provide a <file>*.shlibs</file> file handling
5447           <file>libbar.so.1</file> in <file>/var/lib/dpkg/info/</file>.  Let's
5448           determine the package responsible:
5449           <example compact="compact">
5450 $ dpkg -S /usr/lib/libbar.so.1
5451 bar1: /usr/lib/libbar.so.1
5452 $ dpkg -s bar1 | grep Version
5453 Version: 1.0-1
5454           </example>
5455           This tells us that the <tt>bar1</tt> package, version 1.0-1,
5456           is the one we are using.  Now we can file a bug against the
5457           <tt>bar1</tt> package and create our own
5458           <file>debian/shlibs.local</file> to locally fix the problem.
5459           Including the following line into your
5460           <file>debian/shlibs.local</file> file:
5461           <example compact="compact">
5462 libbar 1 bar1 (>= 1.0-1)
5463           </example>
5464           should allow the package build to work.
5465         </p>
5466
5467         <p>
5468           As soon as the maintainer of <tt>bar1</tt> provides a
5469           correct <file>shlibs</file> file, you should remove this line
5470           from your <file>debian/shlibs.local</file> file.  (You should
5471           probably also then have a versioned <tt>Build-Depends</tt>
5472           on <tt>bar1</tt> to help ensure that others do not have the
5473           same problem building your package.)
5474         </p>
5475       </sect1>
5476
5477       </sect>
5478
5479     </chapt>
5480
5481
5482     <chapt id="opersys"><heading>The Operating System</heading>
5483
5484       <sect>
5485         <heading>File system hierarchy</heading>
5486
5487
5488         <sect1 id="fhs">
5489           <heading>File system Structure</heading>
5490
5491           <p>
5492             The location of all installed files and directories must
5493             comply with the File system Hierarchy Standard (FHS),
5494             version 2.3, with the exceptions noted below, and except
5495             where doing so would violate other terms of Debian
5496             Policy.  The following exceptions to the FHS apply:
5497
5498             <enumlist>
5499               <item>
5500                 <p>
5501                   Legacy XFree86 servers are permitted to retain the
5502                   configuration file location 
5503                   <file>/etc/X11/XF86Config-4</file>.
5504                 </p>
5505               </item>
5506               <item>
5507                 <p>
5508                   The optional rules related to user specific
5509                   configuration files for applications are stored in
5510                   the user's home directory are relaxed.  It is
5511                   recommended that such files start with the
5512                   '<tt>.</tt>' character (a "dot file"), and if an
5513                   application needs to create more than one dot file
5514                   then the preferred placement is in a subdirectory
5515                   with a name starting with a '.' character, (a "dot
5516                   directory"). In this case it is recommended the
5517                   configuration files not start with the '.'
5518                   character.
5519                 </p>
5520               </item>
5521               <item>
5522                 <p>
5523                   The requirement for amd64 to use <file>/lib64</file>
5524                   for 64 bit binaries is removed.
5525                 </p>
5526               </item>
5527               <item>
5528                 <p>
5529                   The requirement that
5530                   <file>/usr/local/share/man</file> be "synonymous"
5531                   with <file>/usr/local/man</file> is relaxed to a
5532                   recommendation</p>
5533               </item>
5534               <item>
5535                 <p>
5536                   The requirement that windowmanagers with a single
5537                   configuration file call it <file>system.*wmrc</file>
5538                   is removed, as is the restriction that the window
5539                   manager subdirectory be named identically to the
5540                   window manager name itself.
5541                 </p>
5542               </item>
5543               <item>
5544                 <p>
5545                   The requirement that boot manager configuration
5546                   files live in <file>/etc</file>, or at least are
5547                   symlinked there, is relaxed to a recommendation.
5548                 </p>
5549               </item>
5550             </enumlist>
5551
5552           </p>
5553           <p>
5554             The version of this document referred here can be
5555             found in the <tt>debian-policy</tt> package or on <url
5556             id="http://www.debian.org/doc/packaging-manuals/fhs/"
5557               name="FHS (Debian copy)"> alongside this manual (or, if
5558             you have the <package>debian-policy</package> installed,
5559             you can try <url
5560               id="file:///usr/share/doc/debian-policy/fhs/" name="FHS
5561               (local copy)">). The
5562             latest version, which may be a more recent version, may
5563             be found on
5564             <url id="http://www.pathname.com/fhs/" name="FHS (upstream)">.
5565             Specific questions about following the standard may be
5566             asked on the <tt>debian-devel</tt> mailing list, or
5567             referred to the FHS mailing list (see the
5568             <url id="http://www.pathname.com/fhs/" name="FHS web site"> for
5569             more information).
5570           </p>
5571         </sect1>
5572
5573         <sect1>
5574           <heading>Site-specific programs</heading>
5575
5576           <p>
5577             As mandated by the FHS, packages must not place any
5578             files in <file>/usr/local</file>, either by putting them in
5579             the file system archive to be unpacked by <prgn>dpkg</prgn>
5580             or by manipulating them in their maintainer scripts.
5581           </p>
5582
5583           <p>
5584             However, the package may create empty directories below
5585             <file>/usr/local</file> so that the system administrator knows
5586             where to place site-specific files.  These are not
5587             directories <em>in</em> <file>/usr/local</file>, but are
5588             children of directories in <file>/usr/local</file>.  These
5589             directories (<file>/usr/local/*/dir/</file>)
5590             should be removed on package removal if they are
5591             empty.
5592           </p>
5593
5594           <p>
5595             Note, that this applies only to directories <em>below</em>
5596             <file>/usr/local</file>, not <em>in</em> <file>/usr/local</file>.
5597             Packages must not create sub-directories in the directory
5598             <file>/usr/local</file> itself, except those listed in FHS,
5599             section 4.5.  However, you may create directories below
5600             them as you wish. You must not remove any of the
5601             directories listed in 4.5, even if you created them.
5602           </p>
5603
5604           <p>
5605             Since <file>/usr/local</file> can be mounted read-only from a
5606             remote server, these directories must be created and
5607             removed by the <prgn>postinst</prgn> and <prgn>prerm</prgn>
5608             maintainer scripts and not be included in the
5609             <file>.deb</file> archive.  These scripts must not fail if
5610             either of these operations fail.
5611           </p>
5612
5613           <p>
5614             For example, the <tt>emacsen-common</tt> package could
5615             contain something like
5616             <example compact="compact">
5617 if [ ! -e /usr/local/share/emacs ]
5618 then
5619   if mkdir /usr/local/share/emacs 2>/dev/null
5620   then
5621     chown root:staff /usr/local/share/emacs
5622     chmod 2775 /usr/local/share/emacs
5623   fi
5624 fi
5625             </example>
5626             in its <prgn>postinst</prgn> script, and
5627             <example compact="compact">
5628 rmdir /usr/local/share/emacs/site-lisp 2>/dev/null || true
5629 rmdir /usr/local/share/emacs 2>/dev/null || true
5630             </example>
5631             in the <prgn>prerm</prgn> script.  (Note that this form is
5632             used to ensure that if the script is interrupted, the
5633             directory <file>/usr/local/share/emacs</file> will still be
5634             removed.)
5635           </p>
5636
5637           <p>
5638             If you do create a directory in <file>/usr/local</file> for
5639             local additions to a package, you should ensure that
5640             settings in <file>/usr/local</file> take precedence over the
5641             equivalents in <file>/usr</file>.
5642           </p>
5643
5644           <p>
5645             However, because <file>/usr/local</file> and its contents are
5646             for exclusive use of the local administrator, a package
5647             must not rely on the presence or absence of files or
5648             directories in <file>/usr/local</file> for normal operation.
5649           </p>
5650
5651           <p>
5652             The <file>/usr/local</file> directory itself and all the
5653             subdirectories created by the package should (by default) have
5654             permissions 2775 (group-writable and set-group-id) and be
5655             owned by <tt>root:staff</tt>.
5656           </p>
5657         </sect1>
5658
5659         <sect1>
5660           <heading>The system-wide mail directory</heading>
5661           <p>
5662             The system-wide mail directory is <file>/var/mail</file>. This
5663             directory is part of the base system and should not owned
5664             by any particular mail agents.  The use of the old
5665             location <file>/var/spool/mail</file> is deprecated, even
5666             though the spool may still be physically located there.
5667             To maintain partial upgrade compatibility for systems
5668             which have <file>/var/spool/mail</file> as their physical mail
5669             spool, packages using <file>/var/mail</file> must depend on
5670             either <package>libc6</package> (&gt;= 2.1.3-13), or on
5671             <package>base-files</package> (&gt;= 2.2.0), or on later
5672             versions of either one of these packages.
5673           </p>
5674         </sect1>
5675       </sect>
5676
5677       <sect>
5678         <heading>Users and groups</heading>
5679
5680         <sect1>
5681           <heading>Introduction</heading>
5682           <p>
5683             The Debian system can be configured to use either plain or
5684             shadow passwords.
5685           </p>
5686
5687           <p>
5688             Some user ids (UIDs) and group ids (GIDs) are reserved
5689             globally for use by certain packages.  Because some
5690             packages need to include files which are owned by these
5691             users or groups, or need the ids compiled into binaries,
5692             these ids must be used on any Debian system only for the
5693             purpose for which they are allocated. This is a serious
5694             restriction, and we should avoid getting in the way of
5695             local administration policies. In particular, many sites
5696             allocate users and/or local system groups starting at 100.
5697           </p>
5698
5699           <p>
5700             Apart from this we should have dynamically allocated ids,
5701             which should by default be arranged in some sensible
5702             order, but the behavior should be configurable.
5703           </p>
5704
5705           <p>
5706             Packages other than <tt>base-passwd</tt> must not modify
5707             <file>/etc/passwd</file>, <file>/etc/shadow</file>,
5708             <file>/etc/group</file> or <file>/etc/gshadow</file>.
5709           </p>
5710         </sect1>
5711
5712         <sect1>
5713           <heading>UID and GID classes</heading>
5714           <p>
5715             The UID and GID numbers are divided into classes as
5716             follows:
5717             <taglist>
5718               <tag>0-99:</tag>
5719               <item>
5720                 <p>
5721                   Globally allocated by the Debian project, the same
5722                   on every Debian system.  These ids will appear in
5723                   the <file>passwd</file> and <file>group</file> files of all
5724                   Debian systems, new ids in this range being added
5725                   automatically as the <tt>base-passwd</tt> package is
5726                   updated.
5727                 </p>
5728
5729                 <p>
5730                   Packages which need a single statically allocated
5731                   uid or gid should use one of these; their
5732                   maintainers should ask the <tt>base-passwd</tt>
5733                   maintainer for ids.
5734                 </p>
5735               </item>
5736
5737               <tag>100-999:</tag>
5738               <item>
5739                 <p>
5740                   Dynamically allocated system users and groups.
5741                   Packages which need a user or group, but can have
5742                   this user or group allocated dynamically and
5743                   differently on each system, should use <tt>adduser
5744                   --system</tt> to create the group and/or user.
5745                   <prgn>adduser</prgn> will check for the existence of
5746                   the user or group, and if necessary choose an unused
5747                   id based on the ranges specified in
5748                   <file>adduser.conf</file>.
5749                 </p>
5750               </item>
5751
5752               <tag>1000-29999:</tag>
5753               <item>
5754                 <p>
5755                   Dynamically allocated user accounts.  By default
5756                   <prgn>adduser</prgn> will choose UIDs and GIDs for
5757                   user accounts in this range, though
5758                   <file>adduser.conf</file> may be used to modify this
5759                   behavior.
5760                 </p>
5761               </item>
5762
5763               <tag>30000-59999:</tag>
5764               <item>
5765                 <p>Reserved.</p>
5766               </item>
5767
5768               <tag>60000-64999:</tag>
5769               <item>
5770                 <p>
5771                   Globally allocated by the Debian project, but only
5772                   created on demand. The ids are allocated centrally
5773                   and statically, but the actual accounts are only
5774                   created on users' systems on demand.
5775                 </p>
5776
5777                 <p>
5778                   These ids are for packages which are obscure or
5779                   which require many statically-allocated ids.  These
5780                   packages should check for and create the accounts in
5781                   <file>/etc/passwd</file> or <file>/etc/group</file> (using
5782                   <prgn>adduser</prgn> if it has this facility) if
5783                   necessary.  Packages which are likely to require
5784                   further allocations should have a "hole" left after
5785                   them in the allocation, to give them room to
5786                   grow.
5787                 </p>
5788               </item>
5789
5790               <tag>65000-65533:</tag>
5791               <item>
5792                 <p>Reserved.</p>
5793               </item>
5794
5795               <tag>65534:</tag>
5796               <item>
5797                 <p>
5798                   User <tt>nobody</tt>. The corresponding gid refers
5799                   to the group <tt>nogroup</tt>.
5800                 </p>
5801               </item>
5802
5803               <tag>65535:</tag>
5804               <item>
5805                 <p>
5806                   <tt>(uid_t)(-1) == (gid_t)(-1)</tt> <em>must
5807                   not</em> be used, because it is the error return
5808                   sentinel value.
5809                 </p>
5810               </item>
5811             </taglist>
5812           </p>
5813         </sect1>
5814       </sect>
5815
5816       <sect id="sysvinit">
5817         <heading>System run levels and <file>init.d</file> scripts</heading>
5818
5819         <sect1 id="/etc/init.d">
5820           <heading>Introduction</heading>
5821
5822           <p>
5823             The <file>/etc/init.d</file> directory contains the scripts
5824             executed by <prgn>init</prgn> at boot time and when the
5825             init state (or "runlevel") is changed (see <manref
5826             name="init" section="8">).
5827           </p>
5828
5829           <p>
5830             There are at least two different, yet functionally
5831             equivalent, ways of handling these scripts.  For the sake
5832             of simplicity, this document describes only the symbolic
5833             link method. However, it must not be assumed by maintainer
5834             scripts that this method is being used, and any automated
5835             manipulation of the various runlevel behaviors by
5836             maintainer scripts must be performed using
5837             <prgn>update-rc.d</prgn> as described below and not by
5838             manually installing or removing symlinks.  For information
5839             on the implementation details of the other method,
5840             implemented in the <tt>file-rc</tt> package, please refer
5841             to the documentation of that package.
5842           </p>
5843
5844           <p>
5845             These scripts are referenced by symbolic links in the
5846             <file>/etc/rc<var>n</var>.d</file> directories.  When changing
5847             runlevels, <prgn>init</prgn> looks in the directory
5848             <file>/etc/rc<var>n</var>.d</file> for the scripts it should
5849             execute, where <tt><var>n</var></tt> is the runlevel that
5850             is being changed to, or <tt>S</tt> for the boot-up
5851             scripts.
5852           </p>
5853
5854           <p>
5855             The names of the links all have the form
5856             <file>S<var>mm</var><var>script</var></file> or
5857             <file>K<var>mm</var><var>script</var></file> where
5858             <var>mm</var> is a two-digit number and <var>script</var>
5859             is the name of the script (this should be the same as the
5860             name of the actual script in <file>/etc/init.d</file>).
5861           </p>
5862
5863           <p>
5864             When <prgn>init</prgn> changes runlevel first the targets
5865             of the links whose names start with a <tt>K</tt> are
5866             executed, each with the single argument <tt>stop</tt>,
5867             followed by the scripts prefixed with an <tt>S</tt>, each
5868             with the single argument <tt>start</tt>.  (The links are
5869             those in the <file>/etc/rc<var>n</var>.d</file> directory
5870             corresponding to the new runlevel.)  The <tt>K</tt> links
5871             are responsible for killing services and the <tt>S</tt>
5872             link for starting services upon entering the runlevel.
5873           </p>
5874
5875           <p>
5876             For example, if we are changing from runlevel 2 to
5877             runlevel 3, init will first execute all of the <tt>K</tt>
5878             prefixed scripts it finds in <file>/etc/rc3.d</file>, and then
5879             all of the <tt>S</tt> prefixed scripts in that directory.
5880             The links starting with <tt>K</tt> will cause the
5881             referred-to file to be executed with an argument of
5882             <tt>stop</tt>, and the <tt>S</tt> links with an argument
5883             of <tt>start</tt>.
5884           </p>
5885
5886           <p>
5887             The two-digit number <var>mm</var> is used to determine
5888             the order in which to run the scripts: low-numbered links
5889             have their scripts run first.  For example, the
5890             <tt>K20</tt> scripts will be executed before the
5891             <tt>K30</tt> scripts.  This is used when a certain service
5892             must be started before another.  For example, the name
5893             server <prgn>bind</prgn> might need to be started before
5894             the news server <prgn>inn</prgn> so that <prgn>inn</prgn>
5895             can set up its access lists.  In this case, the script
5896             that starts <prgn>bind</prgn> would have a lower number
5897             than the script that starts <prgn>inn</prgn> so that it
5898             runs first:
5899             <example compact="compact">
5900 /etc/rc2.d/S17bind
5901 /etc/rc2.d/S70inn
5902             </example>
5903           </p>
5904
5905           <p>
5906             The two runlevels 0 (halt) and 6 (reboot) are slightly
5907             different.  In these runlevels, the links with an
5908             <tt>S</tt> prefix are still called after those with a
5909             <tt>K</tt> prefix, but they too are called with the single
5910             argument <tt>stop</tt>.
5911           </p>
5912
5913           <p>
5914             Also, if the script name ends in <tt>.sh</tt>, the script
5915             will be sourced in runlevel <tt>S</tt> rather than being
5916             run in a forked subprocess, but will be explicitly run by
5917             <prgn>sh</prgn> in all other runlevels.
5918           </p>
5919         </sect1>
5920
5921         <sect1>
5922           <heading>Writing the scripts</heading>
5923
5924           <p>
5925             Packages that include daemons for system services should
5926             place scripts in <file>/etc/init.d</file> to start or stop
5927             services at boot time or during a change of runlevel.
5928             These scripts should be named
5929             <file>/etc/init.d/<var>package</var></file>, and they should
5930             accept one argument, saying what to do:
5931
5932             <taglist>
5933               <tag><tt>start</tt></tag>
5934               <item>start the service,</item>
5935
5936               <tag><tt>stop</tt></tag>
5937               <item>stop the service,</item>
5938
5939               <tag><tt>restart</tt></tag>
5940               <item>stop and restart the service if it's already running,
5941                   otherwise start the service</item>
5942
5943               <tag><tt>reload</tt></tag>
5944               <item><p>cause the configuration of the service to be
5945                   reloaded without actually stopping and restarting
5946                   the service,</item>
5947
5948               <tag><tt>force-reload</tt></tag>
5949               <item>cause the configuration to be reloaded if the
5950                   service supports this, otherwise restart the
5951                   service.</item>
5952             </taglist>
5953
5954             The <tt>start</tt>, <tt>stop</tt>, <tt>restart</tt>, and
5955             <tt>force-reload</tt> options should be supported by all
5956             scripts in <file>/etc/init.d</file>, the <tt>reload</tt>
5957             option is optional.
5958           </p>
5959
5960           <p>
5961             The <file>init.d</file> scripts must ensure that they will
5962             behave sensibly (i.e., returning success and not starting
5963             multiple copies of a service) if invoked with <tt>start</tt>
5964             when the service is already running, or with <tt>stop</tt>
5965             when it isn't, and that they don't kill unfortunately-named
5966             user processes.  The best way to achieve this is usually to
5967             use <prgn>start-stop-daemon</prgn> with the <tt>--oknodo</tt>
5968             option.
5969           </p>
5970
5971           <p>
5972             If a service reloads its configuration automatically (as
5973             in the case of <prgn>cron</prgn>, for example), the
5974             <tt>reload</tt> option of the <file>init.d</file> script
5975             should behave as if the configuration has been reloaded
5976             successfully.
5977           </p>
5978
5979           <p>
5980             The <file>/etc/init.d</file> scripts must be treated as
5981             configuration files, either (if they are present in the
5982             package, that is, in the .deb file) by marking them as
5983             <tt>conffile</tt>s, or, (if they do not exist in the .deb)
5984             by managing them correctly in the maintainer scripts (see
5985             <ref id="config-files">).  This is important since we want
5986             to give the local system administrator the chance to adapt
5987             the scripts to the local system, e.g., to disable a
5988             service without de-installing the package, or to specify
5989             some special command line options when starting a service,
5990             while making sure their changes aren't lost during the next
5991             package upgrade.
5992           </p>
5993
5994           <p>
5995             These scripts should not fail obscurely when the
5996             configuration files remain but the package has been
5997             removed, as configuration files remain on the system after
5998             the package has been removed.  Only when <prgn>dpkg</prgn>
5999             is executed with the <tt>--purge</tt> option will
6000             configuration files be removed.  In particular, as the
6001             <file>/etc/init.d/<var>package</var></file> script itself is
6002             usually a <tt>conffile</tt>, it will remain on the system
6003             if the package is removed but not purged.  Therefore, you
6004             should include a <tt>test</tt> statement at the top of the
6005             script, like this:
6006             <example compact="compact">
6007 test -f <var>program-executed-later-in-script</var> || exit 0
6008             </example>
6009           </p>
6010
6011           <p>
6012             Often there are some variables in the <file>init.d</file>
6013             scripts whose values control the behavior of the scripts,
6014             and which a system administrator is likely to want to
6015             change.  As the scripts themselves are frequently
6016             <tt>conffile</tt>s, modifying them requires that the
6017             administrator merge in their changes each time the package
6018             is upgraded and the <tt>conffile</tt> changes.  To ease
6019             the burden on the system administrator, such configurable
6020             values should not be placed directly in the script.
6021             Instead, they should be placed in a file in
6022             <file>/etc/default</file>, which typically will have the same
6023             base name as the <file>init.d</file> script.  This extra file
6024             should be sourced by the script when the script runs.  It
6025             must contain only variable settings and comments in SUSv3
6026             <prgn>sh</prgn> format.  It may either be a
6027             <tt>conffile</tt> or a configuration file maintained by
6028             the package maintainer scripts.  See <ref id="config-files">
6029             for more details.
6030           </p>
6031
6032           <p>
6033             To ensure that vital configurable values are always
6034             available, the <file>init.d</file> script should set default
6035             values for each of the shell variables it uses, either
6036             before sourcing the <file>/etc/default/</file> file or
6037             afterwards using something like the <tt>:
6038             ${VAR:=default}</tt> syntax.  Also, the <file>init.d</file>
6039             script must behave sensibly and not fail if the
6040             <file>/etc/default</file> file is deleted.
6041           </p>
6042         </sect1>
6043
6044         <sect1>
6045           <heading>Interfacing with the initscript system</heading>
6046
6047           <p>
6048             Maintainers should use the abstraction layer provided by
6049             the <prgn>update-rc.d</prgn> and <prgn>invoke-rc.d</prgn>
6050             programs to deal with initscripts in their packages'
6051             scripts such as <prgn>postinst</prgn>, <prgn>prerm</prgn>
6052             and <prgn>postrm</prgn>.
6053           </p>
6054
6055           <p>
6056             Directly managing the /etc/rc?.d links and directly
6057             invoking the <file>/etc/init.d/</file> initscripts should
6058             be done only by packages providing the initscript
6059             subsystem (such as <prgn>sysv-rc</prgn> and
6060             <prgn>file-rc</prgn>).
6061           </p>
6062
6063           <sect2>
6064             <heading>Managing the links</heading>
6065
6066             <p>
6067               The program <prgn>update-rc.d</prgn> is provided for
6068               package maintainers to arrange for the proper creation and
6069               removal of <file>/etc/rc<var>n</var>.d</file> symbolic links,
6070               or their functional equivalent if another method is being
6071               used.  This may be used by maintainers in their packages'
6072               <prgn>postinst</prgn> and <prgn>postrm</prgn> scripts.
6073             </p>
6074
6075             <p>
6076               You must not include any <file>/etc/rc<var>n</var>.d</file>
6077               symbolic links in the actual archive or manually create or
6078               remove the symbolic links in maintainer scripts; you must
6079               use the <prgn>update-rc.d</prgn> program instead.  (The
6080               former will fail if an alternative method of maintaining
6081               runlevel information is being used.)  You must not include
6082               the <file>/etc/rc<var>n</var>.d</file> directories themselves
6083               in the archive either.  (Only the <tt>sysvinit</tt>
6084               package may do so.)
6085             </p>
6086
6087             <p>
6088               By default <prgn>update-rc.d</prgn> will start services in
6089               each of the multi-user state runlevels (2, 3, 4, and 5)
6090               and stop them in the halt runlevel (0), the single-user
6091               runlevel (1) and the reboot runlevel (6).  The system
6092               administrator will have the opportunity to customize
6093               runlevels by simply adding, moving, or removing the
6094               symbolic links in <file>/etc/rc<var>n</var>.d</file> if
6095               symbolic links are being used, or by modifying
6096               <file>/etc/runlevel.conf</file> if the <tt>file-rc</tt> method
6097               is being used.
6098             </p>
6099
6100             <p>
6101               To get the default behavior for your package, put in your
6102               <prgn>postinst</prgn> script
6103               <example compact="compact">
6104                 update-rc.d <var>package</var> defaults
6105               </example>
6106               and in your <prgn>postrm</prgn>
6107               <example compact="compact">
6108                 if [ "$1" = purge ]; then
6109                 update-rc.d <var>package</var> remove
6110                 fi
6111               </example>. Note that if your package changes runlevels
6112               or priority, you may have to remove and recreate the links,
6113               since otherwise the old links may persist. Refer to the
6114               documentation of <prgn>update-rc.d</prgn>.
6115             </p>
6116
6117             <p>
6118               This will use a default sequence number of 20.  If it does
6119               not matter when or in which order the <file>init.d</file>
6120               script is run, use this default.  If it does, then you
6121               should talk to the maintainer of the <prgn>sysvinit</prgn>
6122               package or post to <tt>debian-devel</tt>, and they will
6123               help you choose a number.
6124             </p>
6125
6126             <p>
6127               For more information about using <tt>update-rc.d</tt>,
6128               please consult its man page <manref name="update-rc.d"
6129                 section="8">.
6130             </p>
6131           </sect2>
6132
6133           <sect2>
6134             <heading>Running initscripts</heading>
6135             <p>
6136               The program <prgn>invoke-rc.d</prgn> is provided to make
6137               it easier for package maintainers to properly invoke an
6138               initscript, obeying runlevel and other locally-defined
6139               constraints that might limit a package's right to start,
6140               stop and otherwise manage services. This program may be
6141               used by maintainers in their packages' scripts.
6142             </p>
6143
6144             <p>
6145               The package maintainer scripts must use
6146               <prgn>invoke-rc.d</prgn> to invoke the
6147               <file>/etc/init.d/*</file> initscripts, instead of
6148               calling them directly.
6149             </p>
6150
6151             <p>
6152               By default, <prgn>invoke-rc.d</prgn> will pass any
6153               action requests (start, stop, reload, restart...) to the
6154               <file>/etc/init.d</file> script, filtering out requests
6155               to start or restart a service out of its intended
6156               runlevels.
6157             </p>
6158
6159             <p>
6160               Most packages will simply need to change:
6161               <example compact="compact">/etc/init.d/&lt;package&gt;
6162               &lt;action&gt;</example> in their <prgn>postinst</prgn>
6163               and <prgn>prerm</prgn> scripts to:
6164               <example compact="compact">
6165         if which invoke-rc.d >/dev/null 2>&1; then
6166                 invoke-rc.d <var>package</var> &lt;action&gt;
6167         else
6168                 /etc/init.d/<var>package</var> &lt;action&gt;
6169         fi
6170               </example>
6171             </p>
6172
6173             <p>
6174               A package should register its initscript services using
6175               <prgn>update-rc.d</prgn> before it tries to invoke them
6176               using <prgn>invoke-rc.d</prgn>. Invocation of
6177               unregistered services may fail.
6178             </p>
6179
6180             <p>
6181               For more information about using
6182               <prgn>invoke-rc.d</prgn>, please consult its man page
6183               <manref name="invoke-rc.d" section="8">.
6184             </p>
6185           </sect2>
6186         </sect1>
6187
6188         <sect1>
6189           <heading>Boot-time initialization</heading>
6190
6191           <p>
6192             There used to be another directory, <file>/etc/rc.boot</file>,
6193             which contained scripts which were run once per machine
6194             boot. This has been deprecated in favour of links from
6195             <file>/etc/rcS.d</file> to files in <file>/etc/init.d</file> as
6196             described in <ref id="/etc/init.d">.  Packages must not
6197             place files in <file>/etc/rc.boot</file>.
6198           </p>
6199         </sect1>
6200
6201         <sect1>
6202           <heading>Example</heading>
6203
6204           <p>
6205             An example on which you can base your
6206             <file>/etc/init.d</file> scripts is found in
6207             <file>/etc/init.d/skeleton</file>.
6208           </p>
6209
6210         </sect1>
6211       </sect>
6212
6213       <sect>
6214         <heading>Console messages from <file>init.d</file> scripts</heading>
6215
6216         <p>
6217           This section describes the formats to be used for messages
6218           written to standard output by the <file>/etc/init.d</file>
6219           scripts.  The intent is to improve the consistency of
6220           Debian's startup and shutdown look and feel.  For this
6221           reason, please look very carefully at the details.  We want
6222           the messages to have the same format in terms of wording,
6223           spaces, punctuation and case of letters.
6224         </p>
6225
6226         <p>
6227           Here is a list of overall rules that should be used for
6228           messages generated by <file>/etc/init.d</file> scripts.  
6229         </p>
6230
6231         <p>
6232           <list>
6233             <item>
6234                 The message should fit in one line (fewer than 80
6235                 characters), start with a capital letter and end with
6236                 a period (<tt>.</tt>) and line feed (<tt>"\n"</tt>).
6237             </item>
6238
6239             <item>
6240               If the script is performing some time consuming task in
6241               the background (not merely starting or stopping a
6242               program, for instance), an ellipsis (three dots:
6243               <tt>...</tt>) should be output to the screen, with no
6244               leading or tailing whitespace or line feeds.
6245             </item>
6246
6247             <item>
6248               The messages should appear as if the computer is telling
6249               the user what it is doing (politely :-), but should not
6250                 mention "it" directly.  For example, instead of:
6251                 <example compact="compact">
6252 I'm starting network daemons: nfsd mountd.
6253                 </example>
6254                 the message should say
6255                 <example compact="compact">
6256 Starting network daemons: nfsd mountd.
6257                 </example>
6258             </item>
6259           </list>
6260         </p>
6261
6262         <p>
6263           <tt>init.d</tt> script should use the following  standard
6264           message formats for the situations enumerated below.
6265         </p>
6266
6267         <p>
6268           <list>
6269             <item>
6270               <p>When daemons are started</p>
6271
6272               <p>
6273                 If the script starts one or more daemons, the output
6274                 should look like this (a single line, no leading
6275                 spaces):
6276                 <example compact="compact">
6277 Starting <var>description</var>: <var>daemon-1</var> ... <var>daemon-n</var>.
6278                 </example>
6279                 The <var>description</var> should describe the
6280                 subsystem the daemon or set of daemons are part of,
6281                 while <var>daemon-1</var> up to <var>daemon-n</var>
6282                 denote each daemon's name (typically the file name of
6283                 the program).
6284               </p>
6285
6286               <p>
6287                 For example, the output of <file>/etc/init.d/lpd</file>
6288                 would look like:
6289                 <example compact="compact">
6290 Starting printer spooler: lpd.
6291                 </example>
6292               </p>
6293
6294               <p>
6295                 This can be achieved by saying
6296                 <example compact="compact">
6297 echo -n "Starting printer spooler: lpd"
6298 start-stop-daemon --start --quiet --exec /usr/sbin/lpd
6299 echo "."
6300                 </example>
6301                 in the script. If there are more than one daemon to
6302                 start, the output should look like this:
6303                 <example compact="compact">
6304 echo -n "Starting remote file system services:"
6305 echo -n " nfsd"; start-stop-daemon --start --quiet nfsd
6306 echo -n " mountd"; start-stop-daemon --start --quiet mountd
6307 echo -n " ugidd"; start-stop-daemon --start --quiet ugidd
6308 echo "."
6309                 </example>
6310                 This makes it possible for the user to see what is
6311                 happening and when the final daemon has been started.
6312                 Care should be taken in the placement of white spaces:
6313                 in the example above the system administrators can
6314                 easily comment out a line if they don't want to start
6315                 a specific daemon, while the displayed message still
6316                 looks good.
6317               </p>
6318             </item>
6319
6320             <item>
6321               <p>When a system parameter is being set</p>
6322
6323               <p>
6324                 If you have to set up different system parameters
6325                 during the system boot, you should use this format:
6326                 <example compact="compact">
6327 Setting <var>parameter</var> to "<var>value</var>".
6328                 </example>
6329               </p>
6330
6331               <p>
6332                 You can use a statement such as the following to get
6333                 the quotes right:
6334                 <example compact="compact">
6335 echo "Setting DNS domainname to \"$domainname\"."
6336                 </example>
6337               </p>
6338
6339               <p>
6340                 Note that the same symbol (<tt>"</tt>) is used for the left
6341                 and right quotation marks.  A grave accent (<tt>`</tt>) is
6342                 not a quote character; neither is an apostrophe
6343                 (<tt>'</tt>).
6344               </p>
6345             </item>
6346
6347             <item>
6348               <p>When a daemon is stopped or restarted</p>
6349
6350               <p>
6351                 When you stop or restart a daemon, you should issue a
6352                 message identical to the startup message, except that
6353                 <tt>Starting</tt> is replaced with <tt>Stopping</tt>
6354                 or <tt>Restarting</tt> respectively.
6355               </p>
6356
6357               <p>
6358                 For example, stopping the printer daemon will look like
6359                 this:
6360                 <example compact="compact">
6361 Stopping printer spooler: lpd.
6362                 </example>
6363               </p>
6364             </item>
6365
6366             <item>
6367               <p>When something is executed</p>
6368
6369               <p>
6370                 There are several examples where you have to run a
6371                 program at system startup or shutdown to perform a
6372                 specific task, for example, setting the system's clock
6373                 using <prgn>netdate</prgn> or killing all processes
6374                 when the system shuts down.  Your message should look
6375                 like this:
6376                 <example compact="compact">
6377 Doing something very useful...done.
6378                 </example>
6379                 You should print the <tt>done.</tt> immediately after
6380                 the job has been completed, so that the user is
6381                 informed why they have to wait.  You can get this
6382                 behavior by saying
6383                 <example compact="compact">
6384 echo -n "Doing something very useful..."
6385 do_something
6386 echo "done."
6387                 </example>
6388                 in your script.
6389               </p>
6390             </item>
6391
6392             <item>
6393               <p>When the configuration is reloaded</p>
6394
6395               <p>
6396                 When a daemon is forced to reload its configuration
6397                 files you should use the following format:
6398                 <example compact="compact">
6399 Reloading <var>description</var> configuration...done.
6400                 </example>
6401                 where <var>description</var> is the same as in the
6402                 daemon starting message.
6403               </p>
6404             </item>
6405           </list>
6406         </p>
6407       </sect>
6408
6409       <sect>
6410         <heading>Cron jobs</heading>
6411
6412         <p>
6413           Packages must not modify the configuration file
6414           <file>/etc/crontab</file>, and they must not modify the files in
6415           <file>/var/spool/cron/crontabs</file>.</p>
6416
6417         <p>
6418           If a package wants to install a job that has to be executed
6419           via cron, it should place a file with the name of the
6420           package in one or more of the following directories:
6421           <example compact="compact">
6422 /etc/cron.hourly
6423 /etc/cron.daily
6424 /etc/cron.weekly
6425 /etc/cron.monthly
6426           </example>
6427           As these directory names imply, the files within them are
6428           executed on an hourly, daily, weekly, or monthly basis,
6429           respectively. The exact times are listed in
6430           <file>/etc/crontab</file>.</p>
6431
6432         <p>
6433           All files installed in any of these directories must be
6434           scripts (e.g., shell scripts or Perl scripts) so that they
6435           can easily be modified by the local system administrator.
6436           In addition, they must be treated as configuration files.
6437         </p>
6438
6439         <p>
6440           If a certain job has to be executed at some other frequency or
6441           at a specific time, the package should install a file
6442           <file>/etc/cron.d/<var>package</var></file>. This file uses the
6443           same syntax as <file>/etc/crontab</file> and is processed by
6444           <prgn>cron</prgn> automatically. The file must also be
6445           treated as a configuration file. (Note that entries in the
6446           <file>/etc/cron.d</file> directory are not handled by
6447           <prgn>anacron</prgn>. Thus, you should only use this
6448           directory for jobs which may be skipped if the system is not
6449           running.)</p>
6450
6451         <p>
6452           The scripts or crontab entries in these directories should
6453           check if all necessary programs are installed before they
6454           try to execute them. Otherwise, problems will arise when a
6455           package was removed but not purged since configuration files
6456           are kept on the system in this situation.</p>
6457       </sect>
6458
6459       <sect id="menus">
6460         <heading>Menus</heading>
6461
6462         <p>
6463           The Debian <tt>menu</tt> package provides a standard
6464           interface between packages providing applications and
6465           <em>menu programs</em> (either X window managers or
6466           text-based menu programs such as <prgn>pdmenu</prgn>).
6467         </p>
6468
6469         <p>
6470           All packages that provide applications that need not be
6471           passed any special command line arguments for normal
6472           operation should register a menu entry for those
6473           applications, so that users of the <tt>menu</tt> package
6474           will automatically get menu entries in their window
6475           managers, as well in shells like <tt>pdmenu</tt>.
6476         </p>
6477
6478         <p>
6479           Menu entries should follow the current menu policy.
6480         </p>
6481
6482         <p>
6483           The menu policy can be found in the <tt>menu-policy</tt>
6484           files in the <tt>debian-policy</tt> package.
6485           It is also available from the Debian web mirrors at
6486           <tt><url name="/doc/packaging-manuals/menu-policy/"
6487                 id="http://www.debian.org/doc/packaging-manuals/menu-policy/"></tt>.
6488         </p>
6489
6490         <p>
6491           Please also refer to the <em>Debian Menu System</em>
6492           documentation that comes with the <package>menu</package>
6493           package for information about how to register your
6494           applications.
6495         </p>
6496       </sect>
6497
6498       <sect id="mime">
6499         <heading>Multimedia handlers</heading>
6500
6501         <p>
6502           MIME (Multipurpose Internet Mail Extensions, RFCs 2045-2049)
6503           is a mechanism for encoding files and data streams and
6504           providing meta-information about them, in particular their
6505           type (e.g.  audio or video) and format (e.g. PNG, HTML,
6506           MP3).
6507         </p>
6508
6509         <p>
6510           Registration of MIME type handlers allows programs like mail
6511           user agents and web browsers to invoke these handlers to
6512           view, edit or display MIME types they don't support directly.
6513         </p>
6514
6515         <p>
6516           Packages which provide the ability to view/show/play,
6517           compose, edit or print MIME types should register themselves
6518           as such following the current MIME support policy.
6519         </p>
6520
6521         <p>
6522           The MIME support policy can be found in the <tt>mime-policy</tt>
6523           files in the <tt>debian-policy</tt> package.
6524           It is also available from the Debian web mirrors at
6525           <tt><url name="/doc/packaging-manuals/mime-policy/"
6526                 id="http://www.debian.org/doc/packaging-manuals/mime-policy/"></tt>.
6527         </p>
6528
6529       </sect>
6530
6531       <sect>
6532         <heading>Keyboard configuration</heading>
6533
6534         <p>
6535           To achieve a consistent keyboard configuration so that all
6536           applications interpret a keyboard event the same way, all
6537           programs in the Debian distribution must be configured to
6538           comply with the following guidelines.
6539         </p>
6540
6541         <p>
6542           The following keys must have the specified interpretations:
6543
6544           <taglist>
6545             <tag><tt>&lt;--</tt></tag>
6546             <item>delete the character to the left of the cursor</item>
6547
6548             <tag><tt>Delete</tt></tag>
6549             <item>delete the character to the right of the cursor</item>
6550
6551             <tag><tt>Control+H</tt></tag>
6552             <item>emacs: the help prefix</item>
6553           </taglist>
6554
6555           The interpretation of any keyboard events should be
6556           independent of the terminal that is used, be it a virtual
6557           console, an X terminal emulator, an rlogin/telnet session,
6558           etc.
6559         </p>
6560
6561         <p>
6562           The following list explains how the different programs
6563           should be set up to achieve this:
6564         </p>
6565
6566         <p>
6567           <list>
6568             <item>
6569                 <tt>&lt;--</tt> generates <tt>KB_BackSpace</tt> in X.
6570             </item>
6571
6572             <item>
6573                 <tt>Delete</tt> generates <tt>KB_Delete</tt> in X.
6574             </item>
6575
6576             <item>
6577                 X translations are set up to make
6578                 <tt>KB_Backspace</tt> generate ASCII DEL, and to make
6579                 <tt>KB_Delete</tt> generate <tt>ESC [ 3 ~</tt> (this
6580                 is the vt220 escape code for the "delete character"
6581                 key).  This must be done by loading the X resources
6582                 using <prgn>xrdb</prgn> on all local X displays, not
6583                 using the application defaults, so that the
6584                 translation resources used correspond to the
6585                 <prgn>xmodmap</prgn> settings.
6586             </item>
6587
6588             <item>
6589                 The Linux console is configured to make
6590                 <tt>&lt;--</tt> generate DEL, and <tt>Delete</tt>
6591                 generate <tt>ESC [ 3 ~</tt>.
6592             </item>
6593
6594             <item>
6595                 X applications are configured so that <tt>&lt;</tt>
6596                 deletes left, and <tt>Delete</tt> deletes right.  Motif
6597                 applications already work like this.
6598             </item>
6599
6600             <item>
6601                 Terminals should have <tt>stty erase ^?</tt> .
6602             </item>
6603
6604             <item>
6605                 The <tt>xterm</tt> terminfo entry should have <tt>ESC
6606                 [ 3 ~</tt> for <tt>kdch1</tt>, just as for
6607                 <tt>TERM=linux</tt> and <tt>TERM=vt220</tt>.
6608             </item>
6609
6610             <item>
6611                 Emacs is programmed to map <tt>KB_Backspace</tt> or
6612                 the <tt>stty erase</tt> character to
6613                 <tt>delete-backward-char</tt>, and <tt>KB_Delete</tt>
6614                 or <tt>kdch1</tt> to <tt>delete-forward-char</tt>, and
6615                 <tt>^H</tt> to <tt>help</tt> as always.
6616             </item>
6617
6618             <item>
6619                 Other applications use the <tt>stty erase</tt>
6620                 character and <tt>kdch1</tt> for the two delete keys,
6621                 with ASCII DEL being "delete previous character" and
6622                 <tt>kdch1</tt> being "delete character under
6623                 cursor".
6624             </item>
6625
6626           </list>
6627         </p>
6628
6629         <p>
6630           This will solve the problem except for the following
6631           cases:
6632         </p>
6633
6634         <p>
6635           <list>
6636             <item>
6637                 Some terminals have a <tt>&lt;--</tt> key that cannot
6638                 be made to produce anything except <tt>^H</tt>.  On
6639                 these terminals Emacs help will be unavailable on
6640                 <tt>^H</tt> (assuming that the <tt>stty erase</tt>
6641                 character takes precedence in Emacs, and has been set
6642                 correctly).  <tt>M-x help</tt> or <tt>F1</tt> (if
6643                 available) can be used instead.
6644             </item>
6645
6646             <item>
6647                 Some operating systems use <tt>^H</tt> for <tt>stty
6648                 erase</tt>.  However, modern telnet versions and all
6649                 rlogin versions propagate <tt>stty</tt> settings, and
6650                 almost all UNIX versions honour <tt>stty erase</tt>.
6651                 Where the <tt>stty</tt> settings are not propagated
6652                 correctly, things can be made to work by using
6653                 <tt>stty</tt> manually.
6654             </item>
6655
6656             <item>
6657                 Some systems (including previous Debian versions) use
6658                 <prgn>xmodmap</prgn> to arrange for both
6659                 <tt>&lt;--</tt> and <tt>Delete</tt> to generate
6660                 <tt>KB_Delete</tt>.  We can change the behavior of
6661                 their X clients using the same X resources that we use
6662                 to do it for our own clients, or configure our clients
6663                 using their resources when things are the other way
6664                 around.  On displays configured like this
6665                 <tt>Delete</tt> will not work, but <tt>&lt;--</tt>
6666                 will.
6667             </item>
6668
6669             <item>
6670                 Some operating systems have different <tt>kdch1</tt>
6671                 settings in their <tt>terminfo</tt> database for
6672                 <tt>xterm</tt> and others.  On these systems the
6673                 <tt>Delete</tt> key will not work correctly when you
6674                 log in from a system conforming to our policy, but
6675                 <tt>&lt;--</tt> will.
6676             </item>
6677           </list>
6678         </p>
6679       </sect>
6680
6681       <sect>
6682         <heading>Environment variables</heading>
6683
6684         <p>
6685           A program must not depend on environment variables to get
6686           reasonable defaults.  (That's because these environment
6687           variables would have to be set in a system-wide
6688           configuration file like <file>/etc/profile</file>, which is not
6689           supported by all shells.)
6690         </p>
6691
6692         <p>
6693           If a program usually depends on environment variables for its
6694           configuration, the program should be changed to fall back to
6695           a reasonable default configuration if these environment
6696           variables are not present. If this cannot be done easily
6697           (e.g., if the source code of a non-free program is not
6698           available), the program must be replaced by a small
6699           "wrapper" shell script which sets the environment variables
6700           if they are not already defined, and calls the original program.
6701         </p>
6702
6703         <p>
6704           Here is an example of a wrapper script for this purpose:
6705
6706           <example compact="compact">
6707 #!/bin/sh
6708 BAR=${BAR:-/var/lib/fubar}
6709 export BAR
6710 exec /usr/lib/foo/foo "$@"
6711           </example>
6712         </p>
6713
6714         <p>
6715           Furthermore, as <file>/etc/profile</file> is a configuration
6716           file of the <prgn>base-files</prgn> package, other packages must
6717           not put any environment variables or other commands into that
6718           file.
6719         </p>
6720       </sect>
6721
6722       <sect id="doc-base">
6723         <heading>Registering Documents using doc-base</heading>
6724
6725         <p>
6726           The <package>doc-base</package> package implements a
6727           flexible mechanism for handling and presenting
6728           documentation. The recommended practice is for every Debian
6729           package that provides online documentation (other than just
6730           manual pages) to register these documents with
6731           <package>doc-base</package> by installing a
6732           <package>doc-base</package> control file via the
6733           <prgn/install-docs/ script at installation time and
6734           de-register the manuals again when the package is removed.
6735         </p> 
6736         <p>
6737           Please refer to the documentation that comes with the
6738           <package>doc-base</package>  package for information and
6739           details. 
6740         </p>
6741       </sect>
6742
6743     </chapt>
6744
6745
6746     <chapt id="files">
6747       <heading>Files</heading>
6748
6749       <sect>
6750         <heading>Binaries</heading>
6751
6752         <p>
6753           Two different packages must not install programs with
6754           different functionality but with the same filenames.  (The
6755           case of two programs having the same functionality but
6756           different implementations is handled via "alternatives" or
6757           the "Conflicts" mechanism.  See <ref id="maintscripts"> and
6758           <ref id="conflicts"> respectively.)  If this case happens,
6759           one of the programs must be renamed.  The maintainers should
6760           report this to the <tt>debian-devel</tt> mailing list and
6761           try to find a consensus about which program will have to be
6762           renamed.  If a consensus cannot be reached, <em>both</em>
6763           programs must be renamed.
6764         </p>
6765
6766         <p>
6767          By default, when a package is being built, any binaries
6768          created should include debugging information, as well as
6769          being compiled with optimization.  You should also turn on
6770          as many reasonable compilation warnings as possible; this
6771          makes life easier for porters, who can then look at build
6772          logs for possible problems.  For the C programming language,
6773          this means the following compilation parameters should be
6774          used:
6775           <example compact="compact">
6776 CC = gcc
6777 CFLAGS = -O2 -g -Wall # sane warning options vary between programs
6778 LDFLAGS = # none
6779 INSTALL = install -s # (or use strip on the files in debian/tmp)
6780           </example>
6781         </p>
6782
6783         <p>
6784           Note that by default all installed binaries should be stripped,
6785           either by using the <tt>-s</tt> flag to
6786           <prgn>install</prgn>, or by calling <prgn>strip</prgn> on
6787           the binaries after they have been copied into
6788           <file>debian/tmp</file> but before the tree is made into a
6789           package.
6790         </p>
6791
6792         <p>
6793           Although binaries in the build tree should be compiled with
6794           debugging information by default, it can often be difficult to
6795           debug programs if they are also subjected to compiler
6796           optimization.  For this reason, it is recommended to support the
6797           standardized environment variable <tt>DEB_BUILD_OPTIONS</tt>
6798           (see <ref id="debianrules-options">).  This variable can contain
6799           several flags to change how a package is compiled and built.
6800         </p>
6801
6802         <p>
6803           It is up to the package maintainer to decide what
6804           compilation options are best for the package.  Certain
6805           binaries (such as computationally-intensive programs) will
6806           function better with certain flags (<tt>-O3</tt>, for
6807           example); feel free to use them.  Please use good judgment
6808           here.  Don't use flags for the sake of it; only use them
6809           if there is good reason to do so.  Feel free to override
6810           the upstream author's ideas about which compilation
6811           options are best: they are often inappropriate for our
6812           environment.
6813         </p>
6814       </sect>
6815
6816
6817       <sect id="libraries">
6818         <heading>Libraries</heading>
6819
6820         <p>
6821           If the package is <strong>architecture: any</strong>, then
6822           the shared library compilation and linking flags must have
6823           <tt>-fPIC</tt>, or the package shall not build on some of
6824           the supported architectures<footnote>
6825             <p>
6826               If you are using GCC, <tt>-fPIC</tt> produces code with
6827               relocatable position independent code, which is required for
6828               most architectures to create a shared library, with i386 and
6829               perhaps some others where non position independent code is
6830               permitted in a shared library.
6831             </p>
6832             <p>
6833               Position independent code may have a performance penalty,
6834               especially on <tt>i386</tt>. However, in most cases the
6835               speed penalty must be measured against the memory wasted on
6836               the few architectures where non position independent code is
6837               even possible.
6838             </p>
6839           </footnote>. Any exception to this rule must be discussed on
6840           the mailing list <em>debian-devel@lists.debian.org</em>, and
6841           a rough consensus obtained.  The reasons for not compiling
6842           with <tt>-fPIC</tt> flag must be recorded in the file
6843           <tt>README.Debian</tt>, and care must be taken to either
6844           restrict the architecture or arrange for <tt>-fPIC</tt> to
6845           be used on architectures where it is required.<footnote>
6846             <p>
6847               Some of the reasons why this might be required is if the
6848               library contains hand crafted assembly code that is not
6849               relocatable, the speed penalty is excessive for compute
6850               intensive libs, and similar reasons.
6851             </p>
6852           </footnote>
6853         </p>
6854         <p>
6855           As to the static libraries, the common case is not to have
6856           relocatable code, since there is no benefit, unless in specific
6857           cases; therefore the static version must not be compiled
6858           with the <tt>-fPIC</tt> flag. Any exception to this rule
6859           should be discussed on the mailing list
6860           <em>debian-devel@lists.debian.org</em>,  and the reasons for
6861           compiling with the <tt>-fPIC</tt> flag must be recorded in
6862           the file <tt>README.Debian</tt>. <footnote>
6863             <p>
6864               Some of the reasons for linking static libraries with
6865               the <tt>-fPIC</tt> flag are if, for example, one needs a
6866               Perl API for a library that is under rapid development,
6867               and has an unstable API, so shared libraries are
6868               pointless at this phase of the library's development. In
6869               that case, since Perl needs a library with relocatable
6870               code, it may make sense to create a static library with
6871               relocatable code. Another reason cited is if you are
6872               distilling various libraries into a common shared
6873               library, like <tt>mklibs</tt> does in the Debian
6874               installer project.
6875             </p>
6876           </footnote>
6877         </p>
6878         <p>
6879           In other words, if both a shared and a static library is
6880           being built, each source unit (<tt>*.c</tt>, for example,
6881           for C files) will need to be compiled twice, for the normal
6882           case. 
6883         </p>
6884         <p>
6885           You must specify the gcc option <tt>-D_REENTRANT</tt>
6886           when building a library (either static or shared) to make
6887           the library compatible with LinuxThreads.
6888         </p>
6889
6890         <p>
6891           Although not enforced by the build tools, shared libraries
6892           must be linked against all libraries that they use symbols from
6893           in the same way that binaries are.  This ensures the correct
6894           functioning of the <qref id="sharedlibs-shlibdeps">shlibs</qref>
6895           system and guarantees that all libraries can be safely opened
6896           with <tt>dlopen()</tt>.  Packagers may wish to use the gcc
6897           option <tt>-Wl,-z,defs</tt> when building a shared library.
6898           Since this option enforces symbol resolution at build time,
6899           a missing library reference will be caught early as a fatal
6900           build error.
6901         </p>
6902
6903         <p>
6904           All installed shared libraries should be stripped with
6905           <example compact="compact">
6906 strip --strip-unneeded <var>your-lib</var>
6907           </example>
6908           (The option <tt>--strip-unneeded</tt> makes
6909           <prgn>strip</prgn> remove only the symbols which aren't
6910           needed for relocation processing.)  Shared libraries can
6911           function perfectly well when stripped, since the symbols for
6912           dynamic linking are in a separate part of the ELF object
6913           file.<footnote>
6914               You might also want to use the options
6915               <tt>--remove-section=.comment</tt> and
6916               <tt>--remove-section=.note</tt> on both shared libraries
6917               and executables, and <tt>--strip-debug</tt> on static
6918               libraries.
6919           </footnote>
6920         </p>
6921
6922         <p>
6923           Note that under some circumstances it may be useful to
6924           install a shared library unstripped, for example when
6925           building a separate package to support debugging.
6926         </p>
6927
6928         <p>
6929           Shared object files (often <file>.so</file> files) that are not
6930           public libraries, that is, they are not meant to be linked
6931           to by third party executables (binaries of other packages),
6932           should be installed in subdirectories of the
6933           <file>/usr/lib</file> directory.  Such files are exempt from the
6934           rules that govern ordinary shared libraries, except that
6935           they must not be installed executable and should be
6936           stripped.<footnote>
6937               A common example are the so-called "plug-ins",
6938               internal shared objects that are dynamically loaded by
6939               programs using <manref name="dlopen" section="3">.
6940           </footnote>
6941         </p>
6942
6943         <p>
6944           Packages containing shared libraries that may be linked to
6945           by other packages' binaries, but which for some
6946           <em>compelling</em> reason can not be installed in
6947           <file>/usr/lib</file> directory, may install the shared library
6948           files in subdirectories of the <file>/usr/lib</file> directory,
6949           in which case they should arrange to add that directory in
6950           <file>/etc/ld.so.conf</file> in the package's post-installation
6951           script, and remove it in the package's post-removal script.
6952         </p>
6953
6954         <p>
6955           An ever increasing number of packages are using
6956           <prgn>libtool</prgn> to do their linking.  The latest GNU
6957           libtools (>= 1.3a) can take advantage of the metadata in the
6958           installed <prgn>libtool</prgn> archive files (<file>*.la</file>
6959           files).  The main advantage of <prgn>libtool</prgn>'s
6960           <file>.la</file> files is that it allows <prgn>libtool</prgn> to
6961           store and subsequently access metadata with respect to the
6962           libraries it builds.  <prgn>libtool</prgn> will search for
6963           those files, which contain a lot of useful information about
6964           a library (such as library dependency information for static
6965           linking).  Also, they're <em>essential</em> for programs
6966           using <tt>libltdl</tt>.<footnote>
6967               Although <prgn>libtool</prgn> is fully capable of
6968               linking against shared libraries which don't have
6969               <tt>.la</tt> files, as it is a mere shell script it can
6970               add considerably to the build time of a
6971               <prgn>libtool</prgn>-using package if that shell script
6972               has to derive all this information from first principles
6973               for each library every time it is linked.  With the
6974               advent of <prgn>libtool</prgn> version 1.4 (and to a
6975               lesser extent <prgn>libtool</prgn> version 1.3), the
6976               <file>.la</file> files also store information about
6977               inter-library dependencies which cannot necessarily be
6978               derived after the <file>.la</file> file is deleted.
6979           </footnote>
6980         </p>
6981
6982         <p>
6983           Packages that use <prgn>libtool</prgn> to create shared
6984           libraries should include the <file>.la</file> files in the
6985           <tt>-dev</tt> package, unless the package relies on
6986           <tt>libtool</tt>'s <tt>libltdl</tt> library, in which case
6987           the <tt>.la</tt> files must go in the run-time library
6988           package.
6989         </p>
6990
6991         <p>
6992           You must make sure that you use only released versions of
6993           shared libraries to build your packages; otherwise other
6994           users will not be able to run your binaries
6995           properly. Producing source packages that depend on
6996           unreleased compilers is also usually a bad
6997           idea.
6998         </p>
6999       </sect>
7000
7001
7002       <sect>
7003         <heading>Shared libraries</heading>
7004         <p>
7005           This section has moved to <ref id="sharedlibs">.
7006         </p>
7007       </sect>
7008
7009
7010       <sect id="scripts">
7011         <heading>Scripts</heading>
7012
7013         <p>
7014           All command scripts, including the package maintainer
7015           scripts inside the package and used by <prgn>dpkg</prgn>,
7016           should have a <tt>#!</tt> line naming the shell to be used
7017           to interpret them.
7018         </p>
7019
7020         <p>
7021           In the case of Perl scripts this should be
7022           <tt>#!/usr/bin/perl</tt>.
7023         </p>
7024
7025         <p>
7026           When scripts are installed into a directory in the system
7027           PATH, the script name should not include an extension such
7028           as <tt>.sh</tt> or <tt>.pl</tt> that denotes the scripting
7029           language currently used to implement it.
7030         </p>
7031         <p>
7032           Shell scripts (<prgn>sh</prgn> and <prgn>bash</prgn>)
7033           should almost certainly start with <tt>set -e</tt> so that
7034           errors are detected.  Every script should use
7035           <tt>set -e</tt> or check the exit status of <em>every</em>
7036           command.
7037         </p>
7038
7039         <p>
7040           Scripts may assume that <file>/bin/sh</file> implements the
7041           SUSv3 Shell Command Language<footnote>
7042             Single UNIX Specification, version 3, which is also IEEE
7043             1003.1-2004 (POSIX), and is available on the World Wide Web
7044             from <url id="http://www.unix.org/version3/online.html"
7045                       name="The Open Group"> after free
7046             registration.</footnote>
7047           plus the following additional features not mandated by
7048           SUSv3:<footnote>
7049             These features are in widespread use in the Linux community
7050             and are implemented in all of bash, dash, and ksh, the most
7051             common shells users may wish to use as <file>/bin/sh</file>.
7052           </footnote>
7053           <list>
7054             <item><tt>echo -n</tt>, if implemented as a shell built-in,
7055               must not generate a newline.</item>
7056             <item><tt>test</tt>, if implemented as a shell built-in, must
7057               support <tt>-a</tt> and <tt>-o</tt> as binary logical
7058               operators.</item>
7059             <item><tt>local</tt> to create a scoped variable must be
7060               supported, including listing multiple variables in a single
7061               local command and assigning a value to a variable at the
7062               same time as localizing it.  <tt>local</tt> may or
7063               may not preserve the variable value from an outer scope if
7064               no assignment is present.  Uses such as:
7065 <example compact>
7066 fname () {
7067     local a b c=delta d
7068     # ... use a, b, c, d ...
7069 }
7070 </example>
7071               must be supported and must set the value of <tt>c</tt> to
7072               <tt>delta</tt>.
7073             </item>
7074           </list>
7075           If a shell script requires non-SUSv3 features from the shell
7076           interpreter other than those listed above, the appropriate shell
7077           must be specified in the first line of the script (e.g.,
7078           <tt>#!/bin/bash</tt>) and the package must depend on the package
7079           providing the shell (unless the shell package is marked
7080           "Essential", as in the case of <prgn>bash</prgn>).
7081         </p>
7082
7083         <p>
7084           You may wish to restrict your script to SUSv3 features plus the
7085           above set when possible so that it may use <file>/bin/sh</file>
7086           as its interpreter. If your script works with <prgn>dash</prgn>
7087           (originally called <prgn>ash</prgn>), it probably complies with
7088           the above requirements, but if you are in doubt, use
7089           <file>/bin/bash</file>.
7090         </p>
7091
7092         <p>
7093           Perl scripts should check for errors when making any
7094           system calls, including <tt>open</tt>, <tt>print</tt>,
7095           <tt>close</tt>, <tt>rename</tt> and <tt>system</tt>.
7096         </p>
7097
7098         <p>
7099           <prgn>csh</prgn> and <prgn>tcsh</prgn> should be avoided as
7100           scripting languages.  See <em>Csh Programming Considered
7101           Harmful</em>, one of the <tt>comp.unix.*</tt> FAQs, which
7102           can be found at <url id="http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/">.
7103           If an upstream package comes with <prgn>csh</prgn> scripts
7104           then you must make sure that they start with
7105           <tt>#!/bin/csh</tt> and make your package depend on the
7106           <prgn>c-shell</prgn> virtual package.
7107         </p>
7108
7109         <p>
7110           Any scripts which create files in world-writeable
7111           directories (e.g., in <file>/tmp</file>) must use a
7112           mechanism which will fail atomically if a file with the same
7113           name already exists.
7114         </p>
7115
7116         <p>
7117           The Debian base system provides the <prgn>tempfile</prgn>
7118           and <prgn>mktemp</prgn> utilities for use by scripts for
7119           this purpose.
7120         </p>
7121       </sect>
7122
7123
7124       <sect>
7125         <heading>Symbolic links</heading>
7126
7127         <p>
7128           In general, symbolic links within a top-level directory
7129           should be relative, and symbolic links pointing from one
7130           top-level directory into another should be absolute. (A
7131           top-level directory is a sub-directory of the root
7132           directory <file>/</file>.)
7133         </p>
7134
7135         <p>
7136           In addition, symbolic links should be specified as short as
7137           possible, i.e., link targets like <file>foo/../bar</file> are
7138           deprecated.
7139         </p>
7140
7141         <p>
7142           Note that when creating a relative link using
7143           <prgn>ln</prgn> it is not necessary for the target of the
7144           link to exist relative to the working directory you're
7145           running <prgn>ln</prgn> from, nor is it necessary to change
7146           directory to the directory where the link is to be made.
7147           Simply include the string that should appear as the target
7148           of the link (this will be a pathname relative to the
7149           directory in which the link resides) as the first argument
7150           to <prgn>ln</prgn>.
7151         </p>
7152
7153         <p>
7154           For example, in your <prgn>Makefile</prgn> or
7155           <file>debian/rules</file>, you can do things like:
7156           <example compact="compact">
7157 ln -fs gcc $(prefix)/bin/cc
7158 ln -fs gcc debian/tmp/usr/bin/cc
7159 ln -fs ../sbin/sendmail $(prefix)/bin/runq
7160 ln -fs ../sbin/sendmail debian/tmp/usr/bin/runq
7161           </example>
7162         </p>
7163
7164         <p>
7165           A symbolic link pointing to a compressed file should always
7166           have the same file extension as the referenced file. (For
7167           example, if a file <file>foo.gz</file> is referenced by a
7168           symbolic link, the filename of the link has to end with
7169           "<file>.gz</file>" too, as in <file>bar.gz</file>.)
7170         </p>
7171       </sect>
7172
7173       <sect>
7174         <heading>Device files</heading>
7175
7176         <p>
7177           Packages must not include device files in the package file
7178           tree.
7179         </p>
7180
7181         <p>
7182           If a package needs any special device files that are not
7183           included in the base system, it must call
7184           <prgn>MAKEDEV</prgn> in the <prgn>postinst</prgn> script,
7185           after notifying the user<footnote>
7186               This notification could be done via a (low-priority)
7187               debconf message, or an echo (printf) statement.
7188           </footnote>.
7189         </p>
7190
7191         <p>
7192           Packages must not remove any device files in the
7193           <prgn>postrm</prgn> or any other script. This is left to the
7194           system administrator.
7195         </p>
7196
7197         <p>
7198           Debian uses the serial devices
7199           <file>/dev/ttyS*</file>. Programs using the old
7200           <file>/dev/cu*</file> devices should be changed to use
7201           <file>/dev/ttyS*</file>.
7202         </p>
7203       </sect>
7204
7205       <sect id="config-files">
7206         <heading>Configuration files</heading>
7207
7208         <sect1>
7209           <heading>Definitions</heading>
7210
7211           <p>
7212             <taglist>
7213               <tag>configuration file</tag>
7214               <item>
7215                   A file that affects the operation of a program, or
7216                   provides site- or host-specific information, or
7217                   otherwise customizes the behavior of a program.
7218                   Typically, configuration files are intended to be
7219                   modified by the system administrator (if needed or
7220                   desired) to conform to local policy or to provide
7221                   more useful site-specific behavior.
7222               </item>
7223
7224               <tag><tt>conffile</tt></tag>
7225               <item>
7226                   A file listed in a package's <tt>conffiles</tt>
7227                   file, and is treated specially by <prgn>dpkg</prgn>
7228                   (see <ref id="configdetails">).
7229               </item>
7230             </taglist>
7231           </p>
7232
7233           <p>
7234             The distinction between these two is important; they are
7235             not interchangeable concepts. Almost all
7236             <tt>conffile</tt>s are configuration files, but many
7237             configuration files are not <tt>conffiles</tt>.
7238           </p>
7239
7240           <p>
7241             As noted elsewhere, <file>/etc/init.d</file> scripts,
7242             <file>/etc/default</file> files, scripts installed in
7243             <file>/etc/cron.{hourly,daily,weekly,monthly}</file>, and cron
7244             configuration installed in <file>/etc/cron.d</file> must be
7245             treated as configuration files.  In general, any script that
7246             embeds configuration information is de-facto a configuration
7247             file and should be treated as such.
7248           </p>
7249         </sect1>
7250
7251         <sect1>
7252           <heading>Location</heading>
7253
7254           <p>
7255             Any configuration files created or used by your package
7256             must reside in <file>/etc</file>. If there are several,
7257             consider creating a subdirectory of <file>/etc</file>
7258             named after your package.
7259           </p>
7260
7261           <p>
7262             If your package creates or uses configuration files
7263             outside of <file>/etc</file>, and it is not feasible to modify
7264             the package to use <file>/etc</file> directly, put the files
7265             in <file>/etc</file> and create symbolic links to those files
7266             from the location that the package requires.
7267           </p>
7268         </sect1>
7269
7270         <sect1>
7271           <heading>Behavior</heading>
7272
7273           <p>
7274             Configuration file handling must conform to the following
7275             behavior:
7276             <list compact="compact">
7277               <item>
7278                   local changes must be preserved during a package
7279                   upgrade, and
7280               </item>
7281               <item>
7282                   configuration files must be preserved when the
7283                   package is removed, and only deleted when the
7284                   package is purged.
7285               </item>
7286             </list>
7287           </p>
7288
7289           <p>
7290             The easy way to achieve this behavior is to make the
7291             configuration file a <tt>conffile</tt>. This is
7292             appropriate only if it is possible to distribute a default
7293             version that will work for most installations, although
7294             some system administrators may choose to modify it. This
7295             implies that the default version will be part of the
7296             package distribution, and must not be modified by the
7297             maintainer scripts during installation (or at any other
7298             time).
7299           </p>
7300
7301           <p>
7302             In order to ensure that local changes are preserved
7303             correctly, no package may contain or make hard links to
7304             conffiles.<footnote>
7305                 Rationale: There are two problems with hard links.
7306                 The first is that some editors break the link while
7307                 editing one of the files, so that the two files may
7308                 unwittingly become unlinked and different.  The second
7309                 is that <prgn>dpkg</prgn> might break the hard link
7310                 while upgrading <tt>conffile</tt>s.
7311             </footnote>
7312           </p>
7313
7314           <p>
7315             The other way to do it is via the maintainer scripts.  In
7316             this case, the configuration file must not be listed as a
7317             <tt>conffile</tt> and must not be part of the package
7318             distribution. If the existence of a file is required for
7319             the package to be sensibly configured it is the
7320             responsibility of the package maintainer to provide
7321             maintainer scripts which correctly create, update and
7322             maintain the file and remove it on purge.  (See <ref
7323             id="maintainerscripts"> for more information.)  These
7324             scripts must be idempotent (i.e., must work correctly if
7325             <prgn>dpkg</prgn> needs to re-run them due to errors
7326             during installation or removal), must cope with all the
7327             variety of ways <prgn>dpkg</prgn> can call maintainer
7328             scripts, must not overwrite or otherwise mangle the user's
7329             configuration without asking, must not ask unnecessary
7330             questions (particularly during upgrades), and must
7331             otherwise be good citizens.
7332           </p>
7333
7334           <p>
7335             The scripts are not required to configure every possible
7336             option for the package, but only those necessary to get
7337             the package running on a given system. Ideally the
7338             sysadmin should not have to do any configuration other
7339             than that done (semi-)automatically by the
7340             <prgn>postinst</prgn> script.
7341           </p>
7342
7343           <p>
7344             A common practice is to create a script called
7345             <file><var>package</var>-configure</file> and have the
7346             package's <prgn>postinst</prgn> call it if and only if the
7347             configuration file does not already exist.  In certain
7348             cases it is useful for there to be an example or template
7349             file which the maintainer scripts use.  Such files should
7350             be in <file>/usr/share/<var>package</var></file> or
7351             <file>/usr/lib/<var>package</var></file> (depending on whether
7352             they are architecture-independent or not).  There should
7353             be symbolic links to them from
7354             <file>/usr/share/doc/<var>package</var>/examples</file> if
7355             they are examples, and should be perfectly ordinary
7356             <prgn>dpkg</prgn>-handled files (<em>not</em>
7357             configuration files).
7358           </p>
7359
7360           <p>
7361             These two styles of configuration file handling must
7362             not be mixed, for that way lies madness:
7363             <prgn>dpkg</prgn> will ask about overwriting the file
7364             every time the package is upgraded.
7365           </p>
7366         </sect1>
7367
7368         <sect1>
7369           <heading>Sharing configuration files</heading>
7370
7371           <p>
7372             Packages which specify the same file as a
7373             <tt>conffile</tt> must be tagged as <em>conflicting</em>
7374             with each other.  (This is an instance of the general rule
7375             about not sharing files.  Note that neither alternatives
7376             nor diversions are likely to be appropriate in this case;
7377             in particular, <prgn>dpkg</prgn> does not handle diverted
7378             <tt>conffile</tt>s well.)
7379           </p>
7380
7381           <p>
7382             The maintainer scripts must not alter a <tt>conffile</tt>
7383             of <em>any</em> package, including the one the scripts
7384             belong to.
7385           </p>
7386
7387           <p>
7388             If two or more packages use the same configuration file
7389             and it is reasonable for both to be installed at the same
7390             time, one of these packages must be defined as
7391             <em>owner</em> of the configuration file, i.e., it will be
7392             the package which handles that file as a configuration
7393             file.  Other packages that use the configuration file must
7394             depend on the owning package if they require the
7395             configuration file to operate. If the other package will
7396             use the configuration file if present, but is capable of
7397             operating without it, no dependency need be declared.
7398           </p>
7399
7400           <p>
7401             If it is desirable for two or more related packages to
7402             share a configuration file <em>and</em> for all of the
7403             related packages to be able to modify that configuration
7404             file, then the following should be done:
7405             <enumlist compact="compact">
7406               <item>
7407                   One of the related packages (the "owning" package)
7408                   will manage the configuration file with maintainer
7409                   scripts as described in the previous section.
7410               </item>
7411               <item>
7412                   The owning package should also provide a program
7413                   that the other packages may use to modify the
7414                   configuration file.
7415               </item>
7416               <item>
7417                   The related packages must use the provided program
7418                   to make any desired modifications to the
7419                   configuration file.  They should either depend on
7420                   the core package to guarantee that the configuration
7421                   modifier program is available or accept gracefully
7422                   that they cannot modify the configuration file if it
7423                   is not.  (This is in addition to the fact that the
7424                   configuration file may not even be present in the
7425                   latter scenario.)
7426               </item>
7427             </enumlist>
7428           </p>
7429
7430           <p>
7431             Sometimes it's appropriate to create a new package which
7432             provides the basic infrastructure for the other packages
7433             and which manages the shared configuration files.  (The
7434             <tt>sgml-base</tt> package is a good example.)
7435           </p>
7436         </sect1>
7437
7438         <sect1>
7439           <heading>User configuration files ("dotfiles")</heading>
7440
7441           <p>
7442             The files in <file>/etc/skel</file> will automatically be
7443             copied into new user accounts by <prgn>adduser</prgn>.
7444             No other program should reference the files in
7445             <file>/etc/skel</file>.
7446           </p>
7447
7448           <p>
7449             Therefore, if a program needs a dotfile to exist in
7450             advance in <file>$HOME</file> to work sensibly, that dotfile
7451             should be installed in <file>/etc/skel</file> and treated as a
7452             configuration file.
7453           </p>
7454
7455           <p>
7456             However, programs that require dotfiles in order to
7457             operate sensibly are a bad thing, unless they do create
7458             the dotfiles themselves automatically.
7459           </p>
7460
7461           <p>
7462             Furthermore, programs should be configured by the Debian
7463             default installation to behave as closely to the upstream
7464             default behavior as possible.
7465           </p>
7466
7467           <p>
7468             Therefore, if a program in a Debian package needs to be
7469             configured in some way in order to operate sensibly, that
7470             should be done using a site-wide configuration file placed
7471             in <file>/etc</file>.  Only if the program doesn't support a
7472             site-wide default configuration and the package maintainer
7473             doesn't have time to add it may a default per-user file be
7474             placed in <file>/etc/skel</file>.
7475           </p>
7476
7477           <p>
7478             <file>/etc/skel</file> should be as empty as we can make it.
7479             This is particularly true because there is no easy (or
7480             necessarily desirable) mechanism for ensuring that the
7481             appropriate dotfiles are copied into the accounts of
7482             existing users when a package is installed.
7483           </p>
7484         </sect1>
7485       </sect>
7486
7487       <sect>
7488         <heading>Log files</heading>
7489         <p>
7490           Log files should usually be named
7491           <file>/var/log/<var>package</var>.log</file>.  If you have many
7492           log files, or need a separate directory for permission
7493           reasons (<file>/var/log</file> is writable only by
7494           <file>root</file>), you should usually create a directory named
7495           <file>/var/log/<var>package</var></file> and place your log
7496           files there.
7497         </p>
7498
7499         <p>
7500           Log files must be rotated occasionally so that they don't
7501           grow indefinitely; the best way to do this is to drop a log
7502           rotation configuration file into the directory
7503           <file>/etc/logrotate.d</file> and use the facilities provided by
7504           logrotate.<footnote>
7505             <p>
7506               The traditional approach to log files has been to set up
7507               <em>ad hoc</em> log rotation schemes using simple shell
7508               scripts and cron.  While this approach is highly
7509               customizable, it requires quite a lot of sysadmin work.
7510               Even though the original Debian system helped a little
7511               by automatically installing a system which can be used
7512               as a template, this was deemed not enough.
7513             </p>
7514
7515             <p>
7516               The use of <prgn>logrotate</prgn>, a program developed
7517               by Red Hat, is better, as it centralizes log management.
7518               It has both a configuration file
7519               (<file>/etc/logrotate.conf</file>) and a directory where
7520               packages can drop their individual log rotation
7521               configurations (<file>/etc/logrotate.d</file>).
7522             </p>
7523           </footnote>
7524           Here is a good example for a logrotate config
7525           file (for more information see <manref name="logrotate"
7526             section="8">):
7527           <example compact="compact">
7528 /var/log/foo/*.log {
7529 rotate 12
7530 weekly
7531 compress
7532 postrotate
7533 /etc/init.d/foo force-reload
7534 endscript
7535 }
7536           </example>
7537           This rotates all files under <file>/var/log/foo</file>, saves 12
7538           compressed generations, and forces the daemon to reload its
7539           configuration information after the log rotation.
7540         </p>
7541
7542         <p>
7543           Log files should be removed when the package is
7544           purged (but not when it is only removed).  This should be
7545           done by the <prgn>postrm</prgn> script when it is called
7546           with the argument <tt>purge</tt> (see <ref
7547           id="removedetails">).
7548         </p>
7549       </sect>
7550
7551       <sect>
7552         <heading>Permissions and owners</heading>
7553
7554         <p>
7555           The rules in this section are guidelines for general use.
7556           If necessary you may deviate from the details below.
7557           However, if you do so you must make sure that what is done
7558           is secure and you should try to be as consistent as possible
7559           with the rest of the system.  You should probably also
7560           discuss it on <prgn>debian-devel</prgn> first.
7561         </p>
7562
7563         <p>
7564           Files should be owned by <tt>root:root</tt>, and made
7565           writable only by the owner and universally readable (and
7566           executable, if appropriate), that is mode 644 or 755.
7567         </p>
7568
7569         <p>
7570           Directories should be mode 755 or (for group-writability)
7571           mode 2775.  The ownership of the directory should be
7572           consistent with its mode: if a directory is mode 2775, it
7573           should be owned by the group that needs write access to
7574           it.<footnote>
7575             <p>
7576               When a package is upgraded, and the owner or permissions
7577               of a file included in the package has changed, dpkg
7578               arranges for the ownership and permissions to be
7579               correctly set upon installation. However, this does not
7580               extend to directories; the permissions and ownership of
7581               directories already on the system does not change on
7582               install or upgrade of packages.  This makes sense, since
7583               otherwise common directories like <tt>/usr</tt> would
7584               always be in flux.  To correctly change permissions of a
7585               directory the package owns, explicit action is required,
7586               usually in the <tt>postinst</tt> script. Care must be
7587               taken to handle downgrades as well, in that case.
7588             </p>
7589           </footnote>
7590         </p>
7591
7592
7593         <p>
7594           Setuid and setgid executables should be mode 4755 or 2755
7595           respectively, and owned by the appropriate user or group.
7596           They should not be made unreadable (modes like 4711 or
7597           2711 or even 4111); doing so achieves no extra security,
7598           because anyone can find the binary in the freely available
7599           Debian package; it is merely inconvenient.  For the same
7600           reason you should not restrict read or execute permissions
7601           on non-set-id executables.
7602         </p>
7603
7604         <p>
7605           Some setuid programs need to be restricted to particular
7606           sets of users, using file permissions.  In this case they
7607           should be owned by the uid to which they are set-id, and by
7608           the group which should be allowed to execute them.  They
7609           should have mode 4754; again there is no point in making
7610           them unreadable to those users who must not be allowed to
7611           execute them.
7612         </p>
7613
7614         <p>
7615           It is possible to arrange that the system administrator can
7616           reconfigure the package to correspond to their local
7617           security policy by changing the permissions on a binary:
7618           they can do this by using <prgn>dpkg-statoverride</prgn>, as
7619           described below.<footnote>
7620               Ordinary files installed by <prgn>dpkg</prgn> (as
7621               opposed to <tt>conffile</tt>s and other similar objects)
7622               normally have their permissions reset to the distributed
7623               permissions when the package is reinstalled.  However,
7624               the use of <prgn>dpkg-statoverride</prgn> overrides this
7625               default behavior.  If you use this method, you should
7626               remember to describe <prgn>dpkg-statoverride</prgn> in
7627               the package documentation; being a relatively new
7628               addition to Debian, it is probably not yet well-known.
7629           </footnote>
7630           Another method you should consider is to create a group for
7631           people allowed to use the program(s) and make any setuid
7632           executables executable only by that group.
7633         </p>
7634
7635         <p>
7636           If you need to create a new user or group for your package
7637           there are two possibilities.  Firstly, you may need to
7638           make some files in the binary package be owned by this
7639           user or group, or you may need to compile the user or
7640           group id (rather than just the name) into the binary
7641           (though this latter should be avoided if possible, as in
7642           this case you need a statically allocated id).</p>
7643
7644         <p>
7645           If you need a statically allocated id, you must ask for a
7646           user or group id from the <tt>base-passwd</tt> maintainer,
7647           and must not release the package until you have been
7648           allocated one.  Once you have been allocated one you must
7649           either make the package depend on a version of the
7650           <tt>base-passwd</tt> package with the id present in
7651           <file>/etc/passwd</file> or <file>/etc/group</file>, or arrange for
7652           your package to create the user or group itself with the
7653           correct id (using <tt>adduser</tt>) in its
7654           <prgn>preinst</prgn> or <prgn>postinst</prgn>.  (Doing it in
7655           the <prgn>postinst</prgn> is to be preferred if it is
7656           possible, otherwise a pre-dependency will be needed on the
7657           <tt>adduser</tt> package.)
7658         </p>
7659
7660         <p>
7661           On the other hand, the program might be able to determine
7662           the uid or gid from the user or group name at runtime, so
7663           that a dynamically allocated id can be used.  In this case
7664           you should choose an appropriate user or group name,
7665           discussing this on <prgn>debian-devel</prgn> and checking
7666           with the <package/base-passwd/ maintainer that it is unique and that
7667           they do not wish you to use a statically allocated id
7668           instead.  When this has been checked you must arrange for
7669           your package to create the user or group if necessary using
7670           <prgn>adduser</prgn> in the <prgn>preinst</prgn> or
7671           <prgn>postinst</prgn> script (again, the latter is to be
7672           preferred if it is possible).
7673         </p>
7674
7675         <p>
7676           Note that changing the numeric value of an id associated
7677           with a name is very difficult, and involves searching the
7678           file system for all appropriate files.  You need to think
7679           carefully whether a static or dynamic id is required, since
7680           changing your mind later will cause problems.
7681         </p>
7682
7683         <sect1><heading>The use of <prgn>dpkg-statoverride</prgn></heading>
7684           <p>
7685             This section is not intended as policy, but as a
7686             description of the use of <prgn>dpkg-statoverride</prgn>.
7687           </p>
7688
7689           <p>
7690             If a system administrator wishes to have a file (or
7691             directory or other such thing) installed with owner and
7692             permissions different from those in the distributed Debian
7693             package, they can use the <prgn>dpkg-statoverride</prgn>
7694             program to instruct <prgn>dpkg</prgn> to use the different
7695             settings every time the file is installed.  Thus the
7696             package maintainer should distribute the files with their
7697             normal permissions, and leave it for the system
7698             administrator to make any desired changes.  For example, a
7699             daemon which is normally required to be setuid root, but
7700             in certain situations could be used without being setuid,
7701             should be installed setuid in the <tt>.deb</tt>.  Then the
7702             local system administrator can change this if they wish.
7703             If there are two standard ways of doing it, the package
7704             maintainer can use <tt>debconf</tt> to find out the
7705             preference, and call <prgn>dpkg-statoverride</prgn> in the
7706             maintainer script if necessary to accommodate the system
7707             administrator's choice. Care must be taken during
7708             upgrades to not override an existing setting.
7709           </p>
7710
7711           <p>
7712             Given the above, <prgn>dpkg-statoverride</prgn> is
7713             essentially a tool for system administrators and would not
7714             normally be needed in the maintainer scripts.  There is
7715             one type of situation, though, where calls to
7716             <prgn>dpkg-statoverride</prgn> would be needed in the
7717             maintainer scripts, and that involves packages which use
7718             dynamically allocated user or group ids.  In such a
7719             situation, something like the following idiom can be very
7720             helpful in the package's <prgn>postinst</prgn>, where
7721             <tt>sysuser</tt> is a dynamically allocated id:
7722             <example>
7723 for i in /usr/bin/foo /usr/sbin/bar
7724 do
7725   # only do something when no setting exists
7726   if ! dpkg-statoverride --list $i >/dev/null 2>&1
7727   then
7728     #include: debconf processing, question about foo and bar
7729     if [ "$RET" = "true" ] ; then
7730       dpkg-statoverride --update --add sysuser root 4755 $i
7731     fi
7732   fi
7733 done
7734             </example>
7735             The corresponding <tt>dpkg-statoverride --remove</tt>
7736             calls can then be made unconditionally when the package is
7737             purged.
7738           </p>
7739         </sect1>
7740       </sect>
7741     </chapt>
7742
7743
7744     <chapt id="customized-programs">
7745       <heading>Customized programs</heading>
7746
7747       <sect id="arch-spec">
7748         <heading>Architecture specification strings</heading>
7749
7750         <p>
7751           If a program needs to specify an <em>architecture specification
7752             string</em> in some place, it should select one of the
7753           strings provided by <tt>dpkg-architecture -L</tt>. The
7754           strings are in the format
7755           <tt><var>os</var>-<var>arch</var></tt>, though the OS part
7756           is sometimes elided, as when the OS is Linux.<footnote>
7757             <p>Currently, the strings are:
7758               i386 ia64 alpha amd64 armeb arm hppa m32r m68k mips
7759               mipsel powerpc ppc64 s390 s390x sh3 sh3eb sh4 sh4eb
7760               sparc darwin-i386 darwin-ia64 darwin-alpha darwin-amd64
7761               darwin-armeb darwin-arm darwin-hppa darwin-m32r
7762               darwin-m68k darwin-mips darwin-mipsel darwin-powerpc
7763               darwin-ppc64 darwin-s390 darwin-s390x darwin-sh3
7764               darwin-sh3eb darwin-sh4 darwin-sh4eb darwin-sparc
7765               freebsd-i386 freebsd-ia64 freebsd-alpha freebsd-amd64
7766               freebsd-armeb freebsd-arm freebsd-hppa freebsd-m32r
7767               freebsd-m68k freebsd-mips freebsd-mipsel freebsd-powerpc
7768               freebsd-ppc64 freebsd-s390 freebsd-s390x freebsd-sh3
7769               freebsd-sh3eb freebsd-sh4 freebsd-sh4eb freebsd-sparc
7770               kfreebsd-i386 kfreebsd-ia64 kfreebsd-alpha
7771               kfreebsd-amd64 kfreebsd-armeb kfreebsd-arm kfreebsd-hppa
7772               kfreebsd-m32r kfreebsd-m68k kfreebsd-mips
7773               kfreebsd-mipsel kfreebsd-powerpc kfreebsd-ppc64
7774               kfreebsd-s390 kfreebsd-s390x kfreebsd-sh3 kfreebsd-sh3eb
7775               kfreebsd-sh4 kfreebsd-sh4eb kfreebsd-sparc knetbsd-i386
7776               knetbsd-ia64 knetbsd-alpha knetbsd-amd64 knetbsd-armeb
7777               knetbsd-arm knetbsd-hppa knetbsd-m32r knetbsd-m68k
7778               knetbsd-mips knetbsd-mipsel knetbsd-powerpc
7779               knetbsd-ppc64 knetbsd-s390 knetbsd-s390x knetbsd-sh3
7780               knetbsd-sh3eb knetbsd-sh4 knetbsd-sh4eb knetbsd-sparc
7781               netbsd-i386 netbsd-ia64 netbsd-alpha netbsd-amd64
7782               netbsd-armeb netbsd-arm netbsd-hppa netbsd-m32r
7783               netbsd-m68k netbsd-mips netbsd-mipsel netbsd-powerpc
7784               netbsd-ppc64 netbsd-s390 netbsd-s390x netbsd-sh3
7785               netbsd-sh3eb netbsd-sh4 netbsd-sh4eb netbsd-sparc
7786               openbsd-i386 openbsd-ia64 openbsd-alpha openbsd-amd64
7787               openbsd-armeb openbsd-arm openbsd-hppa openbsd-m32r
7788               openbsd-m68k openbsd-mips openbsd-mipsel openbsd-powerpc
7789               openbsd-ppc64 openbsd-s390 openbsd-s390x openbsd-sh3
7790               openbsd-sh3eb openbsd-sh4 openbsd-sh4eb openbsd-sparc
7791               hurd-i386 hurd-ia64 hurd-alpha hurd-amd64 hurd-armeb
7792               hurd-arm hurd-hppa hurd-m32r hurd-m68k hurd-mips
7793               hurd-mipsel hurd-powerpc hurd-ppc64 hurd-s390 hurd-s390x
7794               hurd-sh3 hurd-sh3eb hurd-sh4 hurd-sh4eb hurd-sparc
7795             </p>
7796           </footnote>
7797         </p>
7798
7799         <p>
7800           Note that we don't want to use
7801           <tt><var>arch</var>-debian-linux</tt> to apply to the rule
7802           <tt><var>architecture</var>-<var>vendor</var>-<var>os</var></tt>
7803           since this would make our programs incompatible with other
7804           Linux distributions.  We also don't use something like
7805           <tt><var>arch</var>-unknown-linux</tt>, since the
7806           <tt>unknown</tt> does not look very good.
7807         </p>
7808       </sect>
7809
7810       <sect>
7811         <heading>Daemons</heading>
7812
7813         <p>
7814           The configuration files <file>/etc/services</file>,
7815           <file>/etc/protocols</file>, and <file>/etc/rpc</file> are managed
7816           by the <prgn>netbase</prgn> package and must not be modified
7817           by other packages.
7818         </p>
7819
7820         <p>
7821           If a package requires a new entry in one of these files, the
7822           maintainer should get in contact with the
7823           <prgn>netbase</prgn> maintainer, who will add the entries
7824           and release a new version of the <prgn>netbase</prgn>
7825           package.
7826         </p>
7827
7828         <p>
7829           The configuration file <file>/etc/inetd.conf</file> must not be
7830           modified by the package's scripts except via the
7831           <prgn>update-inetd</prgn> script or the
7832           <file>DebianNet.pm</file> Perl module.  See their documentation
7833           for details on how to add entries.
7834         </p>
7835
7836         <p>
7837           If a package wants to install an example entry into
7838           <file>/etc/inetd.conf</file>, the entry must be preceded with
7839           exactly one hash character (<tt>#</tt>). Such lines are
7840           treated as "commented out by user" by the
7841           <prgn>update-inetd</prgn> script and are not changed or
7842           activated during package updates.
7843         </p>
7844       </sect>
7845
7846       <sect>
7847         <heading>Using pseudo-ttys and modifying wtmp, utmp and
7848         lastlog</heading>
7849
7850         <p>
7851           Some programs need to create pseudo-ttys. This should be done
7852           using Unix98 ptys if the C library supports it. The resulting
7853           program must not be installed setuid root, unless that
7854           is required for other functionality.
7855         </p>
7856
7857         <p>
7858           The files <file>/var/run/utmp</file>, <file>/var/log/wtmp</file> and
7859           <file>/var/log/lastlog</file> must be installed writable by
7860           group <tt>utmp</tt>.  Programs which need to modify those
7861           files must be installed setgid <tt>utmp</tt>.
7862         </p>
7863       </sect>
7864
7865       <sect>
7866         <heading>Editors and pagers</heading>
7867
7868         <p>
7869           Some programs have the ability to launch an editor or pager
7870           program to edit or display a text document.  Since there are
7871           lots of different editors and pagers available in the Debian
7872           distribution, the system administrator and each user should
7873           have the possibility to choose their preferred editor and
7874           pager.
7875         </p>
7876
7877         <p>
7878           In addition, every program should choose a good default
7879           editor/pager if none is selected by the user or system
7880           administrator.
7881         </p>
7882
7883         <p>
7884           Thus, every program that launches an editor or pager must
7885           use the EDITOR or PAGER environment variable to determine
7886           the editor or pager the user wishes to use.  If these
7887           variables are not set, the programs <file>/usr/bin/editor</file>
7888           and <file>/usr/bin/pager</file> should be used, respectively.
7889         </p>
7890
7891         <p>
7892           These two files are managed through the <prgn>dpkg</prgn>
7893           "alternatives" mechanism.  Thus every package providing an
7894           editor or pager must call the
7895           <prgn>update-alternatives</prgn> script to register these
7896           programs.
7897         </p>
7898
7899         <p>
7900           If it is very hard to adapt a program to make use of the
7901           EDITOR or PAGER variables, that program may be configured to
7902           use <file>/usr/bin/sensible-editor</file> and
7903           <file>/usr/bin/sensible-pager</file> as the editor or pager
7904           program respectively.  These are two scripts provided in the
7905           Debian base system that check the EDITOR and PAGER variables
7906           and launch the appropriate program, and fall back to
7907           <file>/usr/bin/editor</file> and <file>/usr/bin/pager</file> if the
7908           variable is not set.
7909         </p>
7910
7911         <p>
7912           A program may also use the VISUAL environment variable to
7913           determine the user's choice of editor.  If it exists, it
7914           should take precedence over EDITOR.  This is in fact what
7915           <file>/usr/bin/sensible-editor</file> does.
7916         </p>
7917
7918         <p>
7919           It is not required for a package to depend on
7920           <tt>editor</tt> and <tt>pager</tt>, nor is it required for a
7921           package to provide such virtual packages.<footnote>
7922               The Debian base system already provides an editor and a
7923               pager program.
7924           </footnote>
7925         </p>
7926       </sect>
7927
7928       <sect id="web-appl">
7929         <heading>Web servers and applications</heading>
7930
7931         <p>
7932           This section describes the locations and URLs that should
7933           be used by all web servers and web applications in the
7934           Debian system.
7935         </p>
7936
7937         <p>
7938           <enumlist>
7939             <item>
7940                 Cgi-bin executable files are installed in the
7941                 directory
7942                 <example compact="compact">
7943 /usr/lib/cgi-bin/<var>cgi-bin-name</var>
7944                 </example>
7945                 and should be referred to as
7946                 <example compact="compact">
7947 http://localhost/cgi-bin/<var>cgi-bin-name</var>
7948                 </example>
7949
7950             </item>
7951
7952             <item>
7953               <p>Access to HTML documents</p>
7954
7955               <p>
7956                 HTML documents for a package are stored in
7957                 <file>/usr/share/doc/<var>package</var></file>
7958                 and can be referred to as
7959                 <example compact="compact">
7960 http://localhost/doc/<var>package</var>/<var>filename</var>
7961                 </example>
7962               </p>
7963
7964               <p>
7965                 The web server should restrict access to the document
7966                 tree so that only clients on the same host can read
7967                 the documents. If the web server does not support such
7968                 access controls, then it should not provide access at
7969                 all, or ask about providing access during installation.
7970               </p>
7971             </item>
7972
7973             <item>
7974               <p>Access to images</p>
7975               <p>
7976                 It is recommended that images for a package be stored
7977                 in <tt>/usr/share/images/<var>package</var></tt> and
7978                 may be referred to through an alias <tt>/images/</tt>
7979                 as
7980                 <example>
7981                   http://localhost/images/&lt;package&gt;/&lt;filename&gt;     
7982                 </example>
7983                 
7984               </p>
7985             </item>
7986
7987             <item>
7988               <p>Web Document Root</p>
7989
7990               <p>
7991                 Web Applications should try to avoid storing files in
7992                 the Web Document Root.  Instead they should use the
7993                 /usr/share/doc/<var>package</var> directory for
7994                 documents and register the Web Application via the
7995                 <package>doc-base</package> package.  If access to the
7996                 web document root is unavoidable then use
7997                 <example compact="compact">
7998 /var/www
7999                 </example>
8000                 as the Document Root.  This might be just a symbolic
8001                 link to the location where the system administrator
8002                 has put the real document root.
8003               </p>
8004             </item>
8005             <item><p>Providing httpd and/or httpd-cgi</p>
8006               <p>
8007                 All web servers should provide the virtual package
8008                 <tt>httpd</tt>. If a web server has CGI support it should
8009                 provide <tt>httpd-cgi</tt> additionally.
8010               </p>
8011               <p>
8012                 All web applications which do not contain CGI scripts should
8013                 depend on <tt>httpd</tt>, all those web applications which
8014                 <tt>do</tt> contain CGI scripts, should depend on
8015                 <tt>httpd-cgi</tt>.
8016               </p>
8017             </item>
8018           </enumlist>
8019         </p>
8020       </sect>
8021
8022       <sect id="mail-transport-agents">
8023         <heading>Mail transport, delivery and user agents</heading>
8024
8025         <p>
8026           Debian packages which process electronic mail, whether mail
8027           user agents (MUAs) or mail transport agents (MTAs), must
8028           ensure that they are compatible with the configuration
8029           decisions below.  Failure to do this may result in lost
8030           mail, broken <tt>From:</tt> lines, and other serious brain
8031           damage!
8032         </p>
8033
8034         <p>
8035           The mail spool is <file>/var/mail</file> and the interface to
8036           send a mail message is <file>/usr/sbin/sendmail</file> (as per
8037           the FHS).  On older systems, the mail spool may be
8038           physically located in <file>/var/spool/mail</file>, but all
8039           access to the mail spool should be via the
8040           <file>/var/mail</file> symlink.  The mail spool is part of the
8041           base system and not part of the MTA package.
8042         </p>
8043
8044         <p>
8045           All Debian MUAs, MTAs, MDAs and other mailbox accessing
8046           programs (such as IMAP daemons) must lock the mailbox in an
8047           NFS-safe way. This means that <tt>fcntl()</tt> locking must
8048           be combined with dot locking.  To avoid deadlocks, a program
8049           should use <tt>fcntl()</tt> first and dot locking after
8050           this, or alternatively implement the two locking methods in
8051           a non blocking way<footnote>
8052               If it is not possible to establish both locks, the
8053               system shouldn't wait for the second lock to be
8054               established, but remove the first lock, wait a (random)
8055               time, and start over locking again.
8056           </footnote>. Using the functions <tt>maillock</tt> and
8057           <tt>mailunlock</tt> provided by the
8058           <tt>liblockfile*</tt><footnote>
8059               You will need to depend on <tt>liblockfile1 (&gt;&gt;1.01)</tt>
8060               to use these functions.
8061           </footnote> packages is the recommended way to realize this.
8062         </p>
8063
8064         <p>
8065           Mailboxes are generally either mode 600 and owned by
8066           <var>user</var> or mode 660 and owned by
8067           <tt><var>user</var>:mail</tt><footnote>
8068             There are two traditional permission schemes for mail spools:
8069             mode 600 with all mail delivery done by processes running as
8070             the destination user, or mode 660 and owned by group mail with
8071             mail delivery done by a process running as a system user in
8072             group mail.  Historically, Debian required mode 660 mail
8073             spools to enable the latter model, but that model has become
8074             increasingly uncommon and the principle of least privilege
8075             indicates that mail systems that use the first model should
8076             use permissions of 600.  If delivery to programs is permitted,
8077             it's easier to keep the mail system secure if the delivery
8078             agent runs as the destination user.  Debian Policy therefore
8079             permits either scheme.
8080           </footnote>. The local system administrator may choose a
8081           different permission scheme; packages should not make
8082           assumptions about the permission and ownership of mailboxes
8083           unless required (such as when creating a new mailbox).  A MUA
8084           may remove a mailbox (unless it has nonstandard permissions) in
8085           which case the MTA or another MUA must recreate it if needed.
8086         </p>
8087
8088         <p>
8089           The mail spool is 2775 <tt>root:mail</tt>, and MUAs should
8090           be setgid mail to do the locking mentioned above (and
8091           must obviously avoid accessing other users' mailboxes
8092           using this privilege).</p>
8093
8094         <p>
8095           <file>/etc/aliases</file> is the source file for the system mail
8096           aliases (e.g., postmaster, usenet, etc.), it is the one
8097           which the sysadmin and <prgn>postinst</prgn> scripts may
8098           edit.  After <file>/etc/aliases</file> is edited the program or
8099           human editing it must call <prgn>newaliases</prgn>.  All MTA
8100           packages must come with a <prgn>newaliases</prgn> program,
8101           even if it does nothing, but older MTA packages did not do
8102           this so programs should not fail if <prgn>newaliases</prgn>
8103           cannot be found.  Note that because of this, all MTA
8104           packages must have <tt>Provides</tt>, <tt>Conflicts</tt> and
8105           <tt>Replaces: mail-transport-agent</tt> control file
8106           fields.
8107         </p>
8108
8109         <p>
8110           The convention of writing <tt>forward to
8111             <var>address</var></tt> in the mailbox itself is not
8112           supported.  Use a <tt>.forward</tt> file instead.</p>
8113
8114         <p>
8115           The <prgn>rmail</prgn> program used by UUCP
8116           for incoming mail should be  <file>/usr/sbin/rmail</file>.
8117           Likewise, <prgn>rsmtp</prgn>, for receiving
8118           batch-SMTP-over-UUCP, should be <file>/usr/sbin/rsmtp</file> if it
8119           is supported.</p>
8120
8121         <p>
8122           If your package needs to know what hostname to use on (for
8123           example) outgoing news and mail messages which are generated
8124           locally, you should use the file <file>/etc/mailname</file>.  It
8125           will contain the portion after the username and <tt>@</tt>
8126           (at) sign for email addresses of users on the machine
8127           (followed by a newline).
8128         </p>
8129
8130         <p>
8131           Such a package should check for the existence of this file
8132           when it is being configured.  If it exists, it should be
8133           used without comment, although an MTA's configuration script
8134           may wish to prompt the user even if it finds that this file
8135           exists.  If the file does not exist, the package should
8136           prompt the user for the value (preferably using
8137           <prgn>debconf</prgn>) and store it in <file>/etc/mailname</file>
8138           as well as using it in the package's configuration.  The
8139           prompt should make it clear that the name will not just be
8140           used by that package.  For example, in this situation the
8141           <tt>inn</tt> package could say something like:
8142           <example compact="compact">
8143 Please enter the "mail name" of your system.  This is the
8144 hostname portion of the address to be shown on outgoing
8145 news and mail messages.  The default is
8146 <var>syshostname</var>, your system's host name.  Mail
8147 name ["<var>syshostname</var>"]:
8148           </example>
8149           where <var>syshostname</var> is the output of <tt>hostname
8150             --fqdn</tt>.
8151         </p>
8152       </sect>
8153
8154       <sect>
8155         <heading>News system configuration</heading>
8156
8157         <p>
8158           All the configuration files related to the NNTP (news)
8159           servers and clients should be located under
8160           <file>/etc/news</file>.</p>
8161
8162         <p>
8163           There are some configuration issues that apply to a number
8164           of news clients and server packages on the machine. These
8165           are:
8166
8167           <taglist>
8168             <tag><file>/etc/news/organization</file></tag>
8169             <item>
8170                 A string which should appear as the
8171                 organization header for all messages posted
8172                 by NNTP clients on the machine
8173             </item>
8174
8175             <tag><file>/etc/news/server</file></tag>
8176             <item>
8177                 Contains the FQDN of the upstream NNTP
8178                 server, or localhost if the local machine is
8179                 an NNTP server.
8180             </item>
8181           </taglist>
8182
8183           Other global files may be added as required for cross-package news
8184           configuration.
8185         </p>
8186       </sect>
8187
8188
8189       <sect>
8190         <heading>Programs for the X Window System</heading>
8191
8192         <sect1>
8193           <heading>Providing X support and package priorities</heading>
8194
8195           <p>
8196             Programs that can be configured with support for the X
8197             Window System must be configured to do so and must declare
8198             any package dependencies necessary to satisfy their
8199             runtime requirements when using the X Window System.  If
8200             such a package is of higher priority than the X packages
8201             on which it depends, it is required that either the
8202             X-specific components be split into a separate package, or
8203             that an alternative version of the package, which includes
8204             X support, be provided, or that the package's priority be
8205             lowered.
8206           </p>
8207         </sect1>
8208
8209         <sect1>
8210           <heading>Packages providing an X server</heading>
8211
8212           <p>
8213             Packages that provide an X server that, directly or
8214             indirectly, communicates with real input and display
8215             hardware should declare in their control data that they
8216             provide the virtual package <tt>xserver</tt>.<footnote>
8217                 This implements current practice, and provides an
8218                 actual policy for usage of the <tt>xserver</tt>
8219                 virtual package which appears in the virtual packages
8220                 list.  In a nutshell, X servers that interface
8221                 directly with the display and input hardware or via
8222                 another subsystem (e.g., GGI) should provide
8223                 <tt>xserver</tt>.  Things like <tt>Xvfb</tt>,
8224                 <tt>Xnest</tt>, and <tt>Xprt</tt> should not.
8225             </footnote>
8226           </p>
8227         </sect1>
8228
8229         <sect1>
8230           <heading>Packages providing a terminal emulator</heading>
8231
8232           <p>
8233             Packages that provide a terminal emulator for the X Window
8234             System which meet the criteria listed below should declare
8235             in their control data that they provide the virtual
8236             package <tt>x-terminal-emulator</tt>.  They should also
8237             register themselves as an alternative for
8238             <file>/usr/bin/x-terminal-emulator</file>, with a priority of
8239             20.
8240           </p>
8241
8242           <p>
8243             To be an <tt>x-terminal-emulator</tt>, a program must:
8244             <list compact="compact">
8245               <item>
8246                   Be able to emulate a DEC VT100 terminal, or a
8247                   compatible terminal.
8248               </item>
8249
8250               <item>
8251                   Support the command-line option <tt>-e
8252                     <var>command</var></tt>, which creates a new
8253                   terminal window<footnote>
8254                       "New terminal window" does not necessarily mean
8255                       a new top-level X window directly parented by
8256                       the window manager; it could, if the terminal
8257                       emulator application were so coded, be a new
8258                       "view" in a multiple-document interface (MDI).
8259                   </footnote>
8260                   and runs the specified <var>command</var>,
8261                   interpreting the entirety of the rest of the command
8262                   line as a command to pass straight to exec, in the
8263                   manner that <tt>xterm</tt> does.
8264               </item>
8265
8266               <item>
8267                   Support the command-line option <tt>-T
8268                     <var>title</var></tt>, which creates a new terminal
8269                   window with the window title <var>title</var>.
8270               </item>
8271             </list>
8272           </p>
8273         </sect1>
8274
8275         <sect1>
8276           <heading>Packages providing a window manager</heading>
8277
8278           <p>
8279             Packages that provide a window manager should declare in
8280             their control data that they provide the virtual package
8281             <tt>x-window-manager</tt>.  They should also register
8282             themselves as an alternative for
8283             <file>/usr/bin/x-window-manager</file>, with a priority
8284             calculated as follows:
8285             <list compact="compact">
8286               <item>
8287                   Start with a priority of 20.
8288               </item>
8289
8290               <item>
8291                   If the window manager supports the Debian menu
8292                   system, add 20 points if this support is available
8293                   in the package's default configuration (i.e., no
8294                   configuration files belonging to the system or user
8295                   have to be edited to activate the feature); if
8296                   configuration files must be modified, add only 10
8297                   points.
8298                 </p>
8299               </item>
8300
8301               <item>
8302                   If the window manager complies with <url
8303                     id="http://www.freedesktop.org/Standards/wm-spec"
8304                     name="The Window Manager Specification Project">,
8305                   written by the <url id="http://www.freedesktop.org/"
8306                     name="Free Desktop Group">, add 40 points.
8307               </item>
8308
8309               <item>
8310                   If the window manager permits the X session to be
8311                   restarted using a <em>different</em> window manager
8312                   (without killing the X server) in its default
8313                   configuration, add 10 points; otherwise add none.
8314               </item>
8315             </list>
8316           </p>
8317         </sect1>
8318
8319         <sect1>
8320           <heading>Packages providing fonts</heading>
8321
8322           <p>
8323             Packages that provide fonts for the X Window
8324             System<footnote>
8325                 For the purposes of Debian Policy, a "font for the X
8326                 Window System" is one which is accessed via X protocol
8327                 requests.  Fonts for the Linux console, for PostScript
8328                 renderer, or any other purpose, do not fit this
8329                 definition.  Any tool which makes such fonts available
8330                 to the X Window System, however, must abide by this
8331                 font policy.
8332             </footnote>
8333             must do a number of things to ensure that they are both
8334             available without modification of the X or font server
8335             configuration, and that they do not corrupt files used by
8336             other font packages to register information about
8337             themselves.
8338             <enumlist>
8339               <item>
8340                   Fonts of any type supported by the X Window System
8341                   must be in a separate binary package from any
8342                   executables, libraries, or documentation (except
8343                   that specific to the fonts shipped, such as their
8344                   license information).  If one or more of the fonts
8345                   so packaged are necessary for proper operation of
8346                   the package with which they are associated the font
8347                   package may be Recommended; if the fonts merely
8348                   provide an enhancement, a Suggests relationship may
8349                   be used.  Packages must not Depend on font
8350                   packages.<footnote>
8351                       This is because the X server may retrieve fonts
8352                       from the local file system or over the network
8353                       from an X font server; the Debian package system
8354                       is empowered to deal only with the local
8355                       file system.
8356                   </footnote>
8357               </item>
8358
8359               <item>
8360                   BDF fonts must be converted to PCF fonts with the
8361                   <prgn>bdftopcf</prgn> utility (available in the
8362                   <tt>xfonts-utils</tt> package, <prgn>gzip</prgn>ped, and
8363                   placed in a directory that corresponds to their
8364                   resolution:
8365                   <list compact="compact">
8366                     <item>
8367                         100 dpi fonts must be placed in
8368                         <file>/usr/share/fonts/X11/100dpi/</file>.
8369                     </item>
8370
8371                     <item>
8372                         75 dpi fonts must be placed in
8373                         <file>/usr/share/fonts/X11/75dpi/</file>.
8374                     </item>
8375
8376                     <item>
8377                         Character-cell fonts, cursor fonts, and other
8378                         low-resolution fonts must be placed in
8379                         <file>/usr/share/fonts/X11/misc/</file>.
8380                     </item>
8381                   </list>
8382               </item>
8383
8384               <item>
8385                   Speedo fonts must be placed in
8386                   <file>/usr/share/fonts/X11/Speedo/</file>.
8387               </item>
8388
8389               <item>
8390                   Type 1 fonts must be placed in
8391                   <file>/usr/share/fonts/X11/Type1/</file>.  If font
8392                   metric files are available, they must be placed here
8393                   as well.
8394               </item>
8395
8396               <item>
8397                   Subdirectories of <file>/usr/share/fonts/X11/</file>
8398                   other than those listed above must be neither
8399                   created nor used.  (The <file>PEX</file>, <file>CID</file>,
8400                   and <file>cyrillic</file> directories are excepted for
8401                   historical reasons, but installation of files into
8402                   these directories remains discouraged.)
8403               </item>
8404
8405               <item>
8406                   Font packages may, instead of placing files directly
8407                   in the X font directories listed above, provide
8408                   symbolic links in that font directory pointing to
8409                   the files' actual location in the filesystem.  Such
8410                   a location must comply with the FHS.
8411               </item>
8412
8413               <item>
8414                   Font packages should not contain both 75dpi and
8415                   100dpi versions of a font.  If both are available,
8416                   they should be provided in separate binary packages
8417                   with <tt>-75dpi</tt> or <tt>-100dpi</tt> appended to
8418                   the names of the packages containing the
8419                   corresponding fonts.
8420               </item>
8421
8422               <item>
8423                   Fonts destined for the <file>misc</file> subdirectory
8424                   should not be included in the same package as 75dpi
8425                   or 100dpi fonts; instead, they should be provided in
8426                   a separate package with <tt>-misc</tt> appended to
8427                   its name.
8428               </item>
8429
8430               <item>
8431                   Font packages must not provide the files
8432                   <file>fonts.dir</file>, <file>fonts.alias</file>, or
8433                   <file>fonts.scale</file> in a font directory:
8434                   <list>
8435                     <item>
8436                         <file>fonts.dir</file> files must not be provided at all.
8437                     </item>
8438
8439                     <item>
8440                         <file>fonts.alias</file> and <file>fonts.scale</file>
8441                         files, if needed, should be provided in the
8442                         directory
8443                         <file>/etc/X11/fonts/<var>fontdir</var>/<var>package</var>.<var>extension</var></file>,
8444                         where <var>fontdir</var> is the name of the
8445                         subdirectory of
8446                         <file>/usr/share/fonts/X11/</file> where the
8447                         package's corresponding fonts are stored
8448                         (e.g., <tt>75dpi</tt> or <tt>misc</tt>),
8449                         <var>package</var> is the name of the package
8450                         that provides these fonts, and
8451                         <var>extension</var> is either <tt>scale</tt>
8452                         or <tt>alias</tt>, whichever corresponds to
8453                         the file contents.
8454                     </item>
8455                   </list>
8456               </item>
8457
8458               <item>
8459                   Font packages must declare a dependency on
8460                   <tt>xfonts-utils</tt> in their control
8461                   data.
8462               </item>
8463
8464               <item>
8465                   Font packages that provide one or more
8466                   <file>fonts.scale</file> files as described above must
8467                   invoke <prgn>update-fonts-scale</prgn> on each
8468                   directory into which they installed fonts
8469                   <em>before</em> invoking
8470                   <prgn>update-fonts-dir</prgn> on that directory.
8471                   This invocation must occur in both the
8472                   <prgn>postinst</prgn> (for all arguments) and
8473                   <prgn>postrm</prgn> (for all arguments except
8474                   <tt>upgrade</tt>) scripts.
8475               </item>
8476
8477               <item>
8478                   Font packages that provide one or more
8479                   <file>fonts.alias</file> files as described above must
8480                   invoke <prgn>update-fonts-alias</prgn> on each
8481                   directory into which they installed fonts.  This
8482                   invocation must occur in both the
8483                   <prgn>postinst</prgn> (for all arguments) and
8484                   <prgn>postrm</prgn> (for all arguments except
8485                   <tt>upgrade</tt>) scripts.
8486               </item>
8487
8488               <item>
8489                   Font packages must invoke
8490                   <prgn>update-fonts-dir</prgn> on each directory into
8491                   which they installed fonts.  This invocation must
8492                   occur in both the <prgn>postinst</prgn> (for all
8493                   arguments) and <prgn>postrm</prgn> (for all
8494                   arguments except <tt>upgrade</tt>) scripts.
8495               </item>
8496
8497               <item>
8498                   Font packages must not provide alias names for the
8499                   fonts they include which collide with alias names
8500                   already in use by fonts already packaged.
8501               </item>
8502
8503               <item>
8504                   Font packages must not provide fonts with the same
8505                   XLFD registry name as another font already packaged.
8506               </item>
8507             </enumlist>
8508           </p>
8509         </sect1>
8510
8511         <sect1>
8512           <heading>Application defaults files</heading>
8513
8514           <p>
8515             Application defaults files must be installed in the
8516             directory <file>/etc/X11/app-defaults/</file> (use of a
8517             localized subdirectory of <file>/etc/X11/</file> as described
8518             in the <em>X Toolkit Intrinsics - C Language
8519             Interface</em> manual is also permitted).  They must be
8520             registered as <tt>conffile</tt>s or handled as
8521             configuration files.
8522           </p>
8523
8524           <p>
8525             Customization of programs' X resources may also be
8526             supported with the provision of a file with the same name
8527             as that of the package placed in the
8528             <file>/etc/X11/Xresources/</file> directory, which must
8529             registered as a <tt>conffile</tt> or handled as a
8530             configuration file.<footnote>
8531                 Note that this mechanism is not the same as using
8532                 app-defaults; app-defaults are tied to the client
8533                 binary on the local file system, whereas X resources
8534                 are stored in the X server and affect all connecting
8535                 clients.
8536             </footnote>
8537           </p>
8538         </sect1>
8539
8540         <sect1>
8541           <heading>Installation directory issues</heading>
8542
8543           <p>
8544             Packages using the X Window System should not be
8545             configured to install files under the
8546             <file>/usr/X11R6/</file> directory. The
8547             <file>/usr/X11R6/</file> directory hierarchy should be
8548             regarded as obsolete.
8549           </p>
8550
8551           <p>
8552             Programs that use GNU <prgn>autoconf</prgn> and
8553             <prgn>automake</prgn> are usually easily configured at
8554             compile time to use <file>/usr/</file> instead of
8555             <file>/usr/X11R6/</file>, and this should be done whenever
8556             possible.  Configuration files for window managers and
8557             display managers should be placed in a subdirectory of
8558             <file>/etc/X11/</file> corresponding to the package name due
8559             to these programs' tight integration with the mechanisms
8560             of the X Window System.  Application-level programs should
8561             use the <file>/etc/</file> directory unless otherwise mandated
8562             by policy.
8563           </p>
8564
8565           <p>
8566             The installation of files into subdirectories
8567             of <file>/usr/X11R6/include/X11/</file> and
8568             <file>/usr/X11R6/lib/X11/</file> is now prohibited;
8569             package maintainers should determine if subdirectories of
8570             <file>/usr/lib/</file> and <file>/usr/share/</file> can be used
8571             instead. 
8572           </p>
8573
8574           <p>
8575             Packages should install any relevant files into the
8576             directories <file>/usr/include/X11/</file> and
8577             <file>/usr/lib/X11/</file>, but if they do so, they must
8578             pre-depend on <tt>x11-common (&gt;=
8579             1:7.0.0)</tt><footnote>
8580               <p>
8581                 These libraries used to be all symbolic
8582                 links. However, with <tt>X11R7</tt>,
8583                 <tt>/usr/include/X11</tt> and <tt>/usr/lib/X11</tt>
8584                 are now real directories, and packages
8585                 <strong>should</strong> ship their files here instead
8586                 of in <tt>/usr/X11R6/{include,lib}/X11</tt>.
8587                 <tt>x11-common (&gt;= 1:7.0.0) </tt> is the package
8588                 responsible for converting these symlinks into
8589                 directories.
8590               </p>
8591             </footnote>
8592           </p>
8593         </sect1>
8594
8595         <sect1>
8596           <heading>The OSF/Motif and OpenMotif libraries</heading>
8597
8598           <p>
8599             <em>Programs that require the non-DFSG-compliant OSF/Motif or
8600               OpenMotif libraries</em><footnote>
8601                 OSF/Motif and OpenMotif are collectively referred to as
8602                 "Motif" in this policy document.
8603             </footnote>
8604             should be compiled against and tested with LessTif (a free
8605             re-implementation of Motif) instead.  If the maintainer
8606             judges that the program or programs do not work
8607             sufficiently well with LessTif to be distributed and
8608             supported, but do so when compiled against Motif, then two
8609             versions of the package should be created; one linked
8610             statically against Motif and with <tt>-smotif</tt>
8611             appended to the package name, and one linked dynamically
8612             against Motif and with <tt>-dmotif</tt> appended to the
8613             package name.
8614           </p>
8615
8616           <p>
8617             Both Motif-linked versions are dependent
8618             upon non-DFSG-compliant software and thus cannot be
8619             uploaded to the <em>main</em> distribution; if the
8620             software is itself DFSG-compliant it may be uploaded to
8621             the <em>contrib</em> distribution.  While known existing
8622             versions of Motif permit unlimited redistribution of
8623             binaries linked against the library (whether statically or
8624             dynamically), it is the package maintainer's
8625             responsibility to determine whether this is permitted by
8626             the license of the copy of Motif in their possession.
8627           </p>
8628         </sect1>
8629       </sect>
8630
8631       <sect id="perl">
8632         <heading>Perl programs and modules</heading>
8633
8634         <p>
8635           Perl programs and modules should follow the current Perl policy.
8636         </p>
8637
8638         <p>
8639           The Perl policy can be found in the <tt>perl-policy</tt>
8640           files in the <tt>debian-policy</tt> package.
8641           It is also available from the Debian web mirrors at
8642           <tt><url name="/doc/packaging-manuals/perl-policy/"
8643                 id="http://www.debian.org/doc/packaging-manuals/perl-policy/"></tt>.
8644         </p>
8645       </sect>
8646
8647       <sect id="emacs">
8648         <heading>Emacs lisp programs</heading>
8649
8650         <p>
8651           Please refer to the "Debian Emacs Policy" for details of how to
8652           package emacs lisp programs.
8653         </p>
8654
8655         <p>
8656           The Emacs policy is available in
8657           <file>debian-emacs-policy.gz</file> of the
8658           <package>emacsen-common</package> package.
8659           It is also available from the Debian web mirrors at
8660           <tt><url name="/doc/packaging-manuals/debian-emacs-policy"
8661                 id="http://www.debian.org/doc/packaging-manuals/debian-emacs-policy"></tt>.
8662         </p>
8663       </sect>
8664
8665       <sect>
8666         <heading>Games</heading>
8667
8668         <p>
8669           The permissions on <file>/var/games</file> are mode 755, owner
8670           <tt>root</tt> and group <tt>root</tt>.
8671         </p>
8672
8673         <p>
8674           Each game decides on its own security policy.</p>
8675
8676         <p>
8677           Games which require protected, privileged access to
8678           high-score files, saved games, etc., may be made
8679           set-<em>group</em>-id (mode 2755) and owned by
8680           <tt>root:games</tt>, and use files and directories with
8681           appropriate permissions (770 <tt>root:games</tt>, for
8682           example).  They must not be made
8683           set-<em>user</em>-id, as this causes security problems. (If
8684           an attacker can subvert any set-user-id game they can
8685           overwrite the executable of any other, causing other players
8686           of these games to run a Trojan horse program.  With a
8687           set-group-id game the attacker only gets access to less
8688           important game data, and if they can get at the other
8689           players' accounts at all it will take considerably more
8690           effort.)</p>
8691
8692         <p>
8693           Some packages, for example some fortune cookie programs, are
8694           configured by the upstream authors to install with their
8695           data files or other static information made unreadable so
8696           that they can only be accessed through set-id programs
8697           provided.  You should not do this in a Debian package: anyone can
8698           download the <file>.deb</file> file and read the data from it,
8699           so there is no point making the files unreadable.  Not
8700           making the files unreadable also means that you don't have
8701           to make so many programs set-id, which reduces the risk of a
8702           security hole.</p>
8703
8704         <p>
8705           As described in the FHS, binaries of games should be
8706           installed in the directory <file>/usr/games</file>. This also
8707           applies to games that use the X Window System. Manual pages
8708           for games (X and non-X games) should be installed in
8709           <file>/usr/share/man/man6</file>.</p>
8710       </sect>
8711     </chapt>
8712
8713
8714     <chapt id="docs">
8715       <heading>Documentation</heading>
8716
8717       <sect>
8718         <heading>Manual pages</heading>
8719
8720         <p>
8721           You should install manual pages in <prgn>nroff</prgn> source
8722           form, in appropriate places under <file>/usr/share/man</file>.
8723           You should only use sections 1 to 9 (see the FHS for more
8724           details).  You must not install a pre-formatted "cat page".
8725         </p>
8726
8727         <p>
8728           Each program, utility, and function should have an
8729           associated manual page included in the same package. It is
8730           suggested that all configuration files also have a manual
8731           page included as well. Manual pages for protocols and other
8732           auxiliary things are optional.
8733         </p>
8734
8735         <p>
8736           If no manual page is available, this is considered as a bug
8737           and should be reported to the Debian Bug Tracking System (the
8738           maintainer of the package is allowed to write this bug report
8739           themselves, if they so desire).  Do not close the bug report
8740           until a proper man page is available.<footnote>
8741               It is not very hard to write a man page. See the
8742               <url id="http://www.schweikhardt.net/man_page_howto.html"
8743                 name="Man-Page-HOWTO">,
8744               <manref name="man" section="7">, the examples
8745               created by <prgn>debmake</prgn> or <prgn>dh_make</prgn>,
8746               the helper programs <prgn>help2man</prgn>, or the
8747               directory <file>/usr/share/doc/man-db/examples</file>.
8748           </footnote>
8749         </p>
8750
8751         <p>
8752           You may forward a complaint about a missing man page to the
8753           upstream authors, and mark the bug as forwarded in the
8754           Debian bug tracking system.  Even though the GNU Project do
8755           not in general consider the lack of a man page to be a bug,
8756           we do; if they tell you that they don't consider it a bug
8757           you should leave the bug in our bug tracking system open
8758           anyway.
8759         </p>
8760
8761         <p>
8762           Manual pages should be installed compressed using <tt>gzip -9</tt>.
8763         </p>
8764
8765         <p>
8766           If one man page needs to be accessible via several names it
8767           is better to use a symbolic link than the <file>.so</file>
8768           feature, but there is no need to fiddle with the relevant
8769           parts of the upstream source to change from <file>.so</file> to
8770           symlinks: don't do it unless it's easy.  You should not
8771           create hard links in the manual page directories, nor put
8772           absolute filenames in <file>.so</file> directives.  The filename
8773           in a <file>.so</file> in a man page should be relative to the
8774           base of the man page tree (usually
8775           <file>/usr/share/man</file>). If you do not create any links
8776           (whether symlinks, hard links, or <tt>.so</tt> directives)
8777           in the file system to the alternate names of the man page,
8778           then you should not rely on <prgn>man</prgn> finding your
8779           man page under those names based solely on the information in
8780           the man page's header.<footnote>
8781               Supporting this in <prgn>man</prgn> often requires
8782               unreasonable processing time to find a manual page or to
8783               report that none exists, and moves knowledge into man's
8784               database that would be better left in the file system.
8785               This support is therefore deprecated and will cease to
8786               be present in the future.
8787           </footnote>
8788         </p>
8789
8790         <p>
8791           Manual pages in locale-specific subdirectories of
8792           <file>/usr/share/man</file> should use either UTF-8 or the usual
8793           legacy encoding for that language (normally the one corresponding
8794           to the shortest relevant locale name in
8795           <file>/usr/share/i18n/SUPPORTED</file>). For example, pages under
8796           <file>/usr/share/man/fr</file> should use either UTF-8 or
8797           ISO-8859-1.<footnote>
8798             <prgn>man</prgn> will automatically detect whether UTF-8 is in
8799             use. In future, all manual pages will be required to use
8800             UTF-8.
8801           </footnote>
8802         </p>
8803
8804         <p>
8805           A country name (the <tt>DE</tt> in <tt>de_DE</tt>) should not be
8806           included in the subdirectory name unless it indicates a
8807           significant difference in the language, as this excludes
8808           speakers of the language in other countries.<footnote>
8809             At the time of writing, Chinese and Portuguese are the main
8810             languages with such differences, so <file>pt_BR</file>,
8811             <file>zh_CN</file>, and <file>zh_TW</file> are all allowed.
8812           </footnote>
8813         </p>
8814
8815         <p>
8816           Due to limitations in current implementations, all characters
8817           in the manual page source should be representable in the usual
8818           legacy encoding for that language, even if the file is
8819           actually encoded in UTF-8. Safe alternative ways to write many
8820           characters outside that range may be found in
8821           <manref name="groff_char" section="7">.
8822         </p>
8823       </sect>
8824
8825       <sect>
8826         <heading>Info documents</heading>
8827
8828         <p>
8829           Info documents should be installed in <file>/usr/share/info</file>.
8830           They should be compressed with <tt>gzip -9</tt>.
8831         </p>
8832
8833         <p>
8834           Your package should call <prgn>install-info</prgn> to update
8835           the Info <file>dir</file> file in its <prgn>postinst</prgn>
8836           script when called with a <tt>configure</tt> argument, for
8837           example:
8838           <example compact="compact">
8839 install-info --quiet --section Development Development \
8840   /usr/share/info/foobar.info
8841           </example></p>
8842
8843         <p>
8844           It is a good idea to specify a section for the location of
8845           your program; this is done with the <tt>--section</tt>
8846           switch.  To determine which section to use, you should look
8847           at <file>/usr/share/info/dir</file> on your system and choose the most
8848           relevant (or create a new section if none of the current
8849           sections are relevant).  Note that the <tt>--section</tt>
8850           flag takes two arguments; the first is a regular expression
8851           to match (case-insensitively) against an existing section,
8852           the second is used when creating a new one.</p>
8853
8854         <p>
8855           You should remove the entries in the <prgn>prerm</prgn>
8856           script when called with a <tt>remove</tt> argument:
8857           <example compact="compact">
8858 install-info --quiet --remove /usr/share/info/foobar.info
8859           </example></p>
8860
8861         <p>
8862           If <prgn>install-info</prgn> cannot find a description entry
8863           in the Info file you must supply one.  See <manref
8864           name="install-info" section="8"> for details.</p>
8865       </sect>
8866
8867       <sect>
8868         <heading>Additional documentation</heading>
8869
8870         <p>
8871           Any additional documentation that comes with the package may
8872           be installed at the discretion of the package maintainer.
8873           Plain text documentation should be installed in the directory
8874           <file>/usr/share/doc/<var>package</var></file>, where
8875           <var>package</var> is the name of the package, and
8876           compressed with <tt>gzip -9</tt> unless it is small.
8877         </p>
8878
8879         <p>
8880           If a package comes with large amounts of documentation which
8881           many users of the package will not require you should create
8882           a separate binary package to contain it, so that it does not
8883           take up disk space on the machines of users who do not need
8884           or want it installed.</p>
8885
8886         <p>
8887           It is often a good idea to put text information files
8888           (<file>README</file>s, changelogs, and so forth) that come with
8889           the source package in <file>/usr/share/doc/<var>package</var></file>
8890           in the binary package.  However, you don't need to install
8891           the instructions for building and installing the package, of
8892           course!</p>
8893
8894         <p>
8895           Packages must not require the existence of any files in
8896           <file>/usr/share/doc/</file> in order to function
8897           <footnote>
8898               The system administrator should be able to
8899               delete files in <file>/usr/share/doc/</file> without causing
8900               any programs to break.
8901           </footnote>.
8902           Any files that are referenced by programs but are also
8903           useful as stand alone documentation should be installed under
8904           <file>/usr/share/<var>package</var>/</file> with symbolic links from
8905           <file>/usr/share/doc/<var>package</var></file>.
8906         </p>
8907
8908         <p>
8909           <file>/usr/share/doc/<var>package</var></file> may be a symbolic
8910           link to another directory in <file>/usr/share/doc</file> only if
8911           the two packages both come from the same source and the
8912           first package Depends on the second.<footnote>
8913             <p>
8914               Please note that this does not override the section on
8915               changelog files below, so the file 
8916               <file>/usr/share/<var>package</var>/changelog.Debian.gz</file>
8917               must refer to the changelog for the current version of
8918               <var>package</var> in question. In practice, this means
8919               that the sources of the target and the destination of the
8920               symlink must be the same (same source package and
8921               version). 
8922             </p>
8923           </footnote>
8924         </p>
8925
8926         <p>
8927           Former Debian releases placed all additional documentation
8928           in <file>/usr/doc/<var>package</var></file>.  This has been
8929           changed to <file>/usr/share/doc/<var>package</var></file>,
8930           and packages must not put documentation in the directory
8931           <file>/usr/doc/<var>package</var></file>. <footnote>
8932             At this phase of the transition, we no longer require a
8933             symbolic link in <file>/usr/doc/</file>. At a later point,
8934             policy shall change to make the symbolic links a bug.
8935           </footnote>
8936         </p>
8937       </sect>
8938
8939       <sect>
8940         <heading>Preferred documentation formats</heading>
8941
8942         <p>
8943           The unification of Debian documentation is being carried out
8944           via HTML.</p>
8945
8946         <p>
8947           If your package comes with extensive documentation in a
8948           markup format that can be converted to various other formats
8949           you should if possible ship HTML versions in a binary
8950           package, in the directory
8951           <file>/usr/share/doc/<var>appropriate-package</var></file> or
8952           its subdirectories.<footnote>
8953               The rationale: The important thing here is that HTML
8954               docs should be available in <em>some</em> package, not
8955               necessarily in the main binary package.
8956           </footnote>
8957         </p>
8958
8959         <p>
8960           Other formats such as PostScript may be provided at the
8961           package maintainer's discretion.
8962         </p>
8963       </sect>
8964
8965       <sect id="copyrightfile">
8966         <heading>Copyright information</heading>
8967
8968         <p>
8969           Every package must be accompanied by a verbatim copy of its
8970           copyright and distribution license in the file
8971           <file>/usr/share/doc/<var>package</var>/copyright</file>. This
8972           file must neither be compressed nor be a symbolic link.
8973         </p>
8974
8975         <p>
8976           In addition, the copyright file must say where the upstream
8977           sources (if any) were obtained.  It should name the original
8978           authors of the package and the Debian maintainer(s) who were
8979           involved with its creation.
8980         </p>
8981
8982         <p>
8983           Packages in the <em>contrib</em> or <em>non-free</em> categories
8984           should state in the copyright file that the package is not part
8985           of the Debian GNU/Linux distribution and briefly explain why.
8986         </p>
8987
8988         <p>
8989           A copy of the file which will be installed in
8990           <file>/usr/share/doc/<var>package</var>/copyright</file> should
8991           be in <file>debian/copyright</file> in the source package.
8992         </p>
8993
8994         <p>
8995           <file>/usr/share/doc/<var>package</var></file> may be a symbolic
8996           link to another directory in <file>/usr/share/doc</file> only if
8997           the two packages both come from the same source and the
8998           first package Depends on the second.  These rules are
8999           important because copyrights must be extractable by
9000           mechanical means.
9001         </p>
9002
9003         <p>
9004           Packages distributed under the UCB BSD license, the Apache
9005           license (version 2.0), the Artistic license, the GNU GPL
9006           (version 2 or 3), the GNU LGPL (versions 2, 2.1, or 3), and
9007           the GNU FDL (version 1.2) should refer to the corresponding
9008           files under <file>/usr/share/common-licenses</file>,<footnote>
9009             <p>
9010               In particular,
9011               <file>/usr/share/common-licenses/BSD</file>,
9012               <file>/usr/share/common-licenses/Apache-2.0</file>,
9013               <file>/usr/share/common-licenses/Artistic</file>,
9014               <file>/usr/share/common-licenses/GPL-2</file>,
9015               <file>/usr/share/common-licenses/GPL-3</file>,
9016               <file>/usr/share/common-licenses/LGPL-2</file>,
9017               <file>/usr/share/common-licenses/LGPL-2.1</file>,
9018               <file>/usr/share/common-licenses/LGPL-3</file>, and
9019               <file>/usr/share/common-licenses/GFDL-1.2</file>
9020               respectively.
9021             </p>
9022           </footnote> rather than quoting them in the copyright
9023           file. 
9024         </p>
9025
9026         <p>
9027           You should not use the copyright file as a general <file>README</file>
9028           file.  If your package has such a file it should be
9029           installed in <file>/usr/share/doc/<var>package</var>/README</file> or
9030           <file>README.Debian</file> or some other appropriate place.</p>
9031       </sect>
9032
9033       <sect>
9034         <heading>Examples</heading>
9035
9036         <p>
9037           Any examples (configurations, source files, whatever),
9038           should be installed in a directory
9039           <file>/usr/share/doc/<var>package</var>/examples</file>.  These
9040           files should not be referenced by any program: they're there
9041           for the benefit of the system administrator and users as
9042           documentation only.  Architecture-specific example files
9043           should be installed in a directory
9044           <file>/usr/lib/<var>package</var>/examples</file> with symbolic
9045           links to them from
9046           <file>/usr/share/doc/<var>package</var>/examples</file>, or the
9047           latter directory itself may be a symbolic link to the
9048           former.
9049         </p>
9050
9051         <p>
9052           If the purpose of a package is to provide examples, then the
9053           example files may be installed into
9054           <file>/usr/share/doc/<var>package</var></file>.
9055         </p>
9056       </sect>
9057
9058       <sect id="changelogs">
9059         <heading>Changelog files</heading>
9060
9061         <p>
9062           Packages that are not Debian-native must contain a
9063           compressed copy of the <file>debian/changelog</file> file from
9064           the Debian source tree in
9065           <file>/usr/share/doc/<var>package</var></file> with the name
9066           <file>changelog.Debian.gz</file>.
9067         </p>
9068
9069         <p>
9070           If an upstream changelog is available, it should be accessible as
9071           <file>/usr/share/doc/<var>package</var>/changelog.gz</file> in
9072           plain text.  If the upstream changelog is distributed in
9073           HTML, it should be made available in that form as
9074           <file>/usr/share/doc/<var>package</var>/changelog.html.gz</file>
9075           and a plain text <file>changelog.gz</file> should be generated
9076           from it using, for example, <tt>lynx -dump -nolist</tt>.  If
9077           the upstream changelog files do not already conform to this
9078           naming convention, then this may be achieved either by
9079           renaming the files, or by adding a symbolic link, at the
9080           maintainer's discretion.<footnote>
9081               Rationale: People should not have to look in places for
9082               upstream changelogs merely because they are given
9083               different names or are distributed in HTML format.
9084           </footnote>
9085         </p>
9086
9087         <p>
9088           All of these files should be installed compressed using
9089           <tt>gzip -9</tt>, as they will become large with time even
9090           if they start out small.
9091         </p>
9092
9093         <p>
9094           If the package has only one changelog which is used both as
9095           the Debian changelog and the upstream one because there is
9096           no separate upstream maintainer then that changelog should
9097           usually be installed as
9098           <file>/usr/share/doc/<var>package</var>/changelog.gz</file>; if
9099           there is a separate upstream maintainer, but no upstream
9100           changelog, then the Debian changelog should still be called
9101           <file>changelog.Debian.gz</file>.
9102         </p>
9103
9104         <p>
9105           For details about the format and contents of the Debian
9106           changelog file, please see <ref id="dpkgchangelog">.
9107         </p>
9108       </sect>
9109     </chapt>
9110
9111     <appendix id="pkg-scope">
9112       <heading>Introduction and scope of these appendices</heading>
9113
9114       <p>
9115         These appendices are taken essentially verbatim from the
9116         now-deprecated Packaging Manual, version 3.2.1.0.  They are
9117         the chapters which are likely to be of use to package
9118         maintainers and which have not already been included in the
9119         policy document itself. Most of these sections are very likely
9120         not relevant to policy; they should be treated as
9121         documentation for the packaging system. Please note that these
9122         appendices are included for convenience, and for historical
9123         reasons: they used to be part of policy package, and they have
9124         not yet been incorporated into dpkg documentation. However,
9125         they still have value, and hence they are presented here.
9126       </p>
9127
9128       <p>
9129         They have not yet been checked to ensure that they are
9130         compatible with the contents of policy, and if there are any
9131         contradictions, the version in the main policy document takes
9132         precedence.  The remaining chapters of the old Packaging
9133         Manual have also not been read in detail to ensure that there
9134         are not parts which have been left out.  Both of these will be
9135         done in due course.
9136       </p>
9137
9138       <p>
9139         Certain parts of the Packaging manual were integrated into the
9140         Policy Manual proper, and removed from the appendices. Links
9141         have been placed from the old locations to the new ones.
9142       </p>
9143
9144       <p>
9145         <prgn>dpkg</prgn> is a suite of programs for creating binary
9146         package files and installing and removing them on Unix
9147         systems.<footnote>
9148             <prgn>dpkg</prgn> is targeted primarily at Debian
9149             GNU/Linux, but may work on or be ported to other
9150             systems.
9151         </footnote>
9152       </p>
9153
9154       <p>
9155         The binary packages are designed for the management of
9156         installed executable programs (usually compiled binaries) and
9157         their associated data, though source code examples and
9158         documentation are provided as part of some packages.</p>
9159
9160       <p>
9161         This manual describes the technical aspects of creating Debian
9162         binary packages (<file>.deb</file> files).  It documents the
9163         behavior of the package management programs
9164         <prgn>dpkg</prgn>, <prgn>dselect</prgn> et al. and the way
9165         they interact with packages.</p>
9166
9167       <p>
9168         It also documents the interaction between
9169         <prgn>dselect</prgn>'s core and the access method scripts it
9170         uses to actually install the selected packages, and describes
9171         how to create a new access method.</p>
9172
9173       <p>
9174         This manual does not go into detail about the options and
9175         usage of the package building and installation tools.  It
9176         should therefore be read in conjunction with those programs'
9177         man pages.
9178       </p>
9179
9180       <p>
9181         The utility programs which are provided with <prgn>dpkg</prgn>
9182         for managing various system configuration and similar issues,
9183         such as <prgn>update-rc.d</prgn> and
9184         <prgn>install-info</prgn>, are not described in detail here -
9185         please see their man pages.
9186       </p>
9187
9188       <p>
9189         It is assumed that the reader is reasonably familiar with the
9190         <prgn>dpkg</prgn> System Administrators' manual.
9191         Unfortunately this manual does not yet exist.
9192       </p>
9193
9194       <p>
9195         The Debian version of the FSF's GNU hello program is provided
9196         as an example for people wishing to create Debian
9197         packages. The Debian <prgn>debmake</prgn> package is
9198         recommended as a very helpful tool in creating and maintaining
9199         Debian packages. However, while the tools and examples are
9200         helpful, they do not replace the need to read and follow the
9201         Policy and Programmer's Manual.</p>
9202     </appendix>
9203
9204     <appendix id="pkg-binarypkg">
9205       <heading>Binary packages (from old Packaging Manual)</heading>
9206
9207       <p>
9208         The binary package has two main sections.  The first part
9209         consists of various control information files and scripts used
9210         by <prgn>dpkg</prgn> when installing and removing.  See <ref
9211         id="pkg-controlarea">.
9212       </p>
9213
9214       <p>
9215         The second part is an archive containing the files and
9216         directories to be installed.
9217       </p>
9218
9219       <p>
9220         In the future binary packages may also contain other
9221         components, such as checksums and digital signatures. The
9222         format for the archive is described in full in the
9223         <file>deb(5)</file> man page.
9224       </p>
9225
9226
9227       <sect id="pkg-bincreating"><heading>Creating package files -
9228       <prgn>dpkg-deb</prgn>
9229         </heading>
9230
9231         <p>
9232           All manipulation of binary package files is done by
9233           <prgn>dpkg-deb</prgn>; it's the only program that has
9234           knowledge of the format.  (<prgn>dpkg-deb</prgn> may be
9235           invoked by calling <prgn>dpkg</prgn>, as <prgn>dpkg</prgn>
9236           will spot that the options requested are appropriate to
9237           <prgn>dpkg-deb</prgn> and invoke that instead with the same
9238           arguments.)
9239         </p>
9240
9241         <p>
9242           In order to create a binary package you must make a
9243           directory tree which contains all the files and directories
9244           you want to have in the file system data part of the package.
9245           In Debian-format source packages this directory is usually
9246           <file>debian/tmp</file>, relative to the top of the package's
9247           source tree.
9248         </p>
9249
9250         <p>
9251           They should have the locations (relative to the root of the
9252           directory tree you're constructing) ownerships and
9253           permissions which you want them to have on the system when
9254           they are installed.
9255         </p>
9256
9257         <p>
9258           With current versions of <prgn>dpkg</prgn> the uid/username
9259           and gid/groupname mappings for the users and groups being
9260           used should be the same on the system where the package is
9261           built and the one where it is installed.
9262         </p>
9263
9264         <p>
9265           You need to add one special directory to the root of the
9266           miniature file system tree you're creating:
9267           <prgn>DEBIAN</prgn>.  It should contain the control
9268           information files, notably the binary package control file
9269           (see <ref id="pkg-controlfile">).
9270         </p>
9271
9272         <p>
9273           The <prgn>DEBIAN</prgn> directory will not appear in the
9274           file system archive of the package, and so won't be installed
9275           by <prgn>dpkg</prgn> when the package is installed.
9276         </p>
9277
9278         <p>
9279           When you've prepared the package, you should invoke:
9280           <example>
9281   dpkg --build <var>directory</var>
9282           </example>
9283         </p>
9284
9285         <p>
9286           This will build the package in
9287           <file><var>directory</var>.deb</file>.  (<prgn>dpkg</prgn> knows
9288           that <tt>--build</tt> is a <prgn>dpkg-deb</prgn> option, so
9289           it invokes <prgn>dpkg-deb</prgn> with the same arguments to
9290           build the package.)
9291         </p>
9292
9293         <p>
9294           See the man page <manref name="dpkg-deb" section="8"> for details of how
9295           to examine the contents of this newly-created file.  You may find the
9296           output of following commands enlightening:
9297           <example>
9298   dpkg-deb --info <var>filename</var>.deb
9299   dpkg-deb --contents <var>filename</var>.deb
9300   dpkg --contents <var>filename</var>.deb
9301           </example>
9302           To view the copyright file for a package you could use this command:
9303           <example>
9304   dpkg --fsys-tarfile <var>filename</var>.deb | tar xOf - \*/copyright | pager
9305           </example>
9306         </p>
9307       </sect>
9308
9309       <sect id="pkg-controlarea">
9310         <heading>Package control information files</heading>
9311
9312         <p>
9313           The control information portion of a binary package is a
9314           collection of files with names known to <prgn>dpkg</prgn>.
9315           It will treat the contents of these files specially - some
9316           of them contain information used by <prgn>dpkg</prgn> when
9317           installing or removing the package; others are scripts which
9318           the package maintainer wants <prgn>dpkg</prgn> to run.
9319         </p>
9320
9321         <p>
9322           It is possible to put other files in the package control
9323           area, but this is not generally a good idea (though they
9324           will largely be ignored).
9325         </p>
9326
9327         <p>
9328           Here is a brief list of the control info files supported by
9329           <prgn>dpkg</prgn> and a summary of what they're used for.
9330         </p>
9331
9332         <p>
9333           <taglist>
9334             <tag><tt>control</tt>
9335             <item>
9336               <p>
9337                 This is the key description file used by
9338                 <prgn>dpkg</prgn>.  It specifies the package's name
9339                 and version, gives its description for the user,
9340                 states its relationships with other packages, and so
9341                 forth.  See <ref id="sourcecontrolfiles"> and
9342                 <ref id="binarycontrolfiles">.
9343               </p>
9344
9345               <p>
9346                 It is usually generated automatically from information
9347                 in the source package by the
9348                 <prgn>dpkg-gencontrol</prgn> program, and with
9349                 assistance from <prgn>dpkg-shlibdeps</prgn>.
9350                 See <ref id="pkg-sourcetools">.
9351               </p>
9352             </item>
9353
9354             <tag><tt>postinst</tt>, <tt>preinst</tt>, <tt>postrm</tt>,
9355                  <tt>prerm</tt>
9356             </tag>
9357             <item>
9358               <p>
9359                 These are executable files (usually scripts) which
9360                 <prgn>dpkg</prgn> runs during installation, upgrade
9361                 and removal of packages.  They allow the package to
9362                 deal with matters which are particular to that package
9363                 or require more complicated processing than that
9364                 provided by <prgn>dpkg</prgn>.  Details of when and
9365                 how they are called are in <ref id="maintainerscripts">.
9366               </p>
9367
9368               <p>
9369                 It is very important to make these scripts idempotent.
9370                 See <ref id="idempotency">.
9371               </p>
9372
9373               <p>
9374                 The maintainer scripts are guaranteed to run with a
9375                 controlling terminal and can interact with the user.
9376                 See <ref id="controllingterminal">.
9377               </p>
9378             </item>
9379
9380             <tag><tt>conffiles</tt>
9381             </tag>
9382             <item>
9383                 This file contains a list of configuration files which
9384                 are to be handled automatically by <prgn>dpkg</prgn>
9385                 (see <ref id="pkg-conffiles">).  Note that not necessarily
9386                 every configuration file should be listed here.
9387             </item>
9388
9389             <tag><tt>shlibs</tt>
9390             </tag>
9391             <item>
9392                 This file contains a list of the shared libraries
9393                 supplied by the package, with dependency details for
9394                 each.  This is used by <prgn>dpkg-shlibdeps</prgn>
9395                 when it determines what dependencies are required in a
9396                 package control file. The <tt>shlibs</tt> file format
9397                 is described on <ref id="shlibs">.
9398             </item>
9399           </taglist>
9400         </p>
9401
9402       <sect id="pkg-controlfile">
9403         <heading>The main control information file: <tt>control</tt></heading>
9404
9405         <p>
9406           The most important control information file used by
9407           <prgn>dpkg</prgn> when it installs a package is
9408           <tt>control</tt>.  It contains all the package's "vital
9409           statistics".
9410         </p>
9411
9412         <p>
9413           The binary package control files of packages built from
9414           Debian sources are made by a special tool,
9415           <prgn>dpkg-gencontrol</prgn>, which reads
9416           <file>debian/control</file> and <file>debian/changelog</file> to
9417           find the information it needs.  See <ref id="pkg-sourcepkg"> for
9418           more details.
9419         </p>
9420
9421         <p>
9422           The fields in binary package control files are listed in
9423           <ref id="binarycontrolfiles">.
9424         </p>
9425
9426         <p>
9427           A description of the syntax of control files and the purpose
9428           of the fields is available in <ref id="controlfields">.
9429         </p>
9430       </sect>
9431
9432       <sect>
9433         <heading>Time Stamps</heading>
9434
9435         <p>
9436           See <ref id="timestamps">.
9437         </p>
9438       </sect>
9439     </appendix>
9440
9441     <appendix id="pkg-sourcepkg">
9442       <heading>Source packages (from old Packaging Manual) </heading>
9443
9444       <p>
9445         The Debian binary packages in the distribution are generated
9446         from Debian sources, which are in a special format to assist
9447         the easy and automatic building of binaries.
9448       </p>
9449
9450       <sect id="pkg-sourcetools">
9451         <heading>Tools for processing source packages</heading>
9452
9453         <p>
9454           Various tools are provided for manipulating source packages;
9455           they pack and unpack sources and help build of binary
9456           packages and help manage the distribution of new versions.
9457         </p>
9458
9459         <p>
9460           They are introduced and typical uses described here; see
9461           <manref name="dpkg-source" section="1"> for full
9462           documentation about their arguments and operation.
9463         </p>
9464
9465         <p>
9466           For examples of how to construct a Debian source package,
9467           and how to use those utilities that are used by Debian
9468           source packages, please see the <prgn>hello</prgn> example
9469           package.
9470         </p>
9471
9472         <sect1 id="pkg-dpkg-source">
9473           <heading>
9474             <prgn>dpkg-source</prgn> - packs and unpacks Debian source
9475             packages
9476           </heading>
9477
9478           <p>
9479             This program is frequently used by hand, and is also
9480             called from package-independent automated building scripts
9481             such as <prgn>dpkg-buildpackage</prgn>.
9482           </p>
9483
9484           <p>
9485             To unpack a package it is typically invoked with
9486             <example>
9487   dpkg-source -x <var>.../path/to/filename</var>.dsc
9488             </example>
9489           </p>
9490
9491            <p>
9492             with the <file><var>filename</var>.tar.gz</file> and
9493             <file><var>filename</var>.diff.gz</file> (if applicable) in
9494             the same directory.  It unpacks into
9495             <file><var>package</var>-<var>version</var></file>, and if
9496             applicable
9497             <file><var>package</var>-<var>version</var>.orig</file>, in
9498             the current directory.
9499           </p>
9500
9501           <p>
9502             To create a packed source archive it is typically invoked:
9503             <example>
9504   dpkg-source -b <var>package</var>-<var>version</var>
9505           </example>
9506           </p>
9507
9508           <p>
9509             This will create the <file>.dsc</file>, <file>.tar.gz</file> and
9510             <file>.diff.gz</file> (if appropriate) in the current
9511             directory.  <prgn>dpkg-source</prgn> does not clean the
9512             source tree first - this must be done separately if it is
9513             required.
9514           </p>
9515
9516           <p>
9517             See also <ref id="pkg-sourcearchives">.</p>
9518         </sect1>
9519
9520
9521         <sect1 id="pkg-dpkg-buildpackage">
9522           <heading>
9523             <prgn>dpkg-buildpackage</prgn> - overall package-building
9524             control script
9525           </heading>
9526
9527           <p>
9528             <prgn>dpkg-buildpackage</prgn> is a script which invokes
9529             <prgn>dpkg-source</prgn>, the <file>debian/rules</file>
9530             targets <tt>clean</tt>, <tt>build</tt> and
9531             <tt>binary</tt>, <prgn>dpkg-genchanges</prgn> and
9532             <prgn>gpg</prgn> (or <prgn>pgp</prgn>) to build a signed
9533             source and binary package upload.
9534           </p>
9535
9536           <p>
9537             It is usually invoked by hand from the top level of the
9538             built or unbuilt source directory.  It may be invoked with
9539             no arguments; useful arguments include:
9540             <taglist compact="compact">
9541               <tag><tt>-uc</tt>, <tt>-us</tt></tag>
9542               <item>
9543                 <p>
9544                   Do not sign the <tt>.changes</tt> file or the
9545                   source package <tt>.dsc</tt> file, respectively.</p>
9546               </item>
9547               <tag><tt>-p<var>sign-command</var></tt></tag>
9548               <item>
9549                 <p>
9550                   Invoke <var>sign-command</var> instead of finding
9551                   <tt>gpg</tt> or <tt>pgp</tt> on the <prgn>PATH</prgn>.
9552                   <var>sign-command</var> must behave just like
9553                   <prgn>gpg</prgn> or <tt>pgp</tt>.</p>
9554               </item>
9555               <tag><tt>-r<var>root-command</var></tt></tag>
9556               <item>
9557                 <p>
9558                   When root privilege is required, invoke the command
9559                   <var>root-command</var>.  <var>root-command</var>
9560                   should invoke its first argument as a command, from
9561                   the <prgn>PATH</prgn> if necessary, and pass its
9562                   second and subsequent arguments to the command it
9563                   calls.  If no <var>root-command</var> is supplied
9564                   then <var>dpkg-buildpackage</var> will take no
9565                   special action to gain root privilege, so that for
9566                   most packages it will have to be invoked as root to
9567                   start with.</p>
9568               </item>
9569               <tag><tt>-b</tt>, <tt>-B</tt></tag>
9570               <item>
9571                 <p>
9572                   Two types of binary-only build and upload - see
9573                   <manref name="dpkg-source" section="1">.
9574                 </p>
9575               </item>
9576             </taglist>
9577           </p>
9578         </sect1>
9579
9580         <sect1 id="pkg-dpkg-gencontrol">
9581           <heading>
9582             <prgn>dpkg-gencontrol</prgn> - generates binary package
9583             control files
9584           </heading>
9585
9586           <p>
9587             This program is usually called from <file>debian/rules</file>
9588             (see <ref id="pkg-sourcetree">) in the top level of the source
9589             tree.
9590           </p>
9591
9592           <p>
9593             This is usually done just before the files and directories in the
9594             temporary directory tree where the package is being built have their
9595             permissions and ownerships set and the package is constructed using
9596             <prgn>dpkg-deb/</prgn>
9597               <footnote>
9598                 This is so that the control file which is produced has
9599                 the right permissions
9600             </footnote>.
9601           </p>
9602
9603           <p>
9604             <prgn>dpkg-gencontrol</prgn> must be called after all the
9605             files which are to go into the package have been placed in
9606             the temporary build directory, so that its calculation of
9607             the installed size of a package is correct.
9608           </p>
9609
9610           <p>
9611             It is also necessary for <prgn>dpkg-gencontrol</prgn> to
9612             be run after <prgn>dpkg-shlibdeps</prgn> so that the
9613             variable substitutions created by
9614             <prgn>dpkg-shlibdeps</prgn> in <file>debian/substvars</file>
9615             are available.
9616           </p>
9617
9618           <p>
9619             For a package which generates only one binary package, and
9620             which builds it in <file>debian/tmp</file> relative to the top
9621             of the source package, it is usually sufficient to call
9622             <prgn>dpkg-gencontrol</prgn>.
9623           </p>
9624
9625           <p>
9626             Sources which build several binaries will typically need
9627             something like:
9628             <example>
9629   dpkg-gencontrol -Pdebian/tmp-<var>pkg</var> -p<var>package</var>
9630             </example> The <tt>-P</tt> tells
9631             <prgn>dpkg-gencontrol</prgn> that the package is being
9632             built in a non-default directory, and the <tt>-p</tt>
9633             tells it which package's control file should be generated.
9634           </p>
9635
9636           <p>
9637             <prgn>dpkg-gencontrol</prgn> also adds information to the
9638             list of files in <file>debian/files</file>, for the benefit of
9639             (for example) a future invocation of
9640             <prgn>dpkg-genchanges</prgn>.</p>
9641         </sect1>
9642
9643         <sect1 id="pkg-dpkg-shlibdeps">
9644           <heading>
9645             <prgn>dpkg-shlibdeps</prgn> - calculates shared library
9646             dependencies
9647           </heading>
9648
9649           <p>
9650             This program is usually called from <file>debian/rules</file>
9651             just before <prgn>dpkg-gencontrol</prgn> (see <ref
9652             id="pkg-sourcetree">), in the top level of the source tree.
9653           </p>
9654
9655           <p>
9656             Its arguments are executables and shared libraries
9657             <footnote>
9658               <p>
9659                 They may be specified either in the locations in the
9660                 source tree where they are created or in the locations
9661                 in the temporary build tree where they are installed
9662                 prior to binary package creation.
9663               </p>
9664             </footnote> for which shared library dependencies should
9665             be included in the binary package's control file.
9666           </p>
9667
9668           <p>
9669             If some of the found shared libraries should only
9670             warrant a <tt>Recommends</tt> or <tt>Suggests</tt>, or if
9671             some warrant a <tt>Pre-Depends</tt>, this can be achieved
9672             by using the <tt>-d<var>dependency-field</var></tt> option
9673             before those executable(s).  (Each <tt>-d</tt> option
9674             takes effect until the next <tt>-d</tt>.)
9675           </p>
9676
9677           <p>
9678             <prgn>dpkg-shlibdeps</prgn> does not directly cause the
9679             output control file to be modified.  Instead by default it
9680             adds to the <file>debian/substvars</file> file variable
9681             settings like <tt>shlibs:Depends</tt>.  These variable
9682             settings must be referenced in dependency fields in the
9683             appropriate per-binary-package sections of the source
9684             control file.
9685           </p>
9686
9687           <p>
9688             For example, a package that generates an essential part
9689             which requires dependencies, and optional parts that 
9690             which only require a recommendation, would separate those
9691             two sets of dependencies into two different fields.<footnote>
9692                 At the time of writing, an example for this was the
9693                 <package/xmms/ package, with Depends used for the xmms
9694                 executable, Recommends for the plug-ins and Suggests for
9695                 even more optional features provided by unzip.
9696             </footnote>
9697             It can say in its <file>debian/rules</file>:
9698             <example>
9699   dpkg-shlibdeps -dDepends <var>program anotherprogram ...</var> \
9700                  -dRecommends <var>optionalpart anotheroptionalpart</var>
9701             </example>
9702             and then in its main control file <file>debian/control</file>:
9703             <example>
9704   <var>...</var>
9705   Depends: ${shlibs:Depends}
9706   Recommends: ${shlibs:Recommends}
9707   <var>...</var>
9708             </example>
9709           </p>
9710
9711           <p>
9712             Sources which produce several binary packages with
9713             different shared library dependency requirements can use
9714             the <tt>-p<var>varnameprefix</var></tt> option to override
9715             the default <tt>shlibs:</tt> prefix (one invocation of
9716             <prgn>dpkg-shlibdeps</prgn> per setting of this option).
9717             They can thus produce several sets of dependency
9718             variables, each of the form
9719             <tt><var>varnameprefix</var>:<var>dependencyfield</var></tt>,
9720             which can be referred to in the appropriate parts of the
9721             binary package control files.
9722           </p>
9723         </sect1>
9724
9725
9726         <sect1 id="pkg-dpkg-distaddfile">
9727           <heading>
9728             <prgn>dpkg-distaddfile</prgn> - adds a file to
9729             <file>debian/files</file>
9730           </heading>
9731
9732           <p>
9733             Some packages' uploads need to include files other than
9734             the source and binary package files.
9735           </p>
9736
9737           <p>
9738             <prgn>dpkg-distaddfile</prgn> adds a file to the
9739             <file>debian/files</file> file so that it will be included in
9740             the <file>.changes</file> file when
9741             <prgn>dpkg-genchanges</prgn> is run.
9742           </p>
9743
9744           <p>
9745             It is usually invoked from the <tt>binary</tt> target of
9746             <file>debian/rules</file>:
9747             <example>
9748   dpkg-distaddfile <var>filename</var> <var>section</var> <var>priority</var>
9749             </example>
9750             The <var>filename</var> is relative to the directory where
9751             <prgn>dpkg-genchanges</prgn> will expect to find it - this
9752             is usually the directory above the top level of the source
9753             tree.  The <file>debian/rules</file> target should put the
9754             file there just before or just after calling
9755             <prgn>dpkg-distaddfile</prgn>.
9756           </p>
9757
9758           <p>
9759             The <var>section</var> and <var>priority</var> are passed
9760             unchanged into the resulting <file>.changes</file> file.
9761           </p>
9762         </sect1>
9763
9764
9765         <sect1 id="pkg-dpkg-genchanges">
9766           <heading>
9767             <prgn>dpkg-genchanges</prgn> - generates a <file>.changes</file>
9768             upload control file
9769           </heading>
9770
9771           <p>
9772             This program is usually called by package-independent
9773             automatic building scripts such as
9774             <prgn>dpkg-buildpackage</prgn>, but it may also be called
9775             by hand.
9776           </p>
9777
9778           <p>
9779             It is usually called in the top level of a built source
9780             tree, and when invoked with no arguments will print out a
9781             straightforward <file>.changes</file> file based on the
9782             information in the source package's changelog and control
9783             file and the binary and source packages which should have
9784             been built.
9785           </p>
9786         </sect1>
9787
9788
9789         <sect1 id="pkg-dpkg-parsechangelog">
9790           <heading>
9791             <prgn>dpkg-parsechangelog</prgn> - produces parsed
9792             representation of a changelog
9793           </heading>
9794
9795           <p>
9796             This program is used internally by
9797             <prgn>dpkg-source</prgn> et al.  It may also occasionally
9798             be useful in <file>debian/rules</file> and elsewhere.  It
9799             parses a changelog, <file>debian/changelog</file> by default,
9800             and prints a control-file format representation of the
9801             information in it to standard output.
9802           </p>
9803         </sect1>
9804
9805         <sect1 id="pkg-dpkg-architecture">
9806           <heading>
9807             <prgn>dpkg-architecture</prgn> - information about the build and
9808             host system
9809           </heading>
9810
9811           <p>
9812             This program can be used manually, but is also invoked by
9813             <tt>dpkg-buildpackage</tt> or <file>debian/rules</file> to set
9814             environment or make variables which specify the build and host
9815             architecture for the package building process.
9816           </p>
9817         </sect1>
9818       </sect>
9819
9820       <sect id="pkg-sourcetree">
9821         <heading>The Debianised source tree</heading>
9822
9823         <p>
9824           The source archive scheme described later is intended to
9825           allow a Debianised source tree with some associated control
9826           information to be reproduced and transported easily.  The
9827           Debianised source tree is a version of the original program
9828           with certain files added for the benefit of the
9829           Debianisation process, and with any other changes required
9830           made to the rest of the source code and installation
9831           scripts.
9832         </p>
9833
9834         <p>
9835           The extra files created for Debian are in the subdirectory
9836           <file>debian</file> of the top level of the Debianised source
9837           tree.  They are described below.
9838         </p>
9839
9840         <sect1 id="pkg-debianrules">
9841           <heading><file>debian/rules</file> - the main building script</heading>
9842
9843           <p>
9844             See <ref id="debianrules">.
9845           </p>
9846         </sect1>
9847
9848
9849         <sect1 id="pkg-dpkgchangelog">
9850           <heading><file>debian/changelog</file></heading>
9851
9852           <p>
9853             See <ref id="dpkgchangelog">.
9854           </p>
9855
9856           <sect2><heading>Defining alternative changelog formats
9857             </heading>
9858
9859             <p>
9860               It is possible to use a different format to the standard
9861               one, by providing a parser for the format you wish to
9862               use.
9863             </p>
9864
9865             <p>
9866               In order to have <tt>dpkg-parsechangelog</tt> run your
9867               parser, you must include a line within the last 40 lines
9868               of your file matching the Perl regular expression:
9869               <tt>\schangelog-format:\s+([0-9a-z]+)\W</tt> The part in
9870               parentheses should be the name of the format.  For
9871               example, you might say:
9872               <example>
9873   @@@ changelog-format: joebloggs @@@
9874               </example>
9875               Changelog format names are non-empty strings of alphanumerics.
9876             </p>
9877
9878             <p>
9879               If such a line exists then <tt>dpkg-parsechangelog</tt>
9880               will look for the parser as
9881               <file>/usr/lib/dpkg/parsechangelog/<var>format-name</var></file>
9882               or
9883               <file>/usr/local/lib/dpkg/parsechangelog/<var>format-name</var></file>;
9884               it is an error for it not to find it, or for it not to
9885               be an executable program.  The default changelog format
9886               is <tt>dpkg</tt>, and a parser for it is provided with
9887               the <tt>dpkg</tt> package.
9888             </p>
9889
9890             <p>
9891               The parser will be invoked with the changelog open on
9892               standard input at the start of the file.  It should read
9893               the file (it may seek if it wishes) to determine the
9894               information required and return the parsed information
9895               to standard output in the form of a series of control
9896               fields in the standard format.  By default it should
9897               return information about only the most recent version in
9898               the changelog; it should accept a
9899               <tt>-v<var>version</var></tt> option to return changes
9900               information from all versions present <em>strictly
9901               after</em> <var>version</var>, and it should then be an
9902               error for <var>version</var> not to be present in the
9903               changelog.
9904             </p>
9905
9906             <p>
9907               The fields are:
9908               <list compact="compact">
9909                 <item><qref id="f-Source"><tt>Source</tt></qref></item>
9910                 <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
9911                 <item><qref id="f-Distribution"><tt>Distribution</tt></qref> (mandatory)</item>
9912                 <item><qref id="f-Urgency"><tt>Urgency</tt></qref> (mandatory)</item>
9913                 <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
9914                 <item><qref id="f-Date"><tt>Date</tt></qref></item>
9915                 <item><qref id="f-Changes"><tt>Changes</tt></qref> (mandatory)</item>
9916               </list>
9917             </p>
9918
9919             <p>
9920               If several versions are being returned (due to the use
9921               of <tt>-v</tt>), the urgency value should be of the
9922               highest urgency code listed at the start of any of the
9923               versions requested followed by the concatenated
9924               (space-separated) comments from all the versions
9925               requested; the maintainer, version, distribution and
9926               date should always be from the most recent version.
9927             </p>
9928
9929             <p>
9930               For the format of the <tt>Changes</tt> field see
9931               <ref id="f-Changes">.
9932             </p>
9933
9934             <p>
9935               If the changelog format which is being parsed always or
9936               almost always leaves a blank line between individual
9937               change notes these blank lines should be stripped out,
9938               so as to make the resulting output compact.
9939             </p>
9940
9941             <p>
9942               If the changelog format does not contain date or package
9943               name information this information should be omitted from
9944               the output.  The parser should not attempt to synthesize
9945               it or find it from other sources.
9946             </p>
9947
9948             <p>
9949               If the changelog does not have the expected format the
9950               parser should exit with a nonzero exit status, rather
9951               than trying to muddle through and possibly generating
9952               incorrect output.
9953             </p>
9954
9955             <p>
9956               A changelog parser may not interact with the user at
9957               all.
9958             </p>
9959           </sect2>
9960         </sect1>
9961
9962         <sect1 id="pkg-srcsubstvars">
9963           <heading><file>debian/substvars</file> and variable substitutions</heading>
9964
9965           <p>
9966             See <ref id="substvars">.
9967           </p>
9968
9969         </sect1>
9970
9971         <sect1>
9972           <heading><file>debian/files</file></heading>
9973
9974           <p>
9975             See <ref id="debianfiles">.
9976           </p>
9977         </sect1>
9978
9979         <sect1><heading><file>debian/tmp</file>
9980           </heading>
9981
9982           <p>
9983             This is the canonical temporary location for the
9984             construction of binary packages by the <tt>binary</tt>
9985             target.  The directory <file>tmp</file> serves as the root of
9986             the file system tree as it is being constructed (for
9987             example, by using the package's upstream makefiles install
9988             targets and redirecting the output there), and it also
9989             contains the <tt>DEBIAN</tt> subdirectory.  See <ref
9990             id="pkg-bincreating">.
9991           </p>
9992
9993           <p>
9994             If several binary packages are generated from the same
9995             source tree it is usual to use several
9996             <file>debian/tmp<var>something</var></file> directories, for
9997             example <file>tmp-a</file> or <file>tmp-doc</file>.
9998           </p>
9999
10000           <p>
10001             Whatever <file>tmp</file> directories are created and used by
10002             <tt>binary</tt> must of course be removed by the
10003             <tt>clean</tt> target.</p></sect1>
10004       </sect>
10005
10006
10007       <sect id="pkg-sourcearchives"><heading>Source packages as archives
10008         </heading>
10009
10010         <p>
10011           As it exists on the FTP site, a Debian source package
10012           consists of three related files.  You must have the right
10013           versions of all three to be able to use them.
10014         </p>
10015
10016         <p>
10017           <taglist>
10018             <tag>Debian source control file - <tt>.dsc</tt></tag>
10019             <item>
10020                 This file is a control file used by <prgn>dpkg-source</prgn>
10021                 to extract a source package.
10022                 See <ref id="debiansourcecontrolfiles">.
10023             </item>
10024
10025             <tag>
10026               Original source archive -
10027               <file>
10028                 <var>package</var>_<var>upstream-version</var>.orig.tar.gz
10029               </file>
10030             </tag>
10031
10032             <item>
10033               <p>
10034                 This is a compressed (with <tt>gzip -9</tt>)
10035                 <prgn>tar</prgn> file containing the source code from
10036                 the upstream authors of the program.
10037               </p>
10038             </item>
10039
10040             <tag>
10041               Debianisation diff -
10042               <file>
10043                 <var>package</var>_<var>upstream_version-revision</var>.diff.gz
10044               </file>
10045             </tag>
10046             <item>
10047
10048               <p>
10049                 This is a unified context diff (<tt>diff -u</tt>)
10050                 giving the changes which are required to turn the
10051                 original source into the Debian source.  These changes
10052                 may only include editing and creating plain files.
10053                 The permissions of files, the targets of symbolic
10054                 links and the characteristics of special files or
10055                 pipes may not be changed and no files may be removed
10056                 or renamed.
10057               </p>
10058
10059               <p>
10060                 All the directories in the diff must exist, except the
10061                 <file>debian</file> subdirectory of the top of the source
10062                 tree, which will be created by
10063                 <prgn>dpkg-source</prgn> if necessary when unpacking.
10064               </p>
10065
10066               <p>
10067                 The <prgn>dpkg-source</prgn> program will
10068                 automatically make the <file>debian/rules</file> file
10069                 executable (see below).</p></item>
10070           </taglist>
10071         </p>
10072
10073         <p>
10074           If there is no original source code - for example, if the
10075           package is specially prepared for Debian or the Debian
10076           maintainer is the same as the upstream maintainer - the
10077           format is slightly different: then there is no diff, and the
10078           tarfile is named
10079           <file><var>package</var>_<var>version</var>.tar.gz</file>,
10080           and preferably contains a directory named
10081           <file><var>package</var>-<var>version</var></file>.
10082         </p>
10083       </sect>
10084
10085       <sect>
10086         <heading>Unpacking a Debian source package without <prgn>dpkg-source</prgn></heading>
10087
10088         <p>
10089           <tt>dpkg-source -x</tt> is the recommended way to unpack a
10090           Debian source package.  However, if it is not available it
10091           is possible to unpack a Debian source archive as follows:
10092         <enumlist compact="compact">
10093           <item>
10094             <p>
10095               Untar the tarfile, which will create a <file>.orig</file>
10096               directory.</p>
10097           </item>
10098           <item>
10099             <p>Rename the <file>.orig</file> directory to
10100               <file><var>package</var>-<var>version</var></file>.</p>
10101           </item>
10102             <item>
10103             <p>
10104               Create the subdirectory <file>debian</file> at the top of
10105               the source tree.</p>
10106           </item>
10107           <item><p>Apply the diff using <tt>patch -p0</tt>.</p>
10108           </item>
10109           <item><p>Untar the tarfile again if you want a copy of the original
10110               source code alongside the Debianised version.</p>
10111           </item>
10112         </enumlist>
10113
10114         <p>
10115           It is not possible to generate a valid Debian source archive
10116           without using <prgn>dpkg-source</prgn>.  In particular,
10117           attempting to use <prgn>diff</prgn> directly to generate the
10118           <file>.diff.gz</file> file will not work.
10119         </p>
10120
10121         <sect1>
10122           <heading>Restrictions on objects in source packages</heading>
10123
10124           <p>
10125             The source package may not contain any hard links
10126             <footnote>
10127                 This is not currently detected when building source
10128                 packages, but only when extracting
10129                 them.
10130             </footnote>
10131             <footnote>
10132                 Hard links may be permitted at some point in the
10133                 future, but would require a fair amount of
10134                 work.
10135             </footnote>, device special files, sockets or setuid or
10136             setgid files.
10137             <footnote>
10138                 Setgid directories are allowed.
10139             </footnote>
10140           </p>
10141
10142           <p>
10143             The source packaging tools manage the changes between the
10144             original and Debianised source using <prgn>diff</prgn> and
10145             <prgn>patch</prgn>.  Turning the original source tree as
10146             included in the <file>.orig.tar.gz</file> into the debianised
10147             source must not involve any changes which cannot be
10148             handled by these tools.  Problematic changes which cause
10149             <prgn>dpkg-source</prgn> to halt with an error when
10150             building the source package are:
10151             <list compact="compact">
10152               <item><p>Adding or removing symbolic links, sockets or pipes.</p>
10153               </item>
10154               <item><p>Changing the targets of symbolic links.</p>
10155               </item>
10156               <item><p>Creating directories, other than <file>debian</file>.</p>
10157               </item>
10158               <item><p>Changes to the contents of binary files.</p></item>
10159             </list> Changes which cause <prgn>dpkg-source</prgn> to
10160             print a warning but continue anyway are:
10161             <list compact="compact">
10162               <item>
10163                 <p>
10164                   Removing files, directories or symlinks.
10165                   <footnote>
10166                       Renaming a file is not treated specially - it is
10167                       seen as the removal of the old file (which
10168                       generates a warning, but is otherwise ignored),
10169                       and the creation of the new one.
10170                   </footnote>
10171                 </p>
10172               </item>
10173               <item>
10174                 <p>
10175                   Changed text files which are missing the usual final
10176                   newline (either in the original or the modified
10177                   source tree).
10178                 </p>
10179               </item>
10180             </list>
10181             Changes which are not represented, but which are not detected by
10182             <prgn>dpkg-source</prgn>, are:
10183             <list compact="compact">
10184               <item><p>Changing the permissions of files (other than
10185                   <file>debian/rules</file>) and directories.</p></item>
10186             </list>
10187           </p>
10188
10189           <p>
10190             The <file>debian</file> directory and <file>debian/rules</file>
10191             are handled specially by <prgn>dpkg-source</prgn> - before
10192             applying the changes it will create the <file>debian</file>
10193             directory, and afterwards it will make
10194             <file>debian/rules</file> world-executable.
10195           </p>
10196         </sect1>
10197       </sect>
10198     </appendix>
10199
10200     <appendix id="pkg-controlfields">
10201       <heading>Control files and their fields (from old Packaging Manual)</heading>
10202
10203       <p>
10204         Many of the tools in the <prgn>dpkg</prgn> suite manipulate
10205         data in a common format, known as control files.  Binary and
10206         source packages have control data as do the <file>.changes</file>
10207         files which control the installation of uploaded files, and
10208         <prgn>dpkg</prgn>'s internal databases are in a similar
10209         format.
10210       </p>
10211
10212       <sect>
10213         <heading>Syntax of control files</heading>
10214
10215         <p>
10216           See <ref id="controlsyntax">.
10217         </p>
10218
10219         <p>
10220           It is important to note that there are several fields which
10221           are optional as far as <prgn>dpkg</prgn> and the related
10222           tools are concerned, but which must appear in every Debian
10223           package, or whose omission may cause problems.
10224         </p>
10225       </sect>
10226
10227       <sect>
10228         <heading>List of fields</heading>
10229
10230         <p>
10231           See <ref id="controlfieldslist">.
10232         </p>
10233
10234         <p>
10235           This section now contains only the fields that didn't belong
10236           to the Policy manual.
10237         </p>
10238
10239         <sect1 id="pkg-f-Filename">
10240           <heading><tt>Filename</tt> and <tt>MSDOS-Filename</tt></heading>
10241
10242           <p>
10243             These fields in <tt>Packages</tt> files give the
10244             filename(s) of (the parts of) a package in the
10245             distribution directories, relative to the root of the
10246             Debian hierarchy.  If the package has been split into
10247             several parts the parts are all listed in order, separated
10248             by spaces.
10249           </p>
10250         </sect1>
10251
10252         <sect1 id="pkg-f-Size">
10253           <heading><tt>Size</tt> and <tt>MD5sum</tt></heading>
10254
10255           <p>
10256             These fields in <file>Packages</file> files give the size (in
10257             bytes, expressed in decimal) and MD5 checksum of the
10258             file(s) which make(s) up a binary package in the
10259             distribution.  If the package is split into several parts
10260             the values for the parts are listed in order, separated by
10261             spaces.
10262           </p>
10263         </sect1>
10264
10265         <sect1 id="pkg-f-Status">
10266           <heading><tt>Status</tt></heading>
10267
10268           <p>
10269             This field in <prgn>dpkg</prgn>'s status file records
10270             whether the user wants a package installed, removed or
10271             left alone, whether it is broken (requiring
10272             re-installation) or not and what its current state on the
10273             system is.  Each of these pieces of information is a
10274             single word.
10275           </p>
10276         </sect1>
10277
10278         <sect1 id="pkg-f-Config-Version">
10279           <heading><tt>Config-Version</tt></heading>
10280
10281           <p>
10282             If a package is not installed or not configured, this
10283             field in <prgn>dpkg</prgn>'s status file records the last
10284             version of the package which was successfully
10285             configured.
10286           </p>
10287         </sect1>
10288
10289         <sect1 id="pkg-f-Conffiles">
10290           <heading><tt>Conffiles</tt></heading>
10291
10292           <p>
10293             This field in <prgn>dpkg</prgn>'s status file contains
10294             information about the automatically-managed configuration
10295             files held by a package.  This field should <em>not</em>
10296             appear anywhere in a package!
10297           </p>
10298         </sect1>
10299
10300         <sect1>
10301           <heading>Obsolete fields</heading>
10302
10303           <p>
10304             These are still recognized by <prgn>dpkg</prgn> but should
10305             not appear anywhere any more.
10306
10307             <taglist compact="compact">
10308
10309               <tag><tt>Revision</tt></tag>
10310               <tag><tt>Package-Revision</tt></tag>
10311               <tag><tt>Package_Revision</tt></tag>
10312               <item>
10313                   The Debian revision part of the package version was
10314                   at one point in a separate control file field.  This
10315                   field went through several names.
10316               </item>
10317
10318               <tag><tt>Recommended</tt></tag>
10319               <item>Old name for <tt>Recommends</tt>.</item>
10320
10321               <tag><tt>Optional</tt></tag>
10322               <item>Old name for <tt>Suggests</tt>.</item>
10323
10324               <tag><tt>Class</tt></tag>
10325               <item>Old name for <tt>Priority</tt>.</item>
10326
10327             </taglist>
10328           </p>
10329         </sect1>
10330       </sect>
10331
10332     </appendix>
10333
10334     <appendix id="pkg-conffiles">
10335       <heading>Configuration file handling (from old Packaging Manual)</heading>
10336
10337       <p>
10338         <prgn>dpkg</prgn> can do a certain amount of automatic
10339         handling of package configuration files.
10340       </p>
10341
10342       <p>
10343         Whether this mechanism is appropriate depends on a number of
10344         factors, but basically there are two approaches to any
10345         particular configuration file.
10346       </p>
10347
10348       <p>
10349         The easy method is to ship a best-effort configuration in the
10350         package, and use <prgn>dpkg</prgn>'s conffile mechanism to
10351         handle updates.  If the user is unlikely to want to edit the
10352         file, but you need them to be able to without losing their
10353         changes, and a new package with a changed version of the file
10354         is only released infrequently, this is a good approach.
10355       </p>
10356
10357       <p>
10358         The hard method is to build the configuration file from
10359         scratch in the <prgn>postinst</prgn> script, and to take the
10360         responsibility for fixing any mistakes made in earlier
10361         versions of the package automatically.  This will be
10362         appropriate if the file is likely to need to be different on
10363         each system.
10364       </p>
10365
10366       <sect><heading>Automatic handling of configuration files by
10367       <prgn>dpkg</prgn>
10368         </heading>
10369
10370         <p>
10371           A package may contain a control area file called
10372           <tt>conffiles</tt>.  This file should be a list of filenames
10373           of configuration files needing automatic handling, separated
10374           by newlines.  The filenames should be absolute pathnames,
10375           and the files referred to should actually exist in the
10376           package.
10377         </p>
10378
10379         <p>
10380           When a package is upgraded <prgn>dpkg</prgn> will process
10381           the configuration files during the configuration stage,
10382           shortly before it runs the package's <prgn>postinst</prgn>
10383           script,
10384         </p>
10385
10386         <p>
10387           For each file it checks to see whether the version of the
10388           file included in the package is the same as the one that was
10389           included in the last version of the package (the one that is
10390           being upgraded from); it also compares the version currently
10391           installed on the system with the one shipped with the last
10392           version.
10393         </p>
10394
10395         <p>
10396           If neither the user nor the package maintainer has changed
10397           the file, it is left alone.  If one or the other has changed
10398           their version, then the changed version is preferred - i.e.,
10399           if the user edits their file, but the package maintainer
10400           doesn't ship a different version, the user's changes will
10401           stay, silently, but if the maintainer ships a new version
10402           and the user hasn't edited it the new version will be
10403           installed (with an informative message).  If both have
10404           changed their version the user is prompted about the problem
10405           and must resolve the differences themselves.
10406         </p>
10407
10408         <p>
10409           The comparisons are done by calculating the MD5 message
10410           digests of the files, and storing the MD5 of the file as it
10411           was included in the most recent version of the package.
10412         </p>
10413
10414         <p>
10415           When a package is installed for the first time
10416           <prgn>dpkg</prgn> will install the file that comes with it,
10417           unless that would mean overwriting a file already on the
10418           file system.
10419         </p>
10420
10421         <p>
10422           However, note that <prgn>dpkg</prgn> will <em>not</em>
10423           replace a conffile that was removed by the user (or by a
10424           script).  This is necessary because with some programs a
10425           missing file produces an effect hard or impossible to
10426           achieve in another way, so that a missing file needs to be
10427           kept that way if the user did it.
10428         </p>
10429
10430         <p>
10431           Note that a package should <em>not</em> modify a
10432           <prgn>dpkg</prgn>-handled conffile in its maintainer
10433           scripts.  Doing this will lead to <prgn>dpkg</prgn> giving
10434           the user confusing and possibly dangerous options for
10435           conffile update when the package is upgraded.</p>
10436       </sect>
10437
10438       <sect><heading>Fully-featured maintainer script configuration
10439       handling
10440         </heading>
10441
10442         <p>
10443           For files which contain site-specific information such as
10444           the hostname and networking details and so forth, it is
10445           better to create the file in the package's
10446           <prgn>postinst</prgn> script.
10447         </p>
10448
10449         <p>
10450           This will typically involve examining the state of the rest
10451           of the system to determine values and other information, and
10452           may involve prompting the user for some information which
10453           can't be obtained some other way.
10454         </p>
10455
10456         <p>
10457           When using this method there are a couple of important
10458           issues which should be considered:
10459         </p>
10460
10461         <p>
10462           If you discover a bug in the program which generates the
10463           configuration file, or if the format of the file changes
10464           from one version to the next, you will have to arrange for
10465           the postinst script to do something sensible - usually this
10466           will mean editing the installed configuration file to remove
10467           the problem or change the syntax.  You will have to do this
10468           very carefully, since the user may have changed the file,
10469           perhaps to fix the very problem that your script is trying
10470           to deal with - you will have to detect these situations and
10471           deal with them correctly.
10472         </p>
10473
10474         <p>
10475           If you do go down this route it's probably a good idea to
10476           make the program that generates the configuration file(s) a
10477           separate program in <file>/usr/sbin</file>, by convention called
10478           <file><var>package</var>config</file> and then run that if
10479           appropriate from the post-installation script.  The
10480           <tt><var>package</var>config</tt> program should not
10481           unquestioningly overwrite an existing configuration - if its
10482           mode of operation is geared towards setting up a package for
10483           the first time (rather than any arbitrary reconfiguration
10484           later) you should have it check whether the configuration
10485           already exists, and require a <tt>--force</tt> flag to
10486           overwrite it.</p></sect>
10487     </appendix>
10488
10489     <appendix id="pkg-alternatives"><heading>Alternative versions of
10490         an interface - <prgn>update-alternatives</prgn> (from old
10491     Packaging Manual)
10492       </heading>
10493
10494       <p>
10495         When several packages all provide different versions of the
10496         same program or file it is useful to have the system select a
10497         default, but to allow the system administrator to change it
10498         and have their decisions respected.
10499       </p>
10500
10501       <p>
10502         For example, there are several versions of the <prgn>vi</prgn>
10503         editor, and there is no reason to prevent all of them from
10504         being installed at once, each under their own name
10505         (<prgn>nvi</prgn>, <prgn>vim</prgn> or whatever).
10506         Nevertheless it is desirable to have the name <tt>vi</tt>
10507         refer to something, at least by default.
10508       </p>
10509
10510       <p>
10511         If all the packages involved cooperate, this can be done with
10512         <prgn>update-alternatives</prgn>.
10513       </p>
10514
10515       <p>
10516         Each package provides its own version under its own name, and
10517         calls <prgn>update-alternatives</prgn> in its postinst to
10518         register its version (and again in its prerm to deregister
10519         it).
10520       </p>
10521
10522       <p>
10523         See the man page <manref name="update-alternatives"
10524         section="8"> for details.
10525       </p>
10526
10527       <p>
10528         If <prgn>update-alternatives</prgn> does not seem appropriate
10529         you may wish to consider using diversions instead.</p>
10530     </appendix>
10531
10532     <appendix id="pkg-diversions"><heading>Diversions - overriding a
10533     package's version of a file (from old Packaging Manual)
10534       </heading>
10535
10536       <p>
10537         It is possible to have <prgn>dpkg</prgn> not overwrite a file
10538         when it reinstalls the package it belongs to, and to have it
10539         put the file from the package somewhere else instead.
10540       </p>
10541
10542       <p>
10543         This can be used locally to override a package's version of a
10544         file, or by one package to override another's version (or
10545         provide a wrapper for it).
10546       </p>
10547
10548       <p>
10549         Before deciding to use a diversion, read <ref
10550         id="pkg-alternatives"> to see if you really want a diversion
10551         rather than several alternative versions of a program.
10552       </p>
10553
10554       <p>
10555         There is a diversion list, which is read by <prgn>dpkg</prgn>,
10556         and updated by a special program <prgn>dpkg-divert</prgn>.
10557         Please see <manref name="dpkg-divert" section="8"> for full
10558         details of its operation.
10559       </p>
10560
10561       <p>
10562         When a package wishes to divert a file from another, it should
10563         call <prgn>dpkg-divert</prgn> in its preinst to add the
10564         diversion and rename the existing file.  For example,
10565         supposing that a <prgn>smailwrapper</prgn> package wishes to
10566         install a wrapper around <file>/usr/sbin/smail</file>:
10567         <example>
10568   if [ install = "$1"  ]; then
10569      dpkg-divert --package smailwrapper --add --rename \
10570         --divert /usr/sbin/smail.real /usr/sbin/smail
10571   fi
10572         </example> Testing <tt>$1</tt> is necessary so that the script
10573         doesn't try to add the diversion again when
10574         <prgn>smailwrapper</prgn> is upgraded.  The <tt>--package
10575         smailwrapper</tt> ensures that <prgn>smailwrapper</prgn>'s
10576         copy of <file>/usr/sbin/smail</file> can bypass the diversion and
10577         get installed as the true version.
10578       </p>
10579
10580       <p>
10581         The postrm has to do the reverse:
10582         <example>
10583   if [ remove = "$1" ]; then
10584      dpkg-divert --package smailwrapper --remove --rename \
10585         --divert /usr/sbin/smail.real /usr/sbin/smail
10586   fi
10587         </example>
10588       </p>
10589
10590       <p>
10591         Do not attempt to divert a file which is vitally important for
10592         the system's operation - when using <prgn>dpkg-divert</prgn>
10593         there is a time, after it has been diverted but before
10594         <prgn>dpkg</prgn> has installed the new version, when the file
10595         does not exist.</p>
10596     </appendix>
10597
10598   </book>
10599 </debiandoc>
10600 <!-- Local variables: -->
10601 <!-- indent-tabs-mode: t -->
10602 <!-- End: -->
10603 <!-- vim:set ai et sts=2 sw=2 tw=76: -->