| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
use warnings; |
| 4 |
|
| 5 |
my $description = "Test that make can execute binaries as well as scripts with" |
| 6 |
." various shabangs and without a shebang"; |
| 7 |
my $details = "The various shells that this test uses are the default" |
| 8 |
." /bin/sh, \$SHELL and the perl interpreter that is" |
| 9 |
." executing this test program. The shells are used for the value" |
| 10 |
." of SHELL inside the test makefile and also as a shebang in the" |
| 11 |
." executed script. There is also a test which executes a script" |
| 12 |
." that has no shebang."; |
| 13 |
|
| 14 |
# Only bother with this on UNIX systems |
| 15 |
$port_type eq 'UNIX' or return -1; |
| 16 |
|
| 17 |
my $usersh = $origENV{SHELL}; |
| 18 |
my $answer = 'hello, world'; |
| 19 |
|
| 20 |
my @shebangs = ('', '#!/bin/sh', "#!$usersh", "#!$perl_name"); |
| 21 |
my @shells = ('', 'SHELL=/bin/sh', "SHELL=$usersh"); |
| 22 |
|
| 23 |
# tests [0-11] |
| 24 |
# Have a makefile with various SHELL= exec a shell program with varios |
| 25 |
# shebangs or without a shebang at all. |
| 26 |
my $stem = './exec.cmd'; |
| 27 |
my $k = 0; |
| 28 |
for my $shebang (@shebangs) { |
| 29 |
for my $shell (@shells) { |
| 30 |
my $cmd = $k ? "$stem.$k" : $stem; |
| 31 |
++$k; |
| 32 |
unlink $cmd; |
| 33 |
open(CMD,"> $cmd"); |
| 34 |
print CMD "$shebang\n"; |
| 35 |
print CMD "printf \"$answer\\n\";\n"; |
| 36 |
close(CMD); |
| 37 |
chmod 0700, $cmd; |
| 38 |
|
| 39 |
run_make_test(q! |
| 40 |
all:; @$(CMD) |
| 41 |
!, "$shell CMD=$cmd", "$answer\n"); |
| 42 |
|
| 43 |
rmfiles($cmd); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
# tests [12-14] |
| 48 |
# Exec a binary from a makefile that has SHELL=. |
| 49 |
for my $shell (@shells) { |
| 50 |
run_make_test(q! |
| 51 |
all:; @#PERL# -e 'printf "$(ANSWER)\n"'; |
| 52 |
!, "$shell ANSWER='$answer'", "$answer\n"); |
| 53 |
} |
| 54 |
|
| 55 |
# test 15 |
| 56 |
# Use perl as a shell. |
| 57 |
run_make_test(q! |
| 58 |
SHELL = #PERL# |
| 59 |
.SHELLFLAGS = -e |
| 60 |
all:; @printf "$(ANSWER)\n"; |
| 61 |
!, "ANSWER='$answer'", "$answer\n"); |
| 62 |
|
| 63 |
1; |