]> 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 4f15152bd49fe0a31ff4f9100bc4f241397b81f5..f21b2cbd6971c06e634b1ea238cb643b51831c13 100644 (file)
@@ -1,4 +1,4 @@
-# A buildsystem plugin for handling simple Makefile based projects.
+# A debhelper build system class for handling simple Makefile based projects.
 #
 # Copyright: © 2008 Joey Hess
 #            © 2008-2009 Modestas Vainius
@@ -7,13 +7,14 @@
 package Debian::Debhelper::Buildsystem::makefile;
 
 use strict;
-use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Lib qw(escape_shell get_make_jobserver_status);
 use base 'Debian::Debhelper::Buildsystem';
 
 sub get_makecmd_C {
        my $this=shift;
-       if ($this->get_builddir()) {
-               return $this->{makecmd} . " -C " . $this->get_builddir();
+       my $buildpath = $this->get_buildpath();
+       if ($buildpath ne '.') {
+               return $this->{makecmd} . " -C " . escape_shell($buildpath);
        }
        return $this->{makecmd};
 }
@@ -24,18 +25,43 @@ sub exists_make_target {
 
        # Use make -n to check to see if the target would do
        # anything. There's no good way to test if a target exists.
-       my $ret=`$makecmd -s -n $target 2>/dev/null`;
+       my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`;
        chomp $ret;
        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;
                }
        }
@@ -70,7 +96,7 @@ sub check_auto_buildable {
 
 sub build {
        my $this=shift;
-       $this->doit_in_builddir($this->{makecmd}, @_);
+       $this->do_make(@_);
 }
 
 sub test {
@@ -86,9 +112,9 @@ sub install {
 
 sub clean {
        my $this=shift;
-       if (!$this->clean_builddir()) {
+       if (!$this->rmdir_builddir()) {
                $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
        }
 }
 
-1;
+1