- # If some packages are excluded, add flags
- # to prevent them from being acted on.
- push @options, map { "-N$_" } @exclude;
-
- # Check for override targets in debian/rules and
- # run them instead of running the command directly.
- my $override_command;
- my $has_explicit_target = rules_explicit_target("override_".$command);
- if (defined $has_explicit_target) {
- $override_command=$command;
- # Check if target isn't noop
- if ($has_explicit_target) {
- # This passes the options through to commands called
- # inside the target.
- $ENV{DH_INTERNAL_OPTIONS}=join("\x1e", @options);
- $command="debian/rules";
- @options="override_".$override_command;
+ my $has_explicit_target = rules_explicit_target($override);
+ return 0 unless defined $has_explicit_target; # no such override
+ return 1 if ! $has_explicit_target; # has empty override
+
+ # This passes the options through to commands called
+ # inside the target.
+ $ENV{DH_INTERNAL_OPTIONS}=join("\x1e", @options);
+ $ENV{DH_INTERNAL_OVERRIDE}=$command;
+ run("debian/rules", "override_".$command);
+ delete $ENV{DH_INTERNAL_OPTIONS};
+ delete $ENV{DH_INTERNAL_OVERRIDE};
+
+ # Update log for overridden command now that it has
+ # finished successfully.
+ # (But avoid logging for dh_clean since it removes
+ # the log earlier.)
+ if (! $dh{NO_ACT} && $command ne 'dh_clean') {
+ my %packages=map { $_ => 1 } @packages;
+ map { delete $packages{$_} } @exclude;
+ write_log($command, keys %packages);
+ commit_override_log(keys %packages);
+ }
+
+ return 1;
+}
+
+sub optimize_sequence {
+ my @sequence;
+ my %seen;
+ my $add=sub {
+ # commands can appear multiple times when sequences are
+ # inlined together; only the first should be needed
+ my $command=shift;
+ if (! $seen{$command}) {
+ $seen{$command}=1;
+ push @sequence, $command;
+ }
+ };
+ foreach my $command (@_) {
+ my $rules_target=rules_target($command);
+ if (defined $rules_target &&
+ ! defined rules_explicit_target($rules_target)) {
+ # inline the sequence for this implicit target
+ $add->($_) foreach optimize_sequence(@{$sequences{$rules_target}});