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