X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=Debian%2FDebhelper%2FBuildsystem%2Fmakefile.pm;h=f21b2cbd6971c06e634b1ea238cb643b51831c13;hb=4fb1f3b2d64a2faa9d961205b1c32f83028172c8;hp=cbd9e3c38b213465a6f421b2160f61f3364c3840;hpb=2b7f42f9ef70c08bb7bc138fb8b24dc993da54ac;p=debhelper.git diff --git a/Debian/Debhelper/Buildsystem/makefile.pm b/Debian/Debhelper/Buildsystem/makefile.pm index cbd9e3c..f21b2cb 100644 --- a/Debian/Debhelper/Buildsystem/makefile.pm +++ b/Debian/Debhelper/Buildsystem/makefile.pm @@ -1,4 +1,4 @@ -# A buildsystem plugin for handling simple Makefile based projects. +# A debhelper build system class for handling simple Makefile based projects. # # Copyright: © 2008 Joey Hess # © 2008-2009 Modestas Vainius @@ -7,31 +7,61 @@ 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 Debian::Debhelper::Dh_Lib qw(escape_shell get_make_jobserver_status); +use base 'Debian::Debhelper::Buildsystem'; + +sub get_makecmd_C { + my $this=shift; + my $buildpath = $this->get_buildpath(); + if ($buildpath ne '.') { + return $this->{makecmd} . " -C " . escape_shell($buildpath); + } + return $this->{makecmd}; +} + +sub exists_make_target { + my ($this, $target) = @_; + my $makecmd=$this->get_makecmd_C(); -# XXX JEH I *like* this. Yay for factoring out ugly ugly stuff! -sub _exists_make_target { - my ($cls, $target) = @_; # 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 --no-print-directory $target 2>/dev/null`; chomp $ret; return length($ret); } -sub _make_first_existing_target { - my $cls = shift; - my $targets = shift; +sub do_make { + my $this=shift; + + # Remove unavailable jobserver options from MAKEFLAGS. + # Always clean MAKEFLAGS from unavailable jobserver options. If parallel + # is enabled, do more extensive clean up from all job control specific + # options + my ($status, $makeflags) = get_make_jobserver_status(); + if ($status eq "jobserver-unavailable" || defined $this->get_parallel()) { + if (defined $makeflags) { + $ENV{MAKEFLAGS} = $makeflags; + } + else { + delete $ENV{MAKEFLAGS} if exists $ENV{MAKEFLAGS}; + } + } + + # Start a new jobserver if parallel building was requested + if (defined $this->get_parallel()) { + unshift @_, "-j" . ($this->get_parallel() > 1 ? $this->get_parallel() : 1); + } + + $this->doit_in_builddir($this->{makecmd}, @_); +} + +sub make_first_existing_target { + my $this=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 ($this->exists_make_target($target)) { + $this->do_make($target, @_); return $target; } } @@ -39,59 +69,52 @@ sub _make_first_existing_target { } sub DESCRIPTION { - "support for building Makefile based packages (make && make install)" + "simple Makefile" +} + +sub new { + my $class=shift; + my $this=$class->SUPER::new(@_); + $this->{makecmd} = (exists $ENV{MAKE}) ? $ENV{MAKE} : "make"; + return $this; } -sub is_buildable { - my $self=shift; - my ($action) = @_; - 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 - 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; +sub check_auto_buildable { + my $this=shift; + my ($step) = @_; + + # Handles build, test, install, clean; configure - next class + if (grep /^\Q$step\E$/, qw{build test install clean}) { + # This is always called in the source directory, but generally + # Makefiles are created (or live) in the the build directory. + return -e $this->get_buildpath("Makefile") || + -e $this->get_buildpath("makefile") || + -e $this->get_buildpath("GNUmakefile"); } + return 0; } -sub build_impl { - my $self=shift; - doit(exists $ENV{MAKE} ? $ENV{MAKE} : "make", @_); +sub build { + my $this=shift; + $this->do_make(@_); } -sub test_impl { - my $self=shift; - $self->_make_first_existing_target(['test', 'check'], @_); +sub test { + my $this=shift; + $this->make_first_existing_target(['test', 'check'], @_); } -sub install_impl { - my $self=shift; +sub install { + my $this=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, @_); + $this->make_first_existing_target(['install'], "DESTDIR=$destdir", @_); } -sub clean_impl { - my $self=shift; - $self->_make_first_existing_target(['distclean', 'realclean', 'clean'], @_); +sub clean { + my $this=shift; + if (!$this->rmdir_builddir()) { + $this->make_first_existing_target(['distclean', 'realclean', 'clean'], @_); + } } -1; +1