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);
27 open(STDERR, ">&SAVEDERR");
28 return defined $output && length $output;
34 # Avoid possible warnings about unavailable jobserver,
35 # and force make to start a new jobserver.
36 clean_jobserver_makeflags();
38 # Note that this will override any -j settings in MAKEFLAGS.
39 unshift @_, "-j" . ($this->get_parallel() > 0 ? $this->get_parallel() : "");
41 $this->doit_in_builddir($this->{makecmd}, @_);
44 sub make_first_existing_target {
48 foreach my $target (@$targets) {
49 if ($this->exists_make_target($target)) {
50 $this->do_make($target, @_);
63 my $this=$class->SUPER::new(@_);
64 $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
68 sub check_auto_buildable {
72 if (-e $this->get_buildpath("Makefile") ||
73 -e $this->get_buildpath("makefile") ||
74 -e $this->get_buildpath("GNUmakefile"))
76 # This is always called in the source directory, but generally
77 # Makefiles are created (or live) in the the build directory.
79 } elsif ($step eq "clean" && defined $this->get_builddir() &&
80 $this->check_auto_buildable("configure"))
82 # Assume that the package can be cleaned (i.e. the build directory can
83 # be removed) as long as it is built out-of-source tree and can be
84 # configured. This is useful for derivative buildsystems which
98 $this->make_first_existing_target(['test', 'check'], @_);
104 $this->make_first_existing_target(['install'],
106 "AM_UPDATE_INFO_DIR=no", @_);
111 if (!$this->rmdir_builddir()) {
112 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);