| 1 | # -*-perl-*-
|
|---|
| 2 |
|
|---|
| 3 | $description = "Test proper handling of SHELL.";
|
|---|
| 4 |
|
|---|
| 5 | # Find the default value when SHELL is not set. On UNIX it will be /bin/sh,
|
|---|
| 6 | # but on other platforms who knows?
|
|---|
| 7 | resetENV();
|
|---|
| 8 | delete $ENV{SHELL};
|
|---|
| 9 | $mshell = `echo 'all:;\@echo \$(SHELL)' | $make_path -f-`;
|
|---|
| 10 | chop $mshell;
|
|---|
| 11 |
|
|---|
| 12 | # According to POSIX, the value of SHELL in the environment has no impact on
|
|---|
| 13 | # the value in the makefile.
|
|---|
| 14 | # Note %extraENV takes precedence over the default value for the shell.
|
|---|
| 15 |
|
|---|
| 16 | $extraENV{SHELL} = '/dev/null';
|
|---|
| 17 | run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
|
|---|
| 18 |
|
|---|
| 19 | # According to POSIX, any value of SHELL set in the makefile should _NOT_ be
|
|---|
| 20 | # exported to the subshell! I wanted to set SHELL to be $^X (perl) in the
|
|---|
| 21 | # makefile, but make runs $(SHELL) -c 'commandline' and that doesn't work at
|
|---|
| 22 | # all when $(SHELL) is perl :-/. So, we just add an extra initial /./ which
|
|---|
| 23 | # works well on UNIX and seems to work OK on at least some non-UNIX systems.
|
|---|
| 24 |
|
|---|
| 25 | $extraENV{SHELL} = $mshell;
|
|---|
| 26 |
|
|---|
| 27 | run_make_test("SHELL := /./$mshell\n".'
|
|---|
| 28 | all:;@echo "$(SHELL) $$SHELL"
|
|---|
| 29 | ', '', "/./$mshell $mshell");
|
|---|
| 30 |
|
|---|
| 31 | # As a GNU make extension, if make's SHELL variable is explicitly exported,
|
|---|
| 32 | # then we really _DO_ export it.
|
|---|
| 33 |
|
|---|
| 34 | $extraENV{SHELL} = $mshell;
|
|---|
| 35 |
|
|---|
| 36 | run_make_test("export SHELL := /./$mshell\n".'
|
|---|
| 37 | all:;@echo "$(SHELL) $$SHELL"
|
|---|
| 38 | ', '', "/./$mshell /./$mshell");
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | # Test out setting of SHELL, both exported and not, as a target-specific
|
|---|
| 42 | # variable.
|
|---|
| 43 |
|
|---|
| 44 | $extraENV{SHELL} = $mshell;
|
|---|
| 45 |
|
|---|
| 46 | run_make_test("all: SHELL := /./$mshell\n".'
|
|---|
| 47 | all:;@echo "$(SHELL) $$SHELL"
|
|---|
| 48 | ', '', "/./$mshell $mshell");
|
|---|
| 49 |
|
|---|
| 50 | $extraENV{SHELL} = $mshell;
|
|---|
| 51 |
|
|---|
| 52 | # bird: This was wrong at some point, see Savannah bug #24655. Was first fixed in kBuild.
|
|---|
| 53 | run_make_test("
|
|---|
| 54 | SHELL := /././$mshell
|
|---|
| 55 | one: two
|
|---|
| 56 | two: export SHELL := /./$mshell\n".'
|
|---|
| 57 | one two:;@echo "$@: $(SHELL) $$SHELL"
|
|---|
| 58 | ', '', "two: /./$mshell /./$mshell\none: /././$mshell $mshell\n");
|
|---|
| 59 |
|
|---|
| 60 | # Test .SHELLFLAGS
|
|---|
| 61 |
|
|---|
| 62 | # We don't know the output here: on Solaris for example, every line printed
|
|---|
| 63 | # by the shell in -x mode has a trailing space (!!)
|
|---|
| 64 | my $script = 'true; true';
|
|---|
| 65 | my $flags = '-xc';
|
|---|
| 66 | my $out = `/bin/sh $flags '$script' 2>&1`;
|
|---|
| 67 |
|
|---|
| 68 | run_make_test(qq!
|
|---|
| 69 | .SHELLFLAGS = $flags
|
|---|
| 70 | all: ; \@$script
|
|---|
| 71 | !,
|
|---|
| 72 | '', $out);
|
|---|
| 73 |
|
|---|
| 74 | # Do it again but add spaces to SHELLFLAGS
|
|---|
| 75 |
|
|---|
| 76 | # Some shells (*shakes fist at Solaris*) cannot handle multiple flags in
|
|---|
| 77 | # separate arguments.
|
|---|
| 78 | my $t = `/bin/sh -e -c true 2>/dev/null`;
|
|---|
| 79 | my $multi_ok = $? == 0;
|
|---|
| 80 |
|
|---|
| 81 | if ($multi_ok) {
|
|---|
| 82 | $flags = '-x -c';
|
|---|
| 83 | run_make_test(qq!
|
|---|
| 84 | .SHELLFLAGS = $flags
|
|---|
| 85 | all: ; \@$script
|
|---|
| 86 | !,
|
|---|
| 87 | '', $out);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | # We can't just use "false" because on different systems it provides a
|
|---|
| 91 | # different exit code--once again Solaris: false exits with 255 not 1
|
|---|
| 92 | $script = 'true; false; true';
|
|---|
| 93 | $flags = '-xec';
|
|---|
| 94 | $out = `/bin/sh $flags '$script' 2>&1`;
|
|---|
| 95 | my $err = $? >> 8;
|
|---|
| 96 |
|
|---|
| 97 | run_make_test(qq!
|
|---|
| 98 | .SHELLFLAGS = $flags
|
|---|
| 99 | all: ; \@$script
|
|---|
| 100 | !,
|
|---|
| 101 | '', "$out#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512);
|
|---|
| 102 |
|
|---|
| 103 | 1;
|
|---|