5 dh - debhelper command sequencer
10 use Debian::Debhelper::Dh_Lib;
14 B<dh> sequence [B<--with> I<addon>[,I<addon>,...]] [B<--list>] [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 Each debhelper command will record when it's successfully run in
28 debian/package.debhelper.log. (Which dh_clean deletes.) So dh can tell
29 which commands have already been run, for which packages, and skip running
32 Each time dh is run, it examines the log, and finds the last logged command
33 that is in the specified sequence. It then continues with the next command
34 in the sequence. The B<--until>, B<--before>, B<--after>, and B<--remaining>
35 options can override this behavior.
37 If debian/rules contains a target with a name like "override_I<dh_command>",
38 then when it would notmally run I<dh_command>, dh will instead call that
39 target. The override target can then run the command with additional options,
40 or run entirely different commands instead. See examples below. (Note that to
41 use this feature, you should Build-Depend on debhelper 7.0.50 or above.)
47 =item B<--with> I<addon>[,I<addon>,...]
49 Add the debhelper commands specified by the given addon to appropriate places
50 in the sequence of commands that is run. This option can be repeated more
51 than once, or multiple addons can be listed, separated by commas.
52 This is used when there is a third-party package that provides
53 debhelper commands. See the PROGRAMMING file for documentation about
54 the sequence addon interface.
56 =item B<--without> I<addon>
58 The inverse of --with, disables using the given addon.
60 =item B<--list>, B<-l>
62 List all available addons.
64 =item B<--until> I<cmd>
66 Run commands in the sequence until and including I<cmd>, then stop.
68 =item B<--before> I<cmd>
70 Run commands in the sequence before I<cmd>, then stop.
72 =item B<--after> I<cmd>
74 Run commands in the sequence that come after I<cmd>.
78 Run all commands in the sequence that have yet to be run.
82 Prints commands that would run for a given sequence, but does not run them.
86 All other options passed to dh are passed on to each command it runs. This
87 can be used to set an option like "-v" or "-X" or "-N", as well as for more
90 In the above options, I<cmd> can be a full name of a debhelper command, or
91 a substring. It'll first search for a command in the sequence exactly
92 matching the name, to avoid any ambiguity. If there are multiple substring
93 matches, the last one in the sequence will be used.
101 foreach my $i (0..$#sequence) {
102 if ($command eq $sequence[$i]) {
108 foreach my $i (0..$#sequence) {
109 if ($sequence[$i] =~ /\Q$command\E/) {
114 error "command specification \"$command\" does not match any command in the sequence"
123 To see what commands are included in a sequence, without actually doing
126 dh binary-arch --no-act
128 This is a very simple rules file, for packages where the default sequences of
129 commands work with no additional options.
135 Often you'll want to pass an option to a specific debhelper command. The
136 easy way to do with is by adding an override target for that command.
145 override_dh_installdocs:
146 dh_installdocs README TODO
148 Sometimes the automated dh_auto_configure and dh_auto_build can't guess
149 what to do for a strange package. Here's how to avoid running either
150 and instead run your own commands.
156 override_dh_auto_configure:
159 override_dh_auto_build:
160 make universe-explode-in-delight
162 Another common case is wanting to do something manually before or
163 after a particular debhelper command is run.
169 override_dh_fixperms:
171 chmod 4755 debian/foo/usr/bin/foo
173 If your package is a python package, dh will use dh_pysupport by
174 default. This is how to use dh_pycentral instead.
178 dh --with python-central $@
180 Here is how to force use of perl's Module::Build build system,
181 which can be necessary if debhelper wrongly detects that the package
186 dh --buildsystem=perl_build $@
188 To patch your package using quilt, you can tell dh to use quilt's dh
189 sequence addons like this:
195 Here is an example of overriding where the dh_auto_* commands find
196 the package's source, for a package where the source is located in a
201 dh --sourcedirectory=src $@
203 Finally, here is a way to prevent dh from running several commands
204 that you don't want it to run, by defining empty override targets for each
211 # Commands not to run:
212 override_dh_auto_test override_dh_compress override_dh_fixperms:
216 # Stash this away before init modifies it.
219 # python-support is enabled by default, at least for now
220 # (and comes first so python-central loads later and can disable it).
221 unshift @ARGV, "--with=python-support";
223 # Disable complaints about unknown options for both dh and the commands
224 # it runs. This is done because dh accepts and passes on options that may
225 # be specific to only some debhelper commands.
226 $ENV{DH_IGNORE_UNKNOWN_OPTIONS}=1;
229 "until=s" => \$dh{UNTIL},
230 "after=s" => \$dh{AFTER},
231 "before=s" => \$dh{BEFORE},
232 "remaining" => \$dh{REMAINING},
234 my ($option,$value)=@_;
235 push @{$dh{WITH}},split(",", $value);
238 my ($option,$value)=@_;
239 @{$dh{WITH}} = grep { $_ ne $value } @{$dh{WITH}};
242 "list" => \$dh{LIST},
246 # If make is using a jobserver, but it is not available
247 # to this process, clean out MAKEFLAGS. This avoids
248 # ugly warnings when calling make.
249 if (is_make_jobserver_unavailable()) {
250 clean_jobserver_makeflags();
253 # Definitions of sequences.
255 $sequences{build} = [qw{
261 $sequences{clean} = [qw{
266 $sequences{install} = [@{$sequences{build}}, qw{
312 $sequences{'binary-indep'} = [@{$sequences{install}}, @b];
313 $sequences{binary} = [@{$sequences{install}}, qw{
318 $sequences{'binary-arch'} = [@{$sequences{binary}}];
320 # Additional command options
323 # sequence addon interface
328 foreach my $sequence (keys %sequences) {
329 my @list=@{$sequences{$sequence}};
330 next unless grep $existing, @list;
332 foreach my $command (@list) {
333 if ($command eq $existing) {
334 push @new, $new if $offset < 0;
336 push @new, $new if $offset > 0;
342 $sequences{$sequence}=\@new;
353 foreach my $sequence (keys %sequences) {
354 $sequences{$sequence}=[grep { $_ ne $command } @{$sequences{$sequence}}];
361 unshift @{$sequences{$sequence}}, $command;
363 sub add_command_options {
365 push @{$command_opts{$command}}, @_;
367 sub remove_command_options {
370 # Remove only specified options
371 if (my $opts = $command_opts{$command}) {
372 foreach my $opt (@_) {
373 $opts = [ grep { $_ ne $opt } @$opts ];
375 $command_opts{$command} = $opts;
379 # Clear all additional options
380 delete $command_opts{$command};
388 eval q{use File::Spec};
389 my $path = File::Spec->catdir($inc, "Debian/Debhelper/Sequence");
391 for my $module_path (glob "$path/*.pm") {
392 my $name = basename($module_path);
400 for my $name (sort keys %addons) {
407 foreach my $addon (@{$dh{WITH}}) {
408 my $mod="Debian::Debhelper::Sequence::$addon";
412 error("unable to load addon $addon: $@");
416 # Get the sequence of commands to run.
418 error "specify a sequence to run";
421 if ($sequence eq 'debian/rules' ||
422 $sequence =~ /^override_dh_/) {
423 # make -B causes the rules file to be run as a target
424 # and support completly empty override targets
427 elsif (! exists $sequences{$sequence}) {
428 error "Unknown sequence $sequence (choose from: ".
429 join(" ", sort keys %sequences).")";
431 my @sequence=@{$sequences{$sequence}};
433 # The list of all packages that can be acted on.
434 my @packages=@{$dh{DOPACKAGES}};
436 # Get the options to pass to commands in the sequence.
437 # Filter out options intended only for this program.
439 if ($sequence eq 'binary-arch') {
441 # as an optimisation, remove from the list any packages
442 # that are not arch dependent
443 my %arch_packages = map { $_ => 1 } getpackages("arch");
444 @packages = grep { $arch_packages{$_} } @packages;
446 elsif ($sequence eq 'binary-indep') {
448 # ditto optimisation for arch indep
449 my %indep_packages = map { $_ => 1 } getpackages("indep");
450 @packages = grep { $indep_packages{$_} } @packages;
453 my $opt=shift @ARGV_orig;
454 next if $opt eq $sequence;
455 if ($opt =~ /^--?(after|until|before|with|without)$/) {
459 elsif ($opt =~ /^--?(no-act|remaining|(after|until|before|with|without)=)/) {
465 # Figure out at what point in the sequence to start for each package.
468 foreach my $package (@packages) {
469 my @log=load_log($package, \%logged);
471 # Run commands in the sequence that come after the
473 $startpoint{$package}=command_pos($dh{AFTER}, @sequence) + 1;
474 # Write a dummy log entry indicating that the specified
475 # command was, in fact, run. This handles the case where
476 # no commands remain to run after it, communicating to
477 # future dh instances that the specified command should not
479 write_log($sequence[$startpoint{$package}-1], $package);
481 elsif ($dh{REMAINING}) {
482 # Start at the beginning so all remaining commands will get
484 $startpoint{$package}=0;
487 # Find the last logged command that is in the sequence, and
488 # continue with the next command after it. If no logged
489 # command is in the sequence, we're starting at the beginning..
490 $startpoint{$package}=0;
491 COMMAND: foreach my $command (reverse @log) {
492 foreach my $i (0..$#sequence) {
493 if ($command eq $sequence[$i]) {
494 $startpoint{$package}=$i+1;
502 # Figure out what point in the sequence to go to.
503 my $stoppoint=$#sequence;
505 $stoppoint=command_pos($dh{UNTIL}, @sequence);
507 elsif ($dh{BEFORE}) {
508 $stoppoint=command_pos($dh{BEFORE}, @sequence) - 1;
511 # Now run the commands in the sequence.
512 foreach my $i (0..$stoppoint) {
513 # Figure out which packages need to run this command.
515 foreach my $package (@packages) {
516 if ($startpoint{$package} > $i ||
517 $logged{$package}{$sequence[$i]}) {
518 push @exclude, $package;
522 if (@exclude eq @packages) {
523 # Command already done for all packages.
527 run($sequence[$i], \@packages, \@exclude, @options);
532 my @packages=@{shift()};
533 my @exclude=@{shift()};
536 # If some packages are excluded, add flags
537 # to prevent them from being acted on.
538 push @options, map { "-N$_" } @exclude;
540 # Check for override targets in debian/rules and
541 # run them instead of running the command directly.
542 my $override_command;
543 if (rules_explicit_target("override_".$command)) {
544 $override_command=$command;
545 # This passes the options through to commands called
547 $ENV{DH_INTERNAL_OPTIONS}=join("\x1e", @options);
548 $command="debian/rules";
549 @options="override_".$override_command;
552 # Pass additional command options if any
553 unshift @options, @{$command_opts{$command}} if exists $command_opts{$command};
556 # 3 space indent lines the command being run up under the
557 # sequence name after "dh ".
558 print " ".escape_shell($command, @options)."\n";
561 my $ret=system($command, @options);
562 if ($ret >> 8 != 0) {
569 if (defined $override_command) {
570 delete $ENV{DH_INTERNAL_OPTIONS};
571 # Need to handle logging for overriden commands here,
572 # because the actual debhelper command may not have
573 # been run by the rules file target.
574 # (But avoid logging for dh_clean since it removes
576 if ($override_command ne 'dh_clean') {
577 my %packages=map { $_ => 1 } @packages;
578 map { delete $packages{$_} } @exclude;
579 write_log($override_command, keys %packages);
589 sub rules_explicit_target {
590 # Checks if a specified target exists as an explicit target
594 if (! $rules_parsed) {
595 my $processing_targets = 0;
596 my $not_a_target = 0;
597 open(MAKE, "LC_ALL=C make -Rrnpsf debian/rules debhelper-fail-me 2>/dev/null |");
599 if ($processing_targets) {
600 if (/^# Not a target:/) {
604 if (!$not_a_target && /^([^#:]+)::?/) {
606 # NOTE: if it is a depenency
607 # of .PHONY it will be
608 # defined too but that's ok.
611 # "Not a target:" is always followed by
612 # a target name, so resetting this one
616 } elsif (/^# Files$/) {
617 $processing_targets = 1;
624 return exists $targets{$target};
633 This program is a part of debhelper.
637 Joey Hess <joeyh@debian.org>