2005-02-27 21:40:23 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
$description = "Test second expansion in ordinary rules.";
|
|
|
|
|
|
|
|
$details = "";
|
|
|
|
|
2005-10-24 13:01:39 +00:00
|
|
|
# TEST #0: Test handing of '$' in prerequisites with and without second
|
|
|
|
# expansion.
|
|
|
|
|
2013-09-21 22:10:08 +00:00
|
|
|
# If we don't support archives then the prerequisite is different
|
|
|
|
my $prereq = exists $FEATURES{'archives'} ? '$' : '$(PRE)';
|
|
|
|
|
2005-10-24 13:01:39 +00:00
|
|
|
run_make_test(q!
|
|
|
|
ifdef SE
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
endif
|
|
|
|
foo$$bar: bar$$baz bar$$biz ; @echo '$@ : $^'
|
|
|
|
PRE = one two
|
|
|
|
bar$$baz: $$(PRE)
|
|
|
|
baraz: $$(PRE)
|
|
|
|
PRE = three four
|
|
|
|
.DEFAULT: ; @echo '$@'
|
|
|
|
!,
|
|
|
|
'',
|
2013-09-21 22:10:08 +00:00
|
|
|
"$prereq\nbar\$biz\nfoo\$bar : bar\$baz bar\$biz");
|
2005-10-24 13:01:39 +00:00
|
|
|
|
|
|
|
run_make_test(undef, 'SE=1', "three\nfour\nbariz\nfoo\$bar : baraz bariz");
|
|
|
|
|
|
|
|
# TEST #1: automatic variables.
|
2005-02-27 21:40:23 +00:00
|
|
|
#
|
2009-09-24 02:41:44 +00:00
|
|
|
run_make_test(q!
|
2005-10-24 13:01:39 +00:00
|
|
|
.SECONDEXPANSION:
|
2009-09-24 02:41:44 +00:00
|
|
|
.DEFAULT: ; @echo '$@'
|
2005-02-27 21:40:23 +00:00
|
|
|
|
|
|
|
foo: bar baz
|
|
|
|
|
|
|
|
foo: biz | buz
|
|
|
|
|
|
|
|
foo: $$@.1 \
|
|
|
|
$$<.2 \
|
|
|
|
$$(addsuffix .3,$$^) \
|
|
|
|
$$(addsuffix .4,$$+) \
|
|
|
|
$$|.5 \
|
|
|
|
$$*.6
|
|
|
|
|
2009-09-24 02:41:44 +00:00
|
|
|
!,
|
2005-02-27 21:40:23 +00:00
|
|
|
'',
|
|
|
|
'bar
|
|
|
|
baz
|
|
|
|
biz
|
|
|
|
buz
|
|
|
|
foo.1
|
|
|
|
bar.2
|
|
|
|
bar.3
|
|
|
|
baz.3
|
|
|
|
biz.3
|
|
|
|
bar.4
|
|
|
|
baz.4
|
|
|
|
biz.4
|
|
|
|
buz.5
|
|
|
|
.6
|
|
|
|
');
|
|
|
|
|
|
|
|
|
|
|
|
# Test #2: target/pattern -specific variables.
|
|
|
|
#
|
2009-09-24 02:41:44 +00:00
|
|
|
run_make_test(q!
|
2005-10-24 13:01:39 +00:00
|
|
|
.SECONDEXPANSION:
|
2009-09-24 02:41:44 +00:00
|
|
|
.DEFAULT: ; @echo '$@'
|
2005-02-27 21:40:23 +00:00
|
|
|
|
|
|
|
foo.x: $$a $$b
|
|
|
|
|
|
|
|
foo.x: a := bar
|
|
|
|
|
|
|
|
%.x: b := baz
|
2009-09-24 02:41:44 +00:00
|
|
|
!,
|
2005-02-27 21:40:23 +00:00
|
|
|
'',
|
|
|
|
'bar
|
|
|
|
baz
|
|
|
|
');
|
|
|
|
|
|
|
|
|
|
|
|
# Test #3: order of prerequisites.
|
|
|
|
#
|
2009-09-24 02:41:44 +00:00
|
|
|
run_make_test(q!
|
2005-10-24 13:01:39 +00:00
|
|
|
.SECONDEXPANSION:
|
2009-09-24 02:41:44 +00:00
|
|
|
.DEFAULT: ; @echo '$@'
|
2005-02-27 21:40:23 +00:00
|
|
|
|
|
|
|
all: foo bar baz
|
|
|
|
|
|
|
|
# Subtest #1
|
|
|
|
foo: foo.1; @:
|
|
|
|
foo: foo.2
|
|
|
|
foo: foo.3
|
|
|
|
|
|
|
|
# Subtest #2
|
|
|
|
bar: bar.2
|
|
|
|
bar: bar.1; @:
|
|
|
|
bar: bar.3
|
|
|
|
|
|
|
|
# Subtest #3
|
|
|
|
baz: baz.1
|
|
|
|
baz: baz.2
|
|
|
|
baz: ; @:
|
2009-09-24 02:41:44 +00:00
|
|
|
!,
|
2005-02-27 21:40:23 +00:00
|
|
|
'',
|
|
|
|
'foo.1
|
|
|
|
foo.2
|
|
|
|
foo.3
|
|
|
|
bar.1
|
|
|
|
bar.2
|
|
|
|
bar.3
|
|
|
|
baz.1
|
|
|
|
baz.2
|
|
|
|
');
|
|
|
|
|
2009-06-04 06:30:27 +00:00
|
|
|
# TEST #4: eval in a context where there is no reading_file
|
2009-09-24 02:41:44 +00:00
|
|
|
run_make_test(q!
|
2009-06-04 06:30:27 +00:00
|
|
|
.SECONDEXPANSION:
|
|
|
|
all : $$(eval $$(info test))
|
2009-09-24 02:41:44 +00:00
|
|
|
!,
|
2012-03-04 00:24:20 +00:00
|
|
|
'', "test\n#MAKE#: Nothing to be done for 'all'.\n");
|
2009-06-04 06:30:27 +00:00
|
|
|
|
2009-06-07 18:16:15 +00:00
|
|
|
# TEST #5: (NEGATIVE) catch eval in a prereq list trying to create new
|
|
|
|
# target/prereq relationships.
|
|
|
|
|
2009-09-24 02:41:44 +00:00
|
|
|
run_make_test(q!
|
2009-06-07 18:16:15 +00:00
|
|
|
.SECONDEXPANSION:
|
|
|
|
proj1.exe : proj1.o $$(eval $$(test))
|
|
|
|
define test
|
|
|
|
proj1.o : proj1.c
|
|
|
|
proj1.c: proj1.h
|
|
|
|
endef
|
2009-09-24 02:41:44 +00:00
|
|
|
!,
|
2009-06-07 18:16:15 +00:00
|
|
|
'', "#MAKE#: *** prerequisites cannot be defined in recipes. Stop.\n", 512);
|
2009-06-04 06:30:27 +00:00
|
|
|
|
2009-09-28 23:08:49 +00:00
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
# Automatic $$+ variable expansion issue. Savannah bug #25780
|
|
|
|
run_make_test(q!
|
2009-09-28 23:08:49 +00:00
|
|
|
all : foo foo
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all : $$+ ; @echo '$+'
|
|
|
|
foo : ;
|
|
|
|
!,
|
|
|
|
'', "foo foo foo foo\n");
|
|
|
|
|
|
|
|
|
2009-10-06 12:36:29 +00:00
|
|
|
# Automatic $$+ variable expansion issue. Savannah bug #25780
|
|
|
|
run_make_test(q!
|
2009-09-28 23:08:49 +00:00
|
|
|
all : bar bar
|
|
|
|
bar : ;
|
|
|
|
q%x : ;
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
a%l: q1x $$+ q2x ; @echo '$+'
|
|
|
|
!,
|
|
|
|
'', "q1x bar bar q2x bar bar\n");
|
|
|
|
|
|
|
|
|
2012-03-04 16:53:50 +00:00
|
|
|
# Allow patsubst shorthand in second expansion context.
|
|
|
|
# Requires the colon to be quoted. Savannah bug #16545
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: foo.bar
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
foo: $$(@\\:%=%.bar); @echo '$^'
|
|
|
|
!,
|
|
|
|
'', "foo.bar\n");
|
|
|
|
|
2019-05-19 14:59:06 +00:00
|
|
|
# SV 54549 : Ensure we don't free used variable_sets
|
|
|
|
run_make_test(q!
|
|
|
|
foo: -lcat
|
|
|
|
|
|
|
|
# Removing second expansion prevents segfault
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
foo: $$@.o ;
|
|
|
|
|
|
|
|
# Having an empty command here prevents segfault unless,
|
|
|
|
# the environment is empty. `env -i make foo`
|
|
|
|
# MFLAGS=-w or MAKEFLAGS=-w `env MFLAGS=-w make foo`
|
|
|
|
# libcat.a target calls an extra command, `@true \n @touch $@`
|
|
|
|
# odd.
|
|
|
|
%.o: ; @true
|
|
|
|
|
|
|
|
# Having an empty command prevents segfault.
|
|
|
|
-l%: lib%.a ; @true
|
|
|
|
|
|
|
|
# Not creating libcat.a here prevents segfault,
|
|
|
|
libcat.a: ; @touch $@
|
|
|
|
!,
|
|
|
|
'', q!#MAKEFILE#:16: Recipe was specified for file '-lcat' at #MAKEFILE#:19,
|
|
|
|
#MAKEFILE#:16: but '-lcat' is now considered the same file as 'libcat.a'.
|
|
|
|
#MAKEFILE#:16: Recipe for 'libcat.a' will be ignored in favor of the one for '-lcat'.!);
|
|
|
|
unlink('libcat.a');
|
|
|
|
|
2019-07-12 01:08:38 +00:00
|
|
|
# SV 28456 : Don't reset $$< for default recipes
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
|
|
|
|
.PHONY: biz baz
|
|
|
|
biz: baz ;
|
|
|
|
biz: $$(info $$<)
|
|
|
|
!,
|
|
|
|
'', "baz\n#MAKE#: Nothing to be done for 'biz'.\n");
|
|
|
|
|
2021-05-29 23:03:07 +00:00
|
|
|
|
|
|
|
# sv 60659. Second expansion of automatic variables inside a function in the
|
|
|
|
# prerequisite list.
|
|
|
|
# $$@ expands to the target in the 1st and following rules.
|
|
|
|
# $$<,$$^,$$+,$$|,$$?,$$*,$$% expand to the empty string in the prerequisite
|
|
|
|
# list of the 1st rule.
|
|
|
|
# $$<,$$^,$$+,$$|,$$?,$$*,$$% in the prerequisite list of the 2nd (and
|
|
|
|
# following) rule expand to the values from the 1st rule.
|
|
|
|
|
|
|
|
|
|
|
|
# subtest 1. Explicit rules. 1st rule.
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all: 2.x
|
|
|
|
2.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ;
|
|
|
|
%.z: ;
|
|
|
|
!, '',
|
|
|
|
"@=2.x,<=,^=,+=,|=,?=,*=,%=
|
|
|
|
#MAKE#: Nothing to be done for 'all'.\n");
|
|
|
|
|
|
|
|
|
|
|
|
# subtest 2. Explicit rules. 2nd rule.
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all: 2.x 1.x
|
|
|
|
2.x: 5.z 6.z 5.z | 7.z 7.z 8.z
|
|
|
|
1.x: 1.z 2.z 2.z | 3.z 4.z
|
|
|
|
2.x 1.x: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ;
|
|
|
|
%.z: ;
|
|
|
|
!, '',
|
|
|
|
"@=2.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=,%=
|
|
|
|
@=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=,%=
|
|
|
|
#MAKE#: Nothing to be done for 'all'.\n");
|
|
|
|
|
|
|
|
|
|
|
|
# subtest 3. Grouped targets in explicit rules. 1st rule.
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all: 2.x
|
|
|
|
2.x 1.x&: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ;
|
|
|
|
%.z: ;
|
|
|
|
!, '',
|
|
|
|
"@=2.x,<=,^=,+=,|=,?=,*=,%=
|
|
|
|
@=1.x,<=,^=,+=,|=,?=,*=,%=
|
|
|
|
#MAKE#: Nothing to be done for 'all'.\n");
|
|
|
|
|
|
|
|
|
|
|
|
# subtest 4. Grouped targets in explicit rules. 2nd rule.
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all: 2.x 1.x
|
|
|
|
2.x: 5.z 6.z 5.z | 7.z 7.z 8.z
|
|
|
|
1.x: 1.z 2.z 2.z | 3.z 4.z
|
|
|
|
2.x 1.x&: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ;
|
|
|
|
%.z: ;
|
|
|
|
!, '',
|
|
|
|
"@=2.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=,%=
|
|
|
|
@=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=,%=
|
|
|
|
#MAKE#: Nothing to be done for 'all'.\n");
|
|
|
|
|
|
|
|
|
|
|
|
# Double colon rules.
|
|
|
|
# Because each double colon rule is independent of the other double colon rules
|
|
|
|
# for the same target, each automatic variable in the prerequisite list, other
|
|
|
|
# than $$@, second expands to the empty string in any rule, 1st, 2nd or later.
|
|
|
|
|
|
|
|
# subtest 5. 1st double colon rule.
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all: 2.x
|
|
|
|
2.x:: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ;
|
|
|
|
%.z: ;
|
|
|
|
!, '',
|
|
|
|
"@=2.x,<=,^=,+=,|=,?=,*=,%=
|
|
|
|
#MAKE#: Nothing to be done for 'all'.\n");
|
|
|
|
|
|
|
|
|
|
|
|
# subtest 6. 2nd double colon rule.
|
|
|
|
run_make_test(q!
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
all: 2.x 1.x
|
|
|
|
2.x:: 5.z 6.z 5.z | 7.z 7.z 8.z ;
|
|
|
|
1.x:: 1.z 2.z 2.z | 3.z 4.z ;
|
|
|
|
2.x 1.x:: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*,%=$$%) ;
|
|
|
|
%.z: ;
|
|
|
|
!, '',
|
|
|
|
"@=2.x,<=,^=,+=,|=,?=,*=,%=
|
|
|
|
@=1.x,<=,^=,+=,|=,?=,*=,%=
|
|
|
|
#MAKE#: Nothing to be done for 'all'.\n");
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-02-27 21:40:23 +00:00
|
|
|
1;
|