Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / variables / SHELL
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 Solaris for example, every line printed
70 # 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 # We can't just use "false" because on different systems it provides a
98 # different exit code--once again Solaris: false exits with 255 not 1
99 $script = 'true; false; true';
100 $flags = '-xec';
101 $out = `$sh_name $flags '$script' 2>&1`;
102 my $err = $? >> 8;
103
104 run_make_test(qq!
105 .SHELLFLAGS = $flags
106 all: ; \@$script
107 !,
108               '', "$out#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512);
109
110 1;