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.debhelper.log. (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 install --until dh_fixperms
155 # dh_fixperms has run, now override it for one program
156 chmod 4755 debian/foo/usr/bin/foo
158 dh install --after dh_fixperms
160 It's also fine to run debhelper commands before starting a 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.
165 dh_installdocs README TODO
166 dh_installchangelogs Changes
167 dh install --remaining
171 dh binary-arch --remaining
175 # Stash this away before init modifies it.
181 # Definitions of sequences.
183 $sequences{build} = [qw{
189 $sequences{clean} = [qw{
194 $sequences{install} = [@{$sequences{build}}, qw{
243 $sequences{'binary-indep'} = [@{$sequences{install}}, @b];
244 $sequences{binary} = [@{$sequences{install}}, qw{
249 $sequences{'binary-arch'} = [@{$sequences{binary}}];
251 # Third-party commands can be listed in the sequences, but should be
252 # listed here as well. They will not be run if not present.
258 # Get the sequence of commands to run.
260 error "specify a sequence to run";
263 if (! exists $sequences{$sequence}) {
264 error "Unknown sequence $sequence (chose from: ".
265 join(" ", sort keys %sequences).")";
267 my @sequence=@{$sequences{$sequence}};
269 # Get the options to pass to commands in the sequence.
270 # Filter out options intended only for this program.
272 if ($sequence eq 'binary-arch') {
275 elsif ($sequence eq 'binary-indep') {
279 my $opt=shift @ARGV_orig;
280 next if $opt eq $sequence;
281 if ($opt =~ /^--?(after|until|before)$/) {
285 elsif ($opt =~ /^--?(remaining|(after|until|before)=)/) {
291 # Figure out at what point in the sequence to start for each package.
294 foreach my $package (@{$dh{DOPACKAGES}}) {
295 my @log=loadlog($package);
297 # Run commands in the sequence that come after the
299 $startpoint{$package}=command_pos($dh{AFTER}, @sequence) + 1;
300 # Write a dummy log entry indicating that the specified
301 # command was, in fact, run. This handles the case where
302 # no commands remain to run after it, communicating to
303 # future dh instances that the specified command should not
305 writelog($package, $sequence[$startpoint{$package}-1]);
307 elsif ($dh{REMAINING}) {
308 # Start at the beginning so all remaining commands will get
310 $startpoint{$package}=0;
313 # Find the last logged command that is in the sequence, and
314 # continue with the next command after it. If no logged
315 # command is in the sequence, we're starting at the beginning..
316 $startpoint{$package}=0;
317 COMMAND: foreach my $command (reverse @log) {
318 foreach my $i (0..$#sequence) {
319 if ($command eq $sequence[$i]) {
320 $startpoint{$package}=$i+1;
328 # Figure out what point in the sequence to go to.
329 my $stoppoint=$#sequence;
331 $stoppoint=command_pos($dh{UNTIL}, @sequence);
333 elsif ($dh{BEFORE}) {
334 $stoppoint=command_pos($dh{BEFORE}, @sequence) - 1;
337 # Now run the commands in the sequence.
338 foreach my $i (0..$stoppoint) {
339 # Figure out which packages need to run this command.
341 foreach my $package (@{$dh{DOPACKAGES}}) {
342 if ($startpoint{$package} > $i ||
343 $logged{$package}{$sequence[$i]}) {
344 push @exclude, $package;
348 if (@exclude eq @{$dh{DOPACKAGES}}) {
349 # Command already done for all packages.
353 # Run command for all packages.
354 run($sequence[$i], @options);
357 # Run command for only a subset of packages.
358 run($sequence[$i], @options,
359 map { "-N$_" } @exclude);
367 # If a third party command is not in /usr/bin, don't try to run it.
368 if ($thirdparty{$command} && ! -x "/usr/bin/$command") {
372 # 3 space indent lines the command being run up under the
373 # sequence name after "dh ".
374 print " ".escape_shell($command, @options)."\n";
377 my $ret=system($command, @options);
378 if ($ret >> 8 != 0) {
389 my $ext=pkgext($package);
392 open(LOG, "<", "debian/${ext}debhelper.log") || return;
396 $logged{$package}{$_}=1;
405 my $ext=pkgext($package);
407 open(LOG, ">>", "debian/${ext}debhelper.log") || error("failed to write to log");
416 This program is a part of debhelper.
420 Joey Hess <joeyh@debian.org>