VirtualBox

source: kBuild/trunk/src/kmk/tests/scripts/features/patternrules@ 2591

Last change on this file since 2591 was 2591, checked in by bird, 13 years ago

kmk: Merged in changes from GNU make 3.82. Previous GNU make base version was gnumake-2008-10-28-CVS.

  • Property svn:eol-style set to LF
File size: 3.7 KB
Line 
1# -*-perl-*-
2
3$description = "Test pattern rules.";
4
5$details = "";
6
7use 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
18run_make_test(q!
19.PHONY: all
20
21all: 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
453.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#
51run_make_test('
52TARGETS := foo foo.out
53
54.PHONY: all foo.in
55
56all: $(TARGETS)
57
58%: %.in
59 @echo $@
60
61%.out: %
62 @echo $@
63
64foo.in: ; @:
65
66',
67'',
68'foo
69foo.out');
70
71
72# TEST #2: make sure intermediate files that also happened to be
73# prerequisites are not removed (Savannah bug #12267).
74#
75run_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
88install: $(dir)/foo.c
89
90',
91"dir=$dir",
92"$dir/foo.y
93touch $dir/foo.c
94$dir/foo.o");
95
96unlink("$dir/foo.c");
97
98
99# TEST #3: make sure precious flag is set properly for targets
100# that are built via implicit rules (Savannah bug #13218).
101#
102run_make_test('
103.DELETE_ON_ERROR:
104
105.PRECIOUS: %.bar
106
107%.bar:; @touch $@ && exit 1
108
109$(dir)/foo.bar:
110
111',
112"dir=$dir",
113(!$is_kmk) ?
114"#MAKE#: *** [$dir/foo.bar] Error 1" :
115"#MAKE#: *** [$dir/foo.bar] Error 1" . '
116The failing command:
117 @touch $@ && exit 1',
118512);
119
120unlink("$dir/foo.bar");
121
122
123# TEST #4: make sure targets of a matched implicit pattern rule are
124# never considered intermediate (Savannah bug #13022).
125#
126run_make_test('
127.PHONY: all
128all: foo.c foo.o
129
130%.h %.c: %.in
131 touch $*.h
132 touch $*.c
133
134%.o: %.c %.h
135 echo $+ >$@
136
137%.o: %.c
138 @echo wrong rule
139
140foo.in:
141 touch $@
142
143',
144'-j1',
145'touch foo.in
146touch foo.h
147touch foo.c
148echo foo.c foo.h >foo.o');
149
150unlink('foo.in', 'foo.h', 'foo.c', 'foo.o');
151
152# TEST #5: make sure both prefix and suffix patterns work with multiple
153# target patterns (Savannah bug #26593).
154#
155run_make_test('
156all: foo.s1 foo.s2 p1.foo p2.foo
157
158p1.% p2.%: %.orig
159 @echo $@
160%.s1 %.s2: %.orig
161 @echo $@
162
163.PHONY: foo.orig
164',
165 '', "foo.s1\np1.foo\n");
166
167# TEST 6: Make sure that non-target files are still eligible to be created
168# as part of implicit rule chaining. Savannah bug #17752.
169
170run_make_test(q!
171BIN = xyz
172COPY = $(BIN).cp
173SRC = $(BIN).c
174allbroken: $(COPY) $(BIN) ; @echo ok
175$(SRC): ; @echo 'main(){}' > $@
176%.cp: % ; @cp $< $@
177% : %.c ; @cp $< $@
178clean: ; @rm -rf $(SRC) $(COPY) $(BIN)
179!,
180 '', "ok\n");
181
182unlink(qw(xyz xyz.cp xyz.c));
183
184# TEST 7: Make sure that all prereqs of all "also_make" targets get created
185# before any of the things that depend on any of them. Savannah bug #19108.
186
187run_make_test(q!
188final: x ; @echo $@
189x: x.t1 x.t2 ; @echo $@
190x.t2: dep
191dep: ; @echo $@
192%.t1 %.t2: ; @echo $*.t1 ; echo $*.t2
193!,
194 '', "dep\nx.t1\nx.t2\nx\nfinal\n");
195
196
197# TEST 8: Verify we can remove pattern rules. Savannah bug #18622.
198
199my @f = (qw(foo.w foo.ch));
200touch(@f);
201
202run_make_test(q!
203CWEAVE := :
204
205# Disable builtin rules
206%.tex : %.w
207%.tex : %.w %.ch
208!,
209 'foo.tex',
210 "#MAKE#: *** No rule to make target `foo.tex'. Stop.", 512);
211
212unlink(@f);
213
214# TEST #9: Test shortest stem selection in pattern rules.
215
216run_make_test('
217%.x: ;@echo one
218%-mt.x: ;@echo two
219
220all: foo.x foo-mt.x
221',
222'',
223"one\ntwo");
224
2251;
226
227# This tells the test driver that the perl test script executed properly.
2281;
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette