Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MM option "SHEBANG=relocatable" #326

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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