Imported Upstream version 4.4
[platform/upstream/make.git] / tests / scripts / features / double_colon
1 #                                                                    -*-perl-*-
2 $description = "Test handling of double-colon rules.";
3
4 $details = "\
5 We test these features:
6
7   - Multiple commands for the same (double-colon) target
8   - Different prerequisites for targets: only out-of-date
9     ones are rebuilt.
10   - Double-colon targets that aren't the goal target.
11
12 Then we do the same thing for parallel builds: double-colon
13 targets should always be built serially.";
14
15 # TEST 0: A simple double-colon rule that isn't the goal target.
16
17 run_make_test(q!
18 all: baz
19
20 foo:: f1.h ; @echo foo FIRST
21 foo:: f2.h ; @echo foo SECOND
22
23 bar:: ; @echo aaa; sleep 1; echo aaa done
24 bar:: ; @echo bbb
25
26 baz:: ; @echo aaa
27 baz:: ; @echo bbb
28
29 biz:: ; @echo aaa
30 biz:: two ; @echo bbb
31
32 two: ; @echo two
33
34 f1.h f2.h: ; @echo $@
35
36 d :: ; @echo ok
37 d :: d ; @echo oops
38 !,
39               "all", "aaa\nbbb\n");
40
41 # TEST 1: As above, in parallel
42
43 if ($parallel_jobs) {
44   run_make_test(undef, "-j10 all", "aaa\nbbb\n");
45 }
46
47 # TEST 2: A simple double-colon rule that is the goal target
48
49 run_make_test(undef, "bar", "aaa\naaa done\nbbb\n");
50
51 # TEST 3: As above, in parallel
52
53 if ($parallel_jobs) {
54   run_make_test(undef, "-j10 bar", "aaa\naaa done\nbbb\n");
55 }
56
57 # TEST 4: Each double-colon rule is supposed to be run individually
58
59 &utouch(-5, 'f2.h');
60 &touch('foo');
61
62 run_make_test(undef, "foo", "f1.h\nfoo FIRST\n");
63
64 # TEST 5: Again, in parallel.
65
66 if ($parallel_jobs) {
67   run_make_test(undef, "-j10 foo", "f1.h\nfoo FIRST\n");
68 }
69
70 # TEST 6: Each double-colon rule is supposed to be run individually
71
72 &utouch(-5, 'f1.h');
73 unlink('f2.h');
74 &touch('foo');
75
76 run_make_test(undef, "foo", "f2.h\nfoo SECOND\n");
77
78 # TEST 7: Again, in parallel.
79
80 if ($parallel_jobs) {
81   run_make_test(undef, "-j10 foo", "f2.h\nfoo SECOND\n");
82 }
83
84 # TEST 8: Test circular dependency check; PR/1671
85
86 run_make_test(undef, "d", "ok\n$make_name: Circular d <- d dependency dropped.\noops\n");
87
88 # TEST 8: I don't grok why this is different than the above, but it is...
89 #
90 # Hmm... further testing indicates this might be timing-dependent?
91 #
92 #if ($parallel_jobs) {
93 #  run_make_test(undef, "-j10 biz", "aaa\ntwo\nbbb\n");
94 #}
95
96 unlink('foo','f1.h','f2.h');
97
98
99 # TEST 9: make sure all rules in s double colon family get executed
100 #         (Savannah bug #14334).
101 #
102
103 &touch('one');
104 &touch('two');
105
106 run_make_test('
107 .RECIPEPREFIX = >
108 .PHONY: all
109 all: result
110
111 result:: one
112 > @echo $^ >>$@
113 > @echo $^
114
115 result:: two
116 > @echo $^ >>$@
117 > @echo $^
118
119 ',
120 '',
121 'one
122 two');
123
124 unlink('result','one','two');
125
126 # TEST 10: SV 33399 : check for proper backslash handling
127
128 run_make_test('
129 a\ xb :: ; @echo one
130 a\ xb :: ; @echo two
131 ',
132               '', "one\ntwo\n");
133
134 # Test 11: SV 44742 : All double-colon rules should be run in parallel build.
135
136 run_make_test('
137 .RECIPEPREFIX = >
138 result :: 01
139 > @echo update
140 > @touch $@
141 result :: 02
142 > @echo update
143 > @touch $@
144 result :: 03
145 > @echo update
146 > @touch $@
147 result :: 04
148 > @echo update
149 > @touch $@
150 result :: 05
151 > @echo update
152 > @touch $@
153 01 02 03 04 05:
154 > @touch 01 02 03 04 05
155 ',
156               '-j10 result', "update\nupdate\nupdate\nupdate\nupdate\n");
157
158 unlink('result', '01', '02', '03', '04', '05');
159
160 # Test 12: SV 44742 : Double-colon rules with parallelism
161
162 run_make_test('
163 root: all ; echo root
164 all:: ; echo all_one
165 all:: 3 ; echo all_two
166 %: ; sleep $*
167 ',
168               '-rs -j2 1 2 root', "all_one\nall_two\nroot\n");
169
170 # SV 47995 : Parallel double-colon rules with FORCE
171
172 run_make_test('
173 all:: ; @echo one
174
175 all:: joe ; @echo four
176
177 joe: FORCE ; touch joe-is-forced
178
179 FORCE:
180 ',
181               '-j5', "one\ntouch joe-is-forced\nfour\n");
182
183 unlink('joe-is-forced');
184
185 # sv 60188.
186 # Even though test.x is explicitly mentioned, terminal pattern rules still
187 # apply only if the prerequisite exists.
188 touch('hello.z');
189
190 # subtest 1. test.x is explicitly mentioned.
191 run_make_test(q!
192 all: hello.z
193 %.z:: test.x ; touch $@
194 %.x: ;
195 !,
196               '', "#MAKE#: Nothing to be done for 'all'.\n");
197
198 unlink('hello.z');
199
200 # subtest 2. hello.x is derived from the stem.
201 touch('hello.z');
202
203 run_make_test(q!
204 all: hello.z
205 %.z:: %.x; touch $@
206 %.x: ; touch $@
207 !,
208               '', "#MAKE#: Nothing to be done for 'all'.\n");
209
210 unlink('hello.z');
211
212 # subtest 3
213 # hello.x is explicitly mentioned on an unrelated rule and thus is not an
214 # intermediate file.
215 # Terminal pattern rules do not apply anyway and there is no rule to built
216 # 'hello.x'.
217 touch('hello.z');
218 run_make_test(q!
219 all: hello.z
220 %.z:: %.x; touch $@
221 %.x: ;
222 unrelated: hello.x
223 !,
224               '', "#MAKE#: *** No rule to make target 'hello.x', needed by 'hello.z'.  Stop.\n", 512);
225
226 unlink('hello.z');
227
228
229 # This tells the test driver that the perl test script executed properly.
230 1;