1999-09-14 02:03:19 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
$description = "Test pattern-specific variable settings.";
|
|
|
|
|
|
|
|
$details = "\
|
|
|
|
Create a makefile containing various flavors of pattern-specific variable
|
|
|
|
settings, override and non-override, and using various variable expansion
|
|
|
|
rules, semicolon interference, etc.";
|
|
|
|
|
|
|
|
open(MAKEFILE,"> $makefile");
|
|
|
|
|
|
|
|
print MAKEFILE <<'EOF';
|
|
|
|
all: one.x two.x three.x
|
|
|
|
FOO = foo
|
|
|
|
BAR = bar
|
|
|
|
BAZ = baz
|
|
|
|
one.x: override FOO = one
|
2003-05-02 01:44:59 +00:00
|
|
|
%.x: BAR = two
|
|
|
|
t%.x: BAR = four
|
|
|
|
thr% : override BAZ = three
|
|
|
|
one.x two.x three.x: ; @echo $@: $(FOO) $(BAR) $(BAZ)
|
|
|
|
four.x: baz ; @echo $@: $(FOO) $(BAR) $(BAZ)
|
|
|
|
baz: ; @echo $@: $(FOO) $(BAR) $(BAZ)
|
|
|
|
|
|
|
|
# test matching multiple patterns
|
|
|
|
a%: AAA = aaa
|
|
|
|
%b: BBB = ccc
|
|
|
|
a%: BBB += ddd
|
|
|
|
%b: AAA ?= xxx
|
|
|
|
%b: AAA += bbb
|
|
|
|
.PHONY: ab
|
|
|
|
ab: ; @echo $(AAA); echo $(BBB)
|
1999-09-14 02:03:19 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
close(MAKEFILE);
|
|
|
|
|
|
|
|
|
|
|
|
# TEST #1 -- basics
|
|
|
|
|
|
|
|
&run_make_with_options($makefile, "", &get_logfile);
|
2003-05-02 01:44:59 +00:00
|
|
|
$answer = "one.x: one two baz\ntwo.x: foo four baz\nthree.x: foo four three\n";
|
1999-09-14 02:03:19 +00:00
|
|
|
&compare_output($answer,&get_logfile(1));
|
|
|
|
|
|
|
|
|
|
|
|
# TEST #2 -- try the override feature
|
|
|
|
|
|
|
|
&run_make_with_options($makefile, "BAZ=five", &get_logfile);
|
2003-05-02 01:44:59 +00:00
|
|
|
$answer = "one.x: one two five\ntwo.x: foo four five\nthree.x: foo four three\n";
|
1999-09-14 02:03:19 +00:00
|
|
|
&compare_output($answer,&get_logfile(1));
|
|
|
|
|
2000-02-05 07:37:40 +00:00
|
|
|
|
|
|
|
# TEST #3 -- make sure patterns are inherited properly
|
|
|
|
|
|
|
|
&run_make_with_options($makefile, "four.x", &get_logfile);
|
2003-05-02 01:44:59 +00:00
|
|
|
$answer = "baz: foo two baz\nfour.x: foo two baz\n";
|
|
|
|
&compare_output($answer,&get_logfile(1));
|
|
|
|
|
|
|
|
|
|
|
|
# TEST #4 -- test multiple patterns matching the same target
|
|
|
|
|
|
|
|
&run_make_with_options($makefile, "ab", &get_logfile);
|
|
|
|
$answer = "aaa bbb\nccc ddd\n";
|
2000-02-05 07:37:40 +00:00
|
|
|
&compare_output($answer,&get_logfile(1));
|
|
|
|
|
2004-09-27 18:09:52 +00:00
|
|
|
# TEST #5 -- test pattern-specific exported variables
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
/%: export foo := foo
|
|
|
|
|
|
|
|
/bar:
|
2005-08-29 14:11:00 +00:00
|
|
|
@echo $(foo) $$foo
|
|
|
|
', '', 'foo foo');
|
2004-09-27 18:09:52 +00:00
|
|
|
|
2004-10-05 16:56:14 +00:00
|
|
|
|
|
|
|
# TEST #6 -- test expansion of pattern-specific simple variables
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
all: inherit := good $$t
|
|
|
|
all: bar baz
|
|
|
|
|
|
|
|
b%: pattern := good $$t
|
|
|
|
|
2013-10-09 05:53:55 +00:00
|
|
|
global := original $$t
|
2004-10-05 16:56:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# normal target
|
|
|
|
#
|
|
|
|
ifdef rec
|
|
|
|
bar: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
|
|
|
|
else
|
|
|
|
bar: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
|
|
|
|
endif
|
|
|
|
|
|
|
|
bar: ; @echo \'normal: $a;\'
|
|
|
|
|
|
|
|
|
|
|
|
# pattern target
|
|
|
|
#
|
|
|
|
ifdef rec
|
|
|
|
%z: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
|
|
|
|
else
|
|
|
|
%z: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
|
|
|
|
endif
|
|
|
|
|
2013-10-09 05:53:55 +00:00
|
|
|
%z: ; @echo \'pattern: $a;\'
|
2004-10-05 16:56:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
global := new $$t
|
|
|
|
',
|
|
|
|
'',
|
2013-10-09 05:53:55 +00:00
|
|
|
'normal: global: original $t pattern: inherit: ;
|
|
|
|
pattern: global: original $t pattern: inherit: ;');
|
2004-10-05 16:56:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
# TEST #7 -- test expansion of pattern-specific recursive variables
|
|
|
|
#
|
|
|
|
run_make_test(undef, # reuse previous makefile
|
|
|
|
'rec=1',
|
|
|
|
'normal: global: new $t pattern: good $t inherit: good $t;
|
2013-10-09 05:53:55 +00:00
|
|
|
pattern: global: new $t pattern: good $t inherit: good $t;');
|
2004-10-05 16:56:14 +00:00
|
|
|
|
2009-06-04 06:30:27 +00:00
|
|
|
# TEST #8: override in pattern-specific variables
|
|
|
|
|
|
|
|
run_make_test('
|
|
|
|
a%: override FOO += f1
|
|
|
|
a%: FOO += f2
|
|
|
|
ab: ; @echo "$(FOO)"
|
|
|
|
',
|
|
|
|
'', "f1\n");
|
|
|
|
|
|
|
|
run_make_test(undef, 'FOO=C', "C f1\n");
|
2004-10-05 16:56:14 +00:00
|
|
|
|
2009-09-28 12:31:55 +00:00
|
|
|
# TEST #9: Test shortest stem selection in pattern-specific variables.
|
|
|
|
|
|
|
|
run_make_test('
|
|
|
|
%-mt.x: x := two
|
|
|
|
%.x: x := one
|
|
|
|
|
|
|
|
all: foo.x foo-mt.x
|
|
|
|
|
|
|
|
foo.x: ;@echo $x
|
|
|
|
foo-mt.x: ;@echo $x
|
|
|
|
',
|
|
|
|
'',
|
|
|
|
"one\ntwo");
|
|
|
|
|
1999-09-14 02:03:19 +00:00
|
|
|
1;
|