]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Buildsystem/makefile.pm
split get_make_jobserver_status into two functions
[debhelper.git] / Debian / Debhelper / Buildsystem / makefile.pm
index 286f0f650433e4e896e88f21d94a83872f9e9562..159f7c1e43f56139bcdd582743270ba1611c7571 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,43 +7,56 @@
 package Debian::Debhelper::Buildsystem::makefile;
 
 use strict;
-use Debian::Debhelper::Dh_Lib;
-use base 'Debian::Debhelper::Dh_Buildsystem_Basic';
+use Debian::Debhelper::Dh_Lib qw(escape_shell is_make_jobserver_unavailable
+       clean_makeflags);
+use base 'Debian::Debhelper::Buildsystem';
 
 sub get_makecmd_C {
-       my $self=shift;
-       if ($self->get_builddir()) {
-               return $self->{makecmd} . " -C " . $self->get_builddir();
+       my $this=shift;
+       my $buildpath = $this->get_buildpath();
+       if ($buildpath ne '.') {
+               return $this->{makecmd} . " -C " . escape_shell($buildpath);
        }
-       return $self->{makecmd};
+       return $this->{makecmd};
 }
 
-# XXX JEH I *like* this. Yay for factoring out ugly ugly stuff!
-# XXX MDX TODO: this could use dh debian/rules parser.
-# XXX JEH That one checks for explicit only targets, while we want
-#         implicit targets here too. I think the current code is ok;
-#         it's a bonus that it checks if the target it empty.
-#         Hmm, one problem is that if a target exists but will run no
-#         commands since it's already built, the approach below will return
-#         nothing and assume it doesn't exist.
 sub exists_make_target {
-       my ($self, $target) = @_;
-       my $makecmd=$self->get_makecmd_C();
+       my ($this, $target) = @_;
+       my $makecmd=$this->get_makecmd_C();
 
        # 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
+       if (defined $this->get_parallel() || is_make_jobserver_unavailable()) {
+               clean_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 $self=shift;
+       my $this=shift;
        my $targets=shift;
 
        foreach my $target (@$targets) {
-               if ($self->exists_make_target($target)) {
-                       $self->doit_in_builddir($self->{makecmd}, $target, @_);
+               if ($this->exists_make_target($target)) {
+                       $this->do_make($target, @_);
                        return $target;
                }
        }
@@ -51,53 +64,52 @@ sub make_first_existing_target {
 }
 
 sub DESCRIPTION {
-       "support for building Makefile based packages (make && make install)"
+       "simple Makefile"
 }
 
 sub new {
-       my $cls=shift;
-       my $self=$cls->SUPER::new(@_);
-       $self->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
-       return $self;
+       my $class=shift;
+       my $this=$class->SUPER::new(@_);
+       $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
+       return $this;
 }
 
-sub is_auto_buildable {
-       my $self=shift;
-       my ($action) = @_;
+sub check_auto_buildable {
+       my $this=shift;
+       my ($step) = @_;
 
        # Handles build, test, install, clean; configure - next class
-       # XXX JEH shouldn't it also handle configure, just as a no-op?
-       if (grep /^\Q$action\E$/, qw{build test install clean}) {
+       if (grep /^\Q$step\E$/, qw{build test install clean}) {
                # This is always called in the source directory, but generally
                # Makefiles are created (or live) in the the build directory.
-               return -e $self->get_buildpath("Makefile") ||
-                      -e $self->get_buildpath("makefile") ||
-                      -e $self->get_buildpath("GNUmakefile");
+               return -e $this->get_buildpath("Makefile") ||
+                      -e $this->get_buildpath("makefile") ||
+                      -e $this->get_buildpath("GNUmakefile");
        }
        return 0;
 }
 
 sub build {
-       my $self=shift;
-       $self->doit_in_builddir($self->{makecmd}, @_);
+       my $this=shift;
+       $this->do_make(@_);
 }
 
 sub test {
-       my $self=shift;
-       $self->make_first_existing_target(['test', 'check'], @_);
+       my $this=shift;
+       $this->make_first_existing_target(['test', 'check'], @_);
 }
 
 sub install {
-       my $self=shift;
+       my $this=shift;
        my $destdir=shift;
-       $self->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
+       $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
 }
 
 sub clean {
-       my $self=shift;
-       if (!$self->clean_builddir()) {
-               $self->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
+       my $this=shift;
+       if (!$this->rmdir_builddir()) {
+               $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
        }
 }
 
-1;
+1