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