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 is_make_jobserver_unavailable
11 clean_jobserver_makeflags);
12 use base 'Debian::Debhelper::Buildsystem';
16 my $buildpath = $this->get_buildpath();
17 if ($buildpath ne '.') {
18 return $this->{makecmd} . " -C " . escape_shell($buildpath);
20 return $this->{makecmd};
23 sub exists_make_target {
24 my ($this, $target) = @_;
25 my $makecmd=$this->get_makecmd_C();
27 # Use make -n to check to see if the target would do
28 # anything. There's no good way to test if a target exists.
29 my $ret=`$makecmd -s -n --no-print-directory $target 2>/dev/null`;
37 # Avoid warnings about unavailable jobserver.
38 if (is_make_jobserver_unavailable()) {
39 clean_jobserver_makeflags();
42 if (defined $this->get_parallel()) {
43 # Note that this will override any -j settings in MAKEFLAGS.
44 unshift @_, "-j" . ($this->get_parallel() > 1 ? $this->get_parallel() : 1);
45 # Force make to start a new jobserver.
46 clean_jobserver_makeflags();
49 $this->doit_in_builddir($this->{makecmd}, @_);
52 sub make_first_existing_target {
56 foreach my $target (@$targets) {
57 if ($this->exists_make_target($target)) {
58 $this->do_make($target, @_);
71 my $this=$class->SUPER::new(@_);
72 $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
76 sub check_auto_buildable {
80 # Handles build, test, install, clean; configure - next class
81 if (grep /^\Q$step\E$/, qw{build test install clean}) {
82 # This is always called in the source directory, but generally
83 # Makefiles are created (or live) in the the build directory.
84 return -e $this->get_buildpath("Makefile") ||
85 -e $this->get_buildpath("makefile") ||
86 -e $this->get_buildpath("GNUmakefile");
98 $this->make_first_existing_target(['test', 'check'], @_);
104 $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
109 if (!$this->rmdir_builddir()) {
110 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);