5 dh - debhelper command sequencer
10 use Debian::Debhelper::Dh_Lib;
14 B<dh> sequence [B<--until> I<cmd>] [B<--before> I<cmd>] [B<--after> I<cmd>] [B<--remaining> [S<I<debhelper options>>]
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".
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.
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
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
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.
45 =item B<--until> I<cmd>
47 Run commands in the sequence until and including I<cmd>, then stop.
49 =item B<--before> I<cmd>
51 Run commands in the sequence before I<cmd>, then stop.
53 =item B<--after> I<cmd>
55 Run commands in the sequence that come after I<cmd>.
59 Run all commands in the sequence that have yet to be run.
61 =head1 COMMAND SPECIFICATION
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.
74 foreach my $i (0..$#sequence) {
75 if ($command eq $sequence[$i]) {
81 foreach my $i (0..$#sequence) {
82 if ($sequence[$i] =~ /\Q$command\E/) {
87 error "command specification \"$command\" does not match any command in the sequence"
96 To see what commands are included in a sequence, without actually doing
99 dh binary-arch --no-act
101 This is a very simple rules file, for packages where the default seqences of
102 commands work with no additional options.
108 This is a simple rules file that is a good starting place for customisation.
109 (It's also available in F</usr/share/doc/debhelper/examples/rules.simple>
125 binary-indep: install
128 binary: binary-arch binary-indep
130 Often you'll want to pass an option to ./configure. This uses dh to run all
131 commands before L<dh_auto_configure(1)>, then runs that command by hand,
132 and then finished up by running the rest of the sequence. You could also
133 run ./configure by hand, instead of bothering with using dh_auto_configure.
134 And if necessary, you can add commands to run automake, etc here too.
137 dh build --before configure
138 dh_auto_configure --kitchen-sink=yes
139 dh build --after configure
141 Here's how to skip two automated in a row (configure and build), and
142 instead run the commands by hand.
145 dh build --before configure
147 make universe-explode-in-delight
148 dh build --after build
150 Another common case is wanting to run some code manually after a particular
151 debhelper command is run.
154 dh binary-arch --until dh_fixperms
155 # dh_fixperms has run, now override it for one program
156 chmod 4755 debian/foo/usr/bin/foo
158 dh binary-arch --after dh_fixperms
160 It's also fine to run debhelper commands before starting the dh sequence.
161 Just be sure to use the B<--remaining> option to ensure that commands
162 that normally come before those in the sequence are still run.
167 dh binary-arch --remaining
171 # Stash this away before init modifies it.
176 # Definitions of sequences.
178 $sequences{build} = [qw{
184 $sequences{clean} = [qw{
189 $sequences{install} = [@{$sequences{build}}, qw{
237 $sequences{'binary-indep'} = [@{$sequences{install}}, @b];
238 $sequences{binary} = [@{$sequences{install}}, qw{
243 $sequences{'binary-arch'} = [@{$sequences{binary}}];
245 # Get the sequence of commands to run.
247 error "specify a sequence to run";
250 if (! exists $sequences{$sequence}) {
251 error "Unknown sequence $sequence (chose from: ".
252 join(" ", sort keys %sequences).")";
254 my @sequence=@{$sequences{$sequence}};
256 # Get the options to pass to commands in the sequence.
257 # Filter out options intended only for this program.
259 if ($sequence eq 'binary-arch') {
262 elsif ($sequence eq 'binary-indep') {
266 my $opt=shift @ARGV_orig;
267 next if $opt eq $sequence;
268 if ($opt =~ /^--?(after|until|before)$/) {
272 elsif ($opt =~ /^--?(remaining|(after|until|before)=)/) {
278 # Figure out at what point in the sequence to start for each package.
281 foreach my $package (@{$dh{DOPACKAGES}}) {
283 # Run commands in the sequence that come after the
285 $startpoint{$package}=command_pos($dh{AFTER}, @sequence) + 1;
287 elsif ($dh{REMAINING}) {
288 # Start at the beginning so all remaining commands will get
290 $startpoint{$package}=0;
293 # Find the last logged command that is in the sequence, and
294 # continue with the next command after it. If no logged
295 # command is in the sequence, we're starting at the beginning..
296 my @log=loadlog($package);
297 $startpoint{$package}=0;
298 COMMAND: foreach my $command (reverse @log) {
299 foreach my $i (0..$#sequence) {
300 if ($command eq $sequence[$i]) {
301 $startpoint{$package}=$i+1;
309 # Figure out what point in the sequence to go to.
310 my $stoppoint=$#sequence;
312 $stoppoint=command_pos($dh{UNTIL}, @sequence);
314 elsif ($dh{BEFORE}) {
315 $stoppoint=command_pos($dh{BEFORE}, @sequence) - 1;
318 # Now run the commands in the sequence.
319 foreach my $i (0..$stoppoint) {
320 # Figure out which packages need to run this command.
322 foreach my $package (@{$dh{DOPACKAGES}}) {
323 if ($startpoint{$package} > $i ||
324 $logged{$package}{$sequence[$i]}) {
325 push @exclude, $package;
329 if (@exclude eq @{$dh{DOPACKAGES}}) {
330 # Command already done for all packages.
334 # Run command for all packages.
335 run($sequence[$i], @options);
338 # Run command for only a subset of packages.
339 run($sequence[$i], @options,
340 map { "-N$_" } @exclude);
348 # dh_clean -k is a special case
349 if ($command eq 'dh_clean' && $sequence ne 'clean') {
350 unshift @options, "-k";
353 # The 4 spaces is a kind of half indent.
354 print " ".escape_shell($command, @options)."\n";
357 my $ret=system($command, @options);
358 exit($ret) if $ret != 0;
364 my $ext=pkgext($package);
367 open(LOG, "<", "debian/${ext}log.debhelper");
371 $logged{$package}{$_}=1;
381 This program is a part of debhelper.
385 Joey Hess <joeyh@debian.org>