3 $description = "Test implicit rule search.";
8 # Each test has a %.c rule ahead of %.f rule.
9 # hello.f exists and hello.c is missing.
11 unlink('hello.c', 'hello.tsk', 'hello.o', 'hello.x');
13 # Run every test with and without a suffix.
14 my @suffixes = ('', '.o');
15 # Run every test with single and double colon rules.
16 my @rules = ('', ':');
18 for my $s (@suffixes) {
22 # Test that make finds the intended implicit rule based on existence of a
23 # prerequisite in the filesystem.
25 # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen.
28 %$s:$r %.c; \$(info hello.c)
29 %$s:$r %.f; \$(info hello.f)
30 ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");
32 # Test that make finds the intended implicit rule based on the explicit
33 # prerequisite of the top goal and despite the existence of a
34 # prerequisite in the filesystem.
36 # hello.c is an explicit prerequisite of the top target (hello.o or hello).
37 # hello.c ought to exist.
38 # hello.c prerequisite causes '%.o: %.c' rule to be chosen.
41 %$s:$r %.c; \$(info hello.c)
42 %$s:$r %.f; \$(info hello.f)
44 "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello$s'. Stop.\n",
47 # Test that make finds the intended implicit rule when the implicit
48 # prerequisite matches a target of an unrelated rule and despite the existence
49 # of a prerequisite of the other rule candidate in the filesystem.
51 # hello.c matches 'hello.c:' rule. This makes hello.c a target and thus ought
53 # hello.c prerequisite causes '%.o: %.c' rule to be chosen.
56 %$s:$r %.c; \$(info hello.c)
57 %$s:$r %.f; \$(info hello.f)
58 hello.c:; @#HELPER# fail 1
59 ", '-r', "fail 1\n#MAKE#: *** [#MAKEFILE#:5: hello.c] Error 1\n", 512);
61 # Test that make finds the intended implicit rule based on existence of a
62 # prerequisite in the filesystem, even when the prerequisite of another
63 # candidate rule is mentioned explicitly on an unrelated rule.
65 # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen, even though hello.c
66 # is mentioned explicitly on 'unrelated: hello.c'.
67 # ought-to-exist does not apply to hello.c.
70 %$s:$r %.c; \$(info hello.c)
71 %$s:$r %.f; \$(info hello.f)
73 ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");
75 # Test that make finds the intended implicit rule based on existence of a
76 # prerequisite in the filesystem.
78 # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen.
79 # Despite '%.o: %.c hello.c' rule having explicit prerequisite hello.c.
80 # ought-to-exist does not apply to hello.c.
83 %$s:$r %.c hello.c; \$(info hello.c)
84 %$s:$r %.f; \$(info hello.f)
85 ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");
87 # '%.o: %.c' rule is skipped and '%.o: %.f' rule is chosen.
88 # '%.o: %.f hello.f' rule has explicit prerequisite hello.f.
89 # ought-to-exist does not apply to hello.c.
92 %$s:$r %.c; \$(info hello.c)
93 %$s:$r %.f hello.f; \$(info hello.f)
94 ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");
96 # Rule '%: %.f' is chosen, because '%: %.f' requires no intermediates.
97 # '%: %.c', on the other hand, requires intemediate hello.c to be built by the
101 %$s:$r %.c; \$(info \$<)
102 %$s:$r %.f; \$(info \$<)
103 .DEFAULT:; \$(info \$\@) true
105 ", '-r', "hello.f\n#MAKE#: Nothing to be done for 'all'.");
108 # hello.f is missing.
109 # This time both hello.c and hello.f are missing and both '%: %.c' and '%: %.f'
110 # require an intermediate.
111 # The default rule builds intemerdiate hello.c.
112 # '%: %.c' rule is chosen to build hello.
116 %$s:$r %.c; \$(info \$<)
117 %$s:$r %.f; \$(info \$<)
118 .DEFAULT:; \@\$(info \$\@) #HELPER# fail 1
120 ", '-r', "hello.c\nfail 1\n#MAKE#: *** [#MAKEFILE#:5: hello.c] Error 1\n", 512);
122 # hello.f is missing.
123 # No rule is found, because hello.c is not mentioned explicitly.
126 %$s:$r %.c; \$(info \$<)
127 %$s:$r %.f; \$(info \$<)
128 .DEFAULT:; \@\$(info \$\@) #HELPER# fail 1
129 ", '-r', "hello$s\nfail 1\n#MAKE#: *** [#MAKEFILE#:5: hello$s] Error 1\n", 512);
134 # Almost the same tests as above, but this time an intermediate is built.
137 for my $s (@suffixes) {
140 my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n";
143 $result = "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.";
149 %.tsk: %$s; \$(info hello.tsk)
150 %$s:$r %.c; \$(info hello.c)
151 %$s:$r %.f; \$(info hello.f)
152 ", '-r', "$result", $rcode);
156 %.tsk: %$s hello$s; \$(info hello.tsk)
157 %$s:$r %.c; \$(info hello.c)
158 %$s:$r %.f; \$(info hello.f)
159 ", '-r', $result, $rcode);
163 %.tsk: %$s; \$(info hello.tsk)
164 %$s:$r %.c hello$s; \$(info hello.c)
165 %$s:$r %.f; \$(info hello.f)
166 ", '-r', $result, $rcode);
173 # Circular dependency hello.o <- hello.tsk is dropped.
176 %.tsk: %.o; \$(info hello.tsk)
177 %.o:$r %.c; \$(info hello.c)
178 %.o:$r %.f %.tsk; \$(info hello.f)
180 "#MAKE#: Circular hello.o <- hello.tsk dependency dropped.\nhello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.");
185 for my $s (@suffixes) {
191 %.tsk: %$s; \$(info hello.tsk)
192 %$s:$r %.c; \$(info hello.c)
193 %$s:$r %.f; \$(info hello.f)
195 "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello$s'. Stop.\n",
200 for my $s (@suffixes) {
203 my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n";
205 $result = "fail 1\n#MAKE#: *** [#MAKEFILE#:6: hello.c] Error 1\n";
210 %.tsk: %$s; \$(info hello.tsk)
211 %$s:$r %.c; \$(info hello.c)
212 %$s:$r %.f; \$(info hello.f)
213 hello.c:; @#HELPER# fail 1
214 ", '-r', $result, 512);
219 for my $s (@suffixes) {
224 %.tsk: %$s; \$(info hello.tsk)
225 %$s:$r %.c; \$(info hello.c)
226 %$s:$r %.f; \$(info hello.f)
228 ", '-r', "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.");
232 for my $s (@suffixes) {
235 my $result = "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n";
238 $result = "hello.f\nhello.tsk\n#MAKE#: Nothing to be done for 'all'.";
244 %.tsk: %$s; \$(info hello.tsk)
245 %$s:$r %.c; \$(info hello.c)
246 %$s:$r %.f hello.f; \$(info hello.f)
247 ", '-r', $result, $rcode);
251 # One of the implicit rules has two prerequisites, hello.c and hello.x
252 # hello.c does not qualify as ought to exit.
253 # hello.x can be made from hello.z.
254 # This test exersizes the break, which prevents making hello.x as an
255 # intermediate from hello.z during compatibility search.
258 for my $s (@suffixes) {
263 %.tsk: %$s; \$(info hello.tsk)
264 %$s:$r %.c %.x; \$(info hello.c)
265 %$s:$r %.f; \$(info hello.f)
267 %.x:$r %.z; \$(info hello.z)
269 "#MAKE#: *** No rule to make target 'hello$s', needed by 'hello.tsk'. Stop.\n",
274 # Test that prerequisite 'hello.x' mentioned explicitly on an unrelated rule is
275 # not considered intermediate.
280 %.tsk: %.x; touch hello.tsk
283 ", '-r', "touch hello.tsk\n");
287 # Test implicit search of builtin rules.
289 # %: %.c (and other builtin rules) are skipped.
293 !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\n");
295 # %.o: %.c (and other builtin rules) are skipped.
296 # %.o: %.f is chosen.
299 !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 -c hello.f\n");
303 # hello.c is an explicit prerequisite of the top target hello.
304 # hello.c ought to exist.
305 # hello.c prerequisite causes '%: %.c' rule to be chosen.
308 !, 'FC="@echo f77" OUTPUT_OPTION=',
309 "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello'. Stop.\n",
312 # %.o: %.c is chosen.
313 # hello.c is an explicit prerequisite of the top target hello.o.
314 # hello.c ought to exist.
315 # hello.c prerequisite causes '%.o: %.c' rule to be chosen.
318 !, 'FC="@echo f77" OUTPUT_OPTION=',
319 "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello.o'. Stop.\n",
322 # %: %.c (and other builtin rules) are skipped.
324 # ought-to-exist does not apply to hello.c.
328 !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 hello.f -o hello\n");
330 # %.o: %.c (and other builtin rules) are skipped.
331 # %.o: %.f is chosen.
332 # ought-to-exist does not apply to hello.c.
336 !, 'FC="@echo f77" OUTPUT_OPTION=', "f77 -c hello.f\n");
338 # builtin rule %.o: %.f is removed.
339 # %.o: %.c (and other builtin rules) are skipped, because hello.c is missing.
340 # ought-to-exist does not apply to hello.c.
341 # %.o: %.c is chosen as a compatibility rule, because of hello.c.
347 "#MAKE#: *** No rule to make target 'hello.c', needed by 'hello.o'. Stop.\n",
352 # In this test the builtin match-anything rule '%: %.f' is used to build
353 # intermediate hello from hello.f, because hello is mentioned explicitly in
357 %.tsk: %; $(info $@ from $<)
359 !, 'FC="@echo f77" OUTPUT_OPTION=',
360 "f77 hello.f -o hello\nhello.tsk from hello\n");
362 # In this test the builtin match-anything rule %: %.f cannot be used to build
363 # intermediate hello from hello.f, because hello is not mentioned explicitly in
367 %.tsk: %; $(info $@ from $<)
368 !, 'FC="@echo f77" OUTPUT_OPTION=',
369 "#MAKE#: *** No rule to make target 'hello.tsk', needed by 'all'. Stop.\n",
372 # This is just like the one above, but compatibility rule '%.tsk: % %.x' has 2
373 # prerequisites, '%' and '%.x'.
374 # '%' expands to 'hello' and matches the explicit 'hello' on the unrelated rule.
375 # '%.x' is an intermediate built from 'hello.xx' by rule '%.x: %.xx' during the
376 # second pass (intermed_ok == 1) of compatibility search.
377 # This test validates that compatibility search performs both intermed_ok == 0
378 # and intermed_ok == 1 passes.
383 %.tsk: % %.x; $(info $@ from $^)
385 %.x: %.xx; $(info $@ from $<)
386 !, 'FC="@echo f77" OUTPUT_OPTION=',
387 "f77 hello.f -o hello\nhello.x from hello.xx\nhello.tsk from hello hello.x\n");
389 unlink('bye.o', 'bye.tsk', 'bye.x');
391 # Default recipe is used to build bye.o.
394 %.tsk: %.o; $(info $@ from $<)
395 .DEFAULT:; $(info bye.o)
397 !, '-r', "bye.o\nbye.tsk from bye.o\n#MAKE#: Nothing to be done for 'all'.");
400 # This is just like the one above, but compatibility rule '%.tsk: %.o %.x' has 2
401 # prerequisites, '%.o' and '%.x'.
402 # '%.o' expands to 'bye.o' and matches the explicit 'bye.o' on the unrelated rule.
403 # '%.x' is an intermediate built from 'bye.xx' by rule '%.x: %.xx' during the
404 # second pass (intermed_ok == 1) of compatibility search.
405 # This test validates that compatibility search performs both intermed_ok == 0
406 # and intermed_ok == 1 passes.
409 %.tsk: %.o %.x; $(info $@ from $^)
410 .DEFAULT:; $(info bye.o)
412 %.x: %.xx; $(info $@ from $<)
414 "bye.o\nbye.x from bye.xx\nbye.tsk from bye.o bye.x\n#MAKE#: Nothing to be done for 'all'.");
416 unlink('hello.f', 'hello.z', 'hello.xx', 'bye.xx');
419 # A target specific variable causes the file to be entered to the database as a
420 # prerequisite. Implicit search then treats this file as explicitly mentioned.
421 # Test that implicit search keeps target specific variables of this file intact.
422 # In this series of tests prerequisite 'hello.x' has a target specific variable
423 # and is built as an intermediate. Implicit search treats 'hello.x' as
424 # explicitly mentioned, but 'hello.x' does not qualify as ought-to-exist.
425 unlink('hello.x', 'hello.tsk');
427 # 'hello.x' is mentioned explicitly on the same implicit rule.
430 %.tsk: hello.x; $(info $@)
433 !, '-r', "true\nhello.tsk\n");
435 # Similar to the one above, but this time 'hello.x' is derived from the stem.
438 %.tsk: %.x; $(info $@)
441 !, '-r', "true\nhello.tsk\n");
443 # Similar to the one above, this time 'hello.x' is also mentioned explicitly on
447 %.tsk: %.x; $(info $@)
451 !, '-r', "true\nhello.tsk\n");
453 # 'hello.x' has a pattern specific variable.
456 %.tsk: %.x; $(info $@)
459 !, '-r', "true\nhello.tsk\n");
461 # 'hello.x' has a target specific variable and a pattern specific variable.
464 %.tsk: %.x; $(info $@)
468 !, '-r', "true good\nhello.tsk\n");
470 # Intermediate prerequisite 'hello.x' has a target specific variable, a pattern
471 # specfic variable, matches on both rules '%.tsk: %.x' and 'big_%.tsk: %.x'.
473 all: hello.tsk big_hello.tsk
474 %.tsk: %.x; $(info $@)
475 big_%.tsk: %.x; $(info $@)
479 !, '-r', "true good\nhello.tsk\nbig_hello.tsk\n");
482 # This tells the test driver that the perl test script executed properly.