]> git.donarmstrong.com Git - debhelper.git/blob - doc/PROGRAMMING
r475: * dh_gencontrol: Added a documented interface for specifying substvars
[debhelper.git] / doc / PROGRAMMING
1 This file documents things you should know to write a new debhelper program.
2
3 Standardization:
4 ---------------
5
6 There are lots of debhelper commands. To make the learning curve shallower,
7 I want them all to behave in a standard manner:
8
9 All debhelper programs have names beginning with "dh_". This is so we don't
10 pollute the name space too much.
11
12 Debhelper programs should never output anything to standard output except
13 error messages, important warnings, and the actual commands they run that
14 modify files under debian/ (this last only if they are passed -v, and if you
15 output the commands, you should indent them with 1 tab). This is so we don't
16 have a lot of noise output when all the debhelper commands in a debian/rules
17 are run, so the important stuff is clearly visible.
18
19 Debhelper programs should accept all options listed in the "SHARED
20 DEBHELPER OPTIONS" section of debhelper(1), including and any long forms of
21 these options, like --verbose . If necessary, the options may be ignored.
22
23 If debhelper commands need config files, they should use
24 debian/package.filename as the name of the config file (replace filename
25 with whatever your command wants), and debian/filename should also be
26 checked for config information for the first binary package in
27 debian/control. Also, debhelper commands should accept the same sort of
28 information that appears in the config files, on their command lines, if
29 possible, and apply that information to the first package they act on.
30
31 Debhelper programs should never modify the debian/postinst, debian/prerm,
32 etc scripts, instead, they can add lines to debian/postinst.debhelper, etc. 
33 The autoscript() function (see below) is one easy way to do this.
34 dh_installdeb is an exception, it will run after the other commands and
35 merge these modifications into the actual postinst scripts.
36
37 In general, files named debian/*.debhelper are internal to debhelper, and
38 their expstence or use should not be relied on by external programs such as
39 the build process of a package.
40
41 Debhelper programs should default to doing exactly what policy says to do.
42
43 There are always exceptions. Just ask me.
44
45 Introducing Dh_Lib.pm:
46 ---------------------
47
48 Dh_Lib.pm is the library used by all debhelper programs to parse their
49 arguments and set some useful variables. It's not mandatory that your
50 program use Dh_Lib.pm, but it will make it a lot easier to keep it in sync
51 with the rest of debhelper if it does, so this is highly encouraged.
52
53 (There used to be a version of Dh_lib.pm that was a library of functions for
54 shell scripts. If you want to write a debhelper command that is a shell
55 script, I can dig up that old library for you. Only the perl one is
56 supported now, though.)
57
58 Use Dh_Lib.pm like this:
59
60 use Debian::Debhelper::Dh_Lib
61 init();
62
63 The BEGIN block is there to make perl look for the module in all the right
64 places.
65
66 The init() function causes Dh_lib to parse the command line and do some other
67 initialization tasks.
68
69 Argument processing:
70 -------------------
71
72 All debhelper programs should respond to certain arguments, such as -v, -i,
73 -a, and -p. To help you make this work right, Dh_Lib.pm handles argument
74 processing. Just call init().
75
76 After argument processing, some global variables are used to hold the
77 results; programs can use them later. These variables are elements of the
78 %dh hash.
79
80 switch          variable        description
81 -v              VERBOSE         should the program verbosely output what it is
82                                 doing?
83 --no-act        NO_ACT          should the program not actually do anything?
84 -i,-a,-p,-N     DOPACKAGES      a space delimited list of the binary packages
85                                 to act on (in Dh_Lib.pm, this is an array)
86 -i,-p,-N        DOINDEP         a space delimited list of the binary independent
87                                 packages to act on
88 -a,-p,-N        DOARCH          a space delimited list of the binary dependent
89                                 packages to act on
90 -n              NOSCRIPTS       if set, do not make any modifications to the 
91                                 package's postinst, postrm, etc scripts.
92 -X              EXCLUDE         exclude a something from processing (you
93                                 decide what this means for your program)
94                                 (This is an array)
95                 EXCLUDE_FIND    same as DH_EXCLUDE, except all items are put
96                                 into a string in a way that they will make
97                                 find find them. (Use ! in front to negate
98                                 that, of course)
99 -x              INCLUDE_CONFFILES
100                                 include conffiles. It's -x for obscure
101                                 historical reasons.
102 -d              D_FLAG          you decide what this means to your program
103 -r              R_FLAG          you decide what this means to your program
104 -k              K_FLAG          you decide what this means to your program
105 -P              TMPDIR          package build directory (implies only one
106                                 package is being acted on)
107 -u              U_PARAMS        will be set to a string, that is typically
108                                 parameters your program passes on to some
109                                 other program. (This is an array)
110 -m              M_PARAMS        will be set to a string, you decide what it
111                                 means to your program
112 -l              L_PARAMS        will be set to a string, you decide what it
113                                 means to your program
114 -V              V_FLAG          will be set to a string, you decide what it
115                                 means to your program
116 -V              V_FLAG_SET      will be 1 if -V was specified, even if no
117                                 parameters were passed along with the -V
118 -A              PARAMS_ALL      generally means that additional command line
119                                 parameters passed to the program (other than
120                                 those processed here), will apply to all 
121                                 binary packages the program acts on, not just
122                                 the first
123 --init-script   INIT_SCRIPT     will be set to a string, which specifies an
124                                 init script name (probably only
125                                 dh_installinit will ever use this)
126 --sourcedir     SOURCEDIR       will be set to a string (probably only
127                                 dh_movefiles will ever use this)
128 --destdir       DESTDIR         will be set to a string (probably only
129                                 dh_builddeb will ever use this)
130 --filename      FILENAME        will be set to a string
131 --flavor        FLAVOR          will be set to a string (probably only
132                                 dh_installemacsen will ever use this)
133 --number        PRIORITY        will be set to a number (deprecated)
134 --priority      PRIORITY        will be set to a number
135
136 Any additional command line parameters that do not start with "-" will be 
137 ignored, and you can access them later just as you normally would.
138
139 If you need a new command line option, just ask me, and I will add it.
140
141 Global variables:
142 ----------------
143
144 The following keys are also set in the %dh hash when you call init():
145
146 MAINPACKAGE     the name of the first binary package listed in
147                 debian/control
148 FIRSTPACKAGE    the first package we were instructed to act on. This package
149                 typically gets special treatment, additional arguments
150                 specified on the command line may effect it.
151
152 Functions:
153 ---------
154
155 Dh_Lib.pm also contains a number of functions you may find useful.
156
157 doit()
158         Pass this function an array that is a 
159         shell command. It will run the command (unless $dh{NO_ACT} is set), and
160         if $dh{VERBOSE} is set, it will also output the command to stdout. You
161         should use this function for almost all commands your program performs
162         that manipulate files in the package build directories.
163 complex_doit()
164         Pass this function a string that is a shell command, it will run it
165         similarly to how doit() does. You can pass more complicated commands 
166         to this (ie, commands involving piping redirection), however, you 
167         have to worry about things like escaping shell metacharacters.
168 verbose_print()
169         Pass this command a string, and it will echo it if $dh{VERBOSE} is set.
170 error()
171         Pass this command a string, it will output it to standard error and
172         exit.
173 warning()
174         Pass this command a string, and it will output it to standard error
175         as a warning message.
176 tmpdir()
177         Pass this command the name of a binary package, it will return the
178         name of the tmp directory that will be used as this package's
179         package build directory. Typically, this will be "debian/package".
180 compat()
181         Pass this command a number, and if the current compatability level
182         equals that number, it will return true. Looks at DH_COMPAT to get
183         the compatability level.
184 pkgfile()
185         Pass this command the name of a binary package, and the base name of a
186         file, and it will return the actual filename to use. This is used
187         for allowing debhelper programs to have configuration files in the
188         debian/ directory, so there can be one config file per binary
189         package. The convention is that the files are named
190         debian/package.filename, and debian/filename is also allowable for
191         the $dh{MAINPACKAGE}. If the file does not exist, nothing is returned.
192 pkgext()
193         Pass this command the name of a binary package, and it will return
194         the name to prefix to files in debian/ for this package. For the
195         $dh{MAINPACKAGE}, it returns nothing (there is no prefix), for the other
196         packages, it returns "package.".
197 isnative()
198         Pass this command the name of a package, it returns 1 if the package
199         is a native debian package.
200         As a side effect, $dh{VERSION} is set to the version number of the
201         package.
202 autoscript()
203         Pass parameters:
204          - binary package to be affected
205          - script to add to
206          - filename of snippet
207          - sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
208            (optional)
209         This command automatically adds shell script snippets to a debian
210         maintainer script (like the postinst or prerm).
211
212 -- Joey Hess <joeyh@debian.org>
213