]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Buildsystem/makefile.pm
move obscure function to EOF
[debhelper.git] / Debian / Debhelper / Buildsystem / makefile.pm
index 3809d594705f077d3bb3f05879e396d679d9642e..f21b2cbd6971c06e634b1ea238cb643b51831c13 100644 (file)
@@ -7,7 +7,7 @@
 package Debian::Debhelper::Buildsystem::makefile;
 
 use strict;
-use Debian::Debhelper::Dh_Lib qw(escape_shell);
+use Debian::Debhelper::Dh_Lib qw(escape_shell get_make_jobserver_status);
 use base 'Debian::Debhelper::Buildsystem';
 
 sub get_makecmd_C {
@@ -30,13 +30,38 @@ sub exists_make_target {
        return length($ret);
 }
 
+sub do_make {
+       my $this=shift;
+
+       # Remove unavailable jobserver options from MAKEFLAGS.
+       # Always clean MAKEFLAGS from unavailable jobserver options. If parallel
+       # is enabled, do more extensive clean up from all job control specific
+       # options
+       my ($status, $makeflags) = get_make_jobserver_status();
+       if ($status eq "jobserver-unavailable" || defined $this->get_parallel()) {
+               if (defined $makeflags) {
+                       $ENV{MAKEFLAGS} = $makeflags;
+               }
+               else {
+                       delete $ENV{MAKEFLAGS} if exists $ENV{MAKEFLAGS};
+               }
+       }
+
+       # Start a new jobserver if parallel building was requested
+       if (defined $this->get_parallel()) {
+               unshift @_, "-j" . ($this->get_parallel() > 1 ? $this->get_parallel() : 1);
+       }
+
+       $this->doit_in_builddir($this->{makecmd}, @_);
+}
+
 sub make_first_existing_target {
        my $this=shift;
        my $targets=shift;
 
        foreach my $target (@$targets) {
                if ($this->exists_make_target($target)) {
-                       $this->doit_in_builddir($this->{makecmd}, $target, @_);
+                       $this->do_make($target, @_);
                        return $target;
                }
        }
@@ -71,7 +96,7 @@ sub check_auto_buildable {
 
 sub build {
        my $this=shift;
-       $this->doit_in_builddir($this->{makecmd}, @_);
+       $this->do_make(@_);
 }
 
 sub test {