~ubuntu-branches/ubuntu/oneiric/debhelper/oneiric-proposed

« back to all changes in this revision

Viewing changes to dh

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2011-07-02 00:04:09 UTC
  • mfrom: (1.4.28 sid)
  • Revision ID: james.westby@ubuntu.com-20110702000409-hdc41wh3amddu4bg
Tags: 8.9.0ubuntu1
* Merge with Debian (LP: #801884); remaining changes:
  - dh_installinit: Add --upstart-only and --onlyscripts-upstart modes.
  - Add various autoscripts for above: postinst-upstart,
    postinst-upstart-replace, postinst-upstart-restart,
    prerm-upstart, prerm-upstart-norestart, preinst-removeconffile.
  - dh_installudev: Change default init.d symlink priority to 40.
  - dh_installchangelogs: Do not install upstream changelog in compat level
    7. This floods packages with huge upstream changelogs which take
    precious CD space.
  - add dh_apparmor and autoscripts
  - debian/rules: set executable bit for dh_apparmor before actually running
    dh build, that is in order to get the manpage built for dh_apparmor.
  - dh_installinit: drop redundant definition of -O.
  - debian/control: dpkg-dev dependency needs to be on 1.16.0~ubuntu4 for
    multiarch, not just 1.16.0~.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
247
B<build-indep>.
248
248
 
249
249
        #!/usr/bin/make -f
250
250
        %:
251
251
                dh $@
252
252
        
253
 
        build: build-arch build-indep ;
254
253
        build-indep:
255
254
                $(MAKE) docs
256
255
        build-arch:
257
256
                $(MAKE) bins
258
257
 
 
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.
 
263
 
259
264
=head1 INTERNALS
260
265
 
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.
272
277
 
 
278
A sequence can also run dependent targets in debian/rules.  For
 
279
example, the "binary" sequence runs the "install" target.
 
280
 
 
281
B<dh> sets environment variables listed by B<dpkg-buildflags>, unless
 
282
they are already set. It supports DEB_BUILD_OPTIONS=noopt too.
 
283
 
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
307
318
        bundling => 0,
308
319
);
309
320
inhibit_log();
310
 
 
 
321
set_buildflags();
311
322
 
312
323
# If make is using a jobserver, but it is not available
313
324
# to this process, clean out MAKEFLAGS. This avoids
316
327
        clean_jobserver_makeflags();
317
328
}
318
329
 
 
330
# Process the sequence parameter.
 
331
my $sequence;
 
332
if (! compat(7)) {
 
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)";
 
337
        }
 
338
}
 
339
else {
 
340
        # Before v8, the sequence could be at any position in the parameters,
 
341
        # so was what was left after parsing.
 
342
        $sequence=shift;
 
343
        if (defined $sequence) {
 
344
                @ARGV_orig=grep { $_ ne $sequence } @ARGV_orig;
 
345
        }
 
346
}
 
347
if (! defined $sequence) {
 
348
        error "specify a sequence to run";
 
349
}
 
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) {
 
358
        exit 0;
 
359
}
 
360
 
 
361
 
319
362
# Definitions of sequences.
320
363
my %sequences;
321
 
$sequences{build} = [qw{
 
364
my @bd_minimal = qw{
 
365
        dh_testdir
 
366
};
 
367
my @bd = qw{
322
368
        dh_testdir
323
369
        dh_auto_configure
324
370
        dh_auto_build
325
371
        dh_auto_test
326
 
}],
327
 
$sequences{'build-indep'} = [@{$sequences{build}}];
328
 
$sequences{'build-arch'} = [@{$sequences{build}}];
329
 
$sequences{clean} = [qw{
330
 
        dh_testdir
331
 
        dh_auto_clean
332
 
        dh_clean
333
 
}];
 
372
};
 
373
my @i_minimal = qw{
 
374
        dh_testroot
 
375
};
334
376
my @i = qw{
335
377
        dh_testroot
336
378
        dh_prep
373
415
        dh_compress
374
416
        dh_fixperms
375
417
};
376
 
$sequences{'install'} = [@{$sequences{build}}, @i];
377
 
