Skip to content

Commit 072f732

Browse files
author
Salve J. Nilsen
committed
Allow the option SHEBANG=relocatable
1 parent 59d0a95 commit 072f732

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
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: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ sub constants {
415415
PERLRUNINST FULLPERLRUNINST ABSPERLRUNINST
416416
PERL_CORE
417417
PERM_DIR PERM_RW PERM_RWX
418+
SHEBANG
418419
419420
) )
420421
{
@@ -1174,8 +1175,9 @@ WARNING
11741175
11751176
Inserts the sharpbang or equivalent magic number to a set of @files.
11761177
1177-
If the environment variable C<PERL_MM_FORCE_SHEBANG=relocatable> is set,
1178-
then any found shebang/sharpbang lines are set to C<#!/usr/bin/env perl>.
1178+
If the WriteMakefile option C<SHEBANG> is set to "relocatable", then any found
1179+
shebang/sharpbang lines are set to C<#!/usr/bin/env perl> instead of the
1180+
default perl.
11791181
11801182
=cut
11811183

@@ -1251,8 +1253,17 @@ sub _fixin_replace_shebang {
12511253

12521254
# Now look (in reverse) for interpreter in absolute PATH (unless perl).
12531255
my $interpreter;
1254-
if ( defined $ENV{PERL_MM_FORCE_SHEBANG} && $ENV{PERL_MM_FORCE_SHEBANG} eq "relocatable" ) {
1255-
$interpreter = "/usr/bin/env perl";
1256+
if ( defined $ENV{PERL_MM_SHEBANG} ) {
1257+
if ( $ENV{PERL_MM_SHEBANG} eq "relocatable" ) {
1258+
$interpreter = "/usr/bin/env perl";
1259+
print "SHEBANG option set to 'relocatable': Changing shebang from '$cmd $arg' to '$interpreter'"
1260+
if $Verbose;
1261+
$arg = ""; # args don't work with /usr/bin/env perl
1262+
}
1263+
else {
1264+
print "SHEBANG option set to something other than 'relocatable': Ignoring it"
1265+
if $Verbose;
1266+
}
12561267
}
12571268
elsif ( $cmd =~ m{^perl(?:\z|[^a-z])} ) {
12581269
if ( $Config{startperl} =~ m,^\#!.*/perl, ) {
@@ -1863,6 +1874,8 @@ EOP
18631874

18641875
$self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
18651876

1877+
$self->{SHEBANG} ||= '';
1878+
18661879
# make a simple check if we find strict
18671880
warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
18681881
(strict.pm not found)"

lib/ExtUtils/MakeMaker.pm

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ my %Special_Sigs = (
113113
BUILD_REQUIRES => 'HASH',
114114
CONFIGURE_REQUIRES => 'HASH',
115115
TEST_REQUIRES => 'HASH',
116+
SHEBANG => '',
116117
SKIP => 'ARRAY',
117118
TYPEMAPS => 'ARRAY',
118119
XS => 'HASH',
@@ -325,6 +326,8 @@ sub full_setup {
325326
326327
MACPERL_SRC MACPERL_LIB MACLIBS_68K MACLIBS_PPC MACLIBS_SC MACLIBS_MRC
327328
MACLIBS_ALL_68K MACLIBS_ALL_PPC MACLIBS_SHARED
329+
330+
SHEBANG
328331
/;
329332
push @attrib_help, @fs_macros;
330333
@macro_fsentity{@fs_macros, @dep_macros} = (1) x (@fs_macros+@dep_macros);
@@ -2785,6 +2788,16 @@ A minimal required perl version, if present, will look like this:
27852788
27862789
perl(perl)>=5.008001
27872790
2791+
=item SHEBANG
2792+
2793+
When set to C<relocatable>, it makes C<ExtUtils::MM_Unix-E<gt>fixup()> change
2794+
any shebang lines found (e.g. C<#!/usr/local/bin/perl>) into a relocatable
2795+
version C<#!/usr/bin/env perl>. This is useful when writing tools that are
2796+
intended to work seamlessly in different environments, eg. both in containers
2797+
and with C<plenv(1)>.
2798+
2799+
If C<SHEBANG> is set to anything else than C<relocatable>, it is ignored.
2800+
27882801
=item SITEPREFIX
27892802
27902803
Like PERLPREFIX, but only for the site install locations.
@@ -3374,14 +3387,6 @@ always return the default without waiting for user input.
33743387
33753388
Same as the PERL_CORE parameter. The parameter overrides this.
33763389
3377-
=item PERL_MM_FORCE_SHEBANG
3378-
3379-
When set to C<relocatable>, it makes C<ExtUtils::MM_Unix-E<gt>fixup()> change
3380-
any shebang lines found (e.g. C<#!/usr/local/bin/perl>) into a relocatable
3381-
version C<#!/usr/bin/env perl>. This is useful when writing tools that are
3382-
intended to work seamlessly in different environments, eg. both in containers
3383-
and with C<plenv(1)>.
3384-
33853390
=back
33863391
33873392
=head1 SEE ALSO

0 commit comments

Comments
 (0)