From 8b0bd69272cedefb77501b74bd4ad851c389eea9 Mon Sep 17 00:00:00 2001 From: "Philipp A. Hartmann" Date: Tue, 28 Aug 2012 18:49:00 +0200 Subject: [PATCH] Makefile.PL: add custom build parameters 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 Reviewed-by: Torsten Maehne --- Makefile.PL | 42 +++++++++++++++++++++++++++++++++++++++--- pristine-tar | 3 +++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 23175a9..97bab60 100755 --- a/Makefile.PL +++ b/Makefile.PL @@ -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 ', 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' }, ); diff --git a/pristine-tar b/pristine-tar index c670d2d..bf60aab 100755 --- a/pristine-tar +++ b/pristine-tar @@ -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"; -- 2.34.1