]> git.donarmstrong.com Git - debhelper.git/blob - PROGRAMMING
r75: Initial Import
[debhelper.git] / 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:
40 ------------------
41
42 All debhelper programs use the dh_lib library (actually it's a shell script)
43 to parse their arguments and set some useful variables. It's not mandatory
44 that your program use dh_lib, but it will make it a lot easier to keep it in
45 sync with the rest of debhelper if it does, so this is highly encouraged.
46
47 Typically, you invoke dh_lib like this:
48
49 PATH=debian:$PATH:/usr/lib/debhelper
50 . dh_lib
51
52 The path statement is there to make your program look first in debian/ for
53 dh_lib (so users can install a modified version there if necessary), then the
54 rest of the path, then the canonical location of dh_lib, /usr/lib/debhelper.
55
56 Argument processing:
57 -------------------
58
59 All debhelper programs should respond to certain arguments, such as -v, -i,
60 -a, and -p. To help you make this work right, dh_lib handles argument
61 processing.
62
63 As soon as dh_lib loads, it processes any arguments that have been passed to
64 your program. The following variables may be set during this stage; your
65 program can use them later:
66
67 switch          variable        description
68 -v              DH_VERBOSE      should the program verbosely output what it is
69                                 doing?
70 --no-act        DH_NO_ACT       should the program not actually do anything?
71 -i,-a,-p        DH_DOPACKAGES   a space delimited list of the binary packages
72                                 to act on
73 -i,-p           DH_DOINDEP      a space delimited list of the binary independent
74                                 packages to act on
75 -a,-p           DH_DOARCH       a space delimited list of the binary dependent
76                                 packages to act on
77 -n              DH_NOSCRIPTS    if set, do not make any modifications to the 
78                                 package's postinst, postrm, etc scripts.
79 -x              DH_EXCLUDE      exclude a something from processing (you
80                                 decide what this means for your program)
81 -d              DH_D_FLAG       you decide what this means to your program
82 -r              DH_R_FLAG       you decide what this means to your program
83 -k              DH_K_FLAG       you decide what this means to your program
84 -P              DH_TMPDIR       package build directory (implies only one
85                                 package is being acted on)
86 -u              DH_U_PARAMS     will be set to a string, that is typically
87                                 parameters your program passes on to some
88                                 other program.
89 -m              DH_M_PARAMS     will be set to a string, you decide what it
90                                 means to your program
91 -V              DH_V_FLAG       will be set to a string, you decide what it
92                                 means to your program
93 -V              DH_V_FLAG_SET   will be 1 if -V was specified, even if no
94                                 parameters were passed along with the -V
95 -A              DH_PARAMS_ALL   generally means that additional command line
96                                 parameters passed to the program (other than
97                                 those processed here), will apply to all 
98                                 binary packages the program acts on, not just
99                                 the first
100 --init-script   DH_INIT_SCRIPT  will be set to a string, which specifies an
101                                 init script name (probably only
102                                 dh_installinit will ever use this)
103
104 Any additional command line parameters that do not start with "-" will be 
105 ignored, and you can access them later just as you normally would ($1, $2,
106 etc).
107
108 If you need a new command line option, just ask me, and I will add it.
109
110 Global variables:
111 ----------------
112
113 The following variables are also set, you can use any of them:
114
115 MAINPACKAGE     the name of the first binary package listed in
116                 debian/control
117 DH_FIRSTPACKAGE the first package we were instructed to act on. This package
118                 typically gets special treatment, additional arguments
119                 specified on the command line may effect it.
120
121 Functions:
122 ---------
123
124 Dh_lib also contains a number of functions you may find useful.
125
126 doit()
127         Pass this function a string that is a shell command. It will run the
128         command (unless DH_NO_ACT is set), and if DH_VERBOSE is set, it will
129         also output the command to stdout. You should use this function for
130         almost all commands your program performs that manipulate files in
131         the package build directories.
132 complex_doit()
133         This is the same as doit(), except you can pass more complicated
134         commands to it (ie, commands involving piping redirection)
135 verbose_echo()
136         Pass this command a string, and it will echo it if DH_VERBOSE is set.
137 error()
138         Pass this command a string, it will output it to standard error and
139         exit.
140 tmpdir()
141         Pass this command the name of a binary package, it will return the
142         name of the tmp directory that will be used as this package's
143         package build directory. Typically, this will be "debian/tmp" or
144         "debian/package".
145 pkgfile()
146         Pass this command the name of a binary package, and the base name of a
147         file, and it will return the actual filename to use. This is used
148         for allowing debhelper programs to have configuration files in the
149         debian/ directory, so there can be one config file per binary
150         package. The convention is that the files are named
151         debian/package.filename, and debian/filename is also allowable for
152         the MAINPACKAGE. If the file does not exist, nothing is returned.
153 pkgext()
154         Pass this command the name of a binary package, and it will return
155         the name to prefix to files in debian/ for this package. For the
156         MAINPACKAGE, it returns nothing (there is no prefix), for the other
157         packages, it returns "package.".
158 isnative()
159         Pass this command the name of a package, it returns 1 if the package
160         is a native debian package.
161         As a side effect, VERSION is set to the version number of the
162         package.
163 autoscript()
164         Pass 3 parameters:
165          1: script to add to
166          2: filename of snippet
167          3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
168             (optional)
169         This command automatically adds shell script snippets to a debian
170         maintainer script (like the postinst or prerm).
171
172 Notes:
173 -----
174
175 Dh_lib is still evolving.
176 There will probably be a perl version too, in the future.
177
178 -- Joey Hess <joeyh@master.debian.org>