2 $description = "Test second expansion in implicit rules.";
9 $dir =~ s,.*/([^/]+)$,../$1,;
12 # Test #1: automatic variables.
16 .DEFAULT: ; @echo '$@'
24 $$(addprefix 3.,$$^) \
25 $$(addprefix 4.,$$+) \
59 # Test #2: target/pattern -specific variables.
65 foo.%: $$(%_a) $$(%_b) bar ; @:
76 # Test #3: order of prerequisites.
80 .DEFAULT: ; @echo '$@'
127 # Test #4: stem splitting logic.
133 $(dir)/tmp/foo/bar.c: ; @echo '$@'
134 $(dir)/tmp/bar/bar.c: ; @echo '$@'
137 %.o: $$(addsuffix /%.c,foo bar) foo.h ; @echo '$@: {$<} $^'
139 "dir=$dir", "$dir/tmp/foo/bar.c
142 $dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h
146 # Test #5: stem splitting logic and order-only prerequisites.
150 $(dir)/tmp/foo.o: $(dir)/tmp/foo.c
151 $(dir)/tmp/foo.c: ; @echo '$@'
154 %.o: %.c|bar.h ; @echo '$@: {$<} {$|} $^'
157 "dir=$dir", "$dir/tmp/foo.c
159 $dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c
163 # Test #6: lack of implicit prerequisites.
170 %.o: ; @echo '$@: {$<} $^'
172 '', "foo.c\nfoo.o: {foo.c} foo.c\n");
175 # Test #7: Test stem from the middle of the name.
181 foo%baz: % $$*.1 ; @echo '$*'
183 bar bar.1: ; @echo '$@'
185 '', "bar\nbar.1\nbar\n");
188 # Test #8: Make sure stem triple-expansion does not happen.
194 f%r: % $$*.1 ; @echo '$*'
196 oo$$ba oo$$ba.1: ; @echo '$@'
203 # Test #9: Check the value of $^
207 %.so: | $$(extra) ; @echo $^
209 foo.so: extra := foo.o
215 # Test #10: Test second expansion with second expansion prerequisites
216 # Ensures pattern_search() recurses with SE prereqs.
220 sim_base_rgg := just_a_name
223 sim_%.f: $${sim_$$*_f} ; echo $@
224 sim_%.src: $${sim_$$*_src} ; echo $@
226 $$(if $$(sim_$$*_src),sim_%.src) \
227 $$(if $$(sim_$$*_f),sim_%.f) \
228 $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s) ; echo $@
230 '-s sim_base', "#MAKE#: *** No rule to make target 'sim_base'. Stop.", 512);
234 # Ensure that order-only tokens embedded in second expansions are parsed
240 f%o: $$(PREREQS) ; @echo '$@' from '$^' and '$|'
241 b%r: p1|$$(P2) ; @echo '$@' from '$^' and '$|'
244 "", ": p1\n: p2\nfoo from p1 and p2\nbar from p1 and p2\n");
246 # SV 28456 : Don't reset $$< for default recipes
255 '', "bar\n#MAKE#: Nothing to be done for 'foo'.\n");
257 # SV 54161: Expand $$* properly when it contains a path
261 %x: $$(info $$*); @echo '$*'
263 'q/ux', "q/u\nq/u\n");
268 # Test that a file explicitly mentioned by the user and made by an implicit
269 # rule is not considered intermediate.
274 # hello.x is derived from the stem and thus is an intermediate file.
279 %.z: %$$(dep) ; @echo $@
281 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
285 # test.x is explicitly mentioned and thus is not an intermediate file.
290 %.z: %.x $$(dep) ; @echo $@
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'.
307 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
310 # Just like subtest 3. $$(dep) is not second expanded. 'hello.x' is
319 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
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.
332 # hello.z is explicitly mentioned and thus is not an intermediate file.
337 %.tsk: $$(dep) ; @echo $@
339 !, '', "hello.z\nhello.tsk");
342 # hello.z is derived from the stem and thus is an intermediate file.
347 %.tsk: %$$(dep) ; @echo $@
349 !, '', "#MAKE#: Nothing to be done for 'all'.\n");
355 # sv 60659. Second expansion of automatic variables inside a function in the
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
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.
367 # subtest 1. Pattern rules. 1st rule.
371 %.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
374 "@=2.x,<=,^=,+=,|=,?=,*=2
375 #MAKE#: Nothing to be done for 'all'.\n");
378 # subtest 2. Pattern rules. 2nd rule.
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 @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
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");
392 # subtest 3. Static pattern rules. 1st rule.
396 2.x: %.x: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
399 "@=2.x,<=,^=,+=,|=,?=,*=2
400 #MAKE#: Nothing to be done for 'all'.\n");
403 # subtest 4. Static pattern rules. 2nd rule.
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 @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
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");
417 # subtest 5. Grouped targets in implicit rules. 1st rule.
421 %.x %.xx&: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
424 "@=2.x,<=,^=,+=,|=,?=,*=2
425 #MAKE#: Nothing to be done for 'all'.\n");
428 # subtest 6. Grouped targets in implicit rules. 2nd rule.
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 @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
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");
442 # subtest 7. Double colon rule.
446 %.x:: 5.z 6.z 5.z $$(info @=$$@,<=$$<,^=$$^,+=$$+,|=$$|,?=$$?,*=$$*) ;
449 "@=2.x,<=,^=,+=,|=,?=,*=2
450 #MAKE#: Nothing to be done for 'all'.\n");
453 # Integrity self check.
457 %.x: $$(firstword %.1;
458 !, '', "#MAKE#: *** unterminated call to function 'firstword': missing ')'. Stop.", 512);
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
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.
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 $@)
474 "second expansion of hello.o prereqs
475 second expansion of hello.tsk prereqs
477 hello.tsk from hello.o
478 #MAKE#: 'hello.tsk' is up to date.\n");
481 # No side effects from second expansion of unrelated rules.
487 %.q: $$(shell touch hello.1);
490 #MAKE#: *** [#MAKEFILE#:4: hello.tsk] Error 1\n", 512);
493 # Second expansion of intermediate prerequisites.
494 # The rule to build hello.x is implicit.
495 # Test that $$(deps) is secondary expanded.
500 %.tsk: %.x; $(info $@)
501 %.x: $$(deps); $(info $@)
503 !, '', "hello.h\nhello.x\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.\n");
505 # This tells the test driver that the perl test script executed properly.