]> git.donarmstrong.com Git - debhelper.git/blob - dh
initial version of dh, with option parsing and sequences in place
[debhelper.git] / dh
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh - debhelper command sequencer
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh> sequence [B<--until> I<cmd>] [B<--before> I<cmd>] [B<--after> I<cmd>] [B<--remaining> [S<I<debhelper options>>]
15
16 =head1 DESCRIPTION
17
18 dh runs a sequence of debhelper commands. The supported sequences
19 correspond to the targets of a debian/rules file: "build", "clean",
20 "install", "binary-arch", "binary-indep", and "binary".
21
22 Commands in the binary-indep sequence are passed the "-i" option to ensure
23 they only work on binary independent packages, and commands in the
24 binary-arch sequences are passed the "-a" option to ensure they only work
25 on architecture dependent packages.
26
27 Options passed to dh are passed on to each command it runs. This can be
28 used to set an option like "-v" or "-X" or "-N", as well as for more
29 specialised options.
30
31 Each debhelper command will record when it's successfully run in
32 debian/package.log.debhelper. (Which dh_clean deletes.) So dh can tell
33 which commands have already been run, for which packages, and skip running
34 those commands again.
35
36 Each time dh is run, it examines the log, and finds the last logged command
37 that is in the specified sequence. It then continues with the next command
38 in the sequence. The B<--until>, B<--before>, B<--after>, and B<--remaining>
39 options can override this behavior.
40
41 =head1 OPTIONS
42
43 =over 4
44
45 =item B<--until> I<cmd>
46
47 Run commands in the sequence until and including I<cmd>, then stop.
48
49 =item B<--before> I<cmd>
50
51 Run commands in the sequence before I<cmd>, then stop.
52
53 =item B<--after> I<cmd>
54
55 Run commands in the sequence that come after I<cmd>.
56
57 =item B<--remaining>
58
59 Run all commands in the sequence that have yet to be run.
60
61 =head1 COMMAND SPECIFICATON
62
63 I<cmd> can be a full name of a debhelper command, or a substring. It'll first
64 search for a command in the sequence exactly matching the name, to avoid any
65 ambiguity. If there are multiple substring matches, the last one in the
66 sequence will be used.
67
68 =head1 EXAMPLES
69
70 To see what commands are included in a sequence, without actually doing
71 anything:
72
73         dh binary-arch -n
74
75 This is a very simple rules file, for packages where the default seqences of
76 commands work with no additional options.
77
78         #!/usr/bin/make -f
79         %:
80                 dh %@
81
82 This is a simple rules file that is a good starting place for customisation.
83 (It's also available in F</usr/share/doc/debhelper/examples/rules.simple>
84
85         #!/usr/bin/make -f
86
87         build:
88                 dh build
89
90         clean:
91                 dh clean
92
93         install: build
94                 dh install
95
96         binary-arch: install
97                 dh binary-arch
98
99         binary-indep: install
100                 dh binary-indep
101
102         binary: binary-arch binary-indep
103
104 Often you'll want to pass an option to ./configure. This uses dh to run all
105 commands before L<dh_auto_configure(1)>, then runs that command by hand,
106 and then finished up by running the rest of the sequence. You could also
107 run ./configure by hand, instead of bothering with using dh_auto_configure.
108 And if necessary, you can add commands to run automake, etc here too.
109
110         build:
111                 dh build --before configure
112                 dh_auto_configure --kitchen-sink=yes
113                 dh build --after configure
114
115 Here's how to skip two automated in a row (configure and build), and
116 instead run the commands by hand.
117
118         build:
119                 dh build --before configure
120                 ./mondoconfig
121                 make universe-explode-in-delight
122                 dh build --after build
123
124 Another common case is wanting to run some code manually after a particular
125 debhelper command is run.
126
127         binary-arch: install
128                 dh binary-arch --until dh_fixperms
129                 # dh_fixperms has run, now override it for one program
130                 chmod 4755 debian/foo/usr/bin/foo
131                 # and continue
132                 dh binary-arch --after dh_fixperms
133
134 It's also fine to run debhelper commands before starting the dh sequence.
135 Just be sure to use the B<--remaining> option to ensure that commands
136 that normally come before those in the sequence are still run.
137
138         binary-arch: install
139                 dh_strip -X foo
140                 dh_fixperms -X bar
141                 dh binary-arch --remaining
142
143 =cut
144
145 # Stash this away before init modifies it.
146 my @ARGV_orig=@ARGV;
147
148 init();
149
150 # Definitions of sequences.
151 my %sequences;
152 $sequences{build} = [qw{
153         dh_testdir
154         dh_auto_configure
155         dh_auto_build
156         dh_auto_test
157 }],
158 $sequences{clean} = [qw{
159         dh_testdir
160         dh_auto_clean
161         dh_clean
162 }];
163 $sequences{install} = [@{$sequences{build}}, "dh_testroot", "dh_clean -k", qw{
164         dh_installdirs
165         dh_auto_install
166
167         dh_install
168         dh_installdocs
169         dh_installchangelogs
170         dh_installexamples
171         dh_installman
172
173         dh_installcatalogs
174         dh_installcron
175         dh_installdebconf
176         dh_installcatalogs
177         dh_installemacsen
178         dh_installifupdown
179         dh_installinfo
180         dh_installinit
181         dh_installmenu
182         dh_installmime
183         dh_installmodules
184         dh_installpam
185         dh_installppp
186         dh_installudev
187         dh_installwm
188         dh_installxfonts
189         dh_lintian
190         dh_desktop
191         dh_gconf
192         dh_icons
193         dh_logcheck
194         dh_logrotate
195         dh_perl
196         dh_python
197         dh_scrollkeeper
198         dh_uselocal
199
200         dh_link
201         dh_compress
202         dh_fixperms
203 }];
204 my @b=qw{
205         dh_gencontrol
206         dh_md5sums
207         dh_builddeb
208 };
209 $sequences{'binary-indep'} = [@{$sequences{install}}, @b];
210 $sequences{binary} = [@{$sequences{install}}, qw{
211         dh_strip
212         dh_makeshlibs
213         dh_shlibdeps
214 }, @b];
215 $sequences{'binary-arch'} = [@{$sequences{binary}}];
216
217 # Sequence parameter.
218 if (! @ARGV) {
219         error "specify a sequence to run";
220 }
221 my $sequence=shift;
222 if (! exists $sequences{$sequence}) {
223         error "Unknown sequence $sequence (chose from: ".
224                 join(" ", sort keys %sequences).")";
225 }
226
227 # Get the options to pass to commands in the sequence.
228 # Filter out options intended only for this program.
229 my @options;
230 if ($sequence eq 'binary-arch') {
231         push @options, "-a";
232 }
233 elsif ($sequence eq 'binary-indep') {
234         push @options, "-i";
235 }
236 while (@ARGV_orig) {
237         my $opt=shift @ARGV_orig;
238         next if $opt eq $sequence;
239         if ($opt =~ /^--?(after|until|before)$/) {
240                 shift @ARGV_orig;
241                 next;
242         }
243         elsif ($opt =~ /^--?(remaining|(after|until|before)=)/) {
244                 next;
245         }
246         push @options, $opt;
247 }
248
249 @options=grep {
250         $_ ne $sequence && !/^--?(before|after|remaining)$/
251 } @options;
252
253 foreach my $cmd (@{$sequences{$sequence}}) {
254         print "$cmd @options\n";
255 }
256
257 foreach my $package (@{$dh{DOPACKAGES}}) {
258         my $tmp=tmpdir($package);
259         my $ext=pkgext($package);
260 }
261
262 =head1 SEE ALSO
263
264 L<debhelper(7)>
265
266 This program is a part of debhelper.
267
268 =head1 AUTHOR
269
270 Joey Hess <joeyh@debian.org>
271
272 =cut