1 # A buildsystem plugin 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;
11 use Debian::Debhelper::Dh_Buildsystem_Bases;
12 use base 'Debian::Debhelper::Dh_Buildsystem_Chdir';
14 sub _exists_make_target {
15 my ($cls, $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 $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`;
23 sub _make_first_existing_target {
27 $ENV{MAKE}="make" unless exists $ENV{MAKE};
28 foreach my $target (@$targets) {
29 if ($cls->_exists_make_target($target)) {
30 doit($ENV{MAKE}, $target, @_);
38 "support for building Makefile based packages (make && make install)"
44 if (grep /^\Q$action\E$/, qw{build test install clean}) {
45 return -e $self->get_buildpath("Makefile") ||
46 -e $self->get_buildpath("makefile") ||
47 -e $self->get_buildpath("GNUmakefile");
55 doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @_);
60 $self->_make_first_existing_target(['test', 'check'], @_);
67 $ENV{MAKE}="make" unless exists $ENV{MAKE};
68 my @params="DESTDIR=$destdir";
70 # Special case for MakeMaker generated Makefiles.
72 system('grep -q "generated automatically by MakeMaker" Makefile') == 0) {
73 push @params, "PREFIX=/usr";
76 $self->_make_first_existing_target(['install'], @params, @_);
81 $self->_make_first_existing_target(['distclean', 'realclean', 'clean'], @_);