]> git.donarmstrong.com Git - debhelper.git/blob - PROGRAMMING
r103: Initial revision
[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 confile file (replace filename
25 with whatever your command wants), and debian/filename should also be
26 checked for config information for the first binart 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 thay 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 Intoroducing 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 canoical location of dh_lib, /usr/lib/debhelper.
55
56 Argument processing:
57 -------------------
58
59 All debhelper programs should respond to certian arguemnts, such as -v, -i,
60 -a, and -p. To help you make this work right, dh_lib handles argumeny
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 independant
74                                 packages to act on
75 -a,-p           DH_DOARCH       a space delimited list of the binary dependant
76                                 packages to act on
77 -n              DH_NOSCRIPTS    if set, do not make any modifications to the 
78                                 package's postinst, posrtm, 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
101 Any additional command line parameters that do not start with "-" will be 
102 ignored, and you can access them later just as you normally would ($1, $2,
103 etc).
104
105 If you need a new command line option, just ask me, and I will add it.
106
107 Global variables:
108 ----------------
109
110 The following variables are also set, you can use any of them:
111
112 MAINPACKAGE     the name of the first binary package listed in
113                 debian/control
114 DH_FIRSTPACKAGE the first package we were instructed to act on. This package
115                 typically gets special tratment, addiiional arguments
116                 specified on the command line may effect it.
117
118 Functions:
119 ---------
120
121 Dh_lib also contains a number of functions you may find useful.
122
123 doit()
124         Pass this function a string that is a shell command. It will run the
125         command (unless DH_NO_ACT is set), and if DH_VERBOSE is set, it will
126         also output the command to stdout. You should use this function for
127         almost all commands your program performs that manipulate files in
128         the package build directories.
129 complex_doit()
130         This is the same as doit(), except you can pass more complicated
131         commands to it (ie, commands involving piping redirection)
132 verbose_echo()
133         Pass this command a string, and it will echo it if DH_VERBOSE is set.
134 error()
135         Pass this command a string, it will output it to standard error and
136         exit.
137 tmpdir()
138         Pass this command the name of a binary package, it will return the
139         name of the tmp directory that will be used as this package's
140         package build directory. Typically, this will be "debian/tmp" or
141         "debian/package".
142 pkgfile()
143         Pass this command the name of a binary package, and the base name of a
144         file, and it will return the actual filename to use. This is used
145         for allowing debhelper programs to have configuration files in the
146         debian/ directory, so there can be one config file per binary
147         package. The conversion is that the files are named
148         debian/package.filename, and debian/filename is also allowable for
149         the MAINPACKAGE. If the file does not exist, nothing is returned.
150 pkgext()
151         Pass this command the name of a binary package, and it will return
152         the name to prefix to files in debian/ for this package. For the
153         MAINPACKAGE, it returns nothing (there is no prefix), for the other
154         packages, it returns "package.".
155 isnative()
156         Pass this command the name of a package, it returns 1 if the package
157         is a native debian package.
158         As a side effect, VERSION is set to the version number of the
159         package.
160 autoscript()
161         Pass 3 parameters:
162          1: script to add to
163          2: filename of snippet
164          3: sed commands to run on the snippet. Ie, s/#PACKAGE#/$PACKAGE/
165             (optional)
166         This command automatically adds shell script snippets to a debian
167         maintainer script (like the postinst or prerm).
168
169 Notes:
170 -----
171
172 Dh_lib is still evolving.
173 There will probably be a perl version too, in the future.
174
175 -- Joey Hess <joeyh@master.debian.org>