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