make/tests/scripts/features/se_explicit
Paul Smith 11095a90f1 Make second expansion optional (partial implementation).
I decided this feature was too impacting to make the permanent default
behavior.  This set of changes makes the default behavior of make the
old behavior (no second expansion).  If you want second expansion, you
must define the .SECONDEXPANSION: special target before the first target
that needs it.

This set of changes ONLY fixes explicit and static pattern rules to work
like this.  Implicit rules still have second expansion enabled all the
time: I'll work on that next.

Note that there is still a backward-incompatibility: now to get the old
SysV behavior using $$@ etc. in the prerequisites list you need to set
.SECONDEXPANSION: as well.
2005-10-24 13:01:39 +00:00

127 lines
1.5 KiB
Perl

# -*-perl-*-
$description = "Test second expansion in ordinary rules.";
$details = "";
# TEST #0: Test handing of '$' in prerequisites with and without second
# expansion.
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 '$@'
!,
'',
"\$\nbar\$biz\nfoo\$bar : bar\$baz bar\$biz");
run_make_test(undef, 'SE=1', "three\nfour\nbariz\nfoo\$bar : baraz bariz");
# TEST #1: automatic variables.
#
run_make_test('
.SECONDEXPANSION:
.DEFAULT: ; @echo $@
foo: bar baz
foo: biz | buz
foo: $$@.1 \
$$<.2 \
$$(addsuffix .3,$$^) \
$$(addsuffix .4,$$+) \
$$|.5 \
$$*.6
',
'',
'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.
#
run_make_test('
.SECONDEXPANSION:
.DEFAULT: ; @echo $@
foo.x: $$a $$b
foo.x: a := bar
%.x: b := baz
',
'',
'bar
baz
');
# Test #3: order of prerequisites.
#
run_make_test('
.SECONDEXPANSION:
.DEFAULT: ; @echo $@
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: ; @:
',
'',
'foo.1
foo.2
foo.3
bar.1
bar.2
bar.3
baz.1
baz.2
');
# This tells the test driver that the perl test script executed properly.
1;