$sequences{'install-indep'} = [@{$sequences{'build-indep'}}, @i];
378
 
$sequences{'install-arch'} = [@{$sequences{'build-arch'}}, @i];
379
418
my @ba=qw{
380
419
        dh_strip
381
420
        dh_makeshlibs
387
426
        dh_md5sums
388
427
        dh_builddeb
389
428
};
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{
 
430
        dh_testdir
 
431
        dh_auto_clean
 
432
        dh_clean
 
433
}];
 
434
$sequences{'build-indep'} = [@bd];
 
435
$sequences{'build-arch'} = [@bd];
 
436
if (! compat(8)) {
 
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")];
 
442
        }
 
443
        else {
 
444
                # run standard sequence (this is faster)
 
445
                $sequences{build} = [@bd];
 
446
        }
 
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")];
 
453
        }
 
454
        else {
 
455
                # run standard sequence (this is faster)
 
456
                $sequences{'install'} = [rules("build"), @i, rules("install-arch"), rules("install-indep")];
 
457
        }
 
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")];
 
461
}
 
462
else {
 
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];
 
470
}
393
471
 
394
472
# Additional command options
395
473
my %command_opts;
478
556
        exit 0;
479
557
}
480
558
 
 
559
# Load addons, which can modify sequences.
481
560
foreach my $addon (@{$dh{WITH}}) {
482
561
        my $mod="Debian::Debhelper::Sequence::$addon";
483
562
        $mod=~s/-/_/g;
487
566
        }
488
567
}
489
568
 
490
 
my $sequence;
491
 
if (! compat(7)) {
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)";
496
 
        }
497
 
}
498
 
else {
499
 
        # Before v8, the sequence could be at any position in the parameters,
500
 
        # so was what was left after parsing.
501
 
        $sequence=shift;
502
 
        if (defined $sequence) {
503
 
                @ARGV_orig=grep { $_ ne $sequence } @ARGV_orig;
504
 
        }
505
 
}
506
 
if (! defined $sequence) {
507
 
        error "specify a sequence to run";
508
 
}
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.
513
 
        exit 0;
514
 
}
515
 
elsif (! exists $sequences{$sequence}) {
 
569
if (! exists $sequences{$sequence}) {
516
570
        error "Unknown sequence $sequence (choose from: ".
517
571
                join(" ", sort keys %sequences).")";
518
572
}
519
 
my @sequence=@{$sequences{$sequence}};
 
573
my @sequence=optimize_sequence(@{$sequences{$sequence}});
520
574
 
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) {
 
699
 
 
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
 
704
                # commands.
 
705
                $override_command=$command;
 
706
                delete $ENV{DH_INTERNAL_OPTIONS};
 
707
                delete $ENV{DH_INTERNAL_OVERRIDE};
 
708
                $command="debian/rules";
 
709
                @options=$rules_target;
 
710
        }
 
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) {
701
767
        }
702
768
}
703
769
 
 
770
sub optimize_sequence {
 
771
        my @sequence;
 
772
        my %seen;
 
773
        my $add=sub {
 
774
                # commands can appear multiple times when sequences are
 
775
                # inlined together; only the first should be needed
 
776
                my $command=shift;
 
777
                if (! $seen{$command}) {
 
778
                        $seen{$command}=1;
 
779
                        push @sequence, $command;
 
780
                }
 
781
        };
 
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}});
 
788
                }
 
789
                else {
 
790
                        $add->($command);
 
791
                }
 
792
        }
 
793
        return @sequence;
 
794
}
 
795
 
 
796
sub rules_target {
 
797
        my $command=shift;
 
798
        if ($command =~ /^debian\/rules\s+(.*)/) {
 
799
                return $1
 
800
        }
 
801
        else {
 
802
                return undef;
 
803
        }
 
804
}
 
805
 
 
806
sub rules {
 
807
        return "debian/rules ".join(" ", @_);
 
808
}
 
809
 
704
810
{
705
811
my %targets;
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 |");
720
826
                while (<MAKE>) {
721
827
                        if ($processing_targets) {
722
828
                                if (/^# Not a target:/) {