]> git.donarmstrong.com Git - debhelper.git/blobdiff - Debian/Debhelper/Buildsystem/makefile.pm
debhelper: Fix minor source comment typos.
[debhelper.git] / Debian / Debhelper / Buildsystem / makefile.pm
index 244ef30d7c062ff95385e6b65780b0438ccc1b04..c63b58eda934c6017ec2d0689e71f89983c78073 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,26 +7,38 @@
 package Debian::Debhelper::Buildsystem::makefile;
 
 use strict;
-use Debian::Debhelper::Dh_Lib;
+use Debian::Debhelper::Dh_Lib qw(escape_shell clean_jobserver_makeflags);
 use base 'Debian::Debhelper::Buildsystem';
 
-sub get_makecmd_C {
-       my $this=shift;
-       if ($this->get_builddir()) {
-               return $this->{makecmd} . " -C " . $this->get_builddir();
-       }
-       return $this->{makecmd};
-}
-
 sub exists_make_target {
        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`;
-       chomp $ret;
-       return length($ret);
+       my @opts=("-s", "-n", "--no-print-directory");
+       my $buildpath = $this->get_buildpath();
+       unshift @opts, "-C", $buildpath if $buildpath ne ".";
+       open(SAVEDERR, ">&STDERR");
+       open(STDERR, ">/dev/null");
+       open(MAKE, "-|", $this->{makecmd}, @opts, $target);
+       my $output=<MAKE>;
+       chomp $output;
+       close MAKE;
+       open(STDERR, ">&SAVEDERR");
+       return defined $output && length $output;
+}
+
+sub do_make {
+       my $this=shift;
+
+       # Avoid possible warnings about unavailable jobserver,
+       # and force make to start a new jobserver.
+       clean_jobserver_makeflags();
+
+       # Note that this will override any -j settings in MAKEFLAGS.
+       unshift @_, "-j" . ($this->get_parallel() > 0 ? $this->get_parallel() : "");
+
+       $this->doit_in_builddir($this->{makecmd}, @_);
 }
 
 sub make_first_existing_target {
@@ -35,7 +47,7 @@ sub make_first_existing_target {
 
        foreach my $target (@$targets) {
                if ($this->exists_make_target($target)) {
-                       $this->doit_in_builddir($this->{makecmd}, $target, @_);
+                       $this->do_make($target, @_);
                        return $target;
                }
        }
@@ -55,22 +67,30 @@ sub new {
 
 sub check_auto_buildable {
        my $this=shift;
-       my ($action) = @_;
+       my ($step) = @_;
 
-       # Handles build, test, install, clean; configure - next class
-       if (grep /^\Q$action\E$/, qw{build test install clean}) {
+       if (-e $this->get_buildpath("Makefile") ||
+           -e $this->get_buildpath("makefile") ||
+           -e $this->get_buildpath("GNUmakefile"))
+       {
                # This is always called in the source directory, but generally
-               # Makefiles are created (or live) in the the build directory.
-               return -e $this->get_buildpath("Makefile") ||
-                      -e $this->get_buildpath("makefile") ||
-                      -e $this->get_buildpath("GNUmakefile");
+               # Makefiles are created (or live) in the build directory.
+               return 1;
+       } elsif ($step eq "clean" && defined $this->get_builddir() &&
+                $this->check_auto_buildable("configure"))
+       {
+               # Assume that the package can be cleaned (i.e. the build directory can
+               # be removed) as long as it is built out-of-source tree and can be
+               # configured. This is useful for derivative buildsystems which
+               # generate Makefiles.
+               return 1;
        }
        return 0;
 }
 
 sub build {
        my $this=shift;
-       $this->doit_in_builddir($this->{makecmd}, @_);
+       $this->do_make(@_);
 }
 
 sub test {
@@ -81,14 +101,16 @@ sub test {
 sub install {
        my $this=shift;
        my $destdir=shift;
-       $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
+       $this->make_first_existing_target(['install'],
+               "DESTDIR=$destdir",
+               "AM_UPDATE_INFO_DIR=no", @_);
 }
 
 sub clean {
        my $this=shift;
-       if (!$this->clean_builddir()) {
+       if (!$this->rmdir_builddir()) {
                $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
        }
 }
 
-1;
+1