1#                                                                    -*-perl-*-
2$description = "Test second expansion in ordinary rules.";
3
4$details = "";
5
6use Cwd;
7
8$dir = cwd;
9$dir =~ s,.*/([^/]+)$,../$1,;
10
11
12# Test #1: automatic variables.
13#
14run_make_test('
15.SECONDEXPANSION:
16.DEFAULT: ; @echo $@
17
18foo.a: bar baz
19
20foo.a: biz | buz
21
22foo.%: 1.$$@ \
23       2.$$< \
24       $$(addprefix 3.,$$^) \
25       $$(addprefix 4.,$$+) \
26       5.$$| \
27       6.$$*
28	@:
29
301.foo.a \
312.bar \
323.bar \
333.baz \
343.biz \
354.bar \
364.baz \
374.biz \
385.buz \
396.a:
40	@echo $@
41
42',
43'',
44'1.foo.a
452.bar
463.bar
473.baz
483.biz
494.bar
504.baz
514.biz
525.buz
536.a
54bar
55baz
56biz
57buz
58');
59
60
61# Test #2: target/pattern -specific variables.
62#
63run_make_test('
64.SECONDEXPANSION:
65foo.x:
66
67foo.%: $$(%_a) $$(%_b) bar
68	@:
69
70foo.x: x_a := bar
71
72%.x: x_b := baz
73
74bar baz: ; @echo $@
75
76',
77'',
78'bar
79baz
80');
81
82
83# Test #3: order of prerequisites.
84#
85run_make_test('
86.SECONDEXPANSION:
87.DEFAULT: ; @echo $@
88
89all: foo bar baz
90
91
92# Subtest #1
93#
94%oo: %oo.1; @:
95
96foo: foo.2
97
98foo: foo.3
99
100foo.1: ; @echo $@
101
102
103# Subtest #2
104#
105bar: bar.2
106
107%ar: %ar.1; @:
108
109bar: bar.3
110
111bar.1: ; @echo $@
112
113
114# Subtest #3
115#
116baz: baz.1
117
118baz: baz.2
119
120%az: ; @:
121
122',
123'',
124'foo.1
125foo.2
126foo.3
127bar.1
128bar.2
129bar.3
130baz.1
131baz.2
132');
133
134
135# Test #4: stem splitting logic.
136#
137run_make_test('
138.SECONDEXPANSION:
139$(dir)/tmp/bar.o:
140
141$(dir)/tmp/foo/bar.c: ; @echo $@
142$(dir)/tmp/bar/bar.c: ; @echo $@
143foo.h: ; @echo $@
144
145%.o: $$(addsuffix /%.c,foo bar) foo.h
146	@echo $@: {$<} $^
147
148',
149"dir=$dir",
150"$dir/tmp/foo/bar.c
151$dir/tmp/bar/bar.c
152foo.h
153$dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h
154");
155
156
157# Test #5: stem splitting logic and order-only prerequisites.
158#
159run_make_test('
160.SECONDEXPANSION:
161$(dir)/tmp/foo.o: $(dir)/tmp/foo.c
162$(dir)/tmp/foo.c: ; @echo $@
163bar.h: ; @echo $@
164
165%.o: %.c|bar.h
166	@echo $@: {$<} {$|} $^
167
168',
169"dir=$dir",
170"$dir/tmp/foo.c
171bar.h
172$dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c
173");
174
175
176# Test #6: lack of implicit prerequisites.
177#
178run_make_test('
179.SECONDEXPANSION:
180foo.o: foo.c
181foo.c: ; @echo $@
182
183%.o:
184	@echo $@: {$<} $^
185
186',
187'',
188'foo.c
189foo.o: {foo.c} foo.c
190');
191
192# Test #7: Test stem from the middle of the name.
193#
194run_make_test('
195.SECONDEXPANSION:
196foobarbaz:
197
198foo%baz: % $$*.1
199	@echo $*
200
201bar bar.1:
202	@echo $@
203
204',
205'',
206'bar
207bar.1
208bar
209');
210
211# Test #8: Make sure stem triple-expansion does not happen.
212#
213run_make_test('
214.SECONDEXPANSION:
215foo$$bar:
216
217f%r: % $$*.1
218	@echo \'$*\'
219
220oo$$ba oo$$ba.1:
221	@echo \'$@\'
222
223',
224'',
225'oo$ba
226oo$ba.1
227oo$ba
228');
229
230
231# This tells the test driver that the perl test script executed properly.
2321;
233