1 # A debhelper build system class for handling simple Makefile based projects.
3 # Copyright: © 2008 Joey Hess
4 # © 2008-2009 Modestas Vainius
7 package Debian::Debhelper::Buildsystem::makefile;
10 use Debian::Debhelper::Dh_Lib qw(escape_shell clean_jobserver_makeflags);
11 use base 'Debian::Debhelper::Buildsystem';
13 sub exists_make_target {
14 my ($this, $target) = @_;
16 # Use make -n to check to see if the target would do
17 # anything. There's no good way to test if a target exists.
18 my @opts=("-s", "-n", "--no-print-directory");
19 my $buildpath = $this->get_buildpath();
20 unshift @opts, "-C", $buildpath if $buildpath ne ".";
21 open(SAVEDERR, ">&STDERR");
22 open(STDERR, ">/dev/null");
23 open(MAKE, "-|", $this->{makecmd}, @opts, $target);
26 open(STDERR, ">&SAVEDERR");
27 return defined $output && length $output;
33 # Avoid possible warnings about unavailable jobserver,
34 # and force make to start a new jobserver.
35 clean_jobserver_makeflags();
37 # Note that this will override any -j settings in MAKEFLAGS.
38 unshift @_, "-j" . ($this->get_parallel() > 0 ? $this->get_parallel() : "");
40 $this->doit_in_builddir($this->{makecmd}, @_);
43 sub make_first_existing_target {
47 foreach my $target (@$targets) {
48 if ($this->exists_make_target($target)) {
49 $this->do_make($target, @_);
62 my $this=$class->SUPER::new(@_);
63 $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
67 sub check_auto_buildable {
71 # This is always called in the source directory, but generally
72 # Makefiles are created (or live) in the the build directory.
73 return (-e $this->get_buildpath("Makefile") ||
74 -e $this->get_buildpath("makefile") ||
75 -e $this->get_buildpath("GNUmakefile")) ? 1 : 0;
85 $this->make_first_existing_target(['test', 'check'], @_);
91 $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
96 if (!$this->rmdir_builddir()) {
97 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);