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