Skip to content

Commit

Permalink
Enhancement: New SHEBANG=relocatable MM option
Browse files Browse the repository at this point in the history
- Adds the option to force a relocatable shebang by setting the
  "SHEBANG=relocatable" MM option.
- Document SHEBANG=relocatable
  • Loading branch information
Salve J. Nilsen committed Aug 9, 2018
1 parent 4546fa6 commit 587a8f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ExtUtils/MM_Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 16 additions & 2 deletions lib/ExtUtils/MM_Unix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ sub constants {
PERL_CORE
PERM_DIR PERM_RW PERM_RWX
SHEBANG
) )
{
next unless defined $self->{$macro};
Expand Down Expand Up @@ -1187,6 +1188,10 @@ WARNING
Inserts the sharpbang or equivalent magic number to a set of @files.
If the WriteMakefile option C<SHEBANG> 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
Expand Down Expand Up @@ -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, ) {
Expand Down
12 changes: 12 additions & 0 deletions lib/ExtUtils/MakeMaker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<relocatable>, it makes C<ExtUtils::MM_Unix-E<gt>fixup()> 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<plenv(1)>.
If C<SHEBANG> is set to anything else than C<relocatable>, it is ignored.
=item SITEPREFIX
Like PERLPREFIX, but only for the site install locations.
Expand Down

0 comments on commit 587a8f2

Please sign in to comment.