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