summaryrefslogtreecommitdiff
path: root/Debian/Debhelper/Buildsystem/makefile.pm
diff options
context:
space:
mode:
authorModestas Vainius <modestas@vainius.eu>2009-04-14 15:12:14 +0300
committerJoey Hess <joey@gnu.kitenet.net>2009-04-14 14:14:07 -0400
commit683f6060d8304d6d4e83bd76e5ac624a35b43442 (patch)
tree12a7a34240e60a52269647584c92c3349c0b2e5a /Debian/Debhelper/Buildsystem/makefile.pm
parent2b7f42f9ef70c08bb7bc138fb8b24dc993da54ac (diff)
Modular object-orientied buildsystem implementation (try 2).
Major changess: * Dh_Buildsystem_Option dropped and Dh_Buildsystem_Chdir functionality partitially merged into Dh_Buildsystem_Basic. Dh_Buildsystem_Bases.pm renamed to Dh_Buildsystem_Basic.pm to match classname. * *_impl() ditched completely. Previous {configure,build,test,install,clean}_impl() renamed to just configure(), build(), test(), install(), clean() instead. Added pre_action($action) and post_action($action) hooks instead which are called by Dh_Buildsystems::buildsystems_do(). * Builddir is handled via mkdir_builddir(), doit_in_buildddir(), clean_builddir() methods which buildsystems should call directly. Removed get_top* method, added get_rel2builddir_path(). * is_buildable() method renamed to is_auto_buildable() to reflect its purpose more. * ::perl_makefile renamed to ::perl_makemaker and which is based on ::makefile now. MakeMaker hack moved from ::makefile to ::perl_makemaker where it belongs (thanks for the tip). * Dh_Buildsystems refactored into a simple perl module rather than OO class and simplified a bit. * @BUILDSYSTEMS and is_auto_buildable() modified to 100% match historical order. TODO: user documentation (e.g. DH_AUTO_BUILDDIRECTORY and DH_AUTO_BUILDSYSTEM environment variables and common dh_auto_* options (--buildsystem and --builddirectory)). Current plugin inheritance hierarchy is like this: Buildsystem::perl_build -> Dh_Buildsystem_Basic <- Buildsystem::python_distutils ^ | Buildsystem::makefile <- Buildsystem::perl_makemaker ^ ^ ^ / | \ Buildsystem::autotools Buildsystem::cmake Buildsystem::python_distutils Signed-off-by: Modestas Vainius <modestas@vainius.eu>
Diffstat (limited to 'Debian/Debhelper/Buildsystem/makefile.pm')
-rw-r--r--Debian/Debhelper/Buildsystem/makefile.pm92
1 files changed, 48 insertions, 44 deletions
diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm
index cbd9e3c3..7ffb048e 100644
--- a/Debian/Debhelper/Buildsystem/makefile.pm
+++ b/Debian/Debhelper/Buildsystem/makefile.pm
@@ -8,30 +8,41 @@ package Debian::Debhelper::Buildsystem::makefile;
use strict;
use Debian::Debhelper::Dh_Lib;
-use Debian::Debhelper::Dh_Buildsystem_Bases;
-use base 'Debian::Debhelper::Dh_Buildsystem_Chdir';
+use base 'Debian::Debhelper::Dh_Buildsystem_Basic';
+
+# XXX JEH setting this env var is dodgy,
+# probably better to test if it exists with a default value.
+# (Factor out to helper function?)
+# XXX MDX Done. See new().
+
+sub get_makecmd_C {
+ my $self=shift;
+ if ($self->get_builddir()) {
+ return $self->{makecmd} . " -C " . $self->get_builddir();
+ }
+ return $self->{makecmd};
+}
# XXX JEH I *like* this. Yay for factoring out ugly ugly stuff!
-sub _exists_make_target {
- my ($cls, $target) = @_;
+# XXX MDX TODO: this could use dh debian/rules parser.
+sub exists_make_target {
+ my ($self, $target) = @_;
+ my $makecmd=$self->get_makecmd_C();
+
# Use make -n to check to see if the target would do
# anything. There's no good way to test if a target exists.
- my $ret=`$ENV{MAKE} -s -n $target 2>/dev/null`;
+ my $ret=`$makecmd -s -n $target 2>/dev/null`;
chomp $ret;
return length($ret);
}
-sub _make_first_existing_target {
- my $cls = shift;
- my $targets = shift;
+sub make_first_existing_target {
+ my $self=shift;
+ my $targets=shift;
- # XXX JEH setting this env var is dodgy,
- # probably better to test if it exists with a default value.
- # (Factor out to helper function?)
- $ENV{MAKE}="make" unless exists $ENV{MAKE};
foreach my $target (@$targets) {
- if ($cls->_exists_make_target($target)) {
- doit($ENV{MAKE}, $target, @_);
+ if ($self->exists_make_target($target)) {
+ $self->doit_in_builddir($self->{makecmd}, $target, @_);
return $target;
}
}
@@ -42,56 +53,49 @@ sub DESCRIPTION {
"support for building Makefile based packages (make && make install)"
}
-sub is_buildable {
+sub new {
+ my $cls=shift;
+ my $self=$cls->SUPER::new(@_);
+ $self->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make";
+ return $self;
+}
+
+sub is_auto_buildable {
my $self=shift;
my ($action) = @_;
+
+ # Handles build, test, install, clean; configure - next class
if (grep /^\Q$action\E$/, qw{build test install clean}) {
- # XXX JEH why does get_buildpath need to be used
- # here? is_buildable is run at the top of the source
- # directory, so -e 'Makefile' should be the same
+ # This is always called in the source directory, but generally
+ # Makefiles are created (or live) in the the build directory.
return -e $self->get_buildpath("Makefile") ||
-e $self->get_buildpath("makefile") ||
-e $self->get_buildpath("GNUmakefile");
- } else {
- # XXX JEH why return 1 here?
- return 1;
}
+ return 0;
}
-sub build_impl {
+sub build {
my $self=shift;
- doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @_);
+ $self->doit_in_builddir($self->{makecmd}, @_);
}
-sub test_impl {
+sub test {
my $self=shift;
- $self->_make_first_existing_target(['test', 'check'], @_);
+ $self->make_first_existing_target(['test', 'check'], @_);
}
-sub install_impl {
+sub install {
my $self=shift;
my $destdir=shift;
-
- # XXX JEH again with the setting the env var, see above..
- $ENV{MAKE}="make" unless exists $ENV{MAKE};
- my @params="DESTDIR=$destdir";
-
- # Special case for MakeMaker generated Makefiles.
- # XXX JEH This is a really unfortunate breaking of the
- # encapsulation of the perl_makefile module. Perhaps it would be
- # better for that module to contain some hack that injects that
- # test into this one?
- if (-e "Makefile" &&
- system('grep -q "generated automatically by MakeMaker" Makefile') == 0) {
- push @params, "PREFIX=/usr";
- }
-
- $self->_make_first_existing_target(['install'], @params, @_);
+ $self->make_first_existing_target(['install'], "DESTDIR=$destdir", @_);
}
-sub clean_impl {
+sub clean {
my $self=shift;
- $self->_make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
+ if (!$self->clean_builddir()) {
+ $self->make_first_existing_target(['distclean', 'realclean', 'clean'], @_);
+ }
}
1;