Skip to content

Commit 587a8f2

Browse files
author
Salve J. Nilsen
committed
Enhancement: New SHEBANG=relocatable MM option
- Adds the option to force a relocatable shebang by setting the "SHEBANG=relocatable" MM option. - Document SHEBANG=relocatable
1 parent 4546fa6 commit 587a8f2

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

lib/ExtUtils/MM_Any.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2373,7 +2373,7 @@ CODE
23732373
$self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]);
23742374
$self->{WARN_IF_OLD_PACKLIST} ||=
23752375
$self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]);
2376-
$self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]);
2376+
$self->{FIXIN} ||= $self->oneliner('$ENV{PERL_MM_SHEBANG} ||= "$(SHEBANG)"; MY->fixin(shift)', ["-MExtUtils::MY"]);
23772377
$self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]);
23782378

23792379
$self->{UNINST} ||= 0;

lib/ExtUtils/MM_Unix.pm

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ sub constants {
429429
PERL_CORE
430430
PERM_DIR PERM_RW PERM_RWX
431431
432+
SHEBANG
432433
) )
433434
{
434435
next unless defined $self->{$macro};
@@ -1187,6 +1188,10 @@ WARNING
11871188
11881189
Inserts the sharpbang or equivalent magic number to a set of @files.
11891190
1191+
If the WriteMakefile option C<SHEBANG> is set to "relocatable", then any found
1192+
shebang/sharpbang lines are set to C<#!/usr/bin/env perl> instead of the
1193+
default perl.
1194+
11901195
=cut
11911196

11921197
sub fixin { # stolen from the pink Camel book, more or less
@@ -1261,8 +1266,17 @@ sub _fixin_replace_shebang {
12611266

12621267
# Now look (in reverse) for interpreter in absolute PATH (unless perl).
12631268
my $interpreter;
1264-
if ( defined $ENV{PERL_MM_SHEBANG} && $ENV{PERL_MM_SHEBANG} eq "relocatable" ) {
1265-
$interpreter = "/usr/bin/env perl";
1269+
if ( defined $ENV{PERL_MM_SHEBANG} ) {
1270+
if ( $ENV{PERL_MM_SHEBANG} eq "relocatable" ) {
1271+
$interpreter = "/usr/bin/env perl";
1272+
print "SHEBANG option set to 'relocatable': Changing shebang from '$cmd $arg' to '$interpreter'"
1273+
if $Verbose;
1274+
$arg = ""; # args don't work with /usr/bin/env perl
1275+
}
1276+
else {
1277+
print "SHEBANG option set to something other than 'relocatable': Ignoring it"
1278+
if $Verbose;
1279+
}
12661280
}
12671281
elsif ( $cmd =~ m{^perl(?:\z|[^a-z])} ) {
12681282
if ( $Config{startperl} =~ m,^\#!.*/perl, ) {

lib/ExtUtils/MakeMaker.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ sub full_setup {
325325
326326
MACPERL_SRC MACPERL_LIB MACLIBS_68K MACLIBS_PPC MACLIBS_SC MACLIBS_MRC
327327
MACLIBS_ALL_68K MACLIBS_ALL_PPC MACLIBS_SHARED
328+
329+
SHEBANG
328330
/;
329331
push @attrib_help, @fs_macros;
330332
@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:
27852787
27862788
perl(perl)>=5.008001
27872789
2790+
=item SHEBANG
2791+
2792+
When set to C<relocatable>, it makes C<ExtUtils::MM_Unix-E<gt>fixup()> change
2793+
any shebang lines found (e.g. C<#!/usr/local/bin/perl>) into a relocatable
2794+
version C<#!/usr/bin/env perl>. This is useful when writing tools that are
2795+
intended to work seamlessly in different environments, eg. both in containers
2796+
and with C<plenv(1)>.
2797+
2798+
If C<SHEBANG> is set to anything else than C<relocatable>, it is ignored.
2799+
27882800
=item SITEPREFIX
27892801
27902802
Like PERLPREFIX, but only for the site install locations.

0 commit comments

Comments
 (0)