Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / se_implicit
1 #                                                                    -*-perl-*-
2 $description = "Test second expansion in implicit rules.";
3
4 $details = "";
5
6 use Cwd;
7
8 $dir = cwd;
9 $dir =~ s,.*/([^/]+)$,../$1,;
10
11
12 # Test #1: automatic variables.
13 #
14 run_make_test(q!
15 .SECONDEXPANSION:
16 .DEFAULT: ; @echo '$@'
17
18 foo.a: bar baz
19
20 foo.a: biz | buz
21
22 foo.%: 1.$$@ \
23        2.$$< \
24        $$(addprefix 3.,$$^) \
25        $$(addprefix 4.,$$+) \
26        5.$$| \
27        6.$$* ; @:
28
29 1.foo.a \
30 2.bar \
31 3.bar \
32 3.baz \
33 3.biz \
34 4.bar \
35 4.baz \
36 4.biz \
37 5.buz \
38 6.a: ; @echo '$@'
39
40 !,
41 '',
42 '1.foo.a
43 2.bar
44 3.bar
45 3.baz
46 3.biz
47 4.bar
48 4.baz
49 4.biz
50 5.buz
51 6.a
52 bar
53 baz
54 biz
55 buz
56 ');
57
58
59 # Test #2: target/pattern -specific variables.
60 #
61 run_make_test(q!
62 .SECONDEXPANSION:
63 foo.x:
64
65 foo.%: $$(%_a) $$(%_b) bar ; @:
66
67 foo.x: x_a := bar
68
69 %.x: x_b := baz
70
71 bar baz: ; @echo '$@'
72 !,
73               '', "bar\nbaz\n");
74
75
76 # Test #3: order of prerequisites.
77 #
78 run_make_test(q!
79 .SECONDEXPANSION:
80 .DEFAULT: ; @echo '$@'
81
82 all: foo bar baz
83
84
85 # Subtest #1
86 #
87 %oo: %oo.1; @:
88
89 foo: foo.2
90
91 foo: foo.3
92
93 foo.1: ; @echo '$@'
94
95
96 # Subtest #2
97 #
98 bar: bar.2
99
100 %ar: %ar.1; @:
101
102 bar: bar.3
103
104 bar.1: ; @echo '$@'
105
106
107 # Subtest #3
108 #
109 baz: baz.1
110
111 baz: baz.2
112
113 %az: ; @:
114 !,
115               '',
116 'foo.1
117 foo.2
118 foo.3
119 bar.1
120 bar.2
121 bar.3
122 baz.1
123 baz.2
124 ');
125
126
127 # Test #4: stem splitting logic.
128 #
129 run_make_test(q!
130 .SECONDEXPANSION:
131 $(dir)/tmp/bar.o:
132
133 $(dir)/tmp/foo/bar.c: ; @echo '$@'
134 $(dir)/tmp/bar/bar.c: ; @echo '$@'
135 foo.h: ; @echo '$@'
136
137 %.o: $$(addsuffix /%.c,foo bar) foo.h ; @echo '$@: {$<} $^'
138 !,
139               "dir=$dir", "$dir/tmp/foo/bar.c
140 $dir/tmp/bar/bar.c
141 foo.h
142 $dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h
143 ");
144
145
146 # Test #5: stem splitting logic and order-only prerequisites.
147 #
148 run_make_test(q!
149 .SECONDEXPANSION:
150 $(dir)/tmp/foo.o: $(dir)/tmp/foo.c
151 $(dir)/tmp/foo.c: ; @echo '$@'
152 bar.h: ; @echo '$@'
153
154 %.o: %.c|bar.h ; @echo '$@: {$<} {$|} $^'
155
156 !,
157               "dir=$dir", "$dir/tmp/foo.c
158 bar.h
159 $dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c
160 ");
161
162
163 # Test #6: lack of implicit prerequisites.
164 #
165 run_make_test(q!
166 .SECONDEXPANSION:
167 foo.o: foo.c
168 foo.c: ; @echo '$@'
169
170 %.o: ; @echo '$@: {$<} $^'
171 !,
172               '', "foo.c\nfoo.o: {foo.c} foo.c\n");
173
174
175 # Test #7: Test stem from the middle of the name.
176 #
177 run_make_test(q!
178 .SECONDEXPANSION:
179 foobarbaz:
180
181 foo%baz: % $$*.1 ; @echo '$*'
182
183 bar bar.1: ; @echo '$@'
184 !,
185               '', "bar\nbar.1\nbar\n");
186
187
188 # Test #8: Make sure stem triple-expansion does not happen.
189 #
190 run_make_test(q!
191 .SECONDEXPANSION:
192 foo$$bar:
193
194 f%r: % $$*.1 ; @echo '$*'
195
196 oo$$ba oo$$ba.1: ; @echo '$@'
197 !,
198               '', 'oo$ba
199 oo$ba.1
200 oo$ba
201 ');
202
203 # Test #9: Check the value of $^
204 run_make_test(q!
205 .SECONDEXPANSION:
206
207 %.so: | $$(extra) ; @echo $^
208
209 foo.so: extra := foo.o
210 foo.so:
211 foo.o:
212 !,
213               '', "\n");
214
215 # Test #10: Test second expansion with second expansion prerequisites
216 # Ensures pattern_search() recurses with SE prereqs.
217 touch('a');
218 run_make_test(q!
219 .SECONDEXPANSION:
220 sim_base_rgg := just_a_name
221 sim_base_src := a
222 sim_base_f := a a a
223 sim_%.f: $${sim_$$*_f} ; echo $@
224 sim_%.src: $${sim_$$*_src} ; echo $@
225 sim_%: \
226         $$(if $$(sim_$$*_src),sim_%.src) \
227         $$(if $$(sim_$$*_f),sim_%.f) \
228         $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s) ; echo $@
229 !,
230               '-s sim_base', "#MAKE#: *** No rule to make target 'sim_base'.  Stop.", 512);
231
232 unlink('a');
233
234 # Ensure that order-only tokens embedded in second expansions are parsed
235 run_make_test(q!
236 .SECONDEXPANSION:
237 PREREQS=p1|p2
238 P2=p2
239 all : foo bar
240 f%o: $$(PREREQS) ; @echo '$@' from '$^' and '$|'
241 b%r: p1|$$(P2)   ; @echo '$@' from '$^' and '$|'
242 p% : ; : $@
243 !,
244               "", ": p1\n: p2\nfoo from p1 and p2\nbar from p1 and p2\n");
245
246 # SV 28456 : Don't reset $$< for default recipes
247 run_make_test(q!
248 .SECONDEXPANSION:
249
250 .PHONY: foo bar
251 foo: bar
252 foo: $$(info $$<)
253 %oo: ;
254 !,
255               '', "bar\n#MAKE#: Nothing to be done for 'foo'.\n");
256
257 # SV 54161: Expand $$* properly when it contains a path
258
259 run_make_test(q!
260 .SECONDEXPANSION:
261 %x: $$(info $$*); @echo '$*'
262 !,
263               'q/ux', "q/u\nq/u\n");
264
265
266
267 # sv 60188.
268 # Test that a file explicitly mentioned by the user and made by an implicit
269 # rule is not considered intermediate.
270
271 touch('hello.z');
272
273 # subtest 1.
274 # hello.x is derived from the stem and thus is an intermediate file.
275 run_make_test(q!
276 .SECONDEXPANSION:
277 dep:=.x
278 all: hello.z
279 %.z: %$$(dep) ; @echo $@
280 %.x: ;
281 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
282
283
284 # subtest 2.
285 # test.x is explicitly mentioned and thus is not an intermediate file.
286 run_make_test(q!
287 .SECONDEXPANSION:
288 dep:=test.x
289 all: hello.z
290 %.z: %.x $$(dep) ; @echo $@
291 %.x: ;
292 !, '', "hello.z\n");
293
294 # subtest 3.
295 # make is building hello.z and does not second expand the prerequisites of rule
296 # 'unrelated: $$(dep)'. '$$(dep)' stays not expanded and 'hello.x' is never
297 # entered to the database. Make considers 'hello.x' intermediate while building
298 # 'hello.z'. Because 'hello.z' is present and 'hello.x' is missing and
299 # 'hello.x' is intermediate, there is no need to rebuild 'hello.z'.
300 run_make_test(q!
301 .SECONDEXPANSION:
302 dep:=hello.x
303 all: hello.z
304 %.z: %.x; @echo $@
305 %.x: ;
306 unrelated: $$(dep)
307 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
308
309 # subtest 4.
310 # Just like subtest 3. $$(dep) is not second expanded. 'hello.x' is
311 # intermediate.
312 run_make_test(q!
313 .SECONDEXPANSION:
314 dep:=hello.x
315 all: hello.z
316 %.z: %.x; @echo $@
317 %.x: ;
318 %.q: $$(dep)
319 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
320
321 unlink('hello.z');
322
323
324 # sv 60188.
325 # Test that a file explicitly mentioned by the user and made by an implicit
326 # rule is not considered intermediate, even when the builtin rules are used.
327
328 touch('hello.x');
329 touch('hello.tsk');
330
331 # subtest 1.
332 # hello.z is explicitly mentioned and thus is not an intermediate file.
333 run_make_test(q!
334 .SECONDEXPANSION:
335 dep:=hello.z
336 all: hello.tsk
337 %.tsk: $$(dep) ; @echo $@
338 %.z : %.x ; @echo $@
339 !, '', "hello.z\nhello.tsk");
340
341 # subtest 2.
342 # hello.z is derived from the stem and thus is an intermediate file.
343 run_make_test(q!
344 .SECONDEXPANSION:
345 dep:=.z
346 all: hello.tsk
347 %.tsk: %$$(dep) ; @echo $@
348 %.z : %.x ; @echo $@
349 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
350
351 unlink('hello.x');
352 unlink('hello.tsk');
353
354
355 # sv 60659. Second expansion of automatic variables inside a function in the
356 # prerequisite list.
357 # $$@ expands to the target in the 1st and following rules.
358 # $$* expands to the stem in the 1st and following rules.
359 # $$<,$$^,$$+,$$|,$$?,$$% expand to the empty string in the prerequisite list
360 # of the 1st rule.
361 # $$<,$$^,$$+,$$|,$$?,$$% in the prerequisite list of the 2nd (and following)
362 # rule expand to the values from the 1st rule.
363 # $$% cannot be used in prerequisites, because in pattern rules % is
364 # substituted for stem.
365
366
367 # subtest 1. Pattern rules. 1st rule.
368 run_make_test(q!
369 .SECONDEXPANSION:
370 all: 2.x
371 %.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
372 %.z: ;
373 !, '',
374 "@=2.x,<=,^=,+=,|=,?=,*=2
375 #MAKE#: Nothing to be done for 'all'.\n");
376
377
378 # subtest 2. Pattern rules. 2nd rule.
379 run_make_test(q!
380 .SECONDEXPANSION:
381 all: 2.x 1.x
382 2.x: 5.z 6.z 5.z | 7.z 7.z 8.z
383 1.x: 1.z 2.z 2.z | 3.z 4.z
384 %.x: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
385 %.z: ;
386 !, '',
387 "@=2.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=2
388 @=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=1
389 #MAKE#: Nothing to be done for 'all'.\n");
390
391
392 # subtest 3. Static pattern rules. 1st rule.
393 run_make_test(q!
394 .SECONDEXPANSION:
395 all: 2.x
396 2.x: %.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
397 %.z: ;
398 !, '',
399 "@=2.x,<=,^=,+=,|=,?=,*=2
400 #MAKE#: Nothing to be done for 'all'.\n");
401
402
403 # subtest 4. Static pattern rules. 2nd rule.
404 run_make_test(q!
405 .SECONDEXPANSION:
406 all: 15.x 1.x
407 15.x: 5.z 6.z 5.z | 7.z 7.z 8.z
408 1.x: 1.z 2.z 2.z | 3.z 4.z
409 15.x 1.x: %.x: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
410 %.z: ;
411 !, '',
412 "@=15.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=15
413 @=1.x,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=1
414 #MAKE#: Nothing to be done for 'all'.\n");
415
416
417 # subtest 5. Grouped targets in implicit rules. 1st rule.
418 run_make_test(q!
419 .SECONDEXPANSION:
420 all: 2.x
421 %.x %.xx&: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
422 %.z: ;
423 !, '',
424 "@=2.x,<=,^=,+=,|=,?=,*=2
425 #MAKE#: Nothing to be done for 'all'.\n");
426
427
428 # subtest 6. Grouped targets in implicit rules. 2nd rule.
429 run_make_test(q!
430 .SECONDEXPANSION:
431 all: 2.x 1.xx
432 2.x: 5.z 6.z 5.z | 7.z 7.z 8.z
433 1.xx: 1.z 2.z 2.z | 3.z 4.z
434 %.x %.xx&: 9.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
435 %.z: ;
436 !, '',
437 "@=2.x,<=5.z,^=5.z 6.z,+=5.z 6.z 5.z,|=7.z 8.z,?=,*=2
438 @=1.xx,<=1.z,^=1.z 2.z,+=1.z 2.z 2.z,|=3.z 4.z,?=,*=1
439 #MAKE#: Nothing to be done for 'all'.\n");
440
441
442 # subtest 7. Double colon rule.
443 run_make_test(q!
444 .SECONDEXPANSION:
445 all: 2.x
446 %.x:: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
447 5.z 6.z: ;
448 !, '',
449 "@=2.x,<=,^=,+=,|=,?=,*=2
450 #MAKE#: Nothing to be done for 'all'.\n");
451
452 # sv 62324.
453 # Integrity self check.
454 run_make_test(q!
455 .SECONDEXPANSION:
456 all: bye.x
457 %.x: $$(firstword %.1;
458 !, '', "#MAKE#: *** unterminated call to function 'firstword': missing ')'.  Stop.", 512);
459
460 # sv 62706.
461 # Test that makes avoids second expanding prerequisites of the rules which are
462 # not tried during implicit search.
463 # Here, make tries rules '%.tsk: %.o' and '%.o' and their prerequisites are
464 # second expanded.
465 # Rules '%.bin: %.x' and '%.x:' are not used in implicit search for 'hello.tsk'
466 # and 'hello.o' and their prerequisites are not expanded.
467 run_make_test(q!
468 .SECONDEXPANSION:
469 %.bin: %.x $$(info second expansion of $$@ prereqs); $(info $@ from $<)
470 %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<)
471 %.x: $$(info second expansion of $$@ prereqs); $(info $@)
472 %.o: $$(info second expansion of $$@ prereqs); $(info $@)
473 !, '-R hello.tsk',
474 "second expansion of hello.o prereqs
475 second expansion of hello.tsk prereqs
476 hello.o
477 hello.tsk from hello.o
478 #MAKE#: 'hello.tsk' is up to date.\n");
479
480 # sv 62706.
481 # No side effects from second expansion of unrelated rules.
482 run_make_test(q!
483 .SECONDEXPANSION:
484 all: hello.tsk
485 %.tsk: %.o; exit 1
486 hello.o:;
487 %.q: $$(shell touch hello.1);
488 !, '',
489 "exit 1
490 #MAKE#: *** [#MAKEFILE#:4: hello.tsk] Error 1\n", 512);
491
492 # sv 62706.
493 # Second expansion of intermediate prerequisites.
494 # The rule to build hello.x is implicit.
495 # Test that $$(deps) is secondary expanded.
496 run_make_test(q!
497 deps:=hello.h
498 .SECONDEXPANSION:
499 all: hello.tsk
500 %.tsk: %.x; $(info $@)
501 %.x: $$(deps); $(info $@)
502 hello.h:; $(info $@)
503 !, '', "hello.h\nhello.x\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.\n");
504
505 # This tells the test driver that the perl test script executed properly.
506 1;