Debian Codegraph @

tests/scripts/features/patternrules

raw
1 # -*-perl-*-
2
3 $description = "Test pattern rules.";
4
5 $details = "";
6
7 use Cwd;
8
9 $dir = cwd;
10 $dir =~ s,.*/([^/]+)$,../$1,;
11
12
13 # TEST #0: Make sure that multiple patterns where the same target
14 # can be built are searched even if the first one fails
15 # to match properly.
16 #
17
18 run_make_test(q!
19 .PHONY: all
20
21 all: case.1 case.2 case.3
22
23 # We can't have this, due to "Implicit Rule Search Algorithm" step 5c
24 #xxx: void
25
26 # 1 - existing file
27 %.1: void
28 @exit 1
29 %.1: #MAKEFILE#
30 @exit 0
31
32 # 2 - phony
33 %.2: void
34 @exit 1
35 %.2: 2.phony
36 @exit 0
37 .PHONY: 2.phony
38
39 # 3 - implicit-phony
40 %.3: void
41 @exit 1
42 %.3: 3.implicit-phony
43 @exit 0
44
45 3.implicit-phony:
46 !, '', '');
47
48 # TEST #1: make sure files that are built via implicit rules are marked
49 # as targets (Savannah bug #12202).
50 #
51 run_make_test('
52 TARGETS := foo foo.out
53
54 .PHONY: all foo.in
55
56 all: $(TARGETS)
57
58 %: %.in
59 @echo $@
60
61 %.out: %
62 @echo $@
63
64 foo.in: ; @:
65
66 ',
67 '',
68 'foo
69 foo.out');
70
71
72 # TEST #2: make sure intermediate files that also happened to be
73 # prerequisites are not removed (Savannah bug #12267).
74 #
75 run_make_test('
76 $(dir)/foo.o:
77
78 $(dir)/foo.y:
79 @echo $@
80
81 %.c: %.y
82 touch $@
83
84 %.o: %.c
85 @echo $@
86
87 .PHONY: install
88 install: $(dir)/foo.c
89
90 ',
91 "dir=$dir",
92 "$dir/foo.y
93 touch $dir/foo.c
94 $dir/foo.o");
95
96 unlink("$dir/foo.c");
97
98 # FIXME rocky
99 # # TEST #3: make sure precious flag is set properly for targets
100 # # that are built via implicit rules (Savannah bug #13218).
101 # #
102
103 # setup_for_test();
104 # open(MAKEFILE,"> $makefile");
105 # print MAKEFILE '
106 # .DELETE_ON_ERROR:
107
108 # .PRECIOUS: %.bar
109
110 # %.bar:; @touch $@ && exit 1
111
112 # $(dir)/foo.bar:
113
114 # ',
115 # "dir=$dir",
116 # "#MAKE#: *** [#MAKEFILE#:6: $dir/foo.bar] Error 1",
117 # 512);
118
119 # unlink("$dir/foo.bar");
120
121
122 # TEST #4: make sure targets of a matched implicit pattern rule are
123 # never considered intermediate (Savannah bug #13022).
124 #
125 run_make_test('
126 .PHONY: all
127 all: foo.c foo.o
128
129 %.h %.c: %.in
130 touch $*.h
131 touch $*.c
132
133 %.o: %.c %.h
134 echo $+ >$@
135
136 %.o: %.c
137 @echo wrong rule
138
139 foo.in:
140 touch $@
141
142 ',
143 '',
144 'touch foo.in
145 touch foo.h
146 touch foo.c
147 echo foo.c foo.h >foo.o');
148
149 unlink('foo.in', 'foo.h', 'foo.c', 'foo.o');
150
151 # TEST #5: make sure both prefix and suffix patterns work with multiple
152 # target patterns (Savannah bug #26593).
153 #
154 run_make_test('
155 all: foo.s1 foo.s2 p1.foo p2.foo
156
157 p1.% p2.%: %.orig
158 @echo $@
159 %.s1 %.s2: %.orig
160 @echo $@
161
162 .PHONY: foo.orig
163 ',
164 '', "foo.s1\np1.foo\n");
165
166 # TEST 6: Make sure that non-target files are still eligible to be created
167 # as part of implicit rule chaining. Savannah bug #17752.
168
169 run_make_test(sprintf(q!
170 BIN = xyz
171 COPY = $(BIN).cp
172 SRC = $(BIN).c
173 allbroken: $(COPY) $(BIN) ; @echo ok
174 $(SRC): ; @echo 'main(){}' > $@
175 %%.cp: %% ; @cp $< $@
176 %% : %%.c ; @cp $< $@
177 clean: ; @%s $(SRC) $(COPY) $(BIN)
178 !, $CMD_rmfile),
179 '', "ok\n");
180
181 unlink(qw(xyz xyz.cp xyz.c));
182
183 # TEST 7: Make sure that all prereqs of all "also_make" targets get created
184 # before any of the things that depend on any of them. Savannah bug #19108.
185
186 run_make_test(q!
187 final: x ; @echo $@
188 x: x.t1 x.t2 ; @echo $@
189 x.t2: dep
190 dep: ; @echo $@
191 %.t1 %.t2: ; @echo $*.t1 ; echo $*.t2
192 !,
193 '', "dep\nx.t1\nx.t2\nx\nfinal\n");
194
195
196 # TEST 8: Verify we can remove pattern rules. Savannah bug #18622.
197
198 my @f = (qw(foo.w foo.ch));
199 touch(@f);
200
201 run_make_test(q!
202 CWEAVE := :
203
204 # Disable builtin rules
205 %.tex : %.w
206 %.tex : %.w %.ch
207 !,
208 'foo.tex',
209 "#MAKE#: *** No rule to make target 'foo.tex'. Stop.", 512);
210
211 unlink(@f);
212
213 # TEST #9: Test shortest stem selection in pattern rules.
214
215 run_make_test('
216 %.x: ;@echo one
217 %-mt.x: ;@echo two
218
219 all: foo.x foo-mt.x
220 ',
221 '',
222 "one\ntwo");
223
224 1;
225
226 # Test pattern rules building the same targets
227 # See SV 54233. Rely on our standard test timeout to break the loop
228
229 touch('a.c');
230
231 run_make_test(q!
232 all: a.elf a.dbg
233
234 %.elf %.lnk: %.c ; : $*.elf $*.lnk
235
236 %.elf %.dbg: %.lnk ; : $*.elf $*.dbg
237 !,
238 '-j2', ": a.elf a.lnk\n: a.elf a.dbg\n");
239
240 unlink('a.c');
241
242 # SV 56655: Test patterns matching files containing whitespace
243 touch('some file.yy');
244 run_make_test(q!
245 %.xx : %.yy ; @echo matched
246 !, '"some file.xx"', "matched\n");
247
248 unlink('some file.xx', 'some file.yy');
249
250 # This tells the test driver that the perl test script executed properly.
251 1;
252
253 ### Local Variables:
254 ### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
255 ### End: