Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / se_statpat
1 #                                                                    -*-perl-*-
2 $description = "Test second expansion in static pattern rules.";
3
4 $details = "";
5
6 # Test #1: automatic variables.
7 #
8 run_make_test(q!
9 .SECONDEXPANSION:
10 .DEFAULT: ; @echo '$@'
11
12 foo.a foo.b: foo.%: bar.% baz.%
13 foo.a foo.b: foo.%: biz.% | buz.%
14
15 foo.a foo.b: foo.%: $$@.1 \
16                     $$<.2 \
17                     $$(addsuffix .3,$$^) \
18                     $$(addsuffix .4,$$+) \
19                     $$|.5 \
20                     $$*.6
21 !,
22               '', 'bar.a
23 baz.a
24 biz.a
25 buz.a
26 foo.a.1
27 bar.a.2
28 bar.a.3
29 baz.a.3
30 biz.a.3
31 bar.a.4
32 baz.a.4
33 biz.a.4
34 buz.a.5
35 a.6
36 ');
37
38
39 # Test #2: target/pattern -specific variables.
40 #
41 run_make_test(q!
42 .SECONDEXPANSION:
43 .DEFAULT: ; @echo '$@'
44
45 foo.x foo.y: foo.%: $$(%_a) $$($$*_b)
46
47 foo.x: x_a := bar
48
49 %.x: x_b := baz
50 !,
51               '', "bar\nbaz\n");
52
53
54 # Test #3: order of prerequisites.
55 #
56 run_make_test(q!
57 .SECONDEXPANSION:
58 .DEFAULT: ; @echo '$@'
59
60 all: foo.a bar.a baz.a
61
62 # Subtest #1
63 foo.a foo.b: foo.%: foo.%.1; @:
64 foo.a foo.b: foo.%: foo.%.2
65 foo.a foo.b: foo.%: foo.%.3
66
67
68 # Subtest #2
69 bar.a bar.b: bar.%: bar.%.2
70 bar.a bar.b: bar.%: bar.%.1; @:
71 bar.a bar.b: bar.%: bar.%.3
72
73
74 # Subtest #3
75 baz.a baz.b: baz.%: baz.%.1
76 baz.a baz.b: baz.%: baz.%.2
77 baz.a baz.b: ; @:
78 !,
79              '', 'foo.a.1
80 foo.a.2
81 foo.a.3
82 bar.a.1
83 bar.a.2
84 bar.a.3
85 baz.a.1
86 baz.a.2
87 ');
88
89
90 # Test #4: Make sure stem triple-expansion does not happen.
91 #
92 run_make_test(q!
93 .SECONDEXPANSION:
94 foo$$bar: f%r: % $$*.1 ; @echo '$*'
95
96 oo$$ba oo$$ba.1: ; @echo '$@'
97 !,
98               '', 'oo$ba
99 oo$ba.1
100 oo$ba
101 ');
102
103 # sv 62324.
104 # Integrity self check.
105 run_make_test(q!
106 .SECONDEXPANSION:
107 all: bye.x
108 bye.x: %.x: $$(firstword %.1;
109 !, '', "#MAKEFILE#:4: *** unterminated call to function 'firstword': missing ')'.  Stop.", 512);
110
111 #unlink('hello.tsk', 'bye.tsk', 'hello.o', 'hello.q', 'bye.o');
112
113 # sv 62706.
114 # Test that makes avoids second expanding prerequisites of the targets which
115 # are not built.
116 # Here, hello.tsk is built and its prerequisites are second expanded.
117 # bye.tsk is not built and its prerequisites are not second expanded.
118
119 # Static pattern rules.
120 run_make_test(q!
121 .SECONDEXPANSION:
122 hello.tsk: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<)
123 bye.tsk: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<)
124 hello.o: $$(info second expansion of $$@ prereqs); $(info $@)
125 bye.o: $$(info second expansion of $$@ prereqs); $(info $@)
126 !, 'hello.tsk',
127 "second expansion of hello.tsk prereqs
128 second expansion of hello.o prereqs
129 hello.o
130 hello.tsk from hello.o
131 #MAKE#: 'hello.tsk' is up to date.\n");
132
133 # sv 62706.
134 # Order only prereqs.
135 run_make_test(q!
136 .SECONDEXPANSION:
137 hello.tsk: %.tsk:| %.o $$(info second expansion of $$@ prereqs); $(info $@ from $|)
138 bye.tsk: %.tsk:| %.o $$(info second expansion of $$@ prereqs); $(info $@ from $|)
139 hello.o:| $$(info second expansion of $$@ prereqs); $(info $@)
140 bye.o:| $$(info second expansion of $$@ prereqs); $(info $@)
141 !, 'hello.tsk',
142 "second expansion of hello.tsk prereqs
143 second expansion of hello.o prereqs
144 hello.o
145 hello.tsk from hello.o
146 #MAKE#: 'hello.tsk' is up to date.\n");
147
148 # sv 62706.
149 # Double colon. 1 rule per target.
150 run_make_test(q!
151 .SECONDEXPANSION:
152 hello.tsk:: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<)
153 bye.tsk:: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $<)
154 hello.o:: $$(info second expansion of $$@ prereqs); $(info $@)
155 bye.o:: $$(info second expansion of $$@ prereqs); $(info $@)
156 !, 'hello.tsk',
157 "second expansion of hello.tsk prereqs
158 second expansion of hello.o prereqs
159 hello.o
160 hello.tsk from hello.o
161 #MAKE#: 'hello.tsk' is up to date.\n");
162
163 # sv 62706.
164 # Double colon. 2 rules per target.
165 run_make_test(q!
166 .SECONDEXPANSION:
167 hello.tsk:: %.tsk: %.o $$(info 1 second expansion of $$@ prereqs); $(info 1 $@ from $<)
168 hello.tsk:: %.tsk: %.o $$(info 2 second expansion of $$@ prereqs); $(info 2 $@ from $<)
169 bye.tsk:: %.tsk: %.o $$(info 1 second expansion of $$@ prereqs); $(info 1 $@ from $<)
170 bye.tsk:: %.tsk: %.o $$(info 2 second expansion of $$@ prereqs); $(info 2 $@ from $<)
171 hello.o:: $$(info 1 second expansion of $$@ prereqs); $(info 1 $@)
172 hello.o:: $$(info 2 second expansion of $$@ prereqs); $(info 2 $@)
173 bye.o:: $$(info 1 second expansion of $$@ prereqs); $(info 1 $@)
174 bye.o:: $$(info 2 second expansion of $$@ prereqs); $(info 2 $@)
175 !, 'hello.tsk',
176 "1 second expansion of hello.tsk prereqs
177 1 second expansion of hello.o prereqs
178 1 hello.o
179 2 second expansion of hello.o prereqs
180 2 hello.o
181 1 hello.tsk from hello.o
182 2 second expansion of hello.tsk prereqs
183 2 hello.tsk from hello.o
184 #MAKE#: 'hello.tsk' is up to date.\n");
185
186 # sv 62706.
187 # Test that the prerequisites of 'hello.tsk' are second expanded once.
188 run_make_test(q!
189 .SECONDEXPANSION:
190 all: hello.tsk hello.q
191 hello.tsk: %.tsk: %.o $$(info second expansion of $$@ prereqs); $(info $@ from $^)
192 hello.o: $$(info second expansion of $$@ prereqs); $(info $@)
193 hello.q: %.q: %.tsk $$(info second expansion of $$@ prereqs); $(info $@ from $^)
194 !, '',
195 "second expansion of hello.tsk prereqs
196 second expansion of hello.o prereqs
197 hello.o
198 hello.tsk from hello.o
199 second expansion of hello.q prereqs
200 hello.q from hello.tsk
201 #MAKE#: Nothing to be done for 'all'.\n");
202
203 unlink('hello.1');
204
205 # sv 62706.
206 # No side effects from second expansion of unrelated rules.
207 run_make_test(q!
208 .SECONDEXPANSION:
209 all: hello.tsk
210 hello.tsk: %.tsk: %.o; exit 1
211 hello.o:;
212 bye.tsk: %.tsk: $$(shell touch hello.1);
213 !, '',
214 "exit 1
215 #MAKE#: *** [#MAKEFILE#:4: hello.tsk] Error 1\n", 512);
216
217 # sv 62706.
218 # Second expansion of intermediate prerequisites.
219 # The rule to build hello.x is static pattern.
220 # .SECONDARY marks hello.x as intermediate.
221 # Test that $$(deps) is secondary expanded.
222 run_make_test(q!
223 deps:=hello.h
224 .SECONDEXPANSION:
225 .SECONDARY: hello.x
226 all: hello.x
227 hello.x: %.x: $$(deps); $(info $@)
228 hello.h:; $(info $@)
229 !, '', "hello.h\nhello.x\n#MAKE#: Nothing to be done for 'all'.\n");
230
231 # This tells the test driver that the perl test script executed properly.
232 1;