]> git.donarmstrong.com Git - debian/debian-policy.git/blob - policy.sgml
* Typos in various documents
[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   Debian GNU/Linux Policy Manual.
9   Copyright (C)1996,1997,1998 Ian Jackson and Christian Schwarz;
10   released under the terms of the GNU
11   General Public License, version 2 or (at your option) any later.
12   Initial version 1996, Ian Jackson, ijackson@gnu.ai.mit.edu
13   Revised November 27, 1996, David A. Morris, bweaver@debian.org
14   New sections March 15, 1997, Christian Schwarz, schwarz@debian.org
15   Reworked/Restructured April-July 1997, Christian Schwarz, schwarz@debian.org
16   Maintainer since 1997, Christian Schwarz, schwarz@debian.org
17   Christoph Lameter contributed the "Web Standard"
18   The debian-policy mailing list has taken responsibility for the
19   contents of this document since September 1998, with the package
20   maintainers responsible for packaging administrivia only.
21   -->
22
23   <book>
24     <titlepag>
25       <title>Debian Policy Manual</title>
26       <author>
27         <name>Ian Jackson </name>
28         <email>ijackson@gnu.ai.mit.edu</email>
29       </author>
30       <author>
31         <name>Christian Schwarz</name>
32         <email>schwarz@debian.org</email>
33       </author>
34       <author>
35         <name>revised: David A. Morris</name>
36         <email>bweaver@debian.org</email>
37       </author>
38       <author>
39         <name>The Debian Policy mailing List</name>
40         <email>debian-policy@lists.debian.org</email>
41       </author>
42       <version>version &version;, &date;</version>
43
44       <abstract>
45         This manual describes the policy requirements for the Debian
46         GNU/Linux distribution. This includes the structure and
47         contents of the Debian archive and several design issues of the
48         operating system, as well as technical requirements that each
49         package must satisfy to be included in the distribution. The
50         policy package itself is maintained by a group of maintainers
51         that have no editorial powers. At the moment, the list of
52         maintainers is:
53         <enumlist>
54           <item>
55             <p>Michael Alan Dorman <email>mdorman@debian.org</email></p>
56           </item>
57           <item>
58             <p>Philip Hands <email>phil@hands.com</email></p>
59           </item>
60           <item>
61             <p>Julian Gilbey <email>jdg@debian.org</email></p>
62           </item>
63           <item>
64             <p>Manoj Srivastava <email>srivasta@debian.org</email></p>
65           </item>
66         </enumlist>
67       </abstract>
68
69
70       <copyright>
71         <copyrightsummary>
72           Copyright &copy;1996,1997,1998 Ian Jackson
73           and Christian Schwarz.
74         </copyrightsummary>
75         <p>
76           This manual is free software; you may redistribute it and/or
77           modify it under the terms of the GNU General Public License
78           as published by the Free Software Foundation; either version
79           2, or (at your option) any later version.
80         </p>
81
82         <p>
83           This is distributed in the hope that it will be useful, but
84           <em>without any warranty</em>; without even the implied
85           warranty of merchantability or fitness for a particular
86           purpose.  See the GNU General Public License for more
87           details.
88         </p>
89
90         <p>
91           A copy of the GNU General Public License is available as
92           <tt>/usr/share/common-licenses/GPL</tt> in the Debian GNU/Linux
93           distribution or on the World Wide Web at
94           <url id="http://www.gnu.org/copyleft/gpl.html"
95                name="The GNU General Public Licence">. You can also obtain it by writing to the
96           Free Software Foundation, Inc., 59 Temple Place - Suite 330,
97           Boston, MA 02111-1307, USA.
98         </p>
99       </copyright>
100     </titlepag>
101
102     <toc detail="sect">
103
104     <chapt id="scope">
105       <heading>About this manual</heading>
106       <sect>
107         <heading>Scope</heading>
108         <p>
109           This manual describes the policy requirements for the Debian
110           GNU/Linux distribution. This includes the structure and
111           contents of the Debian archive and several design issues of the
112           operating system, as well as technical requirements that
113           each package must satisfy to be included in the
114           distribution.
115         </p>
116
117
118         <p>
119           This manual also describes Debian policy as it relates to
120           creating Debian packages. It is not a tutorial on how to build
121           packages, nor is it exhaustive where it comes to describing
122           the behavior of the packaging system. Instead, this manual
123           attempts to define the interface to the package management
124           system that the developers have to be conversant with.
125           <footnote>
126             <p>
127               Informally, the criteria used for inclusion is that the
128               material meet one of the following requirements:
129               <taglist>
130                 <tag>Standard interfaces</tag>
131                 <item>
132                   <p>
133                     The material presented represents an interface to
134                     the packaging system that is mandated for use, and
135                     is used by, a significant number of packages, and
136                     therefore should not be changed without peer
137                     review. Package maintainers can then rely on this
138                     interfaces not changing, and the package
139                     management software authors need to ensure
140                     compatibility with these interface
141                     definitions. (Control file and and changelog file
142                     formats are examples.)
143                   </p>
144                 </item>
145                 <tag>Chosen Convention</tag>
146                 <item>
147                   <p>
148                     If there are a number of technically viable choices
149                     that can be made, but one needs to select one of
150                     these options for inter-operability. The version
151                     number format is one example.
152                   </p>
153                 </item>
154               </taglist>
155               Please note that these are not mutually exclusive;
156               selected conventions often become parts of standard
157               interfaces.
158             </p>
159           </footnote>
160         </p>
161
162         <p>
163           The footnotes present in this manual are
164           merely informative, and are not part of Debian policy itself.
165         </p>
166
167
168         <p>
169           In this manual, the words <em>must</em>, <em>should</em> and
170           <em>may</em>, and the adjectives <em>required</em>,
171           <em>recommended</em> and <em>optional</em>, are used to
172           distinguish the significance of the various guidelines in
173           this policy document. Packages that do not conform the the
174           guidelines denoted by <em>must</em> (or <em>required</em>)
175           will generally not be considered acceptable for the Debian
176           distribution. Non-conformance with guidelines denoted by
177           <em>should</em> (or <em>recommended</em>) will generally be
178           considered a bug, but will not necessarily render a package
179           unsuitable for distribution. Guidelines denoted by
180           <em>may</em> (or <em>optional</em>) are truly optional and
181           adherence is left to the maintainer's discretion.
182         </p>
183         <p>
184           These classifications are roughly equivalent to the bug
185           severities <em>serious</em> (for <em>must</em> or
186           <em>required</em> directive violations), <em>minor</em>,
187           <em>normal</em> or <em>important</em>
188           (for <em>should</em> or <em>recommended</em> directive
189           violations) and <em>wishlist</em> (for <em>optional</em>
190           items). <footnote>
191             <p>Compare RFC 2119.  Note, however, that these words are
192           used in a different way in this document.</p>
193           </footnote>
194         </p>
195         <p>
196           Much of the information presented in this manual will be
197           useful even when building a package which is to be
198           distributed in some other way or is intended for local use
199           only.
200         </p>
201       </sect>
202       <sect>
203         <heading>New versions of this document</heading>
204         <p>
205           The current version of this document is always accessible
206           from the Debian FTP server <ftpsite>ftp.debian.org</ftpsite>
207           as
208           <ftppath>/debian/doc/package-developer/policy.txt.gz</ftppath>
209           (also available from the same directory are several other
210           formats: <tt>policy.html.tar.gz</tt>, <tt>policy.pdf.gz</tt>
211           and <tt>policy.ps.gz</tt>) or from the <url
212           id="http://www.debian.org/doc/debian-policy/" name="Debian
213           Policy Manual"> webpage.</p>
214
215         <p>
216           In addition, this manual is distributed via the Debian package
217           <tt>debian-policy</tt>.
218         </p>
219
220         <p>
221           The <tt>debian-policy</tt> package also includes the file
222           <tt>upgrading-checklist.txt</tt> which indicates policy
223           changes between versions of this document.
224         </p>
225       </sect>
226       <sect>
227         <heading>Feedback</heading>
228
229         <p>
230           As the Debian GNU/Linux system is continuously evolving this
231           manual does so too.
232         </p>
233         <p>
234           While the authors of this document have tried hard to avoid
235           typos and other errors, these do still occur. If you discover
236           an error in this manual or if you want to give any
237           comments, suggestions, or criticisms please send an email to
238           the Debian Policy List,
239           <email>debian-policy@lists.debian.org</email>, or submit a
240           bug report against the <tt>debian-policy</tt> package.
241         </p>
242       </sect>
243     </chapt>
244     <chapt>
245       <heading>The Debian Archive</heading>
246       <p>
247         The Debian GNU/Linux system is maintained and distributed as a
248         collection of <em>packages</em>. Since there are so many of
249         them (currently well over 6000), they are split into
250         <em>sections</em> and given <em>priorities</em> to simplify
251         the handling of them.
252       </p>
253       <p>
254         The effort of the Debian project is to build a free operating
255         system, but not every package we want to make accessible is
256         <em>free</em> in our sense (see the Debian Free Software
257         Guidelines, below), or may be imported/exported without
258         restrictions. Thus, the archive is split into the sections
259         <em>main</em>, <em>non-free</em>, <em>contrib</em>,
260         <em>non-US/main</em>, <em>non-US/non-free</em>, and
261         <em>non-US/contrib</em>.  The sections are explained in detail
262         below.
263       </p>
264
265       <p>
266         The <em>main</em> and the <em>non-US/main</em> sections
267         together form the <em>Debian GNU/Linux distribution</em>.
268       </p>
269
270       <p>
271         Packages in the other sections are not considered to be part
272         of the Debian distribution, although we support their use and
273         provide infrastructure for them (such as our bug-tracking
274         system and mailing lists). This Debian Policy Manual applies
275         to these packages as well.</p>
276
277       <sect id="pkgcopyright">
278         <heading>Package copyright and sections</heading>
279         <p>
280           The aims of this section are:
281
282           <list compact="compact">
283             <item>
284               <p>to allow us to make as much software available as we
285                 can,</p>
286             </item>
287             <item>
288               <p>to allow us to encourage everyone to write free
289               software, and</p>
290             </item>
291             <item>
292               <p>to allow us to make it easy for people to produce
293                 CD-ROMs of our system without violating any licenses,
294                 import/export restrictions, or any other laws.</p>
295             </item>
296           </list>
297         </p>
298         <sect1>
299           <heading>The Debian Free Software Guidelines</heading>
300           <p>
301             The Debian Free Software Guidelines (DFSG) form our
302             definition of `free software'.  These are:
303             <taglist>
304               <tag>Free Redistribution
305               </tag>
306               <item>
307                 <p>
308                   The license of a Debian component may not restrict any
309                   party from selling or giving away the software as a
310                   component of an aggregate software distribution
311                   containing programs from several different
312                   sources. The license may not require a royalty or
313                   other fee for such sale.
314                 </p>
315               </item>
316               <tag>Source Code
317               </tag>
318               <item>
319                 <p>
320                   The program must include source code, and must allow
321                   distribution in source code as well as compiled form.
322                 </p>
323               </item>
324               <tag>Derived Works
325               </tag>
326               <item>
327                 <p>
328                   The license must allow modifications and derived
329                   works, and must allow them to be distributed under the
330                   same terms as the license of the original software.
331                 </p>
332               </item>
333               <tag>Integrity of The Author's Source Code
334               </tag>
335               <item>
336                 <p>
337                   The license may restrict source-code from being
338                   distributed in modified form <em>only</em> if the
339                   license allows the distribution of ``patch files''
340                   with the source code for the purpose of modifying the
341                   program at build time. The license must explicitly
342                   permit distribution of software built from modified
343                   source code. The license may require derived works to
344                   carry a different name or version number from the
345                   original software.  (This is a compromise. The Debian
346                   Project encourages all authors to not restrict any
347                   files, source or binary, from being modified.)
348                 </p>
349               </item>
350               <tag>No Discrimination Against Persons or Groups
351               </tag>
352               <item>
353                 <p>
354                   The license must not discriminate against any person
355                   or group of persons.
356                 </p>
357               </item>
358               <tag>No Discrimination Against Fields of Endeavor
359               </tag>
360               <item>
361                 <p>
362                   The license must not restrict anyone from making use
363                   of the program in a specific field of endeavor. For
364                   example, it may not restrict the program from being
365                   used in a business, or from being used for genetic
366                   research.
367                 </p>
368               </item>
369               <tag>Distribution of License
370               </tag>
371               <item>
372                 <p>
373                   The rights attached to the program must apply to all
374                   to whom the program is redistributed without the need
375                   for execution of an additional license by those
376                   parties.
377                 </p>
378               </item>
379               <tag>License Must Not Be Specific to Debian
380               </tag>
381               <item>
382                 <p>
383                   The rights attached to the program must not depend on
384                   the program's being part of a Debian system. If the
385                   program is extracted from Debian and used or
386                   distributed without Debian but otherwise within the
387                   terms of the program's license, all parties to whom
388                   the program is redistributed must have the same
389                   rights as those that are granted in conjunction with
390                   the Debian system.
391                 </p>
392               </item>
393               <tag>License Must Not Contaminate Other Software
394               </tag>
395               <item>
396                 <p>
397                   The license must not place restrictions on other
398                   software that is distributed along with the licensed
399                   software. For example, the license must not insist
400                   that all other programs distributed on the same medium
401                   must be free software.
402                 </p>
403               </item>
404               <tag>Example Licenses
405               </tag>
406               <item>
407                 <p>
408                   The ``GPL,'' ``BSD,'' and ``Artistic'' licenses are
409                   examples of licenses that we consider <em>free</em>.
410                 </p>
411               </item>
412             </taglist>
413           </p>
414         </sect1>
415         <sect1>
416           <heading>The main section</heading>
417           <p>
418             Every package in <em>main</em> and <em>non-US/main</em>
419             must comply with the DFSG (Debian Free Software
420             Guidelines).</p>
421
422           <p>
423             In addition, the packages in <em>main</em>
424             <list compact="compact">
425               <item>
426                 <p>
427                   must not require a package outside of <em>main</em>
428                   for compilation or execution (thus, the package must
429                   not declare a "Depends", "Recommends", or
430                   "Build-Depends" relationship on a non-<em>main</em>
431                   package),
432                 </p>
433               </item>
434               <item>
435                 <p>
436                   must not be so buggy that we refuse to support them,
437                   and
438                 </p>
439               </item>
440               <item>
441                 <p>
442                   must meet all policy requirements presented in this
443                   manual.
444                 </p>
445               </item>
446             </list>
447           </p>
448           <p>
449             Similarly, the packages in <em>non-US/main</em>
450             <list compact="compact">
451               <item>
452                 <p>
453                    must not require a package outside of <em>main</em>
454                    or <em>non-US/main</em> for compilation or
455                    execution,
456                 </p>
457               </item>
458               <item>
459                 <p>
460                   must not be so buggy that we refuse to support them,
461                 </p>
462               </item>
463               <item>
464                 <p>
465                   must meet all policy requirements presented in this
466                   manual.
467                 </p>
468               </item>
469             </list>
470           </p>
471         </sect1>
472         <sect1>
473           <heading>The contrib section</heading>
474           <p>
475             Every package in <em>contrib</em> and
476             <em>non-US/contrib</em> must comply with the DFSG.
477           </p>
478
479           <p>
480             In addition, the packages in <em>contrib</em> and
481             <em>non-US/contrib</em>
482             <list compact="compact">
483               <item>
484                 <p>
485                   must not be so buggy that we refuse to support them,
486                   and
487                 </p>
488               </item>
489               <item>
490                 <p>
491                   must meet all policy requirements presented in this
492                   manual.
493                 </p>
494               </item>
495             </list>
496           </p>
497
498           <p>
499             Furthermore, packages in <em>contrib</em> must not require
500             a package in a <em>non-US</em> section for compilation or
501             execution.
502           </p>
503
504           <p>
505             Examples of packages which would be included in
506             <em>contrib</em> or <em>non-US/contrib</em> are:
507             <list compact="compact">
508               <item>
509                 <p>
510                   free packages which require <em>contrib</em>,
511                   <em>non-free</em> packages or packages which are not
512                   in our archive at all for compilation or execution,
513                   and
514                 </p>
515               </item>
516               <item>
517                 <p>
518                   wrapper packages or other sorts of free accessories for
519                   non-free programs.
520                 </p>
521               </item>
522             </list>
523           </p>
524         </sect1>
525         <sect1>
526           <heading>The non-free section</heading>
527           <p>
528             Packages must be placed in <em>non-free</em> or
529             <em>non-US/non-free</em> if they are not compliant with
530             the DFSG or are encumbered by patents or other legal
531             issues that make their distribution problematic.
532           </p>
533           <p>
534             In addition, the packages in <em>non-free</em> and
535             <em>non-US/non-free</em>
536             <list compact="compact">
537               <item>
538                 <p>
539                   must not be so buggy that we refuse to support them,
540                   and
541                 </p>
542               </item>
543               <item>
544                 <p>
545                   must meet all policy requirements presented in this
546                   manual that it is possible for them to meet.
547                   <footnote>
548                     <p>
549                       It is possible that there are policy
550                       requirements which the package is unable to
551                       meet, for example, if the source is
552                       unavailable.  These situations will need to be
553                       handled on a case-by-case basis.
554                     </p>
555                   </footnote>
556                 </p>
557               </item>
558             </list>
559           </p>
560         </sect1>
561
562         <sect1>
563           <heading>The non-US sections</heading>
564           <p>
565             Some programs with cryptographic program code need to be
566             stored on the <em>non-US</em> server because of United
567             States export restrictions.  Such programs must be
568             distributed in the appropriate <em>non-US</em> section,
569             either <em>non-US/main</em>, <em>non-US/contrib</em> or
570             <em>non-US/non-free</em>.
571           </p>
572           <p>
573             This applies only to packages which contain cryptographic
574             code. A package containing a program with an interface to
575             a cryptographic program or a program that's dynamically
576             linked against a cryptographic library should not be
577             distributed via the <em>non-US</em> server if it is
578             capable of running without the cryptographic library or
579             program.
580           </p>
581         </sect1>
582         <sect1>
583           <heading>Further copyright considerations</heading>
584           <p>
585             Every package must be accompanied by a verbatim copy of
586             its copyright and distribution license in the file
587             <tt>/usr/share/doc/<ital>&lt;package-name&gt;</ital>/copyright</tt>
588             (see <ref id="copyrightfile"> for further details).
589           </p>
590           <p>
591             We reserve the right to restrict files from being included
592             anywhere in our archives if
593             <list compact="compact">
594               <item>
595                 <p>
596                   their use or distribution would break a law,
597                 </p>
598               </item>
599               <item>
600                 <p>
601                   there is an ethical conflict in their distribution or
602                   use,
603                 </p>
604               </item>
605               <item>
606                 <p>
607                   we would have to sign a license for them, or
608                 </p>
609               </item>
610               <item>
611                 <p>
612                   their distribution would conflict with other project
613                   policies.
614                 </p>
615               </item>
616             </list>
617           </p>
618
619           <p>
620             Programs whose authors encourage the user to make
621             donations are fine for the main distribution, provided
622             that the authors do not claim that not donating is
623             immoral, unethical, illegal or something similar; in such
624             a case they must go in <em>non-free</em>.</p>
625
626           <p>
627             Packages whose copyright permission notices (or patent
628             problems) do not even allow redistribution of binaries
629             only, and where no special permission has been obtained,
630             must not be placed on the Debian FTP site and its mirrors
631             at all.</p>
632
633           <p>
634             Note that under international copyright law (this applies
635             in the United States, too), <em>no</em> distribution or
636             modification of a work is allowed without an explicit
637             notice saying so.  Therefore a program without a copyright
638             notice <em>is</em> copyrighted and you may not do anything
639             to it without risking being sued! Likewise if a program
640             has a copyright notice but no statement saying what is
641             permitted then nothing is permitted.</p>
642
643           <p>
644             Many authors are unaware of the problems that restrictive
645             copyrights (or lack of copyright notices) can cause for
646             the users of their supposedly-free software.  It is often
647             worthwhile contacting such authors diplomatically to ask
648             them to modify their license terms. However, this can be a
649             politically difficult thing to do and you should ask for
650             advice on the <tt>debian-legal</tt> mailing list first, as
651             explained below.
652           </p>
653
654           <p>
655             When in doubt about a copyright, send mail to
656             <email>debian-legal@lists.debian.org</email>.  Be prepared
657             to provide us with the copyright statement.  Software
658             covered by the GPL, public domain software and BSD-like
659             copyrights are safe; be wary of the phrases `commercial
660             use prohibited' and `distribution restricted'.
661           </p>
662         </sect1>
663         <sect1>
664           <heading>Subsections</heading>
665
666           <p>
667             The packages in the sections <em>main</em>,
668             <em>contrib</em> and <em>non-free</em> are grouped further
669             into <em>subsections</em> to simplify handling.
670           </p>
671
672           <p>
673             The section and subsection for each package should be
674             specified in the package's <tt>Section</tt> control
675             record.  However, the maintainer of the Debian archive
676             may override this selection to ensure the consistency of
677             the Debian distribution.  The <tt>Section</tt> field
678             should be of the form:
679             <list compact="compact">
680               <item>
681                 <p>
682                   <ital>subsection</ital> if the package is in the
683                   <em>main</em> section,
684                 </p>
685               </item>
686               <item>
687                 <p>
688                   <ital>section/subsection</ital> if the package is in
689                   the <em>contrib</em> or <em>non-free</em> section,
690                   and
691                 </p>
692               </item>
693               <item>
694                 <p>
695                   <tt>non-US</tt>, <tt>non-US/contrib</tt> or
696                   <tt>non-US/non-free</tt> if the package is in
697                   <em>non-US/main</em>, <em>non-US/contrib</em> or
698                   <em>non-US/non-free</em> respectively.
699                 </p>
700               </item>
701             </list>
702           </p>
703
704           <p>
705             The Debian archive maintainers provide the authoritative
706             list of subsections.  At present, they are:
707             <em>admin</em>, <em>base</em>, <em>comm</em>,
708             <em>contrib</em>, <em>devel</em>, <em>doc</em>,
709             <em>editors</em>, <em>electronics</em>, <em>games</em>,
710             <em>graphics</em>, <em>hamradio</em>,
711             <em>interpreters</em>, <em>libs</em>, <em>mail</em>,
712             <em>math</em>, <em>misc</em>, <em>net</em>, <em>news</em>,
713             <em>non-US</em>, <em>non-free</em>, <em>oldlibs</em>,
714             <em>otherosfs</em>, <em>science</em>, <em>shells</em>,
715             <em>sound</em>, <em>tex</em>, <em>text</em>,
716             <em>utils</em>, <em>web</em>, <em>x11</em>.
717           </p>
718         </sect1>
719       <sect>
720         <heading>Priorities</heading>
721
722         <p>
723           Each package should have a <em>priority</em> value, which is
724           included in the package's <em>control record</em>. This
725           information is used by the Debian package management tools
726           to separate high-priority packages from less-important
727           packages.</p>
728
729         <p>
730           The following <em>priority levels</em> are recognised by the
731           Debian package management tools.
732           <taglist>
733             <tag><tt>required</tt></tag>
734             <item>
735               <p>
736                 Packages which are necessary for the proper
737                 functioning of the system.  You must not remove these
738                 packages or your system may become totally broken and
739                 you may not even be able to use <prgn>dpkg</prgn> to
740                 put things back.  Systems with only the
741                 <tt>required</tt> packages are probably unusable, but
742                 they do have enough functionality to allow the
743                 sysadmin to boot and install more software.</p>
744             </item>
745             <tag><tt>important</tt></tag>
746             <item>
747               <p>
748                 Important programs, including those which one would
749                 expect to find on any Unix-like system.  If the
750                 expectation is that an experienced Unix person who
751                 found it missing would say `What on earth is going on,
752                 where is <prgn>foo</prgn>?', it must be an
753                 <tt>important</tt> package.
754                 <footnote>
755                   <p>
756                     This is an important criterion because we are
757                     trying to produce, amongst other things, a free
758                     Unix.
759                   </p>
760                 </footnote>
761                 Other packages without which the system will not run
762                 well or be usable must also have priority
763                 <tt>important</tt>.  This does
764                 <em>not</em> include Emacs, the X Window System, TeX
765                 or any other large applications.  The
766                 <tt>important</tt> packages are just a bare minimum of
767                 commonly-expected and necessary tools.</p>
768             </item>
769             <tag><tt>standard</tt></tag>
770             <item>
771               <p>
772                 These packages provide a reasonably small but not too
773                 limited character-mode system.  This is what will
774                 install by default if the user doesn't select anything
775                 else.  It doesn't include many large applications, but
776                 it does include Emacs (this is more of a piece of
777                 infrastructure than an application) and a reasonable
778                 subset of TeX and LaTeX.</p>
779             </item>
780             <tag><tt>optional</tt></tag>
781             <item>
782               <p>
783                 (In a sense everything that isn't required is
784                 optional, but that's not what is meant here.) This is
785                 all the software that you might reasonably want to
786                 install if you didn't know what it was and don't have
787                 specialized requirements. This is a much larger system
788                 and includes the X Window System, a full TeX
789                 distribution, and many applications. Note that
790                 optional packages should not conflict with each other.
791               </p>
792             </item>
793             <tag><tt>extra</tt></tag>
794             <item>
795               <p>
796                 This contains all packages that conflict with others
797                 with required, important, standard or optional
798                 priorities, or are only likely to be useful if you
799                 already know what they are or have specialised
800                 requirements.
801               </p>
802             </item>
803           </taglist></p>
804
805         <p>
806           Packages must not depend on packages with lower priority
807           values (excluding build-time dependencies).  In order to
808           ensure this, the priorities of one or more packages may need
809           to be adjusted.
810         </p>
811       </sect>
812
813       <sect>
814         <heading>Binary packages</heading>
815
816         <p>
817           The Debian GNU/Linux distribution is based on the Debian
818           package management system, called <prgn>dpkg</prgn>. Thus,
819           all packages in the Debian distribution must be provided
820           in the <tt>.deb</tt> file format.</p>
821
822
823         <sect1>
824           <heading>The package name</heading>
825
826           <p>
827             Every package must have a name that's unique within the Debian
828             archive.</p>
829
830           <p>
831             Package names must consist of lower case letters (a-z),
832             digits (0-9), plus (+) and minus (-) signs, and periods
833             (.).  They must be at least two characters long and must
834             contain at least one letter.
835           </p>
836
837           <p>
838             The package name is part of the file name of the
839             <tt>.deb</tt> file and is included in the control field
840             information.
841           </p>
842         </sect1>
843
844         <sect1>
845           <heading>The maintainer of a package</heading>
846          <p>
847             Every package must have a Debian maintainer (the
848             maintainer may be one person or a group of people
849             reachable from a common email address, such as a mailing
850             list).  The maintainer is responsible for ensuring that
851             the package is placed in the appropriate distributions.
852           </p>
853
854           <p>
855             The maintainer must be specified in the
856             <tt>Maintainer</tt> control field with their correct name
857             and a working email address.  If one person maintains
858             several packages, he/she should try to avoid having
859             different forms of their name and email address in
860             the <tt>Maintainer</tt> fields of those packages.
861           </p>
862
863           <p>
864             If the maintainer of a package quits from the Debian
865             project, "Debian QA Group"
866             <email>packages@qa.debian.org</email> takes over the
867             maintainership of the package until someone else
868             volunteers for that task. These packages are called
869             <em>orphaned packages</em>.
870             <footnote>
871               <p>
872                 The detailed procedure for doing this gracefully can
873                 be found in the Debian Developer's Reference, either
874                 in the <tt>developers-reference</tt> package, or on
875                 the Debian FTP server
876                 <ftpsite>ftp.debian.org</ftpsite> as
877                 <ftppath>/debian/doc/package-developer/developers-reference.txt.gz</ftppath>
878                 or from the <url
879                 id="http://www.debian.org/doc/packaging-manuals/developers-reference/"
880                 name="Debian Developer's Reference"> webpage.
881               </p>
882             </footnote>
883           </p>
884         </sect1>
885
886
887         <sect1>
888           <heading>The description of a package</heading>
889
890           <p>
891             Every Debian package must have an extended description
892             stored in the appropriate field of the control record.</p>
893
894           <p>
895             The description should be written so that it gives the
896             system administrator enough information to decide whether
897             to install the package. This description should not just
898             be copied verbatim from the program's documentation.
899             Instructions for configuring or using the package should
900             not be included -- that is what installation scripts,
901             manual pages, info files, etc., are for.  Copyright
902             statements and other administrivia should not be included
903             either -- that is what the copyright file is for.</p>
904         </sect1>
905
906
907         <sect1>
908           <heading>Dependencies</heading>
909
910           <p>
911             Every package must specify the dependency information
912             about other packages that are required for the first to
913             work correctly.</p>
914
915           <p>
916             For example, a dependency entry must be provided for any
917             shared libraries required by a dynamically-linked executable
918             binary in a package.</p>
919
920           <p>
921             Packages are not required to declare any dependencies they
922             have on other packages which are marked <tt>Essential</tt>
923             (see below), and should not do so unless they depend on a
924             particular version of that package.</p>
925
926           <p>
927             Sometimes, a package requires another package to be installed
928             <em>and</em> configured before it can be installed. In this
929             case, you must specify a <tt>Pre-Depends</tt> entry for
930             the package.</p>
931
932           <p>
933             You should not specify a <tt>Pre-Depends</tt> entry for a
934             package before this has been discussed on the
935             <tt>debian-devel</tt> mailing list and a consensus about
936             doing that has been reached.</p></sect1>
937
938
939         <sect1>
940           <heading>Virtual packages</heading>
941
942           <p>
943             Sometimes, there are several packages which offer
944             more-or-less the same functionality. In this case, it's
945             useful to define a <em>virtual package</em> whose name
946             describes that common functionality.  (The virtual
947             packages only exist logically, not physically--that's why
948             they are called <em>virtual</em>.) The packages with this
949             particular function will then <em>provide</em> the virtual
950             package. Thus, any other package requiring that function
951             can simply depend on the virtual package without having to
952             specify all possible packages individually.</p>
953
954           <p>
955             All packages should use virtual package names where
956             appropriate, and arrange to create new ones if necessary.
957             They should not use virtual package names (except privately,
958             amongst a cooperating group of packages) unless they have
959             been agreed upon and appear in the list of virtual package
960             names.</p>
961
962           <p>
963             The latest version of the authoritative list of virtual
964             package names can be found on
965             <ftpsite>ftp.debian.org</ftpsite> in
966             <ftppath>/debian/doc/package-developer/virtual-package-names-list.txt</ftppath>
967             or your local mirror. In addition, it is included in the
968             <tt>debian-policy</tt> package. The procedure for updating
969             the list is described at the top of the file.</p></sect1>
970
971
972         <sect1>
973           <heading>Base packages</heading>
974
975           <p>
976             The packages included in the <tt>base</tt> section have a
977             special function. They form a minimum subset of the Debian
978             GNU/Linux system that is installed before everything else
979             on a new system. Thus, only very few packages are allowed
980             to go into the <tt>base</tt> section to keep the required
981             disk usage very small.</p>
982
983           <p>
984             Most of these packages will have the priority value
985             <tt>required</tt> or at least <tt>important</tt>, and many
986             of them will be tagged <tt>essential</tt> (see below).</p>
987
988           <p>
989             You must not place any packages into the <tt>base</tt>
990             section before this has been discussed on the
991             <tt>debian-devel</tt> mailing list and a consensus about
992             doing that has been reached.</p></sect1>
993
994
995         <sect1>
996           <heading>Essential packages</heading>
997
998           <p>
999             Some packages are tagged <tt>essential</tt>. (They have
1000             <tt>Essential: yes</tt> in their package control record.)
1001             This flag is used for packages that are <em>essential</em>
1002             for a system.</p>
1003
1004           <p>
1005             Since these packages cannot be easily removed (one has to
1006             specify an extra <em>force option</em> to
1007             <prgn>dpkg</prgn> to do so), this flag must not be used
1008             unless absolutely necessary.  A shared library package
1009             must not be tagged <tt>essential</tt>--dependencies will
1010             prevent its premature removal, and we need to be able to
1011             remove it when it has been superseded.
1012           </p>
1013
1014           <p>
1015             Since dpkg will not prevent upgrading of other packages
1016             while an <tt>essential</tt> package is in an unconfigured
1017             state, all <tt>essential</tt> packages must supply all of
1018             their core functionality even when unconfigured. If the
1019             package cannot satisfy this requirement it must not be
1020             tagged as essential, and any packages depending on this
1021             package must instead have explicit dependency fields as
1022             appropriate.
1023           </p>
1024
1025           <p>
1026             You must not tag any packages <tt>essential</tt> before
1027             this has been discussed on the <tt>debian-devel</tt>
1028             mailing list and a consensus about doing that has been
1029             reached.
1030           </p>
1031         </sect1>
1032
1033         <sect1>
1034           <heading>Maintainer scripts</heading>
1035
1036           <p>
1037             The package installation scripts should avoid producing
1038             output which it is unnecessary for the user to see and
1039             should rely on <prgn>dpkg</prgn> to stave off boredom on
1040             the part of a user installing many packages.  This means,
1041             amongst other things, using the <tt>--quiet</tt> option on
1042             <prgn>install-info</prgn>.</p>
1043
1044           <p>
1045             Errors which occur during the execution of an installation
1046             script must be checked and the installation must not
1047             continue after an error.
1048           </p>
1049
1050           <p>
1051             Note that in general <ref id="scripts"> applies to package
1052             maintainer scripts, too.
1053           </p>
1054
1055           <p>
1056             You should not use <tt>dpkg-divert</tt> on a file
1057             belonging to another package without consulting the
1058             maintainer of that package first.
1059           </p>
1060           <p>
1061             All packages which supply an instance of a common command
1062             name (or, in general, filename) should generally use
1063             <prgn>update-alternatives</prgn>, so that they may be
1064             installed together.  If <prgn>update-alternatives</prgn>
1065             is not used, then each package must use
1066             <var>Conflicts</var> to ensure that other packages are
1067             de-installed.  (In this case, it may be appropriate to
1068             specify a conflict against earlier versions of something
1069             that previously did not use
1070             <prgn>update-alternatives</prgn> - this is an exception to
1071             the usual rule that versioned conflicts should be
1072             avoided).
1073           </p>
1074
1075
1076           <sect2>
1077             <heading>Prompting in maintainer scripts</heading>
1078             <p>
1079               Package maintainer scripts may prompt the user if
1080               necessary. Prompting may be accomplished by hand, or by
1081               communicating with a program, such as
1082               <prgn>debconf</prgn>, which conforms to the Debian
1083               Configuration management specification, version 2 or
1084               higher.  These are included in the
1085               <file>debconf_specification</file> files in the
1086               <package>debian-policy</package> package.
1087               You may also find this file on the FTP site
1088               <ftpsite>ftp.debian.org</ftpsite> in
1089               <ftppath>/debian/doc/package-developer/debconf_specification.txt.gz</ftppath>
1090               or on your local mirror.
1091               <footnote>
1092                 <p>
1093                   2.5% of Debian packages [see <url
1094                   id="http://kitenet.net/programs/debconf/stats/">]
1095                   currently use <package>debconf</package> to prompt
1096                   the user at install time, and this number is growing
1097                   daily. The benefits of using debconf are briefly
1098                   explained at <url
1099                   id="http://kitenet.net/doc/debconf-doc/introduction.html">;
1100                   they include preconfiguration, (mostly)
1101                   noninteractive installation, elimination of
1102                   redundant prompting, consistency of user interface,
1103                   etc.
1104                 </p>
1105                 <p>
1106                   With this increasing number of packages using
1107                   <package>debconf</package>, plus the existance of a
1108                   nascent second implementation of the Debian
1109                   configuration management system
1110                   (<package>cdebconf</package>), and the stabalization
1111                   of the protocol these things use, the time has
1112                   finally come to reflect the use of these things in
1113                   policy.
1114
1115                 </p>
1116               </footnote>
1117             </p>
1118             <p>
1119               Packages which use the Debian Configuration management
1120               specification may contain an additional
1121               <file>config</file> script and a <file>templates</file>
1122               file in their control archive. The <prgn>config</prgn>
1123               script might be run before the <prgn>preinst</prgn>
1124               script, and before the package is unpacked or any of its
1125               dependancies or pre-dependancies are satisfied.
1126               Therefore it must work using only the tools present in
1127               <em>essential</em> packages.
1128               <footnote>
1129                 <p>
1130                   <package>Debconf</package> or another tool that
1131                   implements the Debian Configuration management
1132                   specification will also be installed, and any
1133                   versioned dependencies on it will be satisfied
1134                   before preconfiguration begins.
1135                 </p>
1136               </footnote>
1137             </p>
1138
1139             <p>
1140               Packages should try to minimize the amount of prompting
1141               they need to do, and they should ensure that the user
1142               will only ever be asked each question once.  This means
1143               that packages should try to use appropriate shared
1144               configuration files (such as <tt>/etc/papersize</tt> and
1145               <tt>/etc/news/server</tt>), and shared
1146               <package>debconf</package> variables rather than each
1147               prompting for their own list of required pieces of
1148               information.
1149             </p>
1150
1151             <p>
1152             It also means that an upgrade should not ask the same
1153             questions again, unless the user has used <tt>dpkg
1154               --purge</tt> to remove the package's configuration.  The
1155             answers to configuration questions should be stored in an
1156             appropriate place in <tt>/etc</tt> so that the user can
1157             modify them, and how this has been done should be
1158             documented.</p>
1159
1160           <p>
1161               If a package has a vitally important piece of
1162               information to pass to the user (such as "don't run me
1163               as I am, you must edit the following configuration files
1164               first or you risk your system emitting badly-formatted
1165               messages"), it should display this in the
1166               <prgn>config</prgn> or <prgn>postinst</prgn> script and
1167               prompt the user to hit return to acknowledge the
1168               message.  Copyright messages do not count as vitally
1169               important (they belong in
1170               <tt>/usr/share/doc/<var>package</var>/copyright</tt>);
1171               neither do instructions on how to use a program (these
1172               should be in on-line documentation, where all the users
1173               can see them).</p>
1174
1175           <p>
1176             Any necessary prompting should almost always be confined
1177             to the <prgn>config</prgn> or <prgn>postinst</prgn>
1178             script. If it is done in the <prgn>postinst</prgn>, it
1179             should be protected with a conditional so that unnecessary
1180             prompting doesn't happen if a package's installation fails
1181             and the <prgn>postinst</prgn> is called with
1182             <tt>abort-upgrade</tt>, <tt>abort-remove</tt> or
1183             <tt>abort-deconfigure</tt>.</p>
1184
1185         </sect1>
1186       </sect>
1187       <sect>
1188         <heading>Source packages</heading>
1189
1190         <sect1>
1191           <heading>Standards conformance</heading>
1192
1193           <p>
1194             In the source package's <tt>Standards-Version</tt> control
1195             field, you must specify the most recent version number of
1196             this policy document with which your package complies.
1197             The current version number is &version;.
1198           </p>
1199
1200           <p>
1201             This information may be used to file bug reports
1202             automatically if your package becomes too much out of
1203             date.
1204           </p>
1205
1206           <p>
1207             The version number has four components--major and minor
1208             version number and major and minor patch level.  When the
1209             standards change in a way that requires every package to
1210             change the major number will be changed.  Significant
1211             changes that will require work in many packages will be
1212             signaled by a change to the minor number.  The major patch
1213             level will be changed for any change to the meaning of the
1214             standards, however small; the minor patch level will be
1215             changed when only cosmetic, typographical or other edits
1216             are made which neither change the meaning of the document
1217             nor affect the contents of packages.</p>
1218
1219           <p>
1220             Thus only the first three components of the policy version
1221             are significant in the <em>Standards-Version</em> control
1222             field, and so either these three components or the all
1223             four components may be specified.
1224             <footnote>
1225               <p>
1226                 In the past, people specified the full version number
1227                 in the Standards-Version field, for example `2.3.0.0'.
1228                 Since minor patch-level changes don't introduce new
1229                 policy, it was thought it would be better to relax
1230                 policy and only require the first 3 components to be
1231                 specified, in this example `2.3.0'.  All four
1232                 components may still be used if someone wishes to do
1233                 so.
1234               </p>
1235             </footnote>
1236           </p>
1237
1238           <p>
1239             You should regularly, and especially if your package has
1240             become out of date, check for the newest Policy Manual
1241             available and update your package, if necessary. When your
1242             package complies with the new standards you should update the
1243             <tt>Standards-Version</tt> source package field and
1244             release it.
1245             <footnote>
1246               <p>
1247                 See the file <tt>upgrading-checklist</tt> for
1248                 information about policy which has changed between
1249                 different versions of this document.
1250               </p>
1251             </footnote>
1252           </p>
1253         </sect1>
1254
1255
1256         <sect1>
1257           <heading>Package relationships</heading>
1258
1259           <p>
1260             Source packages should specify which binary packages they
1261             require to be installed or not to be installed in order to
1262             build correctly.  For example, if building a package
1263             requires a certain compiler, then the compiler should be
1264             specified as a build-time dependency.
1265           </p>
1266
1267           <p>
1268             It is not necessary to explicitly specify build-time
1269             relationships on a minimal set of packages that are always
1270             needed to compile, link and put in a Debian package a
1271             standard "Hello World!" program written in C or C++.  The
1272             required packages are called <em>build-essential</em>, and
1273             an informational list can be found in
1274             <tt>/usr/share/doc/build-essential/list</tt> (which is
1275             contained in the <tt>build-essential</tt>
1276             package).
1277             <footnote>
1278               <p>Rationale:
1279                 <list>
1280                   <item>
1281                     <p>This allows maintaining the list separately
1282                       from the policy documents (the list does not
1283                       need the kind of control that the policy
1284                       documents do).
1285                     </p>
1286                   </item>
1287                   <item>
1288                     <p>
1289                       Having a separate package allows one to install
1290                       the build-essential packages on a machine, as
1291                       well as allowing other packages such as task
1292                       packages to require installation of the
1293                       build-essential packages using the depends
1294                       relation.
1295                     </p>
1296                   </item>
1297                   <item>
1298                     <p>
1299                       The separate package allows bug reports against
1300                       the list to be categorized separately from
1301                       the policy management process in the BTS.
1302                     </p>
1303                   </item>
1304                 </list>
1305               </p>
1306
1307             </footnote>
1308           </p>
1309
1310           <p>
1311             When specifying the set of build-time dependencies, one
1312             should list only those packages explicitly required by the
1313             build.  It is not necessary to list packages which are
1314             required merely because some other package in the list of
1315             build-time dependencies depends on them.
1316             <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 <tt>libimlib</tt>, 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             <tt>debian/rules</tt> 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 <tt>.in</tt> 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></sect1>
1380
1381
1382         <sect1>
1383           <heading>Documenting your changes</heading>
1384
1385           <p>
1386             You should document your changes and updates to the source
1387             package properly in the <tt>debian/changelog</tt> file. (Note
1388             that mistakes in changelogs are usually best rectified by
1389             making a new changelog entry rather than "rewriting history"
1390             by editing old changelog entries.)</p>
1391
1392           <p>
1393             In non-experimental packages you must use a format for
1394             <tt>debian/changelog</tt> which is supported by the most
1395             recent released version of <prgn>dpkg</prgn>.
1396             <footnote>
1397               <p>
1398                 If you wish to use an alternative format, you may do
1399                 so as long as you include a parser for it in your
1400                 source package.  The parser must have an API
1401                 compatible with that expected by
1402                 <prgn>dpkg-genchanges</prgn> and
1403                 <prgn>dpkg-gencontrol</prgn>.  If there is general
1404                 interest in the new format, you should contact the
1405                 <package>dpkg</package> maintainer to have the parser
1406                 script for it included in the <prgn>dpkg</prgn>
1407                 package.  (You will need to agree that the parser and
1408                 its manpage may be distributed under the GNU GPL, just
1409                 as the rest of `dpkg' is.)
1410               </p>
1411             </footnote>
1412           </p>
1413         </sect1>
1414
1415
1416         <sect1>
1417           <heading>Error trapping in makefiles</heading>
1418
1419           <p>
1420             When <prgn>make</prgn> invokes a command in a makefile
1421             (including your package's upstream makefiles and
1422             <tt>debian/rules</tt>), it does so using <tt>sh</tt>.  This
1423             means that <tt>sh</tt>'s usual bad error handling
1424             properties apply: if you include a miniature script as one
1425             of the commands in your makefile you'll find that if you
1426             don't do anything about it then errors are not detected
1427             and <prgn>make</prgn> will blithely continue after
1428             problems.</p>
1429
1430           <p>
1431             Every time you put more than one shell command (this
1432             includes using a loop) in a makefile command you
1433             must make sure that errors are trapped.  For
1434             simple compound commands, such as changing directory and
1435             then running a program, using <tt>&amp;&amp;</tt> rather
1436             than semicolon as a command separator is sufficient.  For
1437             more complex commands including most loops and
1438             conditionals you should include a separate <tt>set -e</tt>
1439             command at the start of every makefile command that's
1440             actually one of these miniature shell scripts.</p></sect1>
1441
1442
1443         <sect1>
1444           <heading>Obsolete constructs and libraries</heading>
1445
1446           <p>
1447             The include file <prgn>&lt;varargs.h&gt;</prgn> is
1448             provided to support end-users compiling very old software;
1449             the library <tt>libtermcap</tt> is provided to support the
1450             execution of software which has been linked against it
1451             (either old programs or those such as Netscape which are
1452             only available in binary form).</p>
1453
1454           <p>
1455             Debian packages should be patched to use
1456             <prgn>&lt;stdarg.h&gt;</prgn> and <tt>ncurses</tt>
1457             instead.
1458           </p>
1459         </sect1>
1460       </sect>
1461     </chapt>
1462
1463     <chapt id="controlfields"><heading>Control files and their fields</heading>
1464
1465       <p>
1466         Many of the tools in the package management suite manipulate
1467         data in a common format, known as control files.  Binary and
1468         source packages have control data as do the <tt>.changes</tt>
1469         files which control the installation of uploaded files, and
1470         <prgn>dpkg</prgn>'s internal databases are in a similar
1471         format.
1472       </p>
1473
1474       <sect><heading>Syntax of control files</heading>
1475
1476         <p>
1477           A file consists of one or more paragraphs of fields.  The
1478           paragraphs are separated by blank lines.  Some control files
1479           only allow one paragraph; others allow several, in which
1480           case each paragraph often refers to a different package.
1481         </p>
1482
1483         <p>
1484           Each paragraph is a series of fields and values; each field
1485           consists of a name, followed by a colon and the value.  It
1486           ends at the end of the line.  Horizontal whitespace (spaces
1487           and tabs) may occur immediately before or after the value
1488           and is ignored there; it is conventional to put a single
1489           space after the colon.
1490         </p>
1491
1492         <p>
1493           Some fields' values may span several lines; in this case
1494           each continuation line <em>must</em> start with a space or
1495           tab.  Any trailing spaces or tabs at the end of individual
1496           lines of a field value are ignored.
1497         </p>
1498
1499         <p>
1500           Except where otherwise stated only a single line of data is
1501           allowed and whitespace is not significant in a field body.
1502           Whitespace may never appear inside names (of packages,
1503           architectures, files or anything else), version numbers or
1504           in between the characters of multi-character version
1505           relationships.
1506         </p>
1507
1508         <p>
1509           Field names are not case-sensitive, but it is usual to
1510           capitalize the field names using mixed case as shown below.
1511         </p>
1512
1513         <p>
1514           Blank lines, or lines consisting only of spaces and tabs,
1515           are not allowed within field values or between fields - that
1516           would mean a new paragraph.
1517         </p>
1518
1519         <p>
1520           It is important to note that there are several fields which
1521           are optional as far as <prgn>dpkg</prgn> and the related
1522           tools are concerned, but which must appear in every Debian
1523           package, or whose omission may cause problems.  When writing
1524           the control files for Debian packages you <em>must</em> read
1525           the Debian policy manual in conjunction with the details
1526           below and the list of fields for the particular file.</p>
1527       </sect>
1528
1529       <sect><heading>List of fields</heading>
1530         <p>
1531           This list here is not supposed to be exhaustive. Most fields
1532           are dealt with elsewhere in this document and in the
1533           packaging manual.
1534         </p>
1535         <sect1 id="f-Package"><heading><tt>Package</tt>
1536           </heading>
1537
1538           <p>
1539             The name of the binary package.  Package names consist of
1540             the alphanumerics and <tt>+</tt> <tt>-</tt> <tt>.</tt>
1541             (plus, minus and full stop).
1542           </p>
1543
1544           <p>
1545             They must be at least two characters long and must start
1546             with an alphanumeric character.  The use of lowercase
1547             package names is strongly recommended unless the package
1548             you're building (or referring to, in other fields) is
1549             already using uppercase.</p>
1550         </sect1>
1551
1552         <sect1 id="f-Version"><heading><tt>Version</tt>
1553           </heading>
1554
1555           <p>
1556             This lists the source or binary package's version number -
1557             see <ref id="versions">.
1558           </p>
1559
1560         </sect1>
1561
1562         <sect1
1563                id="f-Standards-Version"><heading><tt>Standards-Version</tt>
1564           </heading>
1565
1566           <p>
1567             The most recent version of the standards (the policy
1568             manual and associated texts) with which the package
1569             complies.  This is updated manually when editing the
1570             source package to conform to newer standards; it can
1571             sometimes be used to tell when a package needs attention.
1572           </p>
1573
1574           <p>
1575             Its format is the same as that of a version number except
1576             that no epoch or Debian revision is allowed - see <ref
1577                                                                    id="versions">.</p>
1578         </sect1>
1579
1580
1581         <sect1 id="f-Distribution"><heading><tt>Distribution</tt>
1582           </heading>
1583
1584           <p>
1585             In a <tt>.changes</tt> file or parsed changelog output
1586             this contains the (space-separated) name(s) of the
1587             distribution(s) where this version of the package should
1588             be or was installed.  Distribution names follow the rules
1589             for package names.  (See <ref id="f-Package">).
1590           </p>
1591
1592           <p>
1593             <footnote>
1594                 Current distribution values are:
1595                 <taglist>
1596                   <tag><em>stable</em></tag>
1597                   <item>
1598                     <p>
1599                       This is the current `released' version of Debian
1600                       GNU/Linux.  Once the
1601                       distribution is <em>stable</em> only major bug fixes
1602                       are allowed. When changes are made to this
1603                       distribution, the release number is increased
1604                       (for example: 1.2r1 becomes 1.2r2 then 1.2r3, etc).
1605                     </p>
1606                   </item>
1607
1608                   <tag><em>unstable</em></tag>
1609                   <item>
1610                     <p>
1611                       This distribution value refers to the
1612                       <em>developmental</em> part of the Debian
1613                       distribution tree. New packages, new upstream
1614                       versions of packages and bug fixes go into the
1615                       <em>unstable</em> directory tree. Download from
1616                       this distribution at your own risk.
1617                     </p>
1618                   </item>
1619
1620                   <tag><em>frozen</em></tag>
1621                   <item>
1622                     <p>
1623                       From time to time, the <em>unstable</em>
1624                       distribution enters a state of `code-freeze' in
1625                       anticipation of release as a <em>stable</em>
1626                       version. During this period of testing only
1627                       fixes for existing or newly-discovered bugs will
1628                       be allowed.
1629                     </p>
1630                   </item>
1631
1632                   <tag><em>experimental</em></tag>
1633                   <item>
1634                     <p>
1635                       The packages with this distribution value are deemed
1636                       by their maintainers to be high risk. Oftentimes they
1637                       represent early beta or developmental packages from
1638                       various sources that the maintainers want people to
1639                       try, but are not ready to be a part of the other parts
1640                       of the Debian distribution tree. Download at your own
1641                       risk.
1642                     </p>
1643                   </item>
1644                 </taglist>
1645                 There are several sections in each
1646                 distribution. Currently, these sections are:
1647
1648                 <taglist>
1649                   <tag><em>main</em></tag>
1650                   <item>
1651                     <p>
1652                       The packages in this section are those in the
1653                       main Debian distribution.  They are all free
1654                       (according to the Debian free software
1655                       guidelines) and meet any other criteria for
1656                       inclusion described in this manual.</p>
1657                   </item>
1658
1659                   <tag><em>contrib</em></tag>
1660                   <item>
1661                     <p>
1662                       The packages in this section do not meet the
1663                       criteria for inclusion in the main Debian
1664                       distribution as defined by this manual, but are
1665                       otherwise free, as defined by the Debian free
1666                       software guidelines.</p>
1667                   </item>
1668
1669                   <tag><em>non-free</em></tag>
1670                   <item>
1671                     <p>
1672                       Packages in <em>non-free</em> do not meet the
1673                       criteria of free software, as defined by the
1674                       Debian free software guidelines. Again, use your
1675                       best judgment in downloading from this
1676                       Distribution.</p>
1677                   </item>
1678
1679                 </taglist> You should list <em>all</em> distributions that
1680                 the package should be installed into. Except in unusual
1681                 circumstances, installations to <em>stable</em> should also
1682                 go into <em>frozen</em> (if it exists) and
1683                 <em>unstable</em>. Likewise, installations into
1684                 <em>frozen</em> should also go into <em>unstable</em>.
1685             </footnote>
1686           </p>
1687         </sect1>
1688
1689
1690       </sect>
1691     </chapt>
1692
1693     <chapt id="versions"><heading>Version numbering    </heading>
1694
1695       <p>
1696         Every package has a version number, in its <tt>Version</tt>
1697         control file field.
1698       </p>
1699
1700       <p>
1701         The package management system imposes an ordering on version
1702         numbers, so that it can tell whether packages are being up- or
1703         downgraded and so that package system front end applications
1704         can tell whether a package it finds available is newer than
1705         the one installed on the system.  The version number format
1706         has the most significant parts (as far as comparison is
1707         concerned) at the beginning.
1708       </p>
1709
1710       <p>
1711         The version number format is:
1712         &lsqb<var>epoch</var><tt>:</tt>&rsqb;<var>upstream-version</var>&lsqb;<tt>-</tt><var>debian-revision</var>&rsqb;
1713       </p>
1714
1715       <p>
1716         The three components here are:
1717         <taglist>
1718           <tag><var>epoch</var></tag>
1719           <item>
1720
1721             <p>
1722               This is a single (generally small) unsigned integer.  It
1723               may be omitted, in which case zero is assumed.  If it is
1724               omitted then the <var>upstream-version</var> may not
1725               contain any colons.
1726             </p>
1727
1728             <p>
1729               It is provided to allow mistakes in the version numbers
1730               of older versions of a package, and also a package's
1731               previous version numbering schemes, to be left behind.
1732             </p>
1733
1734           </item>
1735
1736           <tag><var>upstream-version</var></tag>
1737           <item>
1738
1739             <p>
1740               This is the main part of the version.  It is usually the
1741               version number of the original (`upstream') package from
1742               which the <tt>.deb</tt> file has been made, if this is
1743               applicable.  Usually this will be in the same format as
1744               that specified by the upstream author(s); however, it
1745               may need to be reformatted to fit into the package
1746               management system's format and comparison scheme.
1747             </p>
1748
1749             <p>
1750               The comparison behavior of the package management system
1751               with respect to the <var>upstream-version</var> is
1752               described below.  The <var>upstream-version</var>
1753               portion of the version number is mandatory.
1754             </p>
1755
1756             <p>
1757               The <var>upstream-version</var> may contain only
1758               alphanumerics and the characters <tt>.</tt> <tt>+</tt>
1759               <tt>-</tt> <tt>:</tt> (full stop, plus, hyphen, colon)
1760               and should start with a digit.  If there is no
1761               <var>debian-revision</var> then hyphens are not allowed;
1762               if there is no <var>epoch</var> then colons are not
1763               allowed.</p>
1764           </item>
1765
1766           <tag><var>debian-revision</var></tag>
1767           <item>
1768
1769             <p>
1770               This part of the version represents the version of the
1771               modifications that were made to the package to make it a
1772               Debian binary package.  It is in the same format as the
1773               <var>upstream-version</var> and is compared in the same
1774               way.
1775             </p>
1776
1777             <p>
1778               It is optional; if it isn't present then the
1779               <var>upstream-version</var> may not contain a hyphen.
1780               This format represents the case where a piece of
1781               software was written specifically to be turned into a
1782               Debian binary package, and so there is only one
1783               `debianization' of it and therefore no revision
1784               indication is required.
1785             </p>
1786
1787             <p>
1788               It is conventional to restart the
1789               <var>debian-revision</var> at <tt>1</tt> each time the
1790               <var>upstream-version</var> is increased.
1791             </p>
1792
1793             <p>
1794               The package management system will break the
1795               <var>upstream-version</var> and
1796               <var>debian-revision</var> apart at the last hyphen in
1797               the string.  The absence of a <var>debian-revision</var>
1798               compares earlier than the presence of one (but note that
1799               the <var>debian-revision</var> is the least significant
1800               part of the version number).
1801             </p>
1802
1803             <p>
1804               The <var>debian-revision</var> may contain only
1805               alphanumerics and the characters <tt>+</tt> and
1806               <tt>.</tt> (plus and full stop).
1807             </p>
1808           </item>
1809         </taglist>
1810         The <var>upstream-version</var> and <var>debian-revision</var>
1811         parts are compared by the package management system using the
1812         same algorithm:
1813       </p>
1814
1815       <p>
1816         The strings are compared from left to right.
1817       </p>
1818
1819       <p>
1820         First the initial part of each string consisting entirely of
1821         non-digit characters is determined.  These two parts (one of
1822         which may be empty) are compared lexically.  If a difference
1823         is found it is returned.  The lexical comparison is a
1824         comparison of ASCII values modified so that all the letters
1825         sort earlier than all the non-letters.
1826       </p>
1827
1828       <p>
1829         Then the initial part of the remainder of each string which
1830         consists entirely of digit characters is determined.  The
1831         numerical values of these two parts are compared, and any
1832         difference found is returned as the result of the comparison.
1833         For these purposes an empty string (which can only occur at
1834         the end of one or both version strings being compared) counts
1835         as zero.
1836       </p>
1837
1838       <p>
1839         These two steps are repeated (chopping initial non-digit
1840         strings and initial digit strings off from the start) until a
1841         difference is found or both strings are exhausted.
1842       </p>
1843
1844       <p>
1845         Note that the purpose of epochs is to allow us to leave behind
1846         mistakes in version numbering, and to cope with situations
1847         where the version numbering changes.  It is <em>not</em> there
1848         to cope with version numbers containing strings of letters
1849         which the package management system cannot interpret (such as
1850         <tt>ALPHA</tt> or <tt>pre-</tt>), or with silly orderings (the
1851         author of this manual has heard of a package whose versions
1852         went <tt>1.1</tt>, <tt>1.2</tt>, <tt>1.3</tt>, <tt>1</tt>,
1853         <tt>2.1</tt>, <tt>2.2</tt>, <tt>2</tt> and so forth).
1854       </p>
1855
1856       <p>
1857         If an upstream package has problematic version numbers they
1858         should be converted to a sane form for use in the
1859         <tt>Version</tt> field.
1860       </p>
1861
1862       <sect>
1863         <heading>Version numbers based on dates</heading>
1864         <p>
1865           In general, Debian packages should use the same version
1866           numbers as the upstream sources.</p>
1867
1868         <p>
1869           However, in some cases where the upstream version number is
1870           based on a date (e.g., a development `snapshot' release) the
1871           package management system cannot handle these version
1872           numbers without epochs. For example, dpkg will consider
1873           `96May01' to be greater than `96Dec24'.</p>
1874
1875         <p>
1876           To prevent having to use epochs for every new upstream
1877           version, the version number should be changed to the
1878           following format in such cases: `19960501', `19961224'. It
1879           is up to the maintainer whether he/she wants to bother the
1880           upstream maintainer to change the version numbers upstream,
1881           too.</p>
1882
1883         <p>
1884           Note, that other version formats based on dates which are
1885           parsed correctly by the package management system should
1886           <em>not</em> be changed.</p>
1887
1888         <p>
1889           Native Debian packages (i.e., packages which have been
1890           written especially for Debian) whose version numbers include
1891           dates should always use the `YYYYMMDD' format.</p>
1892       </sect>
1893     </chapt>
1894
1895     <chapt id="miscellaneous"><heading>Packaging Considerations</heading>
1896
1897       <sect id="timestamps"><heading>Time Stamps</heading>
1898         <p>
1899           Maintainers are encouraged to preserve the modification
1900           times of the upstream source files in a package, as far as
1901           is reasonably possible. Even though this is optional, this
1902           is still a good idea.
1903           <footnote>
1904             <p>
1905               The rationale is that there is some information conveyed
1906               by knowing the age of the file, for example, you could
1907               recognize that some documentation is very old by looking
1908               at the modification time, so it would be nice if the
1909               modification time of the upstream source would be
1910               preserved.
1911             </p>
1912           </footnote>
1913         </p>
1914       </sect>
1915
1916       <sect id="debianrules"><heading><tt>debian/rules</tt> - the
1917           main building script    </heading>
1918
1919         <p>
1920           This file must be an executable makefile, and contains the
1921           package-specific recipes for compiling the package and
1922           building binary package(s) out of the source.
1923         </p>
1924
1925         <p>
1926           It must start with the line <tt>#!/usr/bin/make -f</tt>,
1927           so that it can be invoked by saying its name rather than
1928           invoking <prgn>make</prgn> explicitly.
1929         </p>
1930
1931         <p>
1932           Since an interactive <tt>debian/rules</tt> script makes it
1933           impossible to auto-compile that package and also makes it
1934           hard for other people to reproduce the same binary
1935           package, all <strong>required targets</strong> MUST be
1936           non-interactive. At a minimum, required targets are the
1937           ones called by <prgn>dpkg-buildpackage</prgn>, namely,
1938           <em>clean</em>, <em>binary</em>, <em>binary-arch</em>,
1939           <em>binary-indep</em>, and <em>build</em>. It also follows
1940           that any target that these targets depend on must also be
1941           non-interactive.
1942         </p>
1943
1944         <p>
1945           The targets which must be present are:
1946           <taglist>
1947             <tag><tt>build</tt></tag>
1948             <item>
1949               <p>
1950                 This should perform all non-interactive
1951                 configuration and compilation of the package.  If a
1952                 package has an interactive pre-build configuration
1953                 routine, the Debianised source package should be
1954                 built after this has taken place, so that it can be
1955                 built without rerunning the configuration.
1956               </p>
1957
1958               <p>
1959                 For some packages, notably ones where the same
1960                 source tree is compiled in different ways to produce
1961                 two binary packages, the <prgn>build</prgn> target
1962                 does not make much sense.  For these packages it is
1963                 good enough to provide two (or more) targets
1964                 (<tt>build-a</tt> and <tt>build-b</tt> or whatever)
1965                 for each of the ways of building the package, and a
1966                 <prgn>build</prgn> target that does nothing.  The
1967                 <prgn>binary</prgn> target will have to build the
1968                 package in each of the possible ways and make the
1969                 binary package out of each.
1970               </p>
1971
1972               <p>
1973                 The <prgn>build</prgn> target must not do anything
1974                 that might require root privilege.
1975               </p>
1976
1977               <p>
1978                 The <prgn>build</prgn> target may need to run
1979                 <prgn>clean</prgn> first - see below.
1980               </p>
1981
1982               <p>
1983                 When a package has a configuration routine that
1984                 takes a long time, or when the makefiles are poorly
1985                 designed, or when <prgn>build</prgn> needs to run
1986                 <prgn>clean</prgn> first, it is a good idea to
1987                 <tt>touch build</tt> when the build process is
1988                 complete.  This will ensure that if <tt>debian/rules
1989                   build</tt> is run again it will not rebuild the
1990                 whole program.
1991               </p>
1992             </item>
1993
1994             <tag><tt>binary</tt>, <tt>binary-arch</tt>,
1995               <tt>binary-indep</tt>
1996             </tag>
1997             <item>
1998               <p>
1999                 The <prgn>binary</prgn> target must be all that is
2000                 necessary for the user to build the binary
2001                 package. All these targets are required to be
2002                 non-interactive.  It is split into two parts:
2003                 <prgn>binary-arch</prgn> builds the packages' output
2004                 files which are specific to a particular
2005                 architecture, and <prgn>binary-indep</prgn> builds
2006                 those which are not.
2007               </p>
2008
2009               <p>
2010                 <prgn>binary</prgn> may be (and commonly is) a target
2011                 with no commands which simply depends on
2012                 <prgn>binary-arch</prgn> and
2013                 <prgn>binary-indep</prgn>.
2014               </p>
2015
2016               <p>
2017                 Both <prgn>binary-*</prgn> targets should depend on
2018                 the <prgn>build</prgn> target, above, so that the
2019                 package is built if it has not been already.  It
2020                 should then create the relevant binary package(s),
2021                 using <prgn>dpkg-gencontrol</prgn> to make their
2022                 control files and <prgn>dpkg-deb</prgn> to build
2023                 them and place them in the parent of the top level
2024                 directory.
2025               </p>
2026
2027               <p>
2028                 If one of the <prgn>binary-*</prgn> targets has
2029                 nothing to do (this will be always be the case if
2030                 the source generates only a single binary package,
2031                 whether architecture-dependent or not) it
2032                 <em>must</em> still exist, and must always
2033                 succeed.
2034               </p>
2035
2036               <p>
2037                 The <prgn>binary</prgn> targets must be invoked as
2038                 root.
2039               </p>
2040             </item>
2041
2042             <tag><tt>clean</tt></tag>
2043             <item>
2044
2045               <p>
2046                 This must undo any effects that the
2047                 <prgn>build</prgn> and <prgn>binary</prgn> targets
2048                 may have had, except that it should leave alone any
2049                 output files created in the parent directory by a
2050                 run of <prgn>binary</prgn>. This target must be
2051                 non-interactive.
2052               </p>
2053
2054               <p>
2055                 If a <prgn>build</prgn> file is touched at the end
2056                 of the <prgn>build</prgn> target, as suggested
2057                 above, it should be removed as the first thing that
2058                 <prgn>clean</prgn> does, so that running
2059                 <prgn>build</prgn> again after an interrupted
2060                 <prgn>clean</prgn> doesn't think that everything is
2061                 already done.
2062               </p>
2063
2064               <p>
2065                 The <prgn>clean</prgn> target may need to be
2066                 invoked as root if <prgn>binary</prgn> has been
2067                 invoked since the last <prgn>clean</prgn>, or if
2068                 <prgn>build</prgn> has been invoked as root (since
2069                 <prgn>build</prgn> may create directories, for
2070                 example).
2071               </p>
2072             </item>
2073
2074             <tag><tt>get-orig-source</tt> (optional)</tag>
2075             <item>
2076
2077               <p>
2078                 This target fetches the most recent version of the
2079                 original source package from a canonical archive site
2080                 (via FTP or WWW, for example), does any necessary
2081                 rearrangement to turn it into the original source
2082                 tar file format described below, and leaves it in the
2083                 current directory.
2084               </p>
2085
2086               <p>
2087                 This target may be invoked in any directory, and
2088                 should take care to clean up any temporary files it
2089                 may have left.
2090               </p>
2091
2092               <p>
2093                 This target is optional, but providing it if
2094                 possible is a good idea.
2095               </p>
2096             </item>
2097           </taglist>
2098
2099         <p>
2100           The <prgn>build</prgn>, <prgn>binary</prgn> and
2101           <prgn>clean</prgn> targets must be invoked with a current
2102           directory of the package's top-level directory.
2103         </p>
2104
2105
2106         <p>
2107           Additional targets may exist in <tt>debian/rules</tt>,
2108           either as published or undocumented interfaces or for the
2109           package's internal use.
2110         </p>
2111
2112         <p>
2113           The architecture we build on and build for is determined by
2114           make variables via dpkg-architecture. You can get the Debian
2115           architecture and the GNU style architecture specification
2116           string for the build machine as well as the host
2117           machine. Here is a list of supported make variables:
2118           <list compact="compact">
2119             <item>
2120               <p><tt>DEB_*_ARCH</tt> (the Debian architecture)</p>
2121             </item>
2122             <item>
2123               <p><tt>DEB_*_GNU_TYPE</tt> (the GNU style architecture
2124                 specification string)</p>
2125             </item>
2126             <item>
2127               <p><tt>DEB_*_GNU_CPU</tt> (the CPU part of DEB_*_GNU_TYPE)</p>
2128             </item>
2129             <item>
2130               <p><tt>DEB_*_GNU_SYSTEM</tt> (the System part of
2131                 DEB_*_GNU_TYPE)</p>
2132           </list>
2133         </p>
2134
2135         <p>
2136           where <tt>*</tt> is either <tt>BUILD</tt> for specification of
2137           the build machine or <tt>HOST</tt> for specification of the machine
2138           we build for.
2139         </p>
2140
2141         <p>
2142           Backward compatibility can be provided in the rules file
2143           by setting the needed variables to suitable default
2144           values, please refer to the documentation of
2145           dpkg-architecture for details.
2146         </p>
2147
2148         <p>
2149           It is important to understand that the <tt>DEB_*_ARCH</tt>
2150           string only determines which Debian architecture we are
2151           building on or for. It should not be used to get the CPU
2152           or system information; the GNU style variables should be
2153           used for that.
2154         </p>
2155       </sect>
2156
2157       <sect id="dpkgchangelog"><heading><tt>debian/changelog</tt>
2158         </heading>
2159
2160         <p>
2161           This file records the changes to the Debian-specific parts of the
2162           package
2163           <footnote>
2164             <p>
2165               Though there is nothing stopping an author who is also
2166               the Debian maintainer from using it for all their
2167               changes, it will have to be renamed if the Debian and
2168               upstream maintainers become different
2169               people.
2170             </p>
2171           </footnote>.
2172         </p>
2173
2174         <p>
2175           It has a special format which allows the package building
2176           tools to discover which version of the package is being
2177           built and find out other release-specific information.
2178         </p>
2179
2180         <p>
2181           That format is a series of entries like this:
2182           <example>
2183             <var>package</var> (<var>version</var>) <var>distribution(s)</var>; urgency=<var>urgency</var>
2184
2185             * <var>change details</var>
2186             <var>more change details</var>
2187             * <var>even more change details</var>
2188
2189             -- <var>maintainer name and email address</var>  <var>date</var>
2190           </example>
2191         </p>
2192
2193         <p>
2194           <var>package</var> and <var>version</var> are the source
2195           package name and version number.
2196         </p>
2197
2198         <p>
2199           <var>distribution(s)</var> lists the distributions where
2200           this version should be installed when it is uploaded - it
2201           is copied to the <tt>Distribution</tt> field in the
2202           <tt>.changes</tt> file.  See <ref id="f-Distribution">.
2203         </p>
2204
2205         <p>
2206           <var>urgency</var> is the value for the <tt>Urgency</tt>
2207           field in the <tt>.changes</tt> file for the upload. It is
2208           not possible to specify an urgency containing commas; commas
2209           are used to separate
2210           <tt><var>keyword</var>=<var>value</var></tt> settings in the
2211           <prgn>dpkg</prgn> changelog format (though there is
2212           currently only one useful <var>keyword</var>,
2213           <tt>urgency</tt>).
2214         </p>
2215
2216         <p>
2217           The change details may in fact be any series of lines
2218           starting with at least two spaces, but conventionally each
2219           change starts with an asterisk and a separating space and
2220           continuation lines are indented so as to bring them in
2221           line with the start of the text above.  Blank lines may be
2222           used here to separate groups of changes, if desired.
2223         </p>
2224
2225         <p>
2226           The maintainer name and email address need <em>not</em>
2227           necessarily be those of the usual package maintainer.
2228           They should be the details of the person doing
2229           <em>this</em> version.  The information here will be
2230           copied to the <tt>.changes</tt> file, and then later used
2231           to send an acknowledgement when the upload has been
2232           installed.
2233         </p>
2234
2235         <p>
2236           The <var>date</var> should be in RFC822 format
2237           <footnote>
2238             <p>
2239               This is generated by the <prgn>822-date</prgn>
2240               program.
2241             </p>
2242           </footnote>; it should include the time zone specified
2243           numerically, with the time zone name or abbreviation
2244           optionally present as a comment.
2245         </p>
2246
2247         <p>
2248           The first `title' line with the package name should start
2249           at the left hand margin; the `trailer' line with the
2250           maintainer and date details should be preceded by exactly
2251           one space.  The maintainer details and the date must be
2252           separated by exactly two spaces.
2253         </p>
2254
2255         <sect1><heading>Defining alternative changelog formats</heading>
2256
2257           <p>
2258             It is possible to use a different format to the standard
2259             one, by providing a parser for the format you wish to
2260             use.
2261           </p>
2262           <p>
2263             A changelog parser must not interact with the user at
2264             all.
2265           </p>
2266         </sect1>
2267       </sect>
2268
2269       <sect id="srcsubstvars"><heading><tt>debian/substvars</tt>
2270           and variable substitutions      </heading>
2271
2272         <p>
2273           When <prgn>dpkg-gencontrol</prgn>,
2274           <prgn>dpkg-genchanges</prgn> and <prgn>dpkg-source</prgn>
2275           generate control files they do variable substitutions on
2276           their output just before writing it.  Variable
2277           substitutions have the form
2278           <tt>${<var>variable-name</var>}</tt>.  The optional file
2279           <tt>debian/substvars</tt> contains variable substitutions
2280           to be used; variables can also be set directly from
2281           <tt>debian/rules</tt> using the <tt>-V</tt> option to the
2282           source packaging commands, and certain predefined
2283           variables are available.
2284         </p>
2285
2286         <p>
2287           The is usually generated and modified dynamically by
2288           <tt>debian/rules</tt> targets; in this case it must be
2289           removed by the <prgn>clean</prgn> target.
2290         </p>
2291
2292         <p>
2293           See <manref name="dpkg-source" section="1"> for full
2294           details about source variable substitutions, including the
2295           format of <tt>debian/substvars</tt>.</p>
2296       </sect>
2297
2298       <sect id="debianfiles"><heading><tt>debian/files</tt>
2299         </heading>
2300
2301         <p>
2302           This file is not a permanent part of the source tree; it
2303           is used while building packages to record which files are
2304           being generated.  <prgn>dpkg-genchanges</prgn> uses it
2305           when it generates a <tt>.changes</tt> file.
2306         </p>
2307
2308         <p>
2309           It should not exist in a shipped source package, and so it
2310           (and any backup files or temporary files such as
2311           <tt>files.new</tt>
2312           <footnote>
2313             <p>
2314               <tt>files.new</tt> is used as a temporary file by
2315               <prgn>dpkg-gencontrol</prgn> and
2316               <prgn>dpkg-distaddfile</prgn> - they write a new
2317               version of <tt>files</tt> here before renaming it,
2318               to avoid leaving a corrupted copy if an error
2319               occurs
2320             </p>
2321           </footnote>) should be removed by the
2322           <prgn>clean</prgn> target.  It may also be wise to
2323           ensure a fresh start by emptying or removing it at the
2324           start of the <prgn>binary</prgn> target.
2325         </p>
2326
2327         <p>
2328           <prgn>dpkg-gencontrol</prgn> adds an entry to this file
2329           for the <tt>.deb</tt> file that will be created by
2330           <prgn>dpkg-deb</prgn> from the control file that it
2331           generates, so for most packages all that needs to be done
2332           with this file is to delete it in <prgn>clean</prgn>.
2333         </p>
2334
2335         <p>
2336           If a package upload includes files besides the source
2337           package and any binary packages whose control files were
2338           made with <prgn>dpkg-gencontrol</prgn> then they should be
2339           placed in the parent of the package's top-level directory
2340           and <prgn>dpkg-distaddfile</prgn> should be called to add
2341           the file to the list in <tt>debian/files</tt>.</p>
2342       </sect>
2343
2344       <sect id="restrictions"><heading>Restrictions on objects in source packages
2345         </heading>
2346
2347         <p>
2348           The source package may not contain any hard links
2349           <footnote>
2350             <p>
2351               This is not currently detected when building source
2352               packages, but only when extracting
2353               them.
2354             </p>
2355           </footnote>
2356           <footnote>
2357             <p>
2358               Hard links may be permitted at some point in the
2359               future, but would require a fair amount of
2360               work.
2361             </p>
2362           </footnote>, device special files, sockets or setuid or
2363           setgid files.
2364           <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.
2417             <footnote>
2418               <p>
2419                 The blurb that comes with a program in its
2420                 announcements and/or <prgn>README</prgn> files is
2421                 rarely suitable for use in a description.  It is
2422                 usually aimed at people who are already in the
2423                 community where the package is used.
2424               </p>
2425             </footnote>
2426           </p>
2427
2428           <p>
2429             Put important information first, both in the synopsis and
2430             extended description.  Sometimes only the first part of the
2431             synopsis or of the description will be displayed.  You can
2432             assume that there will usually be a way to see the whole
2433             extended description.
2434           </p>
2435
2436           <p>
2437             You may include information about dependencies and so forth
2438             in the extended description, if you wish.
2439           </p>
2440
2441           <p>
2442             Do not use tab characters.  Their effect is not predictable.
2443           </p>
2444
2445         </sect1>
2446       </sect>
2447     </chapt>
2448
2449
2450     <chapt id="maintainerscripts"><heading>Package maintainer scripts
2451         and installation procedure
2452       </heading>
2453
2454       <sect><heading>Introduction to package maintainer scripts
2455         </heading>
2456
2457         <p>
2458           It is possible to supply scripts as part of a package which
2459           the package management system will run for you when your
2460           package is installed, upgraded or removed.
2461         </p>
2462
2463         <p>
2464           These scripts should be the files <tt>preinst</tt>,
2465           <tt>postinst</tt>, <tt>prerm</tt> and <tt>postrm</tt> in the
2466           control area of the package.  They must be proper executable
2467           files; if they are scripts (which is recommended) they must
2468           start with the usual <tt>#!</tt> convention.  They should be
2469           readable and executable by anyone, and not world-writable.
2470         </p>
2471
2472         <p>
2473           The package management system looks at the exit status from
2474           these scripts.  It is important that they exit with a
2475           non-zero status if there is an error, so that the package
2476           management system can stop its processing.  For shell
2477           scripts this means that you <em>almost always</em> need to
2478           use <tt>set -e</tt> (this is usually true when writing shell
2479           scripts, in fact).  It is also important, of course, that
2480           they don't exit with a non-zero status if everything went
2481           well.
2482         </p>
2483
2484         <p>
2485           It is necessary for the error recovery procedures that the
2486           scripts be idempotent: i.e., invoking the same script several
2487           times in the same situation should do no harm.  If the first
2488           call failed, or aborted half way through for some reason,
2489           the second call should merely do the things that were left
2490           undone the first time, if any, and exit with a success
2491           status.
2492         </p>
2493
2494         <p>
2495           When a package is upgraded a combination of the scripts from
2496           the old and new packages is called in amongst the other
2497           steps of the upgrade procedure.  If your scripts are going
2498           to be at all complicated you need to be aware of this, and
2499           may need to check the arguments to your scripts.
2500         </p>
2501
2502         <p>
2503           Broadly speaking the <prgn>preinst</prgn> is called before
2504           (a particular version of) a package is installed, and the
2505           <prgn>postinst</prgn> afterwards; the <prgn>prerm</prgn>
2506           before (a version of) a package is removed and the
2507           <prgn>postrm</prgn> afterwards.
2508         </p>
2509
2510         <p> Programs called from maintainer scripts should not
2511           normally have a path prepended to them. Before installation
2512           is started the package management system checks to see if
2513           the programs <prgn>ldconfig</prgn>,
2514           <prgn>start-stop-daemon</prgn>, <prgn>install-info</prgn>,
2515           and <prgn>update-rc.d</prgn> can be found via the
2516           <tt>PATH</tt> environment variable. Those programs, and any
2517           other program that one would expect to on the <tt>PATH</tt>,
2518           should thus be invoked without an absolute
2519           pathname. Maintainer scripts should also not reset the
2520           <tt>PATH</tt>, though they might choose to modify it by pre-
2521           or appending package-specific directories. These
2522           considerations really apply to all shell scripts.</p>
2523       </sect>
2524       <sect>
2525         <heading>Maintainer scripts Idempotency</heading>
2526
2527         <p>
2528           It is very important to make maintainer scripts
2529           idempotent.
2530           <footnote>
2531             <p>
2532               That means that if it runs successfully or fails
2533               and then you call it again it doesn't bomb out,
2534               but just ensures that everything is the way it
2535               ought to be.
2536             </p>
2537           </footnote> This is so that if an error occurs, the
2538           user interrupts <prgn>dpkg</prgn> or some other
2539           unforeseen circumstance happens you don't leave the
2540           user with a badly-broken package.
2541         </p>
2542       </sect>
2543       <sect>
2544         <heading>Controlling terminal for maintainer scripts</heading>
2545
2546         <p>
2547           The maintainer scripts are guaranteed to run with a
2548           controlling terminal and can interact with the user.
2549           If they need to prompt for passwords, do full-screen
2550           interaction or something similar you should do these
2551           things to and from <tt>/dev/tty</tt>, since
2552           <prgn>dpkg</prgn> will at some point redirect scripts'
2553           standard input and output so that it can log the
2554           installation process.  Likewise, because these scripts
2555           may be executed with standard output redirected into a
2556           pipe for logging purposes, Perl scripts should set
2557           unbuffered output by setting <tt>$|=1</tt> so that the
2558           output is printed immediately rather than being
2559           buffered.
2560         </p>
2561
2562         <p>
2563           Each script should return a zero exit status for
2564           success, or a nonzero one for failure.
2565         </p>
2566       </sect>
2567
2568       <sect id="mscriptsinstact"><heading>Summary of ways maintainer
2569           scripts are called
2570         </heading>
2571
2572         <p>
2573           <list compact="compact">
2574             <item>
2575               <p><var>new-preinst</var> <tt>install</tt></p>
2576             </item>
2577             <item>
2578               <p><var>new-preinst</var> <tt>install</tt>
2579                 <var>old-version</var></p>
2580             </item>
2581             <item>
2582               <p><var>new-preinst</var> <tt>upgrade</tt>
2583                 <var>old-version</var></p>
2584             </item>
2585             <item>
2586               <p><var>old-preinst</var> <tt>abort-upgrade</tt>
2587                 <var>new-version</var>
2588               </p>
2589             </item>
2590           </list>
2591
2592         <p>
2593           <list compact="compact">
2594             <item>
2595               <p><var>postinst</var> <tt>configure</tt>
2596                 <var>most-recently-configured-version</var></p>
2597             </item>
2598             <item>
2599               <p><var>old-postinst</var> <tt>abort-upgrade</tt>
2600                 <var>new version</var></p>
2601             </item>
2602             <item>
2603               <p><var>conflictor's-postinst</var> <tt>abort-remove</tt>
2604                 <tt>in-favour</tt> <var>package</var>
2605                 <var>new-version</var></p>
2606             </item>
2607             <item>
2608               <p>
2609                 <var>deconfigured's-postinst</var>
2610                 <tt>abort-deconfigure</tt> <tt>in-favour</tt>
2611                 <var>failed-install-package</var> <var>version</var>
2612                 <tt>removing</tt> <var>conflicting-package</var>
2613                 <var>version</var>
2614               </p>
2615             </item>
2616           </list>
2617
2618         <p>
2619           <list compact="compact">
2620             <item>
2621               <p><var>prerm</var> <tt>remove</tt></p>
2622             </item>
2623             <item>
2624               <p><var>old-prerm</var> <tt>upgrade</tt>
2625                 <var>new-version</var></p>
2626             </item>
2627             <item>
2628               <p><var>new-prerm</var> <tt>failed-upgrade</tt>
2629                 <var>old-version</var></p>
2630             </item>
2631             <item>
2632               <p><var>conflictor's-prerm</var> <tt>remove</tt>
2633                 <tt>in-favour</tt> <var>package</var>
2634                 <var>new-version</var></p>
2635             </item>
2636             <item>
2637               <p>
2638                 <var>deconfigured's-prerm</var> <tt>deconfigure</tt>
2639                 <tt>in-favour</tt> <var>package-being-installed</var>
2640                 <var>version</var> <tt>removing</tt>
2641                 <var>conflicting-package</var>
2642                 <var>version</var>
2643               </p>
2644             </item>
2645           </list>
2646
2647         <p>
2648           <list compact="compact">
2649             <item>
2650               <p><var>postrm</var> <tt>remove</tt></p>
2651             </item>
2652             <item>
2653               <p><var>postrm</var> <tt>purge</tt></p>
2654             </item>
2655             <item>
2656               <p>
2657                 <var>old-postrm</var> <tt>upgrade</tt>
2658                 <var>new-version</var></p>
2659             </item>
2660             <item>
2661               <p><var>new-postrm</var> <tt>failed-upgrade</tt>
2662                 <var>old-version</var></p>
2663             </item>
2664             <item>
2665               <p><var>new-postrm</var> <tt>abort-install</tt></p>
2666             </item>
2667             <item>
2668               <p><var>new-postrm</var> <tt>abort-install</tt>
2669                 <var>old-version</var></p>
2670             </item>
2671             <item>
2672               <p><var>new-postrm</var> <tt>abort-upgrade</tt>
2673                 <var>old-version</var></p>
2674             </item>
2675             <item>
2676               <p>
2677                 <var>disappearer's-postrm</var> <tt>disappear</tt>
2678                 <var>overwriter</var>
2679                 <var>overwriter-version</var></p></item>
2680           </list>
2681         </p>
2682
2683
2684       <sect id="unpackphase"><heading>Details of unpack phase of
2685           installation or upgrade
2686         </heading>
2687
2688         <p>
2689           The procedure on installation/upgrade/overwrite/disappear
2690           (i.e., when running <tt>dpkg --unpack</tt>, or the unpack
2691           stage of <tt>dpkg --install</tt>) is as follows.  In each
2692           case if an error occurs the actions are, in general, run
2693           backwards - this means that the maintainer scripts are run
2694           with different arguments in reverse order.  These are the
2695           `error unwind' calls listed below.
2696
2697           <enumlist>
2698             <item>
2699               <p>
2700                 <enumlist>
2701                   <item>
2702                     <p>If a version of the package is already
2703                       installed, call
2704                       <example>
2705                         <var>old-prerm</var> upgrade <var>new-version</var>
2706                       </example></p>
2707                   </item>
2708                   <item>
2709                     <p>
2710                       If the script runs but exits with a non-zero
2711                       exit status, <prgn>dpkg</prgn> will attempt:
2712                       <example>
2713                         <var>new-prerm</var> failed-upgrade <var>old-version</var>
2714                       </example>
2715                       Error unwind, for both the above cases:
2716                       <example>
2717                         <var>old-postinst</var> abort-upgrade <var>new-version</var>
2718                       </example>
2719                     </p>
2720                   </item>
2721                 </enumlist>
2722               </p>
2723             </item>
2724             <item>
2725               <p>If a `conflicting' package is being removed at the same time:
2726                 <enumlist>
2727                   <item>
2728                     <p>
2729                       If any packages depended on that conflicting
2730                       package and <tt>--auto-deconfigure</tt> is
2731                       specified, call, for each such package:
2732                       <example>
2733                         <var>deconfigured's-prerm</var> deconfigure \
2734                         in-favour <var>package-being-installed</var> <var>version</var> \
2735                         removing <var>conflicting-package</var> <var>version</var>
2736                       </example>
2737                       Error unwind:
2738                       <example>
2739                         <var>deconfigured's-postinst</var> abort-deconfigure \
2740                         in-favour <var>package-being-installed-but-failed</var> <var>version</var> \
2741                         removing <var>conflicting-package</var> <var>version</var>
2742                       </example>
2743                       The deconfigured packages are marked as
2744                       requiring configuration, so that if
2745                       <tt>--install</tt> is used they will be
2746                       configured again if possible.</p>
2747                   </item>
2748                   <item>
2749                     <p>To prepare for removal of the conflicting package, call:
2750                       <example>
2751                         <var>conflictor's-prerm</var> remove in-favour <var>package</var> <var>new-version</var>
2752                       </example>
2753                       Error unwind:
2754                       <example>
2755                         <var>conflictor's-postinst</var> abort-remove \
2756                         in-favour <var>package</var> <var>new-version</var>
2757                       </example>
2758                     </p>
2759                   </item>
2760                 </enumlist>
2761               </p>
2762             </item>
2763             <item>
2764               <p>
2765                 <enumlist>
2766                   <item>
2767                     <p>If the package is being upgraded, call:
2768                       <example>
2769                         <var>new-preinst</var> upgrade <var>old-version</var>
2770                       </example></p>
2771                   </item>
2772                   <item>
2773                     <p>
2774                       Otherwise, if the package had some configuration
2775                       files from a previous version installed (i.e., it
2776                       is in the `configuration files only' state):
2777                       <example>
2778                         <var>new-preinst</var> install <var>old-version</var>
2779                       </example></p>
2780
2781                   <item>
2782                     <p>Otherwise (i.e., the package was completely purged):
2783                       <example>
2784                         <var>new-preinst</var> install
2785                       </example>
2786                       Error unwind versions, respectively:
2787                       <example>
2788                         <var>new-postrm</var> abort-upgrade <var>old-version</var>
2789                         <var>new-postrm</var> abort-install <var>old-version</var>
2790                         <var>new-postrm</var> abort-install
2791                       </example>
2792                     </p>
2793                   </item>
2794                 </enumlist>
2795               </p>
2796             </item>
2797             <item>
2798
2799               <p>
2800                 The new package's files are unpacked, overwriting any
2801                 that may be on the system already, for example any
2802                 from the old version of the same package or from
2803                 another package (backups of the old files are left
2804                 around, and if anything goes wrong the package
2805                 management system will attempt to put them back as
2806                 part of the error unwind).
2807               </p>
2808
2809               <p>
2810                 It is an error for a package to contains files which
2811                 are on the system in another package, unless
2812                 <tt>Replaces</tt> is used (see <ref id="replaces">).
2813                 Currently the <tt>--force-overwrite</tt> flag is
2814                 enabled, downgrading it to a warning, but this may not
2815                 always be the case.
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.
2835                 <footnote>
2836                   <p>
2837                     Part of the problem is due to what is arguably a
2838                     bug in <prgn>dpkg</prgn>.
2839                   </p>
2840                 </footnote>
2841               </p>
2842
2843               <p>
2844                 A directory will never be replaced by a symbolic links
2845                 to a directory or vice versa; instead, the existing
2846                 state (symlink or not) will be left alone and
2847                 <prgn>dpkg</prgn> will follow the symlink if there is
2848                 one.</p>
2849             </item>
2850
2851             <item>
2852
2853               <p><enumlist>
2854                   <item>
2855                     <p>If the package is being upgraded, call
2856                       <example>
2857                         <var>old-postrm</var> upgrade <var>new-version</var>
2858                       </example></p>
2859                   </item>
2860                   <item>
2861                     <p>If this fails, <prgn>dpkg</prgn> will attempt:
2862                       <example>
2863                         <var>new-postrm</var> failed-upgrade <var>old-version</var>
2864                       </example>
2865                       Error unwind, for both cases:
2866                       <example>
2867                         <var>old-preinst</var> abort-upgrade <var>new-version</var>
2868                       </example>
2869                     </p>
2870                   </item>
2871                 </enumlist>
2872               <p>
2873                 This is the point of no return - if
2874                 <prgn>dpkg</prgn> gets this far, it won't back off
2875                 past this point if an error occurs.  This will
2876                 leave the package in a fairly bad state, which
2877                 will require a successful re-installation to clear
2878                 up, but it's when <prgn>dpkg</prgn> starts doing
2879                 things that are irreversible.
2880               </p>
2881             </item>
2882             <item>
2883               <p>
2884                 Any files which were in the old version of the package
2885                 but not in the new are removed.</p>
2886             </item>
2887             <item>
2888               <p>The new file list replaces the old.</p>
2889             </item>
2890             <item>
2891               <p>The new maintainer scripts replace the old.</p>
2892             </item>
2893
2894             <item>
2895               <p>Any packages all of whose files have been overwritten during the
2896                 installation, and which aren't required for
2897                 dependencies, are considered to have been removed.
2898                 For each such package,
2899                 <enumlist>
2900                   <item>
2901                     <p><prgn>dpkg</prgn> calls:
2902                       <example>
2903                         <var>disappearer's-postrm</var> disappear \
2904                         <var>overwriter</var> <var>overwriter-version</var>
2905                       </example>
2906                     </p>
2907                   </item>
2908                   <item>
2909                     <p>The package's maintainer scripts are removed.
2910                     </p>
2911                   </item>
2912                   <item>
2913                     <p>
2914                       It is noted in the status database as being in a
2915                       sane state, namely not installed (any conffiles
2916                       it may have are ignored, rather than being
2917                       removed by <prgn>dpkg</prgn>).  Note that
2918                       disappearing packages do not have their prerm
2919                       called, because <prgn>dpkg</prgn> doesn't know
2920                       in advance that the package is going to
2921                       vanish.
2922                     </p>
2923                   </item>
2924                 </enumlist>
2925               </p>
2926             </item>
2927             <item>
2928               <p>
2929                 Any files in the package we're unpacking that are also
2930                 listed in the file lists of other packages are removed
2931                 from those lists.  (This will lobotomize the file list
2932                 of the `conflicting' package if there is one.)
2933               </p>
2934             </item>
2935             <item>
2936               <p>
2937                 The backup files made during installation, above, are
2938                 deleted.
2939               </p>
2940             </item>
2941
2942             <item>
2943               <p>
2944                 The new package's status is now sane, and recorded as
2945                 `unpacked'.  Here is another point of no return - if
2946                 the conflicting package's removal fails we do not
2947                 unwind the rest of the installation; the conflicting
2948                 package is left in a half-removed limbo.
2949               </p>
2950             </item>
2951             <item>
2952               <p>
2953                 If there was a conflicting package we go and do the
2954                 removal actions (described below), starting with the
2955                 removal of the conflicting package's files (any that
2956                 are also in the package being installed have already
2957                 been removed from the conflicting package's file list,
2958                 and so do not get removed now).
2959               </p>
2960             </item>
2961           </enumlist>
2962         </p>
2963       </sect>
2964
2965       <sect><heading>Details of configuration</heading>
2966
2967         <p>
2968           When we configure a package (this happens with <tt>dpkg
2969             --install</tt>, or with <tt>--configure</tt>), we first
2970           update the conffiles and then call:
2971           <example>
2972             <var>postinst</var> configure <var>most-recently-configured-version</var>
2973           </example>
2974         </p>
2975
2976         <p>
2977           No attempt is made to unwind after errors during
2978           configuration.
2979         </p>
2980
2981         <p>
2982           If there is no most recently configured version
2983           <prgn>dpkg</prgn> will pass a null argument; older versions
2984           of dpkg may pass <tt>&lt;unknown&gt;</tt> (including the
2985           angle brackets) in this case.  Even older ones do not pass a
2986           second argument at all, under any circumstances.
2987         </p>
2988       </sect>
2989
2990       <sect><heading>Details of removal and/or configuration purging
2991         </heading>
2992
2993         <p>
2994           <enumlist>
2995             <item>
2996               <p>
2997                 <example>
2998                   <var>prerm</var> remove
2999                 </example>
3000               </p>
3001             </item>
3002             <item>
3003               <p>
3004                 The package's files are removed (except conffiles).
3005               </p>
3006             </item>
3007             <item>
3008               <p><example>
3009                   <var>postrm</var> remove
3010                 </example></p>
3011             </item>
3012             <item>
3013               <p>All the maintainer scripts except the postrm are removed.
3014               </p>
3015
3016               <p>
3017                 If we aren't purging the package we stop here.  Note
3018                 that packages which have no postrm and no conffiles
3019                 are automatically purged when removed, as there is no
3020                 difference except for the <prgn>dpkg</prgn>
3021                 status.</p>
3022             </item>
3023             <item>
3024               <p>
3025                 The conffiles and any backup files (<tt>~</tt>-files,
3026                 <tt>#*#</tt> files, <tt>%</tt>-files,
3027                 <tt>.dpkg-{old,new,tmp}</tt>, etc.) are removed.</p>
3028             </item>
3029             <item>
3030               <p><example>
3031                   <var>postrm</var> purge
3032                 </example></p>
3033             </item>
3034             <item>
3035               <p>The package's file list is removed.</p>
3036             </item>
3037           </enumlist>
3038           No attempt is made to unwind after errors during
3039           removal.</p>
3040       </sect>
3041     </chapt>
3042
3043
3044     <chapt id="relationships"><heading>Declaring relationships between
3045         packages      </heading>
3046
3047       <p>
3048         Packages can declare in their control file that they have
3049         certain relationships to other packages - for example, that
3050         they may not be installed at the same time as certain other
3051         packages, and/or that they depend on the presence of others,
3052         or that they should overwrite files in certain other packages
3053         if present.
3054       </p>
3055
3056       <p>
3057         This is done using the <tt>Depends</tt>, <tt>Recommends</tt>,
3058         <tt>Suggests</tt>, <tt>Enhances</tt>, <tt>Conflicts</tt>,
3059         <tt>Provides</tt> and <tt>Replaces</tt> control file fields.
3060       </p>
3061
3062       <p>
3063         Source packages may declare relationships to binary packages,
3064         saying that they require certain binary packages to be
3065         installed or absent at the time of building the package.
3066       </p>
3067
3068       <p>
3069         This is done using the <tt>Build-Depends</tt>,
3070         <tt>Build-Depends-Indep</tt>, <tt>Build-Conflicts</tt>, and
3071         <tt>Build-Conflicts-Indep</tt> control file fields.
3072       </p>
3073
3074       <sect id="depsyntax"><heading>Syntax of relationship fields
3075         </heading>
3076
3077         <p>
3078           These fields all have a uniform syntax.  They are a list of
3079           package names separated by commas.
3080         </p>
3081
3082         <p>
3083           In the <tt>Depends</tt>, <tt>Recommends</tt>,
3084           <tt>Suggests</tt>, <tt>Pre-Depends</tt>,
3085           <tt>Build-Depends</tt> and <tt>Build-Depends-Indep</tt>
3086           control file fields of the package, which declare
3087           dependencies on other packages, the package names listed may
3088           also include lists of alternative package names, separated
3089           by vertical bar symbols <tt>|</tt> (pipe symbols).  In such
3090           a case, the presence of any one of the alternative packages
3091           is installed, that part of the dependency is considered to
3092           be satisfied.
3093         </p>
3094
3095         <p>
3096           All the fields except <tt>Provides</tt> may restrict their
3097           applicability to particular versions of each named package.
3098           This is done in parentheses after each individual package
3099           name; the parentheses should contain a relation from the
3100           list below followed by a version number, in the format
3101           described in <ref id="versions">.
3102         </p>
3103
3104         <p>
3105           The relations allowed are <tt>&lt;&lt;</tt>, <tt>&lt;=</tt>,
3106           <tt>=</tt>, <tt>&gt;=</tt> and <tt>&gt;&gt;</tt> for
3107           strictly earlier, earlier or equal, exactly equal, later or
3108           equal and strictly later, respectively.  The forms
3109           <tt>&lt;</tt> and <tt>&gt;</tt> were used to mean
3110           earlier/later or equal, rather than strictly earlier/later,
3111           so they should not appear in new packages (though
3112           <prgn>dpkg</prgn> still supports them).
3113         </p>
3114
3115         <p>
3116           Whitespace may appear at any point in the version
3117           specification, and must appear where it's necessary to
3118           disambiguate; it is not otherwise significant.  For
3119           consistency and in case of future changes to
3120           <prgn>dpkg</prgn> it is recommended that a single space be
3121           used after a version relationship and before a version
3122           number; it is usual also to put a single space after each
3123           comma, on either side of each vertical bar, and before each
3124           open parenthesis.
3125         </p>
3126
3127         <p>
3128           For example:
3129           <example>
3130             Package: metamail
3131             Version: 2.7-3
3132             Depends: libc5 (>= 5.2.18-4), mime-support, csh | tcsh
3133           </example>
3134         </p>
3135
3136         <p>
3137           All fields that specify build-time relationships
3138           (<tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
3139           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt>)
3140           may be restricted to a certain set of architectures.  This
3141           is done in brackets after each individual package name and
3142           the optional version specification.  The brackets enclose a
3143           list of Debian architecture names separated by whitespace.
3144           An exclamation mark may be prepended to each name. If the
3145           current Debian host architecture is not in this list and
3146           there are no exclamation marks in the list, or it is in the
3147           list with a prepended exclamation mark, the package name and
3148           the associated version specification are ignored completely
3149           for the purposes of defining the relationships.
3150         </p>
3151
3152         <p>
3153           For example:
3154           <example>
3155             Source: glibc
3156             Build-Depends-Indep: texinfo
3157             Build-Depends: kernel-headers-2.2.10 [!hurd-i386],
3158             hurd-dev [hurd-i386], gnumach-dev [hurd-i386]
3159           </example>
3160         </p>
3161       </sect>
3162
3163       <sect>
3164         <heading>Binary Dependencies - <tt>Depends</tt>,
3165           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Enhances</tt>,
3166           <tt>Pre-Depends</tt>
3167         </heading>
3168
3169         <p>
3170           These five fields are used to declare a dependency
3171           relationship by one package on another.  They appear in the
3172           depending package's control file.
3173         </p>
3174
3175         <p>
3176           All but <tt>Pre-Depends</tt> and <tt>Conflicts</tt>
3177           (discussed below) take effect <em>only</em> when a package
3178           is to be configured.  They do not prevent a package being on
3179           the system in an unconfigured state while its dependencies
3180           are unsatisfied, and it is possible to replace a package
3181           whose dependencies are satisfied and which is properly
3182           installed with a different version whose dependencies are
3183           not and cannot be satisfied; when this is done the depending
3184           package will be left unconfigured (since attempts to
3185           configure it will give errors) and will not function
3186           properly.
3187         </p>
3188
3189         <p>
3190           For this reason packages in an installation run are usually
3191           all unpacked first and all configured later; this gives
3192           later versions of packages with dependencies on later
3193           versions of other packages the opportunity to have their
3194           dependencies satisfied.
3195         </p>
3196
3197         <p>
3198           Thus <tt>Depends</tt> allows package maintainers to impose
3199           an order in which packages should be configured.
3200           <taglist>
3201             <tag><tt>Depends</tt></tag>
3202             <item>
3203
3204               <p>This declares an absolute dependency.
3205               </p>
3206
3207               <p>
3208                 The <tt>Depends</tt> field should be used if the
3209                 depended-on package is required for the depending
3210                 package to provide a significant amount of
3211                 functionality.</p>
3212             </item>
3213
3214             <tag><tt>Recommends</tt></tag>
3215             <item>
3216               <p>This declares a strong, but not absolute, dependency.
3217               </p>
3218
3219               <p>
3220                 The <tt>Recommends</tt> field should list packages
3221                 that would be found together with this one in all but
3222                 unusual installations.</p>
3223             </item>
3224
3225             <tag><tt>Suggests</tt></tag>
3226             <item>
3227
3228               <p>
3229                 This is used to declare that one package may be more
3230                 useful with one or more others.  Using this field
3231                 tells the packaging system and the user that the
3232                 listed packages are related to this one and can
3233                 perhaps enhance its usefulness, but that installing
3234                 this one without them is perfectly reasonable.
3235               </p>
3236             </item>
3237
3238             <tag><tt>Enhances</tt></tag>
3239             <item>
3240               <p>
3241                 This field is similar to Suggests but works in the
3242                 opposite direction. It is used to declare that a
3243                 package can enhance the functionality of another
3244                 package.
3245               </p>
3246             </item>
3247
3248             <tag><tt>Pre-Depends</tt></tag>
3249             <item>
3250
3251               <p>
3252                 This field is like <tt>Depends</tt>, except that it
3253                 also forces <prgn>dpkg</prgn> to complete installation
3254                 of the packages named before even starting the
3255                 installation of the package which declares the
3256                 Pre-dependency.
3257               </p>
3258
3259               <p>
3260                 <tt>Pre-Depends</tt> should be used sparingly,
3261                 preferably only by packages whose premature upgrade or
3262                 installation would hamper the ability of the system to
3263                 continue with any upgrade that might be in progress.
3264               </p>
3265
3266               <p>
3267                 When the package declaring it is being configured, a
3268                 <tt>Pre-Dependency</tt> will be considered satisfied
3269                 only if the depending package has been correctly
3270                 configured, just as if an ordinary <tt>Depends</tt>
3271                 had been used.
3272               </p>
3273
3274               <p>
3275                 However, when a package declaring a Pre-dependency is
3276                 being unpacked the predependency can be satisfied even
3277                 if the depended-on package(s) are only unpacked or
3278                 half-configured, provided that they have been
3279                 configured correctly at some point in the past (and
3280                 not removed or partially removed since).  In this case
3281                 both the previously-configured and currently unpacked
3282                 or half-configured versions must satisfy any version
3283                 clause in the <tt>Pre-Depends</tt> field.
3284               </p>
3285             </item>
3286           </taglist>
3287         </p>
3288         <p>
3289           When selecting which level of dependency to use you should
3290           consider how important the depended-on package is to the
3291           functionality of the one declaring the dependency.  Some
3292           packages are composed of components of varying degrees of
3293           importance.  Such a package should list using
3294           <tt>Depends</tt> the package(s) which are required by the
3295           more important components.  The other components'
3296           requirements may be mentioned as Suggestions or
3297           Recommendations, as appropriate to the components' relative
3298           importance.
3299         </p>
3300
3301
3302       <sect id="conflicts"><heading>Alternative binary packages -
3303           <tt>Conflicts</tt> and <tt>Replaces</tt>
3304         </heading>
3305
3306         <p>
3307           When one binary package declares a conflict with another
3308           <prgn>dpkg</prgn> will refuse to allow them to be installed
3309           on the system at the same time.
3310         </p>
3311
3312         <p>
3313           If one package is to be installed, the other must be removed
3314           first - if the package being installed is marked as
3315           replacing (<ref id="replaces">) the one on the system, or
3316           the one on the system is marked as deselected, or both
3317           packages are marked <tt>Essential</tt>, then
3318           <prgn>dpkg</prgn> will automatically remove the package
3319           which is causing the conflict, otherwise it will halt the
3320           installation of the new package with an error. This
3321           mechanism specifically doesn't work when the installed
3322           package is <tt>Essential</tt>, but the new package is not.
3323         </p>
3324
3325
3326         <p>
3327           A package will not cause a conflict merely because its
3328           configuration files are still installed; it must be at least
3329           half-installed.
3330         </p>
3331
3332         <p>
3333           A special exception is made for packages which declare a
3334           conflict with their own package name, or with a virtual
3335           package which they provide (see below): this does not
3336           prevent their installation, and allows a package to conflict
3337           with others providing a replacement for it.  You use this
3338           feature when you want the package in question to be the only
3339           package providing something.
3340         </p>
3341
3342         <p>
3343           A <tt>Conflicts</tt> entry should almost never have an
3344           `earlier than' version clause.  This would prevent
3345           <prgn>dpkg</prgn> from upgrading or installing the package
3346           which declared such a conflict until the upgrade or removal
3347           of the conflicted-with package had been completed.
3348         </p>
3349       </sect>
3350
3351       <sect id="virtual"><heading>Virtual packages - <tt>Provides</tt>
3352         </heading>
3353
3354         <p>
3355           As well as the names of actual (`concrete') packages, the
3356           package relationship fields <tt>Depends</tt>,
3357           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
3358           <tt>Recommends</tt>, <tt>Suggests</tt>, <tt>Conflicts</tt>,
3359           <tt>Build-Conflicts</tt> and <tt>Build-Conflicts-Indep</tt> may
3360           mention virtual packages.
3361         </p>
3362
3363         <p>
3364           A virtual package is one which appears in the
3365           <tt>Provides</tt> control file field of another package.
3366           The effect is as if the package(s) which provide a
3367           particular virtual package name had been listed by name
3368           everywhere the virtual package name appears.
3369         </p>
3370
3371         <p>
3372           If there are both a real and a virtual package of the same
3373           name then the dependency may be satisfied (or the conflict
3374           caused) by either the real package or any of the virtual
3375           packages which provide it.  This is so that, for example,
3376           supposing we have
3377           <example>
3378             Package: vm
3379             Depends: emacs
3380           </example>
3381           and someone else releases an xemacs package they can say
3382           <example>
3383             Package: xemacs
3384             Provides: emacs
3385           </example> and all will work in the interim (until a purely
3386           virtual package name is decided on and the <tt>emacs</tt>
3387           and <tt>vm</tt> packages are changed to use it).
3388         </p>
3389
3390         <p>
3391           If a dependency or a conflict has a version number attached
3392           then only real packages will be considered to see whether
3393           the relationship is satisfied (or the prohibition violated,
3394           for a conflict) - it is assumed that a real package which
3395           provides the virtual package is not of the `right' version.
3396           So, a <tt>Provides</tt> field may not contain version
3397           numbers, and the version number of the concrete package
3398           which provides a particular virtual package will not be
3399           looked at when considering a dependency on or conflict with
3400           the virtual package name.
3401         </p>
3402
3403         <p>
3404           It is likely that the ability will be added in a future
3405           release of <prgn>dpkg</prgn> to specify a version number for
3406           each virtual package it provides.  This feature is not yet
3407           present, however, and is expected to be used only
3408           infrequently.
3409         </p>
3410
3411         <p>
3412           If you want to specify which of a set of real packages should be the
3413           default to satisfy a particular dependency on a virtual package, you
3414           should list the real package as an alternative before the virtual.
3415         </p>
3416       </sect>
3417
3418
3419       <sect id="replaces"><heading><tt>Replaces</tt> - overwriting
3420           files and replacing packages
3421         </heading>
3422
3423         <p>
3424           The <tt>Replaces</tt> control file field has two purposes,
3425           which come into play in different situations.
3426         </p>
3427
3428         <p>
3429           Virtual packages (<ref id="virtual">) are not considered
3430           when looking at a <tt>Replaces</tt> field - the packages
3431           declared as being replaced must be mentioned by their real
3432           names.
3433         </p>
3434
3435         <sect1><heading>Overwriting files in other packages
3436           </heading>
3437
3438           <p>
3439             Firstly, as mentioned before, it is usually an error for a
3440             package to contain files which are on the system in
3441             another package, though currently the
3442             <tt>--force-overwrite</tt> flag is enabled by default,
3443             downgrading the error to a warning,
3444           </p>
3445
3446           <p>
3447             If the overwriting package declares that it replaces the
3448             one containing the file being overwritten then
3449             <prgn>dpkg</prgn> will proceed, and replace the file from
3450             the old package with that from the new.  The file will no
3451             longer be listed as `owned' by the old package.
3452           </p>
3453
3454           <p>
3455             If a package is completely replaced in this way, so that
3456             <prgn>dpkg</prgn> does not know of any files it still
3457             contains, it is considered to have disappeared.  It will
3458             be marked as not wanted on the system (selected for
3459             removal) and not installed.  Any conffiles details noted
3460             in the package will be ignored, as they will have been
3461             taken over by the replacing package(s).  The package's
3462             <prgn>postrm</prgn> script will be run to allow the
3463             package to do any final cleanup required.  See <ref
3464                                                                 id="mscriptsinstact">.
3465           </p>
3466
3467           <p>
3468             In the future <prgn>dpkg</prgn> will discard files which
3469             would overwrite those from an already installed package
3470             which declares that it replaces the package being
3471             installed.  This is so that you can install an older
3472             version of a package without problems.
3473           </p>
3474
3475           <p>
3476             This usage of <tt>Replaces</tt> only takes effect when
3477             both packages are at least partially on the system at
3478             once, so that it can only happen if they do not conflict
3479             or if the conflict has been overridden.</p>
3480         </sect1>
3481
3482         <sect1><heading>Replacing whole packages, forcing their
3483             removal
3484           </heading>
3485
3486           <p>
3487             Secondly, <tt>Replaces</tt> allows the packaging system to
3488             resolve which package should be removed when there is a
3489             conflict - see <ref id="conflicts">.  This usage only
3490             takes effect when the two packages <em>do</em> conflict,
3491             so that the two effects do not interfere with each other.
3492           </p>
3493         </sect1>
3494       </sect>
3495
3496       <sect><heading>Relationships between source and binary packages -
3497           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
3498           <tt>Build-Conflicts</tt>, <tt>Build-Conflicts-Indep</tt>
3499         </heading>
3500
3501         <p>
3502           A source package may declare a dependency or a conflict on a
3503           binary package.  This is done with the control file fields
3504           <tt>Build-Depends</tt>, <tt>Build-Depends-Indep</tt>,
3505           <tt>Build-Conflicts</tt>, and
3506           <tt>Build-Conflicts-Indep</tt>.  Their semantics are that
3507           the dependencies and conflicts they define must be satisfied
3508           (as defined earlier for binary packages), when one of the
3509           targets in <tt>debian/rules</tt> that the particular field
3510           applies to is invoked.
3511
3512           <taglist>
3513             <tag><tt>Build-Depends</tt>, <tt>Build-Conflicts</tt></tag>
3514             <item>
3515               <p>
3516                 The <tt>Build-Depends</tt> and
3517                 <tt>Build-Conflicts</tt> fields apply to the targets
3518                 <tt>build</tt>, <tt>binary</tt>, <tt>binary-arch</tt>
3519                 and <tt>binary-indep</tt>.
3520               </p>
3521             </item>
3522             <tag><tt>Build-Depends-Indep</tt>, <tt>Build-Conflicts-Indep</tt></tag>
3523             <item>
3524               <p>
3525                 The <tt>Build-Depends-Indep</tt> and
3526                 <tt>Build-Conflicts-Indep</tt> fields apply to the
3527                 targets <tt>binary</tt> and <tt>binary-indep</tt>.
3528               </p>
3529             </item>
3530           </taglist>
3531
3532         </p>
3533
3534       </sect>
3535     </chapt>
3536
3537
3538     <chapt id="conffiles"><heading>Configuration file handling
3539       </heading>
3540
3541       <p>
3542         <prgn>dpkg</prgn> can do a certain amount of automatic
3543         handling of package configuration files.
3544       </p>
3545
3546       <p>
3547         Whether this mechanism is appropriate depends on a number of
3548         factors, but basically there are two approaches to any
3549         particular configuration file.
3550       </p>
3551
3552       <p>
3553         The easy method is to ship a best-effort configuration in the
3554         package, and use <prgn>dpkg</prgn>'s conffile mechanism to
3555         handle updates.  If the user is unlikely to want to edit the
3556         file, but you need them to be able to without losing their
3557         changes, and a new package with a changed version of the file
3558         is only released infrequently, this is a good approach.
3559       </p>
3560
3561       <p>
3562         The hard method is to build the configuration file from
3563         scratch in the <prgn>postinst</prgn> script, and to take the
3564         responsibility for fixing any mistakes made in earlier
3565         versions of the package automatically.  This will be
3566         appropriate if the file is likely to need to be different on
3567         each system.
3568       </p>
3569
3570
3571     <chapt id="sharedlibs"><heading>Shared libraries
3572       </heading>
3573
3574       <p>
3575         Packages containing shared libraries must be constructed with
3576         a little care to make sure that the shared library is always
3577         available.  This is especially important for packages whose
3578         shared libraries are vitally important, such as the libc.
3579       </p>
3580
3581       <p>
3582         Firstly, your package should install the shared libraries
3583         under their normal names.  For example, the
3584         <prgn>libgdbm1</prgn> package should install
3585         <tt>libgdbm.so.1.7.3</tt> as
3586         <tt>/usr/lib/libgdbm.so.1.7.3</tt>.  The files should not be
3587         renamed or re-linked by any prerm or postrm scripts;
3588         <prgn>dpkg</prgn> will take care of renaming things safely
3589         without affecting running programs, and attempts to interfere
3590         with this are likely to lead to problems.
3591       </p>
3592
3593       <p>
3594         Secondly, your package should include the symlink that
3595         <prgn>ldconfig</prgn> would create for the shared libraries.
3596         For example, the <prgn>libgdbm1</prgn> package should include
3597         a symlink from <tt>/usr/lib/libgdbm.so.1</tt> to
3598         <tt>libgdbm.so.1.7.3</tt>.  This is needed so that
3599         <prgn>ld.so</prgn> can find the library in between the time
3600         <prgn>dpkg</prgn> installs it and <prgn>ldconfig</prgn> is run
3601         in the <prgn>postinst</prgn> script.  Furthermore, older
3602         versions of the package management system required the library
3603         must be placed before the symlink pointing to it in the
3604         <tt>.deb</tt> file.  This is so that by the time
3605         <prgn>dpkg</prgn> comes to install the symlink (overwriting
3606         the previous symlink pointing at an older version of the
3607         library) the new shared library is already in place.
3608         Unfortunately, this was not not always possible, since it
3609         highly depends on the behavior of the file system. Some
3610         file systems (such as reiserfs) will reorder the files so it
3611         doesn't matter in what order you create them. Starting with
3612         release <tt>1.7.0</tt> <prgn>dpkg</prgn> will reorder the
3613         files itself when building a package.
3614       </p>
3615
3616       <p>
3617         Thirdly, the development package should contain a symlink for
3618         the shared library without a version number.  For example, the
3619         <tt>libgdbm1-dev</tt> package should include a symlink from
3620         <tt>/usr/lib/libgdm.so</tt> to <tt>libgdm.so.1.7.3</tt>.  This
3621         symlink is needed by <prgn>ld</prgn> when compiling packages
3622         as it will only look for <tt>libgdm.so</tt> and
3623         <tt>libgdm.a</tt> when compiling dynamically or statically,
3624         respectively.
3625       </p>
3626
3627       <p>
3628         Any package installing shared libraries in a directory that's listed
3629         in <tt>/etc/ld.so.conf</tt> or in one of the default library
3630         directories of <prgn>ld.so</prgn> (currently, these are <tt>/usr/lib</tt>
3631         and <tt>/lib</tt>) must call <prgn>ldconfig</prgn> in its <prgn>postinst</prgn>
3632         script if and only if the first argument is `configure'. However, it
3633         is important not to call <prgn>ldconfig</prgn> in the postrm or preinst
3634         scripts in the case where the package is being upgraded (see <ref
3635                                                                           id="unpackphase">), as <prgn>ldconfig</prgn> will see the temporary names
3636         that <prgn>dpkg</prgn> uses for the files while it is
3637         installing them and will make the shared library links point
3638         to them, just before <prgn>dpkg</prgn> continues the
3639         installation and removes the links!
3640       </p>
3641
3642       <sect id="shlibs"><heading>The <tt>shlibs</tt> File Format
3643         </heading>
3644
3645         <p>
3646           This file is for use by <prgn>dpkg-shlibdeps</prgn> and is
3647           required when your package provides shared libraries.
3648         </p>
3649
3650         <p>
3651           Each line is of the form:
3652           <example>
3653             <var>library-name</var> <var>version-or-soname</var> <var>dependencies ...</var>
3654           </example>
3655         </p>
3656
3657         <p>
3658           <var>library-name</var> is the name of the shared library,
3659           for example <tt>libc5</tt>.
3660         </p>
3661
3662         <p>
3663           <var>version-or-soname</var> is the soname of the library -
3664           i.e., the thing that must exactly match for the library to be
3665           recognized by <prgn>ld.so</prgn>.  Usually this is the major
3666           version number of the library.
3667         </p>
3668
3669         <p>
3670           <var>dependencies</var> has the same syntax as a dependency
3671           field in a binary package control file.  It should give
3672           details of which package(s) are required to satisfy a binary
3673           built against the version of the library contained in the
3674           package.  See <ref id="depsyntax">.
3675         </p>
3676
3677         <p>
3678           For example, if the package <tt>foo</tt> contains
3679           <tt>libfoo.so.1.2.3</tt>, where the soname of the library is
3680           <tt>libfoo.so.1</tt>, and the first version of the package
3681           which contained a minor number of at least <tt>2.3</tt> was
3682           <var>1.2.3-1</var>, then the package's <var>shlibs</var>
3683           could say:
3684           <example>
3685             libfoo 1    foo (>= 1.2.3-1)
3686           </example>
3687         </p>
3688
3689         <p>
3690           The version-specific dependency is to avoid warnings from
3691           <prgn>ld.so</prgn> about using older shared libraries with
3692           newer binaries.</p>
3693       </sect>
3694
3695       <sect><heading>Further Technical information on
3696           <tt>shlibs</tt></heading>
3697
3698         <sect1><heading><em>What</em> are the <tt>shlibs</tt> files?
3699           </heading>
3700
3701           <p>
3702             The <tt>debian/shlibs</tt> file provides a way of checking
3703             for shared library dependencies on packaged binaries.
3704             They are intended to be used by package maintainers to
3705             make their lives easier.
3706           </p>
3707
3708           <p>
3709             Other <tt>shlibs</tt> files that exist on a Debian system are
3710             <list>
3711               <item> <p><tt>/etc/dpkg/shlibs.default</tt></p></item>
3712               <item> <p><tt>/etc/dpkg/shlibs.override</tt></p></item>
3713               <item> <p><tt>/var/lib/dpkg/info/*.shlibs</tt></p></item>
3714               <item> <p><tt>debian/shlibs.local</tt></p></item>
3715             </list>
3716             These files are used by <prgn>dpkg-shlibdeps</prgn> when
3717             creating a binary package.</p>
3718         </sect1>
3719
3720         <sect1><heading><em>How</em> does <prgn>dpkg-shlibdeps</prgn>
3721             work?
3722           </heading>
3723           <p>
3724             <prgn>dpkg-shlibdeps</prgn>
3725             determines the shared libraries directly
3726             <footnote>
3727               <p>
3728                 It used to do this by calling <prgn>ldd</prgn>, but it
3729                 now calls <prgn>objdump</prgn> to to this. This
3730                 requires a couple of changes in the way that packages
3731                 are built.
3732               </p>
3733               <p>
3734                 A binary <tt>foo</tt> directly uses a library
3735                 <tt>libbar</tt> if it is linked with that
3736                 library. Other libraries that are needed by
3737                 <tt>libbar</tt> are linked indirectly to <tt>foo</tt>,
3738                 and the dynamic linker will load them automatically
3739                 when it loads <tt>libbar</tt>. Running<prgn>ldd</prgn>
3740                 lists all of the libraries used, both directly and
3741                 indirectly; but <prgn>objdump</prgn> only lists the
3742                 directly linked libraries. A package only needs to
3743                 depend on the libraries it is directly linked to,
3744                 since the dependencies for those libraries should
3745                 automatically pull in the other libraries.
3746               </p>
3747               <p>
3748                 This change does mean a change in the way packages are
3749                 build though: currently <prgn>dpkg-shlibdeps</prgn> is
3750                 only run on binaries. But since we will now rely on the
3751                 libraries depending on the libraries they themselves
3752                 need, the packages containing those libraries will
3753                 need to run <prgn>dpkg-shlibdeps</prgn> on the
3754                 libraries.
3755               </p>
3756               <p>
3757                 A good example where this would help us is the current
3758                 mess with multiple version of the <tt>mesa</tt>
3759                 library. With the <prgn>ldd</prgn>-based system, every
3760                 package that uses <tt>mesa</tt> needs to add a
3761                 dependency on <tt>svgalib|svgalib-dummy</tt> in order
3762                 to handle the glide <tt>mesa</tt> variant.  With an
3763                 <prgn>objdump</prgn>-based system this isn't necessary
3764                 anymore and would have saved everyone a lot of work.
3765               </p>
3766               <p>
3767                 Another example: we could update <tt>libimlib</tt>
3768                 with a new version that supports a new graphics format
3769                 called dgf. If we use the old <prgn>ldd</prgn> method,
3770                 every package that uses <tt>libimlib</tt> would need
3771                 to be recompiled so it would also depend on
3772                 <tt>libdgf</tt> or it wouldn't run due to missing
3773                 symbols. However with the new system, packages using
3774                 <tt>libimlib</tt> can rely on <tt>libimlib</tt> itself
3775                 having the dependency on <tt>libdgf</tt> and wouldn't
3776                 need to be updated.
3777               </p>
3778             </footnote>
3779             used by the compiled binaries and libraries passed through
3780             on its command line.
3781           </p>
3782
3783           <p>
3784             For each shared library linked to,
3785             <prgn>dpkg-shlibdeps</prgn> needs to know
3786             <list compact="compact">
3787               <item><p>the package containing the library, and</p></item>
3788               <item><p>the library version number,</p></item>
3789             </list>
3790             and it scans the following files in this order:
3791             <enumlist compact="compact">
3792               <item><p><tt>debian/shlibs.local</tt></p></item>
3793               <item><p><tt>/etc/dpkg/shlibs.override</tt></p></item>
3794               <item><p><tt>/var/lib/dpkg/info/*.shlibs</tt></p></item>
3795               <item><p><tt>/etc/dpkg/shlibs.default</tt></p></item>
3796             </enumlist>
3797           </p>
3798         </sect1>
3799
3800         <sect1><heading><em>Who</em> maintains the various
3801             <tt>shlibs</tt> files?
3802           </heading>
3803
3804           <p>
3805             <list compact="compact">
3806               <item>
3807                 <p><tt>/etc/dpkg/shlibs.default</tt> - the maintainer
3808                   of dpkg</p>
3809               </item>
3810               <item>
3811                 <p>
3812                   <tt>/var/lib/dpkg/info/<var>package</var>.shlibs</tt>
3813                   - the maintainer of each package</p>
3814               </item>
3815               <item>
3816                 <p>
3817                   <tt>/etc/dpkg/shlibs.override</tt> - the local
3818                   system administrator</p>
3819               </item>
3820               <item>
3821                 <p><tt>debian/shlibs.local</tt> - the maintainer of
3822                   the package
3823                 </p>
3824               </item>
3825             </list>
3826             The <tt>shlibs.default</tt> file is managed by
3827             <prgn>dpkg</prgn>. The entries in <tt>shlibs.default</tt>
3828             that are provided by <prgn>dpkg</prgn> are just there to
3829             fix things until the shared library packages all have
3830             <tt>shlibs</tt> files.
3831           </p>
3832         </sect1>
3833
3834         <sect1><heading><em>How</em> to use <prgn>dpkg-shlibdeps</prgn> and
3835             the <tt>shlibs</tt> files
3836           </heading>
3837
3838           <sect2><heading>If your package doesn't provide a shared
3839               library
3840             </heading>
3841
3842             <p>
3843               Put a call to <prgn>dpkg-shlibdeps</prgn> into your
3844               <tt>debian/rules</tt> file.  If your package contains
3845               only binaries (e.g. no scripts) use:
3846               <example>
3847                 dpkg-shlibdeps debian/tmp/usr/bin/* debian/tmp/usr/sbin/*
3848               </example>
3849               If <prgn>dpkg-shlibdeps</prgn> doesn't complain, you're
3850               done. If it does complain you might need to create your
3851               own <tt>debian/shlibs.local</tt> file.</p>
3852           </sect2>
3853
3854           <sect2><heading>If your package provides a shared library
3855             </heading>
3856
3857             <p>
3858               Create a <tt>debian/shlibs</tt> file and let
3859               <tt>debian/rules</tt> install it in the control area:
3860               <example>
3861                 install -m644 debian/shlibs debian/tmp/DEBIAN
3862               </example>
3863               If your package contains additional binaries see above.
3864             </p>
3865           </sect2>
3866         </sect1>
3867
3868         <sect1><heading><em>How</em> to write
3869             <tt>debian/shlibs.local</tt>
3870           </heading>
3871
3872           <p>
3873             This file is intended only as a <em>temporary</em> fix if
3874             your binaries depend on a library which doesn't provide
3875             its own <tt>/var/lib/dpkg/info/*.shlibs</tt> file yet.
3876           </p>
3877
3878           <p>
3879             Let's assume you are packaging a binary <tt>foo</tt>. Your
3880             output in building the package might look like this.
3881             <example>
3882               $ ldd foo
3883               libbar.so.1 => /usr/X11R6/lib/libbar.so.1.0 (0x4001e000)
3884               libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x4002c000)
3885               libc.so.6 => /lib/libc.so.6 (0x40114000)
3886               /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
3887             </example>
3888             And when you ran <prgn>dpkg-shlibdeps</prgn>
3889             <example>
3890               $ dpkg-shlibdeps -O foo
3891               dpkg-shlibdeps: warning: unable to find dependency information for shared library libbar
3892               (soname 1, path /usr/X11R6/lib/libbar.so.1.0, dependency field Depends)
3893               shlibs:Depends=libc6 (>= 2.2.1), xlibs (>= 4.0.1-11)
3894             </example>
3895             The <prgn>foo</prgn> binary depends on the
3896             <prgn>libbar</prgn> shared library, but no package seems
3897             to provide a <tt>*.shlibs</tt> file in
3898             <tt>/var/lib/dpkg/info/</tt>.  Let's determine the package
3899             responsible:
3900           </p>
3901
3902           <p>
3903             <example>
3904               $ dpkg -S /usr/X11R6/lib/libbar.so.1.0
3905               bar1: /usr/X11R6/lib/libbar.so.1.0
3906               $ dpkg -s bar1 | grep Version
3907               Version: 1.0-1
3908             </example>
3909             This tells us that the <prgn>bar1</prgn> package, version
3910             1.0-1 is the one we are using. Now we can create our own
3911             <tt>debian/shlibs.local</tt> to temporarily fix the above
3912             problem. Include the following line into your
3913             <tt>debian/shlibs.local</tt> file.
3914             <example>
3915               libbar 1 bar1 (>= 1.0-1)
3916             </example>
3917             Now your package build should work. As soon as the
3918             maintainer of <prgn>libbar1</prgn> provides a
3919             <tt>shlibs</tt> file, you can remove your
3920             <tt>debian/shlibs.local</tt> file.
3921           </p>
3922         </sect1>
3923       </sect>
3924     </chapt>
3925
3926     <chapt><heading>The Operating System</heading>
3927
3928
3929       <sect>
3930         <heading>File system hierarchy</heading>
3931
3932
3933         <sect1>
3934           <heading>Linux File system Structure</heading>
3935
3936           <p>
3937             The location of all installed files and directories must
3938             comply  with the Linux File system Hierarchy Standard
3939             (FHS).  The latest version of this document can be found
3940             alongside this manual or on
3941             <url id="http://www.pathname.com/fhs/">.
3942             Specific questions about following the standard may be
3943             asked on <prgn>debian-devel</prgn>, or referred to Daniel
3944             Quinlan, the FHS coordinator, at
3945             <email>quinlan@pathname.com</email>.</p></sect1>
3946
3947
3948         <sect1>
3949           <heading>Site-specific programs</heading>
3950
3951           <p>
3952             As mandated by the FHS, packages must not place any
3953             files in <tt>/usr/local</tt>, either by putting them in
3954             the file system archive to be unpacked by <prgn>dpkg</prgn>
3955             or by manipulating them in their maintainer scripts.</p>
3956
3957           <p>
3958             However, the package may create empty directories below
3959             <tt>/usr/local</tt> so that the system administrator knows
3960             where to place site-specific files. These directories
3961             should be removed on package removal if they are
3962             empty.</p>
3963
3964           <p>
3965             Note, that this applies only to directories <em>below</em>
3966             <tt>/usr/local</tt>, not <em>in</em>
3967             <tt>/usr/local</tt>. Packages must not create sub-directories
3968             in the directory <tt>/usr/local</tt> itself, except those listed in
3969             FHS, section 4.5. However, you may create directories
3970             below them as you wish. You must not remove any of the
3971             directories listed in 4.5, even if you created them.</p>
3972
3973           <p>
3974             Since <tt>/usr/local</tt> can be mounted read-only from a
3975             remote server, these directories must be created and
3976             removed by the <tt>postinst</tt> and <tt>prerm</tt>
3977             maintainer scripts. These scripts must not fail if either
3978             of these operations fail. (In the future, it will be
3979             possible to tell <prgn>dpkg</prgn> not to unpack files
3980             matching certain patterns, so that the directories can be
3981             included in the <tt>.deb</tt> packages and system
3982             administrators who do not wish these directories in
3983             /usr/local do not need to have them.)</p>
3984
3985           <p>
3986             For example, the <prgn>emacs</prgn> package will contain
3987             <example>
3988               mkdir -p /usr/local/lib/emacs/site-lisp || true
3989             </example>
3990             in the <tt>postinst</tt> script, and
3991             <example>
3992               rmdir /usr/local/lib/emacs/site-lisp || true
3993               rmdir /usr/local/lib/emacs || true
3994             </example>
3995             in the <tt>prerm</tt> script.</p>
3996
3997           <p>
3998             If you do create a directory in <tt>/usr/local</tt> for
3999             local additions to a package, you should ensure that
4000             settings in <tt>/usr/local</tt> take precedence over the
4001             equivalents in <tt>/usr</tt>.</p>
4002
4003           <p>
4004             However, because '/usr/local' and its contents are for
4005             exclusive use of the local administrator, a package must
4006             not rely on the presence or absence of files or
4007             directories in '/usr/local' for normal operation.</p>
4008
4009           <p>
4010             The <tt>/usr/local</tt> directory itself and all the
4011             subdirectories created by the package should (by default) have
4012             permissions 2775 (group-writable and set-group-id) and be
4013             owned by <tt>root.staff</tt>.</p>
4014         </sect1>
4015       </sect>
4016
4017       <sect>
4018         <heading>Users and groups</heading>
4019
4020         <p>
4021           The Debian system can be configured to use either plain or
4022           shadow passwords.</p>
4023
4024         <p>
4025           Some user ids (UIDs) and group ids (GIDs) are reserved
4026           globally for use by certain packages.  Because some packages
4027           need to include files which are owned by these users or
4028           groups, or need the ids compiled into binaries, these ids
4029           must be used on any Debian system only for the purpose for
4030           which they are allocated. This is a serious restriction, and
4031           we should avoid getting in the way of local administration
4032           policies. In particular, many sites allocate users and/or
4033           local system groups starting at 100.</p>
4034
4035         <p>
4036           Apart from this we should have dynamically allocated ids,
4037           which should by default be arranged in some sensible
4038           order--but the behavior should be configurable.</p>
4039
4040         <p>
4041           Packages other than <tt>base-passwd</tt> must not modify
4042           <tt>/etc/passwd</tt>, <tt>/etc/shadow</tt>,
4043           <tt>/etc/group</tt> or <tt>/etc/gshadow</tt>.</p>
4044
4045         <p>
4046           The UID and GID ranges are as follows:
4047           <taglist>
4048             <tag>0-99:</tag>
4049             <item>
4050               <p>
4051                 Globally allocated by the Debian project, the
4052                 same on every Debian system.  These ids will appear in
4053                 the <tt>passwd</tt> and <tt>group</tt> files of all
4054                 Debian systems, new ids in this range being added
4055                 automatically as the <tt>base-passwd</tt> package is
4056                 updated.</p>
4057
4058               <p>
4059                 Packages which need a single statically allocated uid
4060                 or gid should use one of these; their maintainers
4061                 should ask the <tt>base-passwd</tt> maintainer for
4062                 ids.</p>
4063             </item>
4064
4065             <tag>100-999:</tag>
4066             <item>
4067               <p>
4068                 Dynamically allocated system users and groups.
4069                 Packages which need a user or group, but can have this
4070                 user or group allocated dynamically and differently on
4071                 each system, should use `<tt>adduser --system</tt>' to
4072                 create the group and/or user.  <prgn>adduser</prgn>
4073                 will check for the existence of the user or group, and
4074                 if necessary choose an unused id based on the ranges
4075                 specified in <tt>adduser.conf</tt>.</p></item>
4076
4077
4078             <tag>1000-29999:</tag>
4079             <item>
4080               <p>
4081                 Dynamically allocated user accounts.  By default
4082                 <prgn>adduser</prgn> will choose UIDs and GIDs for
4083                 user accounts in this range, though
4084                 <tt>adduser.conf</tt> may be used to modify this
4085                 behavior.</p>
4086             </item>
4087
4088             <tag>30000-59999:</tag>
4089             <item>
4090               <p>Reserved.</p></item>
4091
4092
4093             <tag>60000-64999:</tag>
4094             <item>
4095               <p>
4096                 Globally allocated by the Debian project, but only
4097                 created on demand. The ids are allocated centrally and
4098                 statically, but the actual accounts are only created
4099                 on users' systems on demand.</p>
4100
4101               <p>
4102                 These ids are for packages which are obscure or which
4103                 require many statically-allocated ids.  These packages
4104                 should check for and create the accounts in
4105                 <tt>/etc/passwd</tt> or <tt>/etc/group</tt> (using
4106                 <prgn>adduser</prgn> if it has this facility) if
4107                 necessary.  Packages which are likely to require
4108                 further allocations should have a `hole' left after
4109                 them in the allocation, to give them room to
4110                 grow.</p></item>
4111
4112
4113             <tag>65000-65533:</tag>
4114             <item>
4115               <p>Reserved.</p></item>
4116
4117
4118             <tag>65534:</tag>
4119             <item>
4120               <p>User `<tt>nobody</tt>.' The corresponding gid refers
4121               to the group  `<tt>nogroup</tt>.'</p></item>
4122
4123
4124             <tag>65535:</tag>
4125             <item>
4126               <p>
4127                 <tt>(uid_t)(-1) == (gid_t)(-1)</tt>. NOT TO BE USED,
4128                 because it is the error return sentinel value.</p>
4129             </item>
4130           </taglist>
4131         </p>
4132       </sect>
4133       <sect id="sysvinit">
4134         <heading>System run levels</heading>
4135
4136
4137         <sect1 id="/etc/init.d">
4138           <heading>Introduction</heading>
4139
4140           <p>
4141             The <tt>/etc/init.d</tt> directory contains the scripts
4142             executed by <prgn>init</prgn> at boot time and when init
4143             state (or `runlevel') is changed (see <manref name="init"
4144                                                           section="8">).</p>
4145
4146           <p>
4147             There are at least two different, yet functionally
4148             equivalent, ways of handling these scripts.  For the sake
4149             of simplicity, this document describes only the symbolic
4150             link method. However, it must not be assumed by maintainer
4151             scripts that this method is being used, and any automated
4152             manipulation of the various runlevel behaviours by
4153             maintainer scripts must be performed using `update-rc.d'
4154             as described below and not by manually installing or
4155             removing symlinks.  For  information on the
4156             implementation details of the other method, implemented in
4157             the <tt>file-rc</tt> package, please refer to the
4158             documentation of that package.</p>
4159
4160           <p>
4161             These scripts are referenced by symbolic links in
4162             the <tt>/etc/rc<var>n</var>.d</tt> directories.  When
4163             changing runlevels, <prgn>init</prgn> looks in the
4164             directory <tt>/etc/rc<var>n</var>.d</tt> for the scripts
4165             it should execute, where <var>n</var> is the runlevel that
4166             is being changed to, or `S' for the boot-up scripts.</p>
4167
4168           <p>
4169             The names of the links all have the form
4170             <tt>S<var>mm</var><var>script</var></tt> or
4171             <tt>K<var>mm</var><var>script</var></tt> where
4172             <var>mm</var> is a two-digit number and <var>script</var>
4173             is the name of the script (this should be the same as the
4174             name of the actual script in <tt>/etc/init.d</tt>.</p>
4175
4176           <p>
4177             When <prgn>init</prgn> changes runlevel first the targets
4178             of the links whose names starting with a <tt>K</tt> are
4179             executed, each with the single argument <tt>stop</tt>,
4180             followed by the scripts prefixed with an <tt>S</tt>, each
4181             with the single argument <tt>start</tt>.  The <tt>K</tt>
4182             links are responsible for killing services and the
4183             <tt>S</tt> link for starting services upon entering the
4184             runlevel.</p>
4185
4186           <p>
4187             For example, if we are changing from runlevel 2 to
4188             runlevel 3, init will first execute all of the <tt>K</tt>
4189             prefixed scripts it finds in <tt>/etc/rc3.d</tt>, and then
4190             all of the <tt>S</tt> prefixed scripts.  The links
4191             starting with <tt>K</tt> will cause the referred-to file
4192             to be executed with an argument of <tt>stop</tt>, and the
4193             <tt>S</tt> links with an argument of <tt>start</tt>.</p>
4194
4195           <p>
4196             The two-digit number <var>mm</var> is used to decide which
4197             order to start and stop things in--low-numbered links have
4198             their scripts run first.  For example, the <tt>K20</tt>
4199             scripts will be executed before the <tt>K30</tt> scripts.
4200             This is used when a certain service must be started before
4201             another.  For example, the name server <prgn>bind</prgn>
4202             might need to be started before the news server
4203             <prgn>inn</prgn> so that <prgn>inn</prgn> can set up its
4204             access lists.  In this case, the script that starts
4205             <prgn>bind</prgn> would have a lower number than the
4206             script that starts <prgn>inn</prgn> so that it runs first:
4207             <example>
4208               /etc/rc2.d/S17bind
4209               /etc/rc2.d/S70inn
4210             </example>
4211           </p>
4212         </sect1>
4213
4214         <sect1>
4215           <heading>Writing the scripts</heading>
4216
4217           <p>
4218             Packages that include daemons for system services should
4219             place scripts in <tt>/etc/init.d</tt> to start or stop
4220             services at boot time or during a change of runlevel.
4221             These scripts should be named
4222             <tt>/etc/init.d/<var>package</var></tt>, and they should
4223             accept one argument, saying what to do:
4224
4225             <taglist>
4226               <tag><tt>start</tt></tag>
4227               <item><p>start the service,</p></item>
4228
4229               <tag><tt>stop</tt></tag>
4230               <item><p>stop the service,</p></item>
4231
4232               <tag><tt>restart</tt></tag>
4233               <item><p>stop and restart the service,</p></item>
4234
4235               <tag><tt>reload</tt></tag>
4236               <item><p>cause the configuration of the service to be
4237                   reloaded without actually stopping and restarting
4238                   the service,</p></item>
4239
4240               <tag><tt>force-reload</tt></tag> <item><p>cause the
4241                   configuration to be reloaded if the service supports
4242                   this, otherwise restart the service.</p></item>
4243             </taglist>
4244
4245             The <tt>start</tt>, <tt>stop</tt>, <tt>restart</tt>, and
4246             <tt>force-reload</tt> options should be supported by all
4247             scripts in <tt>/etc/init.d</tt>, the <tt>reload</tt>
4248             option is optional.</p>
4249
4250           <p>
4251             The <tt>init.d</tt> scripts should ensure that they will
4252             behave sensibly if invoked with <tt>start</tt> when the
4253             service is already running, or with <tt>stop</tt> when it
4254             isn't, and that they don't kill unfortunately-named user
4255             processes.  The best way to achieve this is usually to use
4256             <prgn>start-stop-daemon</prgn>.</p>
4257
4258           <p>
4259             If a service reloads its configuration automatically (as
4260             in the case of <prgn>cron</prgn>, for example), the
4261             <tt>reload</tt> option of the <tt>init.d</tt> script
4262             should behave as if the configuration has been reloaded
4263             successfully.</p>
4264
4265           <p>
4266             These scripts should not fail obscurely when the
4267             configuration files remain but the package has been
4268             removed, as configuration files remain on the system after
4269             the package has been removed. Only when <prgn>dpkg</prgn>
4270             is executed with the <tt>--purge</tt> option will
4271             configuration files be removed. In particular, the init
4272             script itself is usually a configuration file (see
4273             <ref id="init.d notes">), and will remain on the system if
4274             the package is removed but not purged. Therefore, you
4275             should include a <tt>test</tt> statement at the top of the
4276             script, like this:
4277             <example>
4278               test -f <var>program-executed-later-in-script</var> || exit 0
4279             </example></p>
4280
4281           <p>
4282             Often there are some values in the `<tt>init.d</tt>'
4283             scripts that a system administrator will frequently want
4284             to change. While the scripts are frequently conffiles,
4285             modifying them requires that the administrator merge in
4286             their changes each time the package is upgraded and the
4287             conffile changes. To ease the burden on the system
4288             administrator, such configurable values should not be
4289             placed directly in the script.  Instead, they should be
4290             placed in a file in `<tt>/etc/default</tt>', which
4291             typically will have the same base name as the
4292             `<tt>init.d</tt>' script. This extra file can be sourced
4293             by the script when the script runs. It must contain only
4294             variable settings and comments.
4295           </p>
4296
4297           <p>
4298             To ensure that vital configurable values are always
4299             available, the `<tt>init.d</tt>' script should set default
4300             values for each of the shell variables it uses before
4301             sourcing the <tt>/etc/default/</tt> file. Also, since the
4302             `<tt>/etc/default/</tt>' file is often a conffile, the
4303             `<tt>init.d</tt>' script must behave sensibly without
4304             failing if it is deleted.
4305           </p>
4306
4307         </sect1>
4308
4309         <sect1>
4310           <heading>Managing the links</heading>
4311
4312           <p>
4313             The program <prgn>update-rc.d</prgn> is provided to make
4314             it easier for package maintainers to arrange for the
4315             proper creation and removal of
4316             <tt>/etc/rc<var>n</var>.d</tt> symbolic links, or their
4317             functional equivalent if another method is being used.
4318             This may be used by maintainers in their packages'
4319             <tt>postinst</tt> and <tt>postrm</tt> scripts.</p>
4320
4321           <p>
4322             You must use this script to make changes to
4323             <tt>/etc/rc<var>n</var>.d</tt> and <em>never</em> either
4324             include any <tt>/etc/rc<var>n</var>.d</tt> symbolic links
4325             in the actual archive or manually create or remove the
4326             symbolic links in maintainer scripts.  (The latter will
4327             fail if an alternative method of maintaining runlevel
4328             information is being used.)</p>
4329
4330           <p>
4331             By default <prgn>update-rc.d</prgn> will start services in
4332             each of the multi-user state runlevels (2, 3, 4, and 5)
4333             and stop them in the halt runlevel (0), the single-user
4334             runlevel (1) and the reboot runlevel (6).  The system
4335             administrator will have the opportunity to customize
4336             runlevels by either running <prgn>update-rc.d</prgn>, by
4337             simply adding, moving, or removing the symbolic links in
4338             <tt>/etc/rc<var>n</var>.d</tt> if symbolic links are being
4339             used, or by modifying <tt>/etc/runlevel.conf</tt> if the
4340             <tt>file-rc</tt> method is being used.</p>
4341
4342           <p>
4343             To get the default behavior for your package, put in your
4344             <tt>postinst</tt> script
4345             <example>
4346               update-rc.d <var>package</var> defaults &gt;/dev/null
4347             </example>
4348             and in your <tt>postrm</tt>
4349             <example>
4350               if [ purge = "$1" ]; then
4351               update-rc.d <var>package</var> remove &gt;/dev/null
4352               fi
4353             </example></p>
4354
4355           <p>
4356             This will use a default sequence number of 20.  If it does
4357             not matter when or in which order the script is run, use
4358             this default.  If it does, then you should talk to the
4359             maintainer of the <prgn>sysvinit</prgn> package or post to
4360             <tt>debian-devel</tt>, and they will help you choose a
4361             number.</p>
4362
4363           <p>
4364             For more information about using <tt>update-rc.d</tt>,
4365             please consult its manpage <manref name="update-rc.d"
4366                                                section="8">.</p></sect1>
4367
4368
4369         <sect1>
4370           <heading>Boot-time initialization</heading>
4371
4372           <p>
4373             There used to be another directory, <tt>/etc/rc.boot</tt>,
4374             which contained scripts which were run once per machine
4375             boot. This has been deprecated in favour of links from
4376             <tt>/etc/rcS.d</tt> to files in <tt>/etc/init.d</tt> as
4377             described in <ref id="/etc/init.d">.  Packages must not
4378             place files in <tt>/etc/rc.boot</tt>.</p>
4379
4380         <sect1 id="init.d notes">
4381           <heading>Notes</heading>
4382
4383           <p>
4384             <em>Do not</em> include the
4385             <tt>/etc/rc<var>n</var>.d/*</tt> symbolic links in the
4386             <tt>.deb</tt> file system archive!  <em>This will cause
4387               problems!</em> You must create them with
4388             <prgn>update-rc.d</prgn>, as above.</p>
4389
4390           <p>
4391             <em>Do not</em> include the
4392             <tt>/etc/rc<var>n</var>.d/*</tt> symbolic links in
4393             <prgn>dpkg</prgn>'s conffiles list!  <em>This will cause
4394               problems!</em> You should, however, treat the
4395             <tt>/etc/init.d</tt> scripts as configuration files,
4396             either by marking them as conffiles or managing them
4397             correctly in the maintainer scripts (see
4398             <ref id="config files">). (This is important since we want
4399             to give the local system administrator the chance to adapt
4400             the scripts to the local system--e.g., to disable a
4401             service without de-installing the package, or to specify
4402             some special command line options when starting a
4403             service--while making sure her changes aren't lost during
4404             the next package upgrade.)</p>
4405         </sect1>
4406
4407         <sect1>
4408           <heading>Example</heading>
4409
4410           <p>
4411             The <prgn>bind</prgn> DNS (nameserver) package wants to
4412             make sure that the nameserver is running in multiuser
4413             runlevels, and is properly shut down with the system.  It
4414             puts a script in <tt>/etc/init.d</tt>, naming the script
4415             appropriately <tt>bind</tt>.  As you can see, the script
4416             interprets the argument <tt>reload</tt> to send the
4417             nameserver a <tt>HUP</tt> signal (causing it to reload its
4418             configuration); this way the user can say
4419             <tt>/etc/init.d/bind reload</tt> to reload the name
4420             server.  The script has one configurable value, which can
4421             be used to pass parameters to the named program at
4422             startup.
4423           </p>
4424
4425           <p>
4426             <example>
4427               #!/bin/sh
4428               #
4429               # Original version by Robert Leslie
4430               # &lt;rob@mars.org&gt;, edited by iwj and cs
4431
4432               test -x /usr/sbin/named || exit 0
4433
4434               # Source defaults file.
4435               PARAMS=''
4436               if [ -f /etc/default/bind ]; then
4437                 . /etc/default/bind
4438               fi
4439
4440
4441               case "$1" in
4442               start)
4443               echo -n "Starting domain name service: named"
4444               start-stop-daemon --start --quiet --exec /usr/sbin/named \
4445                                 -- $PARAMS
4446               echo "."
4447               ;;
4448               stop)
4449               echo -n "Stopping domain name service: named"
4450               start-stop-daemon --stop --quiet  \
4451               --pidfile /var/run/named.pid --exec /usr/sbin/named
4452               echo "."
4453               ;;
4454               restart)
4455               echo -n "Restarting domain name service: named"
4456               start-stop-daemon --stop --quiet  \
4457               --pidfile /var/run/named.pid --exec /usr/sbin/named
4458               start-stop-daemon --start --verbose --exec /usr/sbin/named \
4459                                 -- $PARAMS
4460               echo "."
4461               ;;
4462               force-reload|reload)
4463               echo -n "Reloading configuration of domain name service: named"
4464               start-stop-daemon --stop --signal 1 --quiet  \
4465               --pidfile /var/run/named.pid --exec /usr/sbin/named
4466               echo "."
4467               ;;
4468               *)
4469               echo "Usage: /etc/init.d/bind {start|stop|restart|reload|force-reload}" >&2
4470               exit 1
4471               ;;
4472               esac
4473
4474               exit 0
4475             </example>
4476           </p>
4477
4478           <p>
4479             Complementing the above init script is a file
4480             '<tt>/etc/default/bind</tt>', which contains configurable
4481             parameters used by the script.
4482           </p>
4483           <p>
4484             <example>
4485               # Specified parameters to pass to named. See named(8).
4486               # You may uncomment the following line, and edit to taste.
4487               #PARAMS="-u nobody"
4488             </example>
4489           </p>
4490
4491           <p>
4492             Another example on which to base your <tt>/etc/init.d</tt>
4493             scripts is in <tt>/etc/init.d/skeleton</tt>.</p>
4494
4495           <p>
4496             If this package is happy with the default setup from
4497             <prgn>update-rc.d</prgn>, namely an ordering number of 20
4498             and having named running in all runlevels, it can say in
4499             its <tt>postinst</tt>:
4500             <example>
4501               update-rc.d bind defaults >/dev/null
4502             </example>
4503             And in its <tt>postrm</tt>, to remove the links when the
4504             package is purged:
4505             <example>
4506               if [ purge = "$1" ]; then
4507               update-rc.d bind remove >/dev/null
4508               fi
4509             </example></p>
4510         </sect1></sect>
4511
4512       <sect>
4513         <heading>Cron jobs</heading>
4514
4515         <p>
4516           Packages must not modify the configuration file
4517           <tt>/etc/crontab</tt>, and they must not modify the files in
4518           <tt>/var/spool/cron/crontabs</tt>.</p>
4519
4520         <p>
4521           If a package wants to install a job that has to be executed
4522           via cron, it should place a file with the name of the
4523           package in one of the following directories:
4524           <example>
4525             /etc/cron.daily
4526             /etc/cron.weekly
4527             /etc/cron.monthly
4528           </example>
4529           As these directory names imply, the files within them are
4530           executed on a daily, weekly, or monthly basis,
4531           respectively. The exact times are listed in
4532           <tt>/etc/crontab</tt>.</p>
4533
4534         <p>
4535           All files installed in any of these directories must be
4536           scripts (shell scripts, Perl scripts, etc.) so that they can
4537           easily be modified by the local system administrator. In
4538           addition, they should be treated as configuration files.</p>
4539
4540         <p>
4541           If a certain job has to be executed more frequently than
4542           daily, the package should install a file
4543           <tt>/etc/cron.d/<var>package-name</var></tt>. This file uses
4544           the same syntax as <tt>/etc/crontab</tt> and is processed by
4545           <prgn>cron</prgn> automatically. The file must also be
4546           treated as a configuration file. (Note, that entries in the
4547           <tt>/etc/cron.d</tt> directory are not handled by
4548           <prgn>anacron</prgn>. Thus, you should only use this
4549           directory for jobs which may be skipped if the system is not
4550           running.)</p>
4551
4552         <p>
4553           The scripts or crontab entries in these directories should
4554           check if all necessary programs are installed before they
4555           try to execute them. Otherwise, problems will arise when a
4556           package was removed but not purged since configuration files
4557           are kept on the system in this situation.</p>
4558       </sect>
4559
4560       <sect>
4561         <heading>Console messages</heading>
4562
4563         <p>
4564           This section describes different formats for messages
4565           written to standard output by the <tt>/etc/init.d</tt>
4566           scripts. The intent is to improve the consistency of
4567           Debian's startup and shutdown look and feel.</p>
4568
4569         <p>
4570           Please look very careful at the details. We want to get the
4571           messages to look exactly the same way concerning spaces,
4572           punctuation, and case of letters.</p>
4573
4574         <p>
4575           Here is a list of overall rules that you should use when you
4576           create output messages. They can be useful if you have a
4577           non-standard message that isn't covered in the sections
4578           below.</p>
4579
4580         <p>
4581           <list>
4582             <item>
4583               <p>
4584                 Every message should cover one line, start with a
4585                 capital letter and end with a period `.'.</p></item>
4586
4587
4588             <item>
4589               <p>
4590                 If you want to express that the computer is working on
4591                 something (performing a specific task, not starting or
4592                 stopping a program), we use an ``ellipsis'', namely
4593                 three dots `...'. Note that we don't insert spaces in
4594                 front of or behind the dots.  If the task has been
4595                 completed we write `done.' and a line feed.</p></item>
4596
4597
4598             <item>
4599               <p>
4600                 Design your messages as if the computer is telling you
4601                 what he is doing (let him be polite :-) but don't
4602                 mention ``him'' directly.  For example, if you think
4603                 of saying
4604                 <example>
4605                   I'm starting network daemons: nfsd mountd.
4606                 </example>
4607                 just say
4608                 <example>
4609                   Starting network daemons: nfsd mountd.
4610                 </example></p></item>
4611           </list></p>
4612
4613         <p>
4614           The following formats should be used</p>
4615
4616         <p>
4617           <list>
4618             <item>
4619               <p>when daemons get started.</p>
4620
4621               <p>
4622                 Use this format if your script starts one or more
4623                 daemons.  The output should look like this (a single
4624                 line, no leading spaces):
4625                 <example>
4626                   Starting &lt;description&gt;: &lt;daemon-1&gt; &lt;daemon-2&gt; &lt;...&gt; &lt;daemon-n&gt;.
4627                 </example>
4628                 The &lt;description&gt; should describe the subsystem
4629                 the daemon or set of daemons are part of, while
4630                 &lt;daemon-1&gt; up to &lt;daemon-n&gt; denote each
4631                 daemon's name (typically the file name of the
4632                 program).</p>
4633
4634               <p>
4635                 For example, the output of /etc/init.d/lpd would look like:
4636                 <example>
4637                   Starting printer spooler: lpd.
4638                 </example></p>
4639
4640               <p>
4641                 This can be achieved by saying
4642                 <example>
4643                   echo -n "Starting printer spooler: lpd"
4644                   start-stop-daemon --start --quiet lpd
4645                   echo "."
4646                 </example>
4647                 in the script. If you have more than one daemon to
4648                 start, you should do the following:
4649                 <example>
4650                   echo -n "Starting remote file system services:"
4651                   echo -n " nfsd"; start-stop-daemon --start --quiet nfsd
4652                   echo -n " mountd"; start-stop-daemon --start --quiet mountd
4653                   echo -n " ugidd"; start-stop-daemon --start --quiet ugidd
4654                   echo "."
4655                 </example>
4656                 This makes it possible for the user to see what takes
4657                 so long and when the final daemon has been
4658                 started. You should be careful where to put spaces: In the
4659                 example above the system administrator can easily
4660                 comment out a line if he don't wants to start a
4661                 specific daemon, while the displayed message still
4662                 looks good.</p></item>
4663
4664
4665             <item>
4666               <p>when something needs to be configured.</p>
4667
4668               <p>
4669                 If you have to set up different parameters of the
4670                 system upon boot up, you should use this format:
4671                 <example>
4672                   Setting &lt;parameter&gt; to `&lt;value&gt;'.
4673                 </example></p>
4674
4675               <p>
4676                 You can use the following echo statement to get the quotes right:
4677                 <example>
4678                   echo "Setting DNS domainname to \`"value"'."
4679                 </example></p>
4680
4681               <p>
4682                 Note that the left quotation mark (`) is different
4683                 from the right (').</p></item>
4684
4685             <item>
4686               <p>when a daemon is stopped.</p>
4687
4688               <p>
4689                 When you stop a daemon you should issue a message
4690                 similar to the startup message, except that `Starting'
4691                 is replaced with `Stopping'.</p>
4692
4693               <p>
4694                 So stopping the printer daemon will like like this:
4695                 <example>
4696                   Stopping printer spooler: lpd.
4697                 </example></p></item>
4698
4699             <item>
4700               <p>when something is executed.</p>
4701
4702               <p>
4703                 There are several examples where you have to run a
4704                 program at system startup or shutdown to perform a
4705                 specific task. For example, setting the system's clock
4706                 via `netdate' or killing all processes when the system
4707                 comes down. Your message should like this:
4708                 <example>
4709                   Doing something very useful...done.
4710                 </example>
4711                 You should print the `done.' right after the job has been completed,
4712                 so that the user gets informed why he has to wait. You can get this
4713                 behavior by saying
4714                 <example>
4715                   echo -n "Doing something very useful..."
4716                   do_something
4717                   echo "done."
4718                 </example>
4719                 in your script.</p></item>
4720
4721             <item>
4722               <p>when the configuration is reloaded.</p>
4723
4724               <p>
4725                 When a daemon is forced to reload its configuration
4726                 files you should use the following format:
4727                 <example>
4728                   Reloading &lt;daemon's-name&gt; configuration...done.
4729                 </example></p></item>
4730
4731             <item>
4732               <p>when none of the above rules apply.</p>
4733
4734               <p>
4735                 If you have to print a message that doesn't fit into
4736                 the styles described above, you can use something
4737                 appropriate, but please have a look at the overall
4738                 rules listed above.</p></item>
4739           </list></p></sect>
4740
4741
4742       <sect>
4743         <heading>Menus</heading>
4744
4745         <p>
4746           Menu entries should follow the current menu policy as
4747           defined in the file <ftpsite>ftp.debian.org</ftpsite> in
4748           <ftppath>/debian/doc/package-developer/menu-policy.txt.gz</ftppath>
4749           or your local mirror. In addition, it is included in the
4750           <tt>debian-policy</tt> package.
4751         </p>
4752
4753         <p>
4754           The Debian <tt>menu</tt> packages provides a unique
4755           interface between packages providing applications and
4756           documents, and <em>menu programs</em> (either X window
4757           managers or text-based menu programs as
4758           <prgn>pdmenu</prgn>).</p>
4759
4760         <p>
4761           All packages that provide applications that need not be
4762           passed any special command line arguments for normal
4763           operation should register a menu entry for those
4764           applications, so that users of the <tt>menu</tt> package
4765           will automatically get menu entries in their window
4766           managers, as well in shells like <tt>pdmenu</tt>.</p>
4767
4768         <p>
4769           Please refer to the <em>Debian Menu System</em> document
4770           that comes with the <tt>menu</tt> package for information
4771           about how to register your applications and web
4772           documents.</p>
4773       </sect>
4774
4775
4776       <sect>
4777         <heading>Multimedia handlers</heading>
4778
4779         <p>
4780           Packages which provide the ability to view/show/play,
4781           compose, edit or print MIME types should register themselves
4782           as such following the current MIME support policy as defined
4783           in the file found on <ftpsite>ftp.debian.org</ftpsite> in
4784           <ftppath>/debian/doc/package-developer/mime-policy.txt.gz</ftppath>
4785           or your local mirror. In addition, it is included in the
4786           <tt>debian-policy</tt> package.
4787         </p>
4788
4789         <p>
4790           MIME (Multipurpose Internet Mail Extensions, RFC 1521) is a
4791           mechanism for encoding files and data streams and providing
4792           meta-information about them, in particular their type (e.g.
4793           audio or video) and format (e.g. PNG, HTML, MP3).
4794         </p>
4795
4796         <p>
4797           Registration of MIME type handlers allows programs like mail
4798           user agents and web browsers to to invoke these handlers to
4799           view, edit or display MIME types they don't support
4800           directly.
4801         </p>
4802       </sect>
4803
4804       <sect>
4805         <heading>Keyboard configuration</heading>
4806
4807         <p>
4808           To achieve a consistent keyboard configuration (i.e., all
4809           applications interpret a keyboard event the same way) all
4810           programs in the Debian distribution must be configured to
4811           comply with the following guidelines.</p>
4812
4813         <p>
4814           Here is a list that contains certain keys and their interpretation:
4815
4816           <taglist>
4817             <tag><tt>&lt;--</tt></tag>
4818             <item><p>delete the character to the left of the cursor</p></item>
4819
4820             <tag><tt>Delete</tt></tag>
4821             <item><p>delete the character to the right of the cursor</p></item>
4822
4823             <tag><tt>Control+H</tt></tag>
4824             <item><p>emacs: the help prefix</p></item>
4825           </taglist>
4826
4827           The interpretation of any keyboard events should be independent
4828           of the terminal that's used, be it a virtual console, an X
4829           terminal emulator, an rlogin/telnet session, etc.</p>
4830
4831         <p>
4832           The following list explains how the different programs
4833           should be set up to achieve this:</p>
4834
4835         <p>
4836           <list compact="compact">
4837             <item><p>`<tt>&lt;--</tt>' generates KB_Backspace in
4838                 X.</p></item>
4839
4840             <item><p>`<tt>Delete</tt>' generates KB_Delete in X.</p></item>
4841
4842             <item>
4843               <p>
4844                 X translations are set up to make KB_Backspace
4845                 generate ASCII DEL, and to make KB_Delete generate
4846                 <tt>ESC [ 3 ~</tt> (this is the vt220 escape code for
4847                 the `delete character' key).  This must be done by
4848                 loading the resources using xrdb on all local X
4849                 displays, not using the application defaults, so that
4850                 the translation resources used correspond to the
4851                 xmodmap settings.</p></item>
4852
4853             <item>
4854               <p>
4855                 The Linux console is configured to make
4856                 `<tt>&lt;--</tt>' generate DEL, and `Delete' generate
4857                 <tt>ESC [ 3 ~</tt> (this is the case at the
4858                 moment).</p></item>
4859
4860             <item><p>
4861                 X applications are configured so that Backspace
4862                 deletes left, and Delete deletes right.  Motif
4863                 applications already work like this.</p></item>
4864
4865             <item><p>stty erase <tt>^?</tt> .</p></item>
4866
4867             <item><p>
4868                 The `xterm' terminfo entry should have <tt>ESC [ 3
4869                   ~</tt> for kdch1, just like TERM=linux and
4870                 TERM=vt220.</p></item>
4871
4872             <item><p>
4873                 Emacs is programmed to map KB_Backspace or the `stty
4874                 erase' character to delete-backward-char, and
4875                 KB_Delete or kdch1 to delete-forward-char, and
4876                 <tt>^H</tt> to help as always.</p></item>
4877
4878             <item><p>
4879                 Other applications use the `stty erase' character and
4880                 kdch1 for the two delete keys, with ASCII DEL being
4881                 `delete previous character' and kdch1 being `delete
4882                 character under cursor'.</p></item>
4883           </list></p>
4884
4885         <p>
4886           This will solve the problem except for:</p>
4887
4888         <p>
4889           <list compact="compact">
4890             <item><p>
4891                 Some terminals have a <tt>&lt;--</tt> key that cannot
4892                 be made to produce anything except <tt>^H</tt>.  On
4893                 these terminals Emacs help will be unavailable on
4894                 <tt>^H</tt> (assuming that the `stty erase' character
4895                 takes precedence in Emacs, and has been set
4896                 correctly).  M-x help or F1 (if available) can be used
4897                 instead.</p></item>
4898
4899             <item><p>
4900                 Some operating systems use <tt>^H</tt> for stty erase.
4901                 However, modern telnet versions and all rlogin
4902                 versions propagate stty settings, and almost all UNIX
4903                 versions honour stty erase.  Where the stty settings
4904                 are not propagated correctly things can be made to
4905                 work by using stty manually.</p></item>
4906
4907             <item><p>
4908                 Some systems (including previous Debian versions) use
4909                 xmodmap to arrange for both <tt>&lt;--</tt> and Delete
4910                 to generate KB_Delete.  We can change the behavior
4911                 of their X clients via the same X resources that we
4912                 use to do it for our own, or have our clients be
4913                 configured via their resources when things are the
4914                 other way around.  On displays configured like this
4915                 Delete will not work, but <tt>&lt;--</tt>
4916                 will.</p></item>
4917
4918             <item><p>
4919                 Some operating systems have different kdch1 settings
4920                 in their terminfo for xterm and others.  On these
4921                 systems the Delete key will not work correctly when
4922                 you log in from a system conforming to our policy, but
4923                 <tt>&lt;--</tt> will.</p></item>
4924           </list>
4925         </p>
4926       </sect>
4927
4928
4929       <sect>
4930         <heading>Environment variables</heading>
4931
4932         <p>
4933           A program must not depend on environment variables to get
4934           reasonable defaults. (That's because these environment
4935           variables would have to be set in a system-wide
4936           configuration file like /etc/profile, which is not supported
4937           by all shells.)</p>
4938
4939         <p>
4940           If a program usually depends on environment variables for its
4941           configuration, the program should be changed to fall back to
4942           a reasonable default configuration if these environment
4943           variables are not present. If this cannot be done easily
4944           (e.g., if the source code of a non-free program is not
4945           available), the program must be replaced by a small
4946           `wrapper' shell script which sets the environment variables
4947           if they are not already defined, and calls the original program.</p>
4948
4949         <p>
4950           Here is an example of a wrapper script for this purpose:
4951
4952           <example>
4953             #!/bin/sh
4954             BAR=${BAR:-/var/lib/fubar}
4955             export BAR
4956             exec /usr/lib/foo/foo "$@"
4957           </example></p>
4958
4959         <p>
4960           Furthermore, as <tt>/etc/profile</tt> is a configuration
4961           file of the <prgn>base-files</prgn> package, other packages must not
4962           put any environment variables or other commands into that
4963           file.</p>
4964       </sect>
4965     </chapt>
4966     <chapt>
4967       <heading>Files</heading>
4968
4969
4970       <sect>
4971         <heading>Binaries</heading>
4972
4973         <p>
4974           Two different packages must not install programs with
4975           different functionality but with the same filenames. (The
4976           case of two programs having the same functionality but
4977           different implementations is handled via `alternatives.')
4978           If this case happens, one of the programs must be
4979           renamed. The maintainers should report this to the
4980           developers' mailing and try to find a consensus about
4981           which package will have to be renamed.  If a consensus can
4982           not be reached, <em>both</em> programs must be
4983           renamed.</p>
4984
4985         <p>
4986           Generally the following compilation parameters should be used:
4987           <example>
4988             CC = gcc
4989             CFLAGS = -O2 -Wall # sane warning options vary between programs
4990             LDFLAGS = # none
4991             install -s # (or use strip on the files in debian/tmp)
4992           </example></p>
4993
4994         <p>
4995           Note that by default all installed binaries should be stripped,
4996           either by using the <tt>-s</tt> flag to
4997           <prgn>install</prgn>, or by calling <prgn>strip</prgn> on
4998           the binaries after they have been copied into
4999           <tt>debian/tmp</tt> but before the tree is made into a
5000           package.</p>
5001
5002         <p>
5003           The <tt>-N</tt> flag should not be used.  On a.out systems
5004           it may have been useful for some very small binaries, but
5005           for ELF it has no good effect.</p>
5006
5007         <p>
5008           Debugging symbols are useful for error diagnosis,
5009           investigation of core dumps (which may be submitted by users
5010           in bug reports), or testing and developing the
5011           software. Therefore it is recommended to support building
5012           the package with debugging information through the following
5013           interface: If the environment variable
5014           <tt>DEB_BUILD_OPTIONS</tt> contains the string
5015           <tt>debug</tt>, compile the software with debugging
5016           information (usually this involves adding the <tt>-g</tt>
5017           flag to <tt>CFLAGS</tt>). This allows the generation of a
5018           build tree with debugging information. If the environment
5019           variable <tt>DEB_BUILD_OPTIONS</tt> contains the string
5020           <tt>nostrip</tt>, do not strip the files at installation
5021           time. This allows one to generate a package with debugging
5022           information included. The following makefile snippet is only
5023           an example of how one may test for either condition:
5024           <footnote>
5025             <p>
5026               Rationale: Building by default with -g causes more
5027               wasted CPU cycles since the information is stripped away
5028               anyway. The package can by default build without -g if
5029               it also provides a mechanism to easily be rebuilt with
5030               debugging information. This can be done by providing a
5031               "build-debug" make target, or allowing the user to
5032               specify "DEB_BUILD_OPTIONS=debug" in the environment while
5033               compiling that package.
5034             </p>
5035             <p>Now this has several added benefits:
5036               <list>
5037                 <item>
5038                   <p>
5039                     It is actually easier to build debugging bins and
5040                     libraries this way (no more editing debian/rules
5041                     or similar) since it provides a documented way of
5042                     getting this type of build.</p>
5043                 </item>
5044                 <item>
5045                   <p>
5046                     There will be much less wasted CPU time for the
5047                     autobuilders since not having debugging
5048                     information (and hence also not having to strip
5049                     it) will increase the speed of compiles. This
5050                     skips an entire pass of the compiler.
5051                   </p>
5052                 </item>
5053               </list>
5054             </p>
5055           </footnote>
5056
5057
5058           <example>
5059             CFLAGS = -O2 -Wall
5060             INSTALL = install
5061             INSTALL_FILE    = $(INSTALL) -p    -o root -g root  -m  644
5062             INSTALL_PROGRAM = $(INSTALL) -p    -o root -g root  -m  755
5063             INSTALL_SCRIPT  = $(INSTALL) -p    -o root -g root  -m  755
5064             INSTALL_DIR     = $(INSTALL) -p -d -o root -g root  -m  755
5065
5066             ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
5067             CFLAGS += -g
5068             endif
5069             ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
5070             INSTALL_PROGRAM += -s
5071             endif
5072           </example>
5073
5074           Please note that the above example is merely informative,
5075           and is not a policy mandate. You may have to massage this
5076           example in order to make it work for your package.
5077
5078         </p>
5079
5080         <p>
5081           It is up to the package maintainer to decide what
5082           compilation options are best for the package.  Certain
5083           binaries (such as computationally-intensive programs) will
5084           function better with certain flags (<tt>-O3</tt>, for
5085           example); feel free to use them.  Please use good judgment
5086           here.  Don't use flags for the sake of it; only use them
5087           if there is good reason to do so.  Feel free to override
5088           the upstream author's ideas about which compilation
5089           options are best--they are often inappropriate for our
5090           environment.</p></sect>
5091
5092
5093       <sect>
5094         <heading>Libraries</heading>
5095
5096         <p>
5097           All libraries must have a shared version in the lib
5098           package and a static version in the lib-dev package. The
5099           shared version must be compiled with <tt>-fPIC</tt>, and
5100           the static version must not be. In other words, each
5101           <tt>*.c</tt> file will need to be compiled twice.</p>
5102
5103         <p>
5104           You must specify the gcc option <tt>-D_REENTRANT</tt>
5105           when building a library (either static or shared) to make
5106           the library compatible with LinuxThreads.</p>
5107
5108         <p>
5109           Note that all installed shared libraries should be
5110           stripped with
5111           <example>
5112             strip --strip-unneeded &lt;your-lib&gt;
5113           </example>
5114           (The option `--strip-unneeded' makes <tt>strip</tt> remove
5115           only the symbols which aren't needed for relocation
5116           processing.)  Shared libraries can function perfectly well
5117           when stripped, since the symbols for dynamic linking are
5118           in a separate part of the ELF object file.</p>
5119
5120         <p>
5121           Note that under some circumstances it may be useful to
5122           install a shared library unstripped, for example when
5123           building a separate package to support debugging.
5124         </p>
5125
5126         <p>
5127           An ever increasing number of packages are using libtool to
5128           do their linking. The latest GNU libtools (>= 1.3a) can take
5129           advantage of the metadata in the installed libtool archive
5130           files (`*.la'). The main advantage of libtool's .la files is
5131           that it allows libtool to store and subsequently access
5132           metadata with respect to the libraries it builds.  libtool
5133           will search for those files, which contain a lot of useful
5134           information about a library (e.g. dependency libraries for
5135           static linking). Also, they're <em>essential</em> for
5136           programs using libltdl.
5137         </p>
5138
5139         <p>
5140           Certainly libtool is fully capable of linking against shared
5141           libraries which don't have .la files, but being a mere shell
5142           script it can add considerably to the build time of a
5143           libtool using package if that shell-script has to derive all
5144           this information from first principles for each library every
5145           time it is linked. With the advent of libtool-1.4 (and to a
5146           lesser extent libtool-1.3), the .la files will also store
5147           information about inter-library dependencies which cannot
5148           necessarily be derived after the .la file is deleted.
5149         </p>
5150
5151         <p>
5152           Packages that use libtool to create shared libraries should
5153           include the <em>.la</em> files in the <em>-dev</em>
5154           packages, with the exception that if the package relies on
5155           libtool's <em>libltdl</em> library, in which case the .la
5156           files must go in the run-time library package.  This is a
5157           good idea in general, and especially for static linking
5158           issues.
5159         </p>
5160
5161         <p>
5162           You must make sure that you use only released versions of
5163           shared libraries to build your packages; otherwise other
5164           users will not be able to run your binaries
5165           properly. Producing source packages that depend on
5166           unreleased compilers is also usually a bad
5167           idea.
5168         </p>
5169       </sect>
5170
5171
5172       <sect>
5173         <heading>Shared libraries</heading>
5174
5175         <p>
5176           Packages involving shared libraries should be split up
5177           into several binary packages.</p>
5178
5179         <p>
5180           For a straightforward library which has a development
5181           environment and a runtime kit including just shared
5182           libraries you need to create two packages:
5183           <tt><var>libraryname</var><var>soname</var></tt>
5184           (<var>soname</var> is the shared object name of the shared
5185           library--it's the thing that has to match exactly between
5186           building an executable and running it for the dynamic
5187           linker to be able run the program; usually the
5188           <var>soname</var> is the major number of the library) and
5189           <tt><var>libraryname</var><var>soname</var>-dev</tt>.</p>
5190
5191         <p>
5192           If you prefer only to support one development version at a
5193           time you may name the development package
5194           <tt><var>libraryname</var>-dev</tt>; otherwise you may
5195           wish to use <prgn>dpkg</prgn>'s conflicts mechanism to
5196           ensure that the user only installs one development version
5197           at a time (after all, different development versions are
5198           likely to have the same header files in them, causing a
5199           filename clash if both are installed).  Typically the
5200           development version should  also have an exact version
5201           dependency on the runtime library, to make sure that
5202           compilation and linking happens correctly.</p>
5203
5204         <p>
5205           Packages which use the shared library should have a
5206           dependency on the name of the shared library package,
5207           <tt><var>libraryname</var><var>soname</var></tt>.  When
5208           the <var>soname</var> changes you can have both versions
5209           of the library installed while moving from the old library
5210           to the new.</p>
5211
5212         <p>
5213           If your package has some run-time support programs which
5214           use the shared library you must not put them in
5215           the shared library package.  If you do that then you won't
5216           be able to install several versions of the shared library
5217           without getting filename clashes.  Instead, either create
5218           a third package for the runtime binaries (this package
5219           might typically be named
5220           <tt><var>libraryname</var>-runtime</tt>--note the absence
5221           of the <var>soname</var> in the package name) or if the
5222           development package is small include them in there.</p>
5223
5224         <p>
5225           If you have several shared libraries built from the same
5226           source tree you may lump them all together into a single
5227           shared library package, provided that you change all their
5228           <var>soname</var>s at once (so that you don't get filename
5229           clashes if you try to install different versions of the
5230           combined shared libraries package).</p>
5231
5232         <p>
5233           You should follow the directions in the <em>Debian Packaging
5234             Manual</em> for putting the shared library in its package,
5235           and you must include a <tt>shlibs</tt> control area
5236           file with details of the dependencies for packages which
5237           use the library.</p>
5238
5239         <p>
5240           Shared libraries should not be installed
5241           executable, since <prgn>ld.so</prgn> does not require this
5242           and trying to execute a shared library results in a core
5243           dump.</p></sect>
5244
5245
5246       <sect id="scripts">
5247         <heading>Scripts</heading>
5248
5249         <p>
5250           All command scripts, including the package maintainer
5251           scripts inside the package and used by <prgn>dpkg</prgn>,
5252           should have a <tt>#!</tt> line naming the shell to be used
5253           to interpret them.</p>
5254
5255         <p>
5256           In the case of Perl scripts this should be
5257           <tt>#!/usr/bin/perl</tt>.</p>
5258
5259         <p>
5260           Shell scripts (<prgn>sh</prgn> and <prgn>bash</prgn>)
5261           should almost certainly start with <tt>set -e</tt> so that
5262           errors are detected.  Every script should use
5263           <tt>set -e</tt> or check the exit status of <em>every</em>
5264           command.</p>
5265
5266         <p>
5267           The standard shell interpreter `<tt>/bin/sh</tt>' can be a
5268           symbolic link to any POSIX compatible shell, if <tt>echo
5269             -n</tt> does not generate a newline.
5270           <footnote>
5271             <p>
5272               Debian policy specifies POSIX behavior for /bin/sh, but
5273               echo -n has widespread use in the Linux community
5274               (including especially debian policy, the linux kernel
5275               source, many debian scripts, etc.).  This echo -n
5276               mechanism is valid but not required under POSIX, hence
5277               this explicit addition. Also, rumour has it that this
5278               shall be mandated under the LSB anyway.
5279             </p>
5280           </footnote>
5281           Thus, shell scripts
5282           specifying `<tt>/bin/sh</tt>' as interpreter should only
5283           use POSIX features. If a script requires non-POSIX
5284           features from the shell interpreter, the appropriate shell
5285           must be specified in the first line of the script (e.g.,
5286           `<tt>#!/bin/bash</tt>') and the package must depend on the
5287           package providing the shell (unless the shell package is
5288           marked `Essential', e.g., in the case of
5289           <prgn>bash</prgn>).
5290         </p>
5291
5292         <p>
5293           You may wish to restrict your script to POSIX features when possible so
5294           that it may use <tt>/bin/sh</tt> as its interpreter. If
5295           your script works with <prgn>ash</prgn>, it's probably
5296           POSIX compliant, but if you are in doubt, use
5297           <tt>/bin/bash</tt>.</p>
5298
5299         <p>
5300           Perl scripts should check for errors when making any
5301           system calls, including <tt>open</tt>, <tt>print</tt>,
5302           <tt>close</tt>, <tt>rename</tt> and <tt>system</tt>.</p>
5303
5304         <p>
5305           <prgn>csh</prgn> and <prgn>tcsh</prgn> should be avoided
5306           as scripting languages.  See <em>Csh Programming
5307             Considered Harmful</em>, one of the <tt>comp.unix.*</tt>
5308           FAQs.  It can be found on
5309           <url id="http://language.perl.com/versus/csh.whynot">, or
5310           <url id="http://www.cpan.org/doc/FMTEYEWTK/versus/csh.whynot">
5311           or even on <ftpsite>ftp.cpan.org</ftpsite>
5312           <ftppath>/pub/perl/CPAN/doc/FMTEYEWTK/versus/csh.whynot</ftppath>.
5313           If an upstream package comes with <prgn>csh</prgn> scripts
5314           then you must make sure that they start with
5315           <tt>#!/bin/csh</tt> and make your package depend on the
5316           <prgn>c-shell</prgn> virtual package.</p>
5317
5318         <p>
5319           Any scripts which create files in world-writeable
5320           directories (e.g., in <tt>/tmp</tt>) must use a
5321           mechanism which will fail if a file with the same name
5322           already exists.</p>
5323
5324         <p>
5325           The Debian base distribution provides the
5326           <prgn>tempfile</prgn> and <prgn>mktemp</prgn> utilities
5327           for use by scripts for this purpose.</p></sect>
5328
5329
5330       <sect>
5331         <heading>Symbolic links</heading>
5332
5333         <p>
5334           In general, symbolic links within a top-level directory
5335           should be relative, and symbolic links pointing from one
5336           top-level directory into another should be absolute. (A
5337           top-level directory is a sub-directory of the root
5338           directory `/'.)</p>
5339
5340         <p>
5341           In addition, symbolic links should be specified as short
5342           as possible, i.e., link targets like `foo/../bar' are
5343           deprecated.</p>
5344
5345         <p>
5346           Note that when creating a relative link using
5347           <prgn>ln</prgn> it is not necessary for the target of the
5348           link to exist relative to the working directory you're
5349           running <prgn>ln</prgn> from; nor is it necessary to
5350           change directory to the directory where the link is to be
5351           made.  Simply include the string that should appear as the
5352           target of the link (this will be a pathname relative to
5353           the directory in which the link resides) as the first
5354           argument to <prgn>ln</prgn>.</p>
5355
5356         <p>
5357           For example, in your <prgn>Makefile</prgn> or
5358           <tt>debian/rules</tt>, do things like:
5359           <example>
5360             ln -fs gcc $(prefix)/bin/cc
5361             ln -fs gcc debian/tmp/usr/bin/cc
5362             ln -fs ../sbin/sendmail $(prefix)/bin/runq
5363             ln -fs ../sbin/sendmail debian/tmp/usr/bin/runq
5364           </example></p>
5365
5366         <p>
5367           A symbolic link pointing to a compressed file should
5368           always have the same file extension as the referenced
5369           file. (For example, if a file `<tt>foo.gz</tt>' is
5370           referenced by a symbolic link, the filename of the link
5371           has to end with `<tt>.gz</tt>' too, as in
5372           `bar.gz.')</p></sect>
5373
5374
5375       <sect>
5376         <heading>Device files</heading>
5377
5378         <p>
5379           Packages must not include device files in the package file
5380           tree.</p>
5381
5382         <p>
5383           If a package needs any special device files that are not
5384           included in the base system, it must call
5385           <prgn>MAKEDEV</prgn> in the <tt>postinst</tt> script,
5386           after asking the user for permission to do so.</p>
5387
5388         <p>
5389           Packages must not remove any device files in the
5390           <tt>postrm</tt> or any other script. This is left to the
5391           system administrator.</p>
5392
5393         <p>
5394           Debian uses the serial devices
5395           <tt>/dev/ttyS*</tt>. Programs using the old
5396           <tt>/dev/cu*</tt> devices should be changed to use
5397           <tt>/dev/ttyS*</tt>.</p>
5398       </sect>
5399
5400       <sect id="config files">
5401         <heading>Configuration files</heading>
5402         <sect1>
5403           <heading>Definitions</heading>
5404           <p>
5405             <taglist>
5406               <tag>configuration file</tag>
5407               <item><p>
5408                   A file that affects the operation of program, or
5409                   provides site- or host-specific information, or
5410                   otherwise customizes the behavior of program.
5411                   Typically, configuration files are intended to be
5412                   modified by the system administrator (if needed or
5413                   desired) to conform to local policy or provide more
5414                   useful site-specific behavior.</p>
5415               </item>
5416
5417               <tag><tt>conffile</tt></tag>
5418               <item><p>
5419                   A file listed in a package's <tt>conffiles</tt>
5420                   file, and is treated specially by <prgn>dpkg</prgn>
5421                   (see the <em>Debian Packaging Manual</em>).</p>
5422               </item>
5423             </taglist>
5424           </p>
5425
5426           <p>
5427             The distinction between these two is important; they are
5428             not interchangeable concepts. Almost all
5429             <tt>conffiles</tt> are configuration files, but many
5430             configuration files are not <tt>conffiles</tt>.</p>
5431
5432           <p>
5433             Note that a script that embeds configuration information
5434             (such as most of the files in <tt>/etc/init.d</tt> and
5435             <tt>/etc/cron.{daily,weekly,monthly}</tt>) is de-facto a
5436             configuration file and should be treated as such.</p>
5437         </sect1>
5438
5439         <sect1>
5440           <heading>Location</heading>
5441           <p>
5442             Any configuration files created or used by your package
5443             must reside in <tt>/etc</tt>. If there are several you
5444             should consider creating a subdirectory of <tt>/etc</tt>
5445             named after your package.</p>
5446
5447           <p>
5448             If your package creates or uses configuration files
5449             outside of <tt>/etc</tt>, and it is not feasible to modify
5450             the package to use the <tt>/etc</tt>, you should still put
5451             the files in <tt>/etc</tt> and create symbolic links to
5452             those files from the location that the package
5453             requires.</p>
5454         </sect1>
5455
5456         <sect1>
5457           <heading>Behavior</heading>
5458           <p>
5459             Configuration file handling must conform to the following
5460             behavior:
5461             <list>
5462               <item>
5463                 <p>local changes must be preserved during a package
5464                   upgrade</p>
5465               </item>
5466               <item>
5467                 <p>configuration files must be preserved when the
5468                   package is removed, and only deleted when the
5469                   package is purged.</p>
5470               </item>
5471             </list></p>
5472
5473           <p>
5474             The easy way to achieve this behavior is to make the
5475             configuration file a <tt>conffile</tt>. This is
5476             appropriate only if it is possible to distribute a default
5477             version that will work for most installations, although
5478             some system administrators may choose to modify it. This
5479             implies that the default version will be part of the
5480             package distribution, and must not be modified by the
5481             maintainer scripts during installation (or at any other
5482             time).
5483           </p>
5484
5485           <p>
5486             In order to ensure that local changes are preserved
5487             correctly, no package may contain or make hard links to
5488             conffiles.
5489             <footnote>
5490               <p>
5491                 Rationale: There are two problems with hard links.
5492                 The first is that some editors break the link while
5493                 editing one of the files, so that the two files may
5494                 unwittingly become different.  The second is that
5495                 <prgn>dpkg</prgn> might break the hard link while
5496                 upgrading <tt>conffile</tt>s.
5497               </p>
5498             </footnote>
5499
5500           <p>
5501             The other way to do it is via the maintainer scripts.
5502             In this case, the configuration file must not be listed as
5503             a <tt>conffile</tt> and must not be part of the package
5504             distribution. If the existence of a file is required for
5505             the package to be sensibly configured it is the
5506             responsibility of the package maintainer to write scripts
5507             which correctly create, update, maintain and
5508             remove-on-purge the file. These scripts must be idempotent
5509             (i.e., must work correctly if <prgn>dpkg</prgn> needs to
5510             re-run them due to errors during installation or removal),
5511             must cope with all the variety of ways <prgn>dpkg</prgn>
5512             can call maintainer scripts, must not overwrite or
5513             otherwise mangle the user's configuration without asking,
5514             must not ask unnecessary questions (particularly during
5515             upgrades), and otherwise be good citizens.</p>
5516
5517           <p>
5518             The scripts are not required to configure every possible option for
5519             the package, but only those necessary to get the package
5520             running on a given system. Ideally the sysadmin should not
5521             have to do any configuration other than that done
5522             (semi-)automatically by the <tt>postinst</tt> script.</p>
5523
5524           <p>
5525             A common practice is to create a script called
5526             <tt><var>package</var>-configure</tt> and have the
5527             package's <tt>postinst</tt> call it if and only if the
5528             configuration file does not already exist. In certain
5529             cases it is useful for there to be an example or template
5530             file which the maintainer scripts use. Such files should
5531             be in <tt>/usr/share/doc</tt> if they are examples or
5532             <tt>/usr/lib</tt> if they are templates, and should be
5533             perfectly ordinary <prgn>dpkg</prgn>-handled files
5534             (<em>not</em> <tt>conffiles</tt>).</p>
5535
5536           <p>
5537             These two styles of configuration file handling must
5538             not be mixed, for that way lies madness:
5539             <prgn>dpkg</prgn> will ask about overwriting the file
5540             every time the package is upgraded.</p>
5541
5542         </sect1>
5543
5544         <sect1>
5545           <heading>Sharing configuration files</heading>
5546           <p>
5547             Packages which specify the same file as
5548             `<tt>conffile</tt>' must be tagged as <em>conflicting</em>
5549             with each other.
5550             </p>
5551
5552           <p>
5553             The maintainer scripts must not alter the conffile of
5554             <em>any</em> package, including the one the scripts belong
5555             to.</p>
5556
5557           <p>
5558             If two or more packages use the same configuration file
5559             and it is reasonable for both to be installed at the same
5560             time, one of these packages must be defined as
5561             <em>owner</em> of the configuration file, i.e., it will be
5562             the package to list that distributes the file and lists it
5563             as a <tt>conffile</tt>. Other packages that use the
5564             configuration file must depend on the owning package if
5565             they require the configuration file to operate. If the
5566             other package will use the configuration file if present,
5567             but is capable of operating without it, no dependency need
5568             be declared.</p>
5569
5570           <p>
5571             If it is desirable for two or more related packages to
5572             share a configuration file <em>and</em> for all of the
5573             related packages to be able to modify that configuration
5574             file, then the following should be done:
5575             <enumlist>
5576               <item>
5577                 <p>
5578                   have one of the related packages (the "core"
5579                   package) manage the configuration file with
5580                   maintainer scripts as described in the previous
5581                   section.</p>
5582               </item>
5583               <item><p>
5584                   the core package should also provide a program that
5585                   the other packages may use to modify the
5586                   configuration file.</p>
5587               </item>
5588               <item>
5589                 <p>
5590                   the related packages must use the provided program
5591                   to make any modifications to the configuration file.
5592                   They should either depend on the core package to
5593                   guarantee that the configuration modifier program is
5594                   available or accept gracefully that they cannot
5595                   modify the configuration file if it is not.</p>
5596               </item>
5597             </enumlist></p>
5598
5599           <p>
5600             Sometimes it's appropriate to create a new package which
5601             provides the basic infrastructure for the other packages
5602             and which manages the shared configuration files. (Check
5603             out the <tt>sgml-base</tt> package as an example.)</p>
5604         </sect1>
5605
5606         <sect1>
5607           <heading>User configuration files ("dotfiles")</heading>
5608
5609           <p>
5610             Files in <tt>/etc/skel</tt> will automatically be copied
5611             into new user accounts by <prgn>adduser</prgn>. They
5612             should not be referenced there by any program.</p>
5613
5614           <p>
5615             Therefore, if a program needs a dotfile to exist in
5616             advance in <tt>$HOME</tt> to work sensibly, that dotfile
5617             should be installed in <tt>/etc/skel</tt> (and listed in
5618             conffiles, if it is not generated and modified dynamically
5619             by the package's installation scripts).</p>
5620
5621           <p>
5622             However, programs that require dotfiles in order to
5623             operate sensibly (dotfiles that they do not create
5624             themselves automatically, that is) are a bad thing, and
5625             programs should be configured by the Debian default
5626             installation as close to normal as possible.</p>
5627
5628           <p>
5629             Therefore, if a program in a Debian package needs to be
5630             configured in some way in order to operate sensibly that
5631             configuration should be done in a site-wide global
5632             configuration file elsewhere in <tt>/etc</tt>. Only if the
5633             program doesn't support a site-wide default configuration
5634             and the package maintainer doesn't have time to add it
5635             may a default per-user file be placed in
5636             <tt>/etc/skel</tt>.</p>
5637
5638           <p>
5639             <tt>/etc/skel</tt> should be as empty as we can make it.
5640             This is particularly true because there is no easy
5641             mechanism for ensuring that the appropriate dotfiles are
5642             copied into the accounts of existing users when a package
5643             is installed.</p>
5644         </sect1>
5645       </sect>
5646
5647       <sect>
5648         <heading>Log files</heading>
5649         <p>
5650           The traditional approach to log files has been to set up ad
5651           hoc log rotation schemes using simple shell scripts and
5652           cron. While this approach is highly customizable, it
5653           requires quite a lot of sysadmin work. Even though the
5654           original Debian system helped a little by automatically
5655           installing a system which can be used as a template, this
5656           was deemed not enough.
5657         </p>
5658
5659         <p>
5660           A better scheme is to use logrotate, a GPL'd program
5661           developed by Red Hat, which centralizes log management. It
5662           has both a configuration file (<tt>/etc/logrotate.conf</tt>)
5663           and a directory where packages can drop logrotation info
5664           (<tt>/etc/logrotate.d</tt>).
5665         </p>
5666
5667         <p>
5668           Log files should usually be named
5669           <tt>/var/log/<var>package</var>.log</tt>.  If you have many
5670           log files, or need a separate directory for permissions
5671           reasons (<tt>/var/log</tt> is writable only by
5672           <tt>root</tt>), you should usually create a directory named
5673           <tt>/var/log/<var>package</var></tt>.</p>
5674
5675         <p>
5676           Log files must be rotated occasionally so
5677           that they don't grow indefinitely; the best way to do this
5678           is to drop a script into the directory
5679           <tt>/etc/logrotate.d</tt> and use the facilities provided by
5680           logrotate. Here is a good example for a logrotate config
5681           file (for more information see <manref name="logrotate"
5682                                                  section="8">):
5683           <example>
5684             /var/log/foo/* {
5685             rotate 12
5686             weekly
5687             compress
5688             postrotate
5689             /etc/init.d/foo force-reload
5690             endscript
5691             }
5692           </example>
5693           Which rotates all files under `/var/log/foo', saves 12
5694           compressed generations, and sends a HUP signal at the end of
5695           rotation.
5696
5697         </p>
5698
5699         <p>
5700           Log files should be removed when the package is
5701           purged (but not when it is only removed), by checking the
5702           argument to the <tt>postrm</tt> script (see the <em>Debian
5703             Packaging Manual</em> for details).</p>
5704       </sect>
5705
5706
5707       <sect>
5708         <heading>Permissions and owners</heading>
5709
5710         <p>
5711           The rules in this section are guidelines for general use.
5712           If necessary you may deviate from the details below.
5713           However, if you do so you must make sure that what is done
5714           is secure and you should try to be as consistent as possible
5715           with the rest of the system.  You should probably also
5716           discuss it on <prgn>debian-devel</prgn> first.</p>
5717
5718         <p>
5719           Files should be owned by <tt>root.root</tt>, and made
5720           writable only by the owner and universally readable (and
5721           executable, if appropriate).</p>
5722
5723         <p>
5724           Directories should be mode 755 or (for group-writability)
5725           mode 2775.  The ownership of the directory should be
5726           consistent with its mode--if a directory is mode 2775, it
5727           should be owned by the group that needs write access to
5728           it.</p>
5729
5730         <p>
5731           Setuid and setgid executables should be mode 4755 or 2755
5732           respectively, and owned by the appropriate user or group.
5733           They should not be made unreadable (modes like 4711 or
5734           2711 or even 4111); doing so achieves no extra security,
5735           because anyone can find the binary in the freely available
5736           Debian package--it is merely inconvenient.  For the same
5737           reason you should not restrict read or execute permissions
5738           on non-set-id executables.</p>
5739
5740         <p>
5741           Some setuid programs need to be restricted to particular
5742           sets of users, using file permissions.  In this case they
5743           should be owned by the uid to which they are set-id, and
5744           by the group which should be allowed to execute them.
5745           They should have mode 4754; there is no point in making
5746           them unreadable to those users who must not be allowed to
5747           execute them.</p>
5748
5749         <p>
5750           You must not arrange that the system administrator can only
5751           reconfigure the package to correspond to their local
5752           security policy by changing the permissions on a binary.
5753           Ordinary files installed by <prgn>dpkg</prgn> (as opposed
5754           to conffiles and other similar objects) have their
5755           permissions reset to the distributed permissions when the
5756           package is reinstalled.  Instead you should consider (for
5757           example) creating a group for people allowed to use the
5758           program(s) and making any setuid executables executable
5759           only by that group.</p>
5760
5761         <p>
5762           If you need to create a new user or group for your package
5763           there are two possibilities.  Firstly, you may need to
5764           make some files in the binary package be owned by this
5765           user or group, or you may need to compile the user or
5766           group id (rather than just the name) into the binary
5767           (though this latter should be avoided if possible, as in
5768           this case you need a statically allocated id).</p>
5769
5770         <p>
5771           If you need a statically allocated id, you must ask for a
5772           user or group id from the base system
5773           maintainer, and must not release the package until you
5774           have been allocated one.  Once you have been allocated one
5775           you must make the package depend on a version of the base
5776           system with the id present in <tt>/etc/passwd</tt> or
5777           <tt>/etc/group</tt>, or alternatively arrange for your
5778           package to create the user or group itself with the
5779           correct id (using <tt>adduser</tt>) in its pre- or
5780           post-installation script (the latter is to be preferred if
5781           it is possible).</p>
5782
5783         <p>
5784           On the other hand, the program might be able to determine the
5785           uid or gid from the group name at runtime, so that a
5786           dynamic id can be used.  In this case you should choose an
5787           appropriate user or group name, discussing this on
5788           <prgn>debian-devel</prgn> and checking with the base
5789           system maintainer that it is unique and that they do not
5790           wish you to use a statically allocated id instead.  When
5791           this has been checked you must arrange for your package to
5792           create the user or group if necessary using
5793           <prgn>adduser</prgn> in the pre- or post-installation
5794           script (again, the latter is to be preferred if it is
5795           possible).</p>
5796
5797         <p>
5798           Note that changing the numeric value of an id associated with a name
5799           is very difficult, and involves searching the file system for all
5800           appropriate files.  You need to think carefully whether a static or
5801           dynamic id is required, since changing your mind later will cause
5802           problems.</p>
5803       </sect>
5804     </chapt>
5805
5806     <chapt>
5807       <heading>Customized programs</heading>
5808
5809       <sect id="arch-spec">
5810         <heading>Architecture specification strings</heading>
5811
5812         <p>
5813           If a program needs to specify an <em>architecture specification
5814             string</em> in some place, the following format should be used:
5815           <example>
5816             &lt;arch&gt;-&lt;os&gt;
5817           </example>
5818           where `&lt;arch&gt;' is one of the following: i386, alpha, arm, m68k,
5819           powerpc, sparc and `&lt;os&gt;' is one of: linux, gnu.  Use
5820           of <em>gnu</em> in this string is reserved for the GNU/Hurd
5821           operating system.</p>
5822         <p>
5823           Note, that we don't want to use `&lt;arch&gt;-debian-linux'
5824           to apply to the rule `architecture-vendor-os' since this
5825           would make our programs incompatible to other Linux
5826           distributions. Also note, that we don't use
5827           `&lt;arch&gt;-unknown-linux', since the `unknown' does not
5828           look very good.</p></sect>
5829
5830
5831       <sect>
5832         <heading>Daemons</heading>
5833
5834         <p>
5835           The configuration files <tt>/etc/services</tt>,
5836           <tt>/etc/protocols</tt>, and <tt>/etc/rpc</tt> are managed
5837           by the <prgn>netbase</prgn> package and may not be modified
5838           by other packages.</p>
5839
5840         <p>
5841           If a package requires a new entry in one of these files, the
5842           maintainer should get in contact with the
5843           <prgn>netbase</prgn> maintainer, who will add the entries
5844           and release a new version of the <prgn>netbase</prgn>
5845           package.</p>
5846
5847         <p>
5848           The configuration file <tt>/etc/inetd.conf</tt> must not be
5849           modified by the package's scripts except via the
5850           <prgn>update-inetd</prgn> script or the
5851           <prgn>DebianNet.pm</prgn> Perl module.</p>
5852
5853         <p>
5854           If a package wants to install an example entry into
5855           <tt>/etc/inetd.conf</tt>, the entry must be preceded with
5856           exactly one hash character (<tt>#</tt>). Such lines are
5857           treated as `commented out by user' by the
5858           <prgn>update-inetd</prgn> script and are not changed or
5859           activated during a package updates.</p></sect>
5860
5861
5862       <sect>
5863         <heading>Using pseudo-ttys and modifying wtmp, utmp and lastlog</heading>
5864
5865         <p>
5866           Some programs need to create pseudo-ttys. This should be done
5867           using Unix98 ptys if the C library supports it. The resulting
5868           program must not be installed setuid root, unless that
5869           is required for other functionality.
5870         </p>
5871
5872         <p>
5873           The files <tt>/var/run/utmp</tt>, <tt>/var/log/wtmp</tt> and
5874           <tt>/var/log/lastlog</tt> must be installed writeable by
5875           group utmp.  Programs who need to modify those files must
5876           be installed setgid utmp.
5877         </p>
5878       </sect>
5879
5880       <sect>
5881         <heading>Editors and pagers</heading>
5882
5883         <p>
5884           Some programs have the ability to launch an editor or pager
5885           program to edit or display a text document. Since there are
5886           lots of different editors and pagers available in the Debian
5887           distribution, the system administrator and each user should
5888           have the possibility to choose his/her preferred editor and
5889           pager.</p>
5890
5891         <p>
5892           In addition, every program should choose a good default
5893           editor/pager if none is selected by the user or system
5894           administrator.</p>
5895
5896         <p>
5897           Thus, every program that launches an editor or pager must
5898           use the EDITOR or PAGER environment variables to determine
5899           the editor/pager the user wants to get started. If these
5900           variables are not set, the programs <tt>/usr/bin/editor</tt>
5901           and <tt>/usr/bin/pager</tt> should be used, respectively.</p>
5902
5903         <p>
5904           These two files are managed through `alternatives.' That is,
5905           every package providing an editor or pager must call the
5906           <prgn>update-alternatives</prgn> script to register these
5907           programs.</p>
5908
5909         <p>
5910           If it is very hard to adapt a program to make us of the
5911           EDITOR and PAGER variables, that program may be configured
5912           to use <tt>/usr/bin/sensible-editor</tt> and
5913           <tt>/usr/bin/sensible-pager</tt> as editor or pager program,
5914           respectively. These are two scripts provided in the Debian
5915           base system that check the EDITOR and PAGER variables and
5916           launch the appropriate program or fall back to
5917           <tt>/usr/bin/editor</tt> and <tt>/usr/bin/pager</tt>,
5918           automatically.</p>
5919
5920         <p>
5921           A program may also use the VISUAL environment variable to
5922           determine the user's choice of editor. If it exists, it
5923           should take precedence over EDITOR. This is in fact what
5924           <tt>/usr/bin/sensible-editor</tt> does.</p>
5925
5926         <p>
5927           It is not required for a package to depend on
5928           `editor' and `pager', nor is it required for a package to
5929           provide such virtual packages.
5930           <footnote>
5931             <p>
5932               The Debian base system already provides an editor and
5933               a pager program,
5934             </p>
5935           </footnote>
5936         </p>
5937
5938       </sect>
5939
5940
5941       <sect id="web-appl">
5942         <heading>Web servers and applications</heading>
5943
5944         <p>
5945           This section describes the locations and URLs that should
5946           be used by all web servers and web application in the Debian
5947           system.</p>
5948
5949         <p>
5950           <enumlist>
5951             <item>
5952               <p>Cgi-bin executable files are installed in the
5953                 directory
5954                 <example>
5955                   /usr/lib/cgi-bin/&lt;cgi-bin-name&gt;
5956                 </example>
5957                 and should be referred to as
5958                 <example>
5959                   http://localhost/cgi-bin/&lt;cgi-bin-name&gt;
5960                 </example></p></item>
5961
5962
5963             <item><p>Access to html documents</p>
5964
5965               <p>
5966                 Html documents for a package are stored in
5967                 <tt>/usr/share/doc/<var>package</var></tt> but should
5968                 be accessed via symlinks as
5969                 <tt>/usr/doc/<var>package</var></tt><footnote> for
5970                     backward compatibility, see <ref id="usrdoc"></footnote>
5971                 and can be referred to as
5972                 <example>
5973                   http://localhost/doc/&lt;package&gt;/&lt;filename&gt;
5974                 </example></p></item>
5975
5976
5977             <item><p>Web Document Root</p>
5978
5979               <p>
5980                 Web Applications should try to avoid storing files in
5981                 the Web Document Root.  Instead they should use the
5982                 /usr/share/doc/&lt;package&gt; directory for documents and
5983                 register the Web Application via the menu package. If
5984                 access to the web-root is unavoidable then use
5985                 <example>
5986                   /var/www
5987                 </example>
5988                 as the Document Root. This might be just a
5989                 symbolic link to the location where the sysadmin has
5990                 put the real document root.</p>
5991             </item>
5992
5993           </enumlist></p></sect>
5994
5995
5996       <sect>
5997         <heading>Mail transport, delivery and user agents</heading>
5998
5999         <p>
6000           Debian packages which process electronic mail, whether
6001           mail-user-agents (MUAs) or mail-transport-agents (MTAs),
6002           must make sure that they are compatible with the
6003           configuration decisions below.  Failure to do this may
6004           result in lost mail, broken <tt>From:</tt> lines, and other
6005           serious brain damage!</p>
6006
6007         <p>
6008           The mail spool is <tt>/var/spool/mail</tt> and the interface
6009           to send a mail message is <tt>/usr/sbin/sendmail</tt> (as
6010           per the FHS).  The mail spool is part of the base system
6011           and not part of the MTA package.</p>
6012
6013         <p>
6014           All Debian MUAs, MTAs, MDAs and other mailbox accessing
6015           programs (like IMAP daemons) must lock the mailbox in an
6016           NFS-safe way. This means that <tt>fcntl()</tt> locking must
6017           be combined with dot locking.  To avoid deadlocks, a
6018           program should use <tt>fcntl()</tt> first and dot locking
6019           after this or alternatively implement the two locking
6020           methods in a non blocking way<footnote>
6021             <p>
6022               If it is not possible to establish both locks, the
6023               system shouldn't wait for the second lock to be
6024               established, but remove the first lock, wait a (random)
6025               time, and start over locking again.</p>
6026           </footnote>. Using the functions <tt>maillock</tt> and
6027           <tt>mailunlock</tt> provided by the
6028           <tt>liblockfile*</tt><footnote>
6029             <p>
6030               <tt>liblockfile</tt> version &gt;&gt;1.01</p>
6031           </footnote> packages is the recommended way to realize this.
6032         </p>
6033
6034         <p>
6035           Mailboxes are generally 660 <tt><var>user</var>.mail</tt>
6036           unless the user has chosen otherwise.  A MUA may remove a
6037           mailbox (unless it has nonstandard permissions) in which
6038           case the MTA or another MUA must recreate it if needed.
6039           Mailboxes must be writable by group mail.</p>
6040
6041         <p>
6042           The mail spool is 2775 <tt>root.mail</tt>, and MUAs should
6043           be setgid mail to do the locking mentioned above (and
6044           must obviously avoid accessing other users' mailboxes
6045           using this privilege).</p>
6046
6047         <p>
6048           <tt>/etc/aliases</tt> is the source file for the system mail
6049           aliases (e.g., postmaster, usenet, etc.)--it is the one
6050           which the sysadmin and <tt>postinst</tt> scripts may edit.
6051           After <tt>/etc/aliases</tt> is edited the program or human
6052           editing it must call <prgn>newaliases</prgn>.  All MTA
6053           packages must come with a <prgn>newaliases</prgn> program,
6054           even if it does nothing, but older MTA packages do not do
6055           this so programs should not fail if <prgn>newaliases</prgn>
6056           cannot be found.</p>
6057
6058         <p>
6059           The convention of writing <tt>forward to
6060             <var>address</var></tt> in the mailbox itself is not
6061           supported.  Use a <tt>.forward</tt> file instead.</p>
6062
6063         <p>
6064           The <prgn>rmail</prgn> program used by UUCP
6065           for incoming mail should be  <tt>/usr/sbin/rmail</tt>.
6066           Likewise, <prgn>rsmtp</prgn>, for receiving
6067           batch-SMTP-over-UUCP, should be <tt>/usr/sbin/rsmtp</tt> if it
6068           is supported.</p>
6069
6070         <p>
6071           If you need to know what name to use (for example) on
6072           outgoing news and mail messages which are generated locally,
6073           you should use the file <tt>/etc/mailname</tt>.  It will
6074           contain the portion after the username and <tt>@</tt> (at)
6075           sign for email addresses of users on the machine (followed
6076           by a newline).</p>
6077
6078         <p>
6079           A package should check for the existence of this file.  If
6080           it exists it should use it without comment. (An MTA's
6081           prompting configuration script may wish to prompt the user
6082           even if it finds this file exists.) If it does not exist it
6083           should prompt the user for the value and store it in
6084           <tt>/etc/mailname</tt> as well as using it in the package's
6085           configuration.  The prompt should make it clear that the
6086           name will not just be used by that package.  For example, in
6087           this situation the INN package says:
6088           <example>
6089             Please enter the `mail name' of your system.  This is the
6090             hostname portion of the address to be shown on outgoing
6091             news and mail messages.  The default is
6092             <var>syshostname</var>, your system's host name.  Mail
6093             name [`<var>syshostname</var>']:
6094           </example>
6095           where <var>syshostname</var> is the output of <tt>hostname
6096             --fqdn</tt>.</p></sect>
6097
6098
6099       <sect>
6100         <heading>News system configuration</heading>
6101
6102         <p>
6103           All the configuration files related to the NNTP (news)
6104           servers and clients should be located under
6105           <tt>/etc/news</tt>.</p>
6106
6107         <p>
6108           There are some configuration issues that apply to a number
6109           of news clients and server packages on the machine. These
6110           are:
6111
6112           <taglist>
6113             <tag>/etc/news/organization</tag>
6114             <item><p>A string which should appear as the
6115                 organization header for all messages posted
6116                 by NNTP clients on the machine</p></item>
6117
6118             <tag>/etc/news/server</tag>
6119             <item><p>Contains the FQDN of the upstream NNTP
6120                 server, or localhost if the local machine is
6121                 an NNTP server.</p></item>
6122           </taglist>
6123
6124           Other global files may be added as required for cross-package news
6125           configuration.</p></sect>
6126
6127
6128       <sect>
6129         <heading>Programs for the X Window System</heading>
6130
6131         <p>
6132           <em>Programs that may be configured with support for the X Window
6133             System</em> must be configured to do so and must declare any
6134           package dependencies necessary to satisfy their runtime
6135           requirements when using the X Window System, unless the package
6136           in question is of standard or higher priority, in which case
6137           X-specific binaries may be split into a separate package, or
6138           alternative versions of the package with X support may be
6139           provided.
6140         </p>
6141
6142
6143         <p>
6144           <em>Packages which provide an X server</em> that, directly or
6145           indirectly, communicates with real input and display hardware
6146           should declare in their control data that they provide the
6147           virtual package <tt>xserver</tt>.
6148           <footnote>
6149             <p>
6150               This implements current practice, and provides an actual
6151               policy for usage of the "xserver" virtual package which
6152               appears in the virtual packages list.  In a nutshell, X
6153               servers that interface directly with the display and input
6154               hardware or via another subsystem (e.g., GGI) should provide
6155               xserver.  Things like Xvfb, Xnest, and Xprt should not.
6156             </p>
6157           </footnote>
6158         </p>
6159
6160         <p>
6161           <em>Packages that provide a terminal emulator</em> for the X
6162           Window System which support a terminal type with a terminfo
6163           description provided in the <tt>ncurses-base</tt> package
6164           should declare in their control data that they provide the
6165           virtual package <tt>x-terminal-emulator</tt>.  They should
6166           also register themselves as an alternative for
6167           <tt>/usr/bin/x-terminal-emulator</tt>, with a priority of
6168           20.
6169         </p>
6170
6171         <p>
6172           <em>Packages that provide window managers</em> should declare in
6173           their control data that they provide the virtual package
6174           <tt>x-window-manager</tt>.  They should also register themselves as an
6175           alternative for <tt>/usr/bin/x-window-manager</tt>, with a priority
6176           calculated as follows:
6177           <list>
6178             <item>Start with a priority of 20.</item>
6179             <item>If the window manager supports the Debian menu system,
6180                 add 20 points if this support is available in the
6181                 package's default configuration (i.e., no
6182                 configuration files belonging to the system or user
6183                 have to be edited to activate the feature); if
6184                 configuration files must be modified, add only 10
6185                 points.</item>
6186             <item>If the window manager permits the X session to be
6187                 restarted using a <em>different</em> window manager
6188                 (without killing the X server) in its default
6189                 configuration, add 10 points; otherwise add
6190                 none.</item>
6191           </list>
6192         </p>
6193
6194         <p>
6195           <em>Packages that provide fonts for the X Window System</em>
6196           must do a number of things to ensure that they are both
6197           available without modification of the X or font server
6198           configuration, and that they do not corrupt files used by
6199           other font packages to register information about themselves.
6200           <enumlist>
6201             <item>
6202                 Fonts of any type supported by the X Window System
6203                 should be be in a separate binary package from any
6204                 executables, libraries, or documentation (except that
6205                 specific to the fonts shipped); if a program or
6206                 library is <em>unusable</em> without one or more
6207                 specific fonts, the package containing the program or
6208                 library should declare a dependency on the package(s)
6209                 containing the font(s) it requires.
6210             </item>
6211             <item>
6212                 BDF fonts should be converted to PCF fonts with the
6213                 <tt>bdftopcf</tt> utility (available in the
6214                 <tt>xutils</tt> package, <tt>gzip</tt>ped, and
6215                 placed in a directory that corresponds to their
6216                 resolution:
6217                 <list>
6218                   <item>
6219                       100 dpi fonts should be placed in
6220                       <tt>/usr/X11R6/lib/X11/fonts/100dpi/</tt>.
6221                   </item>
6222                   <item>
6223                       75 dpi fonts should be placed in
6224                       <tt>/usr/X11R6/lib/X11/fonts/75dpi/</tt>.
6225                   </item>
6226                   <item>
6227                       Character-cell fonts, cursor fonts, and other
6228                       low-resolution fonts should be placed in
6229                       <tt>/usr/X11R6/lib/X11/fonts/misc/</tt>.
6230                   </item>
6231                 </list>
6232             </item>
6233             <item>
6234                 Speedo fonts should be placed in
6235                 <tt>/usr/X11R6/lib/X11/fonts/Speedo/</tt>.
6236             </item>
6237             <item>
6238                 Type 1 fonts should be placed in
6239                 <tt>/usr/X11R6/lib/X11/fonts/Type1/</tt>.  If font
6240                 metric files are available, they may be placed here as
6241                 well.
6242             </item>
6243             <item>
6244                 Subdirectories of <tt>/usr/X11R6/lib/X11/fonts/</tt>
6245                 other than those listed above should be neither created nor
6246                 used.  (The <tt>PEX</tt> and <tt>cyrillic</tt> directories are
6247                 excepted for historical reasons, but installation of files into
6248                 these directories remains discouraged.)
6249             </item>
6250             <item>
6251                 Font packages may, instead of placing files directly in
6252                 the X font directories listed above, provide symbolic links in
6253                 the font directory which point to the files' actual location
6254                 in the filesystem.  Such a location should comply with the
6255                 FHS.
6256             </item>
6257             <item>
6258                 Font packages should not contain both 75dpi and 100dpi
6259                 versions of a font.  If both are available, they should be
6260                 provided in separate binary packages with "-75dpi" or "-100dpi"
6261                 appended to the names of the packages containing the
6262                 corresponding fonts.
6263             </item>
6264             <item>
6265                 Fonts destined for the <tt>misc</tt> subdirectory should
6266                 not be included in the same package as 75dpi or 100dpi fonts;
6267                 instead, they should be provided in a separate package with
6268                 "-misc" appended to its name.
6269             </item>
6270             <item>
6271                 Font packages <em>must not</em> provide the files
6272                 <tt>fonts.dir</tt>, <tt>fonts.alias</tt>, or
6273                 <tt>fonts.scale</tt> in a font directory.
6274                 <list>
6275                   <item>
6276                       <tt>fonts.dir</tt> files must not be provided at
6277                       all.
6278                   </item>
6279                   <item>
6280                       <tt>fonts.alias</tt> and <tt>fonts.scale</tt>
6281                       files, if needed, should be provided in the
6282                       directory
6283                       <tt>/etc/X11/fonts/<em>fontdir</em>/<em>package</em>.<em>extension</em></tt>,
6284                       where <em>fontdir</em> is the name of the
6285                       subdirectory of
6286                       <tt>/usr/X11R6/lib/X11/fonts/</tt> where the
6287                       package's corresponding fonts are stored (e.g.,
6288                       <tt>75dpi</tt> or <tt>misc</tt>),
6289                       <em>package</em> is the name of the package that
6290                       provides these fonts, and <em>extension</em> is
6291                       either <tt>scale</tt> or <tt>alias</tt>,
6292                       whichever corresponds to the file
6293                       contents.
6294                   </item>
6295                 </list>
6296             </item>
6297             <item>
6298                 Font packages must declare a dependency on
6299                 <tt>xutils</tt> and, in the package
6300                 post-installation and post-removal scripts, invoke the
6301                 <tt>mkfontdir</tt> command on each directory into
6302                 which they installed fonts.
6303             </item>
6304             <item>
6305                 Font packages that provide one or more
6306                 <tt>fonts.scale</tt> files as described above must declare a
6307                 versioned dependency on <tt>xutils (&gt;=
6308                   4.0.2)</tt> and invoke <tt>update-fonts-scale</tt> on each
6309                 directory into which they installed fonts
6310                 <em>before</em> invoking <tt>mkfontdir</tt> on that
6311                 directory.  This invocation must occur in both the
6312                 post-installation and post-removal scripts.
6313             </item>
6314             <item>
6315                 Font packages that provide one or more
6316                 <tt>fonts.alias</tt> files as described above must
6317                 declare a versioned dependency on <tt>xutils
6318                   (&gt;= 4.0.2)</tt> and, in the package
6319                 post-installation and post-removal scripts, invoke
6320                 <tt>update-fonts-alias</tt> on each directory into
6321                 which they installed fonts.
6322             </item>
6323             <item>
6324                 Font packages must not provide alias names for the
6325                 fonts they include which collide with alias names already in
6326                 use by fonts already packaged.
6327             </item>
6328             <item>
6329                 Font packages must not provide fonts with the same XLFD
6330                 registry name as another font already packaged.
6331             </item>
6332           </enumlist>
6333         </p>
6334
6335         <p>
6336           <em>Application defaults</em> files must be installed in the
6337           directory <tt>/etc/X11/app-defaults/</tt> (use of a
6338           localized subdirectory of <tt>/etc/X11/</tt> as described in
6339           the <em>X Toolkit Intrinsics - C Language Interface</em>
6340           manual is also permitted).  They must be registered as
6341           <em>conffile</em>s or handled as configuration files.  For
6342           programs that are not linked against the X Toolkit (Xt)
6343           library, customization of programs' X resources may also be
6344           supported with the provision of a file with the same name as
6345           that of the package placed in the
6346           <tt>/etc/X11/Xresources/</tt> directory, which must
6347           registered as a <em>conffile</em> or handled as a
6348           configuration file.  <em>Important:</em> packages that
6349           install files into the <tt>/etc/X11/Xresources/</tt>
6350           directory <em>must</em> declare a conflict with <tt>xbase
6351           (&lt;&lt; 3.3.2.3a-2)</tt>; if this is not done it is
6352           possible for the installing package to destroy a
6353           previously-existing <tt>/etc/X11/Xresources</tt> file which
6354           had been customized by the system administrator.
6355         </p>
6356
6357         <p>
6358           <em>Packages using the X Window System should abide by the FHS
6359             standard whenever possible</em>; they should install binaries,
6360           libraries, manual pages, and other files in FHS-mandated
6361           locations wherever possible.  This means that files must
6362           not be installed into <tt>/usr/X11R6/bin/</tt>,
6363           <tt>/usr/X11R6/lib/</tt>, or <tt>/usr/X11R6/man/</tt> unless
6364           this is necessary for the package to operate properly.
6365           Configuration files for window managers and display managers
6366           should be placed in a subdirectory of <tt>/etc/X11/</tt>
6367           corresponding to the package name due to these programs'
6368           tight integration with the mechanisms of the X Window
6369           System.  Application-level programs should use the
6370           <tt>/etc/</tt> directory unless otherwise mandated by
6371           policy.  The installation of files into subdirectories of
6372           <tt>/usr/X11R6/include/X11/</tt> and
6373           <tt>/usr/X11R6/lib/X11/</tt> is permitted but discouraged;
6374           package maintainers should determine if subdirectories of
6375           <tt>/usr/lib/</tt> and <tt>/usr/share/</tt> can be used
6376           instead (symlinks from the X11R6 directories to
6377           FHS-compliant locations is encouraged if the program is not
6378           easily configured to look elsewhere for its files).
6379           Packages must not provide -- or install files into -- the
6380           directories <tt>/usr/bin/X11/</tt>,
6381           <tt>/usr/include/X11/</tt>, or <tt>/usr/lib/X11/</tt>.
6382           Files within a package should, however, make reference to
6383           these directories, rather than their X11R6-named
6384           counterparts <tt>/usr/X11R6/bin/</tt>,
6385           <tt>/usr/X11R6/include/X11/</tt>, and
6386           <tt>/usr/X11R6/lib/X11/</tt>, if the resources being
6387           referred to have not been moved to FHS-compliant locations.
6388         </p>
6389
6390         <p>
6391           <em>Programs that require the non-DFSG-compliant OSF/Motif
6392             library</em> should be compiled against and tested with
6393           LessTif (a free re-implementation of Motif) instead.  If the
6394           maintainer judges that the program or programs do not work
6395           sufficiently well with LessTif to be distributed and
6396           supported, but do so when compiled against Motif, then two
6397           versions of the package should be created; one linked
6398           statically against Motif and with <tt>-smotif</tt> appended
6399           to the package name, and one linked dynamically against
6400           Motif and with <tt>-dmotif</tt> appended to the package
6401           name.  Both Motif-linked versions are dependent upon
6402           non-DFSG-compliant software and thus cannot be uploaded to
6403           the main distribution; if the software is itself
6404           DFSG-compliant it may be uploaded to the contrib
6405           distribution.  While known existing versions of OSF/Motif
6406           permit unlimited redistribution of binaries linked against
6407           the library (whether statically or dynamically), it is the
6408           package maintainer's responsibility to determine whether
6409           this is permitted by the license of the copy of OSF/Motif in
6410           his or her possession.
6411         </p>
6412       </sect>
6413
6414
6415       <sect>
6416         <heading>Emacs lisp programs</heading>
6417
6418         <p>
6419           Please refer to the `Debian Emacs Policy' (documented in
6420           <tt>debian-emacs-policy.gz</tt> of the
6421           <prgn>emacsen-common</prgn> package) for details of how to
6422           package emacs lisp programs.</p></sect>
6423
6424
6425       <sect>
6426         <heading>Games</heading>
6427
6428         <p>
6429           The permissions on /var/games are 755
6430           <tt>root.root</tt>.</p>
6431
6432         <p>
6433           Each game decides on its own security policy.</p>
6434
6435         <p>
6436           Games which require protected, privileged access to
6437           high-score files, savegames, etc., may be made
6438           set-<em>group</em>-id (mode 2755) and owned by
6439           <tt>root.games</tt>, and use files and directories with
6440           appropriate permissions (770 <tt>root.games</tt>, for
6441           example).  They must not be made
6442           set-<em>user</em>-id, as this causes security problems. (If
6443           an attacker can subvert any set-user-id game they can
6444           overwrite the executable of any other, causing other players
6445           of these games to run a Trojan horse program.  With a
6446           set-group-id game the attacker only gets access to less
6447           important game data, and if they can get at the other
6448           players' accounts at all it will take considerably more
6449           effort.)</p>
6450
6451         <p>
6452           Some packages, for example some fortune cookie programs, are
6453           configured by the upstream authors to install with their
6454           data files or other static information made unreadable so
6455           that they can only be accessed through set-id programs
6456           provided.  You should not do this in a Debian package: anyone can
6457           download the <tt>.deb</tt> file and read the data from it,
6458           so there is no point making the files unreadable.  Not
6459           making the files unreadable also means that you don't have
6460           to make so many programs set-id, which reduces the risk of a
6461           security hole.</p>
6462
6463         <p>
6464           As described in the FHS, binaries of games should be
6465           installed in the directory <tt>/usr/games</tt>. This also
6466           applies to games that use the X Window System. Manual pages
6467           for games (X and non-X games) should be installed in
6468           <tt>/usr/share/man/man6</tt>.</p>
6469       </sect>
6470     </chapt>
6471
6472     <chapt><heading>Documentation</heading>
6473
6474
6475       <sect>
6476         <heading>Manual pages</heading>
6477
6478         <p>
6479           You should install manual pages in <prgn>nroff</prgn> source
6480           form, in appropriate places under <tt>/usr/share/man</tt>.  You
6481           should only use sections 1 to 9 (see the FHS for more
6482           details).  You must not install a preformatted `cat
6483           page'.</p>
6484
6485         <p>
6486           Each program, utility, and function should have an
6487           associated manpage included in the same package. It is
6488           suggested that all configuration files also have a manual
6489           page included as well.
6490         </p>
6491
6492         <p>
6493           If no manual page is available for a particular program,
6494           utility, function or configuration file and this is reported as a bug on
6495           debian-bugs, a symbolic link from the requested manual page
6496           to the <manref name="undocumented" section="7"> manual page
6497           may be provided.  This symbolic link can be created from
6498           <tt>debian/rules</tt> like this:
6499           <example>
6500             ln -s ../man7/undocumented.7.gz \
6501             debian/tmp/usr/share/man/man[1-9]/the_requested_manpage.[1-9].gz
6502           </example>
6503           This manpage claims that the lack of a manpage has been
6504           reported as a bug, so you may only do this if it really has
6505           (you can report it yourself, if you like).  Do not close the
6506           bug report until a proper manpage is available.</p>
6507
6508         <p>
6509           You may forward a complaint about a missing manpage to the
6510           upstream authors, and mark the bug as forwarded in the
6511           Debian bug tracking system.  Even though the GNU Project do
6512           not in general consider the lack of a manpage to be a bug,
6513           we do--if they tell you that they don't consider it a bug
6514           you should leave the bug in our bug tracking system open
6515           anyway.</p>
6516
6517         <p>
6518           Manual pages should be installed compressed using <tt>gzip
6519             -9</tt>.</p>
6520
6521         <p>
6522           If one manpage needs to be accessible via several names it
6523           is better to use a symbolic link than the <tt>.so</tt>
6524           feature, but there is no need to fiddle with the relevant
6525           parts of the upstream source to change from <tt>.so</tt> to
6526           symlinks--don't do it unless it's easy.  You should not create hard
6527           links in the manual page directories, nor put
6528           absolute filenames in <tt>.so</tt> directives.  The filename
6529           in a <tt>.so</tt> in a manpage should be relative to the
6530           base of the manpage tree (usually
6531           <tt>/usr/share/man</tt>).</p></sect>
6532
6533
6534       <sect>
6535         <heading>Info documents</heading>
6536
6537         <p>
6538           Info documents should be installed in <tt>/usr/share/info</tt>.
6539           They should be compressed with <tt>gzip -9</tt>.</p>
6540
6541         <p>
6542           Your package should call <prgn>install-info</prgn> to update the Info
6543           <tt>dir</tt>
6544           file, in its post-installation script:
6545           <example>
6546             install-info --quiet --section Development Development \
6547             /usr/share/info/foobar.info
6548           </example></p>
6549
6550         <p>
6551           It is a good idea to specify a section for the location of
6552           your program; this is done with the <tt>--section</tt>
6553           switch.  To determine which section to use, you should look
6554           at <tt>/usr/share/info/dir</tt> on your system and choose the most
6555           relevant (or create a new section if none of the current
6556           sections are relevant).  Note that the <tt>--section</tt>
6557           flag takes two arguments; the first is a regular expression
6558           to match (case-insensitively) against an existing section,
6559           the second is used when creating a new one.</p>
6560
6561         <p>
6562           You should remove the entries in the pre-removal script:
6563           <example>
6564             install-info --quiet --remove /usr/share/info/foobar.info
6565           </example></p>
6566
6567         <p>
6568           If <prgn>install-info</prgn> cannot find a description entry
6569           in the Info file you must supply one.  See <manref
6570                                                              name="install-info" section="8"> for details.</p>
6571       </sect>
6572
6573       <sect>
6574         <heading>Additional documentation</heading>
6575
6576         <p>
6577           Any additional documentation that comes with the package may
6578           be installed at the discretion of the package maintainer.
6579           Text documentation should be installed in a directory
6580           <tt>/usr/share/doc/<var>package</var></tt>, where
6581           <var>package</var> is the name of the package, and
6582           compressed with <tt>gzip -9</tt> unless it is small.</p>
6583
6584         <p>
6585           If a package comes with large amounts of documentation which
6586           many users of the package will not require you should create
6587           a separate binary package to contain it, so that it does not
6588           take up disk space on the machines of users who do not need
6589           or want it installed.</p>
6590
6591         <p>
6592           It is often a good idea to put text information files
6593           (<tt>README</tt>s, changelogs, and so forth) that come with
6594           the source package in <tt>/usr/share/doc/<var>package</var></tt>
6595           in the binary package.  However, you don't need to install
6596           the instructions for building and installing the package, of
6597           course!</p>
6598
6599         <p>
6600           Files in <tt>/usr/share/doc</tt> should not be referenced by
6601           any program, and the system administrator should be able to
6602           delete them without causing any programs to break. Any files
6603           that are referenced by programs but are also useful as
6604           standalone documentation should be installed under
6605           <tt>/usr/share/&lt;package&gt;/</tt> and symlinked in
6606           <tt>/usr/share/doc/&lt;package&gt;/</tt>.
6607         </p>
6608
6609       </sect>
6610
6611       <sect id="usrdoc">
6612         <heading>Accessing the documentation</heading>
6613
6614         <p>
6615           Former Debian releases placed all additional documentation
6616           in <tt>/usr/doc/<var>package</var></tt>.  To realize a
6617           smooth migration to
6618           <tt>/usr/share/doc/<var>package</var></tt>, each package
6619           must maintain a symlink <tt>/usr/doc/<var>package</var></tt>
6620           that points to the new location of its documentation in
6621           <tt>/usr/share/doc/<var>package</var></tt><footnote>These
6622               symlinks will be removed in the future, but they have to be
6623               there for compatibility reasons until all packages have
6624               moved and the policy is changed accordingly.</footnote>.
6625           The symlink must be created when the package is installed;
6626           it cannot be contained in the package itself due to problems
6627           with <prgn>dpkg</prgn>. One reasonable way to accomplish
6628           this is to put the following in the package's
6629           <prgn>postinst</prgn>:
6630           <example>
6631             if [ "$1" = "configure" ]; then
6632             if [ -d /usr/doc -a ! -e /usr/doc/#PACKAGE# \
6633             -a -d /usr/share/doc/#PACKAGE# ]; then
6634             ln -sf ../share/doc/#PACKAGE# /usr/doc/#PACKAGE#
6635             fi
6636             fi
6637           </example>
6638           And the following in the package's <prgn>prerm</prgn>:
6639           <example>
6640             if [ \( "$1" = "upgrade" -o "$1" = "remove" \) \
6641             -a -L /usr/doc/#PACKAGE# ]; then
6642             rm -f /usr/doc/#PACKAGE#
6643             fi
6644           </example>
6645         </p>
6646       </sect>
6647
6648       <sect>
6649         <heading>Preferred documentation formats</heading>
6650
6651         <p>
6652           The unification of Debian documentation is being carried out
6653           via HTML.</p>
6654
6655         <p>
6656           If your package comes with extensive documentation in a
6657           mark up format that can be converted to various other formats
6658           you should if possible ship HTML versions in a binary
6659           package, in the directory
6660           <tt>/usr/share/doc/<var>appropriate package</var></tt> or its
6661           subdirectories.
6662           <footnote>
6663             <p>The rationale: The important thing here is that HTML
6664               docs should be available in <em>some</em> package, not
6665               necessarily in the main binary package, though. </p>
6666           </footnote>
6667         </p>
6668
6669         <p>
6670           Other formats such as PostScript may be provided at your
6671           option.</p>
6672       </sect>
6673
6674       <sect id="copyrightfile">
6675         <heading>Copyright information</heading>
6676
6677         <p>
6678           Every package must be accompanied by a verbatim copy of its
6679           copyright and distribution license in the file
6680           /usr/share/doc/&lt;package-name&gt;/copyright. This file must
6681           neither be compressed nor be a symbolic link.</p>
6682
6683         <p>
6684           In addition, the copyright file must say where the upstream
6685           sources (if any) were obtained, and should explain briefly what
6686           modifications were made in the Debian version of the package
6687           compared to the upstream one.  It should name the original
6688           authors of the package and the Debian maintainer(s) who were
6689           involved with its creation.</p>
6690
6691         <p>
6692           A copy of the file which will be installed in
6693           <tt>/usr/share/doc/<var>package</var>/copyright</tt> should be
6694           in <tt>debian/copyright</tt>.</p>
6695
6696
6697         <p>
6698           /usr/share/doc/&lt;package-name&gt; may be a symbolic link to a
6699           directory in /usr/share/doc only if two packages both come from
6700           the same source and the first package has a "Depends"
6701           relationship on the second.  These rules are important
6702           because copyrights must be extractable by mechanical
6703           means.</p>
6704
6705         <p>
6706           Packages distributed under the UCB BSD license, the Artistic
6707           license, the GNU GPL, and the GNU LGPL should refer to the
6708           files /usr/share/common-licenses/BSD,
6709           /usr/share/common-licenses/Artistic,
6710           /usr/share/common-licenses/GPL, and
6711           /usr/share/common-licenses/LGPL.
6712           <footnote>
6713             <p>
6714               Why "licenses" and not "copyright"? Because
6715               <tt>/usr/doc/copyright</tt> used to contain all the
6716               copyright files, plus the four common licenses GPL,
6717               LGPL, Artistic and BSD. Now individual copyright files
6718               for packages are no longer in a common directory. Once
6719               <tt>/usr/doc/copyright</tt> is almost empty it makes
6720               sense to rename "copyright" to "licenses"
6721             </p>
6722             <p>
6723               Why "common-licenses" and not "licenses"? Because if I
6724               put just "licenses" I'm sure I will receive a bug report
6725               saying "license foo is not included in the licenses
6726               directory. They are not all the licenses, just a few
6727               common ones. I could use /usr/share/doc/common-licenses
6728               but I think this is too long, and, after all, the GPL
6729               does not "document" anything, it is merely a license.
6730             </p>
6731           </footnote>
6732         </p>
6733
6734         <p>
6735           You should not use the copyright file as a general <tt>README</tt>
6736           file.  If your package has such a file it should be
6737           installed in <tt>/usr/share/doc/<var>package</var>/README</tt> or
6738           <tt>README.Debian</tt> or some other appropriate place.</p>
6739       </sect>
6740
6741       <sect>
6742         <heading>Examples</heading>
6743
6744         <p>
6745           Any examples (configurations, source files, whatever),
6746           should be installed in a directory
6747           <tt>/usr/share/doc/<var>package</var>/examples</tt>.  These
6748           files should not be referenced by any program--they're there
6749           for the benefit of the system administrator and users, as
6750           documentation only. Architecture-specific example files
6751           should be installed in a directory
6752           <tt>/usr/lib/<var>package</var>/examples</tt>, and files in
6753           <tt>/usr/share/doc/<var>package</var>/examples</tt> symlink
6754           to files in it. Or the latter directory may be a symlink to
6755           the former.</p>
6756       </sect>
6757
6758       <sect id="instchangelog">
6759         <heading>Changelog files</heading>
6760
6761         <p>
6762           Packages that are not Debian-native must contain a copy of
6763           <tt>debian/changelog</tt> file from the Debian source tree
6764           in <tt>/usr/share/doc/<var>package</var></tt> as
6765           <tt>changelog.Debian.gz</tt>. If an upstream changelog is
6766           available, it should be accessible as
6767           <tt>/usr/share/doc/<var>package</var>/changelog.gz</tt> in
6768           plain text. If the upstream changelog is distributed in
6769           HTML, it should be made available in that form as
6770           <tt>/usr/share/doc/<var>package</var>/changelog.html.gz</tt>
6771           and the <tt>changelog.gz</tt> should be generated using, eg,
6772           <tt>lynx -dump -nolist</tt>. If the upstream changelog files
6773           do not already conform to this naming convention, then this
6774           may be achieved either by renaming the files, or adding a
6775           symbolic link, at the maintainer's discretion.
6776           <footnote>
6777             <p>
6778               Rationale: People should not have to look into two
6779               places for upstream changelogs merely because they are
6780               in HTML format.
6781             </p>
6782           </footnote>
6783         </p>
6784
6785
6786         <p>
6787           All these files should be installed compressed using <tt>gzip -9</tt>,
6788           as they will become large with time even if they start out
6789           small.
6790         </p>
6791
6792         <p>
6793           If the package has only one changelog which is used both as
6794           the Debian changelog and the upstream one because there is
6795           no separate upstream maintainer then that changelog should
6796           usually be installed as
6797           <tt>/usr/share/doc/<var>package</var>/changelog.gz</tt>; if
6798           there is a separate upstream maintainer, but no upstream
6799           changelog, then the Debian changelog should still be called
6800           <tt>changelog.Debian.gz</tt>.</p>
6801       </sect>
6802     </chapt>
6803   </book>
6804 </debiandoc>