2004-11-28 23:11:23 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
|
|
|
|
$description = "Test proper handling of SHELL.";
|
|
|
|
|
|
|
|
# Find the default value when SHELL is not set. On UNIX it will be /bin/sh,
|
|
|
|
# but on other platforms who knows?
|
2005-07-12 04:35:13 +00:00
|
|
|
resetENV();
|
2004-11-28 23:11:23 +00:00
|
|
|
delete $ENV{SHELL};
|
2005-07-04 03:50:59 +00:00
|
|
|
$mshell = `echo 'all:;\@echo \$(SHELL)' | $make_path -f-`;
|
2004-11-28 23:11:23 +00:00
|
|
|
chop $mshell;
|
|
|
|
|
|
|
|
# According to POSIX, the value of SHELL in the environment has no impact on
|
|
|
|
# the value in the makefile.
|
2005-07-12 04:35:13 +00:00
|
|
|
# Note %extraENV takes precedence over the default value for the shell.
|
2004-11-28 23:11:23 +00:00
|
|
|
|
2005-07-12 04:35:13 +00:00
|
|
|
$extraENV{SHELL} = '/dev/null';
|
2004-11-28 23:11:23 +00:00
|
|
|
run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
|
|
|
|
|
|
|
|
# According to POSIX, any value of SHELL set in the makefile should _NOT_ be
|
|
|
|
# exported to the subshell! I wanted to set SHELL to be $^X (perl) in the
|
|
|
|
# makefile, but make runs $(SHELL) -c 'commandline' and that doesn't work at
|
2005-08-25 04:40:10 +00:00
|
|
|
# all when $(SHELL) is perl :-/. So, we just add an extra initial /./ which
|
|
|
|
# works well on UNIX and seems to work OK on at least some non-UNIX systems.
|
2004-11-28 23:11:23 +00:00
|
|
|
|
2005-07-12 04:35:13 +00:00
|
|
|
$extraENV{SHELL} = $mshell;
|
2004-11-28 23:11:23 +00:00
|
|
|
|
2005-08-25 04:40:10 +00:00
|
|
|
run_make_test("SHELL := /./$mshell\n".'
|
2004-11-28 23:11:23 +00:00
|
|
|
all:;@echo "$(SHELL) $$SHELL"
|
2005-08-25 04:40:10 +00:00
|
|
|
', '', "/./$mshell $mshell");
|
2004-11-28 23:11:23 +00:00
|
|
|
|
|
|
|
# As a GNU make extension, if make's SHELL variable is explicitly exported,
|
|
|
|
# then we really _DO_ export it.
|
|
|
|
|
2005-07-12 04:35:13 +00:00
|
|
|
$extraENV{SHELL} = $mshell;
|
|
|
|
|
2005-08-25 04:40:10 +00:00
|
|
|
run_make_test("export SHELL := /./$mshell\n".'
|
2004-11-28 23:11:23 +00:00
|
|
|
all:;@echo "$(SHELL) $$SHELL"
|
2005-08-25 04:40:10 +00:00
|
|
|
', '', "/./$mshell /./$mshell");
|
2004-11-28 23:11:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Test out setting of SHELL, both exported and not, as a target-specific
|
|
|
|
# variable.
|
|
|
|
|
2005-07-12 04:35:13 +00:00
|
|
|
$extraENV{SHELL} = $mshell;
|
|
|
|
|
2005-08-25 04:40:10 +00:00
|
|
|
run_make_test("all: SHELL := /./$mshell\n".'
|
2004-11-28 23:11:23 +00:00
|
|
|
all:;@echo "$(SHELL) $$SHELL"
|
2005-08-25 04:40:10 +00:00
|
|
|
', '', "/./$mshell $mshell");
|
2004-11-28 23:11:23 +00:00
|
|
|
|
2005-07-12 04:35:13 +00:00
|
|
|
$extraENV{SHELL} = $mshell;
|
|
|
|
|
2009-06-06 23:16:46 +00:00
|
|
|
run_make_test("
|
|
|
|
SHELL := /././$mshell
|
|
|
|
one: two
|
|
|
|
two: export SHELL := /./$mshell\n".'
|
|
|
|
one two:;@echo "$@: $(SHELL) $$SHELL"
|
|
|
|
', '', "two: /./$mshell /./$mshell\none: /././$mshell $mshell\n");
|
2004-11-28 23:11:23 +00:00
|
|
|
|
2010-07-06 06:37:42 +00:00
|
|
|
# Test .SHELLFLAGS
|
|
|
|
|
2010-07-28 05:39:50 +00:00
|
|
|
# We don't know the output here: on Solaris for example, every line printed
|
2010-07-19 07:10:53 +00:00
|
|
|
# by the shell in -x mode has a trailing space (!!)
|
2010-07-28 05:39:50 +00:00
|
|
|
my $script = 'true; true';
|
|
|
|
my $flags = '-xc';
|
|
|
|
my $out = `/bin/sh $flags '$script' 2>&1`;
|
2010-07-19 07:10:53 +00:00
|
|
|
|
2012-03-03 22:56:20 +00:00
|
|
|
run_make_test(qq!
|
|
|
|
.SHELLFLAGS = $flags
|
|
|
|
all: ; \@$script
|
|
|
|
!,
|
|
|
|
'', $out);
|
|
|
|
|
|
|
|
# Do it again but add spaces to SHELLFLAGS
|
2013-09-29 17:31:32 +00:00
|
|
|
|
|
|
|
# Some shells (*shakes fist at Solaris*) cannot handle multiple flags in
|
|
|
|
# separate arguments.
|
|
|
|
my $t = `/bin/sh -e -c true 2>/dev/null`;
|
|
|
|
my $multi_ok = $? == 0;
|
|
|
|
|
|
|
|
if ($multi_ok) {
|
|
|
|
$flags = '-x -c';
|
|
|
|
run_make_test(qq!
|
2010-07-28 05:39:50 +00:00
|
|
|
.SHELLFLAGS = $flags
|
2010-07-19 07:10:53 +00:00
|
|
|
all: ; \@$script
|
2010-07-06 06:37:42 +00:00
|
|
|
!,
|
2010-07-19 07:10:53 +00:00
|
|
|
'', $out);
|
2013-09-29 17:31:32 +00:00
|
|
|
}
|
2010-07-19 07:10:53 +00:00
|
|
|
|
|
|
|
# We can't just use "false" because on different systems it provides a
|
2010-07-28 05:39:50 +00:00
|
|
|
# different exit code--once again Solaris: false exits with 255 not 1
|
|
|
|
$script = 'true; false; true';
|
|
|
|
$flags = '-xec';
|
|
|
|
$out = `/bin/sh $flags '$script' 2>&1`;
|
|
|
|
my $err = $? >> 8;
|
2010-07-06 06:37:42 +00:00
|
|
|
|
2010-07-19 07:10:53 +00:00
|
|
|
run_make_test(qq!
|
2010-07-28 05:39:50 +00:00
|
|
|
.SHELLFLAGS = $flags
|
2010-07-19 07:10:53 +00:00
|
|
|
all: ; \@$script
|
2010-07-06 06:37:42 +00:00
|
|
|
!,
|
2016-03-19 21:24:00 +00:00
|
|
|
'', "$out#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512);
|
2010-07-06 06:37:42 +00:00
|
|
|
|
2004-11-28 23:11:23 +00:00
|
|
|
1;
|