* New feature: -L option
[make.git] / tests / scripts / features / patspecific_vars
blob9e98b437646adbb3b56b6620118b791c30ab2900
1 #                                                                    -*-perl-*-
2 $description = "Test pattern-specific variable settings.";
4 $details = "\
5 Create a makefile containing various flavors of pattern-specific variable
6 settings, override and non-override, and using various variable expansion
7 rules, semicolon interference, etc.";
9 open(MAKEFILE,"> $makefile");
11 print MAKEFILE <<'EOF';
12 all: one.x two.x three.x
13 FOO = foo
14 BAR = bar
15 BAZ = baz
16 one.x: override FOO = one
17 %.x: BAR = two
18 t%.x: BAR = four
19 thr% : override BAZ = three
20 one.x two.x three.x: ; @echo $@: $(FOO) $(BAR) $(BAZ)
21 four.x: baz ; @echo $@: $(FOO) $(BAR) $(BAZ)
22 baz: ; @echo $@: $(FOO) $(BAR) $(BAZ)
24 # test matching multiple patterns
25 a%: AAA = aaa
26 %b: BBB = ccc
27 a%: BBB += ddd
28 %b: AAA ?= xxx
29 %b: AAA += bbb
30 .PHONY: ab
31 ab: ; @echo $(AAA); echo $(BBB)
32 EOF
34 close(MAKEFILE);
37 # TEST #1 -- basics
39 &run_make_with_options($makefile, "", &get_logfile);
40 $answer = "one.x: one two baz\ntwo.x: foo four baz\nthree.x: foo four three\n";
41 &compare_output($answer,&get_logfile(1));
44 # TEST #2 -- try the override feature
46 &run_make_with_options($makefile, "BAZ=five", &get_logfile);
47 $answer = "one.x: one two five\ntwo.x: foo four five\nthree.x: foo four three\n";
48 &compare_output($answer,&get_logfile(1));
51 # TEST #3 -- make sure patterns are inherited properly
53 &run_make_with_options($makefile, "four.x", &get_logfile);
54 $answer = "baz: foo two baz\nfour.x: foo two baz\n";
55 &compare_output($answer,&get_logfile(1));
58 # TEST #4 -- test multiple patterns matching the same target
60 &run_make_with_options($makefile, "ab", &get_logfile);
61 $answer = "aaa bbb\nccc ddd\n";
62 &compare_output($answer,&get_logfile(1));
64 # TEST #5 -- test pattern-specific exported variables
66 run_make_test('
67 /%: export foo := foo
69 /bar:
70         @test "$(foo)" = "$$foo"
71 ', '', '');
74 # TEST #6 -- test expansion of pattern-specific simple variables
76 run_make_test('
77 .PHONY: all
79 all: inherit := good $$t
80 all: bar baz
82 b%: pattern := good $$t
84 global := orginal $$t
87 # normal target
89 ifdef rec
90 bar: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
91 else
92 bar: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
93 endif
95 bar: ; @echo \'normal: $a;\'
98 # pattern target
100 ifdef rec
101 %z: a = global: $(global) pattern: $(pattern) inherit: $(inherit)
102 else
103 %z: a := global: $(global) pattern: $(pattern) inherit: $(inherit)
104 endif
106 %z: ; @echo \'pattrn: $a;\'
109 global := new $$t
112 'normal: global: orginal $t pattern:  inherit: ;
113 pattrn: global: orginal $t pattern:  inherit: ;');
116 # TEST #7 -- test expansion of pattern-specific recursive variables
118 run_make_test(undef, # reuse previous makefile
119 'rec=1',
120 'normal: global: new $t pattern: good $t inherit: good $t;
121 pattrn: global: new $t pattern: good $t inherit: good $t;');