Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / statipattrules
1 #                                                                    -*-perl-*-
2 $description = "Test handling of static pattern rules.";
3
4 $details = "\
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
10 to emacs a .el file";
11
12 &touch('bar.c', 'lose.c');
13
14 #   TEST #0
15 #   -------
16
17 run_make_test('
18 files = foo.elc bar.o lose.o
19
20 $(filter %.o,$(files)): %.o: %.c ; @echo CC -c $(CFLAGS) $< -o $@
21
22 $(filter %.elc,$(files)): %.elc: %.el ; @echo emacs $<
23 ',
24               '',
25               'CC -c bar.c -o bar.o');
26
27 #  TEST #1
28 #  -------
29
30 run_make_test(undef, 'lose.o', 'CC -c lose.c -o lose.o');
31
32
33 #   TEST #2
34 #   -------
35 &touch("foo.el");
36
37 run_make_test(undef, 'foo.elc', 'emacs foo.el');
38
39 # Clean up after the first tests.
40 unlink('foo.el', 'bar.c', 'lose.c');
41
42
43 # TEST #3 -- PR/1670: don't core dump on invalid static pattern rules
44 # -------
45
46 run_make_test('
47 .DEFAULT: ; @echo $@
48 foo: foo%: % %.x % % % y.% % ; @echo $@
49 ',
50               '', ".x\ny.\nfoo");
51
52
53 # TEST #4 -- bug #12180: core dump on a stat pattern rule with an empty
54 #                        prerequisite list.
55 run_make_test('
56 foo.x bar.x: %.x : ; @echo $@
57
58 ',
59               '', 'foo.x');
60
61
62 # TEST #5 -- bug #13881: double colon static pattern rule does not
63 #                        substitute %.
64 run_make_test('
65 foo.bar:: %.bar: %.baz
66 foo.baz: ;@:
67 ',
68               '', '');
69
70
71 # TEST #6: make sure the second stem does not overwrite the first
72 #          perprerequisite's stem (Savannah bug #16053).
73 #
74 run_make_test('
75 .RECIPEPREFIX := >
76
77 all.foo.bar: %.foo.bar: %.one
78
79 all.foo.bar: %.bar: %.two
80
81 all.foo.bar:
82 >       @echo $*
83 >       @echo $^
84
85 .DEFAULT:;@:
86 ',
87 '',
88 'all.foo
89 all.one all.foo.two');
90
91
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).
95 #
96 run_make_test('
97 .RECIPEPREFIX := >
98 .SECONDEXPANSION:
99
100 all.foo.bar: %.foo.bar: %.one $$*-one
101
102 all.foo.bar: %.bar: %.two $$*-two
103
104 all.foo.bar:
105 >       @echo $*
106 >       @echo $^
107
108 .DEFAULT:;@:
109 ',
110 '',
111 'all.foo
112 all.one all-one all.foo.two all.foo-two');
113
114 # Test #8:
115 # sv 60188.
116 # Static pattern rules are considered explicit rules: no prerequisite of
117 # a static pattern rule can ever be considered intermediate.
118
119 touch('hello.z');
120
121 # subtest 1
122 run_make_test(q!
123 hello.z: %.z: %.x ; @echo $@
124 %.x: ;
125 !, '', "hello.z\n");
126
127 # subtest 2
128 run_make_test(q!
129 hello.z: %.z: %.x test.x ; @echo $@
130 %.x: ;
131 !, '', "hello.z\n");
132
133 # subtest 3
134 # 'hello.x' is mentioned explicitly on an unrelated rule.
135 run_make_test(q!
136 hello.z: %.z: %.x ; @echo $@
137 %.x: ;
138 unrelated: hello.x
139 !, '', "hello.z\n");
140
141 unlink('hello.z');
142
143 # sv 17374 Ensure double-colon static pattern rules work
144
145 touch(qw(a.src b.src));
146
147 run_make_test(q!
148 all: a.tgt b.tgt
149 a.tgt b.tgt:: %.tgt : %.src ; cp $< $@
150 !,
151     '', "cp a.src a.tgt\ncp b.src b.tgt\n");
152
153 unlink(qw(a.src b.src a.tgt b.tgt));
154
155 my @dir = ('', 'lib/'); # With and without last slash.
156 my @secondexpansion = ('', '.SECONDEXPANSION:');
157
158 # The following combinations are generated with and without second expansion.
159 # 1.
160 # all: bye.x
161 # bye.x: %.x: ...
162 #
163 # 2.
164 # all: lib/bye.x
165 # lib/bye.x: %.x: ...
166 #
167 # 3.
168 # all: lib/bye.x
169 # lib/bye.x: lib/%.x: ...
170 #
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.
173 # 4.
174 # all: bye.x
175 # bye.x: lib/%.x: ...
176 #
177
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 ? '$' : '';
183
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 : '';
188
189
190 # One func, one %.
191 my $prereqs = "${pdir}bye.1";
192 run_make_test("
193 $se
194 .PHONY: $prereqs
195 all: ${d}bye.x
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");
198
199
200 # Multiple funcs, each has one %.
201 $prereqs = "${pdir}bye.1 ${pdir}bye.2";
202 run_make_test("
203 $se
204 .PHONY: $prereqs
205 all: ${d}bye.x
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");
208
209
210 # Multiple funcs, each has multiple %.
211 $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4";
212 run_make_test("
213 $se
214 .PHONY: $prereqs
215 all: ${d}bye.x
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");
218
219
220 # Multiple funcs, each has multiple %, each prerequisite has multiple %.
221 $prereqs = "${pdir}bye_%_%.1 ${pdir}bye_%_%.2 ${pdir}bye_%_%.3 ${pdir}bye_%_%.4";
222 run_make_test("
223 $se
224 .PHONY: $prereqs
225 all: ${d}bye.x
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");
228
229
230 # Nested functions.
231 $prereqs = "${pdir}bye.1 ${pdir}bye.2 ${pdir}bye.3 ${pdir}bye.4";
232 run_make_test("
233 $se
234 .PHONY: $prereqs
235 all: ${d}bye.x
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");
238
239
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
243 # stem.
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";
245 run_make_test("
246 $se
247 .PHONY: $prereqs
248 all: ${d}bye.x
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");
251
252
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";
259 run_make_test("
260 $se
261 .PHONY: $prereqs
262 all: ${d}bye.x
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");
265 }
266
267
268 # Empty stem.
269 $prereqs = "${pdir}.1";
270 run_make_test("
271 $se
272 .PHONY: $prereqs
273 all: ${d}bye.x
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");
276
277
278 # A word expands to an empty prerequisite.
279 run_make_test("
280 $se
281 all: ${d}bye.x
282 ${d}bye.x: $r%.x: $dollar\$(%); \$(info \$@ from \$^)
283 ", '', "${d}bye.x from \n#MAKE#: Nothing to be done for 'all'.\n");
284
285 }
286 }
287 }
288
289 # Escaped %.
290 # The following combinations are generated without second expansion.
291 # 1.
292 # all: the%weird\\_hello_pattern\\.x
293 # the\\%weird\\_hello_pattern\\.x: the\\%weird\\_%_pattern\\.x: ...
294 #
295 # 2.
296 # all: lib/the%weird\\_hello_pattern\\.x
297 # lib/the\\%weird\\_hello_pattern\\.x: lib/the\\%weird\\_%_pattern\\.x: ...
298 #
299 # Other combinations or second expansion are not tested, because escaped % is
300 # not implemented for those.
301
302 for my $d (@dir) {
303 my $prereqs = "${d}the%weird\\\\_hello_pattern%\\\\.1 ${d}the%weird\\\\_hello_pattern%\\\\.2";
304 run_make_test("
305 .PHONY: $prereqs
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");
309 }
310
311 1;