]> git.donarmstrong.com Git - debian/debian-policy.git/blob - policy.sgml
Merge branch 'master' into bug473439-rra
[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 components<footnote>
323           The Debian archive software uses the term "component" internally
324           and in the Release file format to refer to the division of an
325           archive.  The Debian Social Contract refers to distribution
326           areas.  This document uses the same terminology as the Social
327           Contract.
328         </footnote> based on their licenses and other restrictions.
329       </p>
330
331       <p>
332         The aims of this are:
333
334         <list compact="compact">
335           <item>to allow us to make as much software available as we can</item>
336           <item>to allow us to encourage everyone to write free software,
337                 and</item>
338           <item>to allow us to make it easy for people to produce
339                 CD-ROMs of our system without violating any licenses,
340                 import/export restrictions, or any other laws.</item>
341         </list>
342       </p>
343
344       <p>
345         The <em>main</em> distribution area forms the <em>Debian GNU/Linux
346         distribution</em>.
347       </p>
348
349       <p>
350         Packages in the other distribution areas (<tt>contrib</tt>,
351         <tt>non-free</tt>) are not considered to be part of the Debian
352         distribution, although we support their use and provide
353         infrastructure for them (such as our bug-tracking system and
354         mailing lists). This Debian Policy Manual applies to these
355         packages as well.
356       </p>
357
358       <sect id="dfsg">
359         <heading>The Debian Free Software Guidelines</heading>
360         <p>
361           The Debian Free Software Guidelines (DFSG) form our
362           definition of "free software".  These are:
363             <taglist>
364               <tag>Free Redistribution
365               </tag>
366               <item>
367                   The license of a Debian component may not restrict any
368                   party from selling or giving away the software as a
369                   component of an aggregate software distribution
370                   containing programs from several different
371                   sources. The license may not require a royalty or
372                   other fee for such sale.
373               </item>
374               <tag>Source Code
375               </tag>
376               <item>
377                   The program must include source code, and must allow
378                   distribution in source code as well as compiled form.
379               </item>
380               <tag>Derived Works
381               </tag>
382               <item>
383                   The license must allow modifications and derived
384                   works, and must allow them to be distributed under the
385                   same terms as the license of the original software.
386               </item>
387               <tag>Integrity of The Author's Source Code
388               </tag>
389               <item>
390                   The license may restrict source-code from being
391                   distributed in modified form <em>only</em> if the
392                   license allows the distribution of "patch files"
393                   with the source code for the purpose of modifying the
394                   program at build time. The license must explicitly
395                   permit distribution of software built from modified
396                   source code. The license may require derived works to
397                   carry a different name or version number from the
398                   original software.  (This is a compromise. The Debian
399                   Project encourages all authors to not restrict any
400                   files, source or binary, from being modified.)
401               </item>
402               <tag>No Discrimination Against Persons or Groups
403               </tag>
404               <item>
405                   The license must not discriminate against any person
406                   or group of persons.
407               </item>
408               <tag>No Discrimination Against Fields of Endeavor
409               </tag>
410               <item>
411                   The license must not restrict anyone from making use
412                   of the program in a specific field of endeavor. For
413                   example, it may not restrict the program from being
414                   used in a business, or from being used for genetic
415                   research.
416               </item>
417               <tag>Distribution of License
418               </tag>
419               <item>
420                   The rights attached to the program must apply to all
421                   to whom the program is redistributed without the need
422                   for execution of an additional license by those
423                   parties.
424               </item>
425               <tag>License Must Not Be Specific to Debian
426               </tag>
427               <item>
428                   The rights attached to the program must not depend on
429                   the program's being part of a Debian system. If the
430                   program is extracted from Debian and used or
431                   distributed without Debian but otherwise within the
432                   terms of the program's license, all parties to whom
433                   the program is redistributed must have the same
434                   rights as those that are granted in conjunction with
435                   the Debian system.
436               </item>
437               <tag>License Must Not Contaminate Other Software
438               </tag>
439               <item>
440                   The license must not place restrictions on other
441                   software that is distributed along with the licensed
442                   software. For example, the license must not insist
443                   that all other programs distributed on the same medium
444                   must be free software.
445               </item>
446               <tag>Example Licenses
447               </tag>
448               <item>
449                   The "GPL," "BSD," and "Artistic" licenses are examples of
450                   licenses that we consider <em>free</em>.
451               </item>
452             </taglist>
453         </p>
454       </sect>
455
456       <sect id="sections">
457         <heading>Distribution areas</heading>
458
459         <sect1 id="main">
460           <heading>The main distribution area</heading>
461
462           <p>
463             Every package in <em>main</em> must comply with the DFSG
464             (Debian Free Software Guidelines).
465           </p>
466
467           <p>
468             In addition, the packages in <em>main</em>
469             <list compact="compact">
470               <item>
471                   must not require a package outside of <em>main</em>
472                   for compilation or execution (thus, the package must
473                   not declare a "Depends", "Recommends", or
474                   "Build-Depends" relationship on a non-<em>main</em>
475                   package),
476               </item>
477               <item>
478                   must not be so buggy that we refuse to support them,
479                   and
480               </item>
481               <item>
482                   must meet all policy requirements presented in this
483                   manual.
484               </item>
485             </list>
486           </p>
487
488         </sect1>
489
490         <sect1 id="contrib">
491           <heading>The contrib distribution area</heading>
492
493           <p>
494             Every package in <em>contrib</em> must comply with the DFSG.
495           </p>
496
497           <p>
498             In addition, the packages in <em>contrib</em>
499             <list compact="compact">
500               <item>
501                   must not be so buggy that we refuse to support them,
502                   and
503               </item>
504               <item>
505                   must meet all policy requirements presented in this
506                   manual.
507               </item>
508             </list>
509           </p>
510
511
512           <p>
513             Examples of packages which would be included in
514             <em>contrib</em> are:
515             <list compact="compact">
516               <item>
517                   free packages which require <em>contrib</em>,
518                   <em>non-free</em> packages or packages which are not
519                   in our archive at all for compilation or execution,
520                   and
521               </item>
522               <item>
523                   wrapper packages or other sorts of free accessories for
524                   non-free programs.
525               </item>
526             </list>
527           </p>
528         </sect1>
529
530         <sect1 id="non-free">
531           <heading>The non-free distribution area</heading>
532
533           <p>
534             Packages must be placed in <em>non-free</em> if they are
535             not compliant with the DFSG or are encumbered by patents
536             or other legal issues that make their distribution
537             problematic.
538           </p>
539
540           <p>
541             In addition, the packages in <em>non-free</em>
542             <list compact="compact">
543               <item>
544                   must not be so buggy that we refuse to support them,
545                   and
546               </item>
547               <item>
548                   must meet all policy requirements presented in this
549                   manual that it is possible for them to meet.
550                   <footnote>
551                       It is possible that there are policy
552                       requirements which the package is unable to
553                       meet, for example, if the source is
554                       unavailable.  These situations will need to be
555                       handled on a case-by-case basis.
556                   </footnote>
557               </item>
558             </list>
559           </p>
560         </sect1>
561
562       </sect>
563
564       <sect id="pkgcopyright">
565         <heading>Copyright considerations</heading>
566
567         <p>
568           Every package must be accompanied by a verbatim copy of
569           its copyright and distribution license in the file
570           <file>/usr/share/doc/<var>package</var>/copyright</file>
571           (see <ref id="copyrightfile"> for further details).
572         </p>
573
574         <p>
575           We reserve the right to restrict files from being included
576           anywhere in our archives if
577           <list compact="compact">
578             <item>
579                   their use or distribution would break a law,
580             </item>
581             <item>
582                   there is an ethical conflict in their distribution or
583                   use,
584             </item>
585             <item>
586                   we would have to sign a license for them, or
587             </item>
588             <item>
589                   their distribution would conflict with other project
590                   policies.
591             </item>
592           </list>
593         </p>
594
595         <p>
596           Programs whose authors encourage the user to make
597           donations are fine for the main distribution, provided
598           that the authors do not claim that not donating is
599           immoral, unethical, illegal or something similar; in such
600           a case they must go in <em>non-free</em>.
601         </p>
602
603         <p>
604           Packages whose copyright permission notices (or patent
605           problems) do not even allow redistribution of binaries
606           only, and where no special permission has been obtained,
607           must not be placed on the Debian FTP site and its mirrors
608           at all.
609         </p>
610
611         <p>
612           Note that under international copyright law (this applies
613           in the United States, too), <em>no</em> distribution or
614           modification of a work is allowed without an explicit
615           notice saying so.  Therefore a program without a copyright
616           notice <em>is</em> copyrighted and you may not do anything
617           to it without risking being sued! Likewise if a program
618           has a copyright notice but no statement saying what is
619           permitted then nothing is permitted.
620         </p>
621
622         <p>
623           Many authors are unaware of the problems that restrictive
624           copyrights (or lack of copyright notices) can cause for
625           the users of their supposedly-free software.  It is often
626           worthwhile contacting such authors diplomatically to ask
627           them to modify their license terms. However, this can be a
628           politically difficult thing to do and you should ask for
629           advice on the <tt>debian-legal</tt> mailing list first, as
630           explained below.
631         </p>
632
633         <p>
634           When in doubt about a copyright, send mail to
635           <email>debian-legal@lists.debian.org</email>.  Be prepared
636           to provide us with the copyright statement.  Software
637           covered by the GPL, public domain software and BSD-like
638           copyrights are safe; be wary of the phrases "commercial
639           use prohibited" and "distribution restricted".
640         </p>
641       </sect>
642
643       <sect id="subsections">
644         <heading>Sections</heading>
645
646         <p>
647           The packages in the distribution areas <em>main</em>,
648           <em>contrib</em> and <em>non-free</em> are grouped further
649           into <em>sections</em> to simplify handling.
650         </p>
651
652         <p>
653           The distribution area and section for each package should be
654           specified in the package's <tt>Section</tt> control record
655           (see <ref id="f-Section">).  However, the maintainer of the
656           Debian archive may override this selection to ensure the
657           consistency of the Debian distribution.  The
658           <tt>Section</tt> field should be of the form:
659           <list compact="compact">
660             <item>
661                   <em>section</em> if the package is in the
662                   <em>main</em> distribution area,
663             </item>
664             <item>
665                   <em>area/section</em> if the package is in
666                   the <em>contrib</em> or <em>non-free</em>
667                   distribution areas.
668             </item>
669           </list>
670         </p>
671
672         <p>
673           The Debian archive maintainers provide the authoritative
674           list of sections.  At present, they are:
675           <em>admin</em>, <em>comm</em>,
676           <em>devel</em>, <em>doc</em>,
677           <em>editors</em>, <em>electronics</em>, <em>embedded</em>,
678           <em>games</em>, <em>gnome</em>, <em>graphics</em>,
679           <em>hamradio</em>, <em>interpreters</em>, <em>kde</em>,
680           <em>libs</em>, <em>libdevel</em>, <em>mail</em>,
681           <em>math</em>, <em>misc</em>, <em>net</em>, <em>news</em>,
682           <em>oldlibs</em>,
683           <em>otherosfs</em>, <em>perl</em>, <em>python</em>,
684           <em>science</em>, <em>shells</em>,
685           <em>sound</em>, <em>tex</em>, <em>text</em>,
686           <em>utils</em>, <em>web</em>, <em>x11</em>.
687         </p>
688       </sect>
689
690       <sect id="priorities">
691         <heading>Priorities</heading>
692
693         <p>
694           Each package should have a <em>priority</em> value, which is
695           included in the package's <em>control record</em>
696           (see <ref id="f-Priority">).
697           This information is used by the Debian package management tools to
698           separate high-priority packages from less-important packages.
699         </p>
700
701         <p>
702           The following <em>priority levels</em> are recognized by the
703           Debian package management tools.
704           <taglist>
705             <tag><tt>required</tt></tag>
706             <item>
707                 Packages which are necessary for the proper
708                 functioning of the system (usually, this means that
709                 dpkg functionality depends on these packages).
710                 Removing a <tt>required</tt> package may cause your
711                 system to become totally broken and you may not even
712                 be able to use <prgn>dpkg</prgn> to put things back,
713                 so only do so if you know what you are doing.  Systems
714                 with only the <tt>required</tt> packages are probably
715                 unusable, but they do have enough functionality to
716                 allow the sysadmin to boot and install more software.
717             </item>
718             <tag><tt>important</tt></tag>
719             <item>
720                 Important programs, including those which one would
721                 expect to find on any Unix-like system.  If the
722                 expectation is that an experienced Unix person who
723                 found it missing would say "What on earth is going on,
724                 where is <prgn>foo</prgn>?", it must be an
725                 <tt>important</tt> package.<footnote>
726                     This is an important criterion because we are
727                     trying to produce, amongst other things, a free
728                     Unix.
729                 </footnote>
730                 Other packages without which the system will not run
731                 well or be usable must also have priority
732                 <tt>important</tt>.  This does
733                 <em>not</em> include Emacs, the X Window System, TeX
734                 or any other large applications.  The
735                 <tt>important</tt> packages are just a bare minimum of
736                 commonly-expected and necessary tools.
737             </item>
738             <tag><tt>standard</tt></tag>
739             <item>
740                 These packages provide a reasonably small but not too
741                 limited character-mode system.  This is what will be
742                 installed by default if the user doesn't select anything
743                 else.  It doesn't include many large applications.
744             </item>
745             <tag><tt>optional</tt></tag>
746             <item>
747                 (In a sense everything that isn't required is
748                 optional, but that's not what is meant here.) This is
749                 all the software that you might reasonably want to
750                 install if you didn't know what it was and don't have
751                 specialized requirements. This is a much larger system
752                 and includes the X Window System, a full TeX
753                 distribution, and many applications. Note that
754                 optional packages should not conflict with each other.
755             </item>
756             <tag><tt>extra</tt></tag>
757             <item>
758                 This contains all packages that conflict with others
759                 with required, important, standard or optional
760                 priorities, or are only likely to be useful if you
761                 already know what they are or have specialized
762                 requirements (such as packages containing only detached
763                 debugging symbols).
764             </item>
765           </taglist>
766         </p>
767
768         <p>
769           Packages must not depend on packages with lower priority
770           values (excluding build-time dependencies).  In order to
771           ensure this, the priorities of one or more packages may need
772           to be adjusted.
773         </p>
774       </sect>
775
776     </chapt>
777
778
779     <chapt id="binary">
780       <heading>Binary packages</heading>
781
782       <p>
783         The Debian GNU/Linux distribution is based on the Debian
784         package management system, called <prgn>dpkg</prgn>. Thus,
785         all packages in the Debian distribution must be provided
786         in the <tt>.deb</tt> file format.
787       </p>
788
789       <sect>
790         <heading>The package name</heading>
791
792         <p>
793           Every package must have a name that's unique within the Debian
794           archive.
795         </p>
796
797         <p>
798           The package name is included in the control field
799           <tt>Package</tt>, the format of which is described
800           in <ref id="f-Package">.
801           The package name is also included as a part of the file name
802           of the <tt>.deb</tt> file.
803         </p>
804       </sect>
805
806       <sect id="versions">
807         <heading>The version of a package</heading>
808
809         <p>
810           Every package has a version number recorded in its
811           <tt>Version</tt> control file field, described in
812           <ref id="f-Version">.
813         </p>
814
815         <p>
816           The package management system imposes an ordering on version
817           numbers, so that it can tell whether packages are being up- or
818           downgraded and so that package system front end applications
819           can tell whether a package it finds available is newer than
820           the one installed on the system.  The version number format
821           has the most significant parts (as far as comparison is
822           concerned) at the beginning.
823         </p>
824
825         <p>
826           If an upstream package has problematic version numbers they
827           should be converted to a sane form for use in the
828           <tt>Version</tt> field.
829         </p>
830
831         <sect1>
832           <heading>Version numbers based on dates</heading>
833
834           <p>
835             In general, Debian packages should use the same version
836             numbers as the upstream sources.
837           </p>
838
839           <p>
840             However, in some cases where the upstream version number is
841             based on a date (e.g., a development "snapshot" release) the
842             package management system cannot handle these version
843             numbers without epochs. For example, dpkg will consider
844             "96May01" to be greater than "96Dec24".
845           </p>
846
847           <p>
848             To prevent having to use epochs for every new upstream
849             version, the date based portion of the version number
850             should be changed to the following format in such cases:
851             "19960501", "19961224". It is up to the maintainer whether
852             they want to bother the upstream maintainer to change
853             the version numbers upstream, too.
854           </p>
855
856           <p>
857             Note that other version formats based on dates which are
858             parsed correctly by the package management system should
859             <em>not</em> be changed.
860           </p>
861
862           <p>
863             Native Debian packages (i.e., packages which have been
864             written especially for Debian) whose version numbers include
865             dates should always use the "YYYYMMDD" format.
866           </p>
867         </sect1>
868
869       </sect>
870
871       <sect>
872         <heading>The maintainer of a package</heading>
873
874         <p>
875           Every package must have a Debian maintainer (the
876           maintainer may be one person or a group of people
877           reachable from a common email address, such as a mailing
878           list).  The maintainer is responsible for ensuring that
879           the package is placed in the appropriate distributions.
880         </p>
881
882         <p>
883           The maintainer must be specified in the
884           <tt>Maintainer</tt> control field with their correct name
885           and a working email address.  If one person maintains
886           several packages, they should try to avoid having
887           different forms of their name and email address in
888           the <tt>Maintainer</tt> fields of those packages.
889         </p>
890
891         <p>
892           The format of the <tt>Maintainer</tt> control field is
893           described in <ref id="f-Maintainer">.
894         </p>
895
896         <p>
897           If the maintainer of a package quits from the Debian
898           project, "Debian QA Group"
899           <email>packages@qa.debian.org</email> takes over the
900           maintainer-ship of the package until someone else
901           volunteers for that task. These packages are called
902           <em>orphaned packages</em>.<footnote>
903                 The detailed procedure for doing this gracefully can
904                 be found in the Debian Developer's Reference,
905                 see <ref id="related">.
906           </footnote>
907         </p>
908       </sect>
909
910       <sect id="descriptions">
911         <heading>The description of a package</heading>
912
913         <p>
914           Every Debian package must have an extended description
915           stored in the appropriate field of the control record.
916           The technical information about the format of the
917           <tt>Description</tt> field is in <ref id="f-Description">.
918         </p>
919
920         <p>
921           The description should describe the package (the program) to a
922           user (system administrator) who has never met it before so that
923           they have enough information to decide whether they want to
924           install it. This description should not just be copied verbatim
925           from the program's documentation.
926         </p>
927
928         <p>
929           Put important information first, both in the synopsis and
930           extended description.  Sometimes only the first part of the
931           synopsis or of the description will be displayed.  You can
932           assume that there will usually be a way to see the whole
933           extended description.
934         </p>
935
936         <p>
937           The description should also give information about the
938           significant dependencies and conflicts between this package
939           and others, so that the user knows why these dependencies and
940           conflicts have been declared.
941         </p>
942
943         <p>
944           Instructions for configuring or using the package should
945           not be included (that is what installation scripts,
946           manual pages, info files, etc., are for).  Copyright
947           statements and other administrivia should not be included
948           either (that is what the copyright file is for).
949         </p>
950
951         <sect1 id="synopsis"><heading>The single line synopsis</heading>
952
953           <p>
954             The single line synopsis should be kept brief - certainly
955             under 80 characters.
956           </p>
957
958           <p>
959             Do not include the package name in the synopsis line.  The
960             display software knows how to display this already, and you
961             do not need to state it.  Remember that in many situations
962             the user may only see the synopsis line - make it as
963             informative as you can.
964           </p>
965
966         </sect1>
967
968         <sect1 id="extendeddesc"><heading>The extended description</heading>
969
970           <p>
971             Do not try to continue the single line synopsis into the
972             extended description.  This will not work correctly when
973             the full description is displayed, and makes no sense
974             where only the summary (the single line synopsis) is
975             available.
976           </p>
977
978           <p>
979             The extended description should describe what the package
980             does and how it relates to the rest of the system (in terms
981             of, for example, which subsystem it is which part of).
982           </p>
983
984           <p>
985             The description field needs to make sense to anyone, even
986             people who have no idea about any of the things the
987             package deals with.<footnote>
988                 The blurb that comes with a program in its
989                 announcements and/or <prgn>README</prgn> files is
990                 rarely suitable for use in a description.  It is
991                 usually aimed at people who are already in the
992                 community where the package is used.
993             </footnote>
994           </p>
995
996         </sect1>
997
998       </sect>
999
1000       <sect>
1001         <heading>Dependencies</heading>
1002
1003         <p>
1004           Every package must specify the dependency information
1005           about other packages that are required for the first to
1006           work correctly.
1007         </p>
1008
1009         <p>
1010           For example, a dependency entry must be provided for any
1011           shared libraries required by a dynamically-linked executable
1012           binary in a package.
1013         </p>
1014
1015         <p>
1016           Packages are not required to declare any dependencies they
1017           have on other packages which are marked <tt>Essential</tt>
1018           (see below), and should not do so unless they depend on a
1019           particular version of that package.<footnote>
1020             <p>
1021               Essential is needed in part to avoid unresolvable dependency
1022               loops on upgrade.  If packages add unnecessary dependencies
1023               on packages in this set, the chances that there
1024               <strong>will</strong> be an unresolvable dependency loop
1025               caused by forcing these Essential packages to be configured
1026               first before they need to be is greatly increased.  It also
1027               increases the chances that frontends will be unable to
1028               <strong>calculate</strong> an upgrade path, even if one
1029               exists.
1030             </p>
1031             <p>
1032               Also, functionality is rarely ever removed from the
1033               Essential set, but <em>packages</em> have been removed from
1034               the Essential set when the functionality moved to a
1035               different package. So depending on these packages <em>just
1036               in case</em> they stop being essential does way more harm
1037               than good.
1038             </p>
1039           </footnote>
1040         </p>
1041
1042         <p>
1043           Sometimes, a package requires another package to be installed
1044           <em>and</em> configured before it can be installed. In this
1045           case, you must specify a <tt>Pre-Depends</tt> entry for
1046           the package.
1047         </p>
1048
1049         <p>
1050           You should not specify a <tt>Pre-Depends</tt> entry for a
1051           package before this has been discussed on the
1052           <tt>debian-devel</tt> mailing list and a consensus about
1053           doing that has been reached.
1054         </p>
1055
1056         <p>
1057           The format of the package interrelationship control fields is
1058           described in <ref id="relationships">.
1059         </p>
1060       </sect>
1061
1062       <sect id="virtual_pkg">
1063         <heading>Virtual packages</heading>
1064
1065         <p>
1066           Sometimes, there are several packages which offer
1067           more-or-less the same functionality. In this case, it's
1068           useful to define a <em>virtual package</em> whose name
1069           describes that common functionality.  (The virtual
1070           packages only exist logically, not physically; that's why
1071           they are called <em>virtual</em>.) The packages with this
1072           particular function will then <em>provide</em> the virtual
1073           package. Thus, any other package requiring that function
1074           can simply depend on the virtual package without having to
1075           specify all possible packages individually.
1076         </p>
1077
1078         <p>
1079           All packages should use virtual package names where
1080           appropriate, and arrange to create new ones if necessary.
1081           They should not use virtual package names (except privately,
1082           amongst a cooperating group of packages) unless they have
1083           been agreed upon and appear in the list of virtual package
1084           names. (See also <ref id="virtual">)
1085         </p>
1086
1087         <p>
1088           The latest version of the authoritative list of virtual
1089           package names can be found in the <tt>debian-policy</tt> package.
1090           It is also available from the Debian web mirrors at
1091           <tt><url name="/doc/packaging-manuals/virtual-package-names-list.txt"
1092                 id="http://www.debian.org/doc/packaging-manuals/virtual-package-names-list.txt"></tt>.
1093         </p>
1094
1095         <p>
1096           The procedure for updating the list is described in the preface
1097           to the list.
1098         </p>
1099
1100       </sect>
1101
1102       <sect>
1103         <heading>Base system</heading>
1104
1105         <p>
1106           The <tt>base system</tt> is a minimum subset of the Debian
1107           GNU/Linux system that is installed before everything else
1108           on a new system. Only very few packages are allowed to form
1109           part of the base system, in order to keep the required disk
1110           usage very small.
1111         </p>
1112
1113         <p>
1114           The base system consists of all those packages with priority
1115           <tt>required</tt> or <tt>important</tt>. Many of them will
1116           be tagged <tt>essential</tt> (see below).
1117         </p>
1118       </sect>
1119
1120       <sect>
1121         <heading>Essential packages</heading>
1122
1123         <p>
1124           Essential is defined as the minimal set of functionality that
1125           must be available and usable on the system at all times, even
1126           when packages are in an unconfigured (but unpacked) state.
1127           Packages are tagged <tt>essential</tt> for a system using the
1128           <tt>Essential</tt> control file field.  The format of the
1129           <tt>Essential</tt> control field is described in <ref
1130           id="f-Essential">.
1131         </p>
1132
1133         <p>
1134           Since these packages cannot be easily removed (one has to
1135           specify an extra <em>force option</em> to
1136           <prgn>dpkg</prgn> to do so), this flag must not be used
1137           unless absolutely necessary.  A shared library package
1138           must not be tagged <tt>essential</tt>; dependencies will
1139           prevent its premature removal, and we need to be able to
1140           remove it when it has been superseded.
1141         </p>
1142
1143         <p>
1144           Since dpkg will not prevent upgrading of other packages
1145           while an <tt>essential</tt> package is in an unconfigured
1146             state, all <tt>essential</tt> packages must supply all of
1147             their core functionality even when unconfigured. If the
1148             package cannot satisfy this requirement it must not be
1149             tagged as essential, and any packages depending on this
1150             package must instead have explicit dependency fields as
1151             appropriate.
1152         </p>
1153
1154         <p>
1155           Maintainers should take great care in adding any programs,
1156           interfaces, or functionality to <tt>essential</tt> packages.
1157           Packages may assume that functionality provided by
1158           <tt>essential</tt> packages is always available without
1159           declaring explicit dependencies, which means that removing
1160           functionality from the Essential set is very difficult and is
1161           almost never done.  Any capability added to an
1162           <tt>essential</tt> package therefore creates an obligation to
1163           support that capability as part of the Essential set in
1164           perpetuity.
1165         </p>
1166
1167         <p>
1168           You must not tag any packages <tt>essential</tt> before
1169           this has been discussed on the <tt>debian-devel</tt>
1170           mailing list and a consensus about doing that has been
1171           reached.
1172         </p>
1173       </sect>
1174
1175       <sect id="maintscripts">
1176         <heading>Maintainer Scripts</heading>
1177
1178         <p>
1179           The package installation scripts should avoid producing
1180           output which is unnecessary for the user to see and
1181           should rely on <prgn>dpkg</prgn> to stave off boredom on
1182           the part of a user installing many packages.  This means,
1183           amongst other things, using the <tt>--quiet</tt> option on
1184           <prgn>install-info</prgn>.
1185         </p>
1186
1187         <p>
1188           Errors which occur during the execution of an installation
1189           script must be checked and the installation must not
1190           continue after an error.
1191         </p>
1192
1193         <p>
1194           Note that in general <ref id="scripts"> applies to package
1195           maintainer scripts, too.
1196         </p>
1197
1198         <p>
1199           You should not use <prgn>dpkg-divert</prgn> on a file
1200           belonging to another package without consulting the
1201           maintainer of that package first.
1202         </p>
1203
1204         <p>
1205           All packages which supply an instance of a common command
1206           name (or, in general, filename) should generally use
1207           <prgn>update-alternatives</prgn>, so that they may be
1208           installed together.  If <prgn>update-alternatives</prgn>
1209           is not used, then each package must use
1210           <tt>Conflicts</tt> to ensure that other packages are
1211           de-installed.  (In this case, it may be appropriate to
1212           specify a conflict against earlier versions of something
1213           that previously did not use
1214           <prgn>update-alternatives</prgn>; this is an exception to
1215           the usual rule that versioned conflicts should be
1216           avoided.)
1217         </p>
1218
1219         <sect1 id="maintscriptprompt">
1220           <heading>Prompting in maintainer scripts</heading>
1221           <p>
1222             Package maintainer scripts may prompt the user if
1223             necessary. Prompting should be done by communicating
1224             through a program, such as <prgn>debconf</prgn>, which
1225             conforms to the Debian Configuration Management
1226             Specification, version 2 or higher.  Prompting the user by
1227             other means, such as by hand<footnote>
1228                 From the Jargon file: by hand 2. By extension,
1229                 writing code which does something in an explicit or
1230                 low-level way for which a presupplied library
1231                 (<em>debconf, in this instance</em>) routine ought
1232                 to have been available.
1233             </footnote>, is now deprecated.
1234           </p>
1235
1236           <p>
1237             The Debian Configuration Management Specification is included
1238             in the <file>debconf_specification</file> files in the
1239             <package>debian-policy</package> package.
1240             It is also available from the Debian web mirrors at
1241             <tt><url name="/doc/packaging-manuals/debconf_specification.html"
1242                 id="http://www.debian.org/doc/packaging-manuals/debconf_specification.html"></tt>.
1243           </p>
1244
1245           <p>
1246             Packages which use the Debian Configuration Management
1247             Specification may contain an additional
1248             <prgn>config</prgn> script and a <tt>templates</tt>
1249             file in their control archive<footnote>
1250                 The control.tar.gz inside the .deb.
1251                 See <manref name="deb" section="5">.
1252             </footnote>.
1253             The <prgn>config</prgn> script might be run before the
1254             <prgn>preinst</prgn> script, and before the package is unpacked
1255             or any of its dependencies or pre-dependencies are satisfied.
1256             Therefore it must work using only the tools present in
1257             <em>essential</em> packages.<footnote>
1258                   <package>Debconf</package> or another tool that
1259                   implements the Debian Configuration Management
1260                   Specification will also be installed, and any
1261                   versioned dependencies on it will be satisfied
1262                   before preconfiguration begins.
1263             </footnote>
1264           </p>
1265
1266           <p>
1267             Packages which use the Debian Configuration Management
1268             Specification must allow for translation of their user-visible
1269             messages by using a gettext-based system such as the one
1270             provided by the <package>po-debconf</package> package.
1271           </p>
1272
1273           <p>
1274             Packages should try to minimize the amount of prompting
1275             they need to do, and they should ensure that the user
1276             will only ever be asked each question once.  This means
1277             that packages should try to use appropriate shared
1278             configuration files (such as <file>/etc/papersize</file> and
1279             <file>/etc/news/server</file>), and shared
1280             <package>debconf</package> variables rather than each
1281             prompting for their own list of required pieces of
1282             information.
1283           </p>
1284
1285           <p>
1286             It also means that an upgrade should not ask the same
1287             questions again, unless the user has used
1288             <tt>dpkg --purge</tt> to remove the package's configuration.
1289             The answers to configuration questions should be stored in an
1290             appropriate place in <file>/etc</file> so that the user can
1291             modify them, and how this has been done should be
1292             documented.
1293           </p>
1294
1295           <p>
1296             If a package has a vitally important piece of
1297             information to pass to the user (such as "don't run me
1298             as I am, you must edit the following configuration files
1299             first or you risk your system emitting badly-formatted
1300             messages"), it should display this in the
1301             <prgn>config</prgn> or <prgn>postinst</prgn> script and
1302             prompt the user to hit return to acknowledge the
1303             message.  Copyright messages do not count as vitally
1304             important (they belong in
1305             <file>/usr/share/doc/<var>package</var>/copyright</file>);
1306             neither do instructions on how to use a program (these
1307             should be in on-line documentation, where all the users
1308             can see them).
1309           </p>
1310
1311           <p>
1312             Any necessary prompting should almost always be confined
1313             to the <prgn>config</prgn> or <prgn>postinst</prgn>
1314             script. If it is done in the <prgn>postinst</prgn>, it
1315             should be protected with a conditional so that
1316             unnecessary prompting doesn't happen if a package's
1317             installation fails and the <prgn>postinst</prgn> is
1318             called with <tt>abort-upgrade</tt>,
1319             <tt>abort-remove</tt> or <tt>abort-deconfigure</tt>.
1320           </p>
1321         </sect1>
1322
1323       </sect>
1324
1325     </chapt>
1326
1327
1328     <chapt id="source">
1329       <heading>Source packages</heading>
1330
1331       <sect id="standardsversion">
1332         <heading>Standards conformance</heading>
1333
1334         <p>
1335           Source packages should specify the most recent version number
1336           of this policy document with which your package complied
1337           when it was last updated.
1338         </p>
1339
1340         <p>
1341           This information may be used to file bug reports
1342           automatically if your package becomes too much out of date.
1343         </p>
1344
1345         <p>
1346           The version is specified in the <tt>Standards-Version</tt>
1347           control field.
1348           The format of the <tt>Standards-Version</tt> field is
1349           described in <ref id="f-Standards-Version">.
1350         </p>
1351
1352         <p>
1353           You should regularly, and especially if your package has
1354           become out of date, check for the newest Policy Manual
1355           available and update your package, if necessary. When your
1356           package complies with the new standards you should update the
1357           <tt>Standards-Version</tt> source package field and
1358           release it.<footnote>
1359                 See the file <file>upgrading-checklist</file> for
1360                 information about policy which has changed between
1361                 different versions of this document.
1362           </footnote>
1363         </p>
1364
1365       </sect>
1366
1367       <sect id="pkg-relations">
1368         <heading>Package relationships</heading>
1369
1370         <p>
1371           Source packages should specify which binary packages they
1372           require to be installed or not to be installed in order to
1373           build correctly.  For example, if building a package
1374           requires a certain compiler, then the compiler should be
1375           specified as a build-time dependency.
1376         </p>
1377
1378         <p>
1379           It is not necessary to explicitly specify build-time
1380           relationships on a minimal set of packages that are always
1381           needed to compile, link and put in a Debian package a
1382           standard "Hello World!" program written in C or C++.  The
1383           required packages are called <em>build-essential</em>, and
1384           an informational list can be found in
1385           <file>/usr/share/doc/build-essential/list</file> (which is
1386           contained in the <tt>build-essential</tt>
1387           package).<footnote>
1388             Rationale:
1389                 <list compact="compact">
1390                   <item>
1391                       This allows maintaining the list separately
1392                       from the policy documents (the list does not
1393                       need the kind of control that the policy
1394                       documents do).
1395                   </item>
1396                   <item>
1397                       Having a separate package allows one to install
1398                       the build-essential packages on a machine, as
1399                       well as allowing other packages such as tasks to
1400                       require installation of the build-essential
1401                       packages using the depends relation.
1402                   </item>
1403                   <item>
1404                       The separate package allows bug reports against
1405                       the list to be categorized separately from
1406                       the policy management process in the BTS.
1407                   </item>
1408                 </list>
1409           </footnote>
1410         </p>
1411
1412         <p>
1413           When specifying the set of build-time dependencies, one
1414           should list only those packages explicitly required by the
1415           build.  It is not necessary to list packages which are
1416           required merely because some other package in the list of
1417           build-time dependencies depends on them.<footnote>
1418                 The reason for this is that dependencies change, and
1419                 you should list all those packages, and <em>only</em>
1420                 those packages that <em>you</em> need directly.  What
1421                 others need is their business.  For example, if you
1422                 only link against <file>libimlib</file>, you will need to
1423                 build-depend on <package>libimlib2-dev</package> but
1424                 not against any <tt>libjpeg*</tt> packages, even
1425                 though <tt>libimlib2-dev</tt> currently depends on
1426                 them: installation of <package>libimlib2-dev</package>
1427                 will automatically ensure that all of its run-time
1428                 dependencies are satisfied.
1429           </footnote>
1430         </p>
1431
1432         <p>
1433           If build-time dependencies are specified, it must be
1434           possible to build the package and produce working binaries
1435           on a system with only essential and build-essential
1436           packages installed and also those required to satisfy the
1437           build-time relationships (including any implied
1438           relationships).  In particular, this means that version
1439           clauses should be used rigorously in build-time
1440           relationships so that one cannot produce bad or
1441           inconsistently configured packages when the relationships
1442           are properly satisfied.
1443         </p>
1444
1445         <p>
1446           <ref id="relationships"> explains the technical details.
1447         </p>
1448       </sect>
1449
1450       <sect>
1451         <heading>Changes to the upstream sources</heading>
1452
1453         <p>
1454           If changes to the source code are made that are not
1455           specific to the needs of the Debian system, they should be
1456           sent to the upstream authors in whatever form they prefer
1457           so as to be included in the upstream version of the
1458           package.
1459         </p>
1460
1461         <p>
1462           If you need to configure the package differently for
1463           Debian or for Linux, and the upstream source doesn't
1464           provide a way to do so, you should add such configuration
1465           facilities (for example, a new <prgn>autoconf</prgn> test
1466           or <tt>#define</tt>) and send the patch to the upstream
1467           authors, with the default set to the way they originally
1468           had it.  You can then easily override the default in your
1469           <file>debian/rules</file> or wherever is appropriate.
1470         </p>
1471
1472         <p>
1473           You should make sure that the <prgn>configure</prgn> utility
1474           detects the correct architecture specification string
1475           (refer to <ref id="arch-spec"> for details).
1476         </p>
1477
1478         <p>
1479           If you need to edit a <prgn>Makefile</prgn> where GNU-style
1480           <prgn>configure</prgn> scripts are used, you should edit the
1481           <file>.in</file> files rather than editing the
1482           <prgn>Makefile</prgn> directly.  This allows the user to
1483           reconfigure the package if necessary.  You should
1484           <em>not</em> configure the package and edit the generated
1485           <prgn>Makefile</prgn>!  This makes it impossible for someone
1486           else to later reconfigure the package without losing the
1487           changes you made.
1488         </p>
1489
1490       </sect>
1491
1492       <sect id="dpkgchangelog">
1493         <heading>Debian changelog: <file>debian/changelog</file></heading>
1494
1495         <p>
1496           Changes in the Debian version of the package should be
1497           briefly explained in the Debian changelog file
1498           <file>debian/changelog</file>.<footnote>
1499             <p>
1500               Mistakes in changelogs are usually best rectified by
1501               making a new changelog entry rather than "rewriting
1502               history" by editing old changelog entries.
1503             </p>
1504           </footnote>
1505           This includes modifications
1506           made in the Debian package compared to the upstream one
1507           as well as other changes and updates to the package.
1508           <footnote>
1509               Although there is nothing stopping an author who is also
1510               the Debian maintainer from using this changelog for all
1511               their changes, it will have to be renamed if the Debian
1512               and upstream maintainers become different people. In such
1513               a case, however, it might be better to maintain the package
1514               as a non-native package.
1515           </footnote>
1516         </p>
1517
1518         <p>
1519           The format of the <file>debian/changelog</file> allows the
1520           package building tools to discover which version of the package
1521           is being built and find out other release-specific information.
1522         </p>
1523
1524         <p>
1525           That format is a series of entries like this:
1526
1527 <example compact="compact">
1528 <var>package</var> (<var>version</var>) <var>distribution(s)</var>; urgency=<var>urgency</var>
1529             <var>
1530               [optional blank line(s), stripped]
1531             </var>
1532   * <var>change details</var>
1533     <var>more change details</var>
1534             <var>
1535               [blank line(s), included in output of dpkg-parsechangelog]
1536             </var>
1537   * <var>even more change details</var>
1538             <var>
1539               [optional blank line(s), stripped]
1540             </var>
1541  -- <var>maintainer name</var> &lt;<var>email address</var>&gt;<var>[two spaces]</var>  <var>date</var>
1542 </example>
1543         </p>
1544
1545         <p>
1546           <var>package</var> and <var>version</var> are the source
1547           package name and version number.
1548         </p>
1549
1550         <p>
1551           <var>distribution(s)</var> lists the distributions where
1552           this version should be installed when it is uploaded - it
1553           is copied to the <tt>Distribution</tt> field in the
1554           <file>.changes</file> file.  See <ref id="f-Distribution">.
1555         </p>
1556
1557         <p>
1558           <var>urgency</var> is the value for the <tt>Urgency</tt>
1559           field in the <file>.changes</file> file for the upload
1560           (see <ref id="f-Urgency">). It is not possible to specify
1561           an urgency containing commas; commas are used to separate
1562           <tt><var>keyword</var>=<var>value</var></tt> settings in the
1563           <prgn>dpkg</prgn> changelog format (though there is
1564           currently only one useful <var>keyword</var>,
1565           <tt>urgency</tt>).
1566         </p>
1567
1568         <p>
1569           The change details may in fact be any series of lines
1570           starting with at least two spaces, but conventionally each
1571           change starts with an asterisk and a separating space and
1572           continuation lines are indented so as to bring them in
1573           line with the start of the text above.  Blank lines may be
1574           used here to separate groups of changes, if desired.
1575         </p>
1576
1577         <p>
1578           If this upload resolves bugs recorded in the Bug Tracking
1579           System (BTS), they may be automatically closed on the
1580           inclusion of this package into the Debian archive by
1581           including the string: <tt>closes: Bug#<var>nnnnn</var></tt>
1582           in the change details.<footnote>
1583               To be precise, the string should match the following
1584               Perl regular expression:
1585               <example>
1586 /closes:\s*(?:bug)?\#?\s?\d+(?:,\s*(?:bug)?\#?\s?\d+)*/i
1587               </example>
1588               Then all of the bug numbers listed will be closed by the
1589               archive maintenance script (<prgn>katie</prgn>) using the
1590               <var>version</var> of the changelog entry.
1591           </footnote>
1592           This information is conveyed via the <tt>Closes</tt> field
1593           in the <tt>.changes</tt> file (see <ref id="f-Closes">).
1594         </p>
1595
1596         <p>
1597           The maintainer name and email address used in the changelog
1598           should be the details of the person uploading <em>this</em>
1599           version.  They are <em>not</em> necessarily those of the
1600           usual package maintainer.  The information here will be
1601           copied to the <tt>Changed-By</tt> field in the
1602           <tt>.changes</tt> file (see <ref id="f-Changed-By">),
1603           and then later used to send an acknowledgement when the
1604           upload has been installed.
1605         </p>
1606
1607         <p>
1608           The <var>date</var> must be in RFC822 format<footnote>
1609               This is generated by <tt>date -R</tt>.
1610           </footnote>; it must include the time zone specified
1611           numerically, with the time zone name or abbreviation
1612           optionally present as a comment in parentheses.
1613         </p>
1614
1615         <p>
1616           The first "title" line with the package name must start
1617           at the left hand margin.  The "trailer" line with the
1618           maintainer and date details must be preceded by exactly
1619           one space.  The maintainer details and the date must be
1620           separated by exactly two spaces.
1621         </p>
1622
1623         <p>
1624           The entire changelog must be encoded in UTF-8.
1625         </p>
1626
1627         <p>
1628           For more information on placement of the changelog files
1629           within binary packages, please see <ref id="changelogs">.
1630         </p>
1631       </sect>
1632
1633       <sect id="dpkgcopyright">
1634         <heading>Copyright: <file>debian/copyright</file></heading>
1635         <p>
1636           Every package must be accompanied by a verbatim copy of
1637           its copyright and distribution license in the file
1638           <file>/usr/share/doc/<var>package</var>/copyright</file>
1639           (see <ref id="copyrightfile"> for further details). Also see
1640           <ref id="pkgcopyright"> for further considerations relayed
1641           to copyrights for packages.
1642         </p>
1643       </sect>
1644       <sect>
1645         <heading>Error trapping in makefiles</heading>
1646
1647         <p>
1648           When <prgn>make</prgn> invokes a command in a makefile
1649           (including your package's upstream makefiles and
1650           <file>debian/rules</file>), it does so using <prgn>sh</prgn>.  This
1651           means that <prgn>sh</prgn>'s usual bad error handling
1652           properties apply: if you include a miniature script as one
1653           of the commands in your makefile you'll find that if you
1654           don't do anything about it then errors are not detected
1655           and <prgn>make</prgn> will blithely continue after
1656           problems.
1657         </p>
1658
1659         <p>
1660           Every time you put more than one shell command (this
1661           includes using a loop) in a makefile command you
1662           must make sure that errors are trapped.  For
1663           simple compound commands, such as changing directory and
1664           then running a program, using <tt>&amp;&amp;</tt> rather
1665           than semicolon as a command separator is sufficient.  For
1666           more complex commands including most loops and
1667           conditionals you should include a separate <tt>set -e</tt>
1668           command at the start of every makefile command that's
1669           actually one of these miniature shell scripts.
1670         </p>
1671       </sect>
1672
1673       <sect id="timestamps">
1674         <heading>Time Stamps</heading>
1675         <p>
1676           Maintainers should preserve the modification times of the
1677           upstream source files in a package, as far as is reasonably
1678           possible.<footnote>
1679               The rationale is that there is some information conveyed
1680               by knowing the age of the file, for example, you could
1681               recognize that some documentation is very old by looking
1682               at the modification time, so it would be nice if the
1683               modification time of the upstream source would be
1684               preserved.
1685           </footnote>
1686         </p>
1687       </sect>
1688
1689       <sect id="restrictions">
1690         <heading>Restrictions on objects in source packages</heading>
1691
1692         <p>
1693           The source package may not contain any hard links<footnote>
1694             <p>
1695               This is not currently detected when building source
1696               packages, but only when extracting
1697               them.
1698             </p>
1699             <p>
1700               Hard links may be permitted at some point in the
1701               future, but would require a fair amount of
1702               work.
1703             </p>
1704           </footnote>, device special files, sockets or setuid or
1705           setgid files.<footnote>
1706               Setgid directories are allowed.
1707           </footnote>
1708         </p>
1709       </sect>
1710
1711       <sect id="debianrules">
1712         <heading>Main building script: <file>debian/rules</file></heading>
1713
1714         <p>
1715           This file must be an executable makefile, and contains the
1716           package-specific recipes for compiling the package and
1717           building binary package(s) from the source.
1718         </p>
1719
1720         <p>
1721           It must start with the line <tt>#!/usr/bin/make -f</tt>,
1722           so that it can be invoked by saying its name rather than
1723           invoking <prgn>make</prgn> explicitly.
1724         </p>
1725
1726         <p>
1727           Since an interactive <file>debian/rules</file> script makes it
1728           impossible to auto-compile that package and also makes it
1729           hard for other people to reproduce the same binary
1730           package, all <em>required targets</em> MUST be
1731           non-interactive. At a minimum, required targets are the
1732           ones called by <prgn>dpkg-buildpackage</prgn>, namely,
1733           <em>clean</em>, <em>binary</em>, <em>binary-arch</em>,
1734           <em>binary-indep</em>, and <em>build</em>. It also follows
1735           that any target that these targets depend on must also be
1736           non-interactive.
1737         </p>
1738
1739         <p>
1740           The targets are as follows (required unless stated otherwise):
1741           <taglist>
1742             <tag><tt>build</tt></tag>
1743             <item>
1744               <p>
1745                 The <tt>build</tt> target should perform all the
1746                 configuration and compilation of the package.
1747                 If a package has an interactive pre-build
1748                 configuration routine, the Debianized source package
1749                 must either be built after this has taken place (so
1750                 that the binary package can be built without rerunning
1751                 the configuration) or the configuration routine
1752                 modified to become non-interactive.  (The latter is
1753                 preferable if there are architecture-specific features
1754                 detected by the configuration routine.)
1755               </p>
1756
1757               <p>
1758                 For some packages, notably ones where the same
1759                 source tree is compiled in different ways to produce
1760                 two binary packages, the <tt>build</tt> target
1761                 does not make much sense.  For these packages it is
1762                 good enough to provide two (or more) targets
1763                 (<tt>build-a</tt> and <tt>build-b</tt> or whatever)
1764                 for each of the ways of building the package, and a
1765                 <tt>build</tt> target that does nothing.  The
1766                 <tt>binary</tt> target will have to build the
1767                 package in each of the possible ways and make the
1768                 binary package out of each.
1769               </p>
1770
1771               <p>
1772                 The <tt>build</tt> target must not do anything
1773                 that might require root privilege.
1774               </p>
1775
1776               <p>
1777                 The <tt>build</tt> target may need to run the
1778                 <tt>clean</tt> target first - see below.
1779               </p>
1780
1781               <p>
1782                 When a package has a configuration and build routine
1783                 which takes a long time, or when the makefiles are
1784                 poorly designed, or when <tt>build</tt> needs to
1785                 run <tt>clean</tt> first, it is a good idea to
1786                 <tt>touch build</tt> when the build process is
1787                 complete.  This will ensure that if <tt>debian/rules
1788                 build</tt> is run again it will not rebuild the whole
1789                 program.<footnote>
1790                     Another common way to do this is for <tt>build</tt>
1791                     to depend on <prgn>build-stamp</prgn> and to do
1792                     nothing else, and for the <prgn>build-stamp</prgn>
1793                     target to do the building and to <tt>touch
1794                     build-stamp</tt> on completion.  This is
1795                     especially useful if the build routine creates a
1796                     file or directory called <tt>build</tt>; in such a
1797                     case, <tt>build</tt> will need to be listed as
1798                     a phony target (i.e., as a dependency of the
1799                     <tt>.PHONY</tt> target).  See the documentation of
1800                     <prgn>make</prgn> for more information on phony
1801                     targets.
1802                 </footnote>
1803               </p>
1804             </item>
1805
1806             <tag><tt>build-arch</tt> (optional),
1807                  <tt>build-indep</tt> (optional)
1808             </tag>
1809             <item>
1810               <p>
1811                 A package may also provide both of the targets
1812                 <tt>build-arch</tt> and <tt>build-indep</tt>.
1813                 The <tt>build-arch</tt> target, if provided, should
1814                 perform all the configuration and compilation required
1815                 for producing all architecture-dependant binary packages
1816                 (those packages for which the body of the
1817                 <tt>Architecture</tt> field in <tt>debian/control</tt>
1818                 is not <tt>all</tt>).
1819                 Similarly, the <tt>build-indep</tt> target, if
1820                 provided, should perform all the configuration and
1821                 compilation required for producing all
1822                 architecture-independent binary packages
1823                 (those packages for which the body of the
1824                 <tt>Architecture</tt> field in <tt>debian/control</tt>
1825                 is <tt>all</tt>).
1826                 The <tt>build</tt> target should depend on those of the
1827                 targets <tt>build-arch</tt> and <tt>build-indep</tt> that
1828                 are provided in the rules file.
1829               </p>
1830
1831               <p>
1832                 If one or both of the targets <tt>build-arch</tt> and
1833                 <tt>build-indep</tt> are not provided, then invoking
1834                 <file>debian/rules</file> with one of the not-provided
1835                 targets as arguments should produce a exit status code
1836                 of 2.  Usually this is provided automatically by make
1837                 if the target is missing.
1838               </p>
1839
1840               <p>
1841                 The <tt>build-arch</tt> and <tt>build-indep</tt> targets
1842                 must not do anything that might require root privilege.
1843               </p>
1844             </item>
1845
1846             <tag><tt>binary</tt>, <tt>binary-arch</tt>,
1847               <tt>binary-indep</tt>
1848             </tag>
1849             <item>
1850               <p>
1851                 The <tt>binary</tt> target must be all that is
1852                 necessary for the user to build the binary package(s)
1853                 produced from this source package.  It is
1854                 split into two parts: <prgn>binary-arch</prgn> builds
1855                 the binary packages which are specific to a particular
1856                 architecture, and <tt>binary-indep</tt> builds
1857                 those which are not.
1858               </p>
1859               <p>
1860                 <tt>binary</tt> may be (and commonly is) a target with
1861                 no commands which simply depends on
1862                 <tt>binary-arch</tt> and <tt>binary-indep</tt>.
1863               </p>
1864               <p>
1865                 Both <tt>binary-*</tt> targets should depend on the
1866                 <tt>build</tt> target, or on the appropriate
1867                 <tt>build-arch</tt> or <tt>build-indep</tt> target, if
1868                 provided, so that the package is built if it has not
1869                 been already.  It should then create the relevant
1870                 binary package(s), using <prgn>dpkg-gencontrol</prgn> to
1871                 make their control files and <prgn>dpkg-deb</prgn> to
1872                 build them and place them in the parent of the top
1873                 level directory.
1874               </p>
1875
1876               <p>
1877                 Both the <tt>binary-arch</tt> and
1878                 <tt>binary-indep</tt> targets <em>must</em> exist.
1879                 If one of them has nothing to do (which will always be
1880                 the case if the source generates only a single binary
1881                 package, whether architecture-dependent or not), it
1882                 must still exist and must always succeed.
1883               </p>
1884
1885               <p>
1886                 The <tt>binary</tt> targets must be invoked as
1887                 root.<footnote>
1888                     The <prgn>fakeroot</prgn> package often allows one
1889                     to build a package correctly even without being
1890                     root.
1891                 </footnote>
1892               </p>
1893             </item>
1894
1895             <tag><tt>clean</tt></tag>
1896             <item>
1897               <p>
1898                 This must undo any effects that the <tt>build</tt>
1899                 and <tt>binary</tt> targets may have had, except
1900                 that it should leave alone any output files created in
1901                 the parent directory by a run of a <tt>binary</tt>
1902                 target.
1903               </p>
1904
1905               <p>
1906                 If a <tt>build</tt> file is touched at the end of
1907                 the <tt>build</tt> target, as suggested above, it
1908                 should be removed as the first action that
1909                 <tt>clean</tt> performs, so that running
1910                 <tt>build</tt> again after an interrupted
1911                 <tt>clean</tt> doesn't think that everything is
1912                 already done.
1913               </p>
1914
1915               <p>
1916                 The <tt>clean</tt> target may need to be
1917                 invoked as root if <tt>binary</tt> has been
1918                 invoked since the last <tt>clean</tt>, or if
1919                 <tt>build</tt> has been invoked as root (since
1920                 <tt>build</tt> may create directories, for
1921                 example).
1922               </p>
1923             </item>
1924
1925             <tag><tt>get-orig-source</tt> (optional)</tag>
1926             <item>
1927               <p>
1928                 This target fetches the most recent version of the
1929                 original source package from a canonical archive site
1930                 (via FTP or WWW, for example), does any necessary
1931                 rearrangement to turn it into the original source
1932                 tar file format described below, and leaves it in the
1933                 current directory.
1934               </p>
1935
1936               <p>
1937                 This target may be invoked in any directory, and
1938                 should take care to clean up any temporary files it
1939                 may have left.
1940               </p>
1941
1942               <p>
1943                 This target is optional, but providing it if
1944                 possible is a good idea.
1945               </p>
1946             </item>
1947
1948             <tag><tt>patch</tt> (optional)</tag>
1949             <item>
1950               <p>
1951                 This target performs whatever additional actions are
1952                 required to make the source ready for editing (unpacking
1953                 additional upstream archives, applying patches, etc.).
1954                 It is recommended to be implemented for any package where
1955                 <tt>dpkg-source -x</tt> does not result in source ready
1956                 for additional modification.  See
1957                 <ref id="readmesource">.
1958               </p>
1959             </item>
1960           </taglist>
1961
1962         <p>
1963           The <tt>build</tt>, <tt>binary</tt> and
1964           <tt>clean</tt> targets must be invoked with the current
1965           directory being the package's top-level directory.
1966         </p>
1967
1968
1969         <p>
1970           Additional targets may exist in <file>debian/rules</file>,
1971           either as published or undocumented interfaces or for the
1972           package's internal use.
1973         </p>
1974
1975         <p>
1976           The architectures we build on and build for are determined
1977           by <prgn>make</prgn> variables using the utility
1978           <qref id="pkg-dpkg-architecture"><prgn>dpkg-architecture</prgn></qref>.
1979           You can determine the
1980           Debian architecture and the GNU style architecture
1981           specification string for the build machine (the machine type
1982           we are building on) as well as for the host machine (the
1983           machine type we are building for).  Here is a list of
1984           supported <prgn>make</prgn> variables:
1985           <list compact="compact">
1986             <item>
1987                 <tt>DEB_*_ARCH</tt> (the Debian architecture)
1988             </item>
1989             <item>
1990                 <tt>DEB_*_GNU_TYPE</tt> (the GNU style architecture
1991                 specification string)
1992             </item>
1993             <item>
1994                 <tt>DEB_*_GNU_CPU</tt> (the CPU part of
1995                 <tt>DEB_*_GNU_TYPE</tt>)
1996             </item>
1997             <item>
1998                 <tt>DEB_*_GNU_SYSTEM</tt> (the System part of
1999                 <tt>DEB_*_GNU_TYPE</tt>)
2000           </list>
2001           where <tt>*</tt> is either <tt>BUILD</tt> for specification of
2002           the build machine or <tt>HOST</tt> for specification of the
2003           host machine.
2004         </p>
2005
2006         <p>
2007           Backward compatibility can be provided in the rules file
2008           by setting the needed variables to suitable default
2009           values; please refer to the documentation of
2010           <prgn>dpkg-architecture</prgn> for details.
2011         </p>
2012
2013         <p>
2014           It is important to understand that the <tt>DEB_*_ARCH</tt>
2015           string only determines which Debian architecture we are
2016           building on or for. It should not be used to get the CPU
2017           or system information; the GNU style variables should be
2018           used for that.
2019         </p>
2020
2021         <sect1 id="debianrules-options">
2022           <heading><file>debian/rules</file> and
2023             <tt>DEB_BUILD_OPTIONS</tt></heading>
2024
2025           <p>
2026             Supporting the standardized environment variable
2027             <tt>DEB_BUILD_OPTIONS</tt> is recommended.  This variable can
2028             contain several flags to change how a package is compiled and
2029             built.  Each flag must be in the form <var>flag</var> or
2030             <var>flag</var>=<var>options</var>.  If multiple flags are
2031             given, they must be separated by whitespace.<footnote>
2032               Some packages support any delimiter, but whitespace is the
2033               easiest to parse inside a makefile and avoids ambiguity with
2034               flag values that contain commas.
2035             </footnote>
2036             <var>flag</var> must start with a lowercase letter
2037             (<tt>a-z</tt>) and consist only of lowercase letters,
2038             numbers (<tt>0-9</tt>), and the characters
2039             <tt>-</tt> and <tt>_</tt> (hyphen and underscore).
2040             <var>options</var> must not contain whitespace.  The same
2041             tag should not be given multiple times with conflicting
2042             values.  Package maintainers may assume that
2043             <tt>DEB_BUILD_OPTIONS</tt> will not contain conflicting tags.
2044           </p>
2045
2046           <p>
2047             The meaning of the following tags has been standardized:
2048             <taglist>
2049               <tag>nocheck</tag>
2050               <item>
2051                   This tag says to not run any build-time test suite
2052                   provided by the package.
2053               </item>
2054               <tag>noopt</tag>
2055               <item>
2056                   The presence of this tag means that the package should
2057                   be compiled with a minimum of optimization.  For C
2058                   programs, it is best to add <tt>-O0</tt> to
2059                   <tt>CFLAGS</tt> (although this is usually the default).
2060                   Some programs might fail to build or run at this level
2061                   of optimization; it may be necessary to use
2062                   <tt>-O1</tt>, for example.
2063               </item>
2064               <tag>nostrip</tag>
2065               <item>
2066                   This tag means that the debugging symbols should not be
2067                   stripped from the binary during installation, so that
2068                   debugging information may be included in the package.
2069               </item>
2070               <tag>parallel=n</tag>
2071               <item>
2072                   This tag means that the package should be built using up
2073                   to <tt>n</tt> parallel processes if the package build
2074                   system supports this.<footnote>
2075                       Packages built with <tt>make</tt> can often implement
2076                       this by passing the <tt>-j</tt><var>n</var> option to
2077                       <tt>make</tt>.
2078                   </footnote>
2079                   If the package build system does not support parallel
2080                   builds, this string must be ignored.  If the package
2081                   build system only supports a lower level of concurrency
2082                   than <var>n</var>, the package should be built using as
2083                   many parallel processes as the package build system
2084                   supports.  It is up to the package maintainer to decide
2085                   whether the package build times are long enough and the
2086                   package build system is robust enough to make supporting
2087                   parallel builds worthwhile.
2088                </item>
2089             </taglist>
2090           </p>
2091
2092           <p>
2093             Unknown flags must be ignored by <file>debian/rules</file>.
2094           </p>
2095
2096           <p>
2097             The following makefile snippet is an example of how one may
2098             implement the build options; you will probably have to
2099             massage this example in order to make it work for your
2100             package.
2101             <example compact="compact">
2102 CFLAGS = -Wall -g
2103 INSTALL = install
2104 INSTALL_FILE    = $(INSTALL) -p    -o root -g root  -m  644
2105 INSTALL_PROGRAM = $(INSTALL) -p    -o root -g root  -m  755
2106 INSTALL_SCRIPT  = $(INSTALL) -p    -o root -g root  -m  755
2107 INSTALL_DIR     = $(INSTALL) -p -d -o root -g root  -m  755
2108
2109 ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
2110     CFLAGS += -O0
2111 else
2112     CFLAGS += -O2
2113 endif
2114 ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
2115     INSTALL_PROGRAM += -s
2116 endif
2117 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
2118     NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
2119     MAKEFLAGS += -j$(NUMJOBS)
2120 endif
2121
2122 build:
2123         # ...
2124 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
2125         # Code to run the package test suite.
2126 endif
2127             </example>
2128           </p>
2129         </sect1>
2130       </sect>
2131
2132 <!-- FIXME: section pkg-srcsubstvars is the same as substvars -->
2133       <sect id="substvars">
2134         <heading>Variable substitutions: <file>debian/substvars</file></heading>
2135
2136         <p>
2137           When <prgn>dpkg-gencontrol</prgn>,
2138           <prgn>dpkg-genchanges</prgn> and <prgn>dpkg-source</prgn>
2139           generate control files they perform variable substitutions
2140           on their output just before writing it.  Variable
2141           substitutions have the form <tt>${<var>variable</var>}</tt>.
2142           The optional file <file>debian/substvars</file> contains
2143           variable substitutions to be used; variables can also be set
2144           directly from <file>debian/rules</file> using the <tt>-V</tt>
2145           option to the source packaging commands, and certain
2146           predefined variables are also available.
2147         </p>
2148
2149         <p>
2150           The <file>debian/substvars</file> file is usually generated and
2151           modified dynamically by <file>debian/rules</file> targets, in
2152           which case it must be removed by the <tt>clean</tt> target.
2153         </p>
2154
2155         <p>
2156           See <manref name="deb-substvars" section="5"> for full
2157           details about source variable substitutions, including the
2158           format of <file>debian/substvars</file>.</p>
2159       </sect>
2160
2161       <sect id="debianwatch">
2162         <heading>Optional upstream source location: <file>debian/watch</file></heading>
2163
2164         <p>
2165           This is an optional, recommended control file for the
2166           <tt>uscan</tt> utility which defines how to automatically
2167           scan ftp or http sites for newly available updates of the
2168           package. This is used by <url id="
2169           http://dehs.alioth.debian.org/"> and other Debian QA tools
2170           to help with quality control and maintenance of the
2171           distribution as a whole.
2172         </p>
2173
2174       </sect>
2175
2176       <sect id="debianfiles">
2177         <heading>Generated files list: <file>debian/files</file></heading>
2178
2179         <p>
2180           This file is not a permanent part of the source tree; it
2181           is used while building packages to record which files are
2182           being generated.  <prgn>dpkg-genchanges</prgn> uses it
2183           when it generates a <file>.changes</file> file.
2184         </p>
2185
2186         <p>
2187           It should not exist in a shipped source package, and so it
2188           (and any backup files or temporary files such as
2189           <file>files.new</file><footnote>
2190               <file>files.new</file> is used as a temporary file by
2191               <prgn>dpkg-gencontrol</prgn> and
2192               <prgn>dpkg-distaddfile</prgn> - they write a new
2193               version of <tt>files</tt> here before renaming it,
2194               to avoid leaving a corrupted copy if an error
2195               occurs.
2196           </footnote>) should be removed by the
2197           <tt>clean</tt> target.  It may also be wise to
2198           ensure a fresh start by emptying or removing it at the
2199           start of the <tt>binary</tt> target.
2200         </p>
2201
2202         <p>
2203           When <prgn>dpkg-gencontrol</prgn> is run for a binary
2204           package, it adds an entry to <file>debian/files</file> for the
2205           <file>.deb</file> file that will be created when <tt>dpkg-deb
2206           --build</tt> is run for that binary package.  So for most
2207           packages all that needs to be done with this file is to
2208           delete it in the <tt>clean</tt> target.
2209         </p>
2210
2211         <p>
2212           If a package upload includes files besides the source
2213           package and any binary packages whose control files were
2214           made with <prgn>dpkg-gencontrol</prgn> then they should be
2215           placed in the parent of the package's top-level directory
2216           and <prgn>dpkg-distaddfile</prgn> should be called to add
2217           the file to the list in <file>debian/files</file>.</p>
2218       </sect>
2219
2220       <sect id="embeddedfiles">
2221         <heading>Convenience copies of code</heading>
2222
2223         <p>
2224           Some software packages include in their distribution convenience
2225           copies of code from other software packages, generally so that
2226           users compiling from source don't have to download multiple
2227           packages.  Debian packages should not make use of these
2228           convenience copies unless the included package is explicitly
2229           intended to be used in this way.<footnote>
2230             For example, parts of the GNU build system work like this.
2231           </footnote>
2232           If the included code is already in the Debian archive in the
2233           form of a library, the Debian packaging should ensure that
2234           binary packages reference the libraries already in Debian and
2235           the convenience copy is not used.  If the included code is not
2236           already in Debian, it should be packaged separately as a
2237           prerequisite if possible.
2238           <footnote>
2239             Having multiple copies of the same code in Debian is
2240             inefficient, often creates either static linking or shared
2241             library conflicts, and, most importantly, increases the
2242             difficulty of handling security vulnerabilities in the
2243             duplicated code.
2244           </footnote>
2245         </p>
2246       </sect>
2247
2248       <sect id="readmesource">
2249         <heading>Source package handling:
2250           <file>debian/README.source</file></heading>
2251
2252         <p>
2253           If running <prgn>dpkg-source -x</prgn> on a source package
2254           doesn't produce the source of the package, ready for editing,
2255           and allow one to make changes and run
2256           <prgn>dpkg-buildpackage</prgn> to produce a modified package
2257           without taking any additional steps, creating a
2258           <file>debian/README.source</file> documentation file is
2259           recommended.  This file should explain how to do all of the
2260           following:
2261             <enumlist>
2262               <item>Generate the fully patched source, in a form ready for
2263               editing, that would be built to create Debian
2264               packages.  Doing this with a <tt>patch</tt> target in
2265               <file>debian/rules</file> is recommended; see
2266               <ref id="debianrules">.</item>
2267               <item>Modify the source and save those modifications so that
2268               they will be applied when building the package.</item>
2269               <item>Remove source modifications that are currently being
2270               applied when building the package.</item>
2271               <item>Optionally, document what steps are necessary to
2272               upgrade the Debian source package to a new upstream version,
2273               if applicable.</item>
2274             </enumlist>
2275           This explanation should include specific commands and mention
2276           any additional required Debian packages.  It should not assume
2277           familiarity with any specific Debian packaging system or patch
2278           management tools.
2279         </p>
2280
2281         <p>
2282           This explanation may refer to a documentation file installed by
2283           one of the package's build dependencies provided that the
2284           referenced documentation clearly explains these tasks and is not
2285           a general reference manual.
2286         </p>
2287
2288         <p>
2289           <file>debian/README.source</file> may also include any other
2290           information that would be helpful to someone modifying the
2291           source package.  Even if the package doesn't fit the above
2292           description, maintainers are encouraged to document in a
2293           <file>debian/README.source</file> file any source package with a
2294           particularly complex or unintuitive source layout or build
2295           system (for example, a package that builds the same source
2296           multiple times to generate different binary packages).
2297         </p>
2298       </sect>
2299     </chapt>
2300
2301
2302     <chapt id="controlfields">
2303       <heading>Control files and their fields</heading>
2304
2305       <p>
2306         The package management system manipulates data represented in
2307         a common format, known as <em>control data</em>, stored in
2308         <em>control files</em>.
2309         Control files are used for source packages, binary packages and
2310         the <file>.changes</file> files which control the installation
2311         of uploaded files<footnote>
2312             <prgn>dpkg</prgn>'s internal databases are in a similar
2313             format.
2314         </footnote>.
2315       </p>
2316
2317       <sect id="controlsyntax">
2318         <heading>Syntax of control files</heading>
2319
2320         <p>
2321           A control file consists of one or more paragraphs of
2322           fields<footnote>
2323                 The paragraphs are also sometimes referred to as stanzas.
2324           </footnote>.
2325           The paragraphs are separated by blank lines.  Some control
2326           files allow only one paragraph; others allow several, in
2327           which case each paragraph usually refers to a different
2328           package.  (For example, in source packages, the first
2329           paragraph refers to the source package, and later paragraphs
2330           refer to binary packages generated from the source.)
2331         </p>
2332
2333         <p>
2334           Each paragraph consists of a series of data fields; each
2335           field consists of the field name, followed by a colon and
2336           then the data/value associated with that field.  It ends at
2337           the end of the (logical) line.  Horizontal whitespace
2338           (spaces and tabs) may occur immediately before or after the
2339           value and is ignored there; it is conventional to put a
2340           single space after the colon.  For example, a field might
2341           be:
2342           <example compact="compact">
2343 Package: libc6
2344           </example>
2345           the field name is <tt>Package</tt> and the field value
2346           <tt>libc6</tt>.
2347         </p>
2348
2349         <p>
2350           Many fields' values may span several lines; in this case
2351           each continuation line must start with a space or a tab.
2352           Any trailing spaces or tabs at the end of individual
2353           lines of a field value are ignored. 
2354         </p>
2355
2356         <p>
2357           In fields where it is specified that lines may not wrap,
2358           only a single line of data is allowed and whitespace is not
2359           significant in a field body. Whitespace must not appear
2360           inside names (of packages, architectures, files or anything
2361           else) or version numbers, or between the characters of
2362           multi-character version relationships.
2363         </p>
2364
2365         <p>
2366           Field names are not case-sensitive, but it is usual to
2367           capitalize the field names using mixed case as shown below.
2368         </p>
2369
2370         <p>
2371           Blank lines, or lines consisting only of spaces and tabs,
2372           are not allowed within field values or between fields - that
2373           would mean a new paragraph.
2374         </p>
2375
2376         <p>
2377           All control files must be encoded in UTF-8.
2378         </p>
2379       </sect>
2380
2381       <sect id="sourcecontrolfiles">
2382         <heading>Source package control files -- <file>debian/control</file></heading>
2383
2384         <p>
2385           The <file>debian/control</file> file contains the most vital
2386           (and version-independent) information about the source package
2387           and about the binary packages it creates.
2388         </p>
2389
2390         <p>
2391           The first paragraph of the control file contains information about
2392           the source package in general. The subsequent sets each describe a
2393           binary package that the source tree builds.
2394         </p>
2395
2396         <p>
2397           The fields in the general paragraph (the first one, for the source
2398           package) are:
2399
2400           <list compact="compact">
2401             <item><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</item>
2402             <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2403             <item><qref id="f-Uploaders"><tt>Uploaders</tt></qref></item>
2404             <item><qref id="f-Section"><tt>Section</tt></qref> (recommended)</item>
2405             <item><qref id="f-Priority"><tt>Priority</tt></qref> (recommended)</item>
2406             <item><qref id="sourcebinarydeps"><tt>Build-Depends</tt> et al</qref></item>
2407             <item><qref id="f-Standards-Version"><tt>Standards-Version</tt></qref> (recommended)</item>
2408             <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2409           </list>
2410         </p>
2411
2412         <p>
2413           The fields in the binary package paragraphs are:
2414
2415           <list compact="compact">
2416             <item><qref id="f-Package"><tt>Package</tt></qref> (mandatory)</item>
2417             <item><qref id="f-Architecture"><tt>Architecture</tt></qref> (mandatory)</item>
2418             <item><qref id="f-Section"><tt>Section</tt></qref> (recommended)</item>
2419             <item><qref id="f-Priority"><tt>Priority</tt></qref> (recommended)</item>
2420             <item><qref id="f-Essential"><tt>Essential</tt></qref></item>
2421             <item><qref id="binarydeps"><tt>Depends</tt> et al</qref></item>
2422             <item><qref id="f-Description"><tt>Description</tt></qref> (mandatory)</item>
2423             <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2424           </list>
2425         </p>
2426
2427         <p>
2428           The syntax and semantics of the fields are described below.
2429         </p>
2430
2431 <!-- stuff -->
2432
2433         <p>
2434           These fields are used by <prgn>dpkg-gencontrol</prgn> to
2435           generate control files for binary packages (see below), by
2436           <prgn>dpkg-genchanges</prgn> to generate the
2437           <tt>.changes</tt> file to accompany the upload, and by
2438           <prgn>dpkg-source</prgn> when it creates the
2439           <file>.dsc</file> source control file as part of a source
2440           archive. Many fields are permitted to span multiple lines in
2441           <file>debian/control</file> but not in any other control
2442           file. These tools are responsible for removing the line
2443           breaks from such fields when using fields from
2444           <file>debian/control</file> to generate other control files.
2445         </p>
2446
2447         <p>
2448           The fields here may contain variable references - their
2449           values will be substituted by <prgn>dpkg-gencontrol</prgn>,
2450           <prgn>dpkg-genchanges</prgn> or <prgn>dpkg-source</prgn>
2451           when they generate output control files.
2452           See <ref id="substvars"> for details.
2453         </p>
2454
2455       </sect>
2456
2457       <sect id="binarycontrolfiles">
2458         <heading>Binary package control files -- <file>DEBIAN/control</file></heading>
2459
2460         <p>
2461           The <file>DEBIAN/control</file> file contains the most vital
2462           (and version-dependent) information about a binary package.
2463         </p>
2464
2465         <p>
2466           The fields in this file are:
2467
2468           <list compact="compact">
2469             <item><qref id="f-Package"><tt>Package</tt></qref> (mandatory)</item>
2470             <item><qref id="f-Source"><tt>Source</tt></qref></item>
2471             <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
2472             <item><qref id="f-Section"><tt>Section</tt></qref> (recommended)</item>
2473             <item><qref id="f-Priority"><tt>Priority</tt></qref> (recommended)</item>
2474             <item><qref id="f-Architecture"><tt>Architecture</tt></qref> (mandatory)</item>
2475             <item><qref id="f-Essential"><tt>Essential</tt></qref></item>
2476             <item><qref id="binarydeps"><tt>Depends</tt> et al</qref></item>
2477             <item><qref id="f-Installed-Size"><tt>Installed-Size</tt></qref></item>
2478             <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2479             <item><qref id="f-Description"><tt>Description</tt></qref> (mandatory)</item>
2480             <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2481           </list>
2482         </p>
2483       </sect>
2484
2485       <sect id="debiansourcecontrolfiles">
2486         <heading>Debian source control files -- <tt>.dsc</tt></heading>
2487
2488         <p>
2489           This file contains a series of fields, identified and
2490           separated just like the fields in the control file of
2491           a binary package.  The fields are listed below; their
2492           syntax is described above, in <ref id="pkg-controlfields">.
2493
2494         <list compact="compact">
2495           <item><qref id="f-Format"><tt>Format</tt></qref> (mandatory)</item>
2496           <item><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</item>
2497           <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
2498           <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2499           <item><qref id="f-Uploaders"><tt>Uploaders</tt></qref></item>
2500           <item><qref id="f-Binary"><tt>Binary</tt></qref></item>
2501           <item><qref id="f-Architecture"><tt>Architecture</tt></qref></item>
2502           <item><qref id="sourcebinarydeps"><tt>Build-Depends</tt> et al</qref></item>
2503           <item><qref id="f-Standards-Version"><tt>Standards-Version</tt></qref> (recommended)</item>
2504           <item><qref id="f-Files"><tt>Files</tt></qref> (mandatory)</item>
2505           <item><qref id="f-Homepage"><tt>Homepage</tt></qref></item>
2506         </list>
2507         </p>
2508
2509         <p>
2510           The source package control file is generated by
2511           <prgn>dpkg-source</prgn> when it builds the source
2512           archive, from other files in the source package,
2513           described above.  When unpacking, it is checked against
2514           the files and directories in the other parts of the
2515           source package.
2516         </p>
2517
2518       </sect>
2519
2520       <sect id="debianchangesfiles">
2521         <heading>Debian changes files -- <file>.changes</file></heading>
2522
2523         <p>
2524           The .changes files are used by the Debian archive maintenance
2525           software to process updates to packages. They contain one
2526           paragraph which contains information from the
2527           <tt>debian/control</tt> file and other data about the
2528           source package gathered via <tt>debian/changelog</tt>
2529           and <tt>debian/rules</tt>.
2530         </p>
2531
2532         <p>
2533           The fields in this file are:
2534
2535           <list compact="compact">
2536             <item><qref id="f-Format"><tt>Format</tt></qref> (mandatory)</item>
2537             <item><qref id="f-Date"><tt>Date</tt></qref> (mandatory)</item>
2538             <item><qref id="f-Source"><tt>Source</tt></qref> (mandatory)</item>
2539             <item><qref id="f-Binary"><tt>Binary</tt></qref> (mandatory)</item>
2540             <item><qref id="f-Architecture"><tt>Architecture</tt></qref> (mandatory)</item>
2541             <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
2542             <item><qref id="f-Distribution"><tt>Distribution</tt></qref> (mandatory)</item>
2543             <item><qref id="f-Urgency"><tt>Urgency</tt></qref> (recommended)</item>
2544             <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
2545             <item><qref id="f-Changed-By"><tt>Changed-By</tt></qref></item>
2546             <item><qref id="f-Description"><tt>Description</tt></qref> (mandatory)</item>
2547             <item><qref id="f-Closes"><tt>Closes</tt></qref></item>
2548             <item><qref id="f-Changes"><tt>Changes</tt></qref> (mandatory)</item>
2549             <item><qref id="f-Files"><tt>Files</tt></qref> (mandatory)</item>
2550           </list>
2551         </p>
2552       </sect>
2553
2554       <sect id="controlfieldslist">
2555         <heading>List of fields</heading>
2556
2557         <sect1 id="f-Source">
2558           <heading><tt>Source</tt></heading>
2559
2560           <p>
2561             This field identifies the source package name.
2562           </p>
2563
2564           <p>
2565             In <file>debian/control</file> or a <file>.dsc</file> file,
2566             this field must contain only the name of the source package.
2567           </p>
2568
2569           <p>
2570             In a binary package control file or a <file>.changes</file>
2571             file, the source package name may be followed by a version
2572             number in parentheses<footnote>
2573                 It is customary to leave a space after the package name
2574                 if a version number is specified.
2575             </footnote>.
2576             This version number may be omitted (and is, by
2577             <prgn>dpkg-gencontrol</prgn>) if it has the same value as
2578             the <tt>Version</tt> field of the binary package in
2579             question.  The field itself may be omitted from a binary
2580             package control file when the source package has the same
2581             name and version as the binary package.
2582           </p>
2583         </sect1>
2584
2585         <sect1 id="f-Maintainer">
2586           <heading><tt>Maintainer</tt></heading>
2587
2588           <p>
2589             The package maintainer's name and email address.  The name
2590             should come first, then the email address inside angle
2591             brackets <tt>&lt;&gt</tt> (in RFC822 format).
2592           </p>
2593
2594           <p>
2595             If the maintainer's name contains a full stop then the
2596             whole field will not work directly as an email address due
2597             to a misfeature in the syntax specified in RFC822; a
2598             program using this field as an address must check for this
2599             and correct the problem if necessary (for example by
2600             putting the name in round brackets and moving it to the
2601             end, and bringing the email address forward).
2602           </p>
2603         </sect1>
2604
2605         <sect1 id="f-Uploaders">
2606           <heading><tt>Uploaders</tt></heading>
2607
2608           <p>
2609             List of the names and email addresses of co-maintainers of
2610             the package, if any. If the package has other maintainers
2611             beside the one named in the 
2612             <qref id="f-Maintainer">Maintainer field</qref>, their
2613             names and email addresses should be listed here. The
2614             format is the same as that of the Maintainer tag, and
2615             multiple entries should be comma separated. Currently,
2616             this field is restricted to a single line of data.  This
2617             is an optional field.
2618           </p>
2619           <p>
2620             Any parser that interprets the Uploaders field in
2621             <file>debian/control</file> must permit it to span multiple
2622             lines.  Line breaks in an Uploaders field that spans multiple
2623             lines are not significant and the semantics of the field are
2624             the same as if the line breaks had not been present.
2625           </p>
2626         </sect1>
2627
2628         <sect1 id="f-Changed-By">
2629           <heading><tt>Changed-By</tt></heading>
2630
2631           <p>
2632             The name and email address of the person who changed the
2633             said package. Usually the name of the maintainer.
2634             All the rules for the Maintainer field apply here, too.
2635           </p>
2636         </sect1>
2637
2638         <sect1 id="f-Section">
2639           <heading><tt>Section</tt></heading>
2640
2641           <p>
2642             This field specifies an application area into which the package
2643             has been classified. See <ref id="subsections">.
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-Priority">
2656           <heading><tt>Priority</tt></heading>
2657
2658           <p>
2659             This field represents how important that it is that the user
2660             have the package installed. See <ref id="priorities">.
2661           </p>
2662
2663           <p>
2664             When it appears in the <file>debian/control</file> file,
2665             it gives the value for the subfield of the same name in
2666             the <tt>Files</tt> field of the <file>.changes</file> file.
2667             It also gives the default for the same field in the binary
2668             packages.
2669           </p>
2670         </sect1>
2671
2672         <sect1 id="f-Package">
2673           <heading><tt>Package</tt></heading>
2674
2675           <p>
2676             The name of the binary package.
2677           </p>
2678
2679           <p>
2680             Package names must consist only of lower case letters
2681             (<tt>a-z</tt>), digits (<tt>0-9</tt>), plus (<tt>+</tt>)
2682             and minus (<tt>-</tt>) signs, and periods (<tt>.</tt>).
2683             They must be at least two characters long and must start
2684             with an alphanumeric character.
2685           </p>
2686         </sect1>
2687
2688         <sect1 id="f-Architecture">
2689           <heading><tt>Architecture</tt></heading>
2690
2691           <p>
2692             Depending on context and the control file used, the
2693             <tt>Architecture</tt> field can include the following sets of
2694             values:
2695             <list>
2696                 <item>A unique single word identifying a Debian machine
2697                       architecture, see <ref id="arch-spec">.
2698                 <item><tt>all</tt>, which indicates an
2699                       architecture-independent package.
2700                 <item><tt>any</tt>, which indicates a package available
2701                       for building on any architecture.
2702                 <item><tt>source</tt>, which indicates a source package.
2703             </list>
2704           </p>
2705
2706           <p>
2707             In the main <file>debian/control</file> file in the source
2708             package, or in the source package control file
2709             <file>.dsc</file>, one may specify a list of architectures
2710             separated by spaces, or the special values <tt>any</tt> or
2711             <tt>all</tt>.
2712           </p>
2713
2714           <p>
2715             Specifying <tt>any</tt> indicates that the source package
2716             isn't dependent on any particular architecture and should
2717             compile fine on any one. The produced binary package(s)
2718             will be specific to whatever the current build architecture
2719             is.<footnote>
2720                 This is the most often used setting, and is recommended
2721                 for new packages that aren't <tt>Architecture: all</tt>.
2722             </footnote>
2723           </p>
2724
2725           <p>
2726             Specifying a list of architectures indicates that the source
2727             will build an architecture-dependent package, and will only
2728             work correctly on the listed architectures.<footnote>
2729                 This is a setting used for a minority of cases where the
2730                 program is not portable. Generally, it should not be used
2731                 for new packages.
2732             </footnote>
2733           </p>
2734
2735           <p>
2736             In a <file>.changes</file> file, the <tt>Architecture</tt>
2737             field lists the architecture(s) of the package(s)
2738             currently being uploaded.  This will be a list; if the
2739             source for the package is also being uploaded, the special
2740             entry <tt>source</tt> is also present.
2741           </p>
2742
2743           <p>
2744             See <ref id="debianrules"> for information how to get the
2745             architecture for the build process.
2746           </p>
2747         </sect1>
2748
2749         <sect1 id="f-Essential">
2750           <heading><tt>Essential</tt></heading>
2751
2752           <p>
2753             This is a boolean field which may occur only in the
2754             control file of a binary package or in a per-package fields
2755             paragraph of a main source control data file.
2756           </p>
2757
2758           <p>
2759             If set to <tt>yes</tt> then the package management system
2760             will refuse to remove the package (upgrading and replacing
2761             it is still possible). The other possible value is <tt>no</tt>,
2762             which is the same as not having the field at all.
2763           </p>
2764         </sect1>
2765
2766         <sect1>
2767           <heading>Package interrelationship fields:
2768             <tt>Depends</tt>, <tt>Pre-Depends</tt>,
2769             <tt>Recommends</tt>, <tt>Suggests</tt>,
2770             <tt>Breaks</tt>, <tt>Conflicts</tt>,
2771             <tt>Provides</tt>, <tt>Replaces</tt>, <tt>Enhances</tt>
2772           </heading>
2773
2774           <p>
2775             These fields describe the package's relationships with
2776             other packages.  Their syntax and semantics are described
2777             in <ref id="relationships">.</p>
2778         </sect1>
2779
2780         <sect1 id="f-Standards-Version">
2781           <heading><tt>Standards-Version</tt></heading>
2782
2783           <p>
2784             The most recent version of the standards (the policy
2785             manual and associated texts) with which the package
2786             complies.
2787           </p>
2788
2789           <p>
2790             The version number has four components: major and minor
2791             version number and major and minor patch level.  When the
2792             standards change in a way that requires every package to
2793             change the major number will be changed.  Significant
2794             changes that will require work in many packages will be
2795             signaled by a change to the minor number.  The major patch
2796             level will be changed for any change to the meaning of the
2797             standards, however small; the minor patch level will be
2798             changed when only cosmetic, typographical or other edits
2799             are made which neither change the meaning of the document
2800             nor affect the contents of packages.
2801           </p>
2802
2803           <p>
2804             Thus only the first three components of the policy version
2805             are significant in the <em>Standards-Version</em> control
2806             field, and so either these three components or the all
2807             four components may be specified.<footnote>
2808                 In the past, people specified the full version number
2809                 in the Standards-Version field, for example "2.3.0.0".
2810                 Since minor patch-level changes don't introduce new
2811                 policy, it was thought it would be better to relax
2812                 policy and only require the first 3 components to be
2813                 specified, in this example "2.3.0".  All four
2814                 components may still be used if someone wishes to do so.
2815             </footnote>
2816           </p>
2817
2818         </sect1>
2819
2820         <sect1 id="f-Version">
2821           <heading><tt>Version</tt></heading>
2822
2823           <p>
2824             The version number of a package. The format is:
2825             [<var>epoch</var><tt>:</tt>]<var>upstream_version</var>[<tt>-</tt><var>debian_revision</var>]
2826           </p>
2827
2828           <p>
2829             The three components here are:
2830             <taglist>
2831               <tag><var>epoch</var></tag>
2832               <item>
2833                 <p>
2834                   This is a single (generally small) unsigned integer.  It
2835                   may be omitted, in which case zero is assumed.  If it is
2836                   omitted then the <var>upstream_version</var> may not
2837                   contain any colons.
2838                 </p>
2839
2840                 <p>
2841                   It is provided to allow mistakes in the version numbers
2842                   of older versions of a package, and also a package's
2843                   previous version numbering schemes, to be left behind.
2844                 </p>
2845               </item>
2846
2847               <tag><var>upstream_version</var></tag>
2848               <item>
2849                 <p>
2850                   This is the main part of the version number.  It is
2851                   usually the version number of the original ("upstream")
2852                   package from which the <file>.deb</file> file has been made,
2853                   if this is applicable.  Usually this will be in the same
2854                   format as that specified by the upstream author(s);
2855                   however, it may need to be reformatted to fit into the
2856                   package management system's format and comparison
2857                   scheme.
2858                 </p>
2859
2860                 <p>
2861                   The comparison behavior of the package management system
2862                   with respect to the <var>upstream_version</var> is
2863                   described below.  The <var>upstream_version</var>
2864                   portion of the version number is mandatory.
2865                 </p>
2866
2867                 <p>
2868                   The <var>upstream_version</var> may contain only
2869                   alphanumerics<footnote>
2870                         Alphanumerics are <tt>A-Za-z0-9</tt> only.
2871                   </footnote>
2872                   and the characters <tt>.</tt> <tt>+</tt> <tt>-</tt>
2873                   <tt>:</tt> <tt>~</tt> (full stop, plus, hyphen, colon,
2874                   tilde) and should start with a digit.  If there is no
2875                   <var>debian_revision</var> then hyphens are not allowed;
2876                   if there is no <var>epoch</var> then colons are not
2877                   allowed.
2878                 </p>
2879               </item>
2880
2881               <tag><var>debian_revision</var></tag>
2882               <item>
2883                 <p>
2884                   This part of the version number specifies the version of
2885                   the Debian package based on the upstream version.  It
2886                   may contain only alphanumerics and the characters
2887                   <tt>+</tt> <tt>.</tt> <tt>~</tt> (plus, full stop,
2888                   tilde) and is compared in the same way as the
2889                   <var>upstream_version</var> is.
2890                 </p>
2891
2892                 <p>
2893                   It is optional; if it isn't present then the
2894                   <var>upstream_version</var> may not contain a hyphen.
2895                   This format represents the case where a piece of
2896                   software was written specifically to be turned into a
2897                   Debian package, and so there is only one "debianisation"
2898                   of it and therefore no revision indication is required.
2899                 </p>
2900
2901                 <p>
2902                   It is conventional to restart the
2903                   <var>debian_revision</var> at <tt>1</tt> each time the
2904                   <var>upstream_version</var> is increased.
2905                 </p>
2906
2907                 <p>
2908                   The package management system will break the version
2909                   number apart at the last hyphen in the string (if there
2910                   is one) to determine the <var>upstream_version</var> and
2911                   <var>debian_revision</var>.  The absence of a
2912                   <var>debian_revision</var> is equivalent to a
2913                   <var>debian_revision</var> of <tt>0</tt>.
2914                 </p>
2915               </item>
2916             </taglist>
2917           </p>
2918
2919           <p>
2920             When comparing two version numbers, first the <var>epoch</var>
2921             of each are compared, then the <var>upstream_version</var> if
2922             <var>epoch</var> is equal, and then <var>debian_revision</var>
2923             if <var>upstream_version</var> is also equal.
2924             <var>epoch</var> is compared numerically.  The
2925             <var>upstream_version</var> and <var>debian_revision</var>
2926             parts are compared by the package management system using the
2927             following algorithm:
2928           </p>
2929
2930           <p>
2931             The strings are compared from left to right.
2932           </p>
2933
2934           <p>
2935             First the initial part of each string consisting entirely of
2936             non-digit characters is determined.  These two parts (one of
2937             which may be empty) are compared lexically.  If a difference
2938             is found it is returned.  The lexical comparison is a
2939             comparison of ASCII values modified so that all the letters
2940             sort earlier than all the non-letters and so that a tilde
2941             sorts before anything, even the end of a part.  For example,
2942             the following parts are in sorted order from earliest to
2943             latest: <tt>~~</tt>, <tt>~~a</tt>, <tt>~</tt>, the empty part,
2944             <tt>a</tt>.<footnote>
2945               One common use of <tt>~</tt> is for upstream pre-releases.
2946               For example, <tt>1.0~beta1~svn1245</tt> sorts earlier than
2947               <tt>1.0~beta1</tt>, which sorts earlier than <tt>1.0</tt>.
2948             </footnote>
2949           </p>
2950
2951           <p>
2952             Then the initial part of the remainder of each string which
2953             consists entirely of digit characters is determined.  The
2954             numerical values of these two parts are compared, and any
2955             difference found is returned as the result of the comparison.
2956             For these purposes an empty string (which can only occur at
2957             the end of one or both version strings being compared) counts
2958             as zero.
2959           </p>
2960
2961           <p>
2962             These two steps (comparing and removing initial non-digit
2963             strings and initial digit strings) are repeated until a
2964             difference is found or both strings are exhausted.
2965           </p>
2966
2967           <p>
2968             Note that the purpose of epochs is to allow us to leave behind
2969             mistakes in version numbering, and to cope with situations
2970             where the version numbering scheme changes.  It is
2971             <em>not</em> intended to cope with version numbers containing
2972             strings of letters which the package management system cannot
2973             interpret (such as <tt>ALPHA</tt> or <tt>pre-</tt>), or with
2974             silly orderings (the author of this manual has heard of a
2975             package whose versions went <tt>1.1</tt>, <tt>1.2</tt>,
2976             <tt>1.3</tt>, <tt>1</tt>, <tt>2.1</tt>, <tt>2.2</tt>,
2977             <tt>2</tt> and so forth).
2978           </p>
2979         </sect1>
2980
2981         <sect1 id="f-Description">
2982           <heading><tt>Description</tt></heading>
2983
2984           <p>
2985             In a source or binary control file, the <tt>Description</tt>
2986             field contains a description of the binary package, consisting
2987             of two parts, the synopsis or the short description, and the
2988             long description. The field's format is as follows:
2989           </p>
2990
2991           <p>
2992 <example>
2993         Description: &lt;single line synopsis&gt;
2994          &lt;extended description over several lines&gt;
2995 </example>
2996           </p>
2997
2998           <p>
2999             The lines in the extended description can have these formats:
3000           </p>
3001
3002           <p><list>
3003
3004             <item>
3005               Those starting with a single space are part of a paragraph.
3006               Successive lines of this form will be word-wrapped when
3007               displayed. The leading space will usually be stripped off.
3008             </item>
3009
3010             <item>
3011               Those starting with two or more spaces. These will be
3012               displayed verbatim. If the display cannot be panned
3013               horizontally, the displaying program will line wrap them "hard"
3014               (i.e., without taking account of word breaks). If it can they
3015               will be allowed to trail off to the right. None, one or two
3016               initial spaces may be deleted, but the number of spaces
3017               deleted from each line will be the same (so that you can have
3018               indenting work correctly, for example).
3019             </item>
3020
3021             <item>
3022               Those containing a single space followed by a single full stop
3023               character. These are rendered as blank lines. This is the
3024               <em>only</em> way to get a blank line<footnote>
3025                 Completely empty lines will not be rendered as blank lines.
3026                 Instead, they will cause the parser to think you're starting
3027                 a whole new record in the control file, and will therefore
3028                 likely abort with an error.
3029               </footnote>.
3030             </item>
3031
3032             <item>
3033               Those containing a space, a full stop and some more characters.
3034               These are for future expansion. Do not use them.
3035             </item>
3036
3037           </list></p>
3038
3039           <p>
3040             Do not use tab characters.  Their effect is not predictable.
3041           </p>
3042
3043           <p>
3044             See <ref id="descriptions"> for further information on this.
3045           </p>
3046
3047           <p>
3048             In a <file>.changes</file> file, the <tt>Description</tt> field
3049             contains a summary of the descriptions for the packages being
3050             uploaded.
3051           </p>
3052
3053           <p>
3054             The part of the field before the first newline is empty;
3055             thereafter each line has the name of a binary package and
3056             the summary description line from that binary package.
3057             Each line is indented by one space.
3058           </p>
3059
3060         </sect1>
3061
3062         <sect1 id="f-Distribution">
3063           <heading><tt>Distribution</tt></heading>
3064
3065           <p>
3066             In a <file>.changes</file> file or parsed changelog output
3067             this contains the (space-separated) name(s) of the
3068             distribution(s) where this version of the package should
3069             be installed.  Valid distributions are determined by the
3070             archive maintainers.<footnote>
3071                 Current distribution names are:
3072                 <taglist compact="compact">
3073                   <tag><em>stable</em></tag>
3074                   <item>
3075                       This is the current "released" version of Debian
3076                       GNU/Linux.  Once the distribution is
3077                       <em>stable</em> only security fixes and other
3078                       major bug fixes are allowed. When changes are
3079                       made to this distribution, the release number is
3080                       increased (for example: 2.2r1 becomes 2.2r2 then
3081                       2.2r3, etc).
3082                   </item>
3083
3084                   <tag><em>unstable</em></tag>
3085                   <item>
3086                       This distribution value refers to the
3087                       <em>developmental</em> part of the Debian
3088                       distribution tree. New packages, new upstream
3089                       versions of packages and bug fixes go into the
3090                       <em>unstable</em> directory tree. Download from
3091                       this distribution at your own risk.
3092                   </item>
3093
3094                   <tag><em>testing</em></tag>
3095                   <item>
3096                       This distribution value refers to the
3097                       <em>testing</em> part of the Debian distribution
3098                       tree.  It receives its packages from the
3099                       unstable distribution after a short time lag to
3100                       ensure that there are no major issues with the
3101                       unstable packages.  It is less prone to breakage
3102                       than unstable, but still risky.  It is not
3103                       possible to upload packages directly to
3104                       <em>testing</em>.
3105                   </item>
3106
3107                   <tag><em>frozen</em></tag>
3108                   <item>
3109                       From time to time, the <em>testing</em>
3110                       distribution enters a state of "code-freeze" in
3111                       anticipation of release as a <em>stable</em>
3112                       version. During this period of testing only
3113                       fixes for existing or newly-discovered bugs will
3114                       be allowed.  The exact details of this stage are
3115                       determined by the Release Manager.
3116                   </item>
3117
3118                   <tag><em>experimental</em></tag>
3119                   <item>
3120                       The packages with this distribution value are
3121                       deemed by their maintainers to be high
3122                       risk. Oftentimes they represent early beta or
3123                       developmental packages from various sources that
3124                       the maintainers want people to try, but are not
3125                       ready to be a part of the other parts of the
3126                       Debian distribution tree. Download at your own
3127                       risk.
3128                   </item>
3129                 </taglist>
3130
3131                 <p>
3132                   You should list <em>all</em> distributions that the
3133                   package should be installed into.
3134                 </p>
3135
3136                 <p>
3137                   More information is available in the Debian Developer's
3138                   Reference, section "The Debian archive".
3139                 </p>
3140             </footnote>
3141           </p>
3142         </sect1>
3143
3144         <sect1 id="f-Date">
3145           <heading><tt>Date</tt></heading>
3146
3147           <p>
3148             This field includes the date the package was built or last edited.
3149           </p>
3150
3151           <p>
3152             The value of this field is usually extracted from the
3153             <file>debian/changelog</file> file - see
3154             <ref id="dpkgchangelog">).
3155           </p>
3156         </sect1>
3157
3158         <sect1 id="f-Format">
3159           <heading><tt>Format</tt></heading>
3160
3161           <p>
3162             This field specifies a format revision for the file.
3163             The most current format described in the Policy Manual
3164             is version <strong>1.5</strong>.  The syntax of the
3165             format value is the same as that of a package version
3166             number except that no epoch or Debian revision is allowed
3167             - see <ref id="f-Version">.
3168           </p>
3169         </sect1>
3170
3171         <sect1 id="f-Urgency">
3172           <heading><tt>Urgency</tt></heading>
3173
3174           <p>
3175             This is a description of how important it is to upgrade to
3176             this version from previous ones.  It consists of a single
3177             keyword taking one of the values <tt>low</tt>,
3178             <tt>medium</tt>, <tt>high</tt>, <tt>emergency</tt>, or
3179             <tt>critical</tt><footnote>
3180               Other urgency values are supported with configuration
3181               changes in the archive software but are not used in Debian.
3182               The urgency affects how quickly a package will be considered
3183               for inclusion into the <tt>testing</tt> distribution and
3184               gives an indication of the importance of any fixes included
3185               in the upload.  <tt>Emergency</tt> and <tt>critical</tt> are
3186               treated as synonymous.
3187             </footnote> (not case-sensitive) followed by an optional
3188             commentary (separated by a space) which is usually in
3189             parentheses.  For example:
3190
3191             <example>
3192   Urgency: low (HIGH for users of diversions)
3193             </example>
3194
3195           </p>
3196
3197           <p>
3198             The value of this field is usually extracted from the
3199             <file>debian/changelog</file> file - see
3200             <ref id="dpkgchangelog">.
3201           </p>
3202         </sect1>
3203
3204         <sect1 id="f-Changes">
3205           <heading><tt>Changes</tt></heading>
3206
3207           <p>
3208             This field contains the human-readable changes data, describing
3209             the differences between the last version and the current one.
3210           </p>
3211
3212           <p>
3213             There should be nothing in this field before the first
3214             newline; all the subsequent lines must be indented by at
3215             least one space; blank lines must be represented by a line
3216             consisting only of a space and a full stop.
3217           </p>
3218
3219           <p>
3220             The value of this field is usually extracted from the
3221             <file>debian/changelog</file> file - see
3222             <ref id="dpkgchangelog">).
3223           </p>
3224
3225           <p>
3226             Each version's change information should be preceded by a
3227             "title" line giving at least the version, distribution(s)
3228             and urgency, in a human-readable way.
3229           </p>
3230
3231           <p>
3232             If data from several versions is being returned the entry
3233             for the most recent version should be returned first, and
3234             entries should be separated by the representation of a
3235             blank line (the "title" line may also be followed by the
3236             representation of blank line).
3237           </p>
3238         </sect1>
3239
3240         <sect1 id="f-Binary">
3241           <heading><tt>Binary</tt></heading>
3242
3243           <p>
3244             This field is a list of binary packages.
3245           </p>
3246
3247           <p>
3248             When it appears in the <file>.dsc</file> file it is the list
3249             of binary packages which a source package can produce.  It
3250             does not necessarily produce all of these binary packages
3251             for every architecture.  The source control file doesn't
3252             contain details of which architectures are appropriate for
3253             which of the binary packages.
3254           </p>
3255
3256           <p>
3257             When it appears in a <file>.changes</file> file it lists the
3258             names of the binary packages actually being uploaded.
3259           </p>
3260
3261           <p>
3262             The syntax is a list of binary packages separated by
3263             commas<footnote>
3264                 A space after each comma is conventional.
3265             </footnote>. Currently the packages must be separated using
3266             only spaces in the <file>.changes</file> file.
3267           </p>
3268         </sect1>
3269
3270         <sect1 id="f-Installed-Size">
3271           <heading><tt>Installed-Size</tt></heading>
3272
3273           <p>
3274             This field appears in the control files of binary
3275             packages, and in the <file>Packages</file> files.  It gives
3276             the total amount of disk space required to install the
3277             named package.
3278           </p>
3279
3280           <p>
3281             The disk space is represented in kilobytes as a simple
3282             decimal number.
3283           </p>
3284         </sect1>
3285
3286         <sect1 id="f-Files">
3287           <heading><tt>Files</tt></heading>
3288
3289           <p>
3290             This field contains a list of files with information about
3291             each one.  The exact information and syntax varies with
3292             the context.  In all cases the part of the field
3293             contents on the same line as the field name is empty.  The
3294             remainder of the field is one line per file, each line
3295             being indented by one space and containing a number of
3296             sub-fields separated by spaces.
3297           </p>
3298
3299           <p>
3300             In the <file>.dsc</file> file, each line contains the MD5
3301             checksum, size and filename of the tar file and (if applicable)
3302             diff file which make up the remainder of the source
3303             package<footnote>
3304                 That is, the parts which are not the <tt>.dsc</tt>.
3305             </footnote>.
3306             The exact forms of the filenames are described
3307             in <ref id="pkg-sourcearchives">.
3308           </p>
3309
3310           <p>
3311             In the <file>.changes</file> file this contains one line per
3312             file being uploaded.  Each line contains the MD5 checksum,
3313             size, section and priority and the filename.
3314             The <qref id="f-Section">section</qref>
3315             and <qref id="f-Priority">priority</qref>
3316             are the values of the corresponding fields in
3317             the main source control file.  If no section or priority is
3318             specified then <tt>-</tt> should be used, though section
3319             and priority values must be specified for new packages to
3320             be installed properly.
3321           </p>
3322
3323           <p>
3324             The special value <tt>byhand</tt> for the section in a
3325             <tt>.changes</tt> file indicates that the file in question
3326             is not an ordinary package file and must by installed by
3327             hand by the distribution maintainers.  If the section is
3328             <tt>byhand</tt> the priority should be <tt>-</tt>.
3329           </p>
3330
3331           <p>
3332             If a new Debian revision of a package is being shipped and
3333             no new original source archive is being distributed the
3334             <tt>.dsc</tt> must still contain the <tt>Files</tt> field
3335             entry for the original source archive
3336             <file><var>package</var>-<var>upstream-version</var>.orig.tar.gz</file>,
3337             but the <file>.changes</file> file should leave it out.  In
3338             this case the original source archive on the distribution
3339             site must match exactly, byte-for-byte, the original
3340             source archive which was used to generate the
3341             <file>.dsc</file> file and diff which are being uploaded.</p>
3342         </sect1>
3343
3344         <sect1 id="f-Closes">
3345           <heading><tt>Closes</tt></heading>
3346
3347           <p>
3348             A space-separated list of bug report numbers that the upload
3349             governed by the .changes file closes.
3350           </p>
3351         </sect1>
3352
3353         <sect1 id="f-Homepage">
3354           <heading><tt>Homepage</tt></heading>
3355
3356           <p>
3357             The URL of the web site for this package, preferably (when
3358             applicable) the site from which the original source can be
3359             obtained and any additional upstream documentation or
3360             information may be found.  The content of this field is a
3361             simple URL without any surrounding characters such as
3362             <tt>&lt;&gt;</tt>.
3363           </p>
3364         </sect1>
3365
3366       </sect>
3367
3368       <sect>
3369         <heading>User-defined fields</heading>
3370
3371         <p>
3372           Additional user-defined fields may be added to the
3373           source package control file.  Such fields will be
3374           ignored, and not copied to (for example) binary or
3375           source package control files or upload control files.
3376         </p>
3377
3378         <p>
3379           If you wish to add additional unsupported fields to
3380           these output files you should use the mechanism
3381           described here.
3382         </p>
3383
3384         <p>
3385           Fields in the main source control information file with
3386           names starting <tt>X</tt>, followed by one or more of
3387           the letters <tt>BCS</tt> and a hyphen <tt>-</tt>, will
3388           be copied to the output files.  Only the part of the
3389           field name after the hyphen will be used in the output
3390           file.  Where the letter <tt>B</tt> is used the field
3391           will appear in binary package control files, where the
3392           letter <tt>S</tt> is used in source package control
3393           files and where <tt>C</tt> is used in upload control
3394           (<tt>.changes</tt>) files.
3395         </p>
3396
3397         <p>
3398           For example, if the main source information control file
3399           contains the field
3400           <example>
3401   XBS-Comment: I stand between the candle and the star.
3402           </example>
3403           then the binary and source package control files will contain the
3404           field
3405           <example>
3406   Comment: I stand between the candle and the star.
3407           </example>
3408         </p>
3409
3410       </sect>
3411
3412     </chapt>
3413
3414
3415     <chapt id="maintainerscripts">
3416       <heading>Package maintainer scripts and installation procedure</heading>
3417
3418       <sect>
3419         <heading>Introduction to package maintainer scripts</heading>
3420
3421         <p>
3422           It is possible to supply scripts as part of a package which
3423           the package management system will run for you when your
3424           package is installed, upgraded or removed.
3425         </p>
3426
3427         <p>
3428           These scripts are the files <prgn>preinst</prgn>,
3429           <prgn>postinst</prgn>, <prgn>prerm</prgn> and
3430           <prgn>postrm</prgn> in the control area of the package.
3431           They must be proper executable files; if they are scripts
3432           (which is recommended), they must start with the usual
3433           <tt>#!</tt> convention.  They should be readable and
3434           executable by anyone, and must not be world-writable.
3435         </p>
3436
3437         <p>
3438           The package management system looks at the exit status from
3439           these scripts.  It is important that they exit with a
3440           non-zero status if there is an error, so that the package
3441           management system can stop its processing.  For shell
3442           scripts this means that you <em>almost always</em> need to
3443           use <tt>set -e</tt> (this is usually true when writing shell
3444           scripts, in fact).  It is also important, of course, that
3445           they exit with a zero status if everything went well.
3446         </p>
3447
3448         <p>
3449           Additionally, packages interacting with users using
3450           <tt>debconf</tt> in the <prgn>postinst</prgn> script should
3451           install a <prgn>config</prgn> script  in the control area,
3452           see <ref id="maintscriptprompt"> for details.
3453         </p>
3454
3455         <p>
3456           When a package is upgraded a combination of the scripts from
3457           the old and new packages is called during the upgrade
3458           procedure.  If your scripts are going to be at all
3459           complicated you need to be aware of this, and may need to
3460           check the arguments to your scripts.
3461         </p>
3462
3463         <p>
3464           Broadly speaking the <prgn>preinst</prgn> is called before
3465           (a particular version of) a package is installed, and the
3466           <prgn>postinst</prgn> afterwards; the <prgn>prerm</prgn>
3467           before (a version of) a package is removed and the
3468           <prgn>postrm</prgn> afterwards.
3469         </p>
3470
3471         <p>
3472           Programs called from maintainer scripts should not normally
3473           have a path prepended to them. Before installation is
3474           started, the package management system checks to see if the
3475           programs <prgn>ldconfig</prgn>,
3476           <prgn>start-stop-daemon</prgn>, <prgn>install-info</prgn>,
3477           and <prgn>update-rc.d</prgn> can be found via the
3478           <tt>PATH</tt> environment variable. Those programs, and any
3479           other program that one would expect to be in the
3480           <tt>PATH</tt>, should thus be invoked without an absolute
3481           pathname. Maintainer scripts should also not reset the
3482           <tt>PATH</tt>, though they might choose to modify it by
3483           prepending or appending package-specific directories. These
3484           considerations really apply to all shell scripts.</p>
3485       </sect>
3486
3487       <sect id="idempotency">
3488         <heading>Maintainer scripts idempotency</heading>
3489
3490         <p>
3491           It is necessary for the error recovery procedures that the
3492           scripts be idempotent.  This means that if it is run
3493           successfully, and then it is called again, it doesn't bomb
3494           out or cause any harm, but just ensures that everything is
3495           the way it ought to be.  If the first call failed, or
3496           aborted half way through for some reason, the second call
3497           should merely do the things that were left undone the first
3498           time, if any, and exit with a success status if everything
3499           is OK.<footnote>
3500               This is so that if an error occurs, the user interrupts
3501               <prgn>dpkg</prgn> or some other unforeseen circumstance
3502               happens you don't leave the user with a badly-broken
3503               package when <prgn>dpkg</prgn> attempts to repeat the
3504               action.
3505           </footnote>
3506         </p>
3507       </sect>
3508
3509       <sect id="controllingterminal">
3510         <heading>Controlling terminal for maintainer scripts</heading>
3511
3512         <p>
3513           The maintainer scripts are guaranteed to run with a
3514           controlling terminal and can interact with the user.
3515           Because these scripts may be executed with standard output
3516           redirected into a pipe for logging purposes, Perl scripts
3517           should set unbuffered output by setting <tt>$|=1</tt> so
3518           that the output is printed immediately rather than being
3519           buffered.
3520         </p>
3521       </sect>
3522       <sect id="exitstatus">
3523         <heading>Exit status</heading>
3524
3525         <p>
3526           Each script must return a zero exit status for
3527           success, or a nonzero one for failure, since the package
3528           management system looks for the exit status of these scripts
3529           and determines what action to take next based on that datum.
3530         </p>
3531       </sect>
3532
3533       <sect id="mscriptsinstact"><heading>Summary of ways maintainer
3534           scripts are called
3535         </heading>
3536
3537         <p>
3538           <list compact="compact">
3539             <item>
3540               <var>new-preinst</var> <tt>install</tt>
3541             </item>
3542             <item>
3543               <var>new-preinst</var> <tt>install</tt> <var>old-version</var>
3544             </item>
3545             <item>
3546                 <var>new-preinst</var> <tt>upgrade</tt> <var>old-version</var>
3547             </item>
3548             <item>
3549                 <var>old-preinst</var> <tt>abort-upgrade</tt>
3550                 <var>new-version</var>
3551             </item>
3552           </list>
3553
3554         <p>
3555           <list compact="compact">
3556             <item>
3557                 <var>postinst</var> <tt>configure</tt>
3558                 <var>most-recently-configured-version</var>
3559             </item>
3560             <item>
3561                 <var>old-postinst</var> <tt>abort-upgrade</tt>
3562                 <var>new-version</var>
3563             </item>
3564             <item>
3565                 <var>conflictor's-postinst</var> <tt>abort-remove</tt>
3566                 <tt>in-favour</tt> <var>package</var>
3567                 <var>new-version</var>
3568             </item>
3569             <item>
3570                 <var>postinst</var> <tt>abort-remove</tt>
3571             </item>
3572             <item>
3573                 <var>deconfigured's-postinst</var>
3574                 <tt>abort-deconfigure</tt> <tt>in-favour</tt>
3575                 <var>failed-install-package</var> <var>version</var>
3576                 [<tt>removing</tt> <var>conflicting-package</var>
3577                 <var>version</var>]
3578             </item>
3579           </list>
3580
3581         <p>
3582           <list compact="compact">
3583             <item>
3584                 <var>prerm</var> <tt>remove</tt>
3585             </item>
3586             <item>
3587                 <var>old-prerm</var> <tt>upgrade</tt>
3588                 <var>new-version</var>
3589             </item>
3590             <item>
3591                 <var>new-prerm</var> <tt>failed-upgrade</tt>
3592                 <var>old-version</var>
3593             </item>
3594             <item>
3595                 <var>conflictor's-prerm</var> <tt>remove</tt>
3596                 <tt>in-favour</tt> <var>package</var>
3597                 <var>new-version</var>
3598             </item>
3599             <item>
3600                 <var>deconfigured's-prerm</var> <tt>deconfigure</tt>
3601                 <tt>in-favour</tt> <var>package-being-installed</var>
3602                 <var>version</var> [<tt>removing</tt>
3603                 <var>conflicting-package</var>
3604                 <var>version</var>]
3605             </item>
3606           </list>
3607
3608         <p>
3609           <list compact="compact">
3610             <item>
3611                 <var>postrm</var> <tt>remove</tt>
3612             </item>
3613             <item>
3614                 <var>postrm</var> <tt>purge</tt>
3615             </item>
3616             <item>
3617                 <var>old-postrm</var> <tt>upgrade</tt>
3618                 <var>new-version</var>
3619             </item>
3620             <item>
3621                 <var>new-postrm</var> <tt>failed-upgrade</tt>
3622                 <var>old-version</var>
3623             </item>
3624             <item>
3625                 <var>new-postrm</var> <tt>abort-install</tt>
3626             </item>
3627             <item>
3628                 <var>new-postrm</var> <tt>abort-install</tt>
3629                 <var>old-version</var>
3630             </item>
3631             <item>
3632                 <var>new-postrm</var> <tt>abort-upgrade</tt>
3633                 <var>old-version</var>
3634             </item>
3635             <item>
3636                 <var>disappearer's-postrm</var> <tt>disappear</tt>
3637                 <var>overwriter</var>
3638                 <var>overwriter-version</var>
3639             </item>
3640           </list>
3641         </p>
3642
3643
3644       <sect id="unpackphase">
3645         <heading>Details of unpack phase of installation or upgrade</heading>
3646
3647         <p>
3648           The procedure on installation/upgrade/overwrite/disappear
3649           (i.e., when running <tt>dpkg --unpack</tt>, or the unpack
3650           stage of <tt>dpkg --install</tt>) is as follows.  In each
3651           case, if a major error occurs (unless listed below) the
3652           actions are, in general, run backwards - this means that the
3653           maintainer scripts are run with different arguments in
3654           reverse order.  These are the "error unwind" calls listed
3655           below.
3656
3657           <enumlist>
3658             <item>
3659                 <enumlist>
3660                   <item>
3661                       If a version of the package is already installed, call
3662                       <example compact="compact">
3663 <var>old-prerm</var> upgrade <var>new-version</var>
3664                       </example>
3665                   </item>
3666                   <item>
3667                       If the script runs but exits with a non-zero
3668                       exit status, <prgn>dpkg</prgn> will attempt:
3669                       <example compact="compact">
3670 <var>new-prerm</var> failed-upgrade <var>old-version</var>
3671                       </example>
3672                       If this works, the upgrade continues. If this
3673                       does not work, the error unwind:
3674                       <example compact="compact">
3675 <var>old-postinst</var> abort-upgrade <var>new-version</var>
3676                       </example>
3677                       If this works, then the old-version is
3678                       "Installed", if not, the old version is in a
3679                       "Failed-Config" state.
3680                   </item>
3681                 </enumlist>
3682             </item>
3683
3684             <item>
3685                 If a "conflicting" package is being removed at the same time,
3686                 or if any package will be broken (due to <tt>Breaks</tt>):
3687                 <enumlist>
3688                   <item>
3689                       If <tt>--auto-deconfigure</tt> is
3690                       specified, call, for each package to be deconfigured
3691                       due to <tt>Breaks</tt>:
3692                       <example compact="compact">
3693 <var>deconfigured's-prerm</var> deconfigure \
3694   in-favour <var>package-being-installed</var> <var>version</var>
3695                       </example>
3696                       Error unwind:
3697                       <example compact="compact">
3698 <var>deconfigured's-postinst</var> abort-deconfigure \
3699   in-favour <var>package-being-installed-but-failed</var> <var>version</var>
3700                       </example>
3701                       The deconfigured packages are marked as
3702                       requiring configuration, so that if
3703                       <tt>--install</tt> is used they will be
3704                       configured again if possible.
3705                   </item>
3706                   <item>
3707                       If any packages depended on a conflicting
3708                       package being removed and <tt>--auto-deconfigure</tt> is
3709                       specified, call, for each such package:
3710                       <example compact="compact">
3711 <var>deconfigured's-prerm</var> deconfigure \
3712   in-favour <var>package-being-installed</var> <var>version</var> \
3713     removing <var>conflicting-package</var> <var>version</var>
3714                       </example>
3715                       Error unwind:
3716                       <example compact="compact">
3717 <var>deconfigured's-postinst</var> abort-deconfigure \
3718   in-favour <var>package-being-installed-but-failed</var> <var>version</var> \
3719     removing <var>conflicting-package</var> <var>version</var>
3720                       </example>
3721                       The deconfigured packages are marked as
3722                       requiring configuration, so that if
3723                       <tt>--install</tt> is used they will be
3724                       configured again if possible.
3725                   </item>
3726                   <item>
3727                       To prepare for removal of each conflicting package, call:
3728                       <example compact="compact">
3729 <var>conflictor's-prerm</var> remove \
3730   in-favour <var>package</var> <var>new-version</var>
3731                       </example>
3732                       Error unwind:
3733                       <example compact="compact">
3734 <var>conflictor's-postinst</var> abort-remove \
3735   in-favour <var>package</var> <var>new-version</var>
3736                       </example>
3737                   </item>
3738                 </enumlist>
3739             </item>
3740
3741             <item>
3742                 <enumlist>
3743                   <item>
3744                       If the package is being upgraded, call:
3745                       <example compact="compact">
3746 <var>new-preinst</var> upgrade <var>old-version</var>
3747                       </example>
3748                       If this fails, we call:
3749                       <example>
3750 <var>new-postrm</var> abort-upgrade <var>old-version</var>
3751                       </example>
3752                       <enumlist>
3753                         <item>
3754                           <p>
3755                             If that works, then
3756                             <example>
3757 <var>old-postinst</var> abort-upgrade <var>new-version</var>
3758                             </example>
3759                             is called. If this works, then the old version
3760                             is in an "Installed" state, or else it is left
3761                             in an "Unpacked" state.
3762                           </p>
3763                         </item>
3764                         <item>
3765                           <p>
3766                             If it fails, then the old version is left
3767                             in an "Half-Installed" state.
3768                           </p>
3769                         </item>
3770                       </enumlist>
3771                       
3772                   </item>
3773                   <item>
3774                       Otherwise, if the package had some configuration
3775                       files from a previous version installed (i.e., it
3776                       is in the "configuration files only" state):
3777                       <example compact="compact">
3778 <var>new-preinst</var> install <var>old-version</var>
3779                       </example>
3780                       Error unwind:
3781                       <example>
3782 <var>new-postrm</var> abort-install <var>old-version</var>
3783                       </example>
3784                       If this fails, the package is left in a
3785                       "Half-Installed" state, which requires a
3786                       reinstall. If it works, the packages is left in
3787                       a "Config Files" state.
3788                   </item>
3789                   <item>
3790                       Otherwise (i.e., the package was completely purged):
3791                       <example compact="compact">
3792 <var>new-preinst</var> install
3793                       </example>
3794                       Error unwind:
3795                       <example compact="compact">
3796 <var>new-postrm</var> abort-install
3797                       </example>
3798                       If the error-unwind fails, the package is in a
3799                       "Half Installed" phase, and requires a
3800                       reinstall. If the error unwind works, the
3801                       package is in a not installed state.
3802                   </item>
3803                 </enumlist>
3804             </item>
3805
3806             <item>
3807               <p>
3808                 The new package's files are unpacked, overwriting any
3809                 that may be on the system already, for example any
3810                 from the old version of the same package or from
3811                 another package.  Backups of the old files are kept
3812                 temporarily, and if anything goes wrong the package
3813                 management system will attempt to put them back as
3814                 part of the error unwind.
3815               </p>
3816
3817               <p>
3818                 It is an error for a package to contain files which
3819                 are on the system in another package, unless
3820                 <tt>Replaces</tt> is used (see <ref id="replaces">).
3821                 <!--
3822                 The following paragraph is not currently the case:
3823                 Currently the <tt>- - force-overwrite</tt> flag is
3824                 enabled, downgrading it to a warning, but this may not
3825                 always be the case.
3826                 -->
3827               </p>
3828
3829               <p>
3830                 It is a more serious error for a package to contain a
3831                 plain file or other kind of non-directory where another
3832                 package has a directory (again, unless
3833                 <tt>Replaces</tt> is used).  This error can be
3834                 overridden if desired using
3835                 <tt>--force-overwrite-dir</tt>, but this is not
3836                 advisable.
3837               </p>
3838
3839               <p>
3840                 Packages which overwrite each other's files produce
3841                 behavior which, though deterministic, is hard for the
3842                 system administrator to understand.  It can easily
3843                 lead to "missing" programs if, for example, a package
3844                 is installed which overwrites a file from another
3845                 package, and is then removed again.<footnote>
3846                     Part of the problem is due to what is arguably a
3847                     bug in <prgn>dpkg</prgn>.
3848                 </footnote>
3849               </p>
3850
3851               <p>
3852                 A directory will never be replaced by a symbolic link
3853                 to a directory or vice versa; instead, the existing
3854                 state (symlink or not) will be left alone and
3855                 <prgn>dpkg</prgn> will follow the symlink if there is
3856                 one.
3857               </p>
3858             </item>
3859
3860             <item>
3861               <p>
3862                 <enumlist>
3863                   <item>
3864                       If the package is being upgraded, call
3865                       <example compact="compact">
3866 <var>old-postrm</var> upgrade <var>new-version</var>
3867                       </example>
3868                   </item>
3869                   <item>
3870                       If this fails, <prgn>dpkg</prgn> will attempt:
3871                       <example compact="compact">
3872 <var>new-postrm</var> failed-upgrade <var>old-version</var>
3873                       </example>
3874                       If this works, installation continues. If not, 
3875                       Error unwind:
3876                       <example compact="compact">
3877 <var>old-preinst</var> abort-upgrade <var>new-version</var>
3878                       </example>
3879                       If this fails, the old version is left in an
3880                       "Half Installed" state. If it works, dpkg now
3881                       calls:
3882                       <example compact="compact">
3883 <var>new-postrm</var> abort-upgrade <var>old-version</var>
3884                       </example>
3885                       If this fails, the old version is left in an
3886                       "Half Installed" state. If it works, dpkg now
3887                       calls:
3888                       <example compact="compact">
3889 <var>old-postinst</var> abort-upgrade <var>new-version</var>
3890                       </example>
3891                       If this fails, the old version is in an
3892                       "Unpacked" state.
3893                   </item>
3894                 </enumlist>
3895               </p>
3896
3897               <p>
3898                 This is the point of no return - if
3899                 <prgn>dpkg</prgn> gets this far, it won't back off
3900                 past this point if an error occurs.  This will
3901                 leave the package in a fairly bad state, which
3902                 will require a successful re-installation to clear
3903                 up, but it's when <prgn>dpkg</prgn> starts doing
3904                 things that are irreversible.
3905               </p>
3906             </item>
3907
3908             <item>
3909                 Any files which were in the old version of the package
3910                 but not in the new are removed.
3911             </item>
3912
3913             <item>
3914                 The new file list replaces the old.
3915             </item>
3916
3917             <item>
3918                 The new maintainer scripts replace the old.
3919             </item>
3920
3921             <item>
3922                 Any packages all of whose files have been overwritten
3923                 during the installation, and which aren't required for
3924                 dependencies, are considered to have been removed.
3925                 For each such package
3926                 <enumlist>
3927                   <item>
3928                       <prgn>dpkg</prgn> calls:
3929                       <example compact="compact">
3930 <var>disappearer's-postrm</var> disappear \
3931   <var>overwriter</var> <var>overwriter-version</var>
3932                       </example>
3933                   </item>
3934                   <item>
3935                       The package's maintainer scripts are removed.
3936                   </item>
3937                   <item>
3938                       It is noted in the status database as being in a
3939                       sane state, namely not installed (any conffiles
3940                       it may have are ignored, rather than being
3941                       removed by <prgn>dpkg</prgn>).  Note that
3942                       disappearing packages do not have their prerm
3943                       called, because <prgn>dpkg</prgn> doesn't know
3944                       in advance that the package is going to
3945                       vanish.
3946                   </item>
3947                 </enumlist>
3948             </item>
3949
3950             <item>
3951                 Any files in the package we're unpacking that are also
3952                 listed in the file lists of other packages are removed
3953                 from those lists.  (This will lobotomize the file list
3954                 of the "conflicting" package if there is one.)
3955             </item>
3956
3957             <item>
3958                 The backup files made during installation, above, are
3959                 deleted.
3960             </item>
3961
3962             <item>
3963               <p>
3964                 The new package's status is now sane, and recorded as
3965                 "unpacked".
3966               </p>
3967
3968               <p>
3969                 Here is another point of no return - if the
3970                 conflicting package's removal fails we do not unwind
3971                 the rest of the installation; the conflicting package
3972                 is left in a half-removed limbo.
3973               </p>
3974             </item>
3975
3976             <item>
3977                 If there was a conflicting package we go and do the
3978                 removal actions (described below), starting with the
3979                 removal of the conflicting package's files (any that
3980                 are also in the package being installed have already
3981                 been removed from the conflicting package's file list,
3982                 and so do not get removed now).
3983             </item>
3984           </enumlist>
3985         </p>
3986       </sect>
3987
3988       <sect id="configdetails"><heading>Details of configuration</heading>
3989
3990         <p>
3991           When we configure a package (this happens with <tt>dpkg
3992             --install</tt> and <tt>dpkg --configure</tt>), we first
3993           update any <tt>conffile</tt>s and then call:
3994           <example compact="compact">
3995 <var>postinst</var> configure <var>most-recently-configured-version</var>
3996           </example>
3997         </p>
3998
3999         <p>
4000           No attempt is made to unwind after errors during
4001           configuration. If the configuration fails, the package is in
4002           a "Failed Config" state, and an error message is generated.
4003         </p>
4004
4005         <p>
4006           If there is no most recently configured version
4007           <prgn>dpkg</prgn> will pass a null argument.
4008           <footnote>
4009             <p>
4010               Historical note: Truly ancient (pre-1997) versions of
4011               <prgn>dpkg</prgn> passed <tt>&lt;unknown&gt;</tt>
4012               (including the angle brackets) in this case.  Even older
4013               ones did not pass a second argument at all, under any
4014               circumstance.  Note that upgrades using such an old dpkg
4015               version are unlikely to work for other reasons, even if
4016               this old argument behavior is handled by your postinst script.
4017             </p>
4018           </footnote>     
4019         </p>
4020       </sect>
4021
4022       <sect id="removedetails"><heading>Details of removal and/or
4023       configuration purging</heading>
4024
4025         <p>
4026           <enumlist>
4027             <item>
4028               <p>
4029                 <example compact="compact">
4030 <var>prerm</var> remove
4031                 </example>
4032               </p>
4033               <p>
4034                 If prerm fails during replacement due to conflict
4035                 <example>
4036 <var>conflictor's-postinst</var> abort-remove \
4037   in-favour <var>package</var> <var>new-version</var>
4038                 </example>
4039                 Or else we call:
4040                 <example>
4041 <var>postinst</var> abort-remove
4042                 </example>
4043               </p>
4044               <p>
4045                 If this fails, the package is in a "Failed-Config"
4046                 state, or else it remains "Installed".
4047               </p>
4048             </item>
4049             <item>
4050                 The package's files are removed (except <tt>conffile</tt>s).
4051             </item>
4052             <item>
4053                 <example compact="compact">
4054 <var>postrm</var> remove
4055                 </example>
4056
4057               <p>
4058                 If it fails, there's no error unwind, and the package is in
4059                 an "Half-Installed" state.
4060               </p>
4061             </item>
4062             <item>
4063               <p>
4064                 All the maintainer scripts except the <prgn>postrm</prgn>
4065                 are removed.
4066               </p>
4067
4068               <p>
4069                 If we aren't purging the package we stop here.  Note
4070                 that packages which have no <prgn>postrm</prgn> and no
4071                 <tt>conffile</tt>s are automatically purged when
4072                 removed, as there is no difference except for the
4073                 <prgn>dpkg</prgn> status.
4074               </p>
4075             </item>
4076             <item>
4077                 The <tt>conffile</tt>s and any backup files
4078                 (<tt>~</tt>-files, <tt>#*#</tt> files,
4079                 <tt>%</tt>-files, <tt>.dpkg-{old,new,tmp}</tt>, etc.)
4080                 are removed.
4081             </item>
4082             <item>
4083               <p>
4084                 <example compact="compact">
4085 <var>postrm</var> purge
4086                 </example>
4087               </p>
4088               <p>
4089                 If this fails, the package remains in a "Config-Files"
4090                 state.
4091               </p>
4092             </item>
4093             <item>
4094                 The package's file list is removed.
4095             </item>
4096           </enumlist>
4097
4098         </p>
4099       </sect>
4100     </chapt>
4101
4102
4103     <chapt id="relationships">
4104       <heading>Declaring relationships between packages</heading>
4105
4106       <sect id="depsyntax">
4107         <heading>Syntax of relationship fields</heading>
4108
4109         <p>
4110           These fields all have a uniform syntax.  They are a list of
4111           package names separated by commas.
4112         </p>
4113
4114         <p>
4115           In the <tt>Depends</tt>, <tt>Recommends</tt>,
4116           <tt>Suggests</tt>, <tt>Pre-Depends</tt>,
4117           <tt>Build-Depends</tt> and <tt>Build-Depends-Indep</tt>
4118           control file fields of the package, which declare
4119           dependencies on other packages, the package names listed may
4120           also include lists of alternative package names, separated
4121           by vertical bar (pipe) symbols <tt>|</tt>.  In such a case,
4122           if any one of the alternative packages is installed, that
4123           part of the dependency is considered to be satisfied.
4124         </p>
4125
4126         <p>
4127           All of the fields except for <tt>Provides</tt> may restrict
4128           their applicability to particular versions of each named
4129           package.  This is done in parentheses after each individual
4130           package name; the parentheses should contain a relation from
4131           the list below followed by a version number, in the format
4132           described in <ref id="f-Version">.
4133         </p>
4134
4135         <p>
4136           The relations allowed are <tt>&lt;&lt;</tt>, <tt>&lt;=</tt>,
4137           <tt>=</tt>, <tt>&gt;=</tt> and <tt>&gt;&gt;</tt> for
4138           strictly earlier, earlier or equal, exactly equal, later or
4139           equal and strictly later, respectively.  The deprecated
4140           forms <tt>&lt;</tt> and <tt>&gt;</tt> were used to mean
4141           earlier/later or equal, rather than strictly earlier/later,
4142           so they should not appear in new packages (though
4143           <prgn>dpkg</prgn> still supports them).
4144         </p>
4145
4146         <p>
4147           Whitespace may appear at any point in the version
4148           specification subject to the rules in <ref
4149           id="controlsyntax">, and must appear where it's necessary to
4150           disambiguate; it is not otherwise significant.  All of the
4151           relationship fields may span multiple lines.  For
4152           consistency and in case of future changes to
4153           <prgn>dpkg</prgn> it is recommended that a single space be
4154           used after a version relationship and before a version
4155           number; it is also conventional to put a single space after
4156           each comma, on either side of each vertical bar, and before
4157           each open parenthesis.  When wrapping a relationship field, it
4158           is conventional to do so after a comma and before the space
4159           following that comma.
4160         </p>
4161
4162         <p>
4163           For example, a list of dependencies might appear as:
4164           <example compact="compact">
4165 Package: mutt
4166 Version: 1.3.17-1
4167 Depends: libc6 (>= 2.2.1), exim | mail-transport-agent
4168           </example>
4169         </p>
4170
4171         <p>
4172           All fields that specify build-time relationships
4173           (<tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4174           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt>)
4175           may be restricted to a certain set of architectures.  This
4176           is indicated in brackets after each individual package name and
4177           the optional version specification.  The brackets enclose a
4178           list of Debian architecture names separated by whitespace.
4179           Exclamation marks may be prepended to each of the names.
4180           (It is not permitted for some names to be prepended with
4181           exclamation marks while others aren't.) If the current Debian
4182           host architecture is not in this list and there are no
4183           exclamation marks in the list, or it is in the list with a
4184           prepended exclamation mark, the package name and the
4185           associated version specification are ignored completely for
4186           the purposes of defining the relationships.
4187         </p>
4188
4189         <p>
4190           For example:
4191           <example compact="compact">
4192 Source: glibc
4193 Build-Depends-Indep: texinfo
4194 Build-Depends: kernel-headers-2.2.10 [!hurd-i386],
4195   hurd-dev [hurd-i386], gnumach-dev [hurd-i386]
4196           </example>
4197           requires <tt>kernel-headers-2.2.10</tt> on all architectures
4198           other than hurd-i386 and requires <tt>hurd-dev</tt> and
4199           <tt>gnumach-dev</tt> only on hurd-i386.
4200         </p>
4201
4202         <p>
4203           If the architecture-restricted dependency is part of a set of
4204           alternatives using <tt>|</tt>, that alternative is ignored
4205           completely on architectures that do not match the restriction.
4206           For example:
4207           <example compact="compact">
4208 Build-Depends: foo [!i386] | bar [!amd64]
4209           </example>
4210           is equivalent to <tt>bar</tt> on the i386 architecture, to
4211           <tt>foo</tt> on the amd64 architecture, and to <tt>foo |
4212           bar</tt> on all other architectures.
4213         </p>
4214
4215         <p>
4216           Note that the binary package relationship fields such as
4217           <tt>Depends</tt> appear in one of the binary package
4218           sections of the control file, whereas the build-time
4219           relationships such as <tt>Build-Depends</tt> appear in the
4220           source package section of the control file (which is the
4221           first section).
4222         </p>
4223       </sect>
4224
4225       <sect id="binarydeps">
4226         <heading>Binary Dependencies - <tt>Depends</tt>,
4227           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
4228           <tt>Pre-Depends</tt>
4229         </heading>
4230
4231         <p>
4232           Packages can declare in their control file that they have
4233           certain relationships to other packages - for example, that
4234           they may not be installed at the same time as certain other
4235           packages, and/or that they depend on the presence of others.
4236         </p>
4237
4238         <p>
4239           This is done using the <tt>Depends</tt>, <tt>Pre-Depends</tt>,
4240           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
4241           <tt>Breaks</tt> and <tt>Conflicts</tt> control file fields.
4242         </p>
4243
4244         <p>
4245           These seven fields are used to declare a dependency
4246           relationship by one package on another.  Except for
4247           <tt>Enhances</tt> and <tt>Breaks</tt>, they appear in the
4248           depending (binary) package's control file.
4249           (<tt>Enhances</tt> appears in the recommending package's
4250           control file, and <tt>Breaks</tt> appears in the version of
4251           depended-on package which causes the named package to
4252           break).
4253         </p>
4254
4255         <p>
4256           A <tt>Depends</tt> field takes effect <em>only</em> when a
4257           package is to be configured.  It does not prevent a package
4258           being on the system in an unconfigured state while its
4259           dependencies are unsatisfied, and it is possible to replace
4260           a package whose dependencies are satisfied and which is
4261           properly installed with a different version whose
4262           dependencies are not and cannot be satisfied; when this is
4263           done the depending package will be left unconfigured (since
4264           attempts to configure it will give errors) and will not
4265           function properly.  If it is necessary, a
4266           <tt>Pre-Depends</tt> field can be used, which has a partial
4267           effect even when a package is being unpacked, as explained
4268           in detail below.  (The other three dependency fields,
4269           <tt>Recommends</tt>, <tt>Suggests</tt> and
4270           <tt>Enhances</tt>, are only used by the various front-ends
4271           to <prgn>dpkg</prgn> such as <prgn>apt-get</prgn>,
4272           <prgn>aptitude</prgn>, and <prgn>dselect</prgn>.)
4273         </p>
4274
4275         <p>
4276           For this reason packages in an installation run are usually
4277           all unpacked first and all configured later; this gives
4278           later versions of packages with dependencies on later
4279           versions of other packages the opportunity to have their
4280           dependencies satisfied.
4281         </p>
4282
4283         <p>
4284           In case of circular dependencies, since installation or
4285           removal order honoring the dependency order can't be
4286           established, dependency loops are broken at some point
4287           (based on rules below), and some packages may not be able to
4288           rely on their dependencies being present when being
4289           installed or removed, depending on which side of the break
4290           of the circular dependency loop they happen to be on.  If one
4291           of the packages in the loop has no postinst script, then the
4292           cycle will be broken at that package, so as to ensure that
4293           all postinst scripts run with the dependencies properly
4294           configured if this is possible. Otherwise the breaking point
4295           is arbitrary.
4296         </p>
4297
4298         <p>
4299           The <tt>Depends</tt> field thus allows package maintainers
4300           to impose an order in which packages should be configured.
4301         </p>
4302
4303         <p>
4304           The meaning of the five dependency fields is as follows:
4305           <taglist>
4306             <tag><tt>Depends</tt></tag>
4307             <item>
4308               <p>
4309                 This declares an absolute dependency.  A package will
4310                 not be configured unless all of the packages listed in
4311                 its <tt>Depends</tt> field have been correctly
4312                 configured.
4313               </p>
4314
4315               <p>
4316                 The <tt>Depends</tt> field should be used if the
4317                 depended-on package is required for the depending
4318                 package to provide a significant amount of
4319                 functionality.
4320               </p>
4321
4322               <p>
4323                 The <tt>Depends</tt> field should also be used if the
4324                 <prgn>postinst</prgn>, <prgn>prerm</prgn> or
4325                 <prgn>postrm</prgn> scripts require the package to be
4326                 present in order to run.  Note, however, that the
4327                 <prgn>postrm</prgn> cannot rely on any non-essential
4328                 packages to be present during the <tt>purge</tt>
4329                 phase.
4330             </item>
4331
4332             <tag><tt>Recommends</tt></tag>
4333             <item>
4334               <p>
4335                 This declares a strong, but not absolute, dependency.
4336               </p>
4337
4338               <p>
4339                 The <tt>Recommends</tt> field should list packages
4340                 that would be found together with this one in all but
4341                 unusual installations.
4342               </p>
4343             </item>
4344
4345             <tag><tt>Suggests</tt></tag>
4346             <item>
4347                 This is used to declare that one package may be more
4348                 useful with one or more others.  Using this field
4349                 tells the packaging system and the user that the
4350                 listed packages are related to this one and can
4351                 perhaps enhance its usefulness, but that installing
4352                 this one without them is perfectly reasonable.
4353             </item>
4354
4355             <tag><tt>Enhances</tt></tag>
4356             <item>
4357                 This field is similar to Suggests but works in the
4358                 opposite direction. It is used to declare that a
4359                 package can enhance the functionality of another
4360                 package.
4361             </item>
4362
4363             <tag><tt>Pre-Depends</tt></tag>
4364             <item>
4365               <p>
4366                 This field is like <tt>Depends</tt>, except that it
4367                 also forces <prgn>dpkg</prgn> to complete installation
4368                 of the packages named before even starting the
4369                 installation of the package which declares the
4370                 pre-dependency, as follows:
4371               </p>
4372
4373               <p>
4374                 When a package declaring a pre-dependency is about to
4375                 be <em>unpacked</em> the pre-dependency can be
4376                 satisfied if the depended-on package is either fully
4377                 configured, <em>or even if</em> the depended-on
4378                 package(s) are only unpacked or half-configured,
4379                 provided that they have been configured correctly at
4380                 some point in the past (and not removed or partially
4381                 removed since).  In this case, both the
4382                 previously-configured and currently unpacked or
4383                 half-configured versions must satisfy any version
4384                 clause in the <tt>Pre-Depends</tt> field.
4385               </p>
4386
4387               <p>
4388                 When the package declaring a pre-dependency is about
4389                 to be <em>configured</em>, the pre-dependency will be
4390                 treated as a normal <tt>Depends</tt>, that is, it will
4391                 be considered satisfied only if the depended-on
4392                 package has been correctly configured.
4393               </p>
4394
4395               <p>
4396                 <tt>Pre-Depends</tt> should be used sparingly,
4397                 preferably only by packages whose premature upgrade or
4398                 installation would hamper the ability of the system to
4399                 continue with any upgrade that might be in progress.
4400               </p>
4401
4402               <p>
4403                 <tt>Pre-Depends</tt> are also required if the
4404                 <prgn>preinst</prgn> script depends on the named
4405                 package.  It is best to avoid this situation if
4406                 possible.
4407               </p>
4408             </item>
4409           </taglist>
4410         </p>
4411
4412         <p>
4413           When selecting which level of dependency to use you should
4414           consider how important the depended-on package is to the
4415           functionality of the one declaring the dependency.  Some
4416           packages are composed of components of varying degrees of
4417           importance.  Such a package should list using
4418           <tt>Depends</tt> the package(s) which are required by the
4419           more important components.  The other components'
4420           requirements may be mentioned as Suggestions or
4421           Recommendations, as appropriate to the components' relative
4422           importance.
4423         </p>
4424       </sect>
4425
4426       <sect id="breaks">
4427         <heading>Packages which break other packages - <tt>Breaks</tt></heading>
4428
4429         <p>
4430           Using <tt>Breaks</tt> may cause problems for upgrades from older
4431           versions of Debian and should not be used until the stable
4432           release of Debian supports <tt>Breaks</tt>.
4433         </p>
4434
4435         <p>
4436           When one binary package declares that it breaks another,
4437           <prgn>dpkg</prgn> will refuse to allow the package which
4438           declares <tt>Breaks</tt> be installed unless the broken
4439           package is deconfigured first, and it will refuse to
4440           allow the broken package to be reconfigured.
4441         </p>
4442
4443         <p>
4444           A package will not be regarded as causing breakage merely
4445           because its configuration files are still installed; it must
4446           be at least half-installed.
4447         </p>
4448
4449         <p>
4450           A special exception is made for packages which declare that
4451           they break their own package name or a virtual package which
4452           they provide (see below): this does not count as a real
4453           breakage.
4454         </p>
4455
4456         <p>
4457           Normally a <tt>Breaks</tt> entry will have an "earlier than"
4458           version clause; such a <tt>Breaks</tt> is introduced in the
4459           version of an (implicit or explicit) dependency which
4460           violates an assumption or reveals a bug in earlier versions
4461           of the broken package.  This use of <tt>Breaks</tt> will
4462           inform higher-level package management tools that broken
4463           package must be upgraded before the new one.
4464         </p>
4465
4466         <p>
4467           If the breaking package also overwrites some files from the
4468           older package, it should use <tt>Replaces</tt> (not
4469           <tt>Conflicts</tt>) to ensure this goes smoothly.
4470         </p>
4471       </sect>
4472
4473       <sect id="conflicts">
4474         <heading>Conflicting binary packages - <tt>Conflicts</tt></heading>
4475
4476         <p>
4477           When one binary package declares a conflict with another
4478           using a <tt>Conflicts</tt> field, <prgn>dpkg</prgn> will
4479           refuse to allow them to be installed on the system at the
4480           same time.
4481         </p>
4482
4483         <p>
4484           If one package is to be installed, the other must be removed
4485           first - if the package being installed is marked as
4486           replacing (see <ref id="replaces">) the one on the system,
4487           or the one on the system is marked as deselected, or both
4488           packages are marked <tt>Essential</tt>, then
4489           <prgn>dpkg</prgn> will automatically remove the package
4490           which is causing the conflict, otherwise it will halt the
4491           installation of the new package with an error.  This
4492           mechanism is specifically designed to produce an error when
4493           the installed package is <tt>Essential</tt>, but the new
4494           package is not.
4495         </p>
4496
4497         <p>
4498           A package will not cause a conflict merely because its
4499           configuration files are still installed; it must be at least
4500           half-installed.
4501         </p>
4502
4503         <p>
4504           A special exception is made for packages which declare a
4505           conflict with their own package name, or with a virtual
4506           package which they provide (see below): this does not
4507           prevent their installation, and allows a package to conflict
4508           with others providing a replacement for it.  You use this
4509           feature when you want the package in question to be the only
4510           package providing some feature.
4511         </p>
4512
4513         <p>
4514           A <tt>Conflicts</tt> entry should almost never have an
4515           "earlier than" version clause.  This would prevent
4516           <prgn>dpkg</prgn> from upgrading or installing the package
4517           which declared such a conflict until the upgrade or removal
4518           of the conflicted-with package had been completed.  Instead,
4519           <tt>Breaks</tt> may be used (once <tt>Breaks</tt> is supported
4520           by the stable release of Debian).
4521         </p>
4522       </sect>
4523
4524       <sect id="virtual"><heading>Virtual packages - <tt>Provides</tt>
4525         </heading>
4526
4527         <p>
4528           As well as the names of actual ("concrete") packages, the
4529           package relationship fields <tt>Depends</tt>,
4530           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
4531           <tt>Pre-Depends</tt>, <tt>Breaks</tt>, <tt>Conflicts</tt>,
4532           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4533           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt>
4534           may mention "virtual packages".
4535         </p>
4536
4537         <p>
4538           A <em>virtual package</em> is one which appears in the
4539           <tt>Provides</tt> control file field of another package.
4540           The effect is as if the package(s) which provide a
4541           particular virtual package name had been listed by name
4542           everywhere the virtual package name appears. (See also <ref
4543             id="virtual_pkg">)
4544         </p>
4545
4546         <p>
4547           If there are both concrete and virtual packages of the same
4548           name, then the dependency may be satisfied (or the conflict
4549           caused) by either the concrete package with the name in
4550           question or any other concrete package which provides the
4551           virtual package with the name in question.  This is so that,
4552           for example, supposing we have
4553           <example compact="compact">
4554 Package: foo
4555 Depends: bar
4556           </example> and someone else releases an enhanced version of
4557           the <tt>bar</tt> package they can say:
4558           <example compact="compact">
4559 Package: bar-plus
4560 Provides: bar
4561           </example>
4562           and the <tt>bar-plus</tt> package will now also satisfy the
4563           dependency for the <tt>foo</tt> package.
4564         </p>
4565
4566         <p>
4567           If a relationship field has a version number attached
4568           then only real packages will be considered to see whether
4569           the relationship is satisfied (or the prohibition violated,
4570           for a conflict or breakage) - it is assumed that a real
4571           package which provides the virtual package is not of the
4572           "right" version.  So, a <tt>Provides</tt> field may not
4573           contain version numbers, and the version number of the
4574           concrete package which provides a particular virtual package
4575           will not be looked at when considering a dependency on or
4576           conflict with the virtual package name.
4577         </p>
4578
4579         <p>
4580           It is likely that the ability will be added in a future
4581           release of <prgn>dpkg</prgn> to specify a version number for
4582           each virtual package it provides.  This feature is not yet
4583           present, however, and is expected to be used only
4584           infrequently.
4585         </p>
4586
4587         <p>
4588           If you want to specify which of a set of real packages
4589           should be the default to satisfy a particular dependency on
4590           a virtual package, you should list the real package as an
4591           alternative before the virtual one.
4592         </p>
4593       </sect>
4594
4595
4596       <sect id="replaces"><heading>Overwriting files and replacing
4597           packages - <tt>Replaces</tt></heading>
4598
4599         <p>
4600           Packages can declare in their control file that they should
4601           overwrite files in certain other packages, or completely
4602           replace other packages. The <tt>Replaces</tt> control file
4603           field has these two distinct purposes.
4604         </p>
4605
4606         <sect1><heading>Overwriting files in other packages</heading>
4607
4608           <p>
4609             Firstly, as mentioned before, it is usually an error for a
4610             package to contain files which are on the system in
4611             another package.
4612           </p>
4613
4614           <p>
4615             However, if the overwriting package declares that it
4616             <tt>Replaces</tt> the one containing the file being
4617             overwritten, then <prgn>dpkg</prgn> will replace the file
4618             from the old package with that from the new.  The file
4619             will no longer be listed as "owned" by the old package.
4620           </p>
4621
4622           <p>
4623             If a package is completely replaced in this way, so that
4624             <prgn>dpkg</prgn> does not know of any files it still
4625             contains, it is considered to have "disappeared".  It will
4626             be marked as not wanted on the system (selected for
4627             removal) and not installed.  Any <tt>conffile</tt>s
4628             details noted for the package will be ignored, as they
4629             will have been taken over by the overwriting package.  The
4630             package's <prgn>postrm</prgn> script will be run with a
4631             special argument to allow the package to do any final
4632             cleanup required.  See <ref id="mscriptsinstact">.
4633             <footnote>
4634               <p>
4635                 Replaces is a one way relationship -- you have to              
4636                 install the replacing package after the replaced
4637                 package.
4638               </p>
4639             </footnote>
4640           </p>
4641
4642           <p>
4643             For this usage of <tt>Replaces</tt>, virtual packages (see
4644             <ref id="virtual">) are not considered when looking at a
4645             <tt>Replaces</tt> field - the packages declared as being
4646             replaced must be mentioned by their real names.
4647           </p>
4648
4649           <p>
4650             Furthermore, this usage of <tt>Replaces</tt> only takes
4651             effect when both packages are at least partially on the
4652             system at once, so that it can only happen if they do not
4653             conflict or if the conflict has been overridden.
4654           </p>
4655
4656         </sect1>
4657
4658         <sect1><heading>Replacing whole packages, forcing their
4659             removal</heading>
4660
4661           <p>
4662             Secondly, <tt>Replaces</tt> allows the packaging system to
4663             resolve which package should be removed when there is a
4664             conflict - see <ref id="conflicts">.  This usage only
4665             takes effect when the two packages <em>do</em> conflict,
4666             so that the two usages of this field do not interfere with
4667             each other.
4668           </p>
4669
4670           <p>
4671             In this situation, the package declared as being replaced
4672             can be a virtual package, so for example, all mail
4673             transport agents (MTAs) would have the following fields in
4674             their control files:
4675             <example compact="compact">
4676 Provides: mail-transport-agent
4677 Conflicts: mail-transport-agent
4678 Replaces: mail-transport-agent
4679             </example>
4680             ensuring that only one MTA can be installed at any one
4681             time.
4682         </sect1>
4683       </sect>
4684
4685       <sect id="sourcebinarydeps">
4686         <heading>Relationships between source and binary packages -
4687           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
4688           <tt>Build-Conflicts</tt>, <tt>Build-Conflicts-Indep</tt>
4689         </heading>
4690
4691         <p>
4692           Source packages that require certain binary packages to be
4693           installed or absent at the time of building the package
4694           can declare relationships to those binary packages.
4695         </p>
4696
4697         <p>
4698           This is done using the <tt>Build-Depends</tt>,
4699           <tt>Build-Depends-Indep</tt>, <tt>Build-Conflicts</tt> and
4700           <tt>Build-Conflicts-Indep</tt> control file fields.
4701         </p>
4702
4703         <p>
4704           Build-dependencies on "build-essential" binary packages can be
4705           omitted. Please see <ref id="pkg-relations"> for more information.
4706         </p>
4707
4708         <p>
4709           The dependencies and conflicts they define must be satisfied
4710           (as defined earlier for binary packages) in order to invoke
4711           the targets in <tt>debian/rules</tt>, as follows:<footnote>
4712             <p>
4713               If you make "build-arch" or "binary-arch", you need
4714               Build-Depends.  If you make "build-indep" or
4715               "binary-indep", you need Build-Depends and
4716               Build-Depends-Indep.  If you make "build" or "binary",
4717               you need both.
4718             </p>
4719             <p>
4720               There is no Build-Depends-Arch; this role is essentially
4721               met with Build-Depends.  Anyone building the
4722               <tt>build-indep</tt> and binary-indep<tt></tt> targets
4723               is basically assumed to be building the whole package
4724               anyway and so installs all build dependencies.  The
4725               autobuilders use <tt>dpkg-buildpackage -B</tt>, which
4726               calls <tt>build</tt> (not <tt>build-arch</tt>, since it
4727               does not yet know how to check for its existence) and
4728               <tt>binary-arch</tt>.
4729             </p>
4730             <p>
4731               The purpose of the original split, I recall, was so that
4732               the autobuilders wouldn't need to install extra packages
4733               needed only for the binary-indep targets.  But without a
4734               build-arch/build-indep split, this didn't work, since
4735               most of the work is done in the build target, not in the
4736               binary target.
4737             </p>
4738           </footnote>
4739
4740           <taglist>
4741             <tag><tt>Build-Depends</tt>, <tt>Build-Conflicts</tt></tag>
4742             <item>
4743                 The <tt>Build-Depends</tt> and
4744                 <tt>Build-Conflicts</tt> fields must be satisfied when
4745                 any of the following targets is invoked:
4746                 <tt>build</tt>, <tt>clean</tt>, <tt>binary</tt>,
4747                 <tt>binary-arch</tt>, <tt>build-arch</tt>,
4748                 <tt>build-indep</tt> and <tt>binary-indep</tt>.
4749             </item>
4750             <tag><tt>Build-Depends-Indep</tt>,
4751               <tt>Build-Conflicts-Indep</tt></tag>
4752             <item>
4753                 The <tt>Build-Depends-Indep</tt> and
4754                 <tt>Build-Conflicts-Indep</tt> fields must be
4755                 satisfied when any of the following targets is
4756                 invoked: <tt>build</tt>, <tt>build-indep</tt>,
4757                 <tt>binary</tt> and <tt>binary-indep</tt>.
4758             </item>
4759           </taglist>
4760         </p>
4761
4762       </sect>
4763
4764     </chapt>
4765
4766
4767     <chapt id="sharedlibs"><heading>Shared libraries</heading>
4768
4769       <p>
4770         Packages containing shared libraries must be constructed with
4771         a little care to make sure that the shared library is always
4772         available.  This is especially important for packages whose
4773         shared libraries are vitally important, such as the C library
4774         (currently <tt>libc6</tt>).
4775       </p>
4776
4777       <p>
4778         Packages involving shared libraries should be split up into
4779         several binary packages. This section mostly deals with how
4780         this separation is to be accomplished; rules for files within
4781         the shared library packages are in <ref id="libraries"> instead.
4782       </p>
4783
4784       <sect id="sharedlibs-runtime">
4785         <heading>Run-time shared libraries</heading>
4786
4787       <p>
4788         The run-time shared library needs to be placed in a package
4789         whose name changes whenever the shared object version
4790         changes.<footnote>
4791             <p>
4792               Since it is common place to install several versions of a
4793               package that just provides shared libraries, it is a
4794               good idea that the library package should not
4795               contain any extraneous non-versioned files, unless they
4796               happen to be in versioned directories.</p>
4797           </footnote>
4798           The most common mechanism is to place it in a package
4799         called
4800         <package><var>libraryname</var><var>soversion</var></package>,
4801         where <file><var>soversion</var></file> is the version number
4802         in the soname of the shared library<footnote>
4803               The soname is the shared object name: it's the thing
4804               that has to match exactly between building an executable
4805               and running it for the dynamic linker to be able run the
4806               program.  For example, if the soname of the library is
4807               <file>libfoo.so.6</file>, the library package would be
4808               called <file>libfoo6</file>.
4809           </footnote>.
4810         Alternatively, if it would be confusing to directly append
4811         <var>soversion</var> to <var>libraryname</var> (e.g. because
4812         <var>libraryname</var> itself ends in a number), you may use
4813         <package><var>libraryname</var>-<var>soversion</var></package> and
4814         <package><var>libraryname</var>-<var>soversion</var>-dev</package>
4815         instead.
4816       </p>
4817
4818       <p>
4819         If you have several shared libraries built from the same
4820         source tree you may lump them all together into a single
4821         shared library package, provided that you change all of
4822         their sonames at once (so that you don't get filename
4823         clashes if you try to install different versions of the
4824         combined shared libraries package).
4825       </p>
4826
4827       <p>
4828         The package should install the shared libraries under
4829         their normal names.  For example, the <package>libgdbm3</package>
4830         package should install <file>libgdbm.so.3.0.0</file> as
4831         <file>/usr/lib/libgdbm.so.3.0.0</file>.  The files should not be
4832         renamed or re-linked by any <prgn>prerm</prgn> or
4833         <prgn>postrm</prgn> scripts; <prgn>dpkg</prgn> will take care
4834         of renaming things safely without affecting running programs,
4835         and attempts to interfere with this are likely to lead to
4836         problems.
4837       </p>
4838
4839       <p>
4840         Shared libraries should not be installed executable, since
4841         the dynamic linker does not require this and trying to
4842         execute a shared library usually results in a core dump.
4843       </p>
4844
4845       <p>
4846         The run-time library package should include the symbolic link that
4847         <prgn>ldconfig</prgn> would create for the shared libraries.
4848         For example, the <package>libgdbm3</package> package should include
4849         a symbolic link from <file>/usr/lib/libgdbm.so.3</file> to
4850         <file>libgdbm.so.3.0.0</file>.  This is needed so that the dynamic
4851         linker (for example <prgn>ld.so</prgn> or
4852         <prgn>ld-linux.so.*</prgn>) can find the library between the
4853         time that <prgn>dpkg</prgn> installs it and the time that
4854         <prgn>ldconfig</prgn> is run in the <prgn>postinst</prgn>
4855         script.<footnote>
4856             The package management system requires the library to be
4857             placed before the symbolic link pointing to it in the
4858             <file>.deb</file> file.  This is so that when
4859             <prgn>dpkg</prgn> comes to install the symlink
4860             (overwriting the previous symlink pointing at an older
4861             version of the library), the new shared library is already
4862             in place.  In the past, this was achieved by creating the
4863             library in the temporary packaging directory before
4864             creating the symlink.  Unfortunately, this was not always
4865             effective, since the building of the tar file in the
4866             <file>.deb</file> depended on the behavior of the underlying
4867             file system.  Some file systems (such as reiserfs) reorder
4868             the files so that the order of creation is forgotten.
4869             Since version 1.7.0, <prgn>dpkg</prgn>
4870             reorders the files itself as necessary when building a
4871             package.  Thus it is no longer important to concern
4872             oneself with the order of file creation.
4873         </footnote>
4874       </p>
4875
4876         <sect1 id="ldconfig">
4877           <heading><tt>ldconfig</tt></heading>
4878
4879         <p>
4880           Any package installing shared libraries in one of the default
4881           library directories of the dynamic linker (which are currently
4882           <file>/usr/lib</file> and <file>/lib</file>) or a directory that is
4883           listed in <file>/etc/ld.so.conf</file><footnote>
4884             These are currently
4885             <list compact="compact">
4886               <item>/usr/local/lib</item>
4887               <item>/usr/lib/libc5-compat</item>
4888               <item>/lib/libc5-compat</item>
4889             </list>
4890           </footnote>
4891           must use <prgn>ldconfig</prgn> to update the shared library
4892           system.
4893         </p>
4894
4895         <p>
4896             The package maintainer scripts must only call
4897             <prgn>ldconfig</prgn> under these circumstances:
4898             <list compact="compact">
4899               <item>When the <prgn>postinst</prgn> script is run with a
4900                   first argument of <tt>configure</tt>, the script must call
4901                   <prgn>ldconfig</prgn>, and may optionally invoke
4902                   <prgn>ldconfig</prgn> at other times.
4903               </item>
4904               <item>When the <prgn>postrm</prgn> script is run with a
4905                   first argument of <tt>remove</tt>, the script should call
4906                   <prgn>ldconfig</prgn>.
4907               </item>
4908             </list>
4909          <footnote>
4910             <p>
4911               During install or upgrade, the preinst is called before
4912               the new files are installed, so calling "ldconfig" is
4913               pointless.  The preinst of an existing package can also be
4914               called if an upgrade fails.  However, this happens during
4915               the critical time when a shared libs may exist on-disk
4916               under a temporary name.  Thus, it is dangerous and
4917               forbidden by current policy to call "ldconfig" at this
4918               time.
4919             </p>
4920
4921             <p>
4922               When a package is installed or upgraded, "postinst
4923               configure" runs after the new files are safely on-disk.
4924               Since it is perfectly safe to invoke ldconfig
4925               unconditionally in a postinst, it is OK for a package to
4926               simply put ldconfig in its postinst without checking the
4927               argument.  The postinst can also be called to recover from
4928               a failed upgrade.  This happens before any new files are
4929               unpacked, so there is no reason to call "ldconfig" at this
4930               point.
4931             </p>
4932
4933             <p>
4934               For a package that is being removed, prerm is
4935               called with all the files intact, so calling ldconfig is
4936               useless.  The other calls to "prerm" happen in the case of
4937               upgrade at a time when all the files of the old package
4938               are on-disk, so again calling "ldconfig" is pointless.
4939             </p>
4940
4941             <p>
4942               postrm, on the other hand, is called with the "remove"
4943               argument just after the files are removed, so this is
4944               the proper time to call "ldconfig" to notify the system
4945               of the fact that the shared libraries from the package
4946               are removed.  The postrm can be called at several other
4947               times.  At the time of "postrm purge", "postrm
4948               abort-install", or "postrm abort-upgrade", calling
4949               "ldconfig" is useless because the shared lib files are
4950               not on-disk.  However, when "postrm" is invoked with
4951               arguments "upgrade", "failed-upgrade", or "disappear", a
4952               shared lib may exist on-disk under a temporary filename.
4953             </p>
4954           </footnote>
4955         </p>
4956         </sect1>
4957
4958       </sect>
4959
4960       <sect id="sharedlibs-support-files">
4961         <heading>Shared library support files</heading>
4962
4963         <p>
4964           If your package contains files whose names do not change with
4965           each change in the library shared object version, you must not
4966           put them in the shared library package.  Otherwise, several
4967           versions of the shared library cannot be installed at the same
4968           time without filename clashes, making upgrades and transitions
4969           unnecessarily difficult.
4970         </p>
4971
4972         <p>
4973           It is recommended that supporting files and run-time support
4974           programs that do not need to be invoked manually by users, but
4975           are nevertheless required for the package to function, be placed
4976           (if they are binary) in a subdirectory of <file>/usr/lib</file>,
4977           preferably under <file>/usr/lib/</file><var>package-name</var>.
4978           If the program or file is architecture independent, the
4979           recommendation is for it to be placed in a subdirectory of
4980           <file>/usr/share</file> instead, preferably under
4981           <file>/usr/share/</file><var>package-name</var>.  Following the
4982           <var>package-name</var> naming convention ensures that the file
4983           names change when the shared object version changes.
4984         </p>
4985
4986         <p>
4987           Run-time support programs that use the shared library but are
4988           not required for the library to function or files used by the
4989           shared library that can be used by any version of the shared
4990           library package should instead be put in a separate package.
4991           This package might typically be named
4992           <package><var>libraryname</var>-tools</package>; note the
4993           absence of the <var>soversion</var> in the package name.
4994         </p>
4995
4996         <p>
4997           Files and support programs only useful when compiling software
4998           against the library should be included in the development
4999           package for the library.<footnote>
5000             For example, a <file><var>package-name</var>-config</file>
5001             script or <package>pkg-config</package> configuration files.
5002           </footnote>
5003         </p>
5004       </sect>
5005
5006       <sect id="sharedlibs-static">
5007         <heading>Static libraries</heading>
5008
5009       <p>
5010         The static library (<file><var>libraryname.a</var></file>)
5011         is usually provided in addition to the shared version.
5012         It is placed into the development package (see below).
5013       </p>
5014
5015       <p>
5016         In some cases, it is acceptable for a library to be
5017         available in static form only; these cases include:
5018         <list>
5019           <item>libraries for languages whose shared library support
5020                 is immature or unstable</item>
5021           <item>libraries whose interfaces are in flux or under
5022                 development (commonly the case when the library's
5023                 major version number is zero, or where the ABI breaks
5024                 across patchlevels)</item>
5025           <item>libraries which are explicitly intended to be
5026                 available only in static form by their upstream
5027                 author(s)</item>
5028         </list>
5029       </p>
5030
5031       <sect id="sharedlibs-dev">
5032         <heading>Development files</heading>
5033
5034       <p>
5035         The development files associated to a shared library need to be
5036         placed in a package called
5037         <package><var>libraryname</var><var>soversion</var>-dev</package>,
5038         or if you prefer only to support one development version at a
5039         time, <package><var>libraryname</var>-dev</package>.
5040       </p>
5041
5042       <p>
5043         In case several development versions of a library exist, you may
5044         need to use <prgn>dpkg</prgn>'s Conflicts mechanism (see
5045         <ref id="conflicts">) to ensure that the user only installs one
5046         development version at a time (as different development versions are
5047         likely to have the same header files in them, which would cause a
5048         filename clash if both were installed).
5049       </p>
5050
5051       <p>
5052         The development package should contain a symlink for the associated
5053         shared library without a version number. For example, the
5054         <package>libgdbm-dev</package> package should include a symlink
5055         from <file>/usr/lib/libgdbm.so</file> to
5056         <file>libgdbm.so.3.0.0</file>.  This symlink is needed by the linker
5057         (<prgn>ld</prgn>) when compiling packages, as it will only look for
5058         <file>libgdbm.so</file> when compiling dynamically.
5059       </p>
5060       </sect>
5061
5062       <sect id="sharedlibs-intradeps">
5063         <heading>Dependencies between the packages of the same library</heading>
5064
5065         <p>
5066           Typically the development version should have an exact
5067           version dependency on the runtime library, to make sure that
5068           compilation and linking happens correctly.  The
5069           <tt>${binary:Version}</tt> substitution variable can be
5070           useful for this purpose.
5071           <footnote>
5072             Previously, <tt>${Source-Version}</tt> was used, but its name
5073             was confusing and it has been deprecated since dpkg 1.13.19.
5074           </footnote>
5075         </p>
5076       </sect>
5077
5078       <sect id="sharedlibs-shlibdeps">
5079         <heading>Dependencies between the library and other packages -
5080         the <tt>shlibs</tt> system</heading>
5081
5082         <p>
5083           If a package contains a binary or library which links to a
5084           shared library, we must ensure that when the package is
5085           installed on the system, all of the libraries needed are
5086           also installed.  This requirement led to the creation of the
5087           <tt>shlibs</tt> system, which is very simple in its design:
5088           any package which <em>provides</em> a shared library also
5089           provides information on the package dependencies required to
5090           ensure the presence of this library, and any package which
5091           <em>uses</em> a shared library uses this information to
5092           determine the dependencies it requires.  The files which
5093           contain the mapping from shared libraries to the necessary
5094           dependency information are called <file>shlibs</file> files.
5095         </p>
5096
5097         <p>
5098           Thus, when a package is built which contains any shared
5099           libraries, it must provide a <file>shlibs</file> file for other
5100           packages to use, and when a package is built which contains
5101           any shared libraries or compiled binaries, it must run
5102           <qref id="pkg-dpkg-shlibdeps"><prgn>dpkg-shlibdeps</prgn></qref>
5103           on these to determine the libraries used and hence the
5104           dependencies needed by this package.<footnote>
5105             <p>
5106               In the past, the shared libraries linked to were
5107               determined by calling <prgn>ldd</prgn>, but now
5108               <prgn>objdump</prgn> is used to do this.  The only
5109               change this makes to package building is that
5110               <prgn>dpkg-shlibdeps</prgn> must also be run on shared
5111               libraries, whereas in the past this was unnecessary.
5112               The rest of this footnote explains the advantage that
5113               this method gives.
5114             </p>
5115
5116             <p>
5117               We say that a binary <tt>foo</tt> <em>directly</em> uses
5118               a library <tt>libbar</tt> if it is explicitly linked
5119               with that library (that is, it uses the flag
5120               <tt>-lbar</tt> during the linking stage).  Other
5121               libraries that are needed by <tt>libbar</tt> are linked
5122               <em>indirectly</em> to <tt>foo</tt>, and the dynamic
5123               linker will load them automatically when it loads
5124               <tt>libbar</tt>.  A package should depend on
5125               the libraries it directly uses, and the dependencies for
5126               those libraries should automatically pull in the other
5127               libraries.
5128             </p>
5129
5130             <p>
5131               Unfortunately, the <prgn>ldd</prgn> program shows both
5132               the directly and indirectly used libraries, meaning that
5133               the dependencies determined included both direct and
5134               indirect dependencies.  The use of <prgn>objdump</prgn>
5135               avoids this problem by determining only the directly
5136               used libraries.
5137             </p>
5138
5139             <p>
5140               A good example of where this helps is the following.  We
5141               could update <tt>libimlib</tt> with a new version that
5142               supports a new graphics format called dgf (but retaining
5143               the same major version number).  If we used the old
5144               <prgn>ldd</prgn> method, every package that uses
5145               <tt>libimlib</tt> would need to be recompiled so it
5146               would also depend on <tt>libdgf</tt> or it wouldn't run
5147               due to missing symbols.  However with the new system,
5148               packages using <tt>libimlib</tt> can rely on
5149               <tt>libimlib</tt> itself having the dependency on
5150               <tt>libdgf</tt> and so they would not need rebuilding.
5151             </p>
5152           </footnote>
5153         </p>
5154
5155         <p>
5156           In the following sections, we will first describe where the
5157           various <tt>shlibs</tt> files are to be found, then how to
5158           use <prgn>dpkg-shlibdeps</prgn>, and finally the <tt>shlibs</tt>
5159           file format and how to create them if your package contains a
5160           shared library.
5161         </p>
5162
5163       <sect1>
5164         <heading>The <tt>shlibs</tt> files present on the system</heading>
5165
5166         <p>
5167           There are several places where <tt>shlibs</tt> files are
5168           found.  The following list gives them in the order in which
5169           they are read by
5170           <qref id="pkg-dpkg-shlibdeps"><prgn>dpkg-shlibdeps</prgn></qref>.
5171           (The first one which gives the required information is used.)
5172         </p>
5173
5174         <p>
5175           <list>
5176             <item>
5177               <p><file>debian/shlibs.local</file></p>
5178
5179               <p>
5180                 This lists overrides for this package.  Its use is
5181                 described below (see <ref id="shlibslocal">).
5182               </p>
5183             </item>
5184
5185             <item>
5186               <p><file>/etc/dpkg/shlibs.override</file></p>
5187
5188               <p>
5189                 This lists global overrides.  This list is normally
5190                 empty.  It is maintained by the local system
5191                 administrator.
5192               </p>
5193             </item>
5194
5195             <item>
5196               <p><file>DEBIAN/shlibs</file> files in the "build directory"</p>
5197
5198               <p>
5199                 When packages are being built, any
5200                 <file>debian/shlibs</file> files are copied into the
5201                 control file area of the temporary build directory and
5202                 given the name <file>shlibs</file>.  These files give
5203                 details of any shared libraries included in the
5204                 package.<footnote>
5205                     An example may help here.  Let us say that the
5206                     source package <tt>foo</tt> generates two binary
5207                     packages, <tt>libfoo2</tt> and
5208                     <tt>foo-runtime</tt>.  When building the binary
5209                     packages, the two packages are created in the
5210                     directories <file>debian/libfoo2</file> and
5211                     <file>debian/foo-runtime</file> respectively.
5212                     (<file>debian/tmp</file> could be used instead of one
5213                     of these.)  Since <tt>libfoo2</tt> provides the
5214                     <tt>libfoo</tt> shared library, it will require a
5215                     <tt>shlibs</tt> file, which will be installed in
5216                     <file>debian/libfoo2/DEBIAN/shlibs</file>, eventually
5217                     to become
5218                     <file>/var/lib/dpkg/info/libfoo2.shlibs</file>.  Then
5219                     when <prgn>dpkg-shlibdeps</prgn> is run on the
5220                     executable
5221                     <file>debian/foo-runtime/usr/bin/foo-prog</file>, it
5222                     will examine the
5223                     <file>debian/libfoo2/DEBIAN/shlibs</file> file to
5224                     determine whether <tt>foo-prog</tt>'s library
5225                     dependencies are satisfied by any of the libraries
5226                     provided by <tt>libfoo2</tt>.  For this reason,
5227                     <prgn>dpkg-shlibdeps</prgn> must only be run once
5228                     all of the individual binary packages'
5229                     <tt>shlibs</tt> files have been installed into the
5230                     build directory.
5231                 </footnote>
5232               </p>
5233             </item>
5234
5235             <item>
5236               <p><file>/var/lib/dpkg/info/*.shlibs</file></p>
5237
5238               <p>
5239                 These are the <file>shlibs</file> files corresponding to
5240                 all of the packages installed on the system, and are
5241                 maintained by the relevant package maintainers.
5242               </p>
5243             </item>
5244
5245             <item>
5246               <p><file>/etc/dpkg/shlibs.default</file></p>
5247
5248               <p>
5249                 This file lists any shared libraries whose packages
5250                 have failed to provide correct <file>shlibs</file> files.
5251                 It was used when the <file>shlibs</file> setup was first
5252                 introduced, but it is now normally empty.  It is
5253                 maintained by the <tt>dpkg</tt> maintainer.
5254               </p>
5255             </item>
5256           </list>
5257         </p>
5258       </sect1>
5259
5260       <sect1>
5261         <heading>How to use <prgn>dpkg-shlibdeps</prgn> and the
5262             <file>shlibs</file> files</heading>
5263
5264         <p>
5265           Put a call to
5266           <qref id="pkg-dpkg-shlibdeps"><prgn>dpkg-shlibdeps</prgn></qref>
5267           into your <file>debian/rules</file> file.  If your package
5268           contains only compiled binaries and libraries (but no scripts),
5269           you can use a command such as:
5270           <example compact="compact">
5271 dpkg-shlibdeps debian/tmp/usr/bin/* debian/tmp/usr/sbin/* \
5272   debian/tmp/usr/lib/*
5273           </example>
5274           Otherwise, you will need to explicitly list the compiled
5275           binaries and libraries.<footnote>
5276               If you are using <tt>debhelper</tt>, the
5277               <prgn>dh_shlibdeps</prgn> program will do this work for
5278               you.  It will also correctly handle multi-binary
5279               packages.
5280           </footnote>
5281         </p>
5282
5283         <p>
5284           This command puts the dependency information into the
5285           <file>debian/substvars</file> file, which is then used by
5286           <prgn>dpkg-gencontrol</prgn>.  You will need to place a
5287           <tt>${shlibs:Depends}</tt> variable in the <tt>Depends</tt>
5288           field in the control file for this to work.
5289         </p>
5290
5291         <p>
5292           If <prgn>dpkg-shlibdeps</prgn> doesn't complain, you're
5293           done.  If it does complain you might need to create your own
5294           <file>debian/shlibs.local</file> file, as explained below (see
5295           <ref id="shlibslocal">).
5296         </p>
5297
5298         <p>
5299           If you have multiple binary packages, you will need to call
5300           <prgn>dpkg-shlibdeps</prgn> on each one which contains
5301           compiled libraries or binaries.  In such a case, you will
5302           need to use the <tt>-T</tt> option to the <tt>dpkg</tt>
5303           utilities to specify a different <file>substvars</file> file.
5304         </p>
5305
5306         <p>
5307           If you are creating a udeb for use in the Debian Installer, you
5308           will need to specify that <prgn>dpkg-shlibdeps</prgn> should use
5309           the dependency line of type <tt>udeb</tt> by adding
5310           <tt>-tudeb</tt> as option<footnote>
5311               <prgn>dh_shlibdeps</prgn> from the <tt>debhelper</tt> suite
5312               will automatically add this option if it knows it is
5313               processing a udeb.
5314           </footnote>. If there is no dependency line of type <tt>udeb</tt>
5315           in the <file>shlibs</file> file, <prgn>dpkg-shlibdeps</prgn> will
5316           fall back to the regular dependency line.
5317         </p>
5318
5319         <p>
5320           For more details on dpkg-shlibdeps, please see
5321           <ref id="pkg-dpkg-shlibdeps"> and
5322           <manref name="dpkg-shlibdeps" section="1">.
5323         </p>
5324       </sect1>
5325
5326       <sect1 id="shlibs">
5327         <heading>The <file>shlibs</file> File Format</heading>
5328
5329         <p>
5330           Each <file>shlibs</file> file has the same format.  Lines
5331           beginning with <tt>#</tt> are considered to be comments and
5332           are ignored.  Each line is of the form:
5333           <example compact="compact">
5334 [<var>type</var>: ]<var>library-name</var> <var>soname-version</var> <var>dependencies ...</var>
5335           </example>
5336         </p>
5337
5338         <p>
5339           We will explain this by reference to the example of the
5340           <tt>zlib1g</tt> package, which (at the time of writing)
5341           installs the shared library <file>/usr/lib/libz.so.1.1.3</file>.
5342         </p>
5343
5344         <p>
5345           <var>type</var> is an optional element that indicates the type
5346           of package for which the line is valid. The only type currently
5347           in use is <tt>udeb</tt>. The colon and space after the type are
5348           required.
5349         </p>
5350
5351         <p>
5352           <var>library-name</var> is the name of the shared library,
5353           in this case <tt>libz</tt>.  (This must match the name part
5354           of the soname, see below.)
5355         </p>
5356
5357         <p>
5358           <var>soname-version</var> is the version part of the soname of
5359           the library.  The soname is the thing that must exactly match
5360           for the library to be recognized by the dynamic linker, and is
5361           usually of the form
5362           <tt><var>name</var>.so.<var>major-version</var></tt>, in our
5363           example, <tt>libz.so.1</tt>.<footnote>
5364               This can be determined using the command
5365               <example compact="compact">
5366 objdump -p /usr/lib/libz.so.1.1.3 | grep SONAME
5367               </example>
5368           </footnote>
5369           The version part is the part which comes after
5370           <tt>.so.</tt>, so in our case, it is <tt>1</tt>.
5371         </p>
5372
5373         <p>
5374           <var>dependencies</var> has the same syntax as a dependency
5375           field in a binary package control file.  It should give
5376           details of which packages are required to satisfy a binary
5377           built against the version of the library contained in the
5378           package.  See <ref id="depsyntax"> for details.
5379         </p>
5380
5381         <p>
5382           In our example, if the first version of the <tt>zlib1g</tt>
5383           package which contained a minor number of at least
5384           <tt>1.3</tt> was <var>1:1.1.3-1</var>, then the
5385           <tt>shlibs</tt> entry for this library could say:
5386           <example compact="compact">
5387 libz 1 zlib1g (>= 1:1.1.3)
5388           </example>
5389           The version-specific dependency is to avoid warnings from
5390           the dynamic linker about using older shared libraries with
5391           newer binaries.
5392         </p>
5393
5394         <p>
5395           As zlib1g also provides a udeb containing the shared library,
5396           there would also be a second line:
5397           <example compact="compact">
5398 udeb: libz 1 zlib1g-udeb (>= 1:1.1.3)
5399           </example>
5400         </p>
5401       </sect1>
5402
5403       <sect1>
5404         <heading>Providing a <file>shlibs</file> file</heading>
5405
5406         <p>
5407           If your package provides a shared library, you need to create
5408           a <file>shlibs</file> file following the format described above.
5409           It is usual to call this file <file>debian/shlibs</file> (but if
5410           you have multiple binary packages, you might want to call it
5411           <file>debian/shlibs.<var>package</var></file> instead).  Then
5412           let <file>debian/rules</file> install it in the control area:
5413           <example compact="compact">
5414 install -m644 debian/shlibs debian/tmp/DEBIAN
5415           </example>
5416           or, in the case of a multi-binary package:
5417           <example compact="compact">
5418 install -m644 debian/shlibs.<var>package</var> debian/<var>package</var>/DEBIAN/shlibs
5419           </example>
5420           An alternative way of doing this is to create the
5421           <file>shlibs</file> file in the control area directly from
5422           <file>debian/rules</file> without using a <file>debian/shlibs</file>
5423           file at all,<footnote>
5424               This is what <prgn>dh_makeshlibs</prgn> in the
5425               <tt>debhelper</tt> suite does. If your package also has a udeb
5426               that provides a shared library, <prgn>dh_makeshlibs</prgn> can
5427               automatically generate the <tt>udeb:</tt> lines if you specify
5428               the name of the udeb with the <tt>--add-udeb</tt> option.
5429           </footnote>
5430           since the <file>debian/shlibs</file> file itself is ignored by
5431           <prgn>dpkg-shlibdeps</prgn>.
5432         </p>
5433
5434         <p>
5435           As <prgn>dpkg-shlibdeps</prgn> reads the
5436           <file>DEBIAN/shlibs</file> files in all of the binary packages
5437           being built from this source package, all of the
5438           <file>DEBIAN/shlibs</file> files should be installed before
5439           <prgn>dpkg-shlibdeps</prgn> is called on any of the binary
5440           packages.
5441         </p>
5442       </sect1>
5443
5444       <sect1 id="shlibslocal">
5445         <heading>Writing the <file>debian/shlibs.local</file> file</heading>
5446
5447         <p>
5448           This file is intended only as a <em>temporary</em> fix if
5449           your binaries or libraries depend on a library whose package
5450           does not yet provide a correct <file>shlibs</file> file.
5451         </p>
5452
5453         <p>
5454           We will assume that you are trying to package a binary
5455           <tt>foo</tt>.  When you try running
5456           <prgn>dpkg-shlibdeps</prgn> you get the following error
5457           message (<tt>-O</tt> displays the dependency information on
5458           <tt>stdout</tt> instead of writing it to
5459           <tt>debian/substvars</tt>, and the lines have been wrapped
5460           for ease of reading):
5461           <example compact="compact">
5462 $ dpkg-shlibdeps -O debian/tmp/usr/bin/foo
5463 dpkg-shlibdeps: warning: unable to find dependency
5464   information for shared library libbar (soname 1,
5465   path /usr/lib/libbar.so.1, dependency field Depends)
5466 shlibs:Depends=libc6 (>= 2.2.2-2)
5467           </example>
5468           You can then run <prgn>ldd</prgn> on the binary to find the
5469           full location of the library concerned:
5470           <example compact="compact">
5471 $ ldd foo
5472 libbar.so.1 => /usr/lib/libbar.so.1 (0x4001e000)
5473 libc.so.6 => /lib/libc.so.6 (0x40032000)
5474 /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
5475           </example>
5476           So the <prgn>foo</prgn> binary depends on the
5477           <prgn>libbar</prgn> shared library, but no package seems to
5478           provide a <file>*.shlibs</file> file handling
5479           <file>libbar.so.1</file> in <file>/var/lib/dpkg/info/</file>.  Let's
5480           determine the package responsible:
5481           <example compact="compact">
5482 $ dpkg -S /usr/lib/libbar.so.1
5483 bar1: /usr/lib/libbar.so.1
5484 $ dpkg -s bar1 | grep Version
5485 Version: 1.0-1
5486           </example>
5487           This tells us that the <tt>bar1</tt> package, version 1.0-1,
5488           is the one we are using.  Now we can file a bug against the
5489           <tt>bar1</tt> package and create our own
5490           <file>debian/shlibs.local</file> to locally fix the problem.
5491           Including the following line into your
5492           <file>debian/shlibs.local</file> file:
5493           <example compact="compact">
5494 libbar 1 bar1 (>= 1.0-1)
5495           </example>
5496           should allow the package build to work.
5497         </p>
5498
5499         <p>
5500           As soon as the maintainer of <tt>bar1</tt> provides a
5501           correct <file>shlibs</file> file, you should remove this line
5502           from your <file>debian/shlibs.local</file> file.  (You should
5503           probably also then have a versioned <tt>Build-Depends</tt>
5504           on <tt>bar1</tt> to help ensure that others do not have the
5505           same problem building your package.)
5506         </p>
5507       </sect1>
5508
5509       </sect>
5510
5511     </chapt>
5512
5513
5514     <chapt id="opersys"><heading>The Operating System</heading>
5515
5516       <sect>
5517         <heading>File system hierarchy</heading>
5518
5519
5520         <sect1 id="fhs">
5521           <heading>File system Structure</heading>
5522
5523           <p>
5524             The location of all installed files and directories must
5525             comply with the File system Hierarchy Standard (FHS),
5526             version 2.3, with the exceptions noted below, and except
5527             where doing so would violate other terms of Debian
5528             Policy.  The following exceptions to the FHS apply:
5529
5530             <enumlist>
5531               <item>
5532                 <p>
5533                   Legacy XFree86 servers are permitted to retain the
5534                   configuration file location 
5535                   <file>/etc/X11/XF86Config-4</file>.
5536                 </p>
5537               </item>
5538               <item>
5539                 <p>
5540                   The optional rules related to user specific
5541                   configuration files for applications are stored in
5542                   the user's home directory are relaxed.  It is
5543                   recommended that such files start with the
5544                   '<tt>.</tt>' character (a "dot file"), and if an
5545                   application needs to create more than one dot file
5546                   then the preferred placement is in a subdirectory
5547                   with a name starting with a '.' character, (a "dot
5548                   directory"). In this case it is recommended the
5549                   configuration files not start with the '.'
5550                   character.
5551                 </p>
5552               </item>
5553               <item>
5554                 <p>
5555                   The requirement for amd64 to use <file>/lib64</file>
5556                   for 64 bit binaries is removed.
5557                 </p>
5558               </item>
5559               <item>
5560                 <p>
5561                   The requirement that
5562                   <file>/usr/local/share/man</file> be "synonymous"
5563                   with <file>/usr/local/man</file> is relaxed to a
5564                   recommendation</p>
5565               </item>
5566               <item>
5567                 <p>
5568                   The requirement that windowmanagers with a single
5569                   configuration file call it <file>system.*wmrc</file>
5570                   is removed, as is the restriction that the window
5571                   manager subdirectory be named identically to the
5572                   window manager name itself.
5573                 </p>
5574               </item>
5575               <item>
5576                 <p>
5577                   The requirement that boot manager configuration
5578                   files live in <file>/etc</file>, or at least are
5579                   symlinked there, is relaxed to a recommendation.
5580                 </p>
5581               </item>
5582             </enumlist>
5583
5584           </p>
5585           <p>
5586             The version of this document referred here can be
5587             found in the <tt>debian-policy</tt> package or on <url
5588             id="http://www.debian.org/doc/packaging-manuals/fhs/"
5589               name="FHS (Debian copy)"> alongside this manual (or, if
5590             you have the <package>debian-policy</package> installed,
5591             you can try <url
5592               id="file:///usr/share/doc/debian-policy/fhs/" name="FHS
5593               (local copy)">). The
5594             latest version, which may be a more recent version, may
5595             be found on
5596             <url id="http://www.pathname.com/fhs/" name="FHS (upstream)">.
5597             Specific questions about following the standard may be
5598             asked on the <tt>debian-devel</tt> mailing list, or
5599             referred to the FHS mailing list (see the
5600             <url id="http://www.pathname.com/fhs/" name="FHS web site"> for
5601             more information).
5602           </p>
5603         </sect1>
5604
5605         <sect1>
5606           <heading>Site-specific programs</heading>
5607
5608           <p>
5609             As mandated by the FHS, packages must not place any
5610             files in <file>/usr/local</file>, either by putting them in
5611             the file system archive to be unpacked by <prgn>dpkg</prgn>
5612             or by manipulating them in their maintainer scripts.
5613           </p>
5614
5615           <p>
5616             However, the package may create empty directories below
5617             <file>/usr/local</file> so that the system administrator knows
5618             where to place site-specific files.  These are not
5619             directories <em>in</em> <file>/usr/local</file>, but are
5620             children of directories in <file>/usr/local</file>.  These
5621             directories (<file>/usr/local/*/dir/</file>)
5622             should be removed on package removal if they are
5623             empty.
5624           </p>
5625
5626           <p>
5627             Note, that this applies only to directories <em>below</em>
5628             <file>/usr/local</file>, not <em>in</em> <file>/usr/local</file>.
5629             Packages must not create sub-directories in the directory
5630             <file>/usr/local</file> itself, except those listed in FHS,
5631             section 4.5.  However, you may create directories below
5632             them as you wish. You must not remove any of the
5633             directories listed in 4.5, even if you created them.
5634           </p>
5635
5636           <p>
5637             Since <file>/usr/local</file> can be mounted read-only from a
5638             remote server, these directories must be created and
5639             removed by the <prgn>postinst</prgn> and <prgn>prerm</prgn>
5640             maintainer scripts and not be included in the
5641             <file>.deb</file> archive.  These scripts must not fail if
5642             either of these operations fail.
5643           </p>
5644
5645           <p>
5646             For example, the <tt>emacsen-common</tt> package could
5647             contain something like
5648             <example compact="compact">
5649 if [ ! -e /usr/local/share/emacs ]
5650 then
5651   if mkdir /usr/local/share/emacs 2>/dev/null
5652   then
5653     chown root:staff /usr/local/share/emacs
5654     chmod 2775 /usr/local/share/emacs
5655   fi
5656 fi
5657             </example>
5658             in its <prgn>postinst</prgn> script, and
5659             <example compact="compact">
5660 rmdir /usr/local/share/emacs/site-lisp 2>/dev/null || true
5661 rmdir /usr/local/share/emacs 2>/dev/null || true
5662             </example>
5663             in the <prgn>prerm</prgn> script.  (Note that this form is
5664             used to ensure that if the script is interrupted, the
5665             directory <file>/usr/local/share/emacs</file> will still be
5666             removed.)
5667           </p>
5668
5669           <p>
5670             If you do create a directory in <file>/usr/local</file> for
5671             local additions to a package, you should ensure that
5672             settings in <file>/usr/local</file> take precedence over the
5673             equivalents in <file>/usr</file>.
5674           </p>
5675
5676           <p>
5677             However, because <file>/usr/local</file> and its contents are
5678             for exclusive use of the local administrator, a package
5679             must not rely on the presence or absence of files or
5680             directories in <file>/usr/local</file> for normal operation.
5681           </p>
5682
5683           <p>
5684             The <file>/usr/local</file> directory itself and all the
5685             subdirectories created by the package should (by default) have
5686             permissions 2775 (group-writable and set-group-id) and be
5687             owned by <tt>root:staff</tt>.
5688           </p>
5689         </sect1>
5690
5691         <sect1>
5692           <heading>The system-wide mail directory</heading>
5693           <p>
5694             The system-wide mail directory is <file>/var/mail</file>. This
5695             directory is part of the base system and should not owned
5696             by any particular mail agents.  The use of the old
5697             location <file>/var/spool/mail</file> is deprecated, even
5698             though the spool may still be physically located there.
5699             To maintain partial upgrade compatibility for systems
5700             which have <file>/var/spool/mail</file> as their physical mail
5701             spool, packages using <file>/var/mail</file> must depend on
5702             either <package>libc6</package> (&gt;= 2.1.3-13), or on
5703             <package>base-files</package> (&gt;= 2.2.0), or on later
5704             versions of either one of these packages.
5705           </p>
5706         </sect1>
5707       </sect>
5708
5709       <sect>
5710         <heading>Users and groups</heading>
5711
5712         <sect1>
5713           <heading>Introduction</heading>
5714           <p>
5715             The Debian system can be configured to use either plain or
5716             shadow passwords.
5717           </p>
5718
5719           <p>
5720             Some user ids (UIDs) and group ids (GIDs) are reserved
5721             globally for use by certain packages.  Because some
5722             packages need to include files which are owned by these
5723             users or groups, or need the ids compiled into binaries,
5724             these ids must be used on any Debian system only for the
5725             purpose for which they are allocated. This is a serious
5726             restriction, and we should avoid getting in the way of
5727             local administration policies. In particular, many sites
5728             allocate users and/or local system groups starting at 100.
5729           </p>
5730
5731           <p>
5732             Apart from this we should have dynamically allocated ids,
5733             which should by default be arranged in some sensible
5734             order, but the behavior should be configurable.
5735           </p>
5736
5737           <p>
5738             Packages other than <tt>base-passwd</tt> must not modify
5739             <file>/etc/passwd</file>, <file>/etc/shadow</file>,
5740             <file>/etc/group</file> or <file>/etc/gshadow</file>.
5741           </p>
5742         </sect1>
5743
5744         <sect1>
5745           <heading>UID and GID classes</heading>
5746           <p>
5747             The UID and GID numbers are divided into classes as
5748             follows:
5749             <taglist>
5750               <tag>0-99:</tag>
5751               <item>
5752                 <p>
5753                   Globally allocated by the Debian project, the same
5754                   on every Debian system.  These ids will appear in
5755                   the <file>passwd</file> and <file>group</file> files of all
5756                   Debian systems, new ids in this range being added
5757                   automatically as the <tt>base-passwd</tt> package is
5758                   updated.
5759                 </p>
5760
5761                 <p>
5762                   Packages which need a single statically allocated
5763                   uid or gid should use one of these; their
5764                   maintainers should ask the <tt>base-passwd</tt>
5765                   maintainer for ids.
5766                 </p>
5767               </item>
5768
5769               <tag>100-999:</tag>
5770               <item>
5771                 <p>
5772                   Dynamically allocated system users and groups.
5773                   Packages which need a user or group, but can have
5774                   this user or group allocated dynamically and
5775                   differently on each system, should use <tt>adduser
5776                   --system</tt> to create the group and/or user.
5777                   <prgn>adduser</prgn> will check for the existence of
5778                   the user or group, and if necessary choose an unused
5779                   id based on the ranges specified in
5780                   <file>adduser.conf</file>.
5781                 </p>
5782               </item>
5783
5784               <tag>1000-29999:</tag>
5785               <item>
5786                 <p>
5787                   Dynamically allocated user accounts.  By default
5788                   <prgn>adduser</prgn> will choose UIDs and GIDs for
5789                   user accounts in this range, though
5790                   <file>adduser.conf</file> may be used to modify this
5791                   behavior.
5792                 </p>
5793               </item>
5794
5795               <tag>30000-59999:</tag>
5796               <item>
5797                 <p>Reserved.</p>
5798               </item>
5799
5800               <tag>60000-64999:</tag>
5801               <item>
5802                 <p>
5803                   Globally allocated by the Debian project, but only
5804                   created on demand. The ids are allocated centrally
5805                   and statically, but the actual accounts are only
5806                   created on users' systems on demand.
5807                 </p>
5808
5809                 <p>
5810                   These ids are for packages which are obscure or
5811                   which require many statically-allocated ids.  These
5812                   packages should check for and create the accounts in
5813                   <file>/etc/passwd</file> or <file>/etc/group</file> (using
5814                   <prgn>adduser</prgn> if it has this facility) if
5815                   necessary.  Packages which are likely to require
5816                   further allocations should have a "hole" left after
5817                   them in the allocation, to give them room to
5818                   grow.
5819                 </p>
5820               </item>
5821
5822               <tag>65000-65533:</tag>
5823               <item>
5824                 <p>Reserved.</p>
5825               </item>
5826
5827               <tag>65534:</tag>
5828               <item>
5829                 <p>
5830                   User <tt>nobody</tt>. The corresponding gid refers
5831                   to the group <tt>nogroup</tt>.
5832                 </p>
5833               </item>
5834
5835               <tag>65535:</tag>
5836               <item>
5837                 <p>
5838                   <tt>(uid_t)(-1) == (gid_t)(-1)</tt> <em>must
5839                   not</em> be used, because it is the error return
5840                   sentinel value.
5841                 </p>
5842               </item>
5843             </taglist>
5844           </p>
5845         </sect1>
5846       </sect>
5847
5848       <sect id="sysvinit">
5849         <heading>System run levels and <file>init.d</file> scripts</heading>
5850
5851         <sect1 id="/etc/init.d">
5852           <heading>Introduction</heading>
5853
5854           <p>
5855             The <file>/etc/init.d</file> directory contains the scripts
5856             executed by <prgn>init</prgn> at boot time and when the
5857             init state (or "runlevel") is changed (see <manref
5858             name="init" section="8">).
5859           </p>
5860
5861           <p>
5862             There are at least two different, yet functionally
5863             equivalent, ways of handling these scripts.  For the sake
5864             of simplicity, this document describes only the symbolic
5865             link method. However, it must not be assumed by maintainer
5866             scripts that this method is being used, and any automated
5867             manipulation of the various runlevel behaviors by
5868             maintainer scripts must be performed using
5869             <prgn>update-rc.d</prgn> as described below and not by
5870             manually installing or removing symlinks.  For information
5871             on the implementation details of the other method,
5872             implemented in the <tt>file-rc</tt> package, please refer
5873             to the documentation of that package.
5874           </p>
5875
5876           <p>
5877             These scripts are referenced by symbolic links in the
5878             <file>/etc/rc<var>n</var>.d</file> directories.  When changing
5879             runlevels, <prgn>init</prgn> looks in the directory
5880             <file>/etc/rc<var>n</var>.d</file> for the scripts it should
5881             execute, where <tt><var>n</var></tt> is the runlevel that
5882             is being changed to, or <tt>S</tt> for the boot-up
5883             scripts.
5884           </p>
5885
5886           <p>
5887             The names of the links all have the form
5888             <file>S<var>mm</var><var>script</var></file> or
5889             <file>K<var>mm</var><var>script</var></file> where
5890             <var>mm</var> is a two-digit number and <var>script</var>
5891             is the name of the script (this should be the same as the
5892             name of the actual script in <file>/etc/init.d</file>).
5893           </p>
5894
5895           <p>
5896             When <prgn>init</prgn> changes runlevel first the targets
5897             of the links whose names start with a <tt>K</tt> are
5898             executed, each with the single argument <tt>stop</tt>,
5899             followed by the scripts prefixed with an <tt>S</tt>, each
5900             with the single argument <tt>start</tt>.  (The links are
5901             those in the <file>/etc/rc<var>n</var>.d</file> directory
5902             corresponding to the new runlevel.)  The <tt>K</tt> links
5903             are responsible for killing services and the <tt>S</tt>
5904             link for starting services upon entering the runlevel.
5905           </p>
5906
5907           <p>
5908             For example, if we are changing from runlevel 2 to
5909             runlevel 3, init will first execute all of the <tt>K</tt>
5910             prefixed scripts it finds in <file>/etc/rc3.d</file>, and then
5911             all of the <tt>S</tt> prefixed scripts in that directory.
5912             The links starting with <tt>K</tt> will cause the
5913             referred-to file to be executed with an argument of
5914             <tt>stop</tt>, and the <tt>S</tt> links with an argument
5915             of <tt>start</tt>.
5916           </p>
5917
5918           <p>
5919             The two-digit number <var>mm</var> is used to determine
5920             the order in which to run the scripts: low-numbered links
5921             have their scripts run first.  For example, the
5922             <tt>K20</tt> scripts will be executed before the
5923             <tt>K30</tt> scripts.  This is used when a certain service
5924             must be started before another.  For example, the name
5925             server <prgn>bind</prgn> might need to be started before
5926             the news server <prgn>inn</prgn> so that <prgn>inn</prgn>
5927             can set up its access lists.  In this case, the script
5928             that starts <prgn>bind</prgn> would have a lower number
5929             than the script that starts <prgn>inn</prgn> so that it
5930             runs first:
5931             <example compact="compact">
5932 /etc/rc2.d/S17bind
5933 /etc/rc2.d/S70inn
5934             </example>
5935           </p>
5936
5937           <p>
5938             The two runlevels 0 (halt) and 6 (reboot) are slightly
5939             different.  In these runlevels, the links with an
5940             <tt>S</tt> prefix are still called after those with a
5941             <tt>K</tt> prefix, but they too are called with the single
5942             argument <tt>stop</tt>.
5943           </p>
5944
5945           <p>
5946             Also, if the script name ends in <tt>.sh</tt>, the script
5947             will be sourced in runlevel <tt>S</tt> rather than being
5948             run in a forked subprocess, but will be explicitly run by
5949             <prgn>sh</prgn> in all other runlevels.
5950           </p>
5951         </sect1>
5952
5953         <sect1>
5954           <heading>Writing the scripts</heading>
5955
5956           <p>
5957             Packages that include daemons for system services should
5958             place scripts in <file>/etc/init.d</file> to start or stop
5959             services at boot time or during a change of runlevel.
5960             These scripts should be named
5961             <file>/etc/init.d/<var>package</var></file>, and they should
5962             accept one argument, saying what to do:
5963
5964             <taglist>
5965               <tag><tt>start</tt></tag>
5966               <item>start the service,</item>
5967
5968               <tag><tt>stop</tt></tag>
5969               <item>stop the service,</item>
5970
5971               <tag><tt>restart</tt></tag>
5972               <item>stop and restart the service if it's already running,
5973                   otherwise start the service</item>
5974
5975               <tag><tt>reload</tt></tag>
5976               <item><p>cause the configuration of the service to be
5977                   reloaded without actually stopping and restarting
5978                   the service,</item>
5979
5980               <tag><tt>force-reload</tt></tag>
5981               <item>cause the configuration to be reloaded if the
5982                   service supports this, otherwise restart the
5983                   service.</item>
5984             </taglist>
5985
5986             The <tt>start</tt>, <tt>stop</tt>, <tt>restart</tt>, and
5987             <tt>force-reload</tt> options should be supported by all
5988             scripts in <file>/etc/init.d</file>, the <tt>reload</tt>
5989             option is optional.
5990           </p>
5991
5992           <p>
5993             The <file>init.d</file> scripts must ensure that they will
5994             behave sensibly (i.e., returning success and not starting
5995             multiple copies of a service) if invoked with <tt>start</tt>
5996             when the service is already running, or with <tt>stop</tt>
5997             when it isn't, and that they don't kill unfortunately-named
5998             user processes.  The best way to achieve this is usually to
5999             use <prgn>start-stop-daemon</prgn> with the <tt>--oknodo</tt>
6000             option.
6001           </p>
6002
6003           <p>
6004             If a service reloads its configuration automatically (as
6005             in the case of <prgn>cron</prgn>, for example), the
6006             <tt>reload</tt> option of the <file>init.d</file> script
6007             should behave as if the configuration has been reloaded
6008             successfully.
6009           </p>
6010
6011           <p>
6012             The <file>/etc/init.d</file> scripts must be treated as
6013             configuration files, either (if they are present in the
6014             package, that is, in the .deb file) by marking them as
6015             <tt>conffile</tt>s, or, (if they do not exist in the .deb)
6016             by managing them correctly in the maintainer scripts (see
6017             <ref id="config-files">).  This is important since we want
6018             to give the local system administrator the chance to adapt
6019             the scripts to the local system, e.g., to disable a
6020             service without de-installing the package, or to specify
6021             some special command line options when starting a service,
6022             while making sure their changes aren't lost during the next
6023             package upgrade.
6024           </p>
6025
6026           <p>
6027             These scripts should not fail obscurely when the
6028             configuration files remain but the package has been
6029             removed, as configuration files remain on the system after
6030             the package has been removed.  Only when <prgn>dpkg</prgn>
6031             is executed with the <tt>--purge</tt> option will
6032             configuration files be removed.  In particular, as the
6033             <file>/etc/init.d/<var>package</var></file> script itself is
6034             usually a <tt>conffile</tt>, it will remain on the system
6035             if the package is removed but not purged.  Therefore, you
6036             should include a <tt>test</tt> statement at the top of the
6037             script, like this:
6038             <example compact="compact">
6039 test -f <var>program-executed-later-in-script</var> || exit 0
6040             </example>
6041           </p>
6042
6043           <p>
6044             Often there are some variables in the <file>init.d</file>
6045             scripts whose values control the behavior of the scripts,
6046             and which a system administrator is likely to want to
6047             change.  As the scripts themselves are frequently
6048             <tt>conffile</tt>s, modifying them requires that the
6049             administrator merge in their changes each time the package
6050             is upgraded and the <tt>conffile</tt> changes.  To ease
6051             the burden on the system administrator, such configurable
6052             values should not be placed directly in the script.
6053             Instead, they should be placed in a file in
6054             <file>/etc/default</file>, which typically will have the same
6055             base name as the <file>init.d</file> script.  This extra file
6056             should be sourced by the script when the script runs.  It
6057             must contain only variable settings and comments in SUSv3
6058             <prgn>sh</prgn> format.  It may either be a
6059             <tt>conffile</tt> or a configuration file maintained by
6060             the package maintainer scripts.  See <ref id="config-files">
6061             for more details.
6062           </p>
6063
6064           <p>
6065             To ensure that vital configurable values are always
6066             available, the <file>init.d</file> script should set default
6067             values for each of the shell variables it uses, either
6068             before sourcing the <file>/etc/default/</file> file or
6069             afterwards using something like the <tt>:
6070             ${VAR:=default}</tt> syntax.  Also, the <file>init.d</file>
6071             script must behave sensibly and not fail if the
6072             <file>/etc/default</file> file is deleted.
6073           </p>
6074         </sect1>
6075
6076         <sect1>
6077           <heading>Interfacing with the initscript system</heading>
6078
6079           <p>
6080             Maintainers should use the abstraction layer provided by
6081             the <prgn>update-rc.d</prgn> and <prgn>invoke-rc.d</prgn>
6082             programs to deal with initscripts in their packages'
6083             scripts such as <prgn>postinst</prgn>, <prgn>prerm</prgn>
6084             and <prgn>postrm</prgn>.
6085           </p>
6086
6087           <p>
6088             Directly managing the /etc/rc?.d links and directly
6089             invoking the <file>/etc/init.d/</file> initscripts should
6090             be done only by packages providing the initscript
6091             subsystem (such as <prgn>sysv-rc</prgn> and
6092             <prgn>file-rc</prgn>).
6093           </p>
6094
6095           <sect2>
6096             <heading>Managing the links</heading>
6097
6098             <p>
6099               The program <prgn>update-rc.d</prgn> is provided for
6100               package maintainers to arrange for the proper creation and
6101               removal of <file>/etc/rc<var>n</var>.d</file> symbolic links,
6102               or their functional equivalent if another method is being
6103               used.  This may be used by maintainers in their packages'
6104               <prgn>postinst</prgn> and <prgn>postrm</prgn> scripts.
6105             </p>
6106
6107             <p>
6108               You must not include any <file>/etc/rc<var>n</var>.d</file>
6109               symbolic links in the actual archive or manually create or
6110               remove the symbolic links in maintainer scripts; you must
6111               use the <prgn>update-rc.d</prgn> program instead.  (The
6112               former will fail if an alternative method of maintaining
6113               runlevel information is being used.)  You must not include
6114               the <file>/etc/rc<var>n</var>.d</file> directories themselves
6115               in the archive either.  (Only the <tt>sysvinit</tt>
6116               package may do so.)
6117             </p>
6118
6119             <p>
6120               By default <prgn>update-rc.d</prgn> will start services in
6121               each of the multi-user state runlevels (2, 3, 4, and 5)
6122               and stop them in the halt runlevel (0), the single-user
6123               runlevel (1) and the reboot runlevel (6).  The system
6124               administrator will have the opportunity to customize
6125               runlevels by simply adding, moving, or removing the
6126               symbolic links in <file>/etc/rc<var>n</var>.d</file> if
6127               symbolic links are being used, or by modifying
6128               <file>/etc/runlevel.conf</file> if the <tt>file-rc</tt> method
6129               is being used.
6130             </p>
6131
6132             <p>
6133               To get the default behavior for your package, put in your
6134               <prgn>postinst</prgn> script
6135               <example compact="compact">
6136                 update-rc.d <var>package</var> defaults
6137               </example>
6138               and in your <prgn>postrm</prgn>
6139               <example compact="compact">
6140                 if [ "$1" = purge ]; then
6141                 update-rc.d <var>package</var> remove
6142                 fi
6143               </example>. Note that if your package changes runlevels
6144               or priority, you may have to remove and recreate the links,
6145               since otherwise the old links may persist. Refer to the
6146               documentation of <prgn>update-rc.d</prgn>.
6147             </p>
6148
6149             <p>
6150               This will use a default sequence number of 20.  If it does
6151               not matter when or in which order the <file>init.d</file>
6152               script is run, use this default.  If it does, then you
6153               should talk to the maintainer of the <prgn>sysvinit</prgn>
6154               package or post to <tt>debian-devel</tt>, and they will
6155               help you choose a number.
6156             </p>
6157
6158             <p>
6159               For more information about using <tt>update-rc.d</tt>,
6160               please consult its man page <manref name="update-rc.d"
6161                 section="8">.
6162             </p>
6163           </sect2>
6164
6165           <sect2>
6166             <heading>Running initscripts</heading>
6167             <p>
6168               The program <prgn>invoke-rc.d</prgn> is provided to make
6169               it easier for package maintainers to properly invoke an
6170               initscript, obeying runlevel and other locally-defined
6171               constraints that might limit a package's right to start,
6172               stop and otherwise manage services. This program may be
6173               used by maintainers in their packages' scripts.
6174             </p>
6175
6176             <p>
6177               The package maintainer scripts must use
6178               <prgn>invoke-rc.d</prgn> to invoke the
6179               <file>/etc/init.d/*</file> initscripts, instead of
6180               calling them directly.
6181             </p>
6182
6183             <p>
6184               By default, <prgn>invoke-rc.d</prgn> will pass any
6185               action requests (start, stop, reload, restart...) to the
6186               <file>/etc/init.d</file> script, filtering out requests
6187               to start or restart a service out of its intended
6188               runlevels.
6189             </p>
6190
6191             <p>
6192               Most packages will simply need to change:
6193               <example compact="compact">/etc/init.d/&lt;package&gt;
6194               &lt;action&gt;</example> in their <prgn>postinst</prgn>
6195               and <prgn>prerm</prgn> scripts to:
6196               <example compact="compact">
6197         if which invoke-rc.d >/dev/null 2>&1; then
6198                 invoke-rc.d <var>package</var> &lt;action&gt;
6199         else
6200                 /etc/init.d/<var>package</var> &lt;action&gt;
6201         fi
6202               </example>
6203             </p>
6204
6205             <p>
6206               A package should register its initscript services using
6207               <prgn>update-rc.d</prgn> before it tries to invoke them
6208               using <prgn>invoke-rc.d</prgn>. Invocation of
6209               unregistered services may fail.
6210             </p>
6211
6212             <p>
6213               For more information about using
6214               <prgn>invoke-rc.d</prgn>, please consult its man page
6215               <manref name="invoke-rc.d" section="8">.
6216             </p>
6217           </sect2>
6218         </sect1>
6219
6220         <sect1>
6221           <heading>Boot-time initialization</heading>
6222
6223           <p>
6224             There used to be another directory, <file>/etc/rc.boot</file>,
6225             which contained scripts which were run once per machine
6226             boot. This has been deprecated in favour of links from
6227             <file>/etc/rcS.d</file> to files in <file>/etc/init.d</file> as
6228             described in <ref id="/etc/init.d">.  Packages must not
6229             place files in <file>/etc/rc.boot</file>.
6230           </p>
6231         </sect1>
6232
6233         <sect1>
6234           <heading>Example</heading>
6235
6236           <p>
6237             An example on which you can base your
6238             <file>/etc/init.d</file> scripts is found in
6239             <file>/etc/init.d/skeleton</file>.
6240           </p>
6241
6242         </sect1>
6243       </sect>
6244
6245       <sect>
6246         <heading>Console messages from <file>init.d</file> scripts</heading>
6247
6248         <p>
6249           This section describes the formats to be used for messages
6250           written to standard output by the <file>/etc/init.d</file>
6251           scripts.  The intent is to improve the consistency of
6252           Debian's startup and shutdown look and feel.  For this
6253           reason, please look very carefully at the details.  We want
6254           the messages to have the same format in terms of wording,
6255           spaces, punctuation and case of letters.
6256         </p>
6257
6258         <p>
6259           Here is a list of overall rules that should be used for
6260           messages generated by <file>/etc/init.d</file> scripts.  
6261         </p>
6262
6263         <p>
6264           <list>
6265             <item>
6266                 The message should fit in one line (fewer than 80
6267                 characters), start with a capital letter and end with
6268                 a period (<tt>.</tt>) and line feed (<tt>"\n"</tt>).
6269             </item>
6270
6271             <item>
6272               If the script is performing some time consuming task in
6273               the background (not merely starting or stopping a
6274               program, for instance), an ellipsis (three dots:
6275               <tt>...</tt>) should be output to the screen, with no
6276               leading or tailing whitespace or line feeds.
6277             </item>
6278
6279             <item>
6280               The messages should appear as if the computer is telling
6281               the user what it is doing (politely :-), but should not
6282                 mention "it" directly.  For example, instead of:
6283                 <example compact="compact">
6284 I'm starting network daemons: nfsd mountd.
6285                 </example>
6286                 the message should say
6287                 <example compact="compact">
6288 Starting network daemons: nfsd mountd.
6289                 </example>
6290             </item>
6291           </list>
6292         </p>
6293
6294         <p>
6295           <tt>init.d</tt> script should use the following  standard
6296           message formats for the situations enumerated below.
6297         </p>
6298
6299         <p>
6300           <list>
6301             <item>
6302               <p>When daemons are started</p>
6303
6304               <p>
6305                 If the script starts one or more daemons, the output
6306                 should look like this (a single line, no leading
6307                 spaces):
6308                 <example compact="compact">
6309 Starting <var>description</var>: <var>daemon-1</var> ... <var>daemon-n</var>.
6310                 </example>
6311                 The <var>description</var> should describe the
6312                 subsystem the daemon or set of daemons are part of,
6313                 while <var>daemon-1</var> up to <var>daemon-n</var>
6314                 denote each daemon's name (typically the file name of
6315                 the program).
6316               </p>
6317
6318               <p>
6319                 For example, the output of <file>/etc/init.d/lpd</file>
6320                 would look like:
6321                 <example compact="compact">
6322 Starting printer spooler: lpd.
6323                 </example>
6324               </p>
6325
6326               <p>
6327                 This can be achieved by saying
6328                 <example compact="compact">
6329 echo -n "Starting printer spooler: lpd"
6330 start-stop-daemon --start --quiet --exec /usr/sbin/lpd
6331 echo "."
6332                 </example>
6333                 in the script. If there are more than one daemon to
6334                 start, the output should look like this:
6335                 <example compact="compact">
6336 echo -n "Starting remote file system services:"
6337 echo -n " nfsd"; start-stop-daemon --start --quiet nfsd
6338 echo -n " mountd"; start-stop-daemon --start --quiet mountd
6339 echo -n " ugidd"; start-stop-daemon --start --quiet ugidd
6340 echo "."
6341                 </example>
6342                 This makes it possible for the user to see what is
6343                 happening and when the final daemon has been started.
6344                 Care should be taken in the placement of white spaces:
6345                 in the example above the system administrators can
6346                 easily comment out a line if they don't want to start
6347                 a specific daemon, while the displayed message still
6348                 looks good.
6349               </p>
6350             </item>
6351
6352             <item>
6353               <p>When a system parameter is being set</p>
6354
6355               <p>
6356                 If you have to set up different system parameters
6357                 during the system boot, you should use this format:
6358                 <example compact="compact">
6359 Setting <var>parameter</var> to "<var>value</var>".
6360                 </example>
6361               </p>
6362
6363               <p>
6364                 You can use a statement such as the following to get
6365                 the quotes right:
6366                 <example compact="compact">
6367 echo "Setting DNS domainname to \"$domainname\"."
6368                 </example>
6369               </p>
6370
6371               <p>
6372                 Note that the same symbol (<tt>"</tt>) is used for the left
6373                 and right quotation marks.  A grave accent (<tt>`</tt>) is
6374                 not a quote character; neither is an apostrophe
6375                 (<tt>'</tt>).
6376               </p>
6377             </item>
6378
6379             <item>
6380               <p>When a daemon is stopped or restarted</p>
6381
6382               <p>
6383                 When you stop or restart a daemon, you should issue a
6384                 message identical to the startup message, except that
6385                 <tt>Starting</tt> is replaced with <tt>Stopping</tt>
6386                 or <tt>Restarting</tt> respectively.
6387               </p>
6388
6389               <p>
6390                 For example, stopping the printer daemon will look like
6391                 this:
6392                 <example compact="compact">
6393 Stopping printer spooler: lpd.
6394                 </example>
6395               </p>
6396             </item>
6397
6398             <item>
6399               <p>When something is executed</p>
6400
6401               <p>
6402                 There are several examples where you have to run a
6403                 program at system startup or shutdown to perform a
6404                 specific task, for example, setting the system's clock
6405                 using <prgn>netdate</prgn> or killing all processes
6406                 when the system shuts down.  Your message should look
6407                 like this:
6408                 <example compact="compact">
6409 Doing something very useful...done.
6410                 </example>
6411                 You should print the <tt>done.</tt> immediately after
6412                 the job has been completed, so that the user is
6413                 informed why they have to wait.  You can get this
6414                 behavior by saying
6415                 <example compact="compact">
6416 echo -n "Doing something very useful..."
6417 do_something
6418 echo "done."
6419                 </example>
6420                 in your script.
6421               </p>
6422             </item>
6423
6424             <item>
6425               <p>When the configuration is reloaded</p>
6426
6427               <p>
6428                 When a daemon is forced to reload its configuration
6429                 files you should use the following format:
6430                 <example compact="compact">
6431 Reloading <var>description</var> configuration...done.
6432                 </example>
6433                 where <var>description</var> is the same as in the
6434                 daemon starting message.
6435               </p>
6436             </item>
6437           </list>
6438         </p>
6439       </sect>
6440
6441       <sect>
6442         <heading>Cron jobs</heading>
6443
6444         <p>
6445           Packages must not modify the configuration file
6446           <file>/etc/crontab</file>, and they must not modify the files in
6447           <file>/var/spool/cron/crontabs</file>.</p>
6448
6449         <p>
6450           If a package wants to install a job that has to be executed
6451           via cron, it should place a file with the name of the
6452           package in one or more of the following directories:
6453           <example compact="compact">
6454 /etc/cron.hourly
6455 /etc/cron.daily
6456 /etc/cron.weekly
6457 /etc/cron.monthly
6458           </example>
6459           As these directory names imply, the files within them are
6460           executed on an hourly, daily, weekly, or monthly basis,
6461           respectively. The exact times are listed in
6462           <file>/etc/crontab</file>.</p>
6463
6464         <p>
6465           All files installed in any of these directories must be
6466           scripts (e.g., shell scripts or Perl scripts) so that they
6467           can easily be modified by the local system administrator.
6468           In addition, they must be treated as configuration files.
6469         </p>
6470
6471         <p>
6472           If a certain job has to be executed at some other frequency or
6473           at a specific time, the package should install a file
6474           <file>/etc/cron.d/<var>package</var></file>. This file uses the
6475           same syntax as <file>/etc/crontab</file> and is processed by
6476           <prgn>cron</prgn> automatically. The file must also be
6477           treated as a configuration file. (Note that entries in the
6478           <file>/etc/cron.d</file> directory are not handled by
6479           <prgn>anacron</prgn>. Thus, you should only use this
6480           directory for jobs which may be skipped if the system is not
6481           running.)</p>
6482
6483         <p>
6484           The scripts or crontab entries in these directories should
6485           check if all necessary programs are installed before they
6486           try to execute them. Otherwise, problems will arise when a
6487           package was removed but not purged since configuration files
6488           are kept on the system in this situation.</p>
6489       </sect>
6490
6491       <sect id="menus">
6492         <heading>Menus</heading>
6493
6494         <p>
6495           The Debian <tt>menu</tt> package provides a standard
6496           interface between packages providing applications and
6497           <em>menu programs</em> (either X window managers or
6498           text-based menu programs such as <prgn>pdmenu</prgn>).
6499         </p>
6500
6501         <p>
6502           All packages that provide applications that need not be
6503           passed any special command line arguments for normal
6504           operation should register a menu entry for those
6505           applications, so that users of the <tt>menu</tt> package
6506           will automatically get menu entries in their window
6507           managers, as well in shells like <tt>pdmenu</tt>.
6508         </p>
6509
6510         <p>
6511           Menu entries should follow the current menu policy.
6512         </p>
6513
6514         <p>
6515           The menu policy can be found in the <tt>menu-policy</tt>
6516           files in the <tt>debian-policy</tt> package.
6517           It is also available from the Debian web mirrors at
6518           <tt><url name="/doc/packaging-manuals/menu-policy/"
6519                 id="http://www.debian.org/doc/packaging-manuals/menu-policy/"></tt>.
6520         </p>
6521
6522         <p>
6523           Please also refer to the <em>Debian Menu System</em>
6524           documentation that comes with the <package>menu</package>
6525           package for information about how to register your
6526           applications.
6527         </p>
6528       </sect>
6529
6530       <sect id="mime">
6531         <heading>Multimedia handlers</heading>
6532
6533         <p>
6534           MIME (Multipurpose Internet Mail Extensions, RFCs 2045-2049)
6535           is a mechanism for encoding files and data streams and
6536           providing meta-information about them, in particular their
6537           type (e.g.  audio or video) and format (e.g. PNG, HTML,
6538           MP3).
6539         </p>
6540
6541         <p>
6542           Registration of MIME type handlers allows programs like mail
6543           user agents and web browsers to invoke these handlers to
6544           view, edit or display MIME types they don't support directly.
6545         </p>
6546
6547         <p>
6548           Packages which provide the ability to view/show/play,
6549           compose, edit or print MIME types should register themselves
6550           as such following the current MIME support policy.
6551         </p>
6552
6553         <p>
6554           The MIME support policy can be found in the <tt>mime-policy</tt>
6555           files in the <tt>debian-policy</tt> package.
6556           It is also available from the Debian web mirrors at
6557           <tt><url name="/doc/packaging-manuals/mime-policy/"
6558                 id="http://www.debian.org/doc/packaging-manuals/mime-policy/"></tt>.
6559         </p>
6560
6561       </sect>
6562
6563       <sect>
6564         <heading>Keyboard configuration</heading>
6565
6566         <p>
6567           To achieve a consistent keyboard configuration so that all
6568           applications interpret a keyboard event the same way, all
6569           programs in the Debian distribution must be configured to
6570           comply with the following guidelines.
6571         </p>
6572
6573         <p>
6574           The following keys must have the specified interpretations:
6575
6576           <taglist>
6577             <tag><tt>&lt;--</tt></tag>
6578             <item>delete the character to the left of the cursor</item>
6579
6580             <tag><tt>Delete</tt></tag>
6581             <item>delete the character to the right of the cursor</item>
6582
6583             <tag><tt>Control+H</tt></tag>
6584             <item>emacs: the help prefix</item>
6585           </taglist>
6586
6587           The interpretation of any keyboard events should be
6588           independent of the terminal that is used, be it a virtual
6589           console, an X terminal emulator, an rlogin/telnet session,
6590           etc.
6591         </p>
6592
6593         <p>
6594           The following list explains how the different programs
6595           should be set up to achieve this:
6596         </p>
6597
6598         <p>
6599           <list>
6600             <item>
6601                 <tt>&lt;--</tt> generates <tt>KB_BackSpace</tt> in X.
6602             </item>
6603
6604             <item>
6605                 <tt>Delete</tt> generates <tt>KB_Delete</tt> in X.
6606             </item>
6607
6608             <item>
6609                 X translations are set up to make
6610                 <tt>KB_Backspace</tt> generate ASCII DEL, and to make
6611                 <tt>KB_Delete</tt> generate <tt>ESC [ 3 ~</tt> (this
6612                 is the vt220 escape code for the "delete character"
6613                 key).  This must be done by loading the X resources
6614                 using <prgn>xrdb</prgn> on all local X displays, not
6615                 using the application defaults, so that the
6616                 translation resources used correspond to the
6617                 <prgn>xmodmap</prgn> settings.
6618             </item>
6619
6620             <item>
6621                 The Linux console is configured to make
6622                 <tt>&lt;--</tt> generate DEL, and <tt>Delete</tt>
6623                 generate <tt>ESC [ 3 ~</tt>.
6624             </item>
6625
6626             <item>
6627                 X applications are configured so that <tt>&lt;</tt>
6628                 deletes left, and <tt>Delete</tt> deletes right.  Motif
6629                 applications already work like this.
6630             </item>
6631
6632             <item>
6633                 Terminals should have <tt>stty erase ^?</tt> .
6634             </item>
6635
6636             <item>
6637                 The <tt>xterm</tt> terminfo entry should have <tt>ESC
6638                 [ 3 ~</tt> for <tt>kdch1</tt>, just as for
6639                 <tt>TERM=linux</tt> and <tt>TERM=vt220</tt>.
6640             </item>
6641
6642             <item>
6643                 Emacs is programmed to map <tt>KB_Backspace</tt> or
6644                 the <tt>stty erase</tt> character to
6645                 <tt>delete-backward-char</tt>, and <tt>KB_Delete</tt>
6646                 or <tt>kdch1</tt> to <tt>delete-forward-char</tt>, and
6647                 <tt>^H</tt> to <tt>help</tt> as always.
6648             </item>
6649
6650             <item>
6651                 Other applications use the <tt>stty erase</tt>
6652                 character and <tt>kdch1</tt> for the two delete keys,
6653                 with ASCII DEL being "delete previous character" and
6654                 <tt>kdch1</tt> being "delete character under
6655                 cursor".
6656             </item>
6657
6658           </list>
6659         </p>
6660
6661         <p>
6662           This will solve the problem except for the following
6663           cases:
6664         </p>
6665
6666         <p>
6667           <list>
6668             <item>
6669                 Some terminals have a <tt>&lt;--</tt> key that cannot
6670                 be made to produce anything except <tt>^H</tt>.  On
6671                 these terminals Emacs help will be unavailable on
6672                 <tt>^H</tt> (assuming that the <tt>stty erase</tt>
6673                 character takes precedence in Emacs, and has been set
6674                 correctly).  <tt>M-x help</tt> or <tt>F1</tt> (if
6675                 available) can be used instead.
6676             </item>
6677
6678             <item>
6679                 Some operating systems use <tt>^H</tt> for <tt>stty
6680                 erase</tt>.  However, modern telnet versions and all
6681                 rlogin versions propagate <tt>stty</tt> settings, and
6682                 almost all UNIX versions honour <tt>stty erase</tt>.
6683                 Where the <tt>stty</tt> settings are not propagated
6684                 correctly, things can be made to work by using
6685                 <tt>stty</tt> manually.
6686             </item>
6687
6688             <item>
6689                 Some systems (including previous Debian versions) use
6690                 <prgn>xmodmap</prgn> to arrange for both
6691                 <tt>&lt;--</tt> and <tt>Delete</tt> to generate
6692                 <tt>KB_Delete</tt>.  We can change the behavior of
6693                 their X clients using the same X resources that we use
6694                 to do it for our own clients, or configure our clients
6695                 using their resources when things are the other way
6696                 around.  On displays configured like this
6697                 <tt>Delete</tt> will not work, but <tt>&lt;--</tt>
6698                 will.
6699             </item>
6700
6701             <item>
6702                 Some operating systems have different <tt>kdch1</tt>
6703                 settings in their <tt>terminfo</tt> database for
6704                 <tt>xterm</tt> and others.  On these systems the
6705                 <tt>Delete</tt> key will not work correctly when you
6706                 log in from a system conforming to our policy, but
6707                 <tt>&lt;--</tt> will.
6708             </item>
6709           </list>
6710         </p>
6711       </sect>
6712
6713       <sect>
6714         <heading>Environment variables</heading>
6715
6716         <p>
6717           A program must not depend on environment variables to get
6718           reasonable defaults.  (That's because these environment
6719           variables would have to be set in a system-wide
6720           configuration file like <file>/etc/profile</file>, which is not
6721           supported by all shells.)
6722         </p>
6723
6724         <p>
6725           If a program usually depends on environment variables for its
6726           configuration, the program should be changed to fall back to
6727           a reasonable default configuration if these environment
6728           variables are not present. If this cannot be done easily
6729           (e.g., if the source code of a non-free program is not
6730           available), the program must be replaced by a small
6731           "wrapper" shell script which sets the environment variables
6732           if they are not already defined, and calls the original program.
6733         </p>
6734
6735         <p>
6736           Here is an example of a wrapper script for this purpose:
6737
6738           <example compact="compact">
6739 #!/bin/sh
6740 BAR=${BAR:-/var/lib/fubar}
6741 export BAR
6742 exec /usr/lib/foo/foo "$@"
6743           </example>
6744         </p>
6745
6746         <p>
6747           Furthermore, as <file>/etc/profile</file> is a configuration
6748           file of the <prgn>base-files</prgn> package, other packages must
6749           not put any environment variables or other commands into that
6750           file.
6751         </p>
6752       </sect>
6753
6754       <sect id="doc-base">
6755         <heading>Registering Documents using doc-base</heading>
6756
6757         <p>
6758           The <package>doc-base</package> package implements a
6759           flexible mechanism for handling and presenting
6760           documentation. The recommended practice is for every Debian
6761           package that provides online documentation (other than just
6762           manual pages) to register these documents with
6763           <package>doc-base</package> by installing a
6764           <package>doc-base</package> control file via the
6765           <prgn/install-docs/ script at installation time and
6766           de-register the manuals again when the package is removed.
6767         </p> 
6768         <p>
6769           Please refer to the documentation that comes with the
6770           <package>doc-base</package>  package for information and
6771           details. 
6772         </p>
6773       </sect>
6774
6775     </chapt>
6776
6777
6778     <chapt id="files">
6779       <heading>Files</heading>
6780
6781       <sect>
6782         <heading>Binaries</heading>
6783
6784         <p>
6785           Two different packages must not install programs with
6786           different functionality but with the same filenames.  (The
6787           case of two programs having the same functionality but
6788           different implementations is handled via "alternatives" or
6789           the "Conflicts" mechanism.  See <ref id="maintscripts"> and
6790           <ref id="conflicts"> respectively.)  If this case happens,
6791           one of the programs must be renamed.  The maintainers should
6792           report this to the <tt>debian-devel</tt> mailing list and
6793           try to find a consensus about which program will have to be
6794           renamed.  If a consensus cannot be reached, <em>both</em>
6795           programs must be renamed.
6796         </p>
6797
6798         <p>
6799          By default, when a package is being built, any binaries
6800          created should include debugging information, as well as
6801          being compiled with optimization.  You should also turn on
6802          as many reasonable compilation warnings as possible; this
6803          makes life easier for porters, who can then look at build
6804          logs for possible problems.  For the C programming language,
6805          this means the following compilation parameters should be
6806          used:
6807           <example compact="compact">
6808 CC = gcc
6809 CFLAGS = -O2 -g -Wall # sane warning options vary between programs
6810 LDFLAGS = # none
6811 INSTALL = install -s # (or use strip on the files in debian/tmp)
6812           </example>
6813         </p>
6814
6815         <p>
6816           Note that by default all installed binaries should be stripped,
6817           either by using the <tt>-s</tt> flag to
6818           <prgn>install</prgn>, or by calling <prgn>strip</prgn> on
6819           the binaries after they have been copied into
6820           <file>debian/tmp</file> but before the tree is made into a
6821           package.
6822         </p>
6823
6824         <p>
6825           Although binaries in the build tree should be compiled with
6826           debugging information by default, it can often be difficult to
6827           debug programs if they are also subjected to compiler
6828           optimization.  For this reason, it is recommended to support the
6829           standardized environment variable <tt>DEB_BUILD_OPTIONS</tt>
6830           (see <ref id="debianrules-options">).  This variable can contain
6831           several flags to change how a package is compiled and built.
6832         </p>
6833
6834         <p>
6835           It is up to the package maintainer to decide what
6836           compilation options are best for the package.  Certain
6837           binaries (such as computationally-intensive programs) will
6838           function better with certain flags (<tt>-O3</tt>, for
6839           example); feel free to use them.  Please use good judgment
6840           here.  Don't use flags for the sake of it; only use them
6841           if there is good reason to do so.  Feel free to override
6842           the upstream author's ideas about which compilation
6843           options are best: they are often inappropriate for our
6844           environment.
6845         </p>
6846       </sect>
6847
6848
6849       <sect id="libraries">
6850         <heading>Libraries</heading>
6851
6852         <p>
6853           If the package is <strong>architecture: any</strong>, then
6854           the shared library compilation and linking flags must have
6855           <tt>-fPIC</tt>, or the package shall not build on some of
6856           the supported architectures<footnote>
6857             <p>
6858               If you are using GCC, <tt>-fPIC</tt> produces code with
6859               relocatable position independent code, which is required for
6860               most architectures to create a shared library, with i386 and
6861               perhaps some others where non position independent code is
6862               permitted in a shared library.
6863             </p>
6864             <p>
6865               Position independent code may have a performance penalty,
6866               especially on <tt>i386</tt>. However, in most cases the
6867               speed penalty must be measured against the memory wasted on
6868               the few architectures where non position independent code is
6869               even possible.
6870             </p>
6871           </footnote>. Any exception to this rule must be discussed on
6872           the mailing list <em>debian-devel@lists.debian.org</em>, and
6873           a rough consensus obtained.  The reasons for not compiling
6874           with <tt>-fPIC</tt> flag must be recorded in the file
6875           <tt>README.Debian</tt>, and care must be taken to either
6876           restrict the architecture or arrange for <tt>-fPIC</tt> to
6877           be used on architectures where it is required.<footnote>
6878             <p>
6879               Some of the reasons why this might be required is if the
6880               library contains hand crafted assembly code that is not
6881               relocatable, the speed penalty is excessive for compute
6882               intensive libs, and similar reasons.
6883             </p>
6884           </footnote>
6885         </p>
6886         <p>
6887           As to the static libraries, the common case is not to have
6888           relocatable code, since there is no benefit, unless in specific
6889           cases; therefore the static version must not be compiled
6890           with the <tt>-fPIC</tt> flag. Any exception to this rule
6891           should be discussed on the mailing list
6892           <em>debian-devel@lists.debian.org</em>,  and the reasons for
6893           compiling with the <tt>-fPIC</tt> flag must be recorded in
6894           the file <tt>README.Debian</tt>. <footnote>
6895             <p>
6896               Some of the reasons for linking static libraries with
6897               the <tt>-fPIC</tt> flag are if, for example, one needs a
6898               Perl API for a library that is under rapid development,
6899               and has an unstable API, so shared libraries are
6900               pointless at this phase of the library's development. In
6901               that case, since Perl needs a library with relocatable
6902               code, it may make sense to create a static library with
6903               relocatable code. Another reason cited is if you are
6904               distilling various libraries into a common shared
6905               library, like <tt>mklibs</tt> does in the Debian
6906               installer project.
6907             </p>
6908           </footnote>
6909         </p>
6910         <p>
6911           In other words, if both a shared and a static library is
6912           being built, each source unit (<tt>*.c</tt>, for example,
6913           for C files) will need to be compiled twice, for the normal
6914           case. 
6915         </p>
6916         <p>
6917           You must specify the gcc option <tt>-D_REENTRANT</tt>
6918           when building a library (either static or shared) to make
6919           the library compatible with LinuxThreads.
6920         </p>
6921
6922         <p>
6923           Although not enforced by the build tools, shared libraries
6924           must be linked against all libraries that they use symbols from
6925           in the same way that binaries are.  This ensures the correct
6926           functioning of the <qref id="sharedlibs-shlibdeps">shlibs</qref>
6927           system and guarantees that all libraries can be safely opened
6928           with <tt>dlopen()</tt>.  Packagers may wish to use the gcc
6929           option <tt>-Wl,-z,defs</tt> when building a shared library.
6930           Since this option enforces symbol resolution at build time,
6931           a missing library reference will be caught early as a fatal
6932           build error.
6933         </p>
6934
6935         <p>
6936           All installed shared libraries should be stripped with
6937           <example compact="compact">
6938 strip --strip-unneeded <var>your-lib</var>
6939           </example>
6940           (The option <tt>--strip-unneeded</tt> makes
6941           <prgn>strip</prgn> remove only the symbols which aren't
6942           needed for relocation processing.)  Shared libraries can
6943           function perfectly well when stripped, since the symbols for
6944           dynamic linking are in a separate part of the ELF object
6945           file.<footnote>
6946               You might also want to use the options
6947               <tt>--remove-section=.comment</tt> and
6948               <tt>--remove-section=.note</tt> on both shared libraries
6949               and executables, and <tt>--strip-debug</tt> on static
6950               libraries.
6951           </footnote>
6952         </p>
6953
6954         <p>
6955           Note that under some circumstances it may be useful to
6956           install a shared library unstripped, for example when
6957           building a separate package to support debugging.
6958         </p>
6959
6960         <p>
6961           Shared object files (often <file>.so</file> files) that are not
6962           public libraries, that is, they are not meant to be linked
6963           to by third party executables (binaries of other packages),
6964           should be installed in subdirectories of the
6965           <file>/usr/lib</file> directory.  Such files are exempt from the
6966           rules that govern ordinary shared libraries, except that
6967           they must not be installed executable and should be
6968           stripped.<footnote>
6969               A common example are the so-called "plug-ins",
6970               internal shared objects that are dynamically loaded by
6971               programs using <manref name="dlopen" section="3">.
6972           </footnote>
6973         </p>
6974
6975         <p>
6976           Packages containing shared libraries that may be linked to
6977           by other packages' binaries, but which for some
6978           <em>compelling</em> reason can not be installed in
6979           <file>/usr/lib</file> directory, may install the shared library
6980           files in subdirectories of the <file>/usr/lib</file> directory,
6981           in which case they should arrange to add that directory in
6982           <file>/etc/ld.so.conf</file> in the package's post-installation
6983           script, and remove it in the package's post-removal script.
6984         </p>
6985
6986         <p>
6987           An ever increasing number of packages are using
6988           <prgn>libtool</prgn> to do their linking.  The latest GNU
6989           libtools (>= 1.3a) can take advantage of the metadata in the
6990           installed <prgn>libtool</prgn> archive files (<file>*.la</file>
6991           files).  The main advantage of <prgn>libtool</prgn>'s
6992           <file>.la</file> files is that it allows <prgn>libtool</prgn> to
6993           store and subsequently access metadata with respect to the
6994           libraries it builds.  <prgn>libtool</prgn> will search for
6995           those files, which contain a lot of useful information about
6996           a library (such as library dependency information for static
6997           linking).  Also, they're <em>essential</em> for programs
6998           using <tt>libltdl</tt>.<footnote>
6999               Although <prgn>libtool</prgn> is fully capable of
7000               linking against shared libraries which don't have
7001               <tt>.la</tt> files, as it is a mere shell script it can
7002               add considerably to the build time of a
7003               <prgn>libtool</prgn>-using package if that shell script
7004               has to derive all this information from first principles
7005               for each library every time it is linked.  With the
7006               advent of <prgn>libtool</prgn> version 1.4 (and to a
7007               lesser extent <prgn>libtool</prgn> version 1.3), the
7008               <file>.la</file> files also store information about
7009               inter-library dependencies which cannot necessarily be
7010               derived after the <file>.la</file> file is deleted.
7011           </footnote>
7012         </p>
7013
7014         <p>
7015           Packages that use <prgn>libtool</prgn> to create shared
7016           libraries should include the <file>.la</file> files in the
7017           <tt>-dev</tt> package, unless the package relies on
7018           <tt>libtool</tt>'s <tt>libltdl</tt> library, in which case
7019           the <tt>.la</tt> files must go in the run-time library
7020           package.
7021         </p>
7022
7023         <p>
7024           You must make sure that you use only released versions of
7025           shared libraries to build your packages; otherwise other
7026           users will not be able to run your binaries
7027           properly. Producing source packages that depend on
7028           unreleased compilers is also usually a bad
7029           idea.
7030         </p>
7031       </sect>
7032
7033
7034       <sect>
7035         <heading>Shared libraries</heading>
7036         <p>
7037           This section has moved to <ref id="sharedlibs">.
7038         </p>
7039       </sect>
7040
7041
7042       <sect id="scripts">
7043         <heading>Scripts</heading>
7044
7045         <p>
7046           All command scripts, including the package maintainer
7047           scripts inside the package and used by <prgn>dpkg</prgn>,
7048           should have a <tt>#!</tt> line naming the shell to be used
7049           to interpret them.
7050         </p>
7051
7052         <p>
7053           In the case of Perl scripts this should be
7054           <tt>#!/usr/bin/perl</tt>.
7055         </p>
7056
7057         <p>
7058           When scripts are installed into a directory in the system
7059           PATH, the script name should not include an extension such
7060           as <tt>.sh</tt> or <tt>.pl</tt> that denotes the scripting
7061           language currently used to implement it.
7062         </p>
7063         <p>
7064           Shell scripts (<prgn>sh</prgn> and <prgn>bash</prgn>)
7065           should almost certainly start with <tt>set -e</tt> so that
7066           errors are detected.  Every script should use
7067           <tt>set -e</tt> or check the exit status of <em>every</em>
7068           command.
7069         </p>
7070
7071         <p>
7072           Scripts may assume that <file>/bin/sh</file> implements the
7073           SUSv3 Shell Command Language<footnote>
7074             Single UNIX Specification, version 3, which is also IEEE
7075             1003.1-2004 (POSIX), and is available on the World Wide Web
7076             from <url id="http://www.unix.org/version3/online.html"
7077                       name="The Open Group"> after free
7078             registration.</footnote>
7079           plus the following additional features not mandated by
7080           SUSv3:<footnote>
7081             These features are in widespread use in the Linux community
7082             and are implemented in all of bash, dash, and ksh, the most
7083             common shells users may wish to use as <file>/bin/sh</file>.
7084           </footnote>
7085           <list>
7086             <item><tt>echo -n</tt>, if implemented as a shell built-in,
7087               must not generate a newline.</item>
7088             <item><tt>test</tt>, if implemented as a shell built-in, must
7089               support <tt>-a</tt> and <tt>-o</tt> as binary logical
7090               operators.</item>
7091             <item><tt>local</tt> to create a scoped variable must be
7092               supported, including listing multiple variables in a single
7093               local command and assigning a value to a variable at the
7094               same time as localizing it.  <tt>local</tt> may or
7095               may not preserve the variable value from an outer scope if
7096               no assignment is present.  Uses such as:
7097 <example compact>
7098 fname () {
7099     local a b c=delta d
7100     # ... use a, b, c, d ...
7101 }
7102 </example>
7103               must be supported and must set the value of <tt>c</tt> to
7104               <tt>delta</tt>.
7105             </item>
7106           </list>
7107           If a shell script requires non-SUSv3 features from the shell
7108           interpreter other than those listed above, the appropriate shell
7109           must be specified in the first line of the script (e.g.,
7110           <tt>#!/bin/bash</tt>) and the package must depend on the package
7111           providing the shell (unless the shell package is marked
7112           "Essential", as in the case of <prgn>bash</prgn>).
7113         </p>
7114
7115         <p>
7116           You may wish to restrict your script to SUSv3 features plus the
7117           above set when possible so that it may use <file>/bin/sh</file>
7118           as its interpreter. If your script works with <prgn>dash</prgn>
7119           (originally called <prgn>ash</prgn>), it probably complies with
7120           the above requirements, but if you are in doubt, use
7121           <file>/bin/bash</file>.
7122         </p>
7123
7124         <p>
7125           Perl scripts should check for errors when making any
7126           system calls, including <tt>open</tt>, <tt>print</tt>,
7127           <tt>close</tt>, <tt>rename</tt> and <tt>system</tt>.
7128         </p>
7129
7130         <p>
7131           <prgn>csh</prgn> and <prgn>tcsh</prgn> should be avoided as
7132           scripting languages.  See <em>Csh Programming Considered
7133           Harmful</em>, one of the <tt>comp.unix.*</tt> FAQs, which
7134           can be found at <url id="http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/">.
7135           If an upstream package comes with <prgn>csh</prgn> scripts
7136           then you must make sure that they start with
7137           <tt>#!/bin/csh</tt> and make your package depend on the
7138           <prgn>c-shell</prgn> virtual package.
7139         </p>
7140
7141         <p>
7142           Any scripts which create files in world-writeable
7143           directories (e.g., in <file>/tmp</file>) must use a
7144           mechanism which will fail atomically if a file with the same
7145           name already exists.
7146         </p>
7147
7148         <p>
7149           The Debian base system provides the <prgn>tempfile</prgn>
7150           and <prgn>mktemp</prgn> utilities for use by scripts for
7151           this purpose.
7152         </p>
7153       </sect>
7154
7155
7156       <sect>
7157         <heading>Symbolic links</heading>
7158
7159         <p>
7160           In general, symbolic links within a top-level directory
7161           should be relative, and symbolic links pointing from one
7162           top-level directory into another should be absolute. (A
7163           top-level directory is a sub-directory of the root
7164           directory <file>/</file>.)
7165         </p>
7166
7167         <p>
7168           In addition, symbolic links should be specified as short as
7169           possible, i.e., link targets like <file>foo/../bar</file> are
7170           deprecated.
7171         </p>
7172
7173         <p>
7174           Note that when creating a relative link using
7175           <prgn>ln</prgn> it is not necessary for the target of the
7176           link to exist relative to the working directory you're
7177           running <prgn>ln</prgn> from, nor is it necessary to change
7178           directory to the directory where the link is to be made.
7179           Simply include the string that should appear as the target
7180           of the link (this will be a pathname relative to the
7181           directory in which the link resides) as the first argument
7182           to <prgn>ln</prgn>.
7183         </p>
7184
7185         <p>
7186           For example, in your <prgn>Makefile</prgn> or
7187           <file>debian/rules</file>, you can do things like:
7188           <example compact="compact">
7189 ln -fs gcc $(prefix)/bin/cc
7190 ln -fs gcc debian/tmp/usr/bin/cc
7191 ln -fs ../sbin/sendmail $(prefix)/bin/runq
7192 ln -fs ../sbin/sendmail debian/tmp/usr/bin/runq
7193           </example>
7194         </p>
7195
7196         <p>
7197           A symbolic link pointing to a compressed file should always
7198           have the same file extension as the referenced file. (For
7199           example, if a file <file>foo.gz</file> is referenced by a
7200           symbolic link, the filename of the link has to end with
7201           "<file>.gz</file>" too, as in <file>bar.gz</file>.)
7202         </p>
7203       </sect>
7204
7205       <sect>
7206         <heading>Device files</heading>
7207
7208         <p>
7209           Packages must not include device files in the package file
7210           tree.
7211         </p>
7212
7213         <p>
7214           If a package needs any special device files that are not
7215           included in the base system, it must call
7216           <prgn>MAKEDEV</prgn> in the <prgn>postinst</prgn> script,
7217           after notifying the user<footnote>
7218               This notification could be done via a (low-priority)
7219               debconf message, or an echo (printf) statement.
7220           </footnote>.
7221         </p>
7222
7223         <p>
7224           Packages must not remove any device files in the
7225           <prgn>postrm</prgn> or any other script. This is left to the
7226           system administrator.
7227         </p>
7228
7229         <p>
7230           Debian uses the serial devices
7231           <file>/dev/ttyS*</file>. Programs using the old
7232           <file>/dev/cu*</file> devices should be changed to use
7233           <file>/dev/ttyS*</file>.
7234         </p>
7235       </sect>
7236
7237       <sect id="config-files">
7238         <heading>Configuration files</heading>
7239
7240         <sect1>
7241           <heading>Definitions</heading>
7242
7243           <p>
7244             <taglist>
7245               <tag>configuration file</tag>
7246               <item>
7247                   A file that affects the operation of a program, or
7248                   provides site- or host-specific information, or
7249                   otherwise customizes the behavior of a program.
7250                   Typically, configuration files are intended to be
7251                   modified by the system administrator (if needed or
7252                   desired) to conform to local policy or to provide
7253                   more useful site-specific behavior.
7254               </item>
7255
7256               <tag><tt>conffile</tt></tag>
7257               <item>
7258                   A file listed in a package's <tt>conffiles</tt>
7259                   file, and is treated specially by <prgn>dpkg</prgn>
7260                   (see <ref id="configdetails">).
7261               </item>
7262             </taglist>
7263           </p>
7264
7265           <p>
7266             The distinction between these two is important; they are
7267             not interchangeable concepts. Almost all
7268             <tt>conffile</tt>s are configuration files, but many
7269             configuration files are not <tt>conffiles</tt>.
7270           </p>
7271
7272           <p>
7273             As noted elsewhere, <file>/etc/init.d</file> scripts,
7274             <file>/etc/default</file> files, scripts installed in
7275             <file>/etc/cron.{hourly,daily,weekly,monthly}</file>, and cron
7276             configuration installed in <file>/etc/cron.d</file> must be
7277             treated as configuration files.  In general, any script that
7278             embeds configuration information is de-facto a configuration
7279             file and should be treated as such.
7280           </p>
7281         </sect1>
7282
7283         <sect1>
7284           <heading>Location</heading>
7285
7286           <p>
7287             Any configuration files created or used by your package
7288             must reside in <file>/etc</file>. If there are several,
7289             consider creating a subdirectory of <file>/etc</file>
7290             named after your package.
7291           </p>
7292
7293           <p>
7294             If your package creates or uses configuration files
7295             outside of <file>/etc</file>, and it is not feasible to modify
7296             the package to use <file>/etc</file> directly, put the files
7297             in <file>/etc</file> and create symbolic links to those files
7298             from the location that the package requires.
7299           </p>
7300         </sect1>
7301
7302         <sect1>
7303           <heading>Behavior</heading>
7304
7305           <p>
7306             Configuration file handling must conform to the following
7307             behavior:
7308             <list compact="compact">
7309               <item>
7310                   local changes must be preserved during a package
7311                   upgrade, and
7312               </item>
7313               <item>
7314                   configuration files must be preserved when the
7315                   package is removed, and only deleted when the
7316                   package is purged.
7317               </item>
7318             </list>
7319           </p>
7320
7321           <p>
7322             The easy way to achieve this behavior is to make the
7323             configuration file a <tt>conffile</tt>. This is
7324             appropriate only if it is possible to distribute a default
7325             version that will work for most installations, although
7326             some system administrators may choose to modify it. This
7327             implies that the default version will be part of the
7328             package distribution, and must not be modified by the
7329             maintainer scripts during installation (or at any other
7330             time).
7331           </p>
7332
7333           <p>
7334             In order to ensure that local changes are preserved
7335             correctly, no package may contain or make hard links to
7336             conffiles.<footnote>
7337                 Rationale: There are two problems with hard links.
7338                 The first is that some editors break the link while
7339                 editing one of the files, so that the two files may
7340                 unwittingly become unlinked and different.  The second
7341                 is that <prgn>dpkg</prgn> might break the hard link
7342                 while upgrading <tt>conffile</tt>s.
7343             </footnote>
7344           </p>
7345
7346           <p>
7347             The other way to do it is via the maintainer scripts.  In
7348             this case, the configuration file must not be listed as a
7349             <tt>conffile</tt> and must not be part of the package
7350             distribution. If the existence of a file is required for
7351             the package to be sensibly configured it is the
7352             responsibility of the package maintainer to provide
7353             maintainer scripts which correctly create, update and
7354             maintain the file and remove it on purge.  (See <ref
7355             id="maintainerscripts"> for more information.)  These
7356             scripts must be idempotent (i.e., must work correctly if
7357             <prgn>dpkg</prgn> needs to re-run them due to errors
7358             during installation or removal), must cope with all the
7359             variety of ways <prgn>dpkg</prgn> can call maintainer
7360             scripts, must not overwrite or otherwise mangle the user's
7361             configuration without asking, must not ask unnecessary
7362             questions (particularly during upgrades), and must
7363             otherwise be good citizens.
7364           </p>
7365
7366           <p>
7367             The scripts are not required to configure every possible
7368             option for the package, but only those necessary to get
7369             the package running on a given system. Ideally the
7370             sysadmin should not have to do any configuration other
7371             than that done (semi-)automatically by the
7372             <prgn>postinst</prgn> script.
7373           </p>
7374
7375           <p>
7376             A common practice is to create a script called
7377             <file><var>package</var>-configure</file> and have the
7378             package's <prgn>postinst</prgn> call it if and only if the
7379             configuration file does not already exist.  In certain
7380             cases it is useful for there to be an example or template
7381             file which the maintainer scripts use.  Such files should
7382             be in <file>/usr/share/<var>package</var></file> or
7383             <file>/usr/lib/<var>package</var></file> (depending on whether
7384             they are architecture-independent or not).  There should
7385             be symbolic links to them from
7386             <file>/usr/share/doc/<var>package</var>/examples</file> if
7387             they are examples, and should be perfectly ordinary
7388             <prgn>dpkg</prgn>-handled files (<em>not</em>
7389             configuration files).
7390           </p>
7391
7392           <p>
7393             These two styles of configuration file handling must
7394             not be mixed, for that way lies madness:
7395             <prgn>dpkg</prgn> will ask about overwriting the file
7396             every time the package is upgraded.
7397           </p>
7398         </sect1>
7399
7400         <sect1>
7401           <heading>Sharing configuration files</heading>
7402
7403           <p>
7404             Packages which specify the same file as a
7405             <tt>conffile</tt> must be tagged as <em>conflicting</em>
7406             with each other.  (This is an instance of the general rule
7407             about not sharing files.  Note that neither alternatives
7408             nor diversions are likely to be appropriate in this case;
7409             in particular, <prgn>dpkg</prgn> does not handle diverted
7410             <tt>conffile</tt>s well.)
7411           </p>
7412
7413           <p>
7414             The maintainer scripts must not alter a <tt>conffile</tt>
7415             of <em>any</em> package, including the one the scripts
7416             belong to.
7417           </p>
7418
7419           <p>
7420             If two or more packages use the same configuration file
7421             and it is reasonable for both to be installed at the same
7422             time, one of these packages must be defined as
7423             <em>owner</em> of the configuration file, i.e., it will be
7424             the package which handles that file as a configuration
7425             file.  Other packages that use the configuration file must
7426             depend on the owning package if they require the
7427             configuration file to operate. If the other package will
7428             use the configuration file if present, but is capable of
7429             operating without it, no dependency need be declared.
7430           </p>
7431
7432           <p>
7433             If it is desirable for two or more related packages to
7434             share a configuration file <em>and</em> for all of the
7435             related packages to be able to modify that configuration
7436             file, then the following should be done:
7437             <enumlist compact="compact">
7438               <item>
7439                   One of the related packages (the "owning" package)
7440                   will manage the configuration file with maintainer
7441                   scripts as described in the previous section.
7442               </item>
7443               <item>
7444                   The owning package should also provide a program
7445                   that the other packages may use to modify the
7446                   configuration file.
7447               </item>
7448               <item>
7449                   The related packages must use the provided program
7450                   to make any desired modifications to the
7451                   configuration file.  They should either depend on
7452                   the core package to guarantee that the configuration
7453                   modifier program is available or accept gracefully
7454                   that they cannot modify the configuration file if it
7455                   is not.  (This is in addition to the fact that the
7456                   configuration file may not even be present in the
7457                   latter scenario.)
7458               </item>
7459             </enumlist>
7460           </p>
7461
7462           <p>
7463             Sometimes it's appropriate to create a new package which
7464             provides the basic infrastructure for the other packages
7465             and which manages the shared configuration files.  (The
7466             <tt>sgml-base</tt> package is a good example.)
7467           </p>
7468         </sect1>
7469
7470         <sect1>
7471           <heading>User configuration files ("dotfiles")</heading>
7472
7473           <p>
7474             The files in <file>/etc/skel</file> will automatically be
7475             copied into new user accounts by <prgn>adduser</prgn>.
7476             No other program should reference the files in
7477             <file>/etc/skel</file>.
7478           </p>
7479
7480           <p>
7481             Therefore, if a program needs a dotfile to exist in
7482             advance in <file>$HOME</file> to work sensibly, that dotfile
7483             should be installed in <file>/etc/skel</file> and treated as a
7484             configuration file.
7485           </p>
7486
7487           <p>
7488             However, programs that require dotfiles in order to
7489             operate sensibly are a bad thing, unless they do create
7490             the dotfiles themselves automatically.
7491           </p>
7492
7493           <p>
7494             Furthermore, programs should be configured by the Debian
7495             default installation to behave as closely to the upstream
7496             default behavior as possible.
7497           </p>
7498
7499           <p>
7500             Therefore, if a program in a Debian package needs to be
7501             configured in some way in order to operate sensibly, that
7502             should be done using a site-wide configuration file placed
7503             in <file>/etc</file>.  Only if the program doesn't support a
7504             site-wide default configuration and the package maintainer
7505             doesn't have time to add it may a default per-user file be
7506             placed in <file>/etc/skel</file>.
7507           </p>
7508
7509           <p>
7510             <file>/etc/skel</file> should be as empty as we can make it.
7511             This is particularly true because there is no easy (or
7512             necessarily desirable) mechanism for ensuring that the
7513             appropriate dotfiles are copied into the accounts of
7514             existing users when a package is installed.
7515           </p>
7516         </sect1>
7517       </sect>
7518
7519       <sect>
7520         <heading>Log files</heading>
7521         <p>
7522           Log files should usually be named
7523           <file>/var/log/<var>package</var>.log</file>.  If you have many
7524           log files, or need a separate directory for permission
7525           reasons (<file>/var/log</file> is writable only by
7526           <file>root</file>), you should usually create a directory named
7527           <file>/var/log/<var>package</var></file> and place your log
7528           files there.
7529         </p>
7530
7531         <p>
7532           Log files must be rotated occasionally so that they don't
7533           grow indefinitely; the best way to do this is to drop a log
7534           rotation configuration file into the directory
7535           <file>/etc/logrotate.d</file> and use the facilities provided by
7536           logrotate.<footnote>
7537             <p>
7538               The traditional approach to log files has been to set up
7539               <em>ad hoc</em> log rotation schemes using simple shell
7540               scripts and cron.  While this approach is highly
7541               customizable, it requires quite a lot of sysadmin work.
7542               Even though the original Debian system helped a little
7543               by automatically installing a system which can be used
7544               as a template, this was deemed not enough.
7545             </p>
7546
7547             <p>
7548               The use of <prgn>logrotate</prgn>, a program developed
7549               by Red Hat, is better, as it centralizes log management.
7550               It has both a configuration file
7551               (<file>/etc/logrotate.conf</file>) and a directory where
7552               packages can drop their individual log rotation
7553               configurations (<file>/etc/logrotate.d</file>).
7554             </p>
7555           </footnote>
7556           Here is a good example for a logrotate config
7557           file (for more information see <manref name="logrotate"
7558             section="8">):
7559           <example compact="compact">
7560 /var/log/foo/*.log {
7561 rotate 12
7562 weekly
7563 compress
7564 postrotate
7565 /etc/init.d/foo force-reload
7566 endscript
7567 }
7568           </example>
7569           This rotates all files under <file>/var/log/foo</file>, saves 12
7570           compressed generations, and forces the daemon to reload its
7571           configuration information after the log rotation.
7572         </p>
7573
7574         <p>
7575           Log files should be removed when the package is
7576           purged (but not when it is only removed).  This should be
7577           done by the <prgn>postrm</prgn> script when it is called
7578           with the argument <tt>purge</tt> (see <ref
7579           id="removedetails">).
7580         </p>
7581       </sect>
7582
7583       <sect>
7584         <heading>Permissions and owners</heading>
7585
7586         <p>
7587           The rules in this section are guidelines for general use.
7588           If necessary you may deviate from the details below.
7589           However, if you do so you must make sure that what is done
7590           is secure and you should try to be as consistent as possible
7591           with the rest of the system.  You should probably also
7592           discuss it on <prgn>debian-devel</prgn> first.
7593         </p>
7594
7595         <p>
7596           Files should be owned by <tt>root:root</tt>, and made
7597           writable only by the owner and universally readable (and
7598           executable, if appropriate), that is mode 644 or 755.
7599         </p>
7600
7601         <p>
7602           Directories should be mode 755 or (for group-writability)
7603           mode 2775.  The ownership of the directory should be
7604           consistent with its mode: if a directory is mode 2775, it
7605           should be owned by the group that needs write access to
7606           it.<footnote>
7607             <p>
7608               When a package is upgraded, and the owner or permissions
7609               of a file included in the package has changed, dpkg
7610               arranges for the ownership and permissions to be
7611               correctly set upon installation. However, this does not
7612               extend to directories; the permissions and ownership of
7613               directories already on the system does not change on
7614               install or upgrade of packages.  This makes sense, since
7615               otherwise common directories like <tt>/usr</tt> would
7616               always be in flux.  To correctly change permissions of a
7617               directory the package owns, explicit action is required,
7618               usually in the <tt>postinst</tt> script. Care must be
7619               taken to handle downgrades as well, in that case.
7620             </p>
7621           </footnote>
7622         </p>
7623
7624
7625         <p>
7626           Setuid and setgid executables should be mode 4755 or 2755
7627           respectively, and owned by the appropriate user or group.
7628           They should not be made unreadable (modes like 4711 or
7629           2711 or even 4111); doing so achieves no extra security,
7630           because anyone can find the binary in the freely available
7631           Debian package; it is merely inconvenient.  For the same
7632           reason you should not restrict read or execute permissions
7633           on non-set-id executables.
7634         </p>
7635
7636         <p>
7637           Some setuid programs need to be restricted to particular
7638           sets of users, using file permissions.  In this case they
7639           should be owned by the uid to which they are set-id, and by
7640           the group which should be allowed to execute them.  They
7641           should have mode 4754; again there is no point in making
7642           them unreadable to those users who must not be allowed to
7643           execute them.
7644         </p>
7645
7646         <p>
7647           It is possible to arrange that the system administrator can
7648           reconfigure the package to correspond to their local
7649           security policy by changing the permissions on a binary:
7650           they can do this by using <prgn>dpkg-statoverride</prgn>, as
7651           described below.<footnote>
7652               Ordinary files installed by <prgn>dpkg</prgn> (as
7653               opposed to <tt>conffile</tt>s and other similar objects)
7654               normally have their permissions reset to the distributed
7655               permissions when the package is reinstalled.  However,
7656               the use of <prgn>dpkg-statoverride</prgn> overrides this
7657               default behavior.  If you use this method, you should
7658               remember to describe <prgn>dpkg-statoverride</prgn> in
7659               the package documentation; being a relatively new
7660               addition to Debian, it is probably not yet well-known.
7661           </footnote>
7662           Another method you should consider is to create a group for
7663           people allowed to use the program(s) and make any setuid
7664           executables executable only by that group.
7665         </p>
7666
7667         <p>
7668           If you need to create a new user or group for your package
7669           there are two possibilities.  Firstly, you may need to
7670           make some files in the binary package be owned by this
7671           user or group, or you may need to compile the user or
7672           group id (rather than just the name) into the binary
7673           (though this latter should be avoided if possible, as in
7674           this case you need a statically allocated id).</p>
7675
7676         <p>
7677           If you need a statically allocated id, you must ask for a
7678           user or group id from the <tt>base-passwd</tt> maintainer,
7679           and must not release the package until you have been
7680           allocated one.  Once you have been allocated one you must
7681           either make the package depend on a version of the
7682           <tt>base-passwd</tt> package with the id present in
7683           <file>/etc/passwd</file> or <file>/etc/group</file>, or arrange for
7684           your package to create the user or group itself with the
7685           correct id (using <tt>adduser</tt>) in its
7686           <prgn>preinst</prgn> or <prgn>postinst</prgn>.  (Doing it in
7687           the <prgn>postinst</prgn> is to be preferred if it is
7688           possible, otherwise a pre-dependency will be needed on the
7689           <tt>adduser</tt> package.)
7690         </p>
7691
7692         <p>
7693           On the other hand, the program might be able to determine
7694           the uid or gid from the user or group name at runtime, so
7695           that a dynamically allocated id can be used.  In this case
7696           you should choose an appropriate user or group name,
7697           discussing this on <prgn>debian-devel</prgn> and checking
7698           with the <package/base-passwd/ maintainer that it is unique and that
7699           they do not wish you to use a statically allocated id
7700           instead.  When this has been checked you must arrange for
7701           your package to create the user or group if necessary using
7702           <prgn>adduser</prgn> in the <prgn>preinst</prgn> or
7703           <prgn>postinst</prgn> script (again, the latter is to be
7704           preferred if it is possible).
7705         </p>
7706
7707         <p>
7708           Note that changing the numeric value of an id associated
7709           with a name is very difficult, and involves searching the
7710           file system for all appropriate files.  You need to think
7711           carefully whether a static or dynamic id is required, since
7712           changing your mind later will cause problems.
7713         </p>
7714
7715         <sect1><heading>The use of <prgn>dpkg-statoverride</prgn></heading>
7716           <p>
7717             This section is not intended as policy, but as a
7718             description of the use of <prgn>dpkg-statoverride</prgn>.
7719           </p>
7720
7721           <p>
7722             If a system administrator wishes to have a file (or
7723             directory or other such thing) installed with owner and
7724             permissions different from those in the distributed Debian
7725             package, they can use the <prgn>dpkg-statoverride</prgn>
7726             program to instruct <prgn>dpkg</prgn> to use the different
7727             settings every time the file is installed.  Thus the
7728             package maintainer should distribute the files with their
7729             normal permissions, and leave it for the system
7730             administrator to make any desired changes.  For example, a
7731             daemon which is normally required to be setuid root, but
7732             in certain situations could be used without being setuid,
7733             should be installed setuid in the <tt>.deb</tt>.  Then the
7734             local system administrator can change this if they wish.
7735             If there are two standard ways of doing it, the package
7736             maintainer can use <tt>debconf</tt> to find out the
7737             preference, and call <prgn>dpkg-statoverride</prgn> in the
7738             maintainer script if necessary to accommodate the system
7739             administrator's choice. Care must be taken during
7740             upgrades to not override an existing setting.
7741           </p>
7742
7743           <p>
7744             Given the above, <prgn>dpkg-statoverride</prgn> is
7745             essentially a tool for system administrators and would not
7746             normally be needed in the maintainer scripts.  There is
7747             one type of situation, though, where calls to
7748             <prgn>dpkg-statoverride</prgn> would be needed in the
7749             maintainer scripts, and that involves packages which use
7750             dynamically allocated user or group ids.  In such a
7751             situation, something like the following idiom can be very
7752             helpful in the package's <prgn>postinst</prgn>, where
7753             <tt>sysuser</tt> is a dynamically allocated id:
7754             <example>
7755 for i in /usr/bin/foo /usr/sbin/bar
7756 do
7757   # only do something when no setting exists
7758   if ! dpkg-statoverride --list $i >/dev/null 2>&1
7759   then
7760     #include: debconf processing, question about foo and bar
7761     if [ "$RET" = "true" ] ; then
7762       dpkg-statoverride --update --add sysuser root 4755 $i
7763     fi
7764   fi
7765 done
7766             </example>
7767             The corresponding <tt>dpkg-statoverride --remove</tt>
7768             calls can then be made unconditionally when the package is
7769             purged.
7770           </p>
7771         </sect1>
7772       </sect>
7773     </chapt>
7774
7775
7776     <chapt id="customized-programs">
7777       <heading>Customized programs</heading>
7778
7779       <sect id="arch-spec">
7780         <heading>Architecture specification strings</heading>
7781
7782         <p>
7783           If a program needs to specify an <em>architecture specification
7784             string</em> in some place, it should select one of the
7785           strings provided by <tt>dpkg-architecture -L</tt>. The
7786           strings are in the format
7787           <tt><var>os</var>-<var>arch</var></tt>, though the OS part
7788           is sometimes elided, as when the OS is Linux.<footnote>
7789             <p>Currently, the strings are:
7790               i386 ia64 alpha amd64 armeb arm hppa m32r m68k mips
7791               mipsel powerpc ppc64 s390 s390x sh3 sh3eb sh4 sh4eb
7792               sparc darwin-i386 darwin-ia64 darwin-alpha darwin-amd64
7793               darwin-armeb darwin-arm darwin-hppa darwin-m32r
7794               darwin-m68k darwin-mips darwin-mipsel darwin-powerpc
7795               darwin-ppc64 darwin-s390 darwin-s390x darwin-sh3
7796               darwin-sh3eb darwin-sh4 darwin-sh4eb darwin-sparc
7797               freebsd-i386 freebsd-ia64 freebsd-alpha freebsd-amd64
7798               freebsd-armeb freebsd-arm freebsd-hppa freebsd-m32r
7799               freebsd-m68k freebsd-mips freebsd-mipsel freebsd-powerpc
7800               freebsd-ppc64 freebsd-s390 freebsd-s390x freebsd-sh3
7801               freebsd-sh3eb freebsd-sh4 freebsd-sh4eb freebsd-sparc
7802               kfreebsd-i386 kfreebsd-ia64 kfreebsd-alpha
7803               kfreebsd-amd64 kfreebsd-armeb kfreebsd-arm kfreebsd-hppa
7804               kfreebsd-m32r kfreebsd-m68k kfreebsd-mips
7805               kfreebsd-mipsel kfreebsd-powerpc kfreebsd-ppc64
7806               kfreebsd-s390 kfreebsd-s390x kfreebsd-sh3 kfreebsd-sh3eb
7807               kfreebsd-sh4 kfreebsd-sh4eb kfreebsd-sparc knetbsd-i386
7808               knetbsd-ia64 knetbsd-alpha knetbsd-amd64 knetbsd-armeb
7809               knetbsd-arm knetbsd-hppa knetbsd-m32r knetbsd-m68k
7810               knetbsd-mips knetbsd-mipsel knetbsd-powerpc
7811               knetbsd-ppc64 knetbsd-s390 knetbsd-s390x knetbsd-sh3
7812               knetbsd-sh3eb knetbsd-sh4 knetbsd-sh4eb knetbsd-sparc
7813               netbsd-i386 netbsd-ia64 netbsd-alpha netbsd-amd64
7814               netbsd-armeb netbsd-arm netbsd-hppa netbsd-m32r
7815               netbsd-m68k netbsd-mips netbsd-mipsel netbsd-powerpc
7816               netbsd-ppc64 netbsd-s390 netbsd-s390x netbsd-sh3
7817               netbsd-sh3eb netbsd-sh4 netbsd-sh4eb netbsd-sparc
7818               openbsd-i386 openbsd-ia64 openbsd-alpha openbsd-amd64
7819               openbsd-armeb openbsd-arm openbsd-hppa openbsd-m32r
7820               openbsd-m68k openbsd-mips openbsd-mipsel openbsd-powerpc
7821               openbsd-ppc64 openbsd-s390 openbsd-s390x openbsd-sh3
7822               openbsd-sh3eb openbsd-sh4 openbsd-sh4eb openbsd-sparc
7823               hurd-i386 hurd-ia64 hurd-alpha hurd-amd64 hurd-armeb
7824               hurd-arm hurd-hppa hurd-m32r hurd-m68k hurd-mips
7825               hurd-mipsel hurd-powerpc hurd-ppc64 hurd-s390 hurd-s390x
7826               hurd-sh3 hurd-sh3eb hurd-sh4 hurd-sh4eb hurd-sparc
7827             </p>
7828           </footnote>
7829         </p>
7830
7831         <p>
7832           Note that we don't want to use
7833           <tt><var>arch</var>-debian-linux</tt> to apply to the rule
7834           <tt><var>architecture</var>-<var>vendor</var>-<var>os</var></tt>
7835           since this would make our programs incompatible with other
7836           Linux distributions.  We also don't use something like
7837           <tt><var>arch</var>-unknown-linux</tt>, since the
7838           <tt>unknown</tt> does not look very good.
7839         </p>
7840       </sect>
7841
7842       <sect>
7843         <heading>Daemons</heading>
7844
7845         <p>
7846           The configuration files <file>/etc/services</file>,
7847           <file>/etc/protocols</file>, and <file>/etc/rpc</file> are managed
7848           by the <prgn>netbase</prgn> package and must not be modified
7849           by other packages.
7850         </p>
7851
7852         <p>
7853           If a package requires a new entry in one of these files, the
7854           maintainer should get in contact with the
7855           <prgn>netbase</prgn> maintainer, who will add the entries
7856           and release a new version of the <prgn>netbase</prgn>
7857           package.
7858         </p>
7859
7860         <p>
7861           The configuration file <file>/etc/inetd.conf</file> must not be
7862           modified by the package's scripts except via the
7863           <prgn>update-inetd</prgn> script or the
7864           <file>DebianNet.pm</file> Perl module.  See their documentation
7865           for details on how to add entries.
7866         </p>
7867
7868         <p>
7869           If a package wants to install an example entry into
7870           <file>/etc/inetd.conf</file>, the entry must be preceded with
7871           exactly one hash character (<tt>#</tt>). Such lines are
7872           treated as "commented out by user" by the
7873           <prgn>update-inetd</prgn> script and are not changed or
7874           activated during package updates.
7875         </p>
7876       </sect>
7877
7878       <sect>
7879         <heading>Using pseudo-ttys and modifying wtmp, utmp and
7880         lastlog</heading>
7881
7882         <p>
7883           Some programs need to create pseudo-ttys. This should be done
7884           using Unix98 ptys if the C library supports it. The resulting
7885           program must not be installed setuid root, unless that
7886           is required for other functionality.
7887         </p>
7888
7889         <p>
7890           The files <file>/var/run/utmp</file>, <file>/var/log/wtmp</file> and
7891           <file>/var/log/lastlog</file> must be installed writable by
7892           group <tt>utmp</tt>.  Programs which need to modify those
7893           files must be installed setgid <tt>utmp</tt>.
7894         </p>
7895       </sect>
7896
7897       <sect>
7898         <heading>Editors and pagers</heading>
7899
7900         <p>
7901           Some programs have the ability to launch an editor or pager
7902           program to edit or display a text document.  Since there are
7903           lots of different editors and pagers available in the Debian
7904           distribution, the system administrator and each user should
7905           have the possibility to choose their preferred editor and
7906           pager.
7907         </p>
7908
7909         <p>
7910           In addition, every program should choose a good default
7911           editor/pager if none is selected by the user or system
7912           administrator.
7913         </p>
7914
7915         <p>
7916           Thus, every program that launches an editor or pager must
7917           use the EDITOR or PAGER environment variable to determine
7918           the editor or pager the user wishes to use.  If these
7919           variables are not set, the programs <file>/usr/bin/editor</file>
7920           and <file>/usr/bin/pager</file> should be used, respectively.
7921         </p>
7922
7923         <p>
7924           These two files are managed through the <prgn>dpkg</prgn>
7925           "alternatives" mechanism.  Thus every package providing an
7926           editor or pager must call the
7927           <prgn>update-alternatives</prgn> script to register these
7928           programs.
7929         </p>
7930
7931         <p>
7932           If it is very hard to adapt a program to make use of the
7933           EDITOR or PAGER variables, that program may be configured to
7934           use <file>/usr/bin/sensible-editor</file> and
7935           <file>/usr/bin/sensible-pager</file> as the editor or pager
7936           program respectively.  These are two scripts provided in the
7937           Debian base system that check the EDITOR and PAGER variables
7938           and launch the appropriate program, and fall back to
7939           <file>/usr/bin/editor</file> and <file>/usr/bin/pager</file> if the
7940           variable is not set.
7941         </p>
7942
7943         <p>
7944           A program may also use the VISUAL environment variable to
7945           determine the user's choice of editor.  If it exists, it
7946           should take precedence over EDITOR.  This is in fact what
7947           <file>/usr/bin/sensible-editor</file> does.
7948         </p>
7949
7950         <p>
7951           It is not required for a package to depend on
7952           <tt>editor</tt> and <tt>pager</tt>, nor is it required for a
7953           package to provide such virtual packages.<footnote>
7954               The Debian base system already provides an editor and a
7955               pager program.
7956           </footnote>
7957         </p>
7958       </sect>
7959
7960       <sect id="web-appl">
7961         <heading>Web servers and applications</heading>
7962
7963         <p>
7964           This section describes the locations and URLs that should
7965           be used by all web servers and web applications in the
7966           Debian system.
7967         </p>
7968
7969         <p>
7970           <enumlist>
7971             <item>
7972                 Cgi-bin executable files are installed in the
7973                 directory
7974                 <example compact="compact">
7975 /usr/lib/cgi-bin/<var>cgi-bin-name</var>
7976                 </example>
7977                 and should be referred to as
7978                 <example compact="compact">
7979 http://localhost/cgi-bin/<var>cgi-bin-name</var>
7980                 </example>
7981
7982             </item>
7983
7984             <item>
7985               <p>Access to HTML documents</p>
7986
7987               <p>
7988                 HTML documents for a package are stored in
7989                 <file>/usr/share/doc/<var>package</var></file>
7990                 and can be referred to as
7991                 <example compact="compact">
7992 http://localhost/doc/<var>package</var>/<var>filename</var>
7993                 </example>
7994               </p>
7995
7996               <p>
7997                 The web server should restrict access to the document
7998                 tree so that only clients on the same host can read
7999                 the documents. If the web server does not support such
8000                 access controls, then it should not provide access at
8001                 all, or ask about providing access during installation.
8002               </p>
8003             </item>
8004
8005             <item>
8006               <p>Access to images</p>
8007               <p>
8008                 It is recommended that images for a package be stored
8009                 in <tt>/usr/share/images/<var>package</var></tt> and
8010                 may be referred to through an alias <tt>/images/</tt>
8011                 as
8012                 <example>
8013                   http://localhost/images/&lt;package&gt;/&lt;filename&gt;     
8014                 </example>
8015                 
8016               </p>
8017             </item>
8018
8019             <item>
8020               <p>Web Document Root</p>
8021
8022               <p>
8023                 Web Applications should try to avoid storing files in
8024                 the Web Document Root.  Instead they should use the
8025                 /usr/share/doc/<var>package</var> directory for
8026                 documents and register the Web Application via the
8027                 <package>doc-base</package> package.  If access to the
8028                 web document root is unavoidable then use
8029                 <example compact="compact">
8030 /var/www
8031                 </example>
8032                 as the Document Root.  This might be just a symbolic
8033                 link to the location where the system administrator
8034                 has put the real document root.
8035               </p>
8036             </item>
8037             <item><p>Providing httpd and/or httpd-cgi</p>
8038               <p>
8039                 All web servers should provide the virtual package
8040                 <tt>httpd</tt>. If a web server has CGI support it should
8041                 provide <tt>httpd-cgi</tt> additionally.
8042               </p>
8043               <p>
8044                 All web applications which do not contain CGI scripts should
8045                 depend on <tt>httpd</tt>, all those web applications which
8046                 <tt>do</tt> contain CGI scripts, should depend on
8047                 <tt>httpd-cgi</tt>.
8048               </p>
8049             </item>
8050           </enumlist>
8051         </p>
8052       </sect>
8053
8054       <sect id="mail-transport-agents">
8055         <heading>Mail transport, delivery and user agents</heading>
8056
8057         <p>
8058           Debian packages which process electronic mail, whether mail
8059           user agents (MUAs) or mail transport agents (MTAs), must
8060           ensure that they are compatible with the configuration
8061           decisions below.  Failure to do this may result in lost
8062           mail, broken <tt>From:</tt> lines, and other serious brain
8063           damage!
8064         </p>
8065
8066         <p>
8067           The mail spool is <file>/var/mail</file> and the interface to
8068           send a mail message is <file>/usr/sbin/sendmail</file> (as per
8069           the FHS).  On older systems, the mail spool may be
8070           physically located in <file>/var/spool/mail</file>, but all
8071           access to the mail spool should be via the
8072           <file>/var/mail</file> symlink.  The mail spool is part of the
8073           base system and not part of the MTA package.
8074         </p>
8075
8076         <p>
8077           All Debian MUAs, MTAs, MDAs and other mailbox accessing
8078           programs (such as IMAP daemons) must lock the mailbox in an
8079           NFS-safe way. This means that <tt>fcntl()</tt> locking must
8080           be combined with dot locking.  To avoid deadlocks, a program
8081           should use <tt>fcntl()</tt> first and dot locking after
8082           this, or alternatively implement the two locking methods in
8083           a non blocking way<footnote>
8084               If it is not possible to establish both locks, the
8085               system shouldn't wait for the second lock to be
8086               established, but remove the first lock, wait a (random)
8087               time, and start over locking again.
8088           </footnote>. Using the functions <tt>maillock</tt> and
8089           <tt>mailunlock</tt> provided by the
8090           <tt>liblockfile*</tt><footnote>
8091               You will need to depend on <tt>liblockfile1 (&gt;&gt;1.01)</tt>
8092               to use these functions.
8093           </footnote> packages is the recommended way to realize this.
8094         </p>
8095
8096         <p>
8097           Mailboxes are generally either mode 600 and owned by
8098           <var>user</var> or mode 660 and owned by
8099           <tt><var>user</var>:mail</tt><footnote>
8100             There are two traditional permission schemes for mail spools:
8101             mode 600 with all mail delivery done by processes running as
8102             the destination user, or mode 660 and owned by group mail with
8103             mail delivery done by a process running as a system user in
8104             group mail.  Historically, Debian required mode 660 mail
8105             spools to enable the latter model, but that model has become
8106             increasingly uncommon and the principle of least privilege
8107             indicates that mail systems that use the first model should
8108             use permissions of 600.  If delivery to programs is permitted,
8109             it's easier to keep the mail system secure if the delivery
8110             agent runs as the destination user.  Debian Policy therefore
8111             permits either scheme.
8112           </footnote>. The local system administrator may choose a
8113           different permission scheme; packages should not make
8114           assumptions about the permission and ownership of mailboxes
8115           unless required (such as when creating a new mailbox).  A MUA
8116           may remove a mailbox (unless it has nonstandard permissions) in
8117           which case the MTA or another MUA must recreate it if needed.
8118         </p>
8119
8120         <p>
8121           The mail spool is 2775 <tt>root:mail</tt>, and MUAs should
8122           be setgid mail to do the locking mentioned above (and
8123           must obviously avoid accessing other users' mailboxes
8124           using this privilege).</p>
8125
8126         <p>
8127           <file>/etc/aliases</file> is the source file for the system mail
8128           aliases (e.g., postmaster, usenet, etc.), it is the one
8129           which the sysadmin and <prgn>postinst</prgn> scripts may
8130           edit.  After <file>/etc/aliases</file> is edited the program or
8131           human editing it must call <prgn>newaliases</prgn>.  All MTA
8132           packages must come with a <prgn>newaliases</prgn> program,
8133           even if it does nothing, but older MTA packages did not do
8134           this so programs should not fail if <prgn>newaliases</prgn>
8135           cannot be found.  Note that because of this, all MTA
8136           packages must have <tt>Provides</tt>, <tt>Conflicts</tt> and
8137           <tt>Replaces: mail-transport-agent</tt> control file
8138           fields.
8139         </p>
8140
8141         <p>
8142           The convention of writing <tt>forward to
8143             <var>address</var></tt> in the mailbox itself is not
8144           supported.  Use a <tt>.forward</tt> file instead.</p>
8145
8146         <p>
8147           The <prgn>rmail</prgn> program used by UUCP
8148           for incoming mail should be  <file>/usr/sbin/rmail</file>.
8149           Likewise, <prgn>rsmtp</prgn>, for receiving
8150           batch-SMTP-over-UUCP, should be <file>/usr/sbin/rsmtp</file> if it
8151           is supported.</p>
8152
8153         <p>
8154           If your package needs to know what hostname to use on (for
8155           example) outgoing news and mail messages which are generated
8156           locally, you should use the file <file>/etc/mailname</file>.  It
8157           will contain the portion after the username and <tt>@</tt>
8158           (at) sign for email addresses of users on the machine
8159           (followed by a newline).
8160         </p>
8161
8162         <p>
8163           Such a package should check for the existence of this file
8164           when it is being configured.  If it exists, it should be
8165           used without comment, although an MTA's configuration script
8166           may wish to prompt the user even if it finds that this file
8167           exists.  If the file does not exist, the package should
8168           prompt the user for the value (preferably using
8169           <prgn>debconf</prgn>) and store it in <file>/etc/mailname</file>
8170           as well as using it in the package's configuration.  The
8171           prompt should make it clear that the name will not just be
8172           used by that package.  For example, in this situation the
8173           <tt>inn</tt> package could say something like:
8174           <example compact="compact">
8175 Please enter the "mail name" of your system.  This is the
8176 hostname portion of the address to be shown on outgoing
8177 news and mail messages.  The default is
8178 <var>syshostname</var>, your system's host name.  Mail
8179 name ["<var>syshostname</var>"]:
8180           </example>
8181           where <var>syshostname</var> is the output of <tt>hostname
8182             --fqdn</tt>.
8183         </p>
8184       </sect>
8185
8186       <sect>
8187         <heading>News system configuration</heading>
8188
8189         <p>
8190           All the configuration files related to the NNTP (news)
8191           servers and clients should be located under
8192           <file>/etc/news</file>.</p>
8193
8194         <p>
8195           There are some configuration issues that apply to a number
8196           of news clients and server packages on the machine. These
8197           are:
8198
8199           <taglist>
8200             <tag><file>/etc/news/organization</file></tag>
8201             <item>
8202                 A string which should appear as the
8203                 organization header for all messages posted
8204                 by NNTP clients on the machine
8205             </item>
8206
8207             <tag><file>/etc/news/server</file></tag>
8208             <item>
8209                 Contains the FQDN of the upstream NNTP
8210                 server, or localhost if the local machine is
8211                 an NNTP server.
8212             </item>
8213           </taglist>
8214
8215           Other global files may be added as required for cross-package news
8216           configuration.
8217         </p>
8218       </sect>
8219
8220
8221       <sect>
8222         <heading>Programs for the X Window System</heading>
8223
8224         <sect1>
8225           <heading>Providing X support and package priorities</heading>
8226
8227           <p>
8228             Programs that can be configured with support for the X
8229             Window System must be configured to do so and must declare
8230             any package dependencies necessary to satisfy their
8231             runtime requirements when using the X Window System.  If
8232             such a package is of higher priority than the X packages
8233             on which it depends, it is required that either the
8234             X-specific components be split into a separate package, or
8235             that an alternative version of the package, which includes
8236             X support, be provided, or that the package's priority be
8237             lowered.
8238           </p>
8239         </sect1>
8240
8241         <sect1>
8242           <heading>Packages providing an X server</heading>
8243
8244           <p>
8245             Packages that provide an X server that, directly or
8246             indirectly, communicates with real input and display
8247             hardware should declare in their control data that they
8248             provide the virtual package <tt>xserver</tt>.<footnote>
8249                 This implements current practice, and provides an
8250                 actual policy for usage of the <tt>xserver</tt>
8251                 virtual package which appears in the virtual packages
8252                 list.  In a nutshell, X servers that interface
8253                 directly with the display and input hardware or via
8254                 another subsystem (e.g., GGI) should provide
8255                 <tt>xserver</tt>.  Things like <tt>Xvfb</tt>,
8256                 <tt>Xnest</tt>, and <tt>Xprt</tt> should not.
8257             </footnote>
8258           </p>
8259         </sect1>
8260
8261         <sect1>
8262           <heading>Packages providing a terminal emulator</heading>
8263
8264           <p>
8265             Packages that provide a terminal emulator for the X Window
8266             System which meet the criteria listed below should declare
8267             in their control data that they provide the virtual
8268             package <tt>x-terminal-emulator</tt>.  They should also
8269             register themselves as an alternative for
8270             <file>/usr/bin/x-terminal-emulator</file>, with a priority of
8271             20.
8272           </p>
8273
8274           <p>
8275             To be an <tt>x-terminal-emulator</tt>, a program must:
8276             <list compact="compact">
8277               <item>
8278                   Be able to emulate a DEC VT100 terminal, or a
8279                   compatible terminal.
8280               </item>
8281
8282               <item>
8283                   Support the command-line option <tt>-e
8284                     <var>command</var></tt>, which creates a new
8285                   terminal window<footnote>
8286                       "New terminal window" does not necessarily mean
8287                       a new top-level X window directly parented by
8288                       the window manager; it could, if the terminal
8289                       emulator application were so coded, be a new
8290                       "view" in a multiple-document interface (MDI).
8291                   </footnote>
8292                   and runs the specified <var>command</var>,
8293                   interpreting the entirety of the rest of the command
8294                   line as a command to pass straight to exec, in the
8295                   manner that <tt>xterm</tt> does.
8296               </item>
8297
8298               <item>
8299                   Support the command-line option <tt>-T
8300                     <var>title</var></tt>, which creates a new terminal
8301                   window with the window title <var>title</var>.
8302               </item>
8303             </list>
8304           </p>
8305         </sect1>
8306
8307         <sect1>
8308           <heading>Packages providing a window manager</heading>
8309
8310           <p>
8311             Packages that provide a window manager should declare in
8312             their control data that they provide the virtual package
8313             <tt>x-window-manager</tt>.  They should also register
8314             themselves as an alternative for
8315             <file>/usr/bin/x-window-manager</file>, with a priority
8316             calculated as follows:
8317             <list compact="compact">
8318               <item>
8319                   Start with a priority of 20.
8320               </item>
8321
8322               <item>
8323                   If the window manager supports the Debian menu
8324                   system, add 20 points if this support is available
8325                   in the package's default configuration (i.e., no
8326                   configuration files belonging to the system or user
8327                   have to be edited to activate the feature); if
8328                   configuration files must be modified, add only 10
8329                   points.
8330                 </p>
8331               </item>
8332
8333               <item>
8334                   If the window manager complies with <url
8335                     id="http://www.freedesktop.org/Standards/wm-spec"
8336                     name="The Window Manager Specification Project">,
8337                   written by the <url id="http://www.freedesktop.org/"
8338                     name="Free Desktop Group">, add 40 points.
8339               </item>
8340
8341               <item>
8342                   If the window manager permits the X session to be
8343                   restarted using a <em>different</em> window manager
8344                   (without killing the X server) in its default
8345                   configuration, add 10 points; otherwise add none.
8346               </item>
8347             </list>
8348           </p>
8349         </sect1>
8350
8351         <sect1>
8352           <heading>Packages providing fonts</heading>
8353
8354           <p>
8355             Packages that provide fonts for the X Window
8356             System<footnote>
8357                 For the purposes of Debian Policy, a "font for the X
8358                 Window System" is one which is accessed via X protocol
8359                 requests.  Fonts for the Linux console, for PostScript
8360                 renderer, or any other purpose, do not fit this
8361                 definition.  Any tool which makes such fonts available
8362                 to the X Window System, however, must abide by this
8363                 font policy.
8364             </footnote>
8365             must do a number of things to ensure that they are both
8366             available without modification of the X or font server
8367             configuration, and that they do not corrupt files used by
8368             other font packages to register information about
8369             themselves.
8370             <enumlist>
8371               <item>
8372                   Fonts of any type supported by the X Window System
8373                   must be in a separate binary package from any
8374                   executables, libraries, or documentation (except
8375                   that specific to the fonts shipped, such as their
8376                   license information).  If one or more of the fonts
8377                   so packaged are necessary for proper operation of
8378                   the package with which they are associated the font
8379                   package may be Recommended; if the fonts merely
8380                   provide an enhancement, a Suggests relationship may
8381                   be used.  Packages must not Depend on font
8382                   packages.<footnote>
8383                       This is because the X server may retrieve fonts
8384                       from the local file system or over the network
8385                       from an X font server; the Debian package system
8386                       is empowered to deal only with the local
8387                       file system.
8388                   </footnote>
8389               </item>
8390
8391               <item>
8392                   BDF fonts must be converted to PCF fonts with the
8393                   <prgn>bdftopcf</prgn> utility (available in the
8394                   <tt>xfonts-utils</tt> package, <prgn>gzip</prgn>ped, and
8395                   placed in a directory that corresponds to their
8396                   resolution:
8397                   <list compact="compact">
8398                     <item>
8399                         100 dpi fonts must be placed in
8400                         <file>/usr/share/fonts/X11/100dpi/</file>.
8401                     </item>
8402
8403                     <item>
8404                         75 dpi fonts must be placed in
8405                         <file>/usr/share/fonts/X11/75dpi/</file>.
8406                     </item>
8407
8408                     <item>
8409                         Character-cell fonts, cursor fonts, and other
8410                         low-resolution fonts must be placed in
8411                         <file>/usr/share/fonts/X11/misc/</file>.
8412                     </item>
8413                   </list>
8414               </item>
8415
8416               <item>
8417                   Speedo fonts must be placed in
8418                   <file>/usr/share/fonts/X11/Speedo/</file>.
8419               </item>
8420
8421               <item>
8422                   Type 1 fonts must be placed in
8423                   <file>/usr/share/fonts/X11/Type1/</file>.  If font
8424                   metric files are available, they must be placed here
8425                   as well.
8426               </item>
8427
8428               <item>
8429                   Subdirectories of <file>/usr/share/fonts/X11/</file>
8430                   other than those listed above must be neither
8431                   created nor used.  (The <file>PEX</file>, <file>CID</file>,
8432                   and <file>cyrillic</file> directories are excepted for
8433                   historical reasons, but installation of files into
8434                   these directories remains discouraged.)
8435               </item>
8436
8437               <item>
8438                   Font packages may, instead of placing files directly
8439                   in the X font directories listed above, provide
8440                   symbolic links in that font directory pointing to
8441                   the files' actual location in the filesystem.  Such
8442                   a location must comply with the FHS.
8443               </item>
8444
8445               <item>
8446                   Font packages should not contain both 75dpi and
8447                   100dpi versions of a font.  If both are available,
8448                   they should be provided in separate binary packages
8449                   with <tt>-75dpi</tt> or <tt>-100dpi</tt> appended to
8450                   the names of the packages containing the
8451                   corresponding fonts.
8452               </item>
8453
8454               <item>
8455                   Fonts destined for the <file>misc</file> subdirectory
8456                   should not be included in the same package as 75dpi
8457                   or 100dpi fonts; instead, they should be provided in
8458                   a separate package with <tt>-misc</tt> appended to
8459                   its name.
8460               </item>
8461
8462               <item>
8463                   Font packages must not provide the files
8464                   <file>fonts.dir</file>, <file>fonts.alias</file>, or
8465                   <file>fonts.scale</file> in a font directory:
8466                   <list>
8467                     <item>
8468                         <file>fonts.dir</file> files must not be provided at all.
8469                     </item>
8470
8471                     <item>
8472                         <file>fonts.alias</file> and <file>fonts.scale</file>
8473                         files, if needed, should be provided in the
8474                         directory
8475                         <file>/etc/X11/fonts/<var>fontdir</var>/<var>package</var>.<var>extension</var></file>,
8476                         where <var>fontdir</var> is the name of the
8477                         subdirectory of
8478                         <file>/usr/share/fonts/X11/</file> where the
8479                         package's corresponding fonts are stored
8480                         (e.g., <tt>75dpi</tt> or <tt>misc</tt>),
8481                         <var>package</var> is the name of the package
8482                         that provides these fonts, and
8483                         <var>extension</var> is either <tt>scale</tt>
8484                         or <tt>alias</tt>, whichever corresponds to
8485                         the file contents.
8486                     </item>
8487                   </list>
8488               </item>
8489
8490               <item>
8491                   Font packages must declare a dependency on
8492                   <tt>xfonts-utils</tt> in their control
8493                   data.
8494               </item>
8495
8496               <item>
8497                   Font packages that provide one or more
8498                   <file>fonts.scale</file> files as described above must
8499                   invoke <prgn>update-fonts-scale</prgn> on each
8500                   directory into which they installed fonts
8501                   <em>before</em> invoking
8502                   <prgn>update-fonts-dir</prgn> on that directory.
8503                   This invocation must occur in both the
8504                   <prgn>postinst</prgn> (for all arguments) and
8505                   <prgn>postrm</prgn> (for all arguments except
8506                   <tt>upgrade</tt>) scripts.
8507               </item>
8508
8509               <item>
8510                   Font packages that provide one or more
8511                   <file>fonts.alias</file> files as described above must
8512                   invoke <prgn>update-fonts-alias</prgn> on each
8513                   directory into which they installed fonts.  This
8514                   invocation must occur in both the
8515                   <prgn>postinst</prgn> (for all arguments) and
8516                   <prgn>postrm</prgn> (for all arguments except
8517                   <tt>upgrade</tt>) scripts.
8518               </item>
8519
8520               <item>
8521                   Font packages must invoke
8522                   <prgn>update-fonts-dir</prgn> on each directory into
8523                   which they installed fonts.  This invocation must
8524                   occur in both the <prgn>postinst</prgn> (for all
8525                   arguments) and <prgn>postrm</prgn> (for all
8526                   arguments except <tt>upgrade</tt>) scripts.
8527               </item>
8528
8529               <item>
8530                   Font packages must not provide alias names for the
8531                   fonts they include which collide with alias names
8532                   already in use by fonts already packaged.
8533               </item>
8534
8535               <item>
8536                   Font packages must not provide fonts with the same
8537                   XLFD registry name as another font already packaged.
8538               </item>
8539             </enumlist>
8540           </p>
8541         </sect1>
8542
8543         <sect1>
8544           <heading>Application defaults files</heading>
8545
8546           <p>
8547             Application defaults files must be installed in the
8548             directory <file>/etc/X11/app-defaults/</file> (use of a
8549             localized subdirectory of <file>/etc/X11/</file> as described
8550             in the <em>X Toolkit Intrinsics - C Language
8551             Interface</em> manual is also permitted).  They must be
8552             registered as <tt>conffile</tt>s or handled as
8553             configuration files.
8554           </p>
8555
8556           <p>
8557             Customization of programs' X resources may also be
8558             supported with the provision of a file with the same name
8559             as that of the package placed in the
8560             <file>/etc/X11/Xresources/</file> directory, which must
8561             registered as a <tt>conffile</tt> or handled as a
8562             configuration file.<footnote>
8563                 Note that this mechanism is not the same as using
8564                 app-defaults; app-defaults are tied to the client
8565                 binary on the local file system, whereas X resources
8566                 are stored in the X server and affect all connecting
8567                 clients.
8568             </footnote>
8569           </p>
8570         </sect1>
8571
8572         <sect1>
8573           <heading>Installation directory issues</heading>
8574
8575           <p>
8576             Packages using the X Window System should not be
8577             configured to install files under the
8578             <file>/usr/X11R6/</file> directory. The
8579             <file>/usr/X11R6/</file> directory hierarchy should be
8580             regarded as obsolete.
8581           </p>
8582
8583           <p>
8584             Programs that use GNU <prgn>autoconf</prgn> and
8585             <prgn>automake</prgn> are usually easily configured at
8586             compile time to use <file>/usr/</file> instead of
8587             <file>/usr/X11R6/</file>, and this should be done whenever
8588             possible.  Configuration files for window managers and
8589             display managers should be placed in a subdirectory of
8590             <file>/etc/X11/</file> corresponding to the package name due
8591             to these programs' tight integration with the mechanisms
8592             of the X Window System.  Application-level programs should
8593             use the <file>/etc/</file> directory unless otherwise mandated
8594             by policy.
8595           </p>
8596
8597           <p>
8598             The installation of files into subdirectories
8599             of <file>/usr/X11R6/include/X11/</file> and
8600             <file>/usr/X11R6/lib/X11/</file> is now prohibited;
8601             package maintainers should determine if subdirectories of
8602             <file>/usr/lib/</file> and <file>/usr/share/</file> can be used
8603             instead. 
8604           </p>
8605
8606           <p>
8607             Packages should install any relevant files into the
8608             directories <file>/usr/include/X11/</file> and
8609             <file>/usr/lib/X11/</file>, but if they do so, they must
8610             pre-depend on <tt>x11-common (&gt;=
8611             1:7.0.0)</tt><footnote>
8612               <p>
8613                 These libraries used to be all symbolic
8614                 links. However, with <tt>X11R7</tt>,
8615                 <tt>/usr/include/X11</tt> and <tt>/usr/lib/X11</tt>
8616                 are now real directories, and packages
8617                 <strong>should</strong> ship their files here instead
8618                 of in <tt>/usr/X11R6/{include,lib}/X11</tt>.
8619                 <tt>x11-common (&gt;= 1:7.0.0) </tt> is the package
8620                 responsible for converting these symlinks into
8621                 directories.
8622               </p>
8623             </footnote>
8624           </p>
8625         </sect1>
8626
8627         <sect1>
8628           <heading>The OSF/Motif and OpenMotif libraries</heading>
8629
8630           <p>
8631             <em>Programs that require the non-DFSG-compliant OSF/Motif or
8632               OpenMotif libraries</em><footnote>
8633                 OSF/Motif and OpenMotif are collectively referred to as
8634                 "Motif" in this policy document.
8635             </footnote>
8636             should be compiled against and tested with LessTif (a free
8637             re-implementation of Motif) instead.  If the maintainer
8638             judges that the program or programs do not work
8639             sufficiently well with LessTif to be distributed and
8640             supported, but do so when compiled against Motif, then two
8641             versions of the package should be created; one linked
8642             statically against Motif and with <tt>-smotif</tt>
8643             appended to the package name, and one linked dynamically
8644             against Motif and with <tt>-dmotif</tt> appended to the
8645             package name.
8646           </p>
8647
8648           <p>
8649             Both Motif-linked versions are dependent
8650             upon non-DFSG-compliant software and thus cannot be
8651             uploaded to the <em>main</em> distribution; if the
8652             software is itself DFSG-compliant it may be uploaded to
8653             the <em>contrib</em> distribution.  While known existing
8654             versions of Motif permit unlimited redistribution of
8655             binaries linked against the library (whether statically or
8656             dynamically), it is the package maintainer's
8657             responsibility to determine whether this is permitted by
8658             the license of the copy of Motif in their possession.
8659           </p>
8660         </sect1>
8661       </sect>
8662
8663       <sect id="perl">
8664         <heading>Perl programs and modules</heading>
8665
8666         <p>
8667           Perl programs and modules should follow the current Perl policy.
8668         </p>
8669
8670         <p>
8671           The Perl policy can be found in the <tt>perl-policy</tt>
8672           files in the <tt>debian-policy</tt> package.
8673           It is also available from the Debian web mirrors at
8674           <tt><url name="/doc/packaging-manuals/perl-policy/"
8675                 id="http://www.debian.org/doc/packaging-manuals/perl-policy/"></tt>.
8676         </p>
8677       </sect>
8678
8679       <sect id="emacs">
8680         <heading>Emacs lisp programs</heading>
8681
8682         <p>
8683           Please refer to the "Debian Emacs Policy" for details of how to
8684           package emacs lisp programs.
8685         </p>
8686
8687         <p>
8688           The Emacs policy is available in
8689           <file>debian-emacs-policy.gz</file> of the
8690           <package>emacsen-common</package> package.
8691           It is also available from the Debian web mirrors at
8692           <tt><url name="/doc/packaging-manuals/debian-emacs-policy"
8693                 id="http://www.debian.org/doc/packaging-manuals/debian-emacs-policy"></tt>.
8694         </p>
8695       </sect>
8696
8697       <sect>
8698         <heading>Games</heading>
8699
8700         <p>
8701           The permissions on <file>/var/games</file> are mode 755, owner
8702           <tt>root</tt> and group <tt>root</tt>.
8703         </p>
8704
8705         <p>
8706           Each game decides on its own security policy.</p>
8707
8708         <p>
8709           Games which require protected, privileged access to
8710           high-score files, saved games, etc., may be made
8711           set-<em>group</em>-id (mode 2755) and owned by
8712           <tt>root:games</tt>, and use files and directories with
8713           appropriate permissions (770 <tt>root:games</tt>, for
8714           example).  They must not be made
8715           set-<em>user</em>-id, as this causes security problems. (If
8716           an attacker can subvert any set-user-id game they can
8717           overwrite the executable of any other, causing other players
8718           of these games to run a Trojan horse program.  With a
8719           set-group-id game the attacker only gets access to less
8720           important game data, and if they can get at the other
8721           players' accounts at all it will take considerably more
8722           effort.)</p>
8723
8724         <p>
8725           Some packages, for example some fortune cookie programs, are
8726           configured by the upstream authors to install with their
8727           data files or other static information made unreadable so
8728           that they can only be accessed through set-id programs
8729           provided.  You should not do this in a Debian package: anyone can
8730           download the <file>.deb</file> file and read the data from it,
8731           so there is no point making the files unreadable.  Not
8732           making the files unreadable also means that you don't have
8733           to make so many programs set-id, which reduces the risk of a
8734           security hole.</p>
8735
8736         <p>
8737           As described in the FHS, binaries of games should be
8738           installed in the directory <file>/usr/games</file>. This also
8739           applies to games that use the X Window System. Manual pages
8740           for games (X and non-X games) should be installed in
8741           <file>/usr/share/man/man6</file>.</p>
8742       </sect>
8743     </chapt>
8744
8745
8746     <chapt id="docs">
8747       <heading>Documentation</heading>
8748
8749       <sect>
8750         <heading>Manual pages</heading>
8751
8752         <p>
8753           You should install manual pages in <prgn>nroff</prgn> source
8754           form, in appropriate places under <file>/usr/share/man</file>.
8755           You should only use sections 1 to 9 (see the FHS for more
8756           details).  You must not install a pre-formatted "cat page".
8757         </p>
8758
8759         <p>
8760           Each program, utility, and function should have an
8761           associated manual page included in the same package. It is
8762           suggested that all configuration files also have a manual
8763           page included as well. Manual pages for protocols and other
8764           auxiliary things are optional.
8765         </p>
8766
8767         <p>
8768           If no manual page is available, this is considered as a bug
8769           and should be reported to the Debian Bug Tracking System (the
8770           maintainer of the package is allowed to write this bug report
8771           themselves, if they so desire).  Do not close the bug report
8772           until a proper man page is available.<footnote>
8773               It is not very hard to write a man page. See the
8774               <url id="http://www.schweikhardt.net/man_page_howto.html"
8775                 name="Man-Page-HOWTO">,
8776               <manref name="man" section="7">, the examples
8777               created by <prgn>debmake</prgn> or <prgn>dh_make</prgn>,
8778               the helper programs <prgn>help2man</prgn>, or the
8779               directory <file>/usr/share/doc/man-db/examples</file>.
8780           </footnote>
8781         </p>
8782
8783         <p>
8784           You may forward a complaint about a missing man page to the
8785           upstream authors, and mark the bug as forwarded in the
8786           Debian bug tracking system.  Even though the GNU Project do
8787           not in general consider the lack of a man page to be a bug,
8788           we do; if they tell you that they don't consider it a bug
8789           you should leave the bug in our bug tracking system open
8790           anyway.
8791         </p>
8792
8793         <p>
8794           Manual pages should be installed compressed using <tt>gzip -9</tt>.
8795         </p>
8796
8797         <p>
8798           If one man page needs to be accessible via several names it
8799           is better to use a symbolic link than the <file>.so</file>
8800           feature, but there is no need to fiddle with the relevant
8801           parts of the upstream source to change from <file>.so</file> to
8802           symlinks: don't do it unless it's easy.  You should not
8803           create hard links in the manual page directories, nor put
8804           absolute filenames in <file>.so</file> directives.  The filename
8805           in a <file>.so</file> in a man page should be relative to the
8806           base of the man page tree (usually
8807           <file>/usr/share/man</file>). If you do not create any links
8808           (whether symlinks, hard links, or <tt>.so</tt> directives)
8809           in the file system to the alternate names of the man page,
8810           then you should not rely on <prgn>man</prgn> finding your
8811           man page under those names based solely on the information in
8812           the man page's header.<footnote>
8813               Supporting this in <prgn>man</prgn> often requires
8814               unreasonable processing time to find a manual page or to
8815               report that none exists, and moves knowledge into man's
8816               database that would be better left in the file system.
8817               This support is therefore deprecated and will cease to
8818               be present in the future.
8819           </footnote>
8820         </p>
8821
8822         <p>
8823           Manual pages in locale-specific subdirectories of
8824           <file>/usr/share/man</file> should use either UTF-8 or the usual
8825           legacy encoding for that language (normally the one corresponding
8826           to the shortest relevant locale name in
8827           <file>/usr/share/i18n/SUPPORTED</file>). For example, pages under
8828           <file>/usr/share/man/fr</file> should use either UTF-8 or
8829           ISO-8859-1.<footnote>
8830             <prgn>man</prgn> will automatically detect whether UTF-8 is in
8831             use. In future, all manual pages will be required to use
8832             UTF-8.
8833           </footnote>
8834         </p>
8835
8836         <p>
8837           A country name (the <tt>DE</tt> in <tt>de_DE</tt>) should not be
8838           included in the subdirectory name unless it indicates a
8839           significant difference in the language, as this excludes
8840           speakers of the language in other countries.<footnote>
8841             At the time of writing, Chinese and Portuguese are the main
8842             languages with such differences, so <file>pt_BR</file>,
8843             <file>zh_CN</file>, and <file>zh_TW</file> are all allowed.
8844           </footnote>
8845         </p>
8846
8847         <p>
8848           Due to limitations in current implementations, all characters
8849           in the manual page source should be representable in the usual
8850           legacy encoding for that language, even if the file is
8851           actually encoded in UTF-8. Safe alternative ways to write many
8852           characters outside that range may be found in
8853           <manref name="groff_char" section="7">.
8854         </p>
8855       </sect>
8856
8857       <sect>
8858         <heading>Info documents</heading>
8859
8860         <p>
8861           Info documents should be installed in <file>/usr/share/info</file>.
8862           They should be compressed with <tt>gzip -9</tt>.
8863         </p>
8864
8865         <p>
8866           Your package should call <prgn>install-info</prgn> to update
8867           the Info <file>dir</file> file in its <prgn>postinst</prgn>
8868           script when called with a <tt>configure</tt> argument, for
8869           example:
8870           <example compact="compact">
8871 install-info --quiet --section Development Development \
8872   /usr/share/info/foobar.info
8873           </example></p>
8874
8875         <p>
8876           It is a good idea to specify a section for the location of
8877           your program; this is done with the <tt>--section</tt>
8878           switch.  To determine which section to use, you should look
8879           at <file>/usr/share/info/dir</file> on your system and choose the most
8880           relevant (or create a new section if none of the current
8881           sections are relevant).  Note that the <tt>--section</tt>
8882           flag takes two arguments; the first is a regular expression
8883           to match (case-insensitively) against an existing section,
8884           the second is used when creating a new one.</p>
8885
8886         <p>
8887           You should remove the entries in the <prgn>prerm</prgn>
8888           script when called with a <tt>remove</tt> argument:
8889           <example compact="compact">
8890 install-info --quiet --remove /usr/share/info/foobar.info
8891           </example></p>
8892
8893         <p>
8894           If <prgn>install-info</prgn> cannot find a description entry
8895           in the Info file you must supply one.  See <manref
8896           name="install-info" section="8"> for details.</p>
8897       </sect>
8898
8899       <sect>
8900         <heading>Additional documentation</heading>
8901
8902         <p>
8903           Any additional documentation that comes with the package may
8904           be installed at the discretion of the package maintainer.
8905           Plain text documentation should be installed in the directory
8906           <file>/usr/share/doc/<var>package</var></file>, where
8907           <var>package</var> is the name of the package, and
8908           compressed with <tt>gzip -9</tt> unless it is small.
8909         </p>
8910
8911         <p>
8912           If a package comes with large amounts of documentation which
8913           many users of the package will not require you should create
8914           a separate binary package to contain it, so that it does not
8915           take up disk space on the machines of users who do not need
8916           or want it installed.</p>
8917
8918         <p>
8919           It is often a good idea to put text information files
8920           (<file>README</file>s, changelogs, and so forth) that come with
8921           the source package in <file>/usr/share/doc/<var>package</var></file>
8922           in the binary package.  However, you don't need to install
8923           the instructions for building and installing the package, of
8924           course!</p>
8925
8926         <p>
8927           Packages must not require the existence of any files in
8928           <file>/usr/share/doc/</file> in order to function
8929           <footnote>
8930               The system administrator should be able to
8931               delete files in <file>/usr/share/doc/</file> without causing
8932               any programs to break.
8933           </footnote>.
8934           Any files that are referenced by programs but are also
8935           useful as stand alone documentation should be installed under
8936           <file>/usr/share/<var>package</var>/</file> with symbolic links from
8937           <file>/usr/share/doc/<var>package</var></file>.
8938         </p>
8939
8940         <p>
8941           <file>/usr/share/doc/<var>package</var></file> may be a symbolic
8942           link to another directory in <file>/usr/share/doc</file> only if
8943           the two packages both come from the same source and the
8944           first package Depends on the second.<footnote>
8945             <p>
8946               Please note that this does not override the section on
8947               changelog files below, so the file 
8948               <file>/usr/share/<var>package</var>/changelog.Debian.gz</file>
8949               must refer to the changelog for the current version of
8950               <var>package</var> in question. In practice, this means
8951               that the sources of the target and the destination of the
8952               symlink must be the same (same source package and
8953               version). 
8954             </p>
8955           </footnote>
8956         </p>
8957
8958         <p>
8959           Former Debian releases placed all additional documentation
8960           in <file>/usr/doc/<var>package</var></file>.  This has been
8961           changed to <file>/usr/share/doc/<var>package</var></file>,
8962           and packages must not put documentation in the directory
8963           <file>/usr/doc/<var>package</var></file>. <footnote>
8964             At this phase of the transition, we no longer require a
8965             symbolic link in <file>/usr/doc/</file>. At a later point,
8966             policy shall change to make the symbolic links a bug.
8967           </footnote>
8968         </p>
8969       </sect>
8970
8971       <sect>
8972         <heading>Preferred documentation formats</heading>
8973
8974         <p>
8975           The unification of Debian documentation is being carried out
8976           via HTML.</p>
8977
8978         <p>
8979           If your package comes with extensive documentation in a
8980           markup format that can be converted to various other formats
8981           you should if possible ship HTML versions in a binary
8982           package, in the directory
8983           <file>/usr/share/doc/<var>appropriate-package</var></file> or
8984           its subdirectories.<footnote>
8985               The rationale: The important thing here is that HTML
8986               docs should be available in <em>some</em> package, not
8987               necessarily in the main binary package.
8988           </footnote>
8989         </p>
8990
8991         <p>
8992           Other formats such as PostScript may be provided at the
8993           package maintainer's discretion.
8994         </p>
8995       </sect>
8996
8997       <sect id="copyrightfile">
8998         <heading>Copyright information</heading>
8999
9000         <p>
9001           Every package must be accompanied by a verbatim copy of its
9002           copyright and distribution license in the file
9003           <file>/usr/share/doc/<var>package</var>/copyright</file>. This
9004           file must neither be compressed nor be a symbolic link.
9005         </p>
9006
9007         <p>
9008           In addition, the copyright file must say where the upstream
9009           sources (if any) were obtained.  It should name the original
9010           authors of the package and the Debian maintainer(s) who were
9011           involved with its creation.
9012         </p>
9013
9014         <p>
9015           Packages in the <em>contrib</em> or <em>non-free</em>
9016           distribution areas should state in the copyright file that the
9017           package is not part of the Debian GNU/Linux distribution and
9018           briefly explain why.
9019         </p>
9020
9021         <p>
9022           A copy of the file which will be installed in
9023           <file>/usr/share/doc/<var>package</var>/copyright</file> should
9024           be in <file>debian/copyright</file> in the source package.
9025         </p>
9026
9027         <p>
9028           <file>/usr/share/doc/<var>package</var></file> may be a symbolic
9029           link to another directory in <file>/usr/share/doc</file> only if
9030           the two packages both come from the same source and the
9031           first package Depends on the second.  These rules are
9032           important because copyrights must be extractable by
9033           mechanical means.
9034         </p>
9035
9036         <p>
9037           Packages distributed under the UCB BSD license, the Apache
9038           license (version 2.0), the Artistic license, the GNU GPL
9039           (version 2 or 3), the GNU LGPL (versions 2, 2.1, or 3), and
9040           the GNU FDL (version 1.2) should refer to the corresponding
9041           files under <file>/usr/share/common-licenses</file>,<footnote>
9042             <p>
9043               In particular,
9044               <file>/usr/share/common-licenses/BSD</file>,
9045               <file>/usr/share/common-licenses/Apache-2.0</file>,
9046               <file>/usr/share/common-licenses/Artistic</file>,
9047               <file>/usr/share/common-licenses/GPL-2</file>,
9048               <file>/usr/share/common-licenses/GPL-3</file>,
9049               <file>/usr/share/common-licenses/LGPL-2</file>,
9050               <file>/usr/share/common-licenses/LGPL-2.1</file>,
9051               <file>/usr/share/common-licenses/LGPL-3</file>, and
9052               <file>/usr/share/common-licenses/GFDL-1.2</file>
9053               respectively.
9054             </p>
9055           </footnote> rather than quoting them in the copyright
9056           file. 
9057         </p>
9058
9059         <p>
9060           You should not use the copyright file as a general <file>README</file>
9061           file.  If your package has such a file it should be
9062           installed in <file>/usr/share/doc/<var>package</var>/README</file> or
9063           <file>README.Debian</file> or some other appropriate place.</p>
9064       </sect>
9065
9066       <sect>
9067         <heading>Examples</heading>
9068
9069         <p>
9070           Any examples (configurations, source files, whatever),
9071           should be installed in a directory
9072           <file>/usr/share/doc/<var>package</var>/examples</file>.  These
9073           files should not be referenced by any program: they're there
9074           for the benefit of the system administrator and users as
9075           documentation only.  Architecture-specific example files
9076           should be installed in a directory
9077           <file>/usr/lib/<var>package</var>/examples</file> with symbolic
9078           links to them from
9079           <file>/usr/share/doc/<var>package</var>/examples</file>, or the
9080           latter directory itself may be a symbolic link to the
9081           former.
9082         </p>
9083
9084         <p>
9085           If the purpose of a package is to provide examples, then the
9086           example files may be installed into
9087           <file>/usr/share/doc/<var>package</var></file>.
9088         </p>
9089       </sect>
9090
9091       <sect id="changelogs">
9092         <heading>Changelog files</heading>
9093
9094         <p>
9095           Packages that are not Debian-native must contain a
9096           compressed copy of the <file>debian/changelog</file> file from
9097           the Debian source tree in
9098           <file>/usr/share/doc/<var>package</var></file> with the name
9099           <file>changelog.Debian.gz</file>.
9100         </p>
9101
9102         <p>
9103           If an upstream changelog is available, it should be accessible as
9104           <file>/usr/share/doc/<var>package</var>/changelog.gz</file> in
9105           plain text.  If the upstream changelog is distributed in
9106           HTML, it should be made available in that form as
9107           <file>/usr/share/doc/<var>package</var>/changelog.html.gz</file>
9108           and a plain text <file>changelog.gz</file> should be generated
9109           from it using, for example, <tt>lynx -dump -nolist</tt>.  If
9110           the upstream changelog files do not already conform to this
9111           naming convention, then this may be achieved either by
9112           renaming the files, or by adding a symbolic link, at the
9113           maintainer's discretion.<footnote>
9114               Rationale: People should not have to look in places for
9115               upstream changelogs merely because they are given
9116               different names or are distributed in HTML format.
9117           </footnote>
9118         </p>
9119
9120         <p>
9121           All of these files should be installed compressed using
9122           <tt>gzip -9</tt>, as they will become large with time even
9123           if they start out small.
9124         </p>
9125
9126         <p>
9127           If the package has only one changelog which is used both as
9128           the Debian changelog and the upstream one because there is
9129           no separate upstream maintainer then that changelog should
9130           usually be installed as
9131           <file>/usr/share/doc/<var>package</var>/changelog.gz</file>; if
9132           there is a separate upstream maintainer, but no upstream
9133           changelog, then the Debian changelog should still be called
9134           <file>changelog.Debian.gz</file>.
9135         </p>
9136
9137         <p>
9138           For details about the format and contents of the Debian
9139           changelog file, please see <ref id="dpkgchangelog">.
9140         </p>
9141       </sect>
9142     </chapt>
9143
9144     <appendix id="pkg-scope">
9145       <heading>Introduction and scope of these appendices</heading>
9146
9147       <p>
9148         These appendices are taken essentially verbatim from the
9149         now-deprecated Packaging Manual, version 3.2.1.0.  They are
9150         the chapters which are likely to be of use to package
9151         maintainers and which have not already been included in the
9152         policy document itself. Most of these sections are very likely
9153         not relevant to policy; they should be treated as
9154         documentation for the packaging system. Please note that these
9155         appendices are included for convenience, and for historical
9156         reasons: they used to be part of policy package, and they have
9157         not yet been incorporated into dpkg documentation. However,
9158         they still have value, and hence they are presented here.
9159       </p>
9160
9161       <p>
9162         They have not yet been checked to ensure that they are
9163         compatible with the contents of policy, and if there are any
9164         contradictions, the version in the main policy document takes
9165         precedence.  The remaining chapters of the old Packaging
9166         Manual have also not been read in detail to ensure that there
9167         are not parts which have been left out.  Both of these will be
9168         done in due course.
9169       </p>
9170
9171       <p>
9172         Certain parts of the Packaging manual were integrated into the
9173         Policy Manual proper, and removed from the appendices. Links
9174         have been placed from the old locations to the new ones.
9175       </p>
9176
9177       <p>
9178         <prgn>dpkg</prgn> is a suite of programs for creating binary
9179         package files and installing and removing them on Unix
9180         systems.<footnote>
9181             <prgn>dpkg</prgn> is targeted primarily at Debian
9182             GNU/Linux, but may work on or be ported to other
9183             systems.
9184         </footnote>
9185       </p>
9186
9187       <p>
9188         The binary packages are designed for the management of
9189         installed executable programs (usually compiled binaries) and
9190         their associated data, though source code examples and
9191         documentation are provided as part of some packages.</p>
9192
9193       <p>
9194         This manual describes the technical aspects of creating Debian
9195         binary packages (<file>.deb</file> files).  It documents the
9196         behavior of the package management programs
9197         <prgn>dpkg</prgn>, <prgn>dselect</prgn> et al. and the way
9198         they interact with packages.</p>
9199
9200       <p>
9201         It also documents the interaction between
9202         <prgn>dselect</prgn>'s core and the access method scripts it
9203         uses to actually install the selected packages, and describes
9204         how to create a new access method.</p>
9205
9206       <p>
9207         This manual does not go into detail about the options and
9208         usage of the package building and installation tools.  It
9209         should therefore be read in conjunction with those programs'
9210         man pages.
9211       </p>
9212
9213       <p>
9214         The utility programs which are provided with <prgn>dpkg</prgn>
9215         for managing various system configuration and similar issues,
9216         such as <prgn>update-rc.d</prgn> and
9217         <prgn>install-info</prgn>, are not described in detail here -
9218         please see their man pages.
9219       </p>
9220
9221       <p>
9222         It is assumed that the reader is reasonably familiar with the
9223         <prgn>dpkg</prgn> System Administrators' manual.
9224         Unfortunately this manual does not yet exist.
9225       </p>
9226
9227       <p>
9228         The Debian version of the FSF's GNU hello program is provided
9229         as an example for people wishing to create Debian
9230         packages. The Debian <prgn>debmake</prgn> package is
9231         recommended as a very helpful tool in creating and maintaining
9232         Debian packages. However, while the tools and examples are
9233         helpful, they do not replace the need to read and follow the
9234         Policy and Programmer's Manual.</p>
9235     </appendix>
9236
9237     <appendix id="pkg-binarypkg">
9238       <heading>Binary packages (from old Packaging Manual)</heading>
9239
9240       <p>
9241         The binary package has two main sections.  The first part
9242         consists of various control information files and scripts used
9243         by <prgn>dpkg</prgn> when installing and removing.  See <ref
9244         id="pkg-controlarea">.
9245       </p>
9246
9247       <p>
9248         The second part is an archive containing the files and
9249         directories to be installed.
9250       </p>
9251
9252       <p>
9253         In the future binary packages may also contain other
9254         components, such as checksums and digital signatures. The
9255         format for the archive is described in full in the
9256         <file>deb(5)</file> man page.
9257       </p>
9258
9259
9260       <sect id="pkg-bincreating"><heading>Creating package files -
9261       <prgn>dpkg-deb</prgn>
9262         </heading>
9263
9264         <p>
9265           All manipulation of binary package files is done by
9266           <prgn>dpkg-deb</prgn>; it's the only program that has
9267           knowledge of the format.  (<prgn>dpkg-deb</prgn> may be
9268           invoked by calling <prgn>dpkg</prgn>, as <prgn>dpkg</prgn>
9269           will spot that the options requested are appropriate to
9270           <prgn>dpkg-deb</prgn> and invoke that instead with the same
9271           arguments.)
9272         </p>
9273
9274         <p>
9275           In order to create a binary package you must make a
9276           directory tree which contains all the files and directories
9277           you want to have in the file system data part of the package.
9278           In Debian-format source packages this directory is usually
9279           <file>debian/tmp</file>, relative to the top of the package's
9280           source tree.
9281         </p>
9282
9283         <p>
9284           They should have the locations (relative to the root of the
9285           directory tree you're constructing) ownerships and
9286           permissions which you want them to have on the system when
9287           they are installed.
9288         </p>
9289
9290         <p>
9291           With current versions of <prgn>dpkg</prgn> the uid/username
9292           and gid/groupname mappings for the users and groups being
9293           used should be the same on the system where the package is
9294           built and the one where it is installed.
9295         </p>
9296
9297         <p>
9298           You need to add one special directory to the root of the
9299           miniature file system tree you're creating:
9300           <prgn>DEBIAN</prgn>.  It should contain the control
9301           information files, notably the binary package control file
9302           (see <ref id="pkg-controlfile">).
9303         </p>
9304
9305         <p>
9306           The <prgn>DEBIAN</prgn> directory will not appear in the
9307           file system archive of the package, and so won't be installed
9308           by <prgn>dpkg</prgn> when the package is installed.
9309         </p>
9310
9311         <p>
9312           When you've prepared the package, you should invoke:
9313           <example>
9314   dpkg --build <var>directory</var>
9315           </example>
9316         </p>
9317
9318         <p>
9319           This will build the package in
9320           <file><var>directory</var>.deb</file>.  (<prgn>dpkg</prgn> knows
9321           that <tt>--build</tt> is a <prgn>dpkg-deb</prgn> option, so
9322           it invokes <prgn>dpkg-deb</prgn> with the same arguments to
9323           build the package.)
9324         </p>
9325
9326         <p>
9327           See the man page <manref name="dpkg-deb" section="8"> for details of how
9328           to examine the contents of this newly-created file.  You may find the
9329           output of following commands enlightening:
9330           <example>
9331   dpkg-deb --info <var>filename</var>.deb
9332   dpkg-deb --contents <var>filename</var>.deb
9333   dpkg --contents <var>filename</var>.deb
9334           </example>
9335           To view the copyright file for a package you could use this command:
9336           <example>
9337   dpkg --fsys-tarfile <var>filename</var>.deb | tar xOf - --wildcards \*/copyright | pager
9338           </example>
9339         </p>
9340       </sect>
9341
9342       <sect id="pkg-controlarea">
9343         <heading>Package control information files</heading>
9344
9345         <p>
9346           The control information portion of a binary package is a
9347           collection of files with names known to <prgn>dpkg</prgn>.
9348           It will treat the contents of these files specially - some
9349           of them contain information used by <prgn>dpkg</prgn> when
9350           installing or removing the package; others are scripts which
9351           the package maintainer wants <prgn>dpkg</prgn> to run.
9352         </p>
9353
9354         <p>
9355           It is possible to put other files in the package control
9356           area, but this is not generally a good idea (though they
9357           will largely be ignored).
9358         </p>
9359
9360         <p>
9361           Here is a brief list of the control info files supported by
9362           <prgn>dpkg</prgn> and a summary of what they're used for.
9363         </p>
9364
9365         <p>
9366           <taglist>
9367             <tag><tt>control</tt>
9368             <item>
9369               <p>
9370                 This is the key description file used by
9371                 <prgn>dpkg</prgn>.  It specifies the package's name
9372                 and version, gives its description for the user,
9373                 states its relationships with other packages, and so
9374                 forth.  See <ref id="sourcecontrolfiles"> and
9375                 <ref id="binarycontrolfiles">.
9376               </p>
9377
9378               <p>
9379                 It is usually generated automatically from information
9380                 in the source package by the
9381                 <prgn>dpkg-gencontrol</prgn> program, and with
9382                 assistance from <prgn>dpkg-shlibdeps</prgn>.
9383                 See <ref id="pkg-sourcetools">.
9384               </p>
9385             </item>
9386
9387             <tag><tt>postinst</tt>, <tt>preinst</tt>, <tt>postrm</tt>,
9388                  <tt>prerm</tt>
9389             </tag>
9390             <item>
9391               <p>
9392                 These are executable files (usually scripts) which
9393                 <prgn>dpkg</prgn> runs during installation, upgrade
9394                 and removal of packages.  They allow the package to
9395                 deal with matters which are particular to that package
9396                 or require more complicated processing than that
9397                 provided by <prgn>dpkg</prgn>.  Details of when and
9398                 how they are called are in <ref id="maintainerscripts">.
9399               </p>
9400
9401               <p>
9402                 It is very important to make these scripts idempotent.
9403                 See <ref id="idempotency">.
9404               </p>
9405
9406               <p>
9407                 The maintainer scripts are guaranteed to run with a
9408                 controlling terminal and can interact with the user.
9409                 See <ref id="controllingterminal">.
9410               </p>
9411             </item>
9412
9413             <tag><tt>conffiles</tt>
9414             </tag>
9415             <item>
9416                 This file contains a list of configuration files which
9417                 are to be handled automatically by <prgn>dpkg</prgn>
9418                 (see <ref id="pkg-conffiles">).  Note that not necessarily
9419                 every configuration file should be listed here.
9420             </item>
9421
9422             <tag><tt>shlibs</tt>
9423             </tag>
9424             <item>
9425                 This file contains a list of the shared libraries
9426                 supplied by the package, with dependency details for
9427                 each.  This is used by <prgn>dpkg-shlibdeps</prgn>
9428                 when it determines what dependencies are required in a
9429                 package control file. The <tt>shlibs</tt> file format
9430                 is described on <ref id="shlibs">.
9431             </item>
9432           </taglist>
9433         </p>
9434
9435       <sect id="pkg-controlfile">
9436         <heading>The main control information file: <tt>control</tt></heading>
9437
9438         <p>
9439           The most important control information file used by
9440           <prgn>dpkg</prgn> when it installs a package is
9441           <tt>control</tt>.  It contains all the package's "vital
9442           statistics".
9443         </p>
9444
9445         <p>
9446           The binary package control files of packages built from
9447           Debian sources are made by a special tool,
9448           <prgn>dpkg-gencontrol</prgn>, which reads
9449           <file>debian/control</file> and <file>debian/changelog</file> to
9450           find the information it needs.  See <ref id="pkg-sourcepkg"> for
9451           more details.
9452         </p>
9453
9454         <p>
9455           The fields in binary package control files are listed in
9456           <ref id="binarycontrolfiles">.
9457         </p>
9458
9459         <p>
9460           A description of the syntax of control files and the purpose
9461           of the fields is available in <ref id="controlfields">.
9462         </p>
9463       </sect>
9464
9465       <sect>
9466         <heading>Time Stamps</heading>
9467
9468         <p>
9469           See <ref id="timestamps">.
9470         </p>
9471       </sect>
9472     </appendix>
9473
9474     <appendix id="pkg-sourcepkg">
9475       <heading>Source packages (from old Packaging Manual) </heading>
9476
9477       <p>
9478         The Debian binary packages in the distribution are generated
9479         from Debian sources, which are in a special format to assist
9480         the easy and automatic building of binaries.
9481       </p>
9482
9483       <sect id="pkg-sourcetools">
9484         <heading>Tools for processing source packages</heading>
9485
9486         <p>
9487           Various tools are provided for manipulating source packages;
9488           they pack and unpack sources and help build of binary
9489           packages and help manage the distribution of new versions.
9490         </p>
9491
9492         <p>
9493           They are introduced and typical uses described here; see
9494           <manref name="dpkg-source" section="1"> for full
9495           documentation about their arguments and operation.
9496         </p>
9497
9498         <p>
9499           For examples of how to construct a Debian source package,
9500           and how to use those utilities that are used by Debian
9501           source packages, please see the <prgn>hello</prgn> example
9502           package.
9503         </p>
9504
9505         <sect1 id="pkg-dpkg-source">
9506           <heading>
9507             <prgn>dpkg-source</prgn> - packs and unpacks Debian source
9508             packages
9509           </heading>
9510
9511           <p>
9512             This program is frequently used by hand, and is also
9513             called from package-independent automated building scripts
9514             such as <prgn>dpkg-buildpackage</prgn>.
9515           </p>
9516
9517           <p>
9518             To unpack a package it is typically invoked with
9519             <example>
9520   dpkg-source -x <var>.../path/to/filename</var>.dsc
9521             </example>
9522           </p>
9523
9524            <p>
9525             with the <file><var>filename</var>.tar.gz</file> and
9526             <file><var>filename</var>.diff.gz</file> (if applicable) in
9527             the same directory.  It unpacks into
9528             <file><var>package</var>-<var>version</var></file>, and if
9529             applicable
9530             <file><var>package</var>-<var>version</var>.orig</file>, in
9531             the current directory.
9532           </p>
9533
9534           <p>
9535             To create a packed source archive it is typically invoked:
9536             <example>
9537   dpkg-source -b <var>package</var>-<var>version</var>
9538           </example>
9539           </p>
9540
9541           <p>
9542             This will create the <file>.dsc</file>, <file>.tar.gz</file> and
9543             <file>.diff.gz</file> (if appropriate) in the current
9544             directory.  <prgn>dpkg-source</prgn> does not clean the
9545             source tree first - this must be done separately if it is
9546             required.
9547           </p>
9548
9549           <p>
9550             See also <ref id="pkg-sourcearchives">.</p>
9551         </sect1>
9552
9553
9554         <sect1 id="pkg-dpkg-buildpackage">
9555           <heading>
9556             <prgn>dpkg-buildpackage</prgn> - overall package-building
9557             control script
9558           </heading>
9559
9560           <p>
9561             <prgn>dpkg-buildpackage</prgn> is a script which invokes
9562             <prgn>dpkg-source</prgn>, the <file>debian/rules</file>
9563             targets <tt>clean</tt>, <tt>build</tt> and
9564             <tt>binary</tt>, <prgn>dpkg-genchanges</prgn> and
9565             <prgn>gpg</prgn> (or <prgn>pgp</prgn>) to build a signed
9566             source and binary package upload.
9567           </p>
9568
9569           <p>
9570             It is usually invoked by hand from the top level of the
9571             built or unbuilt source directory.  It may be invoked with
9572             no arguments; useful arguments include:
9573             <taglist compact="compact">
9574               <tag><tt>-uc</tt>, <tt>-us</tt></tag>
9575               <item>
9576                 <p>
9577                   Do not sign the <tt>.changes</tt> file or the
9578                   source package <tt>.dsc</tt> file, respectively.</p>
9579               </item>
9580               <tag><tt>-p<var>sign-command</var></tt></tag>
9581               <item>
9582                 <p>
9583                   Invoke <var>sign-command</var> instead of finding
9584                   <tt>gpg</tt> or <tt>pgp</tt> on the <prgn>PATH</prgn>.
9585                   <var>sign-command</var> must behave just like
9586                   <prgn>gpg</prgn> or <tt>pgp</tt>.</p>
9587               </item>
9588               <tag><tt>-r<var>root-command</var></tt></tag>
9589               <item>
9590                 <p>
9591                   When root privilege is required, invoke the command
9592                   <var>root-command</var>.  <var>root-command</var>
9593                   should invoke its first argument as a command, from
9594                   the <prgn>PATH</prgn> if necessary, and pass its
9595                   second and subsequent arguments to the command it
9596                   calls.  If no <var>root-command</var> is supplied
9597                   then <var>dpkg-buildpackage</var> will take no
9598                   special action to gain root privilege, so that for
9599                   most packages it will have to be invoked as root to
9600                   start with.</p>
9601               </item>
9602               <tag><tt>-b</tt>, <tt>-B</tt></tag>
9603               <item>
9604                 <p>
9605                   Two types of binary-only build and upload - see
9606                   <manref name="dpkg-source" section="1">.
9607                 </p>
9608               </item>
9609             </taglist>
9610           </p>
9611         </sect1>
9612
9613         <sect1 id="pkg-dpkg-gencontrol">
9614           <heading>
9615             <prgn>dpkg-gencontrol</prgn> - generates binary package
9616             control files
9617           </heading>
9618
9619           <p>
9620             This program is usually called from <file>debian/rules</file>
9621             (see <ref id="pkg-sourcetree">) in the top level of the source
9622             tree.
9623           </p>
9624
9625           <p>
9626             This is usually done just before the files and directories in the
9627             temporary directory tree where the package is being built have their
9628             permissions and ownerships set and the package is constructed using
9629             <prgn>dpkg-deb/</prgn>
9630               <footnote>
9631                 This is so that the control file which is produced has
9632                 the right permissions
9633             </footnote>.
9634           </p>
9635
9636           <p>
9637             <prgn>dpkg-gencontrol</prgn> must be called after all the
9638             files which are to go into the package have been placed in
9639             the temporary build directory, so that its calculation of
9640             the installed size of a package is correct.
9641           </p>
9642
9643           <p>
9644             It is also necessary for <prgn>dpkg-gencontrol</prgn> to
9645             be run after <prgn>dpkg-shlibdeps</prgn> so that the
9646             variable substitutions created by
9647             <prgn>dpkg-shlibdeps</prgn> in <file>debian/substvars</file>
9648             are available.
9649           </p>
9650
9651           <p>
9652             For a package which generates only one binary package, and
9653             which builds it in <file>debian/tmp</file> relative to the top
9654             of the source package, it is usually sufficient to call
9655             <prgn>dpkg-gencontrol</prgn>.
9656           </p>
9657
9658           <p>
9659             Sources which build several binaries will typically need
9660             something like:
9661             <example>
9662   dpkg-gencontrol -Pdebian/tmp-<var>pkg</var> -p<var>package</var>
9663             </example> The <tt>-P</tt> tells
9664             <prgn>dpkg-gencontrol</prgn> that the package is being
9665             built in a non-default directory, and the <tt>-p</tt>
9666             tells it which package's control file should be generated.
9667           </p>
9668
9669           <p>
9670             <prgn>dpkg-gencontrol</prgn> also adds information to the
9671             list of files in <file>debian/files</file>, for the benefit of
9672             (for example) a future invocation of
9673             <prgn>dpkg-genchanges</prgn>.</p>
9674         </sect1>
9675
9676         <sect1 id="pkg-dpkg-shlibdeps">
9677           <heading>
9678             <prgn>dpkg-shlibdeps</prgn> - calculates shared library
9679             dependencies
9680           </heading>
9681
9682           <p>
9683             This program is usually called from <file>debian/rules</file>
9684             just before <prgn>dpkg-gencontrol</prgn> (see <ref
9685             id="pkg-sourcetree">), in the top level of the source tree.
9686           </p>
9687
9688           <p>
9689             Its arguments are executables and shared libraries
9690             <footnote>
9691               <p>
9692                 They may be specified either in the locations in the
9693                 source tree where they are created or in the locations
9694                 in the temporary build tree where they are installed
9695                 prior to binary package creation.
9696               </p>
9697             </footnote> for which shared library dependencies should
9698             be included in the binary package's control file.
9699           </p>
9700
9701           <p>
9702             If some of the found shared libraries should only
9703             warrant a <tt>Recommends</tt> or <tt>Suggests</tt>, or if
9704             some warrant a <tt>Pre-Depends</tt>, this can be achieved
9705             by using the <tt>-d<var>dependency-field</var></tt> option
9706             before those executable(s).  (Each <tt>-d</tt> option
9707             takes effect until the next <tt>-d</tt>.)
9708           </p>
9709
9710           <p>
9711             <prgn>dpkg-shlibdeps</prgn> does not directly cause the
9712             output control file to be modified.  Instead by default it
9713             adds to the <file>debian/substvars</file> file variable
9714             settings like <tt>shlibs:Depends</tt>.  These variable
9715             settings must be referenced in dependency fields in the
9716             appropriate per-binary-package sections of the source
9717             control file.
9718           </p>
9719
9720           <p>
9721             For example, a package that generates an essential part
9722             which requires dependencies, and optional parts that 
9723             which only require a recommendation, would separate those
9724             two sets of dependencies into two different fields.<footnote>
9725                 At the time of writing, an example for this was the
9726                 <package/xmms/ package, with Depends used for the xmms
9727                 executable, Recommends for the plug-ins and Suggests for
9728                 even more optional features provided by unzip.
9729             </footnote>
9730             It can say in its <file>debian/rules</file>:
9731             <example>
9732   dpkg-shlibdeps -dDepends <var>program anotherprogram ...</var> \
9733                  -dRecommends <var>optionalpart anotheroptionalpart</var>
9734             </example>
9735             and then in its main control file <file>debian/control</file>:
9736             <example>
9737   <var>...</var>
9738   Depends: ${shlibs:Depends}
9739   Recommends: ${shlibs:Recommends}
9740   <var>...</var>
9741             </example>
9742           </p>
9743
9744           <p>
9745             Sources which produce several binary packages with
9746             different shared library dependency requirements can use
9747             the <tt>-p<var>varnameprefix</var></tt> option to override
9748             the default <tt>shlibs:</tt> prefix (one invocation of
9749             <prgn>dpkg-shlibdeps</prgn> per setting of this option).
9750             They can thus produce several sets of dependency
9751             variables, each of the form
9752             <tt><var>varnameprefix</var>:<var>dependencyfield</var></tt>,
9753             which can be referred to in the appropriate parts of the
9754             binary package control files.
9755           </p>
9756         </sect1>
9757
9758
9759         <sect1 id="pkg-dpkg-distaddfile">
9760           <heading>
9761             <prgn>dpkg-distaddfile</prgn> - adds a file to
9762             <file>debian/files</file>
9763           </heading>
9764
9765           <p>
9766             Some packages' uploads need to include files other than
9767             the source and binary package files.
9768           </p>
9769
9770           <p>
9771             <prgn>dpkg-distaddfile</prgn> adds a file to the
9772             <file>debian/files</file> file so that it will be included in
9773             the <file>.changes</file> file when
9774             <prgn>dpkg-genchanges</prgn> is run.
9775           </p>
9776
9777           <p>
9778             It is usually invoked from the <tt>binary</tt> target of
9779             <file>debian/rules</file>:
9780             <example>
9781   dpkg-distaddfile <var>filename</var> <var>section</var> <var>priority</var>
9782             </example>
9783             The <var>filename</var> is relative to the directory where
9784             <prgn>dpkg-genchanges</prgn> will expect to find it - this
9785             is usually the directory above the top level of the source
9786             tree.  The <file>debian/rules</file> target should put the
9787             file there just before or just after calling
9788             <prgn>dpkg-distaddfile</prgn>.
9789           </p>
9790
9791           <p>
9792             The <var>section</var> and <var>priority</var> are passed
9793             unchanged into the resulting <file>.changes</file> file.
9794           </p>
9795         </sect1>
9796
9797
9798         <sect1 id="pkg-dpkg-genchanges">
9799           <heading>
9800             <prgn>dpkg-genchanges</prgn> - generates a <file>.changes</file>
9801             upload control file
9802           </heading>
9803
9804           <p>
9805             This program is usually called by package-independent
9806             automatic building scripts such as
9807             <prgn>dpkg-buildpackage</prgn>, but it may also be called
9808             by hand.
9809           </p>
9810
9811           <p>
9812             It is usually called in the top level of a built source
9813             tree, and when invoked with no arguments will print out a
9814             straightforward <file>.changes</file> file based on the
9815             information in the source package's changelog and control
9816             file and the binary and source packages which should have
9817             been built.
9818           </p>
9819         </sect1>
9820
9821
9822         <sect1 id="pkg-dpkg-parsechangelog">
9823           <heading>
9824             <prgn>dpkg-parsechangelog</prgn> - produces parsed
9825             representation of a changelog
9826           </heading>
9827
9828           <p>
9829             This program is used internally by
9830             <prgn>dpkg-source</prgn> et al.  It may also occasionally
9831             be useful in <file>debian/rules</file> and elsewhere.  It
9832             parses a changelog, <file>debian/changelog</file> by default,
9833             and prints a control-file format representation of the
9834             information in it to standard output.
9835           </p>
9836         </sect1>
9837
9838         <sect1 id="pkg-dpkg-architecture">
9839           <heading>
9840             <prgn>dpkg-architecture</prgn> - information about the build and
9841             host system
9842           </heading>
9843
9844           <p>
9845             This program can be used manually, but is also invoked by
9846             <tt>dpkg-buildpackage</tt> or <file>debian/rules</file> to set
9847             environment or make variables which specify the build and host
9848             architecture for the package building process.
9849           </p>
9850         </sect1>
9851       </sect>
9852
9853       <sect id="pkg-sourcetree">
9854         <heading>The Debianised source tree</heading>
9855
9856         <p>
9857           The source archive scheme described later is intended to
9858           allow a Debianised source tree with some associated control
9859           information to be reproduced and transported easily.  The
9860           Debianised source tree is a version of the original program
9861           with certain files added for the benefit of the
9862           Debianisation process, and with any other changes required
9863           made to the rest of the source code and installation
9864           scripts.
9865         </p>
9866
9867         <p>
9868           The extra files created for Debian are in the subdirectory
9869           <file>debian</file> of the top level of the Debianised source
9870           tree.  They are described below.
9871         </p>
9872
9873         <sect1 id="pkg-debianrules">
9874           <heading><file>debian/rules</file> - the main building script</heading>
9875
9876           <p>
9877             See <ref id="debianrules">.
9878           </p>
9879         </sect1>
9880
9881
9882         <sect1 id="pkg-dpkgchangelog">
9883           <heading><file>debian/changelog</file></heading>
9884
9885           <p>
9886             See <ref id="dpkgchangelog">.
9887           </p>
9888
9889           <sect2><heading>Defining alternative changelog formats
9890             </heading>
9891
9892             <p>
9893               It is possible to use a different format to the standard
9894               one, by providing a parser for the format you wish to
9895               use.
9896             </p>
9897
9898             <p>
9899               In order to have <tt>dpkg-parsechangelog</tt> run your
9900               parser, you must include a line within the last 40 lines
9901               of your file matching the Perl regular expression:
9902               <tt>\schangelog-format:\s+([0-9a-z]+)\W</tt> The part in
9903               parentheses should be the name of the format.  For
9904               example, you might say:
9905               <example>
9906   @@@ changelog-format: joebloggs @@@
9907               </example>
9908               Changelog format names are non-empty strings of alphanumerics.
9909             </p>
9910
9911             <p>
9912               If such a line exists then <tt>dpkg-parsechangelog</tt>
9913               will look for the parser as
9914               <file>/usr/lib/dpkg/parsechangelog/<var>format-name</var></file>
9915               or
9916               <file>/usr/local/lib/dpkg/parsechangelog/<var>format-name</var></file>;
9917               it is an error for it not to find it, or for it not to
9918               be an executable program.  The default changelog format
9919               is <tt>dpkg</tt>, and a parser for it is provided with
9920               the <tt>dpkg</tt> package.
9921             </p>
9922
9923             <p>
9924               The parser will be invoked with the changelog open on
9925               standard input at the start of the file.  It should read
9926               the file (it may seek if it wishes) to determine the
9927               information required and return the parsed information
9928               to standard output in the form of a series of control
9929               fields in the standard format.  By default it should
9930               return information about only the most recent version in
9931               the changelog; it should accept a
9932               <tt>-v<var>version</var></tt> option to return changes
9933               information from all versions present <em>strictly
9934               after</em> <var>version</var>, and it should then be an
9935               error for <var>version</var> not to be present in the
9936               changelog.
9937             </p>
9938
9939             <p>
9940               The fields are:
9941               <list compact="compact">
9942                 <item><qref id="f-Source"><tt>Source</tt></qref></item>
9943                 <item><qref id="f-Version"><tt>Version</tt></qref> (mandatory)</item>
9944                 <item><qref id="f-Distribution"><tt>Distribution</tt></qref> (mandatory)</item>
9945                 <item><qref id="f-Urgency"><tt>Urgency</tt></qref> (mandatory)</item>
9946                 <item><qref id="f-Maintainer"><tt>Maintainer</tt></qref> (mandatory)</item>
9947                 <item><qref id="f-Date"><tt>Date</tt></qref></item>
9948                 <item><qref id="f-Changes"><tt>Changes</tt></qref> (mandatory)</item>
9949               </list>
9950             </p>
9951
9952             <p>
9953               If several versions are being returned (due to the use
9954               of <tt>-v</tt>), the urgency value should be of the
9955               highest urgency code listed at the start of any of the
9956               versions requested followed by the concatenated
9957               (space-separated) comments from all the versions
9958               requested; the maintainer, version, distribution and
9959               date should always be from the most recent version.
9960             </p>
9961
9962             <p>
9963               For the format of the <tt>Changes</tt> field see
9964               <ref id="f-Changes">.
9965             </p>
9966
9967             <p>
9968               If the changelog format which is being parsed always or
9969               almost always leaves a blank line between individual
9970               change notes these blank lines should be stripped out,
9971               so as to make the resulting output compact.
9972             </p>
9973
9974             <p>
9975               If the changelog format does not contain date or package
9976               name information this information should be omitted from
9977               the output.  The parser should not attempt to synthesize
9978               it or find it from other sources.
9979             </p>
9980
9981             <p>
9982               If the changelog does not have the expected format the
9983               parser should exit with a nonzero exit status, rather
9984               than trying to muddle through and possibly generating
9985               incorrect output.
9986             </p>
9987
9988             <p>
9989               A changelog parser may not interact with the user at
9990               all.
9991             </p>
9992           </sect2>
9993         </sect1>
9994
9995         <sect1 id="pkg-srcsubstvars">
9996           <heading><file>debian/substvars</file> and variable substitutions</heading>
9997
9998           <p>
9999             See <ref id="substvars">.
10000           </p>
10001
10002         </sect1>
10003
10004         <sect1>
10005           <heading><file>debian/files</file></heading>
10006
10007           <p>
10008             See <ref id="debianfiles">.
10009           </p>
10010         </sect1>
10011
10012         <sect1><heading><file>debian/tmp</file>
10013           </heading>
10014
10015           <p>
10016             This is the canonical temporary location for the
10017             construction of binary packages by the <tt>binary</tt>
10018             target.  The directory <file>tmp</file> serves as the root of
10019             the file system tree as it is being constructed (for
10020             example, by using the package's upstream makefiles install
10021             targets and redirecting the output there), and it also
10022             contains the <tt>DEBIAN</tt> subdirectory.  See <ref
10023             id="pkg-bincreating">.
10024           </p>
10025
10026           <p>
10027             If several binary packages are generated from the same
10028             source tree it is usual to use several
10029             <file>debian/tmp<var>something</var></file> directories, for
10030             example <file>tmp-a</file> or <file>tmp-doc</file>.
10031           </p>
10032
10033           <p>
10034             Whatever <file>tmp</file> directories are created and used by
10035             <tt>binary</tt> must of course be removed by the
10036             <tt>clean</tt> target.</p></sect1>
10037       </sect>
10038
10039
10040       <sect id="pkg-sourcearchives"><heading>Source packages as archives
10041         </heading>
10042
10043         <p>
10044           As it exists on the FTP site, a Debian source package
10045           consists of three related files.  You must have the right
10046           versions of all three to be able to use them.
10047         </p>
10048
10049         <p>
10050           <taglist>
10051             <tag>Debian source control file - <tt>.dsc</tt></tag>
10052             <item>
10053                 This file is a control file used by <prgn>dpkg-source</prgn>
10054                 to extract a source package.
10055                 See <ref id="debiansourcecontrolfiles">.
10056             </item>
10057
10058             <tag>
10059               Original source archive -
10060               <file>
10061                 <var>package</var>_<var>upstream-version</var>.orig.tar.gz
10062               </file>
10063             </tag>
10064
10065             <item>
10066               <p>
10067                 This is a compressed (with <tt>gzip -9</tt>)
10068                 <prgn>tar</prgn> file containing the source code from
10069                 the upstream authors of the program.
10070               </p>
10071             </item>
10072
10073             <tag>
10074               Debianisation diff -
10075               <file>
10076                 <var>package</var>_<var>upstream_version-revision</var>.diff.gz
10077               </file>
10078             </tag>
10079             <item>
10080
10081               <p>
10082                 This is a unified context diff (<tt>diff -u</tt>)
10083                 giving the changes which are required to turn the
10084                 original source into the Debian source.  These changes
10085                 may only include editing and creating plain files.
10086                 The permissions of files, the targets of symbolic
10087                 links and the characteristics of special files or
10088                 pipes may not be changed and no files may be removed
10089                 or renamed.
10090               </p>
10091
10092               <p>
10093                 All the directories in the diff must exist, except the
10094                 <file>debian</file> subdirectory of the top of the source
10095                 tree, which will be created by
10096                 <prgn>dpkg-source</prgn> if necessary when unpacking.
10097               </p>
10098
10099               <p>
10100                 The <prgn>dpkg-source</prgn> program will
10101                 automatically make the <file>debian/rules</file> file
10102                 executable (see below).</p></item>
10103           </taglist>
10104         </p>
10105
10106         <p>
10107           If there is no original source code - for example, if the
10108           package is specially prepared for Debian or the Debian
10109           maintainer is the same as the upstream maintainer - the
10110           format is slightly different: then there is no diff, and the
10111           tarfile is named
10112           <file><var>package</var>_<var>version</var>.tar.gz</file>,
10113           and preferably contains a directory named
10114           <file><var>package</var>-<var>version</var></file>.
10115         </p>
10116       </sect>
10117
10118       <sect>
10119         <heading>Unpacking a Debian source package without <prgn>dpkg-source</prgn></heading>
10120
10121         <p>
10122           <tt>dpkg-source -x</tt> is the recommended way to unpack a
10123           Debian source package.  However, if it is not available it
10124           is possible to unpack a Debian source archive as follows:
10125         <enumlist compact="compact">
10126           <item>
10127             <p>
10128               Untar the tarfile, which will create a <file>.orig</file>
10129               directory.</p>
10130           </item>
10131           <item>
10132             <p>Rename the <file>.orig</file> directory to
10133               <file><var>package</var>-<var>version</var></file>.</p>
10134           </item>
10135             <item>
10136             <p>
10137               Create the subdirectory <file>debian</file> at the top of
10138               the source tree.</p>
10139           </item>
10140           <item><p>Apply the diff using <tt>patch -p0</tt>.</p>
10141           </item>
10142           <item><p>Untar the tarfile again if you want a copy of the original
10143               source code alongside the Debianised version.</p>
10144           </item>
10145         </enumlist>
10146
10147         <p>
10148           It is not possible to generate a valid Debian source archive
10149           without using <prgn>dpkg-source</prgn>.  In particular,
10150           attempting to use <prgn>diff</prgn> directly to generate the
10151           <file>.diff.gz</file> file will not work.
10152         </p>
10153
10154         <sect1>
10155           <heading>Restrictions on objects in source packages</heading>
10156
10157           <p>
10158             The source package may not contain any hard links
10159             <footnote>
10160                 This is not currently detected when building source
10161                 packages, but only when extracting
10162                 them.
10163             </footnote>
10164             <footnote>
10165                 Hard links may be permitted at some point in the
10166                 future, but would require a fair amount of
10167                 work.
10168             </footnote>, device special files, sockets or setuid or
10169             setgid files.
10170             <footnote>
10171                 Setgid directories are allowed.
10172             </footnote>
10173           </p>
10174
10175           <p>
10176             The source packaging tools manage the changes between the
10177             original and Debianised source using <prgn>diff</prgn> and
10178             <prgn>patch</prgn>.  Turning the original source tree as
10179             included in the <file>.orig.tar.gz</file> into the debianised
10180             source must not involve any changes which cannot be
10181             handled by these tools.  Problematic changes which cause
10182             <prgn>dpkg-source</prgn> to halt with an error when
10183             building the source package are:
10184             <list compact="compact">
10185               <item><p>Adding or removing symbolic links, sockets or pipes.</p>
10186               </item>
10187               <item><p>Changing the targets of symbolic links.</p>
10188               </item>
10189               <item><p>Creating directories, other than <file>debian</file>.</p>
10190               </item>
10191               <item><p>Changes to the contents of binary files.</p></item>
10192             </list> Changes which cause <prgn>dpkg-source</prgn> to
10193             print a warning but continue anyway are:
10194             <list compact="compact">
10195               <item>
10196                 <p>
10197                   Removing files, directories or symlinks.
10198                   <footnote>
10199                       Renaming a file is not treated specially - it is
10200                       seen as the removal of the old file (which
10201                       generates a warning, but is otherwise ignored),
10202                       and the creation of the new one.
10203                   </footnote>
10204                 </p>
10205               </item>
10206               <item>
10207                 <p>
10208                   Changed text files which are missing the usual final
10209                   newline (either in the original or the modified
10210                   source tree).
10211                 </p>
10212               </item>
10213             </list>
10214             Changes which are not represented, but which are not detected by
10215             <prgn>dpkg-source</prgn>, are:
10216             <list compact="compact">
10217               <item><p>Changing the permissions of files (other than
10218                   <file>debian/rules</file>) and directories.</p></item>
10219             </list>
10220           </p>
10221
10222           <p>
10223             The <file>debian</file> directory and <file>debian/rules</file>
10224             are handled specially by <prgn>dpkg-source</prgn> - before
10225             applying the changes it will create the <file>debian</file>
10226             directory, and afterwards it will make
10227             <file>debian/rules</file> world-executable.
10228           </p>
10229         </sect1>
10230       </sect>
10231     </appendix>
10232
10233     <appendix id="pkg-controlfields">
10234       <heading>Control files and their fields (from old Packaging Manual)</heading>
10235
10236       <p>
10237         Many of the tools in the <prgn>dpkg</prgn> suite manipulate
10238         data in a common format, known as control files.  Binary and
10239         source packages have control data as do the <file>.changes</file>
10240         files which control the installation of uploaded files, and
10241         <prgn>dpkg</prgn>'s internal databases are in a similar
10242         format.
10243       </p>
10244
10245       <sect>
10246         <heading>Syntax of control files</heading>
10247
10248         <p>
10249           See <ref id="controlsyntax">.
10250         </p>
10251
10252         <p>
10253           It is important to note that there are several fields which
10254           are optional as far as <prgn>dpkg</prgn> and the related
10255           tools are concerned, but which must appear in every Debian
10256           package, or whose omission may cause problems.
10257         </p>
10258       </sect>
10259
10260       <sect>
10261         <heading>List of fields</heading>
10262
10263         <p>
10264           See <ref id="controlfieldslist">.
10265         </p>
10266
10267         <p>
10268           This section now contains only the fields that didn't belong
10269           to the Policy manual.
10270         </p>
10271
10272         <sect1 id="pkg-f-Filename">
10273           <heading><tt>Filename</tt> and <tt>MSDOS-Filename</tt></heading>
10274
10275           <p>
10276             These fields in <tt>Packages</tt> files give the
10277             filename(s) of (the parts of) a package in the
10278             distribution directories, relative to the root of the
10279             Debian hierarchy.  If the package has been split into
10280             several parts the parts are all listed in order, separated
10281             by spaces.
10282           </p>
10283         </sect1>
10284
10285         <sect1 id="pkg-f-Size">
10286           <heading><tt>Size</tt> and <tt>MD5sum</tt></heading>
10287
10288           <p>
10289             These fields in <file>Packages</file> files give the size (in
10290             bytes, expressed in decimal) and MD5 checksum of the
10291             file(s) which make(s) up a binary package in the
10292             distribution.  If the package is split into several parts
10293             the values for the parts are listed in order, separated by
10294             spaces.
10295           </p>
10296         </sect1>
10297
10298         <sect1 id="pkg-f-Status">
10299           <heading><tt>Status</tt></heading>
10300
10301           <p>
10302             This field in <prgn>dpkg</prgn>'s status file records
10303             whether the user wants a package installed, removed or
10304             left alone, whether it is broken (requiring
10305             re-installation) or not and what its current state on the
10306             system is.  Each of these pieces of information is a
10307             single word.
10308           </p>
10309         </sect1>
10310
10311         <sect1 id="pkg-f-Config-Version">
10312           <heading><tt>Config-Version</tt></heading>
10313
10314           <p>
10315             If a package is not installed or not configured, this
10316             field in <prgn>dpkg</prgn>'s status file records the last
10317             version of the package which was successfully
10318             configured.
10319           </p>
10320         </sect1>
10321
10322         <sect1 id="pkg-f-Conffiles">
10323           <heading><tt>Conffiles</tt></heading>
10324
10325           <p>
10326             This field in <prgn>dpkg</prgn>'s status file contains
10327             information about the automatically-managed configuration
10328             files held by a package.  This field should <em>not</em>
10329             appear anywhere in a package!
10330           </p>
10331         </sect1>
10332
10333         <sect1>
10334           <heading>Obsolete fields</heading>
10335
10336           <p>
10337             These are still recognized by <prgn>dpkg</prgn> but should
10338             not appear anywhere any more.
10339
10340             <taglist compact="compact">
10341
10342               <tag><tt>Revision</tt></tag>
10343               <tag><tt>Package-Revision</tt></tag>
10344               <tag><tt>Package_Revision</tt></tag>
10345               <item>
10346                   The Debian revision part of the package version was
10347                   at one point in a separate control file field.  This
10348                   field went through several names.
10349               </item>
10350
10351               <tag><tt>Recommended</tt></tag>
10352               <item>Old name for <tt>Recommends</tt>.</item>
10353
10354               <tag><tt>Optional</tt></tag>
10355               <item>Old name for <tt>Suggests</tt>.</item>
10356
10357               <tag><tt>Class</tt></tag>
10358               <item>Old name for <tt>Priority</tt>.</item>
10359
10360             </taglist>
10361           </p>
10362         </sect1>
10363       </sect>
10364
10365     </appendix>
10366
10367     <appendix id="pkg-conffiles">
10368       <heading>Configuration file handling (from old Packaging Manual)</heading>
10369
10370       <p>
10371         <prgn>dpkg</prgn> can do a certain amount of automatic
10372         handling of package configuration files.
10373       </p>
10374
10375       <p>
10376         Whether this mechanism is appropriate depends on a number of
10377         factors, but basically there are two approaches to any
10378         particular configuration file.
10379       </p>
10380
10381       <p>
10382         The easy method is to ship a best-effort configuration in the
10383         package, and use <prgn>dpkg</prgn>'s conffile mechanism to
10384         handle updates.  If the user is unlikely to want to edit the
10385         file, but you need them to be able to without losing their
10386         changes, and a new package with a changed version of the file
10387         is only released infrequently, this is a good approach.
10388       </p>
10389
10390       <p>
10391         The hard method is to build the configuration file from
10392         scratch in the <prgn>postinst</prgn> script, and to take the
10393         responsibility for fixing any mistakes made in earlier
10394         versions of the package automatically.  This will be
10395         appropriate if the file is likely to need to be different on
10396         each system.
10397       </p>
10398
10399       <sect><heading>Automatic handling of configuration files by
10400       <prgn>dpkg</prgn>
10401         </heading>
10402
10403         <p>
10404           A package may contain a control area file called
10405           <tt>conffiles</tt>.  This file should be a list of filenames
10406           of configuration files needing automatic handling, separated
10407           by newlines.  The filenames should be absolute pathnames,
10408           and the files referred to should actually exist in the
10409           package.
10410         </p>
10411
10412         <p>
10413           When a package is upgraded <prgn>dpkg</prgn> will process
10414           the configuration files during the configuration stage,
10415           shortly before it runs the package's <prgn>postinst</prgn>
10416           script,
10417         </p>
10418
10419         <p>
10420           For each file it checks to see whether the version of the
10421           file included in the package is the same as the one that was
10422           included in the last version of the package (the one that is
10423           being upgraded from); it also compares the version currently
10424           installed on the system with the one shipped with the last
10425           version.
10426         </p>
10427
10428         <p>
10429           If neither the user nor the package maintainer has changed
10430           the file, it is left alone.  If one or the other has changed
10431           their version, then the changed version is preferred - i.e.,
10432           if the user edits their file, but the package maintainer
10433           doesn't ship a different version, the user's changes will
10434           stay, silently, but if the maintainer ships a new version
10435           and the user hasn't edited it the new version will be
10436           installed (with an informative message).  If both have
10437           changed their version the user is prompted about the problem
10438           and must resolve the differences themselves.
10439         </p>
10440
10441         <p>
10442           The comparisons are done by calculating the MD5 message
10443           digests of the files, and storing the MD5 of the file as it
10444           was included in the most recent version of the package.
10445         </p>
10446
10447         <p>
10448           When a package is installed for the first time
10449           <prgn>dpkg</prgn> will install the file that comes with it,
10450           unless that would mean overwriting a file already on the
10451           file system.
10452         </p>
10453
10454         <p>
10455           However, note that <prgn>dpkg</prgn> will <em>not</em>
10456           replace a conffile that was removed by the user (or by a
10457           script).  This is necessary because with some programs a
10458           missing file produces an effect hard or impossible to
10459           achieve in another way, so that a missing file needs to be
10460           kept that way if the user did it.
10461         </p>
10462
10463         <p>
10464           Note that a package should <em>not</em> modify a
10465           <prgn>dpkg</prgn>-handled conffile in its maintainer
10466           scripts.  Doing this will lead to <prgn>dpkg</prgn> giving
10467           the user confusing and possibly dangerous options for
10468           conffile update when the package is upgraded.</p>
10469       </sect>
10470
10471       <sect><heading>Fully-featured maintainer script configuration
10472       handling
10473         </heading>
10474
10475         <p>
10476           For files which contain site-specific information such as
10477           the hostname and networking details and so forth, it is
10478           better to create the file in the package's
10479           <prgn>postinst</prgn> script.
10480         </p>
10481
10482         <p>
10483           This will typically involve examining the state of the rest
10484           of the system to determine values and other information, and
10485           may involve prompting the user for some information which
10486           can't be obtained some other way.
10487         </p>
10488
10489         <p>
10490           When using this method there are a couple of important
10491           issues which should be considered:
10492         </p>
10493
10494         <p>
10495           If you discover a bug in the program which generates the
10496           configuration file, or if the format of the file changes
10497           from one version to the next, you will have to arrange for
10498           the postinst script to do something sensible - usually this
10499           will mean editing the installed configuration file to remove
10500           the problem or change the syntax.  You will have to do this
10501           very carefully, since the user may have changed the file,
10502           perhaps to fix the very problem that your script is trying
10503           to deal with - you will have to detect these situations and
10504           deal with them correctly.
10505         </p>
10506
10507         <p>
10508           If you do go down this route it's probably a good idea to
10509           make the program that generates the configuration file(s) a
10510           separate program in <file>/usr/sbin</file>, by convention called
10511           <file><var>package</var>config</file> and then run that if
10512           appropriate from the post-installation script.  The
10513           <tt><var>package</var>config</tt> program should not
10514           unquestioningly overwrite an existing configuration - if its
10515           mode of operation is geared towards setting up a package for
10516           the first time (rather than any arbitrary reconfiguration
10517           later) you should have it check whether the configuration
10518           already exists, and require a <tt>--force</tt> flag to
10519           overwrite it.</p></sect>
10520     </appendix>
10521
10522     <appendix id="pkg-alternatives"><heading>Alternative versions of
10523         an interface - <prgn>update-alternatives</prgn> (from old
10524     Packaging Manual)
10525       </heading>
10526
10527       <p>
10528         When several packages all provide different versions of the
10529         same program or file it is useful to have the system select a
10530         default, but to allow the system administrator to change it
10531         and have their decisions respected.
10532       </p>
10533
10534       <p>
10535         For example, there are several versions of the <prgn>vi</prgn>
10536         editor, and there is no reason to prevent all of them from
10537         being installed at once, each under their own name
10538         (<prgn>nvi</prgn>, <prgn>vim</prgn> or whatever).
10539         Nevertheless it is desirable to have the name <tt>vi</tt>
10540         refer to something, at least by default.
10541       </p>
10542
10543       <p>
10544         If all the packages involved cooperate, this can be done with
10545         <prgn>update-alternatives</prgn>.
10546       </p>
10547
10548       <p>
10549         Each package provides its own version under its own name, and
10550         calls <prgn>update-alternatives</prgn> in its postinst to
10551         register its version (and again in its prerm to deregister
10552         it).
10553       </p>
10554
10555       <p>
10556         See the man page <manref name="update-alternatives"
10557         section="8"> for details.
10558       </p>
10559
10560       <p>
10561         If <prgn>update-alternatives</prgn> does not seem appropriate
10562         you may wish to consider using diversions instead.</p>
10563     </appendix>
10564
10565     <appendix id="pkg-diversions"><heading>Diversions - overriding a
10566     package's version of a file (from old Packaging Manual)
10567       </heading>
10568
10569       <p>
10570         It is possible to have <prgn>dpkg</prgn> not overwrite a file
10571         when it reinstalls the package it belongs to, and to have it
10572         put the file from the package somewhere else instead.
10573       </p>
10574
10575       <p>
10576         This can be used locally to override a package's version of a
10577         file, or by one package to override another's version (or
10578         provide a wrapper for it).
10579       </p>
10580
10581       <p>
10582         Before deciding to use a diversion, read <ref
10583         id="pkg-alternatives"> to see if you really want a diversion
10584         rather than several alternative versions of a program.
10585       </p>
10586
10587       <p>
10588         There is a diversion list, which is read by <prgn>dpkg</prgn>,
10589         and updated by a special program <prgn>dpkg-divert</prgn>.
10590         Please see <manref name="dpkg-divert" section="8"> for full
10591         details of its operation.
10592       </p>
10593
10594       <p>
10595         When a package wishes to divert a file from another, it should
10596         call <prgn>dpkg-divert</prgn> in its preinst to add the
10597         diversion and rename the existing file.  For example,
10598         supposing that a <prgn>smailwrapper</prgn> package wishes to
10599         install a wrapper around <file>/usr/sbin/smail</file>:
10600         <example>
10601    dpkg-divert --package smailwrapper --add --rename \
10602       --divert /usr/sbin/smail.real /usr/sbin/smail
10603         </example> The <tt>--package smailwrapper</tt> ensures that
10604         <prgn>smailwrapper</prgn>'s copy of <file>/usr/sbin/smail</file>
10605         can bypass the diversion and get installed as the true version.
10606         It's safe to add the diversion unconditionally on upgrades since
10607         it will be left unchanged if it already exists, but
10608         <prgn>dpkg-divert</prgn> will display a message.  To suppress that
10609         message, make the command conditional on the version from which
10610         the package is being upgraded:
10611         <example>
10612    if [ upgrade != "$1" ] || dpkg --compare-versions "$2" lt 1.0-2; then
10613       dpkg-divert --package smailwrapper --add --rename \
10614          --divert /usr/sbin/smail.real /usr/sbin/smail
10615    fi
10616         </example> where <tt>1.0-2</tt> is the version at which the
10617         diversion was first added to the package.  Running the command
10618         during abort-upgrade is pointless but harmless.
10619       </p>
10620
10621       <p>
10622         The postrm has to do the reverse:
10623         <example>
10624   if [ remove = "$1" -o abort-install = "$1" -o disappear = "$1" ]; then
10625      dpkg-divert --package smailwrapper --remove --rename \
10626         --divert /usr/sbin/smail.real /usr/sbin/smail
10627   fi
10628         </example> If the diversion was added at a particular version, the
10629         postrm should also handle the failure case of upgrading from an
10630         older version (unless the older version is so old that direct
10631         upgrades are no longer supported):
10632         <example>
10633   if [ abort-upgrade = "$1" ] && dpkg --compare-versions "$2" lt 1.0-2; then
10634      dpkg-divert --package smailwrapper --remove --rename \
10635         --divert /usr/sbin/smail.real /usr/sbin/smail
10636   fi
10637         </example> where <tt>1.02-2</tt> is the version at which the
10638         diversion was first added to the package.  The postrm should not
10639         remove the diversion on upgrades both because there's no reason to
10640         remove the diversion only to immediately re-add it and since the
10641         postrm of the old package is run after unpacking so the removal of
10642         the diversion will fail.
10643       </p>
10644
10645       <p>
10646         Do not attempt to divert a file which is vitally important for
10647         the system's operation - when using <prgn>dpkg-divert</prgn>
10648         there is a time, after it has been diverted but before
10649         <prgn>dpkg</prgn> has installed the new version, when the file
10650         does not exist.</p>
10651     </appendix>
10652
10653   </book>
10654 </debiandoc>
10655 <!-- Local variables: -->
10656 <!-- indent-tabs-mode: t -->
10657 <!-- End: -->
10658 <!-- vim:set ai et sts=2 sw=2 tw=76: -->