Makefile.PL: add custom build parameters
authorPhilipp A. Hartmann <philipp.hartmann@offis.de>
Tue, 28 Aug 2012 16:49:00 +0000 (18:49 +0200)
committerPhilipp A. Hartmann <philipp.hartmann@offis.de>
Tue, 28 Aug 2012 16:49:00 +0000 (18:49 +0200)
This patch introduces three custom build parameters

 * PERL_SHEBANG
     Configure the #! line in the installed perl scripts.
     May be needed on some passwords, in case MakeMaker
     does not get the installation right
 * TAR_PROGRAM, XDELTA_PROGRAM
     Set a custom name (or location) for the required (GNU) tar and
     xdelta programs, in case they are not callable through their
     default names from the $PATH

If set, the variables are used to munge the corresponding parts of
the scripts.  The $tar_program and $xdelta_program variables in
pristine-tar are now marked as such.

The patch itself extends the "macro" section of the MakeMaker generated
Makefile.  To call the inherited function, the package needs to be set
explicitly.

This patch is an updated version, incorporating a spacing fix when
using multiple replacements, as discovered by Torsten Maehne during
his review.

Signed-off-by: Philipp A. Hartmann <philipp.hartmann@offis.de>
Reviewed-by: Torsten Maehne <Torsten.Maehne@gmx.de>
Makefile.PL
pristine-tar

index 23175a9065f2d3995adb453d550ff345b8ad1d16..97bab604ddc92f155f7ea3c83d500fd28662acc2 100755 (executable)
@@ -3,14 +3,44 @@ use warnings;
 use strict;
 use ExtUtils::MakeMaker;
 
+# read custom parameters
+my %args = map { split /\s*=\s*/ } @ARGV;
+my $PERL_SHEBANG   = $args{PERL_SHEBANG} || "" ;
+my $TAR_PROGRAM    = $args{TAR_PROGRAM} || "" ;
+my $XDELTA_PROGRAM = $args{XDELTA_PROGRAM} || "" ;
+
+package MY;
+
+sub macro {
+    my $inherited = shift->SUPER::macro(@_);
+    my $subst = '';
+
+    $subst .= q[-e "s|^\#!.*|\#!$(PERL_SHEBANG)|g" ]
+        unless ! ${PERL_SHEBANG};
+    $subst .= q[-e "s|tar_program = \".*\";|tar_program = \"$(TAR_PROGRAM)\";|g" ]
+        unless ! ${TAR_PROGRAM};
+    $subst .= q[-e "s|xdelta_program = \".*\";|xdelta_program = \"$(XDELTA_PROGRAM)\";|g" ]
+        unless ! ${XDELTA_PROGRAM};
+
+    $inherited .= "\nPARAM_SUBST = ${subst}";
+    $inherited;
+}
 # Add a few more targets.
-sub MY::postamble {
+sub postamble {
 q{
 all:: extra_build
 clean:: extra_clean
 install:: extra_install
 pure_install:: extra_install
 
+ifneq (,$(PARAM_SUBST))
+$(EXE_FILES): %:
+       sed $(PARAM_SUBST) $@ > $@.new
+       $(MV) $@.new $@
+       $(CHMOD) $(PERM_RWX) $@
+PHONY+=$(EXE_FILES)
+endif
+
 ZGZ_LIB=$(PREFIX)/lib/zgz
 
 extra_build: zgz/zgz pristine-tar.spec
@@ -40,12 +70,13 @@ extra_clean:
 pristine-tar.spec: debian/changelog
        sed "s/Version:.*/Version: $$($(PERLRUN) -e '$$_=<>;print m/\((.*?)\)/'<$<)/" \
                $@ > $@.new && $(MV) $@.new $@
+PHONY+=pristine-tar.spec
 
-.PHONY: pristine-tar.spec
+.PHONY: $(PHONY)
 }
 }
 
-WriteMakefile(
+ExtUtils::MakeMaker::WriteMakefile(
        NAME            => 'Pristine',
        AUTHOR          => 'Joey Hess <joey@kitenet.net>',
        ABSTRACT        =>
@@ -55,5 +86,10 @@ WriteMakefile(
        MAN3PODS        => {},
        PMLIBDIRS       => ["Pristine"],
        EXE_FILES       => ["pristine-tar","pristine-bz2","pristine-gz","pristine-xz"],
+       macro           => {
+               PERL_SHEBANG   => "${PERL_SHEBANG}",
+               TAR_PROGRAM    => "${TAR_PROGRAM}",
+               XDELTA_PROGRAM => "${XDELTA_PROGRAM}"
+       },
        clean           => { FILES => 'zgz/zgz' },
 );
index c670d2d096e754af274b92daa5644898f248e5dc..bf60aab586b3fe77820e7ad09b92c781aeb806f6 100755 (executable)
@@ -189,6 +189,9 @@ $ENV{LANG}='C';
 delete $ENV{TAR_OPTIONS};
 delete $ENV{TAPE};
 
+# The following two assignments are potentially munged during the
+# build process to hold the values of TAR_PROGRAM and XDELTA_PROGRAM
+# parameters as given to Makefile.PL.
 my $tar_program = "tar";
 my $xdelta_program = "xdelta";