1 | # -*-perl-*-
|
---|
2 | $description = "Test second expansion in ordinary rules.";
|
---|
3 |
|
---|
4 | $details = "";
|
---|
5 |
|
---|
6 | use Cwd;
|
---|
7 |
|
---|
8 | $dir = cwd;
|
---|
9 | $dir =~ s,.*/([^/]+)$,../$1,;
|
---|
10 |
|
---|
11 |
|
---|
12 | # Test #1: automatic variables.
|
---|
13 | #
|
---|
14 | run_make_test(q!
|
---|
15 | .SECONDEXPANSION:
|
---|
16 | .DEFAULT: ; @echo '$@'
|
---|
17 |
|
---|
18 | foo.a: bar baz
|
---|
19 |
|
---|
20 | foo.a: biz | buz
|
---|
21 |
|
---|
22 | foo.%: 1.$$@ \
|
---|
23 | 2.$$< \
|
---|
24 | $$(addprefix 3.,$$^) \
|
---|
25 | $$(addprefix 4.,$$+) \
|
---|
26 | 5.$$| \
|
---|
27 | 6.$$*
|
---|
28 | @:
|
---|
29 |
|
---|
30 | 1.foo.a \
|
---|
31 | 2.bar \
|
---|
32 | 3.bar \
|
---|
33 | 3.baz \
|
---|
34 | 3.biz \
|
---|
35 | 4.bar \
|
---|
36 | 4.baz \
|
---|
37 | 4.biz \
|
---|
38 | 5.buz \
|
---|
39 | 6.a:
|
---|
40 | @echo '$@'
|
---|
41 |
|
---|
42 | !,
|
---|
43 | '-j1',
|
---|
44 | '1.foo.a
|
---|
45 | 2.bar
|
---|
46 | 3.bar
|
---|
47 | 3.baz
|
---|
48 | 3.biz
|
---|
49 | 4.bar
|
---|
50 | 4.baz
|
---|
51 | 4.biz
|
---|
52 | 5.buz
|
---|
53 | 6.a
|
---|
54 | bar
|
---|
55 | baz
|
---|
56 | biz
|
---|
57 | buz
|
---|
58 | ');
|
---|
59 |
|
---|
60 |
|
---|
61 | # Test #2: target/pattern -specific variables.
|
---|
62 | #
|
---|
63 | run_make_test(q!
|
---|
64 | .SECONDEXPANSION:
|
---|
65 | foo.x:
|
---|
66 |
|
---|
67 | foo.%: $$(%_a) $$(%_b) bar
|
---|
68 | @:
|
---|
69 |
|
---|
70 | foo.x: x_a := bar
|
---|
71 |
|
---|
72 | %.x: x_b := baz
|
---|
73 |
|
---|
74 | bar baz: ; @echo '$@'
|
---|
75 | !,
|
---|
76 | '', "bar\nbaz\n");
|
---|
77 |
|
---|
78 |
|
---|
79 | # Test #3: order of prerequisites.
|
---|
80 | #
|
---|
81 | run_make_test(q!
|
---|
82 | .SECONDEXPANSION:
|
---|
83 | .DEFAULT: ; @echo '$@'
|
---|
84 |
|
---|
85 | all: foo bar baz
|
---|
86 |
|
---|
87 |
|
---|
88 | # Subtest #1
|
---|
89 | #
|
---|
90 | %oo: %oo.1; @:
|
---|
91 |
|
---|
92 | foo: foo.2
|
---|
93 |
|
---|
94 | foo: foo.3
|
---|
95 |
|
---|
96 | foo.1: ; @echo '$@'
|
---|
97 |
|
---|
98 |
|
---|
99 | # Subtest #2
|
---|
100 | #
|
---|
101 | bar: bar.2
|
---|
102 |
|
---|
103 | %ar: %ar.1; @:
|
---|
104 |
|
---|
105 | bar: bar.3
|
---|
106 |
|
---|
107 | bar.1: ; @echo '$@'
|
---|
108 |
|
---|
109 |
|
---|
110 | # Subtest #3
|
---|
111 | #
|
---|
112 | baz: baz.1
|
---|
113 |
|
---|
114 | baz: baz.2
|
---|
115 |
|
---|
116 | %az: ; @:
|
---|
117 | !,
|
---|
118 | '-j1',
|
---|
119 | 'foo.1
|
---|
120 | foo.2
|
---|
121 | foo.3
|
---|
122 | bar.1
|
---|
123 | bar.2
|
---|
124 | bar.3
|
---|
125 | baz.1
|
---|
126 | baz.2
|
---|
127 | ');
|
---|
128 |
|
---|
129 |
|
---|
130 | # Test #4: stem splitting logic.
|
---|
131 | #
|
---|
132 | run_make_test(q!
|
---|
133 | .SECONDEXPANSION:
|
---|
134 | $(dir)/tmp/bar.o:
|
---|
135 |
|
---|
136 | $(dir)/tmp/foo/bar.c: ; @echo '$@'
|
---|
137 | $(dir)/tmp/bar/bar.c: ; @echo '$@'
|
---|
138 | foo.h: ; @echo '$@'
|
---|
139 |
|
---|
140 | %.o: $$(addsuffix /%.c,foo bar) foo.h
|
---|
141 | @echo '$@: {$<} $^'
|
---|
142 | !,
|
---|
143 | "dir=$dir", "$dir/tmp/foo/bar.c
|
---|
144 | $dir/tmp/bar/bar.c
|
---|
145 | foo.h
|
---|
146 | $dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h
|
---|
147 | ");
|
---|
148 |
|
---|
149 |
|
---|
150 | # Test #5: stem splitting logic and order-only prerequisites.
|
---|
151 | #
|
---|
152 | run_make_test(q!
|
---|
153 | .SECONDEXPANSION:
|
---|
154 | $(dir)/tmp/foo.o: $(dir)/tmp/foo.c
|
---|
155 | $(dir)/tmp/foo.c: ; @echo '$@'
|
---|
156 | bar.h: ; @echo '$@'
|
---|
157 |
|
---|
158 | %.o: %.c|bar.h
|
---|
159 | @echo '$@: {$<} {$|} $^'
|
---|
160 |
|
---|
161 | !,
|
---|
162 | "dir=$dir", "$dir/tmp/foo.c
|
---|
163 | bar.h
|
---|
164 | $dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c
|
---|
165 | ");
|
---|
166 |
|
---|
167 |
|
---|
168 | # Test #6: lack of implicit prerequisites.
|
---|
169 | #
|
---|
170 | run_make_test(q!
|
---|
171 | .SECONDEXPANSION:
|
---|
172 | foo.o: foo.c
|
---|
173 | foo.c: ; @echo '$@'
|
---|
174 |
|
---|
175 | %.o:
|
---|
176 | @echo '$@: {$<} $^'
|
---|
177 | !,
|
---|
178 | '', "foo.c\nfoo.o: {foo.c} foo.c\n");
|
---|
179 |
|
---|
180 |
|
---|
181 | # Test #7: Test stem from the middle of the name.
|
---|
182 | #
|
---|
183 | run_make_test(q!
|
---|
184 | .SECONDEXPANSION:
|
---|
185 | foobarbaz:
|
---|
186 |
|
---|
187 | foo%baz: % $$*.1
|
---|
188 | @echo '$*'
|
---|
189 |
|
---|
190 | bar bar.1:
|
---|
191 | @echo '$@'
|
---|
192 | !,
|
---|
193 | '', "bar\nbar.1\nbar\n");
|
---|
194 |
|
---|
195 |
|
---|
196 | # Test #8: Make sure stem triple-expansion does not happen.
|
---|
197 | #
|
---|
198 | run_make_test(q!
|
---|
199 | .SECONDEXPANSION:
|
---|
200 | foo$$bar:
|
---|
201 |
|
---|
202 | f%r: % $$*.1
|
---|
203 | @echo '$*'
|
---|
204 |
|
---|
205 | oo$$ba oo$$ba.1:
|
---|
206 | @echo '$@'
|
---|
207 | !,
|
---|
208 | '', 'oo$ba
|
---|
209 | oo$ba.1
|
---|
210 | oo$ba
|
---|
211 | ');
|
---|
212 |
|
---|
213 | # Test #9: Check the value of $^
|
---|
214 | run_make_test(q!
|
---|
215 | .SECONDEXPANSION:
|
---|
216 |
|
---|
217 | %.so: | $$(extra) ; @echo $^
|
---|
218 |
|
---|
219 | foo.so: extra := foo.o
|
---|
220 | foo.so:
|
---|
221 | foo.o:
|
---|
222 | !,
|
---|
223 | '', "\n");
|
---|
224 |
|
---|
225 | # Test #10: Test second expansion with second expansion prerequisites
|
---|
226 | # Ensures pattern_search() recurses with SE prereqs.
|
---|
227 | touch('a');
|
---|
228 | run_make_test(q!
|
---|
229 | .SECONDEXPANSION:
|
---|
230 | sim_base_rgg := just_a_name
|
---|
231 | sim_base_src := a
|
---|
232 | sim_base_f := a a a
|
---|
233 | sim_%.f: $${sim_$$*_f}
|
---|
234 | echo $@
|
---|
235 | sim_%.src: $${sim_$$*_src}
|
---|
236 | echo $@
|
---|
237 | sim_%: \
|
---|
238 | $$(if $$(sim_$$*_src),sim_%.src) \
|
---|
239 | $$(if $$(sim_$$*_f),sim_%.f) \
|
---|
240 | $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s)
|
---|
241 | echo $@
|
---|
242 | !,
|
---|
243 | '-s sim_base', "#MAKE#: *** No rule to make target 'sim_base'. Stop.", 512);
|
---|
244 |
|
---|
245 | unlink('a');
|
---|
246 |
|
---|
247 | # Ensure that order-only tokens embedded in second expansions are parsed
|
---|
248 | run_make_test(q!
|
---|
249 | .SECONDEXPANSION:
|
---|
250 | PREREQS=p1|p2
|
---|
251 | P2=p2
|
---|
252 | all : foo bar
|
---|
253 | f%o: $$(PREREQS) ; @echo '$@' from '$^' and '$|'
|
---|
254 | b%r: p1|$$(P2) ; @echo '$@' from '$^' and '$|'
|
---|
255 | p% : ; : $@
|
---|
256 | !,
|
---|
257 | "", ": p1\n: p2\nfoo from p1 and p2\nbar from p1 and p2\n");
|
---|
258 |
|
---|
259 | # This tells the test driver that the perl test script executed properly.
|
---|
260 | 1;
|
---|