2 $description = "Test handling of static pattern rules.";
5 The makefile created in this test has three targets. The
6 filter command is used to get those target names ending in
7 .o and statically creates a compile command with the target
8 name and the target name with .c. It also does the same thing
9 for another target filtered with .elc and creates a command
12 &touch('bar.c', 'lose.c');
18 files = foo.elc bar.o lose.o
20 $(filter %.o,$(files)): %.o: %.c ; @echo CC -c $(CFLAGS) $< -o $@
22 $(filter %.elc,$(files)): %.elc: %.el ; @echo emacs $<
25 'CC -c bar.c -o bar.o');
30 run_make_test(undef, 'lose.o', 'CC -c lose.c -o lose.o');
37 run_make_test(undef, 'foo.elc', 'emacs foo.el');
39 # Clean up after the first tests.
40 unlink('foo.el', 'bar.c', 'lose.c');
43 # TEST #3 -- PR/1670: don't core dump on invalid static pattern rules
48 foo: foo%: % %.x % % % y.% % ; @echo $@
53 # TEST #4 -- bug #12180: core dump on a stat pattern rule with an empty
56 foo.x bar.x: %.x : ; @echo $@
62 # TEST #5 -- bug #13881: double colon static pattern rule does not
65 foo.bar:: %.bar: %.baz
71 # TEST #6: make sure the second stem does not overwrite the first
72 # perprerequisite's stem (Savannah bug #16053).
77 all.foo.bar: %.foo.bar: %.one
79 all.foo.bar: %.bar: %.two
89 all.one all.foo.two');
92 # TEST #7: make sure the second stem does not overwrite the first
93 # perprerequisite's stem when second expansion is enabled
94 # (Savannah bug #16053).
100 all.foo.bar: %.foo.bar: %.one $$*-one
102 all.foo.bar: %.bar: %.two $$*-two
112 all.one all-one all.foo.two all.foo-two');
116 # Static pattern rules are considered explicit rules: no prerequisite of
117 # a static pattern rule can ever be considered intermediate.
123 hello.z: %.z: %.x ; @echo $@
129 hello.z: %.z: %.x test.x ; @echo $@
134 # 'hello.x' is mentioned explicitly on an unrelated rule.
136 hello.z: %.z: %.x ; @echo $@
143 # sv 17374 Ensure double-colon static pattern rules work
145 touch(qw(a.src b.src));
149 a.tgt b.tgt:: %.tgt : %.src ; cp $< $@
151 '', "cp a.src a.tgt\ncp b.src b.tgt\n");
153 unlink(qw(a.src b.src a.tgt b.tgt));
155 my @dir = ('', 'lib/'); # With and without last slash.
156 my @secondexpansion = ('', '.SECONDEXPANSION:');
158 # The following combinations are generated with and without second expansion.
165 # lib/bye.x: %.x: ...
169 # lib/bye.x: lib/%.x: ...
171 # The following combination is not generated, because there is no rule to
172 # build bye.x, no stem substitution takes place, not of interest of this test.
175 # bye.x: lib/%.x: ...
178 for my $se (@secondexpansion) {
179 for my $d (@dir) { # The directory of the prerequisite of 'all'.
180 for my $r (@dir) { # The directory of the prerequisite in the rule definition.
181 (!$d && $r) && next; # Combination 4.
182 my $dollar = $se ? '$' : '';
184 # The prerequisite should only have directory if the prerequisite of 'all' has
185 # it and if the prequisite pattern in the rule definition does not have it.
186 # That is combination 2.
187 my $pdir = $d && !$r ? $d : '';
191 my $prereqs = "${pdir}bye.1";
196 ${d}bye.x: $r%.x: $dollar\$(firstword %.1); \$(info \$@ from \$^)
197 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
200 # Multiple funcs, each has one %.
201 $prereqs = "${pdir}bye.1 ${pdir}bye.2";
206 ${d}bye.x: $r%.x: $dollar\$(firstword %.1) $dollar\$(firstword %.2); \$(info \$@ from \$^)
207 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
210 # Multiple funcs, each has multiple %.
211 $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4";
216 ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, %.1 %.2) $dollar\$(wordlist 1, 99, %.3 %.4); \$(info \$@ from \$^)
217 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
220 # Multiple funcs, each has multiple %, each prerequisite has multiple %.
221 $prereqs = "${pdir}bye_%_%.1 ${pdir}bye_%_%.2 ${pdir}bye_%_%.3 ${pdir}bye_%_%.4";
226 ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, %_%_%.1 %_%_%.2) $dollar\$(wordlist 1, 99, %_%_%.3 %_%_%.4); \$(info \$@ from \$^)
227 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
231 $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4";
236 ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, $dollar\$(wordlist 1, 99, %.1 %.2)) $dollar\$(wordlist 1, 99, $dollar\$(wordlist 1,99, %.3 %.4)); \$(info \$@ from \$^)
237 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
240 # Multiple funcs, each has multiple words, each word has multiple %, sole %,
241 # various corner cases.
242 # Make should substitude the first % and only the first % in each word with the
244 $prereqs = "${pdir}bye1%2% ${pdir}bye 3${pdir}bye4%5 6${pdir}bye ${pdir}bye7%8 ${pdir}bye9 ${pdir}bye10% 11${pdir}bye12 13";
249 ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, %1%2% % 3%4%5 6%) %7%8 %9 $dollar\$(wordlist 1, 99, %10% 11%12) 13; \$(info \$@ from \$^)
250 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
253 if ($port_type eq 'UNIX') {
254 # Test that make does not use some hardcoded array of a finite size on stack.
255 # Long prerequisite name. This prerequisite name is over 66K long.
256 my $prefix = 'abcdefgh' x 128 x 33; # 33K long.
257 my $suffix = 'stuvwxyz' x 128 x 33; # 33K long.
258 $prereqs = "${prefix}${pdir}bye${suffix}.1 ${prefix}${pdir}bye${suffix}.2";
263 ${d}bye.x: $r%.x: $dollar\$(wordlist 1, 99, ${prefix}%${suffix}.1 ${prefix}%${suffix}.2); \$(info \$@ from \$^)
264 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
269 $prereqs = "${pdir}.1";
274 ${d}bye.x: $r%bye.x: $dollar\$(firstword %.1); \$(info \$@ from \$^)
275 ", '', "${d}bye.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");
278 # A word expands to an empty prerequisite.
282 ${d}bye.x: $r%.x: $dollar\$(%); \$(info \$@ from \$^)
283 ", '', "${d}bye.x from \n#MAKE#: Nothing to be done for 'all'.\n");
290 # The following combinations are generated without second expansion.
292 # all: the%weird\\_hello_pattern\\.x
293 # the\\%weird\\_hello_pattern\\.x: the\\%weird\\_%_pattern\\.x: ...
296 # all: lib/the%weird\\_hello_pattern\\.x
297 # lib/the\\%weird\\_hello_pattern\\.x: lib/the\\%weird\\_%_pattern\\.x: ...
299 # Other combinations or second expansion are not tested, because escaped % is
300 # not implemented for those.
303 my $prereqs = "${d}the%weird\\\\_hello_pattern%\\\\.1 ${d}the%weird\\\\_hello_pattern%\\\\.2";
306 all: ${d}the%weird\\\\_hello_pattern\\\\.x
307 ${d}the\\%weird\\\\_hello_pattern\\\\.x: ${d}the\\%weird\\\\_%_pattern\\\\.x: \$(wordlist 1, 99, ${d}the\\%weird\\\\_%_pattern%\\\\.1 ${d}the\\%weird\\\\_%_pattern%\\\\.2); \$(info \$@ from \$^)
308 ", '', "${d}the%weird\\\\_hello_pattern\\\\.x from $prereqs\n#MAKE#: Nothing to be done for 'all'.\n");