2005-06-27 01:01:07 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
|
|
|
|
$description = 'Test the $(shell ...) function.';
|
|
|
|
|
|
|
|
$details = '';
|
|
|
|
|
2015-07-13 01:03:24 +00:00
|
|
|
# Test standard shell
|
|
|
|
run_make_test('.PHONY: all
|
|
|
|
OUT := $(shell echo hi)
|
|
|
|
all: ; @echo $(OUT)
|
|
|
|
','','hi');
|
2005-06-27 01:01:07 +00:00
|
|
|
|
|
|
|
# Test shells inside rules.
|
|
|
|
run_make_test('.PHONY: all
|
|
|
|
all: ; @echo $(shell echo hi)
|
2015-07-13 01:03:24 +00:00
|
|
|
','','hi');
|
|
|
|
|
|
|
|
# Verify .SHELLSTATUS
|
|
|
|
run_make_test('.PHONY: all
|
|
|
|
PRE := $(.SHELLSTATUS)
|
|
|
|
$(shell exit 0)
|
|
|
|
OK := $(.SHELLSTATUS)
|
|
|
|
$(shell exit 1)
|
|
|
|
BAD := $(.SHELLSTATUS)
|
|
|
|
all: ; @echo PRE=$(PRE) OK=$(OK) BAD=$(BAD)
|
|
|
|
','','PRE= OK=0 BAD=1');
|
2005-06-27 01:01:07 +00:00
|
|
|
|
2009-09-28 23:08:49 +00:00
|
|
|
# Test unescaped comment characters in shells. Savannah bug #20513
|
2016-12-22 23:47:26 +00:00
|
|
|
run_make_test(q!
|
2009-09-28 23:08:49 +00:00
|
|
|
FOO := $(shell echo '#')
|
|
|
|
foo: ; echo '$(FOO)'
|
|
|
|
!,
|
2016-12-22 23:47:26 +00:00
|
|
|
'', "echo '#'\n#\n");
|
2009-09-28 23:08:49 +00:00
|
|
|
|
2022-06-19 00:25:30 +00:00
|
|
|
# Test that exported variables are passed to $(shell ...)
|
|
|
|
$ENV{FOO} = 'baz';
|
|
|
|
run_make_test(q!
|
|
|
|
OUT = $(shell echo $$FOO)
|
|
|
|
foo: ; @echo '$(OUT)'
|
|
|
|
!,
|
|
|
|
'', 'baz');
|
|
|
|
|
|
|
|
$ENV{FOO} = 'baz';
|
|
|
|
run_make_test(q!
|
|
|
|
FOO = bar
|
|
|
|
OUT = $(shell echo $$FOO)
|
|
|
|
foo: ; @echo '$(OUT)'
|
|
|
|
!,
|
|
|
|
'', 'bar');
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
export FOO = bar
|
|
|
|
OUT = $(shell echo $$FOO)
|
|
|
|
foo: ; @echo '$(OUT)'
|
|
|
|
!,
|
|
|
|
'', 'bar');
|
|
|
|
|
|
|
|
# Test shells inside exported environment variables, simply expanded.
|
|
|
|
run_make_test('
|
|
|
|
export HI := $(shell echo hi)
|
|
|
|
.PHONY: all
|
|
|
|
all: ; @echo $$HI
|
|
|
|
',
|
|
|
|
'','hi');
|
|
|
|
|
|
|
|
# Test shells inside exported environment variables. See SV 10593
|
2005-06-27 01:01:07 +00:00
|
|
|
run_make_test('
|
|
|
|
export HI = $(shell echo hi)
|
|
|
|
.PHONY: all
|
|
|
|
all: ; @echo $$HI
|
2022-06-19 00:25:30 +00:00
|
|
|
',
|
|
|
|
'',"hi");
|
|
|
|
|
|
|
|
$ENV{HI} = 'foo';
|
|
|
|
run_make_test('
|
|
|
|
HI = $(shell echo hi)
|
|
|
|
.PHONY: all
|
|
|
|
all: ; @echo $$HI
|
|
|
|
',
|
|
|
|
'',"hi");
|
|
|
|
|
|
|
|
$ENV{HI} = 'foo';
|
|
|
|
run_make_test('
|
|
|
|
HI = $(shell echo hi)
|
|
|
|
bad := $(HI)
|
|
|
|
.PHONY: all
|
|
|
|
all: ; @echo $$HI $(bad)
|
|
|
|
',
|
|
|
|
'',"hi hi");
|
2005-06-27 01:01:07 +00:00
|
|
|
|
2017-04-17 19:37:57 +00:00
|
|
|
if ($port_type ne 'W32') {
|
2018-07-01 20:13:13 +00:00
|
|
|
# Test shell errors in recipes including offset
|
|
|
|
# This needs to be ported to Windows, or else Windows error messages
|
|
|
|
# need to converted to look like more normal make errors.
|
2017-04-17 19:37:57 +00:00
|
|
|
run_make_test('
|
2022-02-06 21:22:40 +00:00
|
|
|
.RECIPEPREFIX = >
|
2016-04-10 21:12:48 +00:00
|
|
|
all:
|
2022-02-06 21:22:40 +00:00
|
|
|
>@echo hi
|
|
|
|
>$(shell ./basdfdfsed there)
|
|
|
|
>@echo $(.SHELLSTATUS)
|
2016-04-10 21:12:48 +00:00
|
|
|
',
|
2018-08-04 16:20:11 +00:00
|
|
|
'', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\nhi\n127\n");
|
|
|
|
|
|
|
|
run_make_test('
|
|
|
|
$(shell ./basdfdfsed where)
|
|
|
|
all: ; @echo $(.SHELLSTATUS)
|
|
|
|
',
|
|
|
|
'', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\n127\n");
|
2018-07-01 20:13:13 +00:00
|
|
|
|
|
|
|
# Test SHELLSTATUS for kill.
|
|
|
|
# This test could be ported to Windows, using taskkill ... ?
|
2019-09-21 18:01:19 +00:00
|
|
|
|
|
|
|
# Figure out the exit code for SIGINT
|
|
|
|
my $pid = fork();
|
|
|
|
if (! $pid) {
|
|
|
|
exec('kill -2 $$') or die "exec: Cannot execute sleep\n";
|
|
|
|
}
|
|
|
|
waitpid($pid, 0);
|
|
|
|
# .SHELLSTATUS for a signal gives 128 + the signal number
|
2019-10-08 22:28:10 +00:00
|
|
|
my $ret = $?;
|
|
|
|
if ($ret > 255) {
|
|
|
|
# Solaris 10 perl 5.8.4 puts signal number + 128 into the high 8 bits.
|
|
|
|
$ret >>= 8;
|
|
|
|
}
|
|
|
|
$ret |= 128;
|
2019-09-21 18:01:19 +00:00
|
|
|
|
2018-07-01 20:13:13 +00:00
|
|
|
run_make_test('.PHONY: all
|
|
|
|
$(shell kill -2 $$$$)
|
2019-09-21 18:01:19 +00:00
|
|
|
STAT := $(.SHELLSTATUS)
|
|
|
|
all: ; @echo STAT=$(STAT)
|
|
|
|
','',"STAT=$ret\n");
|
2022-02-06 21:22:40 +00:00
|
|
|
|
|
|
|
# Test that not-found errors can be redirected
|
|
|
|
if ($ERR_command_not_found) {
|
|
|
|
$_ = $ERR_command_not_found;
|
|
|
|
s/#CMDNAME#/bad-command/g;
|
|
|
|
run_make_test(q!
|
|
|
|
out := $(shell bad-command 2>&1)
|
|
|
|
all: ; @echo '$(.SHELLSTATUS): $(out)'
|
|
|
|
!,
|
|
|
|
'', "127: $_\n");
|
|
|
|
}
|
2017-04-17 19:37:57 +00:00
|
|
|
}
|
2016-04-10 21:12:48 +00:00
|
|
|
|
2005-06-27 01:01:07 +00:00
|
|
|
1;
|