diff --git a/lib/ExtUtils/MM_Any.pm b/lib/ExtUtils/MM_Any.pm index ba4be5637..45b8b540d 100644 --- a/lib/ExtUtils/MM_Any.pm +++ b/lib/ExtUtils/MM_Any.pm @@ -2373,7 +2373,7 @@ CODE $self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]); $self->{WARN_IF_OLD_PACKLIST} ||= $self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]); - $self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]); + $self->{FIXIN} ||= $self->oneliner('$ENV{PERL_MM_SHEBANG} ||= "$(SHEBANG)"; MY->fixin(shift)', ["-MExtUtils::MY"]); $self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]); $self->{UNINST} ||= 0; diff --git a/lib/ExtUtils/MM_Unix.pm b/lib/ExtUtils/MM_Unix.pm index 972a8fe6d..535775d1a 100644 --- a/lib/ExtUtils/MM_Unix.pm +++ b/lib/ExtUtils/MM_Unix.pm @@ -429,6 +429,7 @@ sub constants { PERL_CORE PERM_DIR PERM_RW PERM_RWX + SHEBANG ) ) { next unless defined $self->{$macro}; @@ -1187,6 +1188,10 @@ WARNING Inserts the sharpbang or equivalent magic number to a set of @files. +If the WriteMakefile option C is set to "relocatable", then any found +shebang/sharpbang lines are set to C<#!/usr/bin/env perl> instead of the +default perl. + =cut sub fixin { # stolen from the pink Camel book, more or less @@ -1261,8 +1266,17 @@ sub _fixin_replace_shebang { # Now look (in reverse) for interpreter in absolute PATH (unless perl). my $interpreter; - if ( defined $ENV{PERL_MM_SHEBANG} && $ENV{PERL_MM_SHEBANG} eq "relocatable" ) { - $interpreter = "/usr/bin/env perl"; + if ( defined $ENV{PERL_MM_SHEBANG} ) { + if ( $ENV{PERL_MM_SHEBANG} eq "relocatable" ) { + $interpreter = "/usr/bin/env perl"; + print "SHEBANG option set to 'relocatable': Changing shebang from '$cmd $arg' to '$interpreter'" + if $Verbose; + $arg = ""; # args don't work with /usr/bin/env perl + } + else { + print "SHEBANG option set to something other than 'relocatable': Ignoring it" + if $Verbose; + } } elsif ( $cmd =~ m{^perl(?:\z|[^a-z])} ) { if ( $Config{startperl} =~ m,^\#!.*/perl, ) { diff --git a/lib/ExtUtils/MakeMaker.pm b/lib/ExtUtils/MakeMaker.pm index 6ee69ec0b..771026ddb 100644 --- a/lib/ExtUtils/MakeMaker.pm +++ b/lib/ExtUtils/MakeMaker.pm @@ -325,6 +325,8 @@ sub full_setup { MACPERL_SRC MACPERL_LIB MACLIBS_68K MACLIBS_PPC MACLIBS_SC MACLIBS_MRC MACLIBS_ALL_68K MACLIBS_ALL_PPC MACLIBS_SHARED + + SHEBANG /; push @attrib_help, @fs_macros; @macro_fsentity{@fs_macros, @dep_macros} = (1) x (@fs_macros+@dep_macros); @@ -2785,6 +2787,16 @@ A minimal required perl version, if present, will look like this: perl(perl)>=5.008001 +=item SHEBANG + +When set to C, it makes Cfixup()> change +any shebang lines found (e.g. C<#!/usr/local/bin/perl>) into a relocatable +version C<#!/usr/bin/env perl>. This is useful when writing tools that are +intended to work seamlessly in different environments, eg. both in containers +and with C. + +If C is set to anything else than C, it is ignored. + =item SITEPREFIX Like PERLPREFIX, but only for the site install locations.