/[ddp]/manuals/trunk/maint-guide/maint-guide.en.dbk
ViewVC logotype

Contents of /manuals/trunk/maint-guide/maint-guide.en.dbk

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8757 - (hide annotations) (download)
Sat Apr 30 05:09:16 2011 UTC (2 years ago) by taffit-guest
File size: 213487 byte(s)
Fix typos
1 osamu 8601 <?xml version="1.0" encoding="UTF-8"?>
2     <!-- -*- DocBook -*- -->
3     <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
4     "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
5 osamu 8643 <!ENTITY % trans SYSTEM "po4a/maint-guide.en.ent"> %trans;
6 osamu 8601 <!ENTITY % common SYSTEM "common.ent"> %common;
7     <!ENTITY % version SYSTEM "version.ent"> %version;
8     ]>
9     <book lang="en">
10     <!-- This is UTF-8 encoded. -->
11 osamu 8646 <!--
12     This is reorganized to make this document robust for translation
13     when some externally referenced information changes.
14    
15     If you want to add extra contents to this document, please do so by
16     * adding tag like &othercredit; in English and provide it for each language.
17     * add extra content within msgstr but within <footnote>...</footnote>
18     Please note there will be content checker to match tags of msgid and msgstr.
19     The second rule is a way to get exception to this rule.
20    
21     Please try to correct something in translation. If you think contents needs fix,
22     Let's fix it in the root cause.
23    
24     Please understand to keep this document focused. Not everything you think important
25     for new maintainer should be written down. Something social needs to be elsewhere.
26     Some thing should be left to the practice. Something needs to be left for exercise
27     for people to check official documentations.
28     -->
29 osamu 8601 <title>Debian New Maintainers' Guide</title>
30     <bookinfo>
31     <authorgroup>
32 osamu 8673 <!-- do not use firstname and surname tags it braks Japanese. The same with othercredit -->
33     <author> <personname>Josip Rodin</personname> <email>joy-mg@debian.org</email> <contrib>original contents</contrib> </author>
34     <author> <personname>Osamu Aoki</personname> <email>osamu@debian.org</email> <contrib>updated contents</contrib> </author>
35 osamu 8643 <!-- translator credits in po4a/translator.*.ent -->
36     &othercredit;
37 osamu 8601 </authorgroup>
38     <releaseinfo>version &docversion;</releaseinfo>
39     <pubdate>&docisodate;</pubdate>
40     <copyright><year>1998-2002</year> <holder>Josip Rodin</holder></copyright>
41     <copyright><year>2005-2011</year> <holder>Osamu Aoki</holder></copyright>
42     <copyright><year>2010</year> <holder>Craig Small</holder></copyright>
43     <copyright><year>2010</year> <holder>Raphaël Hertzog</holder></copyright>
44     <legalnotice>
45     <para>
46     This document may be used under the terms the GNU General Public License
47     version 2 or higher.
48     </para>
49     <para>
50     This document was made using with these two documents as examples:
51     </para>
52 osamu 8650 <itemizedlist>
53     <listitem>
54 osamu 8601 <para>
55     Making a Debian Package (AKA the Debmake Manual), copyright © 1997 Jaldhar
56     Vyas.
57     </para>
58 osamu 8650 </listitem>
59     <listitem>
60 osamu 8601 <para>
61     The New-Maintainer's Debian Packaging Howto, copyright © 1997 Will Lowe.
62     </para>
63 osamu 8650 </listitem>
64     </itemizedlist>
65 osamu 8601 </legalnotice>
66     <!-- toc -->
67     </bookinfo>
68     <chapter id="start"><title>Getting started The Right Way</title>
69     <para>
70 osamu 8688 This document tries to describe the building of a Debian package to ordinary
71     Debian users and prospective developers. It uses fairly non-technical language, and
72     it's well covered with working examples. There is an old Latin saying:
73     <emphasis>Longum iter est per praecepta, breve et efficax per
74     exempla</emphasis> (It's a long way by the rules, but short and efficient with
75     examples).
76 osamu 8601 </para>
77     <para>
78 osamu 8636 This document has been updated for the Debian <literal>&base-release;</literal>
79     release.
80 osamu 8688 <footnote><para> The document assumes you are using a
81     <literal>&base-release;</literal> or newer system. If you need to follow this
82 taffit-guest 8665 text in an older system (including an older Ubuntu system etc.), you must
83 osamu 8639 install backported <systemitem role="package">dpkg</systemitem> and
84     <systemitem role="package">debhelper</systemitem> packages, at least.
85     </para> </footnote>
86 osamu 8601 </para>
87     <para>
88     One of the things that makes Debian such a top-notch distribution is its
89     package system. While there is a vast quantity of software already in the
90     Debian format, sometimes you need to install software that isn't. You may be
91 osamu 8688 wondering how you can make your own packages; and perhaps you think it is a very
92 osamu 8601 difficult task. Well, if you are a real novice on Linux, it is hard, but if
93 osamu 8688 you were a rookie, you wouldn't be reading this document now&nbsp;:-)
94     You do need to know a little about Unix programming but you certainly
95     don't need to be a wizard.
96 osamu 8639 <footnote><para>
97 osamu 8688 You can learn about the basic handling of a Debian system from the
98 osamu 8639 <ulink url="&debref;">Debian Reference</ulink>. It contains some pointers to
99     learn about Unix programming, too.
100     </para></footnote>
101 osamu 8601 </para>
102     <para>
103     One thing is certain, though: to properly create and maintain Debian packages
104 osamu 8688 takes many hours. Make no mistake, for our system to work the maintainers
105 osamu 8601 need to be both technically competent and diligent.
106     </para>
107     <para>
108 taffit-guest 8665 If you need some help on packaging, please read <xref linkend="helpme"/>.
109 osamu 8601 </para>
110     <para>
111 osamu 8636 Newer versions of this document should always be available online at
112     <ulink url="&maint-guide;"/> and in the
113     <systemitem role="package">maint-guide</systemitem> package.
114 osamu 8688 The translations may be available in packages such as
115 osamu 8639 <systemitem role="package">maint-guide-es</systemitem>.
116 osamu 8655 Please note that this documentation may be slightly outdated.
117 osamu 8601 </para>
118 osamu 8721 <para>
119     Since this is a tutorial, I choose to explain each detailed step for some
120     important topics. Some of them may look irrelevant to you. Please be patient.
121     I have also intentionally skipped some corner cases and provided only pointers
122     to keep this document simple.
123     </para>
124 osamu 8688 <section id="socialdynamism"><title>Social dynamics of Debian</title>
125 osamu 8651 <para>
126 osamu 8688 Here are some observations of Debian's social dynamics, presented in the hope
127     that it will prepare you for interactions with Debian.
128 osamu 8651 </para>
129     <itemizedlist>
130     <listitem><para>We all are volunteers.</para>
131     <itemizedlist>
132 osamu 8688 <listitem><para>You cannot impose on others what to do.</para></listitem>
133 osamu 8651 <listitem><para>You should be motivated to do things by yourself.</para></listitem>
134     </itemizedlist></listitem>
135     <listitem><para>Friendly cooperation is the driving force.</para>
136     <itemizedlist>
137     <listitem><para>Your contribution should not overstrain others.</para></listitem>
138     <listitem><para>Your contribution is valuable only when others appreciate it.</para></listitem>
139     </itemizedlist></listitem>
140     <listitem><para>Debian is not your school where you get automatic attention of teachers.</para>
141     <itemizedlist>
142     <listitem><para>You should be able to learn many things by yourself.</para></listitem>
143 osamu 8688 <listitem><para>Attention from other volunteers is a very scarce resource.</para></listitem>
144 osamu 8651 </itemizedlist></listitem>
145     <listitem><para>Debian is constantly improving.</para>
146     <itemizedlist>
147 osamu 8655 <listitem><para>You are expected to make high quality packages.</para></listitem>
148 osamu 8688 <listitem><para>You should adapt yourself to change.</para></listitem>
149 osamu 8651 </itemizedlist></listitem>
150     </itemizedlist>
151     <para>
152 osamu 8705 There are several types of people interacting around Debian with different
153     roles.
154 osamu 8651 </para>
155     <itemizedlist>
156 osamu 8705 <listitem>
157     <para>
158     <emphasis role="strong">upstream author</emphasis>: the person who made the
159     original program.
160     </para>
161     </listitem>
162     <listitem>
163     <para>
164     <emphasis role="strong">upstream maintainer</emphasis>: the person who
165     currently maintains the program.
166     </para>
167     </listitem>
168     <listitem>
169     <para>
170     <emphasis role="strong">maintainer</emphasis>: the person making the Debian
171     package of the program.
172     </para>
173     </listitem>
174     <listitem>
175     <para>
176     <emphasis role="strong">sponsor</emphasis>: a person who helps maintainers to
177     upload packages to the official Debian package archive (after checking their
178     contents).
179     </para>
180     </listitem>
181     <listitem>
182     <para>
183     <emphasis role="strong">mentor</emphasis>: a person who helps novice
184     maintainers with packaging etc.
185     </para>
186     </listitem>
187     <listitem>
188     <para>
189     <emphasis role="strong">Debian Developer</emphasis> (DD): a member of
190     the Debian project with full upload rights to the official Debian package
191     archive.
192     </para>
193     </listitem>
194     <listitem>
195     <para>
196     <emphasis role="strong">Debian Maintainer</emphasis> (DM): a person with
197     limited upload rights to the official Debian package archive.
198     </para>
199     </listitem>
200 osamu 8651 </itemizedlist>
201     <para>
202 osamu 8705 Please note that you cannot become an official
203 osamu 8688 <emphasis role="strong">Debian Developer</emphasis> (DD) overnight, because it
204 osamu 8651 takes more than technical skill. Please do not be discouraged by this. If it
205     is useful to others, you can still upload your package either as a
206     <emphasis role="strong">maintainer</emphasis> through a
207     <emphasis role="strong">sponsor</emphasis> or as a
208     <emphasis role="strong">Debian Maintainer</emphasis>.
209     </para>
210     <para>
211     Please note that you do not need to create any new package to become an
212     official Debian Developer. Contributing to the existing packages can provide a
213 osamu 8688 path to becoming an official Debian Developer too. There are many packages
214 taffit-guest 8665 waiting for good maintainers (see <xref linkend="choose"/>).
215 osamu 8651 </para>
216 osamu 8705 <para>
217     Since we focus only on technical aspects of packaging in this document,
218     please refer to the following to learn how Debian functions and how you can get involved.
219     </para>
220     <itemizedlist>
221     <listitem><para><ulink url="&logiciellibre;">Debian: 17 years of Free Software, "do-ocracy", and democracy</ulink> (Introductory slides) </para> </listitem>
222     <listitem><para><ulink url="&debianorghelp;">How can you help Debian?</ulink> (official) </para> </listitem>
223 osamu 8737 <listitem><para><ulink url="&debianfaqhelp;">The Debian GNU/Linux FAQ, Chapter 13 - "Contributing to the Debian Project"</ulink> (semi-official) </para> </listitem>
224 osamu 8705 <listitem><para><ulink url="&debianwikihelp;">Debian Wiki, HelpDebian</ulink> (supplemental) </para> </listitem>
225     <listitem><para><ulink url="&nm-do;">Debian New Maintainer site</ulink> (official) </para> </listitem>
226     <listitem><para><ulink url="&debianmentorfaq;">Debian Mentors FAQ</ulink> (supplemental) </para> </listitem>
227     </itemizedlist>
228 osamu 8651 </section>
229 osamu 8601 <section id="needprogs"><title>Programs you need for development</title>
230     <para>
231     Before you start anything, you should make sure that you have properly
232     installed some additional packages needed for development. Note that the list
233     doesn't contain any packages marked <literal>essential</literal> or
234     <literal>required</literal> - we expect that you have those installed already.
235     </para>
236     <para>
237     The following packages come with the standard Debian installation, so you
238     probably have them already (along with any additional packages they depend on).
239     Still, you should check it with <literal>aptitude show
240 osamu 8621 <replaceable>package</replaceable></literal>
241     or with <literal>dpkg -s <replaceable>package</replaceable></literal>.
242 osamu 8601 </para>
243     <para>
244     The most important package to install on your development system is the
245     <systemitem role="package">build-essential</systemitem> package. Once you try
246 osamu 8688 to install that, it will <emphasis>pull in</emphasis> other packages required to
247 osamu 8601 have a basic build environment.
248     </para>
249     <para>
250 osamu 8688 For some types of packages, that is all you will require; however, there is
251 osamu 8601 another set of packages that while not essential for all package builds are
252 osamu 8688 useful to have installed or may be required by your package:
253 osamu 8601 </para>
254     <itemizedlist>
255     <listitem>
256     <para>
257 osamu 8688 <systemitem role="package">autoconf</systemitem>, <systemitem
258     role="package">automake</systemitem>, and <systemitem
259     role="package">autotools-dev</systemitem> - many newer programs use configure
260     scripts and <filename>Makefile</filename> files preprocessed with the help of
261     programs like these (see <literal>info autoconf</literal>, <literal>info
262     automake</literal>). <systemitem role="package">autotools-dev</systemitem>
263     keeps up-to-date versions of certain auto files and has documentation about the
264     best way to use those files.
265 osamu 8601 </para>
266     </listitem>
267     <listitem>
268     <para>
269 osamu 8688 <systemitem role="package">debhelper</systemitem> and
270     <systemitem role="package">dh-make</systemitem> -
271     <systemitem role="package">dh-make</systemitem> is necessary to create
272     the skeleton of our example package, and it will use some of the
273     <systemitem role="package">debhelper</systemitem> tools for creating
274     packages. They are not essential for this purpose, but are
275     <emphasis>highly</emphasis> recommended for new maintainers. It makes
276     the whole process very much easier to start, and to control afterwards.
277     (See <citerefentry> <refentrytitle>dh_make</refentrytitle>
278     <manvolnum>1</manvolnum> </citerefentry>, <citerefentry>
279     <refentrytitle>debhelper</refentrytitle> <manvolnum>1</manvolnum>
280     </citerefentry>.) <footnote><para> There are also some more specialized
281     but similar packages such as
282     <systemitem role="package">dh-make-perl</systemitem>,
283     <systemitem role="package">dh-make-php</systemitem>, etc. </para>
284     </footnote>
285 osamu 8601 </para>
286     </listitem>
287     <listitem>
288     <para>
289 osamu 8688 <systemitem role="package">devscripts</systemitem> - this package contains some
290     useful scripts that can be helpful for maintainers, but they are also
291     not necessary for building packages. Packages recommended and suggested
292     by this package are worth looking into. (See <ulink url="&devscripts-readme;"/>.)
293 osamu 8601 </para>
294     </listitem>
295     <listitem>
296     <para>
297 osamu 8688 <systemitem role="package">fakeroot</systemitem> - this utility lets you
298     emulate being root which is necessary for some parts of the build process.
299     (See <citerefentry> <refentrytitle>fakeroot</refentrytitle>
300     <manvolnum>1</manvolnum> </citerefentry>.)
301 osamu 8601 </para>
302     </listitem>
303     <listitem>
304     <para>
305 osamu 8688 <systemitem role="package">file</systemitem> - this handy program can determine
306     what type a file is. (See <citerefentry> <refentrytitle>file</refentrytitle>
307     <manvolnum>1</manvolnum> </citerefentry>.)
308 osamu 8601 </para>
309     </listitem>
310     <listitem>
311     <para>
312 osamu 8688 <systemitem role="package">gfortran</systemitem> - the GNU Fortran 95 compiler,
313     necessary if your program is written in Fortran. (See <citerefentry>
314     <refentrytitle>gfortran</refentrytitle> <manvolnum>1</manvolnum>
315     </citerefentry>.)
316 osamu 8601 </para>
317     </listitem>
318     <listitem>
319     <para>
320 osamu 8688 <systemitem role="package">git</systemitem> - this package provides a popular
321     version control system designed to handle very large projects with speed and
322     efficiency; it is used for many high profile open source projects, most notably
323     the Linux kernel. (See <citerefentry> <refentrytitle>git</refentrytitle>
324     <manvolnum>1</manvolnum> </citerefentry>,
325     <ulink url="&git-doc;">git Manual</ulink>.)
326 osamu 8601 </para>
327     </listitem>
328     <listitem>
329     <para>
330     <systemitem role="package">gnupg</systemitem> - a tool that enables you to
331     digitally <emphasis>sign</emphasis> packages. This is especially important if
332     you want to distribute it to other people, and you will certainly be doing that
333 osamu 8688 when your work gets included in the Debian distribution. (See <citerefentry>
334     <refentrytitle>gpg</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>.)
335 osamu 8601 </para>
336     </listitem>
337     <listitem>
338     <para>
339     <systemitem role="package">gpc</systemitem> - the GNU Pascal compiler,
340     necessary if your program is written in Pascal. Worthy of note here is
341     <systemitem role="package">fp-compiler</systemitem>, the Free Pascal Compiler,
342 osamu 8688 which is also good at this task. (See <citerefentry>
343 osamu 8601 <refentrytitle>gpc</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>,
344 osamu 8688 <citerefentry> <refentrytitle>ppc386</refentrytitle>
345     <manvolnum>1</manvolnum> </citerefentry>.)
346 osamu 8601 </para>
347     </listitem>
348     <listitem>
349     <para>
350 osamu 8688 <systemitem role="package">lintian</systemitem> - this is the Debian package
351     checker, which can let you know of any common mistakes after you build the
352     package, and explains the errors found. (See <citerefentry>
353     <refentrytitle>lintian</refentrytitle> <manvolnum>1</manvolnum>
354     </citerefentry>,
355     <ulink url="&lintian-doc;">Lintian User's Manual</ulink>.)
356 osamu 8601 </para>
357     </listitem>
358     <listitem>
359     <para>
360 osamu 8688 <systemitem role="package">patch</systemitem> - this very useful utility will
361     take a file containing a difference listing (produced by the
362     <command>diff</command> program) and apply it to the original file, producing a
363     patched version. (See <citerefentry> <refentrytitle>patch</refentrytitle>
364     <manvolnum>1</manvolnum> </citerefentry>.)
365 osamu 8601 </para>
366     </listitem>
367     <listitem>
368     <para>
369 osamu 8688 <systemitem role="package">patchutils</systemitem> - this package contains some
370     utilities to work with patches such as the <command>lsdiff</command>,
371     <command>interdiff</command> and <command>filterdiff</command> commands.
372     </para>
373     </listitem>
374     <listitem>
375     <para>
376 osamu 8601 <systemitem role="package">pbuilder</systemitem> - this package contains
377     programs which are used for creating and maintaining <command>chroot</command>
378     environment. Building Debian package in this <command>chroot</command>
379     environment verifies the proper build dependency and avoid FTBFS (Fails To
380     Build From Source) bugs. (see <citerefentry>
381     <refentrytitle>pbuilder</refentrytitle> <manvolnum>8</manvolnum>
382     </citerefentry> and <citerefentry> <refentrytitle>pdebuild</refentrytitle>
383     <manvolnum>1</manvolnum> </citerefentry>)
384     </para>
385     </listitem>
386     <listitem>
387     <para>
388 osamu 8688 <systemitem role="package">perl</systemitem> - Perl is one of the most used
389     interpreted scripting languages on today's Unix-like systems, often referred to
390     as Unix's Swiss Army Chainsaw. (See <citerefentry>
391     <refentrytitle>perl</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>.)
392 osamu 8601 </para>
393     </listitem>
394     <listitem>
395     <para>
396 osamu 8688 <systemitem role="package">python</systemitem> - Python is another of the most
397     used interpreted scripting languages on the Debian system, combining
398     remarkable power with very clear syntax. (See <citerefentry>
399     <refentrytitle>python</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>.)
400     </para>
401     </listitem>
402     <listitem>
403     <para>
404 osamu 8601 <systemitem role="package">quilt</systemitem> - this package helps you to
405 taffit-guest 8695 manage large numbers of patches by keeping track of the changes each patch
406 osamu 8688 makes. Patches can be applied, un-applied, refreshed, and more. (See
407     <citerefentry> <refentrytitle>quilt</refentrytitle> <manvolnum>1</manvolnum></citerefentry>,
408     <ulink url="&quilt-pdf;">quilt.pdf</ulink>.)
409 osamu 8601 </para>
410     </listitem>
411     <listitem>
412     <para>
413 osamu 8688 <systemitem role="package">xutils-dev</systemitem> - some programs, usually
414     those made for X11, also use these programs to generate
415     <filename>Makefile</filename> files from sets of macro functions. (See
416     <citerefentry> <refentrytitle>imake</refentrytitle> <manvolnum>1</manvolnum>
417     </citerefentry>, <citerefentry> <refentrytitle>xmkmf</refentrytitle>
418     <manvolnum>1</manvolnum> </citerefentry>.)
419 osamu 8601 </para>
420     </listitem>
421     </itemizedlist>
422 osamu 8651 <para>
423     The short descriptions that are given above only serve to introduce you to what
424 osamu 8725 each package does. Before continuing please read the documentation
425 osamu 8719 of each relevant program including ones installed through the package dependency such as
426 osamu 8715 <command>make</command>, at least, for the standard usage. It may seem like heavy
427 osamu 8651 going now, but later on you'll be <emphasis>very</emphasis> glad you read it.
428 osamu 8688 If you have specific questions later, I would suggest re-reading the documents
429 osamu 8721 mentioned above.
430 osamu 8651 </para>
431 osamu 8646 </section>
432 osamu 8688 <section id="needdocs"><title>Documentation needed for development</title>
433 osamu 8601 <para>
434     The following is the <emphasis>very important</emphasis> documentation which
435     you should read along with this document:
436     </para>
437     <itemizedlist>
438     <listitem>
439     <para>
440 osamu 8628 <systemitem role="package">debian-policy</systemitem> - the <ulink url="&debian-policy;">Debian Policy
441 osamu 8601 Manual</ulink> includes explanations of the structure and contents of the
442 osamu 8688 Debian archive, several OS design issues, the <ulink url="&fhs;">Filesystem Hierarchy Standard</ulink>
443     (FHS, which says where each file and directory should be), etc. For you, the most
444 osamu 8601 important thing is that it describes requirements that each package must
445 osamu 8737 satisfy to be included in the distribution. (See the local copies of
446     <ulink url="&policy-pdf;">policy.pdf</ulink> and <ulink url="&fhs-pdf;">fhs-2.3.pdf</ulink>.)
447 osamu 8601 </para>
448     </listitem>
449     <listitem>
450     <para>
451 osamu 8642 <systemitem role="package">developers-reference</systemitem>
452     - the <ulink url="&developers-reference;">Debian Developer's Reference</ulink>
453     describes all matters not specifically about the technical
454 osamu 8601 details of packaging, like the structure of the archive, how to rename, orphan,
455 osamu 8688 or adopt packages, how to do NMUs, how to manage bugs, best packaging practices,
456     when and where to upload etc. (See the local copy of
457     <ulink url="&developers-refpdf;">developers-reference.pdf</ulink>.)
458 osamu 8601 </para>
459     </listitem>
460 osamu 8725 </itemizedlist>
461     <para>
462     The following is the <emphasis>important</emphasis> documentation which
463     you should read along with this document:
464     </para>
465     <itemizedlist>
466 osamu 8601 <listitem>
467     <para>
468 osamu 8725 <ulink url="&autotools-tutorial;">Autotools
469     Tutorial</ulink> provides a very good tutorial for <ulink url="&gnu-build-system;">the GNU Build System known
470     as the GNU Autotools</ulink> whose most important components are Autoconf,
471     Automake, Libtool, and gettext.
472     </para>
473     </listitem>
474     <listitem>
475     <para>
476 osamu 8601 <systemitem role="package">gnu-standards</systemitem> - this package contains
477 osamu 8639 two pieces of documentation from the GNU project:
478     <ulink url="&gnu-standard;">GNU Coding Standards</ulink>, and
479     <ulink url="&gnu-maintainer;">Information for Maintainers of GNU Software</ulink>.
480     Although Debian does not require these to
481 osamu 8688 be followed, these are still helpful as guidelines and common sense.
482     (See the local copies of
483 osamu 8639 <ulink url="&gnu-standard-pdf;">standards.pdf</ulink> and
484 osamu 8688 <ulink url="&gnu-maintainer-pdf;">maintain.pdf</ulink>.)
485 osamu 8601 </para>
486     </listitem>
487     </itemizedlist>
488     <para>
489 osamu 8688 If this document contradicts any of the documents mentioned above, they
490     are correct. Please file a bug report on the
491 osamu 8642 <systemitem role="package">maint-guide</systemitem> package using
492     <command>reportbug</command>.
493     </para>
494 osamu 8601 </section>
495     <section id="helpme"><title>Where to ask for help</title>
496     <para>
497 osamu 8621 Before you decide to ask your question in some public place, please read the fine documentation.
498 osamu 8601 </para>
499 osamu 8621 <itemizedlist>
500     <listitem>
501 osamu 8601 <para>
502 taffit-guest 8665 files in <filename>/usr/share/doc/<replaceable>package</replaceable></filename> for all pertinent packages
503 osamu 8621 </para>
504     </listitem>
505     <listitem>
506     <para>
507 osamu 8642 contents of <literal><command>man</command> <replaceable>command</replaceable></literal> for all pertinent commands
508 osamu 8621 </para>
509     </listitem>
510     <listitem>
511     <para>
512 osamu 8642 contents of <literal><command>info</command> <replaceable>command</replaceable></literal> for all pertinent commands
513 osamu 8621 </para>
514     </listitem>
515     <listitem>
516     <para>
517 osamu 8636 contents of <ulink url="&debian-mentors-ldo;">debian-mentors@lists.debian.org mailing list archive</ulink>
518 osamu 8621 </para>
519     </listitem>
520 osamu 8636 <listitem>
521     <para>
522     contents of <ulink url="&debian-devel-ldo;">debian-devel@lists.debian.org mailing list archive</ulink>
523     </para>
524     </listitem>
525 osamu 8621 </itemizedlist>
526     <para>
527 osamu 8688 You can use web search engines more effectively by including search strings
528 osamu 8642 such as <literal>site:lists.debian.org</literal> to limit the domain.
529 osamu 8636 </para>
530     <para>
531 osamu 8688 Making a small test package is a good way to learn details of packaging.
532 osamu 8601 Inspecting existing well maintained packages is the best way to learn how other
533     people make packages.
534     </para>
535     <para>
536     If you still have questions about packaging that you couldn't find answers to
537 osamu 8636 in the available documentation and web resources, you can ask them interactively.
538     </para>
539     <itemizedlist>
540     <listitem>
541     <para>
542     <ulink url="&debian-mentors-ldo;">debian-mentors@lists.debian.org mailing list</ulink>. (This mailing list is for the novice.)
543     </para>
544     </listitem>
545     <listitem>
546     <para>
547     <ulink url="&debian-devel-ldo;">debian-devel@lists.debian.org mailing list</ulink>. (This mailing list is for the expert.)
548     </para>
549     </listitem>
550     <listitem>
551     <para>
552     <ulink url="&irc-debian;">IRC</ulink> such as <literal>#debian-mentors</literal>.
553     </para>
554     </listitem>
555     </itemizedlist>
556     <para>
557 osamu 8652 The more experienced Debian developers will gladly help you, if you ask
558     properly after making your required efforts.
559 osamu 8601 </para>
560     <para>
561     When you receive a bug report (yes, actual bug reports!), you will know that it
562 osamu 8636 is time for you to dig into the
563     <ulink url="&bts;">Debian Bug Tracking System</ulink>
564     and read the documentation there, to be able to
565     deal with the reports efficiently. I highly recommend reading the
566 taffit-guest 8722 <ulink url="&devref-bug-handling;">Debian Developer's Reference, 5.8.
567 osamu 8688 "Handling bugs"</ulink>.
568 osamu 8601 </para>
569     <para>
570     Even if it all worked well, it's time to start praying. Why? Because in just
571     a few hours (or days) users from all around the world will start to use your
572     package, and if you made some critical error you'll get mailbombed by numerous
573     angry Debian users... Just kidding. :-)
574     </para>
575     <para>
576     Relax and be ready for bug reports, because there is a lot more work to be done
577     before your package will be fully in line with Debian policies and its best
578     practice guidelines (once again, read the <emphasis>real
579     documentation</emphasis> for details). Good luck!
580     </para>
581     </section>
582     </chapter>
583     <chapter id="first"><title>First steps</title>
584     <para>
585 osamu 8703 Let's start by creating a package of your own (or, even better,
586     adopting an existing one).
587 osamu 8601 </para>
588 osamu 8712 <section id="workflow"><title>Workflow of the Debian package building</title>
589 osamu 8705 <para>
590 osamu 8709 If you are making a Debian package with an upstream program,
591 osamu 8712 typical workflow of the Debian package building involves generating several
592 osamu 8707 specifically named files for each step as the following.
593 osamu 8705 </para>
594     <itemizedlist>
595     <listitem>
596     <para>We obtain an upstream program file usually in a compressed tar format.</para>
597     <itemizedlist>
598 osamu 8725 <listitem><literal><replaceable>package</replaceable>-<replaceable>version</replaceable>.tar.gz</literal></listitem>
599 osamu 8705 </itemizedlist>
600     </listitem>
601     <listitem>
602     <para>
603 taffit-guest 8722 We create a non-native Debian source package in the <literal>3.0 (quilt)</literal> format, which refers to the set of input files for
604 osamu 8709 the Debian package building, by adding Debian package modifications to the upstream program under the <filename>debian</filename> directory.
605 osamu 8705 </para>
606     <itemizedlist>
607 osamu 8725 <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>.orig.tar.gz</literal></listitem>
608     <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>-<replaceable>revision</replaceable>.debian.tar.gz</literal>
609 taffit-guest 8722 <footnote><para>For the older non-native Debian source package in the <literal>1.0</literal> format,
610 osamu 8725 <literal><replaceable>package</replaceable>_<replaceable>version</replaceable>-<replaceable>revision</replaceable>.diff.gz</literal>
611 osamu 8709 is used instead. </para></footnote></listitem>
612 osamu 8725 <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>-<replaceable>revision</replaceable>.dsc</literal></listitem>
613 osamu 8705 </itemizedlist>
614     </listitem>
615     <listitem>
616     <para>
617     We build Debian binary packages, which are ordinary installable package files in <literal>.deb</literal> format (or <literal>.udeb</literal> format, used by the Debian Installer), from the Debian source package.
618     </para>
619     <itemizedlist>
620 osamu 8725 <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>-<replaceable>revision</replaceable>_<replaceable>arch</replaceable>.deb</literal></listitem>
621 osamu 8705 </itemizedlist>
622     </listitem>
623     </itemizedlist>
624     <para>
625 osamu 8715 Please note that the character separating
626 osamu 8725 <literal><replaceable>package</replaceable></literal> and
627 osamu 8715 <literal><replaceable>version</replaceable></literal> was changed from
628     <literal>-</literal> (hyphen) to <literal>_</literal> (underscore).
629     </para>
630     <para>
631 taffit-guest 8722 Here,
632 osamu 8725 <literal><replaceable>package</replaceable></literal> part of the file name is substituted by the
633 taffit-guest 8722 <emphasis role="strong">package name</emphasis>,
634     <literal><replaceable>version</replaceable></literal> part of it is substituted by the
635     <emphasis role="strong">upstream version</emphasis>,
636     <literal><replaceable>revision</replaceable></literal> part of it is substituted by the
637     <emphasis role="strong">Debian revision</emphasis>,
638     <literal><replaceable>arch</replaceable></literal> part of it is substituted by the
639     <emphasis role="strong">package architecture</emphasis>.
640     <footnote><para>
641     The <emphasis role="strong">package name</emphasis>, <emphasis
642     role="strong">upstream version</emphasis>, and <emphasis role="strong">Debian
643 osamu 8725 revision</emphasis> must be adjusted to comply with the Debian Policy Manual:
644     <ulink url="&policy-source;">5.6.1 Source</ulink>,
645     <ulink url="&policy-package;">5.6.7 Package</ulink>, and
646     <ulink url="&policy-version;">5.6.12 Version</ulink>.
647 taffit-guest 8722 The <emphasis role="strong">package architecture</emphasis> follows the
648 osamu 8725 Debian Policy Manual: <ulink url="&policy-architecture;">5.6.8 Architecture</ulink>
649 taffit-guest 8722 and is automatically assigned by the package build process.</para></footnote>
650     </para>
651     <para>
652 osamu 8709 If you are making a Debian specific package without an upstream program instead,
653 osamu 8712 typical workflow of the Debian package building is simpler.
654 osamu 8709 </para>
655     <itemizedlist>
656     <listitem>
657     <para>
658 taffit-guest 8722 We create a native Debian source package in the <literal>3.0 (quilt)</literal> format using a compressed tar format in which required files under the <filename>debian</filename> directory are also included.
659 osamu 8709 </para>
660     <itemizedlist>
661 osamu 8725 <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>.tar.gz</literal></listitem>
662     <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>.dsc</literal></listitem>
663 osamu 8709 </itemizedlist>
664     </listitem>
665     <listitem>
666     <para>
667     We build Debian binary packages from the native Debian source package.
668     </para>
669     <itemizedlist>
670 osamu 8725 <listitem><literal><replaceable>package</replaceable>_<replaceable>version</replaceable>_<replaceable>arch</replaceable>.deb</literal></listitem>
671 osamu 8709 </itemizedlist>
672     </listitem>
673     </itemizedlist>
674     <para>
675 osamu 8707 In the following, each step of this is explained with detailed examples.
676     </para>
677     </section>
678 osamu 8601 <section id="choose"><title>Choose your program</title>
679     <para>
680     You have probably chosen the package you want to create. The first thing you
681     need to do is check if the package is in the distribution archive already by
682 osamu 8636 using the following.
683 osamu 8601 </para>
684 osamu 8636 <itemizedlist>
685     <listitem>
686     <para>the <command>aptitude</command> command</para>
687     </listitem>
688     <listitem>
689 osamu 8703 <para>the <ulink url="&packages-do;">Debian packages</ulink> web page</para>
690 osamu 8636 </listitem>
691     <listitem>
692 osamu 8703 <para>the <ulink url="&packages-qa-do;">Debian Package Tracking System</ulink> web page</para>
693 osamu 8636 </listitem>
694     </itemizedlist>
695 osamu 8601 <para>
696     If the package already exists, well, install it! :-) If it happens to be
697 osamu 8703 <emphasis role="strong">orphaned</emphasis> (that is, if its
698     maintainer is set to <ulink url="&qa-do;">Debian QA Group</ulink>),
699     you may be able to pick it up if it's still available. You may also
700     adopt a package whose maintainer has filed a Request for Adoption
701 osamu 8676 (<emphasis role="strong">RFA</emphasis>).<footnote> <para>See
702 osamu 8703 <ulink url="&devref-adopt;">Debian Developer's Reference 5.9.5.
703     "Adopting a package"</ulink>.</para> </footnote>
704 osamu 8601 </para>
705     <para>
706 osamu 8648 There are several package ownership status resources.
707 osamu 8601 </para>
708     <itemizedlist>
709     <listitem>
710 osamu 8636 <para> <ulink url="&wnpp-do;">Work-Needing and Prospective Packages</ulink> </para>
711 osamu 8601 </listitem>
712     <listitem>
713 taffit-guest 8665 <para> <ulink url="&wnpp-bts;">Debian Bug report logs: Bugs in pseudo-package <systemitem role="package">wnpp</systemitem> in <literal>unstable</literal></ulink> </para>
714 osamu 8601 </listitem>
715     <listitem>
716 osamu 8636 <para> <ulink url="&wnpp-dn;">Debian Packages that Need Lovin'</ulink> </para>
717 osamu 8601 </listitem>
718 osamu 8636 <listitem>
719 taffit-guest 8665 <para> <ulink url="&wnpp-debtags;">Browse <systemitem role="package">wnpp</systemitem> bugs based on debtags</ulink> </para>
720 osamu 8636 </listitem>
721 osamu 8601 </itemizedlist>
722     <para>
723     As a side note, it's important to point out that Debian already has packages
724     for most kinds of programs, and the number of packages already in the Debian
725     archive is much larger than that of contributors with upload rights. Thus,
726     contributions to packages already in the archive are far more appreciated (and
727     more likely to receive sponsorship) by other developers <footnote><para> Having
728 osamu 8703 said that, there will of course always be new programs that are worth
729     packaging. </para> </footnote>. You can contribute in various ways.
730 osamu 8601 </para>
731     <itemizedlist>
732     <listitem>
733     <para>
734     taking over orphaned, yet actively used, packages
735     </para>
736     </listitem>
737     <listitem>
738     <para>
739 osamu 8628 joining <ulink url="&teams;">packaging teams</ulink>
740 osamu 8601 </para>
741     </listitem>
742     <listitem>
743     <para>
744     triaging bugs of very popular packages
745     </para>
746     </listitem>
747     <listitem>
748     <para>
749 osamu 8636 preparing <ulink url="&devref-nmu;">QA or NMU uploads</ulink>
750 osamu 8601 </para>
751     </listitem>
752     </itemizedlist>
753     <para>
754     If you are able to adopt the package, get the sources (with something like
755     <literal>apt-get source <replaceable>packagename</replaceable></literal>) and
756     examine them. This document unfortunately doesn't include comprehensive
757     information about adopting packages. Thankfully you shouldn't have a hard time
758     figuring out how the package works since someone has already done the initial
759 osamu 8703 setup for you. Keep reading, though; a lot of the advice below will still be
760 osamu 8601 applicable for your case.
761     </para>
762     <para>
763     If the package is new, and you decide you'd like to see it in Debian, proceed
764     as follows:
765     </para>
766     <itemizedlist>
767     <listitem>
768     <para>
769 osamu 8703 First, you must know that the program works, and have tried it for some time to
770 osamu 8601 confirm its usefulness.
771     </para>
772     </listitem>
773     <listitem>
774     <para>
775 osamu 8703 You must check that no one else is already working on the package on the
776 osamu 8636 <ulink url="&wnpp-do;">Work-Needing and Prospective Packages</ulink> site.
777     If no one else is working on it, file an ITP (Intent
778 osamu 8601 To Package) bug report to the <systemitem role="package">wnpp</systemitem>
779     pseudo-package using <command>reportbug</command>. If someone's already on it,
780     contact them if you feel you need to. If not - find another interesting
781 osamu 8703 program that nobody is maintaining.
782 osamu 8601 </para>
783     </listitem>
784     <listitem>
785     <para>
786 osamu 8703 The software <emphasis role="strong">must have a license</emphasis>.
787 osamu 8601 </para>
788     <itemizedlist>
789     <listitem>
790     <para>
791 osamu 8703 For the <literal>main</literal> section, Debian Policy requires it
792     <emphasis role="strong">to be fully compliant with the Debian Free Software
793     Guidelines</emphasis> (<ulink url="&dfsg;">DFSG</ulink>)
794     and <emphasis role="strong">not to require a package outside of
795     <literal>main</literal></emphasis> for compilation or execution. This
796     is the desired case.
797 osamu 8601 </para>
798     </listitem>
799     <listitem>
800     <para>
801 osamu 8703 For the <literal>contrib</literal> section, it must comply with the
802 osamu 8601 DFSG but it may require a package outside of <literal>main</literal> for
803     compilation or execution.
804     </para>
805     </listitem>
806     <listitem>
807     <para>
808 osamu 8703 For the <literal>non-free</literal> section, it may be non-compliant
809     with the DFSG but it <emphasis role="strong">must be distributable</emphasis>.
810 osamu 8601 </para>
811     </listitem>
812 osamu 8734 <listitem>
813 osamu 8601 <para>
814 osamu 8730 If you are unsure about where it should go, post the license text on
815     <ulink url="&debian-legal-ldo;">debian-legal@lists.debian.org</ulink>
816 osamu 8601 and ask for advice.
817     </para>
818 osamu 8734 </listitem>
819     </itemizedlist>
820 osamu 8730 <listitem>
821     <para>
822     The program should <emphasis role="strong">not</emphasis> introduce security
823 osamu 8734 and maintenance concerns to the Debian system.
824 osamu 8730 </para>
825 osamu 8601 </listitem>
826 osamu 8730 <itemizedlist>
827 osamu 8601 <listitem>
828     <para>
829 osamu 8734 The program should be well documented and its code needs to be understandable
830     (i.e. not obfuscated).
831 osamu 8601 </para>
832     </listitem>
833     <listitem>
834     <para>
835 osamu 8734 You should contact the program's author(s) to check if they agree with packaging it
836     and are amicable to Debian. It is important to be able to consult with the author(s)
837     in case of any problems with the program, so don't try to package
838     unmaintained software.
839 osamu 8601 </para>
840     </listitem>
841     <listitem>
842     <para>
843 osamu 8734 The program certainly should <emphasis role="strong">not</emphasis> run setuid
844     root, or even better, it shouldn't need to be setuid or setgid to anything.
845 osamu 8601 </para>
846     </listitem>
847     <listitem>
848     <para>
849 osamu 8734 The program should not be a daemon, or go in an
850     <filename>*/sbin</filename> directory, or open a port as root.
851 osamu 8601 </para>
852     </listitem>
853     </itemizedlist>
854 osamu 8730 </listitem>
855     </itemizedlist>
856 osamu 8601 <para>
857 osamu 8734 Of course, the last one is just a safety measures, and intended to save you from
858 osamu 8703 enraging users if you do something wrong in some setuid daemon... When you gain
859     more experience in packaging, you'll be able to package such software.
860 osamu 8601 </para>
861 osamu 8730 <para>
862     As a new maintainer, you are encouraged to get some experience in packaging
863     with easier packages and discouraged from creating complicated packages.
864     </para>
865     <itemizedlist>
866     <listitem><para>Simple packages</para>
867     <itemizedlist>
868     <listitem><para>single binary package, arch = all (collection of data such as wallpaper graphics)</para></listitem>
869 osamu 8744 <listitem><para>single binary package, arch = all (executables written in the POSIX shell language)</para></listitem>
870     <listitem><para>single binary package, arch = all (executables written in interpreter languages)</para></listitem>
871 osamu 8730 </itemizedlist>
872     </listitem>
873     <listitem><para>Intermediate complexity packages</para>
874     <itemizedlist>
875 osamu 8744 <listitem><para>single binary package, arch = any (executables written in compiler languages such as C and C++)</para></listitem>
876     <listitem><para>multiple binary packages, arch = any + all (packages for executables + documentation)</para></listitem>
877 osamu 8730 <listitem><para>upstream source in a format other than <filename>tar.gz</filename> or <filename>tar.bz2</filename></para></listitem>
878     <listitem><para>upstream source containing undistributable contents</para></listitem>
879     </itemizedlist>
880     </listitem>
881     <listitem><para>High complexity packages</para>
882     <itemizedlist>
883 osamu 8744 <listitem><para>interpreter module package used by other packages</para></listitem>
884 osamu 8735 <listitem><para>generic library package used by other packages</para></listitem>
885 osamu 8744 <listitem><para>multiple binary packages containing a library package</para></listitem>
886 osamu 8735 <listitem><para>source package with multiple upstream sources</para></listitem>
887     <listitem><para>kernel module packages</para></listitem>
888 osamu 8730 <listitem><para>kernel patch packages</para></listitem>
889 osamu 8735 <listitem><para>any package with non-trivial maintainer scripts</para></listitem>
890 osamu 8730 </itemizedlist>
891     </listitem>
892     </itemizedlist>
893     <para>
894 osamu 8734 Packaging high complexity packages is not too hard, but it requires a bit more
895 osamu 8754 knowledge. You should seek specific guidances for every complexity. For
896     example, some interpreter languages have their policy.
897 osamu 8730 </para>
898 osamu 8734 <itemizedlist>
899     <listitem><para><ulink url="&policy-perl;">Perl policy</ulink></para></listitem>
900     <listitem><para><ulink url="&policy-python;">Python policy</ulink></para></listitem>
901     <listitem><para><ulink url="&policy-java;">Java policy</ulink></para></listitem>
902     </itemizedlist>
903 osamu 8754 <para>
904 osamu 8755 There is another old Latin saying: <emphasis>Fabricando fit fabe</emphasis>
905     (Practice makes perfect). It is <emphasis>highly</emphasis> recommended to
906     practice and experiment all the steps of Debian packaging with simple packages
907     while reading this tutorial. A trivial upstream tarball
908     <filename>hello-sh-1.0.tar.gz</filename> created with the following may offer
909 osamu 8756 you a good starting point.<footnote><para>Do not worry about missing
910     <filename>Makefile</filename>. You can install the <command>hello</command>
911     command by simply using <command>debhelper</command> as in
912     <xref linkend="install"/>, or by modifying the upstream source to add a new
913     <filename>Makefile</filename> with the <literal>install</literal> target as in
914     <xref linkend="modify"/>.</para></footnote>
915 osamu 8754 </para>
916     <screen>
917     $ mkdir -p hello-sh/hello-sh-1.0; cd hello-sh/hello-sh-1.0
918 osamu 8755 $ cat &gt; hello &lt;&lt;EOF
919 osamu 8754 #!/bin/sh
920     # (C) 2011 Foo Bar, GPL2+
921     echo "Hello!"
922     EOF
923     $ chmod 755 hello
924     $ cd ..
925     $ tar -cvzf hello-sh-1.0.tar.gz hello-sh-1.0
926     </screen>
927 osamu 8601 </section>
928     <section id="getit"><title>Get the program, and try it out</title>
929     <para>
930 osamu 8703 So the first thing to do is to find and download the original source code.
931     Presumably you already have the source file that you picked up at the
932 osamu 8601 author's homepage. Sources for free Unix programs usually come in
933 osamu 8703 <command>tar</command>+<command>gzip</command> format with the extension
934 osamu 8709 <filename>.tar.gz</filename>,
935 osamu 8703 <command>tar</command>+<command>bzip2</command> format with the extension
936 osamu 8709 <filename>.tar.bz2</filename>, or
937     <command>tar</command>+<command>xz</command> format with the extension
938 osamu 8715 <filename>.tar.xz</filename>. These usually contain a directory called
939 osamu 8725 <filename><replaceable>package</replaceable>-<replaceable>version</replaceable></filename>
940 osamu 8703 with all the sources inside.
941 osamu 8601 </para>
942     <para>
943 osamu 8703 If the latest version of the source is available through a VCS such as Git,
944     Subversion, or CVS, you need to get it with <literal>git
945 osamu 8621 clone</literal>, <literal>svn co</literal>, or <literal>cvs co</literal> and
946 osamu 8703 repack it into <command>tar</command>+<command>gzip</command> format yourself
947     by using the <literal>--exclude-vcs</literal> option.
948 osamu 8601 </para>
949     <para>
950     If your program's source comes as some other sort of archive (for instance, the
951     filename ends in <filename>.Z</filename> or
952     <filename>.zip</filename><footnote><para> You can identify the archive format
953     using the <command>file</command> command when the file extension is not
954 osamu 8703 enough. </para> </footnote>), you should also unpack it with the
955     appropriate tools and repack it.
956 osamu 8601 </para>
957     <para>
958 osamu 8703 As an example, I'll use a program called <command>gentoo</command>, a GTK+
959 osamu 8648 file manager.
960 osamu 8703 <footnote><para> This program is already packaged. The
961 osamu 8648 <ulink url="&gentoo-package;">current version</ulink> uses Autotools as its
962 osamu 8703 build structure and is substantially different from the following examples,
963     which were based on version 0.9.12.</para>
964 osamu 8648 </footnote>
965 osamu 8601 </para>
966     <para>
967     Create a subdirectory under your home directory named
968     <filename>debian</filename> or <filename>deb</filename> or anything you find
969     appropriate (e.g. just <filename>~/gentoo</filename> would do fine in this
970     case). Place the downloaded archive in it, and extract it (with <literal>tar
971 osamu 8703 xzf gentoo-0.9.12.tar.gz</literal>). Make sure there are no warning
972     messages, even <emphasis>irrelevant</emphasis> ones, because other
973     people's unpacking tools may or may not ignore these anomalies, so they
974 taffit-guest 8717 may have problems unpacking them. Your shell command line may look
975 osamu 8703 something like this:
976 osamu 8601 </para>
977     <screen>
978     $ mkdir ~/gentoo ; cd ~/gentoo
979     $ wget http://<replaceable>www.example.org</replaceable>/gentoo-0.9.12.tar.gz
980     $ tar xvzf gentoo-0.9.12.tar.gz
981     $ ls -F
982     gentoo-0.9.12/
983     gentoo-0.9.12.tar.gz
984     </screen>
985     <para>
986     Now you have another subdirectory, called <filename>gentoo-0.9.12</filename>.
987     Change to that directory and <emphasis>thoroughly</emphasis> read the provided
988     documentation. Usually there are files named <filename>README*</filename>,
989     <filename>INSTALL*</filename>, <filename>*.lsm</filename> or
990 osamu 8703 <filename>*.html</filename>. You must find instructions on how to
991 osamu 8601 compile and install the program (most probably they'll assume you want to
992 osamu 8703 install to the <filename>/usr/local/bin</filename> directory; you won't be doing
993 taffit-guest 8665 that, but more on that later in <xref linkend="destdir"/>).
994 osamu 8601 </para>
995     <para>
996 osamu 8716 You should start packaging with a completely clean (pristine) source directory,
997     or simply with freshly unpacked sources.
998     </para>
999     </section>
1000     <section id="simplemake"><title>Simple build systems</title>
1001     <para>
1002 osamu 8756 Simple programs usually come with a <filename>Makefile</filename> and can
1003 osamu 8703 be compiled just by invoking <literal>make</literal>.<footnote><para>
1004 osamu 8621 Many modern programs come with a script <filename>configure</filename> which
1005 osamu 8703 when executed creates a <filename>Makefile</filename> customized for
1006     your system.</para></footnote> Some of them support
1007     <literal>make check</literal>, which runs included self-tests. Installation
1008 osamu 8601 to the destination directories is usually done with <literal>make
1009     install</literal>.
1010     </para>
1011     <para>
1012     Now try to compile and run your program, to make sure it works properly and
1013     doesn't break something else while it's installing or running.
1014     </para>
1015     <para>
1016     Also, you can usually run <literal>make clean</literal> (or better
1017     <literal>make distclean</literal>) to clean up the build directory. Sometimes
1018     there's even a <literal>make uninstall</literal> which can be used to remove
1019     all the installed files.
1020     </para>
1021     </section>
1022 osamu 8709 <section id="portable"><title>Popular portable build systems</title>
1023 osamu 8601 <para>
1024 osamu 8714 A lot of free software programs are written in the <ulink url="&c-program;">C</ulink> and
1025 osamu 8716 <ulink url="&cxx;">C++</ulink> languages. Many of these use Autotools or
1026     CMake to make them portable across different platforms. These build tools need
1027     to be used to generate the <filename>Makefile</filename> and other
1028     required source files first. Then, such programs are built using the usual
1029 osamu 8703 <literal>make; make install</literal>.
1030 osamu 8601 </para>
1031     <para>
1032 osamu 8703 <ulink url="&gnu-build-system;">Autotools</ulink> is the GNU build
1033     system comprising <ulink url="&autoconf;">Autoconf</ulink>,
1034     <ulink url="&automake;">Automake</ulink>,
1035     <ulink url="&libtool;">Libtool</ulink>, and
1036     <ulink url="&gettext;">gettext</ulink>. You can recognize
1037 osamu 8601 such sources by the <filename>configure.ac</filename>,
1038     <filename>Makefile.am</filename>, and <filename>Makefile.in</filename> files.
1039 osamu 8716 <footnote><para>Autotools is too big to deal in this small tutorial. This
1040 taffit-guest 8722 section is meant to provide keywords and references only. Please make sure to read the
1041 osamu 8716 <ulink url="&autotools-tutorial;">Autotools Tutorial</ulink> and
1042     <ulink url="&autotools-readme;"/>, if you need to use it.</para></footnote>
1043 osamu 8601 </para>
1044     <para>
1045 osamu 8703 The first step of the Autotools workflow is usually that upstream runs
1046     <literal>autoreconf -i -f</literal> in the source directory and
1047     distributes the generated files along with the source.
1048 osamu 8601 </para>
1049     <screen>
1050     configure.ac-----+-&gt; autoreconf -+-&gt; configure
1051     Makefile.am -----+ | +-&gt; Makefile.in
1052     src/Makefile.am -+ | +-&gt; src/Makefile.in
1053     | +-&gt; config.h.in
1054     automake
1055     aclocal
1056     aclocal.m4
1057     autoheader
1058     </screen>
1059     <para>
1060     Editing <filename>configure.ac</filename> and <filename>Makefile.am</filename>
1061     files requires some knowledge of <command>autoconf</command> and
1062     <command>automake</command>. See <literal>info autoconf</literal> and
1063     <literal>info automake</literal>.
1064     </para>
1065     <para>
1066 osamu 8703 The second step of the Autotools workflow is usually that the user obtains this
1067 osamu 8601 distributed source and runs <literal>./configure &amp;&amp; make</literal> in
1068 osamu 8703 the source directory to compile the program into a
1069 taffit-guest 8722 <command><replaceable>binary</replaceable></command> executable.
1070 osamu 8601 </para>
1071     <screen>
1072     Makefile.in -----+ +-&gt; Makefile -----+-&gt; make -&gt; <replaceable>binary</replaceable>
1073     src/Makefile.in -+-&gt; ./configure -+-&gt; src/Makefile -+
1074     config.h.in -----+ +-&gt; config.h -----+
1075     |
1076     config.status -+
1077     config.guess --+
1078     </screen>
1079     <para>
1080 osamu 8703 You can change many things in the <filename>Makefile</filename>; for
1081     instance you can change the default location for file installation
1082     using the option <command>./configure --prefix=/usr</command>.
1083 osamu 8601 </para>
1084     <para>
1085     Although it is not required, updating the <filename>configure</filename> and
1086 osamu 8703 other files with <literal>autoreconf -i -f</literal> may improve
1087 osamu 8601 the compatibility of the source.
1088 osamu 8646 <footnote><para>You can automate this by using
1089 taffit-guest 8665 <systemitem role="package">dh-autoreconf</systemitem> package.
1090 osamu 8646 See <xref linkend="customrules"/>.</para></footnote>
1091 osamu 8601 </para>
1092     <para>
1093 osamu 8636 <ulink url="&cmake;">CMake</ulink> is an alternative
1094 osamu 8703 build system. You can recognize such sources by the
1095 osamu 8601 <filename>CMakeLists.txt</filename> file.
1096     </para>
1097     </section>
1098     <section id="namever"><title>Package name and version</title>
1099     <para>
1100 osamu 8718 If the upstream source comes as <filename>gentoo-0.9.12.tar.gz</filename>, you can
1101     consider
1102 osamu 8716 <emphasis role="strong">package name</emphasis> to be <literal>gentoo</literal> and
1103 osamu 8718 <emphasis role="strong">upstream version</emphasis> to be <literal>0.9.12</literal>.
1104     These are used in the <filename>debian/changelog</filename> file described later in
1105     <xref linkend="changelog"/>, too.
1106     </para>
1107     <para>
1108 osamu 8716 Although this simple approach works most of the times, you may need to adjust
1109     <emphasis role="strong">package name</emphasis> and
1110 osamu 8718 <emphasis role="strong">upstream version</emphasis> by renaming the upstream
1111 taffit-guest 8722 source to follow the Debian Policy and the existing convention.
1112 osamu 8601 </para>
1113     <para>
1114 osamu 8718 You must choose the <emphasis role="strong">package name</emphasis>
1115     to consist only of lower case letters (<literal>a-z</literal>), digits
1116 osamu 8716 (<literal>0-9</literal>), plus (<literal>+</literal>) and minus
1117     (<literal>-</literal>) signs, and periods (<literal>.</literal>). It must be
1118 osamu 8718 at least two characters long, must start with an alphanumeric character, and
1119     must not be the same as existing ones.
1120 osamu 8738 It is good idea to keep its length within 30 characters.
1121 osamu 8753 <footnote><para>The default package name field length of <command>aptitude</command> is 30. For more than 90% of packages, the package name is less than 24 characters.</para></footnote>
1122 osamu 8601 </para>
1123 osamu 8716 <!--
1124     Osamu's archive stat (2011-04-23, sid, kfreebsd-amd64):
1125     === stat for package name string length ===
1126     11 1947 36.9% mode
1127     14 1717 54.7% 50% median
1128     23 611 91.0% 90%
1129     32 89 99.0% 99%
1130     41 12 99.9% 99.9%
1131     52 1 100.0%
1132     Previous 20 chars is becoming too short for 17% of packages
1133 osamu 8718 Default aptitude setting display up to 30 chars (98.3%).
1134 osamu 8716 -->
1135 osamu 8601 <para>
1136 osamu 8718 If upstream source uses generic words such as <literal>test-suite</literal> as
1137     its name, it is good idea to rename it not to contaminate name space for the
1138     package name and to identify its contents explicitly.
1139     <footnote><para>If you follow the
1140 osamu 8725 <ulink url="&devref-newpackage;">Debian Developer's Reference 5.1. "New packages"</ulink>,
1141 taffit-guest 8722 the ITP process will usually catch this kind of issues.</para></footnote>
1142 osamu 8718 </para>
1143     <para>
1144 osamu 8716 You should choose the <emphasis role="strong">upstream version</emphasis>
1145 osamu 8718 to consist only of
1146     alphanumerics (<literal>0-9A-Za-z</literal>), plus (<literal>+</literal>),
1147 taffit-guest 8722 tildes (<literal>~</literal>), and periods (<literal>.</literal>). It must
1148 osamu 8716 start with a digit (<literal>0-9</literal>). <footnote><para>This stricter
1149     rule should help you avoid confusing file names.</para></footnote>
1150 osamu 8718 It is good idea to keep its length within 8 characters if possible.
1151 taffit-guest 8757 <footnote><para>The default version field length of <command>aptitude</command> is 10. The Debian revision with preceding hyphen usually consumes 2. For more than 80% of packages, the upstream version is less than 8 characters and the Debian revision is less than 2 characters. For more than 90% of packages, the upstream version is less than 10 characters and the Debian revision is less than 3 characters.</para></footnote>
1152 osamu 8601 </para>
1153 osamu 8716 <!--
1154 osamu 8718 Osamu's archive stat (2011-04-23, sid, kfreebsd-amd64):
1155     === stat for upstream version string length ===
1156     5 9765 60.2% 50% median and mode
1157     6 3765 73.3%
1158     7 2789 82.9%
1159     8 1158 86.9%
1160     9 501 88.6%
1161     10 773 91.3% 90%
1162     18 55 99.1% 99%
1163     27 11 99.9% 99.9
1164     35 6 100.0%
1165     === stat for debian revision string length ===
1166     1 22556 83.3% 50% median and mode
1167     2 1106 87.2%
1168     3 1312 91.7% 90%
1169     4 2127 99.1% 99%
1170     7 14 99.9% 99.9%
1171 osamu 8716
1172 osamu 8718 aptitude display 10 = 8char for up + 1char (for -) + 1char for deb
1173     90chars as max for file name of binary debs (package+up+deb+arch+.deb)
1174 osamu 8716 -->
1175 osamu 8601 <para>
1176 osamu 8718 If the upstream software does not use normal version system like
1177     <literal>2.30.32</literal> but uses some kind of date such as
1178 taffit-guest 8722 <literal>09Oct23</literal>, a random codename string or a VCS hash value as a part
1179 osamu 8718 of version, make sure to remove them from the
1180     <emphasis role="strong">upstream version</emphasis>. Such information can be
1181     recorded in the <filename>debian/changelog</filename> file. If you need to
1182     invent a version string, use the <literal>YYYYMMDD</literal> format such as
1183     <literal>20110429</literal> as upstream version. This ensures that
1184     <command>dpkg</command> properly sees later versions as upgrades.
1185 osamu 8601 </para>
1186 osamu 8718 <para>
1187 osamu 8745 Version strings <footnote><para>Version strings may be
1188 osamu 8753 <emphasis role="strong">upstream version</emphasis>
1189     (<literal><replaceable>version</replaceable></literal>),
1190     <emphasis role="strong">Debian revision</emphasis>
1191     (<literal><replaceable>revision</replaceable></literal>), or
1192     <emphasis role="strong">version</emphasis>
1193     (<literal><replaceable>version</replaceable>-<replaceable>revision</replaceable></literal>).
1194     See <xref linkend="newrevision"/> for how the
1195     <emphasis role="strong">Debian revision</emphasis> is incremented.
1196 osamu 8744 </para></footnote>
1197     can be compared with <citerefentry> <refentrytitle>dpkg</refentrytitle> <manvolnum>1</manvolnum> </citerefentry> as the following.
1198 osamu 8718 </para>
1199     <screen>
1200     $ dpkg --compare-versions <replaceable>ver1</replaceable> <replaceable>op</replaceable> <replaceable>ver2</replaceable>
1201     </screen>
1202     <para>
1203 taffit-guest 8722 The version comparison rule can be summarized as the following.
1204 osamu 8718 </para>
1205     <itemizedlist>
1206     <listitem><para>The strings are compared from the head to the tail.</para></listitem>
1207     <listitem><para>Alphabets are larger than numbers.</para></listitem>
1208     <listitem><para>Numbers are compared as the integer.</para></listitem>
1209     <listitem><para>Alphabets are compared in the ASCII code order.</para></listitem>
1210 taffit-guest 8722 <listitem><para>There are some special rules for periods (<literal>.</literal>), plus (<literal>+</literal>) and tildes (<literal>~</literal>) as the followings.</para>
1211 osamu 8718 <para>
1212     <literal>0.0</literal> &lt;
1213     <literal>0.5</literal> &lt;
1214     <literal>0.10</literal> &lt;
1215     <literal>0.99</literal> &lt;
1216     <literal>1</literal> &lt;
1217     <literal>1.0~rc1</literal> &lt;
1218     <literal>1.0</literal> &lt;
1219     <literal>1.0+b1</literal> &lt;
1220     <literal>1.0+nmu1</literal> &lt;
1221     <literal>1.1</literal> &lt;
1222     <literal>2.0</literal>
1223     </para>
1224     </listitem>
1225     </itemizedlist>
1226     <para>
1227     One of the tricky case happens when the upstream releases
1228     <filename>gentoo-0.9.12-ReleaseCandidate-99.tar.gz</filename> as the
1229     pre-release of <filename>gentoo-0.9.12.tar.gz</filename>. You need to make
1230     sure that the upgrade works properly by renaming the upstream source to
1231     <filename>gentoo-0.9.12~rc99.tar.gz</filename>.
1232     </para>
1233 osamu 8601 </section>
1234 osamu 8726 <section id="dh-make"><title>Setting up <command>dh_make</command></title>
1235 osamu 8601 <para>
1236 osamu 8703 Set up the shell environment variables <literal>$DEBEMAIL</literal> and
1237     <literal>$DEBFULLNAME</literal> so that various Debian maintenance
1238 taffit-guest 8717 tools recognize your email address and name to use for packages. <footnote><para> The
1239 osamu 8601 following text assumes you are using Bash as your login shell. If you use
1240 osamu 8703 some other login shell such as Z shell, use their corresponding
1241 taffit-guest 8717 configuration files instead of <filename>~/.bashrc</filename>. </para> </footnote>
1242 osamu 8601 </para>
1243     <screen>
1244     $ cat &gt;&gt;~/.bashrc &lt;&lt;EOF
1245     DEBEMAIL=your.email.address@example.org
1246     DEBFULLNAME=Firstname Lastname
1247     export DEBEMAIL DEBFULLNAME
1248     EOF
1249 osamu 8726 $ . ~/.bashrc
1250 osamu 8601 </screen>
1251 osamu 8726 </section>
1252     <section id="non-native-dh-make"><title>Initial non-native Debian package</title>
1253 osamu 8601 <para>
1254 osamu 8726 Normal Debian packages are non-native Debian packages made from upstream
1255     programs. If you wish to create a non-native Debian package of an upstream
1256     source <filename>gentoo-0.9.12.tar.gz</filename>, you can create an initial
1257     non-native Debian package for it by issuing the <command>dh_make</command>
1258     command as follows.
1259 osamu 8601 </para>
1260     <screen>
1261 osamu 8726 $ cd ~/gentoo
1262     $ wget http://example.org/gentoo-0.9.12.tar.gz
1263     $ tar -xvzf gentoo-0.9.12.tar.gz
1264     $ cd gentoo-0.9.12
1265 osamu 8601 $ dh_make -f ../gentoo-0.9.12.tar.gz
1266     </screen>
1267     <para>
1268     Of course, replace the filename with the name of your original source archive.
1269     <footnote><para> If the upstream source provides the
1270     <filename>debian</filename> directory and its contents, run the
1271 osamu 8703 <command>dh_make</command> command with the extra option
1272     <literal>--addmissing</literal>. The new source <literal>3.0 (quilt)</literal> format is
1273     robust enough not to break even for these packages. You may need to update the contents
1274 osamu 8601 provided by the upstream for your Debian package. </para> </footnote> See
1275     <citerefentry> <refentrytitle>dh_make</refentrytitle> <manvolnum>1</manvolnum>
1276     </citerefentry> for details.
1277     </para>
1278     <para>
1279 osamu 8703 You should see some output asking you what sort of package you want
1280 osamu 8725 to create. Gentoo is a single binary package - it creates only one binary package, i.e,
1281 osamu 8719 one <filename>.deb</filename> file - so we will select the first option
1282 osamu 8703 (with the <literal>s</literal> key), check the information on the screen, and
1283 osamu 8601 confirm by pressing <literal><replaceable>ENTER</replaceable></literal>.
1284 osamu 8719 <footnote><para> There are several choices here: <literal>s</literal> for
1285 osamu 8725 Single binary package, <literal>i</literal> for arch-Independent package, <literal>m</literal> for
1286     Multiple binary packages, <literal>l</literal> for Library package, <literal>k</literal> for
1287 osamu 8719 Kernel module package, <literal>n</literal> for kernel patch package, and <literal>b</literal>
1288     for <systemitem role="package">cdbs</systemitem> package. This document focuses on the
1289 osamu 8703 use of the <command>dh</command> command (from the package
1290 osamu 8725 <systemitem role="package">debhelper</systemitem>) to create a single binary package,
1291 osamu 8703 but also touches on how to use it for arch-independent or
1292 osamu 8725 multiple binary packages. The package
1293 osamu 8703 <systemitem role="package">cdbs</systemitem> offers an alternative packaging script
1294     infrastructure to the <command>dh</command> command and is outside the scope of
1295 osamu 8601 this document. </para> </footnote>
1296     </para>
1297     <para>
1298 osamu 8703 This execution of <command>dh_make</command> creates a copy of the upstream
1299     tarball as <filename>gentoo_0.9.12.orig.tar.gz</filename> in the
1300 osamu 8601 parent directory to accommodate the creation of the non-native Debian source
1301 osamu 8703 package with the name <filename>debian.tar.gz</filename> later.
1302 osamu 8601 </para>
1303     <screen>
1304     $ cd ~/gentoo ; ls -F
1305     gentoo-0.9.12/
1306     gentoo-0.9.12.tar.gz
1307     gentoo_0.9.12.orig.tar.gz
1308     </screen>
1309     <para>
1310 osamu 8703 Please note two key features of this filename
1311     <filename>gentoo_0.9.12.orig.tar.gz</filename>:
1312 osamu 8601 </para>
1313     <itemizedlist>
1314     <listitem>
1315     <para>
1316 osamu 8703 Package name and version are separated by the character <literal>_</literal>
1317 osamu 8601 (underscore).
1318     </para>
1319     </listitem>
1320     <listitem>
1321     <para>
1322 osamu 8703 The string <filename>.orig</filename> is inserted before the
1323 osamu 8601 <filename>.tar.gz</filename>.
1324     </para>
1325     </listitem>
1326     </itemizedlist>
1327     <para>
1328     You should also notice that many template files are created in the source under
1329 osamu 8703 the <filename>debian</filename> directory. These will be explained in
1330     <xref linkend="dreq"/> and <xref linkend="dother"/>. You should also understand
1331     that packaging cannot be a fully automated process. You will need to modify the upstream
1332     source for Debian (see <xref linkend="modify"/>). After this, you need to
1333     use the proper methods for building Debian packages (<xref linkend="build"/>),
1334     testing them (<xref linkend="checkit"/>), and uploading them (<xref linkend="upload"/>).
1335     All the steps will be explained.
1336 osamu 8601 </para>
1337     <para>
1338     If you accidentally erased some template files while working on them, you can
1339     recover them by running <command>dh_make</command> with the
1340     <literal>--addmissing</literal> option again in a Debian package source tree.
1341     </para>
1342     <para>
1343     Updating an existing package may get complicated since it may be using older
1344 osamu 8703 techniques. While learning the basics, please stick to creating a fresh
1345     package; further explanations are given in <xref linkend="update"/>.
1346 osamu 8601 </para>
1347 osamu 8726 <para>
1348 osamu 8728 Please note that the source file does not need to contain any build system
1349     discussed in <xref linkend="simplemake"/> and <xref linkend="portable"/>. It
1350     could be just a collection of graphics data etc. Installation of files may be
1351     enabled by <systemitem role="package">debhelper</systemitem> configuration
1352     files such as <filename>debian/install</filename> (see
1353     <xref linkend="install"/>) only.
1354 osamu 8726 </para>
1355 osamu 8601 </section>
1356 osamu 8726 <section id="native-dh-make"><title>Initial native Debian package</title>
1357     <para>
1358     Debian native packages are simpler to manage if they contain source files you
1359     manage only for Debian, possibly only for local uses. If you have source
1360     files in <filename>~/mypackage-1.0</filename>, you can create an initial native
1361     Debian package for it by issuing the <command>dh_make</command> command as
1362     follows.
1363     </para>
1364     <screen>
1365     $ cd ~/mypackage-1.0
1366     $ dh_make --native
1367     </screen>
1368     <para>
1369     Then the <filename>debian</filename> directory and its contents are created
1370     just like <xref linkend="non-native-dh-make"/>. This does not create a tarball
1371 osamu 8727 since this is a native Debian package. But that is the only difference.
1372     The rest of the packaging activities are practically the same.
1373 osamu 8726 </para>
1374     </section>
1375 osamu 8601 </chapter>
1376     <chapter id="modify"><title>Modifying the source</title>
1377     <para>
1378     Please note that there isn't space here to go into <emphasis>all</emphasis> the
1379     details of fixing upstream sources, but here are some basic steps and problems
1380     people often run across.
1381     </para>
1382 osamu 8709 <section id="quiltrc"><title>Setting up <command>quilt</command></title>
1383 osamu 8601 <para>
1384 osamu 8709 The program <command>quilt</command> offers a basic method for recording
1385     modifications to the upstream source for Debian packaging. It's
1386     useful to have a slightly customized default, so let's create an alias
1387     <command>dquilt</command> for Debian packaging by adding the following
1388     line to <filename>~/.bashrc</filename>.
1389 osamu 8601 </para>
1390     <screen>
1391 osamu 8688 alias dquilt="quilt --quiltrc=~/.quiltrc-dpkg"
1392 osamu 8646 </screen>
1393     <para>
1394     Then let's create <filename>~/.quiltrc-dpkg</filename> as follows.
1395     </para>
1396     <screen>
1397 osamu 8601 d=. ; while [ ! -d $d/debian -a `readlink -e $d` != / ]; do d=$d/..; done
1398     if [ -d $d/debian ] &amp;&amp; [ -z $QUILT_PATCHES ]; then
1399 osamu 8709 # if in Debian packaging tree with unset $QUILT_PATCHES
1400 osamu 8649 QUILT_PATCHES="debian/patches"
1401     QUILT_PATCH_OPTS="--reject-format=unified"
1402     QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
1403     QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
1404     QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33"
1405 osamu 8601 if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
1406     fi
1407     </screen>
1408     <para>
1409     See <citerefentry> <refentrytitle>quilt</refentrytitle>
1410     <manvolnum>1</manvolnum> </citerefentry> and
1411 osamu 8709 <ulink url="&quilt-pdf;">quilt.pdf</ulink> on how to use
1412 osamu 8601 <command>quilt</command>.
1413     </para>
1414     </section>
1415 osamu 8709 <section id="fixupstream"><title>Fixing upstream bugs</title>
1416 osamu 8601 <para>
1417     Let's assume you find an error in the upstream <filename>Makefile</filename>
1418 osamu 8709 as follows where <literal>install: gentoo</literal> should have been
1419 osamu 8601 <literal>install: gentoo-target</literal>.
1420     </para>
1421     <screen>
1422     install: gentoo
1423     install ./gentoo $(BIN)
1424     install icons/* $(ICONS)
1425     install gentoorc-example $(HOME)/.gentoorc
1426     </screen>
1427     <para>
1428 osamu 8709 Let's fix this and record it with the <command>dquilt</command> command as
1429 osamu 8601 <filename>fix-gentoo-target.patch</filename>. <footnote><para> The
1430 osamu 8709 <filename>debian/patches</filename> directory should exist now if you ran
1431 osamu 8601 <command>dh_make</command> as described before. This example operation creates
1432 osamu 8709 it just in case you are updating an existing package. </para> </footnote>
1433 osamu 8601 </para>
1434     <screen>
1435     $ mkdir debian/patches
1436 osamu 8646 $ dquilt new fix-gentoo-target.patch
1437     $ dquilt add Makefile
1438 osamu 8601 </screen>
1439     <para>
1440     You change the <filename>Makefile</filename> file as follows.
1441     </para>
1442     <screen>
1443     install: gentoo-target
1444     install ./gentoo $(BIN)
1445     install icons/* $(ICONS)
1446     install gentoorc-example $(HOME)/.gentoorc
1447     </screen>
1448     <para>
1449 osamu 8709 Ask <command>dquilt</command> to generate the patch to create
1450 osamu 8601 <filename>debian/patches/fix-gentoo-target.patch</filename> and add its
1451 osamu 8621 description following <ulink url="&dep3;">DEP-3: Patch Tagging Guidelines</ulink>.
1452 osamu 8601 </para>
1453     <screen>
1454 osamu 8646 $ dquilt refresh
1455     $ dquilt header -e
1456 osamu 8601 ... describe patch
1457     </screen>
1458     </section>
1459 osamu 8709 <section id="destdir"><title>Installation of files to their destination</title>
1460 osamu 8601 <para>
1461 osamu 8709 Most third-party software installs itself in the <filename>/usr/local</filename>
1462     directory hierarchy. On Debian this is reserved for private use
1463     by the system administrator, so packages must not use directories such
1464     as <filename>/usr/local/bin</filename> but should instead use system
1465     directories such as <filename>/usr/bin</filename>, obeying the
1466     <ulink url="&fhs;">Filesystem Hierarchy Standard</ulink> (FHS).
1467 osamu 8601 </para>
1468     <para>
1469     Normally, <citerefentry> <refentrytitle>make</refentrytitle>
1470     <manvolnum>1</manvolnum> </citerefentry> is used to automate building the
1471 osamu 8709 program, and executing <literal>make install</literal> installs programs
1472     directly to the desired destination (following the
1473     <literal>install</literal> target in the
1474     <filename>Makefile</filename>). In order for Debian to provide
1475     pre-built installable packages, it modifies the build system to install
1476     programs into a file tree image created under a temporary directory
1477     instead of the actual destination.
1478 osamu 8601 </para>
1479     <para>
1480 osamu 8709 These two differences between normal program installation on one hand and the
1481     Debian packaging system on the other can be transparently addressed by the
1482     <systemitem role="package">debhelper</systemitem> package through the
1483 osamu 8601 <command>dh_auto_configure</command> and <command>dh_auto_install</command>
1484     commands if the following conditions are met.
1485     </para>
1486     <itemizedlist>
1487     <listitem>
1488     <para>
1489 osamu 8709 The <filename>Makefile</filename> must follow GNU conventions and
1490     support the <literal>$(DESTDIR)</literal> variable.
1491 osamu 8628 <footnote><para> See <ulink url="&gnu-destdir;">GNU Coding Standards: 7.2.4 DESTDIR: Support for Staged Installs</ulink>.</para></footnote>
1492 osamu 8601 </para>
1493     </listitem>
1494     <listitem>
1495     <para>
1496 osamu 8709 The source must follow the Filesystem Hierarchy Standard (FHS).
1497 osamu 8601 </para>
1498     </listitem>
1499     </itemizedlist>
1500     <para>
1501 osamu 8709 Programs that use GNU <command>autoconf</command> follow the GNU conventions
1502     automatically, so they can be trivial to package. On the basis of
1503     this and other heuristics, it is estimated that the
1504     <systemitem role="package">debhelper</systemitem> package will work for
1505     about 90% of packages without making any intrusive changes to their
1506     build system. So packaging is not as complicated as it may seem.
1507 osamu 8601 </para>
1508     <para>
1509 osamu 8709 If you need to make changes in the <filename>Makefile</filename>, you
1510     should be careful to support the <literal>$(DESTDIR)</literal>
1511     variable. Although it is unset by default, the <literal>$(DESTDIR)</literal>
1512     variable is prepended to each file path used for the program
1513     installation. The packaging script will set
1514     <literal>$(DESTDIR)</literal> to the temporary directory.
1515 osamu 8601 </para>
1516     <para>
1517 osamu 8725 For packages of the single binary type, the temporary directory used
1518 osamu 8709 by the <command>dh_auto_install</command> command will be set to
1519     <filename>debian/<replaceable>package</replaceable></filename>.
1520 osamu 8725 <footnote><para> For packages of the multiple binary type, the
1521 osamu 8601 <command>dh_auto_install</command> command uses <filename>debian/tmp</filename>
1522     as the temporary directory while the <command>dh_install</command> command with
1523     the help of
1524     <filename>debian/<replaceable>package-1</replaceable>.install</filename> and
1525     <filename>debian/<replaceable>package-2</replaceable>.install</filename> files
1526 osamu 8709 will split the contents of <filename>debian/tmp</filename> into
1527 osamu 8601 <filename>debian/<replaceable>package-1</replaceable></filename> and
1528     <filename>debian/<replaceable>package-2</replaceable></filename> temporary
1529 osamu 8709 directories, to create
1530     <filename><replaceable>package-1</replaceable>_*.deb</filename> and
1531     <filename><replaceable>package-2</replaceable>_*.deb</filename> binary
1532     packages.
1533 osamu 8601 </para> </footnote> Everything that is contained in the temporary directory
1534 osamu 8709 will be installed on users' systems when they install your package; the only
1535     difference is that <command>dpkg</command> will be installing the
1536     files to paths relative to the root directory rather than your working
1537     directory.
1538 osamu 8601 </para>
1539     <para>
1540     Bear in mind that even though your program installs in
1541     <filename>debian/<replaceable>package</replaceable></filename>, it still needs
1542 osamu 8709 to behave correctly when installed from the <filename>.deb</filename>
1543     package under the root directory. So you must not allow the build
1544 osamu 8601 system to hardcode strings like
1545     <literal>/home/me/deb/<replaceable>package</replaceable>-<replaceable>version</replaceable>/usr/share/<replaceable>package</replaceable></literal>
1546 osamu 8709 into files in the package.
1547 osamu 8601 </para>
1548     <para>
1549     Here's the relevant part of <systemitem role="package">gentoo</systemitem>'s
1550 osamu 8709 <filename>Makefile</filename><footnote><para> This is just an example to
1551     show what a <filename>Makefile</filename> should look like. If the
1552     <filename>Makefile</filename> is created by the
1553 osamu 8601 <command>./configure</command> command, the correct way to fix this kind of
1554 osamu 8709 <filename>Makefile</filename> is to execute <command>./configure</command>
1555     from the <command>dh_auto_configure</command> command with default
1556 osamu 8601 options including <literal>--prefix=/usr</literal>. </para> </footnote>:
1557     </para>
1558     <screen>
1559 osamu 8719 # Where to put binary executables on 'make install'?
1560 osamu 8601 BIN = /usr/local/bin
1561     # Where to put icons on 'make install'?
1562     ICONS = /usr/local/share/gentoo
1563     </screen>
1564     <para>
1565     We see that the files are set to install under <filename>/usr/local</filename>.
1566 osamu 8709 As explained above, that directory hierarchy is reserved for local use on
1567     Debian, so change those paths to:
1568 osamu 8601 </para>
1569     <screen>
1570 osamu 8719 # Where to put binary executables on 'make install'?
1571 osamu 8601 BIN = $(DESTDIR)/usr/bin
1572     # Where to put icons on 'make install'?
1573     ICONS = $(DESTDIR)/usr/share/gentoo
1574     </screen>
1575     <para>
1576 osamu 8709 The exact locations that should be used for binaries, icons,
1577     documentation, etc. are specified in the Filesystem Hierarchy Standard
1578     (FHS). You should browse through it and read the sections relevant to
1579     your package.
1580 osamu 8601 </para>
1581     <para>
1582 osamu 8719 So, we should install binary executables in <filename>/usr/bin</filename> instead of
1583 osamu 8601 <filename>/usr/local/bin</filename>, the manual page in
1584     <filename>/usr/share/man/man1</filename> instead of
1585 osamu 8709 <filename>/usr/local/man/man1</filename>, and so on. Notice how there's no manual
1586 osamu 8601 page mentioned in <systemitem role="package">gentoo</systemitem>'s
1587 osamu 8709 <filename>Makefile</filename>, but since Debian Policy requires that every
1588 osamu 8601 program has one, we'll make one later and install it in
1589     <filename>/usr/share/man/man1</filename>.
1590     </para>
1591     <para>
1592     Some programs don't use <filename>Makefile</filename> variables to define paths
1593     such as these. This means you might have to edit some real C sources in order
1594     to fix them to use the right locations. But where to search, and exactly what
1595     for? You can find this out by issuing:
1596     </para>
1597     <screen>
1598 osamu 8709 $ grep -nr --include='*.[c|h]' -e 'usr/local/lib' .
1599 osamu 8601 </screen>
1600     <para>
1601     <command>grep</command> will run recursively through the source tree and tell
1602     you the filename and the line number for all matches.
1603     </para>
1604     <para>
1605     Edit those files and in those lines replace <literal>usr/local/lib</literal>
1606 osamu 8621 with <literal>usr/lib</literal>. This can be done automatically as follows:
1607 osamu 8601 </para>
1608     <screen>
1609 osamu 8711 $ sed -i -e 's#usr/local/lib#usr/lib#g' \
1610 osamu 8601 $(find . -type f -name '*.[c|h]')
1611     </screen>
1612     <para>
1613 taffit-guest 8717 If you want to confirm each substitution instead, this can be done interactively as follows:
1614 osamu 8601 </para>
1615 osamu 8709 <screen>
1616     $ vim '+argdo %s#usr/local/lib#usr/lib#gce|update' +q \
1617     $(find . -type f -name '*.[c|h]')
1618     </screen>
1619    
1620 osamu 8601 <para>
1621 osamu 8709 Next you should find the <literal>install</literal> target (searching
1622     for the line that starts with <literal>install:</literal> will usually
1623     work) and rename all references to directories other than ones defined
1624     at the top of the <filename>Makefile</filename>.
1625 osamu 8601 </para>
1626     <para>
1627 osamu 8709 Originally, <systemitem role="package">gentoo</systemitem>'s
1628 osamu 8601 install target said:
1629     </para>
1630     <screen>
1631     install: gentoo-target
1632     install ./gentoo $(BIN)
1633     install icons/* $(ICONS)
1634     install gentoorc-example $(HOME)/.gentoorc
1635     </screen>
1636     <para>
1637 osamu 8709 Let's fix this upstream bug and record it with the <command>dquilt</command> command as
1638 osamu 8601 <filename>debian/patches/install.patch</filename>.
1639     </para>
1640     <screen>
1641 osamu 8646 $ dquilt new install.patch
1642     $ dquilt add Makefile
1643 osamu 8601 </screen>
1644     <para>
1645 osamu 8709 In your editor, change this for the Debian package as follows:
1646 osamu 8601 </para>
1647     <screen>
1648     install: gentoo-target
1649     install -d $(BIN) $(ICONS) $(DESTDIR)/etc
1650     install ./gentoo $(BIN)
1651     install -m644 icons/* $(ICONS)
1652     install -m644 gentoorc-example $(DESTDIR)/etc/gentoorc
1653     </screen>
1654     <para>
1655 osamu 8709 You'll have noticed that there's now an <literal>install -d</literal> command
1656 osamu 8601 before the other commands in the rule. The original
1657 osamu 8709 <filename>Makefile</filename> didn't have it because usually
1658 osamu 8601 <literal>/usr/local/bin</literal> and other directories already exist on the
1659 osamu 8709 system where you are running <literal>make install</literal>. However, since we will
1660     be installing into a newly created private directory tree, we will have to
1661 osamu 8601 create each and every one of those directories.
1662     </para>
1663     <para>
1664     We can also add in other things at the end of the rule, like the installation
1665     of additional documentation that the upstream authors sometimes omit:
1666     </para>
1667     <screen>
1668     install -d $(DESTDIR)/usr/share/doc/gentoo/html
1669     cp -a docs/* $(DESTDIR)/usr/share/doc/gentoo/html
1670     </screen>
1671     <para>
1672 osamu 8709 Check carefully, and if everything is okay, ask <command>dquilt</command> to
1673     generate the patch to create <filename>debian/patches/install.patch</filename>
1674 osamu 8601 and add its description.
1675     </para>
1676     <screen>
1677 osamu 8646 $ dquilt refresh
1678     $ dquilt header -e
1679 osamu 8601 ... describe patch
1680     </screen>
1681     <para>
1682     Now you have a series of patches.
1683     </para>
1684     <orderedlist numeration="arabic">
1685     <listitem>
1686     <para>
1687     Upstream bug fix: <filename>debian/patches/fix-gentoo-target.patch</filename>
1688     </para>
1689     </listitem>
1690     <listitem>
1691     <para>
1692     Debian specific packaging modification:
1693     <filename>debian/patches/install.patch</filename>
1694     </para>
1695     </listitem>
1696     </orderedlist>
1697     <para>
1698     Whenever you make changes that are not specifically related to Debian package
1699     such as <filename>debian/patches/fix-gentoo-target.patch</filename>, be sure to
1700     send them to the upstream maintainer so they can be included in the next
1701 osamu 8709 revision of the program and be useful to everyone else. Also remember
1702     to avoid making your fixes specific to Debian or Linux - or even Unix!
1703     Make them portable. This will make your fixes much easier to apply.
1704 osamu 8601 </para>
1705     <para>
1706     Note that you don't have to send the <filename>debian/*</filename> files
1707     upstream.
1708     </para>
1709     </section>
1710     <section id="difflibs"><title>Differing libraries</title>
1711     <para>
1712     There is one other common problem: libraries are often different from platform
1713     to platform. For example, a <filename>Makefile</filename> can contain a
1714 osamu 8714 reference to a library which doesn't exist on the Debian system. In that case, we
1715 osamu 8601 need to change it to a library which does exist in Debian, and serves the same
1716     purpose.
1717     </para>
1718     <para>
1719 osamu 8714 Let's assume a line in your program's <filename>Makefile</filename> (or
1720     <filename>Makefile.in</filename>) as the following.
1721 osamu 8601 </para>
1722     <screen>
1723 osamu 8713 LIBS = -lfoo -lbar
1724 osamu 8601 </screen>
1725     <para>
1726 osamu 8714 If your program doesn't compile since the <literal>foo</literal> library
1727     doesn't exist and its equivalent is provided by the <literal>foo2</literal>
1728     library on the Debian system, you can fix this build problem as
1729     <filename>debian/patches/foo2.patch</filename> by changing
1730     <literal>foo</literal> into <literal>foo2</literal>.<footnote><para>If there
1731     are API changes from the <literal>foo</literal> library to the
1732     <literal>foo2</literal> library, required changes to the source code need to be
1733     made to match the new API.</para> </footnote>
1734 osamu 8601 </para>
1735     <screen>
1736 osamu 8713 $ dquilt new foo2.patch
1737 osamu 8646 $ dquilt add Makefile
1738 osamu 8713 $ sed -i -e 's/-lfoo/-lfoo2/g' Makefile
1739 osamu 8646 $ dquilt refresh
1740     $ dquilt header -e
1741 osamu 8601 ... describe patch
1742     </screen>
1743     </section>
1744     </chapter>
1745     <chapter id="dreq"><title>Required files under the <filename>debian</filename> directory</title>
1746     <para>
1747     There is a new subdirectory under the program's source directory, it's called
1748     <filename>debian</filename>. There are a number of files in this directory
1749     that we should edit in order to customize the behavior of the package. The
1750     most important of them are <filename>control</filename>,
1751     <filename>changelog</filename>, <filename>copyright</filename> and
1752     <filename>rules</filename>, which are required for all packages.
1753 osamu 8668 <footnote><para>
1754     In this chapter, files in the <filename>debian</filename> directory are
1755     referred without preceding <filename>debian/</filename> for simplicity whenever
1756     they are obvious.
1757     </para></footnote>
1758 osamu 8601 </para>
1759     <section id="control"><title><filename>control</filename> file</title>
1760     <para>
1761     This file contains various values which <command>dpkg</command>,
1762     <command>dselect</command>, <command>apt-get</command>,
1763     <command>apt-cache</command>, <command>aptitude</command>, and other package
1764 osamu 8737 management tools will use to manage the package. It is defined by the
1765     <ulink url="&policy-control;">Debian Policy Manual, 5 "Control files and their fields"</ulink>.
1766 osamu 8601 </para>
1767     <para>
1768     Here is the <filename>control</filename> file <command>dh_make</command>
1769     created for us:
1770     </para>
1771     <screen>
1772     1 Source: gentoo
1773     2 Section: unknown
1774     3 Priority: extra
1775     4 Maintainer: Josip Rodin &lt;joy-mg@debian.org&gt;
1776     5 Build-Depends: debhelper (&gt;= 7.0.50~)
1777     6 Standards-Version: 3.8.4
1778     7 Homepage: &lt;insert the upstream URL, if relevant&gt;
1779     8
1780     9 Package: gentoo
1781     10 Architecture: any
1782     11 Depends: ${shlibs:Depends}, ${misc:Depends}
1783     12 Description: &lt;insert up to 60 chars description&gt;
1784     13 &lt;insert long description, indented with spaces&gt;
1785     </screen>
1786     <para>
1787     (I've added the line numbers.)
1788     </para>
1789     <para>
1790 osamu 8621 Lines 1-7 are the control information for the source package.
1791     Lines 9-13 are the control information for the binary package.
1792 osamu 8601 </para>
1793     <para>
1794     Line 1 is the name of the source package.
1795     </para>
1796     <para>
1797     Line 2 is the section of the distribution the source package goes into.
1798     </para>
1799     <para>
1800     As you may have noticed, Debian archive is divided in sections:
1801     <literal>main</literal> (the free software), <literal>non-free</literal> (the
1802     not really free software) and <literal>contrib</literal> (free software that
1803     depends on non-free software). Under those, there are logical subsections that
1804     describe in short what packages are in. So we have <literal>admin</literal>
1805     for administrator-only programs, <literal>base</literal> for the basic tools,
1806     <literal>devel</literal> for programmer tools, <literal>doc</literal> for
1807     documentation, <literal>libs</literal> for libraries, <literal>mail</literal>
1808     for e-mail readers and daemons, <literal>net</literal> for network apps and
1809     daemons, <literal>x11</literal> for X11 programs that don't fit anywhere else,
1810 osamu 8648 and many more.
1811     <footnote> <para>See
1812 osamu 8737 <ulink url="&policy-subsections;">Debian Policy Manual, 2.4 "Sections"</ulink> and
1813 taffit-guest 8665 <ulink url="&sections-unstable;">List of sections in <literal>sid</literal></ulink>.</para>
1814 osamu 8648 </footnote>
1815 osamu 8601 </para>
1816     <para>
1817     Let's change it then to x11. (A <literal>main/</literal> prefix is implied so
1818     we can omit it.)
1819     </para>
1820     <para>
1821 osamu 8648 Line 3 describes how important it is that the user installs this package.
1822     <footnote> <para>See
1823 osamu 8737 <ulink url="&policy-priorities;">Debian Policy Manual, 2.5 "Priorities"</ulink>.
1824 osamu 8601 </para>
1825 osamu 8648 </footnote>
1826     </para>
1827 osamu 8601 <itemizedlist>
1828     <listitem>
1829     <para>
1830     The <literal>optional</literal> priority will usually work for new packages
1831     that do not conflict with others with <literal>required</literal>,
1832     <literal>important</literal> or <literal>standard</literal> priorities.
1833     </para>
1834     </listitem>
1835     <listitem>
1836     <para>
1837     The <literal>extra</literal> priority will usually work for new packages that
1838     conflict with others with non-<literal>extra</literal> priorities.
1839     </para>
1840     </listitem>
1841     </itemizedlist>
1842     <para>
1843     Section and priority are used by the frontends like <command>aptitude</command>
1844     when they sort packages and select defaults. Once you upload the package to
1845     Debian, the value of these two fields can be overridden by the archive
1846     maintainers, in which case you will be notified by email.
1847     </para>
1848     <para>
1849     As this is a normal priority package and doesn't conflict with anything else,
1850     we will change the priority to <literal>optional</literal>.
1851     </para>
1852     <para>
1853     Line 4 is the name and email address of the maintainer. Make sure that this
1854     field includes a valid <literal>To</literal> header for an email, because after
1855     you upload it, the bug tracking system will use it to deliver bug emails to
1856     you. Avoid using commas, ampersands and parenthesis.
1857     </para>
1858     <para>
1859     The 5th line includes the list of packages required to build your package as
1860     the <literal>Build-Depends</literal> field. You can also have the
1861 osamu 8648 <literal>Build-Depends-Indep</literal> field as an additional line, here.
1862 osamu 8737 <footnote><para>See
1863     <ulink url="&policy-relationships;#s-sourcebinarydeps">Debian Policy Manual, 7.7 "Relationships between source and binary packages - Build-Depends, Build-Depends-Indep, Build-Conflicts, Build-Conflicts-Indep"</ulink>.</para></footnote>
1864     Some packages like
1865 osamu 8642 <systemitem role="package">gcc</systemitem> and
1866     <systemitem role="package">make</systemitem> which are required by the
1867     <systemitem role="package">build-essential</systemitem> package are implied. If you need
1868 osamu 8601 to have other tools to build your package, you should add them to these fields.
1869     Multiple entries are separated with commas; read on for the explanation of
1870 osamu 8719 binary package dependencies to find out more about the syntax of these lines.
1871 osamu 8601 </para>
1872     <itemizedlist>
1873     <listitem>
1874     <para>
1875     For all packages packaged with the <command>dh</command> command in the
1876     <filename>debian/rules</filename> file, you must have <literal>debhelper
1877     (&gt;=7.0.50~)</literal> in the <literal>Build-Depends</literal> field to
1878     satisfy the Debian Policy requirement for the <literal>clean</literal> target.
1879     </para>
1880     </listitem>
1881     <listitem>
1882     <para>
1883     For source packages which have some binary packages with <literal>Architecture:
1884     any</literal>, they are rebuild by the autobuilder. Since this autobuilder
1885     procedure runs <literal>debian/rules build</literal> in it while installing
1886 taffit-guest 8665 only packages listed in the <literal>Build-Depends</literal> field (see <xref linkend="autobuilder"/>), the <literal>Build-Depends</literal> field needs to
1887 osamu 8601 list practically all the required packages and the
1888     <literal>Build-Depends-indep</literal> is rarely used.
1889     </para>
1890     </listitem>
1891     <listitem>
1892     <para>
1893     For source packages which have binary packages only with <literal>Architecture:
1894     all</literal>, the <literal>Build-Depends-Indep</literal> field may list all
1895     the required packages unless they are already listed in the
1896     <literal>Build-Depends</literal> field to satisfy the Debian Policy requirement
1897     for the <literal>clean</literal> target.
1898     </para>
1899     </listitem>
1900     </itemizedlist>
1901     <para>
1902     If you are not sure which one should be used, use the
1903     <literal>Build-Depends</literal> field to be on the safe side.
1904     <footnote><para> This somewhat strange situation is a feature well documented
1905 osamu 8628 in the <ulink url="&policy-build-depends-indep;">Debian Policy
1906 osamu 8601 Manual, Footnotes 48</ulink>. This is not due to the use of the
1907     <command>dh</command> command in the <filename>debian/rules</filename> file but
1908     due to how the <command>dpkg-buildpackage</command> works. The same situation
1909     applies to the <ulink url="https://bugs.launchpad.net/launchpad-buildd/+bug/238141">auto build system
1910     for Ubuntu</ulink>. </para> </footnote>
1911     </para>
1912     <para>
1913     To find out what packages your package needs to be built run the command:
1914     </para>
1915     <screen>
1916     $ dpkg-depcheck -d ./configure
1917     </screen>
1918     <para>
1919     To manually find exact build dependency for
1920     <command><replaceable>/usr/bin/foo</replaceable></command>, you execute
1921     </para>
1922     <screen>
1923     $ objdump -p <replaceable>/usr/bin/foo</replaceable> | grep NEEDED
1924     </screen>
1925     <para>
1926     and for each library listed, e.g., <command>libfoo.so.6</command>, execute
1927     </para>
1928     <screen>
1929     $ dpkg -S libfoo.so.6
1930     </screen>
1931     <para>
1932     Then you just take <literal>-dev</literal> version of every package as
1933     <literal>Build-Depends</literal> entry. If you use <command>ldd</command> for
1934     this purpose, it will report indirect lib dependencies as well, resulting in
1935     the problem of excessive build dependencies.
1936     </para>
1937     <para>
1938     <systemitem role="package">gentoo</systemitem> also happens to require
1939     <systemitem role="package">xlibs-dev</systemitem>, <systemitem role="package">libgtk1.2-dev</systemitem> and <systemitem role="package">libglib1.2-dev</systemitem> to build, so we'll add them here
1940     next to <systemitem role="package">debhelper</systemitem>.
1941     </para>
1942     <para>
1943 osamu 8628 Line 6 is the version of the <ulink url="&debian-policy;">Debian Policy
1944 osamu 8601 Manual</ulink> standards this package follows, the one you read while making
1945     your package.
1946     </para>
1947     <para>
1948     On line 7 you can put the URL of the homepage for the upstream program.
1949     </para>
1950     <para>
1951     Line 9 is the name of the binary package. This is usually the same as the name
1952     of the source package, but it doesn't necessarily have to be that way.
1953     </para>
1954     <para>
1955     Line 10 describes the CPU architecture the binary package can be compiled for.
1956     We'll leave this as <literal>any</literal> because <citerefentry>
1957     <refentrytitle>dpkg-gencontrol</refentrytitle> <manvolnum>1</manvolnum>
1958     </citerefentry> will fill in the appropriate value for any machine this package
1959     gets compiled on.
1960     </para>
1961     <para>
1962     If your package is architecture independent (for example, a shell or Perl
1963     script, or a document), change this to <literal>all</literal>, and read later
1964     in <xref linkend="rules"/> about using the <literal>binary-indep</literal> rule
1965     instead of <literal>binary-arch</literal> for building the package.
1966     </para>
1967     <para>
1968     Line 11 shows one of the most powerful features of the Debian packaging system.
1969     Packages can relate to each other in various ways. Apart from
1970     <literal>Depends</literal>, other relationship fields are
1971     <literal>Recommends</literal>, <literal>Suggests</literal>,
1972     <literal>Pre-Depends</literal>, <literal>Breaks</literal>,
1973     <literal>Conflicts</literal>, <literal>Provides</literal>, and
1974     <literal>Replaces</literal>.
1975     </para>
1976     <para>
1977     The package management tools usually behave the same way when dealing with
1978     these relations; if not, it will be explained. (see <citerefentry>
1979     <refentrytitle>dpkg</refentrytitle> <manvolnum>8</manvolnum> </citerefentry>,
1980     <citerefentry> <refentrytitle>dselect</refentrytitle> <manvolnum>8</manvolnum>
1981     </citerefentry>, <citerefentry> <refentrytitle>apt</refentrytitle>
1982     <manvolnum>8</manvolnum> </citerefentry>, <citerefentry>
1983     <refentrytitle>aptitude</refentrytitle> <manvolnum>1</manvolnum>
1984     </citerefentry> etc.)
1985     </para>
1986     <para>
1987 osamu 8648 Here is a simplified description of package relationships.
1988 osamu 8621 <footnote><para>See
1989 osamu 8737 <ulink url="&policy-relationships;">Debian Policy Manual, 7 "Declaring relationships between packages"</ulink>.
1990 osamu 8648 </para></footnote>
1991 osamu 8601 </para>
1992     <itemizedlist>
1993     <listitem>
1994     <para>
1995     <literal>Depends</literal>
1996     </para>
1997     <para>
1998     The package will not be installed unless the packages it depends on are
1999     installed. Use this if your program absolutely will not run (or will cause
2000     severe breakage) unless a particular package is present.
2001     </para>
2002     </listitem>
2003     <listitem>
2004     <para>
2005     <literal>Recommends</literal>
2006     </para>
2007     <para>
2008     Use this for packages that are not strictly necessary but are typically used
2009     with your program. When a user installs your program, all frontends will
2010     likely prompt them to install the recommended packages.
2011     <command>aptitude</command> and <command>apt-get</command> install recommended
2012     packages along with your package (but the user can disable this default
2013     behaviour). <command>dpkg</command> will ignore this field.
2014     </para>
2015     </listitem>
2016     <listitem>
2017     <para>
2018     <literal>Suggests</literal>
2019     </para>
2020     <para>
2021     Use this for packages which will work nicely with your program but are not at
2022     all necessary. When a user installs your program, all frontends will likely
2023     prompt them to install the suggested packages. <command>aptitude</command> can
2024     be configured to install suggested packages along with your package but this is
2025     not its default. <command>dpkg</command> and <command>apt-get</command> will
2026     ignore this field.
2027     </para>
2028     </listitem>
2029     <listitem>
2030     <para>
2031     <literal>Pre-Depends</literal>
2032     </para>
2033     <para>
2034     This is stronger than <literal>Depends</literal>. The package will not be
2035     installed unless the packages it pre-depends on are installed and
2036     <emphasis>correctly configured</emphasis>. Use this <emphasis>very</emphasis>
2037 osamu 8628 sparingly and only after discussing it on the <ulink url="&debian-devel-ldo;">debian-devel@lists.debian.org</ulink>
2038 osamu 8601 mailing list. Read: don't use it at all. :-)
2039     </para>
2040     </listitem>
2041     <listitem>
2042     <para>
2043     <literal>Conflicts</literal>
2044     </para>
2045     <para>
2046     The package will not be installed until all the packages it conflicts with have
2047     been removed. Use this if your program absolutely will not run or will cause
2048     severe problems if a particular package is present.
2049     </para>
2050     </listitem>
2051     <listitem>
2052     <para>
2053     <literal>Breaks</literal>
2054     </para>
2055     <para>
2056     The package will be installed while all the listed packages will be broken.
2057     Normally a <literal>Breaks</literal> entry has an earlier than version clause.
2058     The resolution is generally to upgrade the listed packages by the higher-level
2059     package management tools.
2060     </para>
2061     </listitem>
2062     <listitem>
2063     <para>
2064     <literal>Provides</literal>
2065     </para>
2066     <para>
2067     For some types of packages where there are multiple alternatives virtual names
2068     have been defined. You can get the full list in the
2069 osamu 8639 <ulink url="&virtual-package;">virtual-package-names-list.txt.gz</ulink>
2070 osamu 8601 file. Use this if your program provides a function of an existing virtual
2071     package.
2072     </para>
2073     </listitem>
2074     <listitem>
2075     <para>
2076     <literal>Replaces</literal>
2077     </para>
2078     <para>
2079     Use this when your program replaces files from another package, or completely
2080     replaces another package (used in conjunction with
2081     <literal>Conflicts</literal>). Files from the named packages will be
2082     overwritten with the files from your package.
2083     </para>
2084     </listitem>
2085     </itemizedlist>
2086     <para>
2087     All these fields have uniform syntax. They are a list of package names
2088     separated by commas. These package names may also be lists of alternative
2089     package names, separated by vertical bar symbols <literal>|</literal> (pipe
2090     symbols).
2091     </para>
2092     <para>
2093     The fields may restrict their applicability to particular versions of each
2094     named package. These versions are listed in parentheses after each individual
2095     package name, and they should contain a relation from the list below followed
2096     by the version number. The relations allowed are: <literal>&lt;&lt;</literal>,
2097     <literal>&lt;=</literal>, <literal>=</literal>, <literal>&gt;=</literal> and
2098     <literal>&gt;&gt;</literal> for strictly lower, lower or equal, exactly equal,
2099     greater or equal and strictly greater, respectively. For example,
2100     </para>
2101     <screen>
2102     Depends: foo (&gt;= 1.2), libbar1 (= 1.3.4)
2103     Conflicts: baz
2104     Recommends: libbaz4 (&gt;&gt; 4.0.7)
2105     Suggests: quux
2106     Replaces: quux (&lt;&lt; 5), quux-foo (&lt;= 7.6)
2107     </screen>
2108     <para>
2109     The last feature you need to know about is
2110     <literal>${shlibs:Depends}</literal>, <literal>${perl:Depends}</literal>,
2111 osamu 8648 <literal>${misc:Depends}</literal>, etc.
2112 osamu 8601 </para>
2113     <para>
2114     <citerefentry> <refentrytitle>dh_shlibdeps</refentrytitle>
2115 osamu 8648 <manvolnum>1</manvolnum> </citerefentry> calculates shared library dependencies
2116     for binary packages. It generates a list of ELF executables and shared
2117     libraries it has found for each binary package. Such list is used for
2118     substituting <literal>${shlibs:Depends}</literal>.
2119 osamu 8601 </para>
2120     <para>
2121 osamu 8648 <citerefentry> <refentrytitle>dh_perl</refentrytitle> <manvolnum>1</manvolnum>
2122 taffit-guest 8665 </citerefentry> calculates Perl dependencies. It generates a list of a
2123     dependency on <literal>perl</literal> or <literal>perlapi</literal> for each binary package. Such list is used for
2124 osamu 8648 substituting <literal>${perl:Depends}</literal>.
2125 osamu 8601 </para>
2126     <para>
2127     Some <systemitem role="package">debhelper</systemitem> commands may make the
2128 osamu 8648 generated package need to depend on some other packages. All such commands
2129     generate a list of required packages for each binary package.
2130     Such list is used for substituting <literal>${misc:Depends}</literal>.
2131 osamu 8601 </para>
2132     <para>
2133 osamu 8648 <citerefentry> <refentrytitle>dh_gencontrol</refentrytitle>
2134     <manvolnum>1</manvolnum> </citerefentry> generates
2135     <filename>DEBIAN/control</filename> for each binary package while
2136     substituting <literal>${shlibs:Depends}</literal>,
2137     <literal>${perl:Depends}</literal>, <literal>${misc:Depends}</literal>, etc.
2138     </para>
2139     <para>
2140 osamu 8601 Having said all that, we can leave the <literal>Depends</literal> field exactly
2141     as it is now, and insert another line after it saying <literal>Suggests:
2142     file</literal>, because <systemitem role="package">gentoo</systemitem> can use
2143     some features provided by that <systemitem role="package">file</systemitem>
2144     package.
2145     </para>
2146 osamu 8621 <para> Line 9 is the Homepage URL. Let's assume this to be at
2147 osamu 8637 <ulink url="&gentoo;"/>.
2148 osamu 8621 </para>
2149 osamu 8601 <para>
2150     Line 12 is the short description. Most people screens are 80 columns wide so
2151     this shouldn't be longer than about 60 characters. I'll change it to
2152     <literal>fully GUI-configurable, two-pane X file manager</literal>.
2153     </para>
2154     <para>
2155     Line 13 is where the long description goes. This should be a paragraph which
2156     gives more details about the package. Column 1 of each line should be empty.
2157     There must be no blank lines, but you can put a single <literal>.</literal>
2158     (dot) in a column to simulate that. Also, there must be no more than one blank
2159 osamu 8621 line after the long description. <footnote><para>These descriptions are in
2160     English. Translations of these descriptions are provided by
2161     <ulink url="&ddtp;">The Debian Description Translation Project - DDTP</ulink>.</para></footnote>
2162 osamu 8601 </para>
2163     <para>
2164 osamu 8648 Let's insert <literal>Vcs-*</literal> fields to document the Version Control
2165     System (VCS) location between line 6 and 7.
2166     <footnote><para>See
2167 osamu 8725 <ulink url="&devref-bpp-vcs;">Debian Developer's Reference, 6.2.5. "Version Control System location"</ulink>.
2168 osamu 8648 </para></footnote>
2169     Let's assume that the <systemitem role="package">gentoo</systemitem>
2170     package has its VCS located in Debian Alioth Git Service at
2171 osamu 8601 <literal>git://git.debian.org/git/collab-maint/gentoo.git</literal>.
2172     </para>
2173     <para>
2174     Finally, here is the updated <filename>control</filename> file:
2175     </para>
2176     <screen>
2177     1 Source: gentoo
2178     2 Section: x11
2179     3 Priority: optional
2180     4 Maintainer: Josip Rodin &lt;joy-mg@debian.org&gt;
2181     5 Build-Depends: debhelper (&gt;= 7.0.5), xlibs-dev, libgtk1.2-dev, libglib1.2-dev
2182     6 Standards-Version: 3.8.4
2183     7 Vcs-Git: git://git.debian.org/git/collab-maint/gentoo.git
2184     8 Vcs-browser: http://git.debian.org/?p=collab-maint/gentoo.git
2185 osamu 8628 9 Homepage: &gentoo;
2186 osamu 8601 10
2187     11 Package: gentoo
2188     12 Architecture: any
2189     13 Depends: ${shlibs:Depends}, ${misc:Depends}
2190     14 Suggests: file
2191     15 Description: fully GUI-configurable, two-pane X file manager
2192     16 gentoo is a two-pane file manager for the X Window System. gentoo lets the
2193     17 user do (almost) all of the configuration and customizing from within the
2194     18 program itself. If you still prefer to hand-edit configuration files,
2195     19 they're fairly easy to work with since they are written in an XML format.
2196     20 .
2197     21 gentoo features a fairly complex and powerful file identification system,
2198     22 coupled to a object-oriented style system, which together give you a lot
2199     23 of control over how files of different types are displayed and acted upon.
2200     24 Additionally, over a hundred pixmap images are available for use in file
2201     25 type descriptions.
2202     26 .
2203     29 gentoo was written from scratch in ANSI C, and it utilises the GTK+ toolkit
2204     30 for its interface.
2205     </screen>
2206     <para>
2207     (I've added the line numbers.)
2208     </para>
2209     </section>
2210     <section id="copyright"><title><filename>copyright</filename> file</title>
2211     <para>
2212     This file contains the information about package upstream resources, copyright
2213 osamu 8648 and license information.
2214 osamu 8737 <ulink url="&policy-copyright;">Debian Policy Manual, 12.5 "Copyright information"</ulink>
2215 osamu 8648 dictates its content and
2216 taffit-guest 8665 <ulink url="&dep5;">DEP-5: Machine-parseable <filename>debian/copyright</filename></ulink>
2217 osamu 8648 provides guidelines for its format.
2218 osamu 8601 </para>
2219     <para>
2220     <command>dh_make</command> can give you a template
2221     <filename>copyright</filename> file. Let's use the <literal>--copyright
2222     gpl2</literal> option here to get a template file for the <systemitem role="package">gentoo</systemitem> package released under GPL-2.
2223     </para>
2224     <para>
2225     You must fill in missing information such as the place you got the package
2226     from, the actual copyright notice and their license to complete this file. For
2227     the common free software licenses such as GNU GPL-1, GNU GPL-2, GNU GPL-3,
2228     LGPL-2, LGPL-2.1, LGPL-3, GNU FDL-1.2, GNU FDL-1.3, Apache-2.0 or the Artistic
2229     license, you can just refer to the appropriate file in
2230     <filename>/usr/share/common-licenses/</filename> directory that exists on every
2231     Debian system. Otherwise, you must include the complete license.
2232     </para>
2233     <para>
2234     In short, here's how <systemitem role="package">gentoo</systemitem>'s
2235     <filename>copyright</filename> file should look like:
2236     </para>
2237     <screen>
2238     1 Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&amp;rev=135
2239     2 Name: gentoo
2240     3 Maintainer: Josip Rodin &lt;joy-mg@debian.org&gt;
2241     4 Source: http://sourceforge.net/projects/gentoo/files/
2242     5
2243     6 Copyright: 1998-2010 Emil Brink &lt;emil@obsession.se&gt;
2244     7 License: GPL-2+
2245     8
2246     9 Files: icons/*
2247     10 Copyright: 1998 Johan Hanson &lt;johan@tiq.com&gt;
2248     11 License: GPL-2+
2249     12
2250     13 Files: debian/*
2251     14 Copyright: 1998-2010 Josip Rodin &lt;joy-mg@debian.org&gt;
2252     15 License: GPL-2+
2253     16
2254     17 License: GPL-2+
2255     18 This program is free software; you can redistribute it and/or modify
2256     19 it under the terms of the GNU General Public License as published by
2257     20 the Free Software Foundation; either version 2 of the License, or
2258     21 (at your option) any later version.
2259     22 .
2260     23 This program is distributed in the hope that it will be useful,
2261     24 but WITHOUT ANY WARRANTY; without even the implied warranty of
2262     25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2263     26 GNU General Public License for more details.
2264     27 .
2265     28 You should have received a copy of the GNU General Public License along
2266     29 with this program; if not, write to the Free Software Foundation, Inc.,
2267     30 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2268     31 .
2269     32 On Debian systems, the full text of the GNU General Public
2270     33 License version 2 can be found in the file
2271     34 `/usr/share/common-licenses/GPL-2'.
2272     </screen>
2273     <para>
2274     (I've added the line numbers.)
2275     </para>
2276     <para>
2277     Please follow the HOWTO provided by ftpmasters and sent to
2278 osamu 8637 debian-devel-announce: <ulink url="&howto-copyright;"/>.
2279 osamu 8601 </para>
2280     </section>
2281     <section id="changelog"><title><filename>changelog</filename> file</title>
2282     <para>
2283 osamu 8648 This is a required file, which has a special format described in the
2284 osamu 8737 <ulink url="&policy-dpkgchangelog;">Debian Policy Manual, 4.4 "debian/changelog"</ulink>.
2285 osamu 8648 This format is used by <command>dpkg</command> and other programs to obtain the
2286     version number, revision, distribution and urgency of your package.
2287 osamu 8601 </para>
2288     <para>
2289     For you, it is also important, since it is good to have documented all changes
2290     you have done. It will help people downloading your package to see whether
2291     there are issues with the package that they should know about. It will be
2292     saved as <filename>/usr/share/doc/gentoo/changelog.Debian.gz</filename> in the
2293     binary package.
2294     </para>
2295     <para>
2296     <command>dh_make</command> created a default one, and this is how it looks
2297     like:
2298     </para>
2299     <screen>
2300     1 gentoo (0.9.12-1) unstable; urgency=low
2301     2
2302     3 * Initial release (Closes: #<replaceable>nnnn</replaceable>) &lt;<replaceable>nnnn</replaceable> is the bug number of your ITP&gt;
2303     4
2304     5 -- Josip Rodin &lt;joy-mg@debian.org&gt; Mon, 22 Mar 2010 00:37:31 +0100
2305     6
2306     </screen>
2307     <para>
2308     (I've added the line numbers.)
2309     </para>
2310     <para>
2311     Line 1 is the package name, version, distribution, and urgency. The name must
2312     match the source package name, distribution should be either
2313     <literal>unstable</literal> (or even <literal>experimental</literal>)
2314     <footnote><para> Some people use invalid distribution values such as
2315     <literal>UNRELEASED</literal> to prevent a package to be accidentally uploaded
2316     when updating a package in a shared VCS. </para> </footnote>, and urgency
2317     shouldn't be changed to anything higher than <literal>low</literal>. :-)
2318     </para>
2319     <para>
2320     Lines 3-5 are a log entry, where you document changes made in this package
2321     revision (not the upstream changes - there is special file for that purpose,
2322     created by the upstream authors, which you will later install as
2323     <filename>/usr/share/doc/gentoo/changelog.gz</filename>). Let's assume your
2324     ITP (Intent To Package) bug report number was <literal>12345</literal>. New
2325     lines must be inserted just before the uppermost line that begins with
2326     <literal>*</literal> (asterisk). You can do it with <citerefentry>
2327     <refentrytitle>dch</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>, or
2328     manually with a text editor.
2329     </para>
2330     <para>
2331     You will end up with something like this:
2332     </para>
2333     <screen>
2334     1 gentoo (0.9.12-1) unstable; urgency=low
2335     2
2336     3 * Initial Release. Closes: #12345
2337     4 * This is my first Debian package.
2338     5 * Adjusted the Makefile to fix $(DESTDIR) problems.
2339     6
2340     7 -- Josip Rodin &lt;joy-mg@debian.org&gt; Mon, 22 Mar 2010 00:37:31 +0100
2341     8
2342     </screen>
2343     <para>
2344     (I've added the line numbers.)
2345     </para>
2346     <para>
2347     You can read more about updating the <filename>changelog</filename> file later
2348 taffit-guest 8665 in <xref linkend="update"/>.
2349 osamu 8601 </para>
2350     </section>
2351     <section id="rules"><title><filename>rules</filename> file</title>
2352     <para>
2353     Now we need to take a look at the exact rules which <citerefentry>
2354     <refentrytitle>dpkg-buildpackage</refentrytitle> <manvolnum>1</manvolnum>
2355     </citerefentry> will use to actually create the package. This file is actually
2356     another <filename>Makefile</filename>, but different from the one(s) in the
2357     upstream source. Unlike other files in <filename>debian</filename>, this one
2358     is marked as executable.
2359     </para>
2360     <section id="targets"><title>Targets of <filename>rules</filename> file</title>
2361     <para>
2362     Every <filename>rules</filename> file, as any other
2363     <filename>Makefile</filename>, consists of several targets and their rules
2364 osamu 8628 specifying how to handle the source. <ulink url="&policy-debianrules;">Debian
2365 osamu 8737 Policy Manual, 4.9 "Main building script: debian/rules"</ulink> explains its
2366 osamu 8601 details.
2367     </para>
2368     <para>
2369     The simplified explanation of targets are the following.
2370     </para>
2371     <itemizedlist>
2372     <listitem>
2373     <para>
2374     <literal>clean</literal> target: to clean all compiled, generated, and useless
2375     files in the build-tree. (required)
2376     </para>
2377     </listitem>
2378     <listitem>
2379     <para>
2380     <literal>build</literal> target: to build the source into compiled programs and
2381     formatted documents in the build-tree. (required)
2382     </para>
2383     </listitem>
2384     <listitem>
2385     <para>
2386     <literal>install</literal> target: to install files into a file tree for each
2387     binary package under the <filename>debian</filename> directory. If defined,
2388     <literal>binary*</literal> targets effectively depend on this target.
2389     (optional)
2390     </para>
2391     </listitem>
2392     <listitem>
2393     <para>
2394     <literal>binary</literal> target: to create all binary packages (effectively
2395     combination of <literal>binary-arch</literal> and
2396     <literal>binary-indep</literal> targets). (required)<footnote><para> This
2397 taffit-guest 8665 target is used by <literal>dpkg-buildpackage</literal> as in <xref linkend="completebuild"/>. </para> </footnote>
2398 osamu 8601 </para>
2399     </listitem>
2400     <listitem>
2401     <para>
2402     <literal>binary-arch</literal> target: to create arch-dependent
2403     (<literal>Architecture: any</literal>) binary packages in the parent directory.
2404     (required)<footnote><para> This target is used by <literal>dpkg-buildpackage
2405 taffit-guest 8665 -B</literal> as in <xref linkend="autobuilder"/>. </para> </footnote>
2406 osamu 8601 </para>
2407     </listitem>
2408     <listitem>
2409     <para>
2410     <literal>binary-indep</literal> target: to create arch-independent
2411     (<literal>Architecture: all</literal>) binary packages in the parent directory.
2412     (required)<footnote><para> This target is used by <literal>dpkg-buildpackage
2413     -A</literal>. </para> </footnote>
2414     </para>
2415     </listitem>
2416     <listitem>
2417     <para>
2418     <literal>get-orig-source</literal> target: to obtain the most recent version of
2419     the original source package from upstream archive site. (optional)
2420     </para>
2421     </listitem>
2422     </itemizedlist>
2423     <para>
2424     Rules that you want to execute are invoked as command line arguments (for
2425     example, <literal>./debian/rules build</literal> or <literal>fakeroot make -f
2426     debian/rules binary</literal>). After the target name, you can name the
2427     dependency, program or file that the rule depends on. After that, there can be
2428     any number of commands, indented with
2429     <literal><replaceable>TAB</replaceable></literal>. A new rule begins with the
2430     target declaration in the first column. Empty lines and lines beginning with
2431     <literal>#</literal> (hash) are treated as comments and ignored.
2432     </para>
2433     <para>
2434     You are probably confused now, but it will all be clear upon examination of the
2435     <filename>rules</filename> file that <command>dh_make</command> gives us as a
2436     default. You should also read <literal>info make</literal> for more
2437     information.
2438     </para>
2439     </section>
2440     <section id="defaultrules"><title>Default <filename>rules</filename> file</title>
2441     <para>
2442     Newer <command>dh_make</command> generates a very simple but powerful default
2443     <filename>rules</filename> file using the <command>dh</command> command:
2444     </para>
2445     <screen>
2446     1 #!/usr/bin/make -f
2447     2 # -*- makefile -*-
2448     3 # Sample debian/rules that uses debhelper.
2449     4 # This file was originally written by Joey Hess and Craig Small.
2450     5 # As a special exception, when this file is copied by dh-make into a
2451     6 # dh-make output file, you may use that output file without restriction.
2452     7 # This special exception was added by Craig Small in version 0.37 of dh-make.
2453     8
2454     9 # Uncomment this to turn on verbose mode.
2455     10 #export DH_VERBOSE=1
2456     11
2457     12 %:
2458     13 dh $@
2459     </screen>
2460     <para>
2461     (I've added the line numbers. In the actual <filename>rules</filename> file,
2462     the leading white spaces are TAB codes.)
2463     </para>
2464     <para>
2465     You are probably familiar with lines like line 1 from shell and Perl scripts.
2466     It tells the operating system that this file is to be processed with
2467     <filename>/usr/bin/make</filename>.
2468     </para>
2469     <para>
2470 taffit-guest 8665 Line 11 can be uncommented to set <literal>DH_VERBOSE</literal> variable to 1.
2471 osamu 8601 Then, the <command>dh</command> command will output which
2472     <command>dh_*</command> commands are executed by the <command>dh</command>
2473     command. You can also add <literal>export DH_OPTIONS=-v</literal> line here.
2474     Then each <command>dh_*</command> command will output which commands are
2475     executed by each <command>dh_*</command> command. This helps you to understand
2476     what exactly is going on behind this simple <filename>rules</filename> file and
2477     to debug its problems. This new <command>dh</command> is a core part of the
2478     <systemitem role="package">debhelper</systemitem> tools and does not hide
2479     anything from you.
2480     </para>
2481     <para>
2482     Lines 12 and 13 are where all the work is done. The percent sign means any
2483     targets which then call a single program, <command>dh</command> with the target
2484     name. <footnote><para> This uses the new <systemitem role="package">debhelper</systemitem> V7 features. Its design concepts are
2485 osamu 8628 explained in <ulink url="&debhelper-slides;">Not Your
2486 osamu 8601 Grandpa's Debhelper</ulink> presented at Debconf9 by the <systemitem role="package">debhelper</systemitem> upstream. Under
2487     <literal>lenny</literal>, <command>dh_make</command> created a much more
2488     complicated <filename>rules</filename> file with many <command>dh_*</command>
2489     scripts listed for each required explicit targets and frozen them to the state
2490     when it was initially packaged. This new <command>dh</command> command is
2491     simpler and frees us from this constrain. You still have full power to
2492 taffit-guest 8665 customize this with <literal>override_dh_*</literal> targets. See <xref linkend="customrules"/>. It is based only on the <systemitem role="package">debhelper</systemitem> package and does not obfuscate the
2493 osamu 8601 package building process like the <systemitem role="package">cdbs</systemitem>
2494     package. </para> </footnote> The <command>dh</command> command is a wrapper
2495     script which runs appropriate sequences of <command>dh_*</command> programs
2496     depending on its argument. <footnote><para> You can verify actual sequences of
2497     <command>dh_*</command> programs invoked for a given
2498     <literal><replaceable>target</replaceable></literal> as <literal>dh --no-act
2499     <replaceable>target</replaceable></literal> or <literal>debian/rules --
2500     '--no-act <replaceable>target</replaceable>'</literal> without really running
2501     them. </para> </footnote>
2502     </para>
2503     <itemizedlist>
2504     <listitem>
2505     <para>
2506     <literal>debian/rules clean</literal> runs <literal>dh clean</literal>; which
2507     in turn runs the following:
2508     </para>
2509     <screen>
2510     dh_testdir
2511     dh_auto_clean
2512     dh_clean
2513     </screen>
2514     </listitem>
2515     <listitem>
2516     <para>
2517     <literal>debian/rules build</literal> runs <literal>dh build</literal>; which
2518     in turn runs the following:
2519     </para>
2520     <screen>
2521     dh_testdir
2522     dh_auto_configure
2523     dh_auto_build
2524     dh_auto_test
2525     </screen>
2526     </listitem>
2527     <listitem>
2528     <para>
2529     <literal>fakeroot debian/rules binary</literal> runs <literal>fakeroot dh
2530     binary</literal>; which in turn runs the following<footnote><para> This assumes
2531     that the <systemitem role="package">python-support</systemitem> package is
2532     installed on the system. </para> </footnote>:
2533     </para>
2534     <screen>
2535     dh_testroot
2536     dh_prep
2537     dh_installdirs
2538     dh_auto_install
2539     dh_install
2540     dh_installdocs
2541     dh_installchangelogs
2542     dh_installexamples
2543     dh_installman
2544     dh_installcatalogs
2545     dh_installcron
2546     dh_installdebconf
2547     dh_installemacsen
2548     dh_installifupdown
2549     dh_installinfo
2550     dh_pysupport
2551     dh_installinit
2552     dh_installmenu
2553     dh_installmime
2554     dh_installmodules
2555     dh_installlogcheck
2556     dh_installlogrotate
2557     dh_installpam
2558     dh_installppp
2559     dh_installudev
2560     dh_installwm
2561     dh_installxfonts
2562     dh_bugfiles
2563     dh_lintian
2564     dh_gconf
2565     dh_icons
2566     dh_perl
2567     dh_usrlocal
2568     dh_link
2569     dh_compress
2570     dh_fixperms
2571     dh_strip
2572     dh_makeshlibs
2573     dh_shlibdeps
2574     dh_installdeb
2575     dh_gencontrol
2576     dh_md5sums
2577     dh_builddeb
2578     </screen>
2579     </listitem>
2580     <listitem>
2581     <para>
2582     <literal>fakeroot debian/rules binary-arch</literal> runs <literal>fakeroot dh
2583     binary-arch</literal>; which in turn runs the same sequence as
2584     <literal>fakeroot dh binary</literal> but with the <literal>-a</literal> option
2585     appended for each command.
2586     </para>
2587     </listitem>
2588     <listitem>
2589     <para>
2590     <literal>fakeroot debian/rules binary-indep</literal> runs <literal>fakeroot dh
2591     binary-indep</literal>; which in turn runs almost the same sequence as
2592     <literal>fakeroot dh binary</literal> but excluding
2593     <command>dh_strip</command>, <command>dh_makeshlibs</command>, and
2594     <command>dh_shlibdeps</command> with the <literal>-i</literal> option appended
2595     for each remaining command.
2596     </para>
2597     </listitem>
2598     </itemizedlist>
2599     <para>
2600     The function of <command>dh_*</command> commands are almost self-evident from
2601     their names. <footnote><para> For complete information on what do all these
2602     <command>dh_*</command> scripts exactly do, and what their other options are,
2603     please read their respective manual pages and the <systemitem role="package">debhelper</systemitem> documentation. </para> </footnote> There
2604     are few notable ones worth making (over)simplified explanation here assuming
2605     typical build environment based on <filename>Makefile</filename>.
2606     <footnote><para> These commands support other build environments such as
2607     <filename>setup.py</filename> which can be listed by executing
2608     <literal>dh_auto_build --list</literal> in a package source directory. </para>
2609     </footnote>
2610     </para>
2611     <itemizedlist>
2612     <listitem>
2613     <para>
2614     <command>dh_auto_clean</command> usually executes the following if
2615     <filename>Makefile</filename> exists with the <literal>distclean</literal>
2616     target. <footnote><para> It actually looks for the first available target of
2617     <literal>distclean</literal>, <literal>realclean</literal> or
2618     <literal>clean</literal> in <filename>Makefile</filename> and execute it.
2619     </para> </footnote>
2620     </para>
2621     <screen>
2622     make distclean
2623     </screen>
2624     </listitem>
2625     <listitem>
2626     <para>
2627     <command>dh_auto_configure</command> usually executes the following if
2628     <filename>./configure</filename> exists (arguments abbreviated for
2629     readability).
2630     </para>
2631     <screen>
2632     ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var ...
2633     </screen>
2634     </listitem>
2635     <listitem>
2636     <para>
2637     <command>dh_auto_build</command> usually executes the following to execute the
2638     first target of <filename>Makefile</filename> if it exists.
2639     </para>
2640     <screen>
2641     make
2642     </screen>
2643     </listitem>
2644     <listitem>
2645     <para>
2646     <command>dh_auto_test</command> usually executes the following if
2647     <filename>Makefile</filename> exists with the <literal>test</literal> target.
2648     <footnote><para> It actually looks for the first available target of
2649     <literal>test</literal> or <literal>check</literal> in
2650     <filename>Makefile</filename> and execute it. </para> </footnote>
2651     </para>
2652     <screen>
2653     make test
2654     </screen>
2655     </listitem>
2656     <listitem>
2657     <para>
2658     <command>dh_auto_install</command> usually executes the following if
2659     <filename>Makefile</filename> exists with the <literal>install</literal> target
2660     (line folded for readability).
2661     </para>
2662     <screen>
2663     make install \
2664     DESTDIR=<replaceable>/path/to</replaceable>/<replaceable>package</replaceable>_<replaceable>version</replaceable>-<replaceable>revision</replaceable>/debian/<replaceable>package</replaceable>
2665     </screen>
2666     </listitem>
2667     </itemizedlist>
2668     <para>
2669     Targets which require the <command>fakeroot</command> command contain
2670     <command>dh_testroot</command>. If you are not pretending to be root using
2671     this command, it exits with an error.
2672     </para>
2673     <para>
2674     The important part to know about the <filename>rules</filename> file created by
2675     <command>dh_make</command>, is that it is just a suggestion. It will work for
2676     most packages but for more complicated ones, don't be afraid to customize it to
2677     fit your needs. Only things that you must not change are the names of the
2678     rules, because all the tools use these names, as mandated by the Debian Policy.
2679     </para>
2680     <para>
2681     Although <literal>install</literal> is not required target, it is supported.
2682     <literal>fakeroot dh install</literal> behaves like <literal>fakeroot dh
2683     binary</literal> but stops after <command>dh_fixperms</command>.
2684     </para>
2685     </section>
2686     <section id="customrules"><title>Customization of <filename>rules</filename> file</title>
2687     <para>
2688     There are many ways to customize the <filename>rules</filename> file created
2689     with the new <command>dh</command> command.
2690     </para>
2691     <para>
2692     The <literal>dh $@</literal> command can be customized as follows.
2693     <footnote><para> If a package installs the
2694     <filename>/usr/share/perl5/Debian/Debhelper/Sequence/<replaceable>custom_name</replaceable>.pm</filename>
2695     file, you should activate its customization function by <literal>dh --with
2696     <replaceable>custom-name</replaceable> $@</literal>. </para> </footnote>
2697     </para>
2698     <itemizedlist>
2699     <listitem>
2700     <para>
2701     Add support of the <command>dh_pysupport</command> command. (The best choice
2702     for Python.) <footnote><para> Use of the <command>dh_pysupport</command>
2703     command is preferred over use of the <command>dh_pycentral</command> command.
2704     Do not use the <command>dh_python</command> command. </para> </footnote>
2705     </para>
2706     <itemizedlist>
2707     <listitem>
2708     <para>
2709     Install the <systemitem role="package">python-support</systemitem> package in
2710     <literal>Build-Depends</literal>.
2711     </para>
2712     </listitem>
2713     <listitem>
2714     <para>
2715     Use <literal>dh $@</literal> as usual. (This is enabled by default)
2716     </para>
2717     </listitem>
2718     <listitem>
2719     <para>
2720     This handles Python modules using the <systemitem role="package">python-support</systemitem> framework.
2721     </para>
2722     </listitem>
2723     </itemizedlist>
2724     </listitem>
2725     <listitem>
2726     <para>
2727     Add support of the <command>dh_pycentral</command> command.
2728     </para>
2729     <itemizedlist>
2730     <listitem>
2731     <para>
2732     Install the <systemitem role="package">python-central</systemitem> package in
2733     <literal>Build-Depends</literal>.
2734     </para>
2735     </listitem>
2736     <listitem>
2737     <para>
2738     Use <literal>dh --with python-central $@</literal> instead.
2739     </para>
2740     </listitem>
2741     <listitem>
2742     <para>
2743     This also deactivates the <command>dh_pysupport</command> command.
2744     </para>
2745     </listitem>
2746     <listitem>
2747     <para>
2748     This handles Python modules using the <systemitem role="package">python-central</systemitem> framework.
2749     </para>
2750     </listitem>
2751     </itemizedlist>
2752     </listitem>
2753     <listitem>
2754     <para>
2755     Add support of the <command>dh_installtex</command> command.
2756     </para>
2757     <itemizedlist>
2758     <listitem>
2759     <para>
2760     Install the <systemitem role="package">tex-common</systemitem> package in
2761     <literal>Build-Depends</literal>.
2762     </para>
2763     </listitem>
2764     <listitem>
2765     <para>
2766     Use <literal>dh --with tex $@</literal> instead.
2767     </para>
2768     </listitem>
2769     <listitem>
2770     <para>
2771     This registers Type 1 fonts, hyphenation patterns, or formats with TeX.
2772     </para>
2773     </listitem>
2774     </itemizedlist>
2775     </listitem>
2776     <listitem>
2777     <para>
2778     Add support of the <command>dh_quilt_patch</command> and
2779     <command>dh_quilt_unpatch</command> commands.
2780     </para>
2781     <itemizedlist>
2782     <listitem>
2783     <para>
2784     Install the <systemitem role="package">quilt</systemitem> package in
2785     <literal>Build-Depends</literal>.
2786     </para>
2787     </listitem>
2788     <listitem>
2789     <para>
2790     Use <literal>dh --with quilt $@</literal> instead.
2791     </para>
2792     </listitem>
2793     <listitem>
2794     <para>
2795     This applies and un-applies patches to the upstream source from files in the
2796     <filename>debian/patches</filename> directory for the <literal>1.0</literal>
2797     source package.
2798     </para>
2799     </listitem>
2800     <listitem>
2801     <para>
2802     This is not needed if you use the new <literal>3.0 (quilt)</literal> source
2803     package.
2804     </para>
2805     </listitem>
2806     </itemizedlist>
2807     </listitem>
2808     <listitem>
2809     <para>
2810     Add support of the <command>dh_dkms</command> command.
2811     </para>
2812     <itemizedlist>
2813     <listitem>
2814     <para>
2815     Install the <systemitem role="package">dkms</systemitem> package in
2816     <literal>Build-Depends</literal>.
2817     </para>
2818     </listitem>
2819     <listitem>
2820     <para>
2821     Use <literal>dh --with dkms $@</literal> instead.
2822     </para>
2823     </listitem>
2824     <listitem>
2825     <para>
2826     This correctly handles DKMS usage by the kernel module package.
2827     </para>
2828     </listitem>
2829     </itemizedlist>
2830     </listitem>
2831     <listitem>
2832     <para>
2833     Add support of the <command>dh_autotools-dev_updateconfig</command> and
2834     <command>dh_autotools-dev_restoreconfig</command> commands.
2835     </para>
2836     <itemizedlist>
2837     <listitem>
2838     <para>
2839     Install the <systemitem role="package">autotools-dev</systemitem> package in
2840     <literal>Build-Depends</literal>.
2841     </para>
2842     </listitem>
2843     <listitem>
2844     <para>
2845     Use <literal>dh --with autotools-dev $@</literal> instead.
2846     </para>
2847     </listitem>
2848     <listitem>
2849     <para>
2850     This updates and restores <filename>config.sub</filename> and
2851     <filename>config.guess</filename>.
2852     </para>
2853     </listitem>
2854     </itemizedlist>
2855     </listitem>
2856     <listitem>
2857     <para>
2858     Add support of the <command>dh_autoreconf</command> and
2859     <command>dh_autoreconf_clean</command> commands.
2860     </para>
2861     <itemizedlist>
2862     <listitem>
2863     <para>
2864     Install the <systemitem role="package">dh-autoreconf</systemitem> package in
2865     <literal>Build-Depends</literal>.
2866     </para>
2867     </listitem>
2868     <listitem>
2869     <para>
2870     Use <literal>dh --with autoreconf $@</literal> instead.
2871     </para>
2872     </listitem>
2873     <listitem>
2874     <para>
2875     This updates the GNU Build System files and restores them after the build.
2876     </para>
2877     </listitem>
2878     </itemizedlist>
2879     </listitem>
2880     <listitem>
2881     <para>
2882     Add support to the <command>bash</command> completion feature.
2883     </para>
2884     <itemizedlist>
2885     <listitem>
2886     <para>
2887     Install the <systemitem role="package">bash-completion</systemitem> package in
2888     <literal>Build-Depends</literal>.
2889     </para>
2890     </listitem>
2891     <listitem>
2892     <para>
2893     Use <literal>dh --with bash-completion $@</literal> instead.
2894     </para>
2895     </listitem>
2896     <listitem>
2897     <para>
2898     This installs <command>bash</command> completions using configuration file at
2899     <filename>debian/<replaceable>package</replaceable>.bash-completion</filename>.
2900     </para>
2901     </listitem>
2902     </itemizedlist>
2903     </listitem>
2904     </itemizedlist>
2905     <para>
2906     Many <command>dh_*</command> commands invoked by the new <command>dh</command>
2907     command can be customized by the corresponding configuration files in the
2908     <filename>debian</filename> directory. See <xref linkend="dother"/> and the
2909     manpage of each command for the customization of such features.
2910     </para>
2911     <para>
2912     Some <command>dh_*</command> commands invoked by the new <command>dh</command>
2913     command may require you to run it with some arguments or to run additional
2914     commands with them or to skip them. For such cases, you create an
2915     <literal>override_dh_<replaceable>foo</replaceable></literal> target with its
2916     rule in the <filename>rules</filename> file only for the
2917     <command>dh_<replaceable>foo</replaceable></command> command you want to
2918     change. It basically say <emphasis>run me instead</emphasis>.
2919     <footnote><para> Under <literal>lenny</literal>, if you wanted to change the
2920     behavior of a <command>dh_*</command> script you found the relevant line in the
2921     <filename>rules</filename> file and adjusted it. </para> </footnote>
2922     </para>
2923     <para>
2924     Please note that the <command>dh_auto_*</command> commands tend to do more than
2925     what has been discussed as (over)simplified explanation to take care all the
2926     corner cases. Use of simplified equivalent command instead of these in
2927     <literal>override_dh_*</literal> targets except the
2928     <literal>override_dh_auto_clean</literal> target is a bad idea since it may
2929     kill such <systemitem role="package">debhelper</systemitem>'s smart features.
2930     </para>
2931     <para>
2932 osamu 8650 If you want to store the system configuration data in the
2933 osamu 8601 <filename>/etc/gentoo</filename> directory instead of the usual
2934 osamu 8650 <filename>/etc</filename> directory for the recent
2935     <systemitem role="package">gentoo</systemitem> package using Autotools, you can override the default
2936 osamu 8601 <literal>--sysconfig=/etc</literal> argument given by the
2937     <command>dh_auto_configure</command> command to the
2938 osamu 8650 <command>./configure</command> command by the following.
2939 osamu 8601 </para>
2940     <screen>
2941     override_dh_auto_configure:
2942     dh_auto_configure -- --sysconfig=/etc/gentoo
2943     </screen>
2944     <para>
2945     The arguments given after <literal>--</literal> are appended to the default
2946     arguments of the auto-executed program to override them. Using the
2947     <command>dh_auto_configure</command> command is better than the
2948     <command>./configure</command> command here since it will only override the
2949     <literal>--sysconfig</literal> argument and keeps well intended other arguments
2950     to the <command>./configure</command> command.
2951     </para>
2952     <para>
2953     If <filename>Makefile</filename> of a source for <systemitem role="package">gentoo</systemitem> requires you to specify
2954     <literal>build</literal> as its target to build it <footnote><para>
2955     <command>dh_auto_build</command> without any arguments will execute the first
2956     target in the <filename>Makefile</filename> file. </para> </footnote>, you
2957     create an <literal>override_dh_auto_build</literal> target to enable it.
2958     </para>
2959     <screen>
2960     override_dh_auto_build:
2961     dh_auto_build -- build
2962     </screen>
2963     <para>
2964     This ensures to run $(MAKE) with all the default arguments given by the
2965     <command>dh_auto_build</command> command and <literal>build</literal> argument.
2966     </para>
2967     <para>
2968     If <filename>Makefile</filename> of a source for <systemitem role="package">gentoo</systemitem> requires you to specify the
2969     <literal>packageclean</literal> target to clean it for Debian package instead
2970     of the <literal>distclean</literal> or <literal>clean</literal> targets in the
2971     <filename>Makefile</filename> file, you create an
2972     <literal>override_dh_auto_clean</literal> target to enable it.
2973     </para>
2974     <screen>
2975     override_dh_auto_clean:
2976     $(MAKE) packageclean
2977     </screen>
2978     <para>
2979     If <filename>Makefile</filename> of a source for <systemitem role="package">gentoo</systemitem> contains <literal>test</literal> target
2980     which you do not want to run for the Debian package building process, you can
2981     use empty <literal>override_dh_auto_test</literal> target to skip it.
2982     </para>
2983     <screen>
2984     override_dh_auto_test:
2985     </screen>
2986     <para>
2987     If <systemitem role="package">gentoo</systemitem> has an unusual upstream
2988     changelog file called <filename>FIXES</filename>,
2989     <command>dh_installchangelogs</command> will not install that file by default.
2990     The <command>dh_installchangelogs</command> command requires
2991     <filename>FIXES</filename> as its argument to install it. <footnote><para> The
2992     <filename>debian/changelog</filename> and <filename>debian/NEWS</filename>
2993     files are always automatically installed. The upstream changelog is searched
2994     by converting filenames to the lower case and matching them with the
2995     <filename>changelog</filename>, <filename>changes</filename>,
2996     <filename>changelog.txt</filename>, and <filename>changes.txt</filename>.
2997     </para> </footnote>
2998     </para>
2999     <screen>
3000     override_dh_installchangelogs:
3001     dh_installchangelogs FIXES
3002     </screen>
3003     <para>
3004     When you use the new <command>dh</command> command, use of explicit targets
3005     such as the ones listed in <xref linkend="targets"/> except
3006     <literal>get-orig-source</literal> target may make it difficult to understand
3007     their exact effects. Please limit explicit targets to
3008     <literal>override_dh_*</literal> targets and completely independent ones, if
3009     possible.
3010     </para>
3011     </section>
3012     </section>
3013     </chapter>
3014     <chapter id="dother"><title>Other files under the <filename>debian</filename> directory</title>
3015     <para>
3016     To control most of what <systemitem role="package">debhelper</systemitem> does
3017     while building the package, you put optional configuration files under the
3018 osamu 8731 <filename>debian</filename> directory. This chapter will provide an overview of
3019     what each of these does and its format. Please read the <ulink url="&debian-policy;">Debian Policy
3020 osamu 8628 Manual</ulink> and <ulink url="&developers-reference;">Debian Developer's
3021 osamu 8731 Reference</ulink> for guidelines for packaging.
3022 osamu 8601 </para>
3023     <para>
3024     The <command>dh_make</command> command will create some template configuration
3025     files under the <filename>debian</filename> directory. Most of them come with
3026     filenames suffixed by <literal>.ex</literal>. Some of them come with filenames
3027     prefixed by the binary package name such as
3028     <literal><replaceable>package</replaceable></literal>. Take a look at all of
3029     them.
3030 osamu 8668 <footnote><para>
3031     In this chapter, files in the <filename>debian</filename> directory are
3032 osamu 8731 referred to without the preceding <filename>debian/</filename> for simplicity whenever
3033 osamu 8668 they are obvious.
3034     </para></footnote>
3035 osamu 8601 </para>
3036     <para>
3037 osamu 8731 Some template configuration files for <systemitem role="package">debhelper</systemitem>
3038     may not be created by the <command>dh_make</command> command. In
3039     such cases, you need to create them with an editor.
3040 osamu 8601 </para>
3041     <para>
3042 osamu 8731 If you wish or need to activate any of these, please do the following:
3043 osamu 8601 </para>
3044     <itemizedlist>
3045     <listitem>
3046     <para>
3047     rename template files by removing the <literal>.ex</literal> or
3048 osamu 8731 <literal>.EX</literal> suffix if they have one;
3049 osamu 8601 </para>
3050     </listitem>
3051     <listitem>
3052     <para>
3053 osamu 8731 rename the configuration files to use the actual binary package
3054     name in place of <literal><replaceable>package</replaceable></literal>;
3055 osamu 8601 </para>
3056     </listitem>
3057     <listitem>
3058     <para>
3059 osamu 8731 modify template file contents to suit your needs;
3060 osamu 8601 </para>
3061     </listitem>
3062     <listitem>
3063     <para>
3064 osamu 8731 remove template files which you do not need;
3065 osamu 8601 </para>
3066     </listitem>
3067     <listitem>
3068     <para>
3069 taffit-guest 8665 modify the <filename>control</filename> file (see <xref linkend="control"/>),
3070 osamu 8731 if necessary;
3071 osamu 8601 </para>
3072     </listitem>
3073     <listitem>
3074     <para>
3075 taffit-guest 8665 modify the <filename>rules</filename> file (see <xref linkend="rules"/>), if
3076 osamu 8601 necessary.
3077     </para>
3078     </listitem>
3079     </itemizedlist>
3080     <para>
3081 osamu 8731 Any <systemitem role="package">debhelper</systemitem> configuration files
3082     without a <filename><replaceable>package</replaceable></filename> prefix, such as
3083     <filename>install</filename>, apply to the first binary package. When there are
3084 osamu 8601 many binary packages, their configurations can be specified by prefixing their
3085     name to their configuration filenames such as
3086     <filename><replaceable>package-1</replaceable>.install</filename>,
3087     <filename><replaceable>package-2</replaceable>.install</filename>, etc.
3088     </para>
3089 osamu 8731 <section id="readme"><title><filename>README.Debian</filename></title>
3090 osamu 8601 <para>
3091     Any extra details or discrepancies between the original package and your Debian
3092     version should be documented here.
3093     </para>
3094     <para>
3095 osamu 8731 <command>dh_make</command> created a default one; this is what it looks like:
3096 osamu 8601 </para>
3097     <screen>
3098     gentoo for Debian
3099     -----------------
3100     &lt;possible notes regarding this package - if none, delete this file&gt;
3101     -- Josip Rodin &lt;joy-mg@debian.org&gt;, Wed, 11 Nov 1998 21:02:14 +0100
3102     </screen>
3103     <para>
3104     If you have nothing to be documented, remove this file. See <citerefentry>
3105     <refentrytitle>dh_installdocs</refentrytitle> <manvolnum>1</manvolnum>
3106     </citerefentry>.
3107     </para>
3108     </section>
3109 osamu 8731 <section id="compat"><title><filename>compat</filename></title>
3110 osamu 8601 <para>
3111     The <filename>compat</filename> file defines the <systemitem role="package">debhelper</systemitem> compatibility level. Currently, you
3112 osamu 8731 should set it to the <systemitem role="package">debhelper</systemitem> v7 as
3113     follows:
3114 osamu 8601 </para>
3115     <screen>
3116     $ echo 7 &gt; debian/compat
3117     </screen>
3118     </section>
3119 osamu 8731 <section id="conffiles"><title><filename>conffiles</filename></title>
3120 osamu 8601 <para>
3121     One of the most annoying things about software is when you spend a great deal
3122     of time and effort customizing a program, only to have an upgrade stomp all
3123 osamu 8622 over your changes. Debian solves this problem by marking such configuration files as conffiles.
3124     <footnote><para>See <citerefentry> <refentrytitle>dpkg</refentrytitle>
3125     <manvolnum>1</manvolnum> </citerefentry> and
3126 osamu 8737 <ulink url="&policy-conffiles;">Debian Policy Manual "D.2.5 Conffiles"</ulink>.
3127 osamu 8622 </para></footnote>
3128 osamu 8731 When you upgrade a package, you'll be asked whether you want to keep
3129 osamu 8622 your old configuration files or not.
3130 osamu 8601 </para>
3131     <para>
3132 osamu 8735 <citerefentry><refentrytitle>dh_installdeb</refentrytitle> <manvolnum>1</manvolnum>
3133     </citerefentry> <emphasis>automatically</emphasis> flags any files under
3134 osamu 8601 the <filename>/etc</filename> directory as conffiles, so if your program only
3135     has conffiles there you do not need to specify them in this file. For most
3136 osamu 8731 package types, the only place conffiles should ever be is under
3137     <filename>/etc</filename>, and so this file doesn't need to exist.
3138 osamu 8601 </para>
3139     <para>
3140     If your program uses configuration files but also rewrites them on its own,
3141 osamu 8731 it's best not to make them conffiles because <command>dpkg</command> will
3142 osamu 8601 then prompt users to verify the changes all the time.
3143     </para>
3144     <para>
3145     If the program you're packaging requires every user to modify the configuration
3146 osamu 8731 files in the <filename>/etc</filename> directory, there are two popular ways to
3147     arrange for them to not be conffiles, keeping <command>dpkg</command> quiet.
3148 osamu 8601 </para>
3149     <itemizedlist>
3150     <listitem>
3151     <para>
3152 osamu 8731 Create a symlink under the <filename>/etc</filename> directory pointing to a
3153 osamu 8601 file under the <filename>/var</filename> directory generated by the
3154 osamu 8731 maintainer scripts.
3155 osamu 8601 </para>
3156     </listitem>
3157     <listitem>
3158     <para>
3159 osamu 8731 Create a file generated by the maintainer scripts under the <filename>/etc</filename> directory.
3160 osamu 8601 </para>
3161     </listitem>
3162     </itemizedlist>
3163     <para>
3164 osamu 8731 For information on maintainer scripts, see <xref linkend="maintscripts"/>.
3165 osamu 8601 </para>
3166     </section>
3167 osamu 8731 <section id="crond"><title><filename><replaceable>package</replaceable>.cron.*</filename></title>
3168 osamu 8601 <para>
3169     If your package requires regularly scheduled tasks to operate properly, you can
3170 osamu 8731 use these files to set that up. You can set up regular tasks that either happen
3171     hourly, daily, weekly, or monthly, or alternatively happen at any other time that
3172 osamu 8601 you wish. The filenames are:
3173     </para>
3174     <itemizedlist>
3175     <listitem>
3176     <para>
3177 osamu 8731 <filename><replaceable>package</replaceable>.cron.hourly</filename> - Installed as
3178     <filename>/etc/cron.hourly/<replaceable>package</replaceable></filename>; run
3179     once an hour.
3180 osamu 8601 </para>
3181     </listitem>
3182     <listitem>
3183     <para>
3184 osamu 8731 <filename><replaceable>package</replaceable>.cron.daily</filename> - Installed as
3185     <filename>/etc/cron.daily/<replaceable>package</replaceable></filename>; run
3186     once a day.
3187 osamu 8601 </para>
3188     </listitem>
3189     <listitem>
3190     <para>
3191 osamu 8731 <filename><replaceable>package</replaceable>.cron.weekly</filename> - Installed as
3192     <filename>/etc/cron.weekly/<replaceable>package</replaceable></filename>; run
3193     once a week.
3194 osamu 8601 </para>
3195     </listitem>
3196     <listitem>
3197     <para>
3198 osamu 8731 <filename><replaceable>package</replaceable>.cron.monthly</filename> - Installed as
3199 osamu 8601 <filename>/etc/cron.monthly/<replaceable>package</replaceable></filename>: run
3200 osamu 8731 once a month.
3201 osamu 8601 </para>
3202     </listitem>
3203     <listitem>
3204     <para>
3205 osamu 8731 <filename><replaceable>package</replaceable>.cron.d</filename> - Installed as
3206 osamu 8601 <filename>/etc/cron.d/<replaceable>package</replaceable></filename>: for any
3207 osamu 8731 other time.
3208 osamu 8601 </para>
3209     </listitem>
3210     </itemizedlist>
3211     <para>
3212 osamu 8731 Most of these files are shell scripts, with the exception of
3213     <filename><replaceable>package</replaceable>.cron.d</filename> which follows
3214 osamu 8601 the format of <citerefentry> <refentrytitle>crontab</refentrytitle>
3215     <manvolnum>5</manvolnum> </citerefentry>.
3216     </para>
3217     <para>
3218 osamu 8731 No explicit <filename>cron.*</filename> file is needed to set up log rotation;
3219     for that, see
3220     <citerefentry><refentrytitle>dh_installlogrotate</refentrytitle>
3221     <manvolnum>1</manvolnum></citerefentry> and
3222     <citerefentry><refentrytitle>logrotate</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
3223 osamu 8601 </para>
3224     </section>
3225 osamu 8731 <section id="dirs"><title><filename>dirs</filename></title>
3226 osamu 8601 <para>
3227 osamu 8731 This file specifies any directories which we need but which are not created by the normal installation
3228 osamu 8601 procedure (<literal>make install DESTDIR=...</literal> invoked by
3229 osamu 8731 <literal>dh_auto_install</literal>). This generally
3230 osamu 8601 means there is a problem with the <filename>Makefile</filename>.
3231     </para>
3232     <para>
3233 osamu 8731 Files listed in an <filename>install</filename> file don't need their
3234 taffit-guest 8665 directories created first. See <xref linkend="install"/>.
3235 osamu 8601 </para>
3236     <para>
3237 osamu 8652 It is best to try to run the installation first and only use this if you
3238 osamu 8731 run into trouble. There is no preceding slash on the directory names listed in
3239 osamu 8622 the <filename>dirs</filename> file.
3240 osamu 8601 </para>
3241     </section>
3242 osamu 8731 <section id="doc-base"><title><filename><replaceable>package</replaceable>.doc-base</filename></title>
3243 osamu 8601 <para>
3244 osamu 8731 If your package has documentation other than manual and info pages, you
3245 osamu 8601 should use the <systemitem role="package">doc-base</systemitem> file to
3246     register it, so the user can find it with e.g. <citerefentry>
3247     <refentrytitle>dhelp</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>,
3248     <citerefentry> <refentrytitle>dwww</refentrytitle> <manvolnum>1</manvolnum>
3249 osamu 8731 </citerefentry>, or <citerefentry> <refentrytitle>doccentral</refentrytitle>
3250 osamu 8601 <manvolnum>1</manvolnum> </citerefentry>.
3251     </para>
3252     <para>
3253     This usually includes HTML, PS and PDF files, shipped in
3254     <filename>/usr/share/doc/<replaceable>packagename</replaceable>/</filename>.
3255     </para>
3256     <para>
3257 osamu 8731 This is what <systemitem role="package">gentoo</systemitem>'s doc-base file
3258 osamu 8601 <filename>gentoo.doc-base</filename> looks like:
3259     </para>
3260     <screen>
3261     Document: gentoo
3262     Title: Gentoo Manual
3263     Author: Emil Brink
3264     Abstract: This manual describes what Gentoo is, and how it can be used.
3265     Section: File Management
3266     Format: HTML
3267     Index: /usr/share/doc/gentoo/html/index.html
3268     Files: /usr/share/doc/gentoo/html/*.html
3269     </screen>
3270     <para>
3271     For information on the file format, see <citerefentry>
3272     <refentrytitle>install-docs</refentrytitle> <manvolnum>8</manvolnum>
3273     </citerefentry> and the <systemitem role="package">doc-base</systemitem>
3274 osamu 8639 manual, in <ulink url="&doc-base;">Debian doc-base Manual</ulink>.
3275 osamu 8601 </para>
3276     <para>
3277 taffit-guest 8665 For more details on installing additional documentation, look in <xref linkend="destdir"/>.
3278 osamu 8601 </para>
3279     </section>
3280 osamu 8731 <section id="docs"><title><filename>docs</filename></title>
3281 osamu 8601 <para>
3282     This file specifies the file names of documentation files we can have
3283     <citerefentry> <refentrytitle>dh_installdocs</refentrytitle>
3284     <manvolnum>1</manvolnum> </citerefentry> install into the temporary directory
3285     for us.
3286     </para>
3287     <para>
3288     By default, it will include all existing files in the top-level source
3289     directory that are called <filename>BUGS</filename>,
3290     <filename>README*</filename>, <filename>TODO</filename> etc.
3291     </para>
3292     <para>
3293 osamu 8731 For <systemitem role="package">gentoo</systemitem>, some other files
3294     are also included:
3295 osamu 8601 </para>
3296     <screen>
3297     BUGS
3298     CONFIG-CHANGES
3299     CREDITS
3300     NEWS
3301     README
3302     README.gtkrc
3303     TODO
3304     </screen>
3305     </section>
3306 osamu 8731 <section id="emacsen"><title><filename>emacsen-*</filename></title>
3307 osamu 8601 <para>
3308     If your package supplies Emacs files that can be bytecompiled at package
3309     installation time, you can use these files to set it up.
3310     </para>
3311     <para>
3312     They are installed into the temporary directory by <citerefentry>
3313     <refentrytitle>dh_installemacsen</refentrytitle> <manvolnum>1</manvolnum>
3314     </citerefentry>.
3315     </para>
3316     <para>
3317     If you don't need these, remove them.
3318     </para>
3319     </section>
3320 osamu 8731 <section id="examples"><title><filename><replaceable>package</replaceable>.examples</filename></title>
3321 osamu 8601 <para>
3322     The <citerefentry> <refentrytitle>dh_installexamples</refentrytitle>
3323     <manvolnum>1</manvolnum> </citerefentry> command installs files and directories
3324     listed in this file as example files.
3325     </para>
3326     </section>
3327 osamu 8731 <section id="initd"><title><filename><replaceable>package</replaceable>.init</filename> and <filename><replaceable>package</replaceable>.default</filename></title>
3328 osamu 8601 <para>
3329 osamu 8731 If your package is a daemon that needs to be run at system start-up, you've
3330 osamu 8601 obviously disregarded my initial recommendation, haven't you? :-)
3331     </para>
3332     <para>
3333     The <filename><replaceable>package</replaceable>.init</filename> file is
3334     installed as the
3335 osamu 8731 <filename>/etc/init.d/<replaceable>package</replaceable></filename> script
3336     which starts and stops the daemon.
3337 osamu 8601 Its fairly generic skeleton template is provided by the
3338     <command>dh_make</command> command as <filename>init.d.ex</filename>. You'll
3339     likely have to rename and edit it, a lot, while making sure to provide
3340 osamu 8642 <ulink url="&lsb;">Linux Standard Base</ulink> (LSB) compliant headers. It
3341 osamu 8601 gets installed into the temporary directory by <citerefentry>
3342     <refentrytitle>dh_installinit</refentrytitle> <manvolnum>1</manvolnum>
3343     </citerefentry>.
3344     </para>
3345     <para>
3346     The <filename><replaceable>package</replaceable>.default</filename> file will
3347 osamu 8731 be installed as
3348 osamu 8601 <filename>/etc/default/<replaceable>package</replaceable></filename>. This
3349 osamu 8731 file sets defaults that are sourced by the init script. This
3350     <filename><replaceable>package</replaceable>.default</filename> file
3351     is most often used to disable running a daemon, or to set some default flags or
3352     timeouts. If your init script has certain configurable
3353     features, you can set them in the <filename><replaceable>package</replaceable>.default</filename> file,
3354     instead of in the init script itself.
3355 osamu 8601 </para>
3356     <para>
3357 osamu 8731 If your upstream program provides a file for the init script, you can either use it or not. If you
3358     don't use their init script then create a new one in
3359 osamu 8668 <filename><replaceable>package</replaceable>.init</filename>. However
3360 osamu 8731 if the upstream init script looks fine and installs in the right place you
3361     still need to set up the <filename>rc*</filename> symlinks. To do this you will
3362 osamu 8601 need to override <command>dh_installinit</command> in the
3363     <filename>rules</filename> file with the following lines:
3364     </para>
3365     <screen>
3366     override_dh_installinit:
3367     dh_installinit --onlyscripts
3368     </screen>
3369     <para>
3370     If you don't need this, remove the files.
3371     </para>
3372     </section>
3373 osamu 8731 <section id="install"><title><filename>install</filename></title>
3374 osamu 8601 <para>
3375     If there are files that need to be installed into your package but your
3376 osamu 8731 standard <literal>make install</literal> won't do it, put the filenames and
3377 osamu 8601 destinations into this <filename>install</filename> file. They are installed
3378     by <citerefentry> <refentrytitle>dh_install</refentrytitle>
3379     <manvolnum>1</manvolnum> </citerefentry>.<footnote><para> This replaces the
3380     deprecated <citerefentry> <refentrytitle>dh_movefiles</refentrytitle>
3381     <manvolnum>1</manvolnum> </citerefentry> command which is configured by the
3382     <filename>files</filename> file. </para> </footnote> You should first check
3383     there is not a more specific tool to use. For example, documents should be in
3384     the <filename>docs</filename> file and not in this one.
3385     </para>
3386     <para>
3387     This <filename>install</filename> file has one line per file installed, with
3388     the name of the file (relative to the top build directory) then a space then
3389 osamu 8731 the installation directory (relative to the install directory). One example of where this is used is if a binary <filename>src/<replaceable>bar</replaceable></filename> is left uninstalled; the
3390     <filename>install</filename> file might look like:
3391 osamu 8601 </para>
3392     <screen>
3393 osamu 8731 src/<replaceable>bar</replaceable> usr/bin
3394 osamu 8601 </screen>
3395     <para>
3396 osamu 8731 This means when this package is installed, there will be a binary executable
3397     <filename>/usr/bin/<replaceable>bar</replaceable></filename>.
3398 osamu 8601 </para>
3399     <para>
3400     Alternatively, this <filename>install</filename> can have the name of the file
3401     only without the installation directory when the relative directory path does
3402 osamu 8731 not change. This format is usually used for a large package that splits the
3403     output of its build into multiple binary packages using
3404 osamu 8601 <filename><replaceable>package-1</replaceable>.install</filename>,
3405     <filename><replaceable>package-2</replaceable>.install</filename>, etc.
3406     </para>
3407     <para>
3408 osamu 8731 The <command>dh_install</command> command will fall back to looking in
3409 osamu 8601 <filename>debian/tmp</filename> for files, if it doesn't find them in the
3410     current directory (or wherever you've told it to look using
3411     <literal>--sourcedir</literal>).
3412     </para>
3413     </section>
3414 osamu 8731 <section id="info"><title><filename><replaceable>package</replaceable>.info</filename></title>
3415 osamu 8601 <para>
3416     If your package has info pages, you should install them using <citerefentry>
3417     <refentrytitle>dh_installinfo</refentrytitle> <manvolnum>1</manvolnum>
3418 osamu 8731 </citerefentry> by listing them in a
3419     <filename><replaceable>package</replaceable>.info</filename> file.
3420 osamu 8601 </para>
3421     </section>
3422 osamu 8731 <section id="lintian"><title><filename>{<replaceable>package</replaceable>.,source/}lintian-overrides</filename></title>
3423 osamu 8601 <para>
3424     If <systemitem role="package">lintian</systemitem> reports an erroneous
3425 osamu 8731 diagnostic for a case where Debian policy allows exceptions to some rule, you can
3426 osamu 8601 use <filename><replaceable>package</replaceable>.lintian-overrides</filename>
3427 osamu 8731 or <filename>source/lintian-overrides</filename> to quieten it. Please read
3428 osamu 8639 <ulink url="&lintian-doc;">Lintian User's Manual</ulink> and refrain
3429 osamu 8601 from abusing this.
3430     </para>
3431     <para>
3432     <filename><replaceable>package</replaceable>.lintian-overrides</filename> is
3433 osamu 8731 for the binary package named <systemitem role="package"><replaceable>package</replaceable></systemitem> and is installed
3434 osamu 8601 into
3435     <filename>usr/share/lintian/overrides/<replaceable>package</replaceable></filename>
3436     by the <command>dh_lintian</command> command.
3437     </para>
3438     <para>
3439     <filename>source/lintian-overrides</filename> is for the source package. This
3440     is not installed.
3441     </para>
3442     </section>
3443 osamu 8731 <section id="manpage"><title><filename>manpage.*</filename></title>
3444 osamu 8601 <para>
3445     Your program(s) should have a manual page. If they don't, you should create
3446 osamu 8731 them. The <command>dh_make</command> command creates some template files for
3447     manual pages. These need to be copied and edited for each command missing its
3448 osamu 8601 manual page. Please make sure to remove unused templates.
3449     </para>
3450 osamu 8731 <section id="manpage1"><title><filename>manpage.1.ex</filename></title>
3451 osamu 8601 <para>
3452     Manual pages are normally written in <citerefentry>
3453     <refentrytitle>nroff</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>.
3454     The <filename>manpage.1.ex</filename> template is written in
3455     <command>nroff</command>, too. See the <citerefentry>
3456     <refentrytitle>man</refentrytitle> <manvolnum>7</manvolnum> </citerefentry>
3457     manual page for a brief description of how to edit such a file.
3458     </para>
3459     <para>
3460 osamu 8731 The final manual page file name should give the name of the program it is
3461 osamu 8601 documenting, so we will rename it from <literal>manpage</literal> to
3462     <literal>gentoo</literal>. The file name also includes <literal>.1</literal>
3463     as the first suffix, which means it's a manual page for a user command. Be
3464     sure to verify that this section is indeed the correct one. Here's a short
3465     list of manual page sections:
3466     </para>
3467 osamu 8732 <informaltable id="manpage-sections" pgwide="0" frame="topbot" rowsep="1" colsep="1">
3468 osamu 8636 <tgroup cols="3">
3469     <colspec colwidth="8*" align="left"/> <colspec colwidth="24*" align="left"/> <colspec colwidth="40*" align="left"/>
3470     <thead>
3471     <row> <entry>Section</entry> <entry>Description</entry> <entry>Notes</entry> </row>
3472     </thead>
3473     <tbody>
3474     <row> <entry>1</entry> <entry>User command</entry> <entry>Executable commands or scripts</entry> </row>
3475     <row> <entry>2</entry> <entry>System calls</entry> <entry>Functions provided by the kernel</entry> </row>
3476     <row> <entry>3</entry> <entry>Library calls</entry> <entry>Functions within system libraries</entry> </row>
3477 taffit-guest 8665 <row> <entry>4</entry> <entry>Special files</entry> <entry>Usually found in <filename>/dev</filename></entry> </row>
3478 osamu 8636 <row> <entry>5</entry> <entry>File formats</entry> <entry>E.g. <filename>/etc/passwd</filename>'s format</entry> </row>
3479     <row> <entry>6</entry> <entry>Games</entry> <entry>Games or other frivolous programs</entry> </row>
3480 taffit-guest 8665 <row> <entry>7</entry> <entry>Macro packages</entry> <entry>Such as <command>man</command> macros</entry> </row>
3481 osamu 8636 <row> <entry>8</entry> <entry>System administration</entry> <entry>Programs typically only run by root</entry> </row>
3482     <row> <entry>9</entry> <entry>Kernel routines</entry> <entry>Non-standard calls and internals</entry> </row>
3483     </tbody>
3484     </tgroup>
3485 osamu 8732 </informaltable>
3486 osamu 8601 <para>
3487     So <systemitem role="package">gentoo</systemitem>'s man page should be called
3488     <filename>gentoo.1</filename>. If there was no <filename>gentoo.1</filename>
3489     man page in the original source, you should create it by renaming the
3490     <filename>manpage.1.ex</filename> template to <filename>gentoo.1</filename> and
3491 osamu 8731 editing it using information from the example and from the upstream docs.
3492 osamu 8601 </para>
3493     <para>
3494     You can use the <command>help2man</command> command to generate a man page out
3495 osamu 8731 of the <literal>--help</literal> and <literal>--version</literal> output of each
3496     program, too. <footnote><para> Note that <command>help2man</command>'s
3497     placeholder man page will claim that more detailed documentation is
3498     available in the info system. If the command is missing an
3499     <command>info</command> page, you
3500     should manually edit the man page created by the
3501 osamu 8601 <command>help2man</command> command. </para> </footnote>
3502     </para>
3503     </section>
3504 osamu 8731 <section id="manpagesgml"><title><filename>manpage.sgml.ex</filename></title>
3505 osamu 8601 <para>
3506     If on the other hand you prefer writing SGML instead of
3507     <command>nroff</command>, you can use the <filename>manpage.sgml.ex</filename>
3508     template. If you do this, you have to:
3509     </para>
3510     <itemizedlist>
3511     <listitem>
3512     <para>
3513     rename the file to something like <filename>gentoo.sgml</filename>.
3514     </para>
3515     </listitem>
3516     <listitem>
3517     <para>
3518     install the <systemitem role="package">docbook-to-man</systemitem> package
3519     </para>
3520     </listitem>
3521     <listitem>
3522     <para>
3523     add <literal>docbook-to-man</literal> to the <literal>Build-Depends</literal>
3524     line in the <filename>control</filename> file
3525     </para>
3526     </listitem>
3527     <listitem>
3528     <para>
3529 osamu 8731 add an <literal>override_dh_auto_build</literal> target to your
3530 osamu 8601 <filename>rules</filename> file:
3531     </para>
3532     <screen>
3533     override_dh_auto_build:
3534     docbook-to-man debian/gentoo.sgml &gt; debian/gentoo.1
3535     dh_auto_build
3536     </screen>
3537     </listitem>
3538     </itemizedlist>
3539     </section>
3540 osamu 8731 <section id="manpagexml"><title><filename>manpage.xml.ex</filename></title>
3541 osamu 8601 <para>
3542     If you prefer XML over SGML, you can use the <literal>manpage.xml.ex</literal>
3543     template. If you do this, you have to:
3544     </para>
3545     <itemizedlist>
3546     <listitem>
3547     <para>
3548     rename the source file to something like <literal>gentoo.1.xml</literal>
3549     </para>
3550     </listitem>
3551     <listitem>
3552     <para>
3553     install the <systemitem role="package">docbook-xsl</systemitem> package and an
3554     XSLT processor like <systemitem role="package">xsltproc</systemitem>
3555     (recommended)
3556     </para>
3557     </listitem>
3558     <listitem>
3559     <para>
3560 osamu 8731 add the <literal>docbook-xsl</literal>, <literal>docbook-xml</literal>, and
3561 osamu 8601 <literal>xsltproc</literal> packages to the <literal>Build-Depends</literal>
3562     line in the <literal>control</literal> file
3563     </para>
3564     </listitem>
3565     <listitem>
3566     <para>
3567 osamu 8731 add an <literal>override_dh_auto_build</literal> target to your
3568 osamu 8601 <filename>rules</filename> file:
3569     </para>
3570     <screen>
3571     override_dh_auto_build:
3572     xsltproc --nonet \
3573     --param make.year.ranges 1 \
3574     --param make.single.year.ranges 1 \
3575     --param man.charmap.use.subset 0 \
3576     -o debian/ \
3577     http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl\
3578     debian/gentoo.1.xml
3579     dh_auto_build
3580     </screen>
3581     </listitem>
3582     </itemizedlist>
3583     </section>
3584     </section>
3585     <section id="manpages"><title><filename><replaceable>package</replaceable>.manpages</filename> file</title>
3586     <para>
3587     If your package has manual pages, you should install them using <citerefentry>
3588     <refentrytitle>dh_installman</refentrytitle> <manvolnum>1</manvolnum>
3589 osamu 8731 </citerefentry> by listing them in a
3590     <filename><replaceable>package</replaceable>.manpages</filename> file.
3591 osamu 8601 </para>
3592     <para>
3593 osamu 8731 To install <filename>docs/gentoo.1</filename> as a manpage for the <systemitem role="package">gentoo</systemitem> package, create a
3594     <filename>gentoo.manpages</filename> file as follows.
3595 osamu 8601 </para>
3596     <screen>
3597     docs/gentoo.1
3598     </screen>
3599     </section>
3600 osamu 8731 <section id="menu"><title><filename>menu</filename></title>
3601 osamu 8601 <para>
3602     X Window System users usually have a window manager with a menu that can be
3603     customized to launch programs. If they have installed the Debian <systemitem role="package">menu</systemitem> package, a set of menus for every program on
3604     the system will be created for them.
3605     </para>
3606     <para>
3607     Here's the default <filename>menu.ex</filename> file that
3608 osamu 8650 <command>dh_make</command> created.
3609 osamu 8601 </para>
3610     <screen>
3611     ?package(gentoo):needs=X11|text|vc|wm \
3612     section=Applications/see-menu-manual\
3613     title=gentoo command=/usr/bin/gentoo
3614     </screen>
3615     <para>
3616     The first field after the colon character is <literal>needs</literal>, and it
3617     specifies what kind of interface the program needs. Change this to one of the
3618     listed alternatives, e.g. <literal>text</literal> or <literal>X11</literal>.
3619     </para>
3620     <para>
3621 osamu 8731 The next is the <literal>section</literal> that the menu and submenu entry
3622     should appear in.
3623     <footnote><para> The current list of sections is in
3624 osamu 8737 <ulink url="&menu-structure;">The Debian Menu sub-policy 2.1 "Preferred menu structure"</ulink>.
3625 osamu 8731 There was a major reorganization of menu structure for <literal>squeeze</literal>.
3626 osamu 8642 </para> </footnote>
3627 osamu 8601 </para>
3628     <para>
3629     The <literal>title</literal> field is the name of the program. You can start
3630     this one in uppercase if you like. Just keep it short.
3631     </para>
3632     <para>
3633     Finally, the <literal>command</literal> field is the command that runs the
3634     program.
3635     </para>
3636     <para>
3637     Let's change the file name to <filename>menu</filename> and change the menu
3638     entry to this:
3639     </para>
3640     <screen>
3641     ?package(gentoo): needs=X11 \
3642     section=Applications/Tools \
3643     title=Gentoo command=gentoo
3644     </screen>
3645     <para>
3646     You can also add other fields like <literal>longtitle</literal>,
3647     <literal>icon</literal>, <literal>hints</literal> etc. See <citerefentry>
3648     <refentrytitle>dh_installmenu</refentrytitle> <manvolnum>1</manvolnum>
3649     </citerefentry>, <citerefentry> <refentrytitle>menufile</refentrytitle>
3650     <manvolnum>5</manvolnum> </citerefentry>, <citerefentry>
3651     <refentrytitle>update-menus</refentrytitle> <manvolnum>1</manvolnum>
3652 osamu 8731 </citerefentry>, and
3653 osamu 8734 <ulink url="&policy-menu;">The Debian Menu sub-policy</ulink> for more
3654 osamu 8601 information.
3655     </para>
3656     </section>
3657 osamu 8731 <section id="news"><title><filename>NEWS</filename></title>
3658 osamu 8601 <para>
3659     The <citerefentry> <refentrytitle>dh_installchangelogs</refentrytitle>
3660     <manvolnum>1</manvolnum> </citerefentry> command installs this.
3661     </para>
3662     </section>
3663 osamu 8731 <section id="maintscripts"><title><filename>{pre,post}{inst,rm}</filename></title>
3664 osamu 8601 <para>
3665     These <filename>postinst</filename>, <filename>preinst</filename>,
3666     <filename>postrm</filename>, and <filename>prerm</filename> files
3667 osamu 8731 <footnote><para> Despite this use of the <command>bash</command>
3668     shorthand expression <filename>{pre,post}{inst,rm}</filename> to indicate these
3669     filenames, you should use pure POSIX syntax for these maintainer scripts for
3670     compatibility with <command>dash</command> as the system shell. </para> </footnote> are
3671 osamu 8601 called <emphasis>maintainer scripts</emphasis>. They are scripts which are put
3672     in the control area of the package and run by <command>dpkg</command> when your
3673 osamu 8731 package is installed, upgraded, or removed.
3674 osamu 8601 </para>
3675     <para>
3676     As a novice maintainer, you should avoid any manual editing of
3677 osamu 8731 maintainer scripts because they are problematic. For more
3678     information refer to the <ulink url="&policy-mantainerscripts;">Debian
3679 osamu 8737 Policy Manual, 6 "Package maintainer scripts and installation
3680     procedure"</ulink>, and take a look at the example files provided by
3681 osamu 8601 <command>dh_make</command>.
3682     </para>
3683     <para>
3684 osamu 8731 If you did not listen to me and have created custom maintainer
3685     scripts for a package, you should make sure to test them not only
3686     for <emphasis role="strong">install</emphasis> and
3687     <emphasis role="strong">upgrade</emphasis> but also for
3688     <emphasis role="strong">remove</emphasis> and
3689     <emphasis role="strong">purge</emphasis>.
3690 osamu 8601 </para>
3691     <para>
3692     Upgrades to the new version should be silent and non-intrusive (existing users
3693     should not notice the upgrade except by discovering that old bugs have been
3694 osamu 8731 fixed and perhaps that there are new features).
3695 osamu 8601 </para>
3696     <para>
3697     When the upgrade is necessarily intrusive (eg., config files scattered through
3698 osamu 8731 various home directories with totally different structure), you may
3699     consider as the last resort switching the package to a safe fallback state
3700     (e.g., disabling a service) and providing the proper documentation
3701     required by policy (<filename>README.Debian</filename> and
3702     <filename>NEWS.Debian</filename>). Don't bother the user with
3703     <command>debconf</command> notes invoked from these maintainer scripts
3704     for upgrades.
3705 osamu 8601 </para>
3706     <para>
3707 osamu 8731 The <systemitem role="package">ucf</systemitem> package provides a
3708 osamu 8601 <emphasis>conffile-like</emphasis> handling infrastructure to preserve user
3709 osamu 8731 changes for files that may not be labeled as <emphasis>conffiles</emphasis> such
3710     as those managed by the maintainer scripts. This should
3711 osamu 8601 minimize issues associated with them.
3712     </para>
3713     <para>
3714 osamu 8731 These maintainer scripts are among the Debian enhancements that
3715 osamu 8601 explain <emphasis role="strong">why people choose Debian</emphasis>. You must
3716 osamu 8731 be very careful not to turn them into a source of annoyance.
3717 osamu 8601 </para>
3718     </section>
3719 osamu 8731 <section id="todo"><title><filename>TODO</filename></title>
3720 osamu 8601 <para>
3721     The <citerefentry> <refentrytitle>dh_installdocs</refentrytitle>
3722     <manvolnum>1</manvolnum> </citerefentry> command installs this.
3723     </para>
3724     </section>
3725 osamu 8731 <section id="watch"><title><filename>watch</filename></title>
3726 osamu 8601 <para>
3727     The <filename>watch</filename> file format is documented in the <citerefentry>
3728     <refentrytitle>uscan</refentrytitle> <manvolnum>1</manvolnum> </citerefentry>
3729     manpage. The <filename>watch</filename> file configures the
3730     <command>uscan</command> program (in the <systemitem role="package">devscripts</systemitem> package) to watch the site where you
3731 osamu 8731 originally got the source from. This is also used by the
3732     <ulink url="&dehs;">Debian External Health Status (DEHS)</ulink> service.
3733 osamu 8601 </para>
3734     <para>
3735 osamu 8731 Here are its contents:
3736 osamu 8601 </para>
3737     <screen>
3738     # watch control file for uscan
3739     version=3
3740 osamu 8628 &sf-net;/gentoo/gentoo-(.+)\.tar\.gz debian uupdate
3741 osamu 8601 </screen>
3742     <para>
3743 osamu 8731 Normally with a <filename>watch</filename> file, the URL at
3744 osamu 8628 <literal>&sf-net;/gentoo</literal> is downloaded and searched for links of
3745 osamu 8731 the form <literal>&lt;a href=...&gt;</literal>. The basename (just the part
3746     after the final <literal>/</literal>) of each linked URL is compared against
3747     the Perl regular expression pattern (see <citerefentry> <refentrytitle>perlre</refentrytitle>
3748     <manvolnum>1</manvolnum> </citerefentry>)
3749     <literal>gentoo-(.+)\.tar\.gz</literal>. Out of the files that match, the one with
3750 osamu 8601 the greatest version number is downloaded and the <command>uupdate</command>
3751 osamu 8731 program is run to create an updated source tree.
3752 osamu 8601 </para>
3753     <para>
3754     Although this is true for other sites, the SourceForge download service at
3755 osamu 8642 <ulink url="&sf-net;"/> is an exception. When the
3756 osamu 8731 <filename>watch</filename> file has an URL matching the Perl regexp
3757 osamu 8601 <literal>^http://sf\.net/</literal>, the <command>uscan</command> program
3758 osamu 8731 replaces it with <literal>&qa-do;watch/sf.php/</literal> and
3759     then applies this rule. The URL redirector service at <ulink url="&qa-do;"/> is designed to offer
3760     a stable redirect service to the desired file for any
3761     <filename>watch</filename> pattern of the form
3762 osamu 8628 <literal>&sf-net;/<replaceable>project</replaceable>/<replaceable>tar-name</replaceable>-(.+)\.tar\.gz</literal>.
3763 osamu 8731 This solves issues related to periodically changing SourceForge URLs.