| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
$description = "Test proper handling of SHELL."; |
| 4 |
|
| 5 |
# If we don't have a POSIX shell available, never mind |
| 6 |
$is_posix_sh or return -1; |
| 7 |
|
| 8 |
# On Windows, shell names might not match |
| 9 |
if ($port_type eq 'W32') { |
| 10 |
return -1; |
| 11 |
} |
| 12 |
|
| 13 |
$mshell = $sh_name; |
| 14 |
|
| 15 |
# According to POSIX, the value of SHELL in the environment has no impact on |
| 16 |
# the value in the makefile. |
| 17 |
|
| 18 |
$ENV{SHELL} = '/dev/null'; |
| 19 |
run_make_test('all:;@echo "$(SHELL)"', '', $mshell); |
| 20 |
|
| 21 |
# According to POSIX, any value of SHELL set in the makefile should not be |
| 22 |
# exported to the subshell. A more portable option might be to set SHELL to |
| 23 |
# be $^X (perl) in the makefile, and set .SHELLFLAGS to -e. |
| 24 |
|
| 25 |
$ENV{SHELL} = $mshell; |
| 26 |
|
| 27 |
my $altshell = "/./$mshell"; |
| 28 |
my $altshell2 = "/././$mshell"; |
| 29 |
|
| 30 |
if ($mshell =~ m,^([a-zA-Z]:)([\\/])(.*),) { |
| 31 |
$altshell = "$1$2.$2$3"; |
| 32 |
$altshell2 = "$1$2.$2.$2$3"; |
| 33 |
} |
| 34 |
|
| 35 |
run_make_test("SHELL := $altshell\n".' |
| 36 |
all:;@echo "$(SHELL) $$SHELL" |
| 37 |
', '', "$altshell $mshell"); |
| 38 |
|
| 39 |
# As a GNU Make extension, if make's SHELL variable is explicitly exported, |
| 40 |
# then we really _DO_ export it. |
| 41 |
|
| 42 |
$ENV{SHELL} = $mshell; |
| 43 |
|
| 44 |
run_make_test("export SHELL := $altshell\n".' |
| 45 |
all:;@echo "$(SHELL) $$SHELL" |
| 46 |
', '', "$altshell $altshell"); |
| 47 |
|
| 48 |
|
| 49 |
# Test out setting of SHELL, both exported and not, as a target-specific |
| 50 |
# variable. |
| 51 |
|
| 52 |
$ENV{SHELL} = $mshell; |
| 53 |
|
| 54 |
run_make_test("all: SHELL := $altshell\n".' |
| 55 |
all:;@echo "$(SHELL) $$SHELL" |
| 56 |
', '', "$altshell $mshell"); |
| 57 |
|
| 58 |
$ENV{SHELL} = $mshell; |
| 59 |
|
| 60 |
run_make_test(" |
| 61 |
SHELL := $altshell2 |
| 62 |
one: two |
| 63 |
two: export SHELL := $altshell\n".' |
| 64 |
one two:;@echo "$@: $(SHELL) $$SHELL" |
| 65 |
', '', "two: $altshell $altshell\none: $altshell2 $mshell\n"); |
| 66 |
|
| 67 |
# Test .SHELLFLAGS |
| 68 |
|
| 69 |
# We don't know the output here: on some systems, for example, every line |
| 70 |
# printed by the shell in -x mode has a trailing space! |
| 71 |
my $script = 'true; true'; |
| 72 |
my $flags = '-xc'; |
| 73 |
my $out = `$sh_name $flags '$script' 2>&1`; |
| 74 |
|
| 75 |
run_make_test(qq! |
| 76 |
.SHELLFLAGS = $flags |
| 77 |
all: ; \@$script |
| 78 |
!, |
| 79 |
'', $out); |
| 80 |
|
| 81 |
# Do it again but add spaces to SHELLFLAGS |
| 82 |
|
| 83 |
# Some shells (*shakes fist at Solaris*) cannot handle multiple flags in |
| 84 |
# separate arguments. |
| 85 |
my $t = `$sh_name -e -c true 2>/dev/null`; |
| 86 |
my $multi_ok = $? == 0; |
| 87 |
|
| 88 |
if ($multi_ok) { |
| 89 |
$flags = '-x -c'; |
| 90 |
run_make_test(qq! |
| 91 |
.SHELLFLAGS = $flags |
| 92 |
all: ; \@$script |
| 93 |
!, |
| 94 |
'', $out); |
| 95 |
} |
| 96 |
|
| 97 |
$script = subst_make_string('true; #HELPER# -q fail 1; true'); |
| 98 |
$flags = '-xec'; |
| 99 |
$out = `$sh_name $flags '$script' 2>&1`; |
| 100 |
|
| 101 |
run_make_test(qq! |
| 102 |
.SHELLFLAGS = $flags |
| 103 |
all: ; \@$script |
| 104 |
!, |
| 105 |
'', "${out}#MAKE#: *** [#MAKEFILE#:3: all] Error 1", 512); |
| 106 |
|
| 107 |
1; |