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 # XXX JEH I *like* this. Yay for factoring out ugly ugly stuff!
15 sub _exists_make_target {
16 my ($cls, $target) = @_;
17 # Use make -n to check to see if the target would do
18 # anything. There's no good way to test if a target exists.
19 my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`;
24 sub _make_first_existing_target {
28 # XXX JEH setting this env var is dodgy,
29 # probably better to test if it exists with a default value.
30 # (Factor out to helper function?)
31 $ENV{MAKE}="make" unless exists $ENV{MAKE};
32 foreach my $target (@$targets) {
33 if ($cls->_exists_make_target($target)) {
34 doit($ENV{MAKE}, $target, @_);
42 "support for building Makefile based packages (make && make install)"
48 if (grep /^\Q$action\E$/, qw{build test install clean}) {
49 # XXX JEH why does get_buildpath need to be used
50 # here? is_buildable is run at the top of the source
51 # directory, so -e 'Makefile' should be the same
52 return -e $self->get_buildpath("Makefile") ||
53 -e $self->get_buildpath("makefile") ||
54 -e $self->get_buildpath("GNUmakefile");
56 # XXX JEH why return 1 here?
63 doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @_);
68 $self->_make_first_existing_target(['test', 'check'], @_);
75 # XXX JEH again with the setting the env var, see above..
76 $ENV{MAKE}="make" unless exists $ENV{MAKE};
77 my @params="DESTDIR=$destdir";
79 # Special case for MakeMaker generated Makefiles.
80 # XXX JEH This is a really unfortunate breaking of the
81 # encapsulation of the perl_makefile module. Perhaps it would be
82 # better for that module to contain some hack that injects that
85 system('grep -q "generated automatically by MakeMaker" Makefile') == 0) {
86 push @params, "PREFIX=/usr";
89 $self->_make_first_existing_target(['install'], @params, @_);
94 $self->_make_first_existing_target(['distclean', 'realclean', 'clean'], @_);