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
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 # Remove unavailable jobserver options from MAKEFLAGS.
38 # Always clean MAKEFLAGS from unavailable jobserver options. If parallel
39 # is enabled, do more extensive clean up from all job control specific
41 if (defined $this->get_parallel() || is_make_jobserver_unavailable()) {
45 # Start a new jobserver if parallel building was requested
46 if (defined $this->get_parallel()) {
47 unshift @_, "-j" . ($this->get_parallel() > 1 ? $this->get_parallel() : 1);
50 $this->doit_in_builddir($this->{makecmd}, @_);
53 sub make_first_existing_target {
57 foreach my $target (@$targets) {
58 if ($this->exists_make_target($target)) {
59 $this->do_make($target, @_);
72 my $this=$class->SUPER::new(@_);
73 $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
77 sub check_auto_buildable {
81 # Handles build, test, install, clean; configure - next class
82 if (grep /^\Q$step\E$/, qw{build test install clean}) {
83 # This is always called in the source directory, but generally
84 # Makefiles are created (or live) in the the build directory.
85 return -e $this->get_buildpath("Makefile") ||
86 -e $this->get_buildpath("makefile") ||
87 -e $this->get_buildpath("GNUmakefile");
99 $this->make_first_existing_target(['test', 'check'], @_);
105 $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
110 if (!$this->rmdir_builddir()) {
111 $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);