package Debian::Debhelper::Buildsystem::makefile;
use strict;
-use Debian::Debhelper::Dh_Lib qw(escape_shell);
+use Debian::Debhelper::Dh_Lib qw(escape_shell clean_jobserver_makeflags);
use base 'Debian::Debhelper::Buildsystem';
-sub get_makecmd_C {
- my $this=shift;
- my $buildpath = $this->get_buildpath();
- if ($buildpath ne '.') {
- return $this->{makecmd} . " -C " . escape_shell($buildpath);
- }
- 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 --no-print-directory $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>;
+ 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 {
foreach my $target (@$targets) {
if ($this->exists_make_target($target)) {
- $this->doit_in_builddir($this->{makecmd}, $target, @_);
+ $this->do_make($target, @_);
return $target;
}
}
my $this=shift;
my ($step) = @_;
- # Handles build, test, install, clean; configure - next class
- 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 $this->get_buildpath("Makefile") ||
- -e $this->get_buildpath("makefile") ||
- -e $this->get_buildpath("GNUmakefile");
- }
- return 0;
+ # 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")) ? 1 : 0;
}
sub build {
my $this=shift;
- $this->doit_in_builddir($this->{makecmd}, @_);
+ $this->do_make(@_);
}
sub test {
}
}
-1;
+1