242
242
Finally, remember that you are not limited to using override targets in the
243
243
rules file when using B<dh>. You can also explicitly define any of the regular
244
244
rules file targets when it makes sense to do so. A common reason to do this
245
is if your package needs different B<build-arch> and B<build-indep> targets. For
246
example, a package with a long document build process can put it in
247
B<build-indep> to avoid build daemons redundantly building the documentation.
245
is when your package needs different B<build-arch> and B<build-indep> targets.
246
For example, a package with a long document build process can put it in
249
249
#!/usr/bin/make -f
253
build: build-arch build-indep ;
258
Note that in the example above, dh will arrange for "debian/rules build"
259
to call your build-indep and build-arch targets. You do not need to
260
explicitly define the dependencies in the rules file when using dh with
261
compatability level v9. This example would be more complicated with
262
earlier compatability levels.
261
266
If you're curious about B<dh>'s internals, here's how it works under the hood.
270
275
in the sequence. The B<--until>, B<--before>, B<--after>, and B<--remaining>
271
276
options can override this behavior.
278
A sequence can also run dependent targets in debian/rules. For
279
example, the "binary" sequence runs the "install" target.
281
B<dh> sets environment variables listed by B<dpkg-buildflags>, unless
282
they are already set. It supports DEB_BUILD_OPTIONS=noopt too.
273
284
B<dh> uses the B<DH_INTERNAL_OPTIONS> environment variable to pass information
274
285
through to debhelper commands that are run inside override targets. The
275
286
contents (and indeed, existence) of this environment variable, as the name
316
327
clean_jobserver_makeflags();
330
# Process the sequence parameter.
333
# From v8, the sequence is the very first parameter.
334
$sequence=shift @ARGV_orig;
335
if ($sequence=~/^-/) {
336
error "Unknown sequence $sequence (options should not come before the sequence)";
340
# Before v8, the sequence could be at any position in the parameters,
341
# so was what was left after parsing.
343
if (defined $sequence) {
344
@ARGV_orig=grep { $_ ne $sequence } @ARGV_orig;
347
if (! defined $sequence) {
348
error "specify a sequence to run";
350
# make -B causes the rules file to be run as a target.
351
# Also support completly empty override targets.
352
# Note: it's not safe to use rules_explicit_target before this check,
353
# since it causes dh to be run.
354
my $dummy_target="debhelper-fail-me";
355
if ($sequence eq 'debian/rules' ||
356
$sequence =~ /^override_dh_/ ||
357
$sequence eq $dummy_target) {
319
362
# Definitions of sequences.
321
$sequences{build} = [qw{
323
369
dh_auto_configure
327
$sequences{'build-indep'} = [@{$sequences{build}}];
328
$sequences{'build-arch'} = [@{$sequences{build}}];
329
$sequences{clean} = [qw{
390
$sequences{binary} = [@{$sequences{install}}, @ba, @b];
391
$sequences{'binary-indep'} = [@{$sequences{'install-indep'}}, @b];
392
$sequences{'binary-arch'} = [@{$sequences{'install-arch'}}, @ba, @b];
429
$sequences{clean} = [qw{
434
$sequences{'build-indep'} = [@bd];
435
$sequences{'build-arch'} = [@bd];
437
# From v9, sequences take standard rules targets into account.
438
if (rules_explicit_target('build-arch') ||
439
rules_explicit_target('build-indep')) {
440
# run sequences separately
441
$sequences{build} = [@bd_minimal, rules("build-arch"), rules("build-indep")];
444
# run standard sequence (this is faster)
445
$sequences{build} = [@bd];
447
$sequences{'install-indep'} = [rules("build-indep"), @i];
448
$sequences{'install-arch'} = [rules("build-arch"), @i];
449
if (rules_explicit_target('install-arch') ||
450
rules_explicit_target('install-indep')) {
451
# run sequences separately
452
$sequences{'install'} = [rules("build"), @i_minimal, rules("install-arch"), rules("install-indep")];
455
# run standard sequence (this is faster)
456
$sequences{'install'} = [rules("build"), @i, rules("install-arch"), rules("install-indep")];
458
$sequences{'binary-indep'} = [rules("install-indep"), @b];
459
$sequences{'binary-arch'} = [rules("install-arch"), @ba, @b];
460
$sequences{binary} = [rules("install"), rules("binary-arch"), rules("binary-indep")];
463
$sequences{build} = [@bd];
464
$sequences{'install'} = [@{$sequences{build}}, @i];
465
$sequences{'install-indep'} = [@{$sequences{'build-indep'}}, @i];
466
$sequences{'install-arch'} = [@{$sequences{'build-arch'}}, @i];
467
$sequences{binary} = [@{$sequences{install}}, @ba, @b];
468
$sequences{'binary-indep'} = [@{$sequences{'install-indep'}}, @b];
469
$sequences{'binary-arch'} = [@{$sequences{'install-arch'}}, @ba, @b];
394
472
# Additional command options
395
473
my %command_opts;
492
# From v8, the sequence is the very first parameter.
493
$sequence=shift @ARGV_orig;
494
if ($sequence=~/^-/) {
495
error "Unknown sequence $sequence (options should not come before the sequence)";
499
# Before v8, the sequence could be at any position in the parameters,
500
# so was what was left after parsing.
502
if (defined $sequence) {
503
@ARGV_orig=grep { $_ ne $sequence } @ARGV_orig;
506
if (! defined $sequence) {
507
error "specify a sequence to run";
509
if ($sequence eq 'debian/rules' ||
510
$sequence =~ /^override_dh_/) {
511
# make -B causes the rules file to be run as a target.
512
# Also support completly empty override targets.
515
elsif (! exists $sequences{$sequence}) {
569
if (! exists $sequences{$sequence}) {
516
570
error "Unknown sequence $sequence (choose from: ".
517
571
join(" ", sort keys %sequences).")";
519
my @sequence=@{$sequences{$sequence}};
573
my @sequence=optimize_sequence(@{$sequences{$sequence}});
521
575
# The list of all packages that can be acted on.
522
576
my @packages=@{$dh{DOPACKAGES}};
642
696
# run them instead of running the command directly.
643
697
my $override_command;
644
698
my $has_explicit_target = rules_explicit_target("override_".$command);
645
if (defined $has_explicit_target) {
700
my $rules_target = rules_target($command);
701
if (defined $rules_target) {
702
# Don't pass DH_ environment variables, since this is
703
# a fresh invocation of debian/rules and any sub-dh
705
$override_command=$command;
706
delete $ENV{DH_INTERNAL_OPTIONS};
707
delete $ENV{DH_INTERNAL_OVERRIDE};
708
$command="debian/rules";
709
@options=$rules_target;
711
elsif (defined $has_explicit_target) {
646
712
$override_command=$command;
647
713
# Check if target isn't noop
648
714
if ($has_explicit_target) {
770
sub optimize_sequence {
774
# commands can appear multiple times when sequences are
775
# inlined together; only the first should be needed
777
if (! $seen{$command}) {
779
push @sequence, $command;
782
foreach my $command (@_) {
783
my $rules_target=rules_target($command);
784
if (defined $rules_target &&
785
! defined rules_explicit_target($rules_target)) {
786
# inline the sequence for this implicit target
787
$add->($_) foreach optimize_sequence(@{$sequences{$rules_target}});
798
if ($command =~ /^debian\/rules\s+(.*)/) {
807
return "debian/rules ".join(" ", @_);
706
812
my $rules_parsed;
716
822
my $processing_targets = 0;
717
823
my $not_a_target = 0;
718
824
my $current_target;
719
open(MAKE, "LC_ALL=C make -Rrnpsf debian/rules debhelper-fail-me 2>/dev/null |");
825
open(MAKE, "LC_ALL=C make -Rrnpsf debian/rules $dummy_target 2>/dev/null |");
721
827
if ($processing_targets) {
722
828
if (/^# Not a target:/) {