1 | # -*-mode: perl; rm-trailing-spaces: nil-*-
|
---|
2 |
|
---|
3 | $description = "Test various forms of the GNU make 'include' command.";
|
---|
4 |
|
---|
5 | $details = "\
|
---|
6 | Test include, -include, sinclude and various regressions involving them.
|
---|
7 | Test extra whitespace at the end of the include, multiple -includes and
|
---|
8 | sincludes (should not give an error) and make sure that errors are reported
|
---|
9 | for targets that were also -included.";
|
---|
10 |
|
---|
11 | $makefile2 = &get_tmpfile;
|
---|
12 |
|
---|
13 | open(MAKEFILE,"> $makefile");
|
---|
14 |
|
---|
15 | # The contents of the Makefile ...
|
---|
16 |
|
---|
17 | print MAKEFILE <<EOF;
|
---|
18 | \#Extra space at the end of the following file name
|
---|
19 | include $makefile2
|
---|
20 | all: ; \@echo There should be no errors for this makefile.
|
---|
21 |
|
---|
22 | -include nonexistent.mk
|
---|
23 | -include nonexistent.mk
|
---|
24 | sinclude nonexistent.mk
|
---|
25 | sinclude nonexistent-2.mk
|
---|
26 | -include makeit.mk
|
---|
27 | sinclude makeit.mk
|
---|
28 |
|
---|
29 | error: makeit.mk
|
---|
30 | EOF
|
---|
31 |
|
---|
32 | close(MAKEFILE);
|
---|
33 |
|
---|
34 |
|
---|
35 | open(MAKEFILE,"> $makefile2");
|
---|
36 |
|
---|
37 | print MAKEFILE "ANOTHER: ; \@echo This is another included makefile\n";
|
---|
38 |
|
---|
39 | close(MAKEFILE);
|
---|
40 |
|
---|
41 | # Create the answer to what should be produced by this Makefile
|
---|
42 | &run_make_with_options($makefile, "all", &get_logfile);
|
---|
43 | $answer = "There should be no errors for this makefile.\n";
|
---|
44 | &compare_output($answer, &get_logfile(1));
|
---|
45 |
|
---|
46 | &run_make_with_options($makefile, "ANOTHER", &get_logfile);
|
---|
47 | $answer = "This is another included makefile\n";
|
---|
48 | &compare_output($answer, &get_logfile(1));
|
---|
49 |
|
---|
50 | $makefile = undef;
|
---|
51 |
|
---|
52 | # Try to build the "error" target; this will fail since we don't know
|
---|
53 | # how to create makeit.mk, but we should also get a message (even though
|
---|
54 | # the -include suppressed it during the makefile read phase, we should
|
---|
55 | # see one during the makefile run phase).
|
---|
56 |
|
---|
57 | run_make_test
|
---|
58 | ('
|
---|
59 | -include foo.mk
|
---|
60 | error: foo.mk ; @echo $@
|
---|
61 | ',
|
---|
62 | '',
|
---|
63 | "#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
|
---|
64 | 512
|
---|
65 | );
|
---|
66 |
|
---|
67 | # Make sure that target-specific variables don't impact things. This could
|
---|
68 | # happen because a file record is created when a target-specific variable is
|
---|
69 | # set.
|
---|
70 |
|
---|
71 | run_make_test
|
---|
72 | ('
|
---|
73 | bar.mk: foo := baz
|
---|
74 | -include bar.mk
|
---|
75 | hello: ; @echo hello
|
---|
76 | ',
|
---|
77 | '',
|
---|
78 | "hello\n"
|
---|
79 | );
|
---|
80 |
|
---|
81 |
|
---|
82 | # Test inheritance of dontcare flag when rebuilding makefiles.
|
---|
83 | #
|
---|
84 | run_make_test('
|
---|
85 | .PHONY: all
|
---|
86 | all: ; @:
|
---|
87 |
|
---|
88 | -include foo
|
---|
89 |
|
---|
90 | foo: bar; @:
|
---|
91 | ', '', '');
|
---|
92 |
|
---|
93 |
|
---|
94 | # Make sure that we don't die when the command fails but we dontcare.
|
---|
95 | # (Savannah bug #13216).
|
---|
96 | #
|
---|
97 | run_make_test('
|
---|
98 | .PHONY: all
|
---|
99 | all:; @:
|
---|
100 |
|
---|
101 | -include foo
|
---|
102 |
|
---|
103 | foo: bar; @:
|
---|
104 |
|
---|
105 | bar:; @exit 1
|
---|
106 | ', '', '');
|
---|
107 |
|
---|
108 | # Check include, sinclude, -include with no filenames.
|
---|
109 | # (Savannah bug #1761).
|
---|
110 |
|
---|
111 | run_make_test('
|
---|
112 | .PHONY: all
|
---|
113 | all:; @:
|
---|
114 | include
|
---|
115 | -include
|
---|
116 | sinclude', '', '');
|
---|
117 |
|
---|
118 |
|
---|
119 | # Test that the diagnostics is issued even if the target has been
|
---|
120 | # tried before with the dontcare flag (direct dependency case).
|
---|
121 | #
|
---|
122 | run_make_test('
|
---|
123 | -include foo
|
---|
124 |
|
---|
125 | all: bar
|
---|
126 |
|
---|
127 | foo: baz
|
---|
128 | bar: baz
|
---|
129 | ',
|
---|
130 | '',
|
---|
131 | "#MAKE#: *** No rule to make target 'baz', needed by 'bar'. Stop.\n",
|
---|
132 | 512);
|
---|
133 |
|
---|
134 | # Test that the diagnostics is issued even if the target has been
|
---|
135 | # tried before with the dontcare flag (indirect dependency case).
|
---|
136 | #
|
---|
137 | run_make_test('
|
---|
138 | -include foo
|
---|
139 |
|
---|
140 | all: bar
|
---|
141 |
|
---|
142 | foo: baz
|
---|
143 | bar: baz
|
---|
144 | baz: end
|
---|
145 | ',
|
---|
146 | '',
|
---|
147 | "#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
|
---|
148 | 512);
|
---|
149 |
|
---|
150 | # Test that the diagnostics is issued even if the target has been
|
---|
151 | # tried before with the dontcare flag (include/-include case).
|
---|
152 | #
|
---|
153 | run_make_test('
|
---|
154 | include bar
|
---|
155 | -include foo
|
---|
156 |
|
---|
157 | all:
|
---|
158 |
|
---|
159 | foo: baz
|
---|
160 | bar: baz
|
---|
161 | baz: end
|
---|
162 | ',
|
---|
163 | '',
|
---|
164 | "#MAKEFILE#:2: bar: No such file or directory
|
---|
165 | #MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
|
---|
166 | 512);
|
---|
167 |
|
---|
168 | # Test include of make-able file doesn't show an error (Savannah #102)
|
---|
169 | run_make_test(q!
|
---|
170 | .PHONY: default
|
---|
171 | default:; @echo DONE
|
---|
172 |
|
---|
173 | inc1:; echo > $@
|
---|
174 | include inc1
|
---|
175 | include inc2
|
---|
176 | inc2:; echo > $@
|
---|
177 | !,
|
---|
178 | '', "echo > inc2\necho > inc1\nDONE\n");
|
---|
179 |
|
---|
180 | rmfiles('inc1', 'inc2');
|
---|
181 |
|
---|
182 | # Test include of non-make-able file does show an error (Savannah #102)
|
---|
183 | run_make_test(q!
|
---|
184 | .PHONY: default
|
---|
185 | default:; @echo DONE
|
---|
186 |
|
---|
187 | inc1:; echo > $@
|
---|
188 | include inc1
|
---|
189 | include inc2
|
---|
190 | !,
|
---|
191 | '', "#MAKEFILE#:7: inc2: No such file or directory\n#MAKE#: *** No rule to make target 'inc2'. Stop.\n", 512);
|
---|
192 |
|
---|
193 | rmfiles('inc1');
|
---|
194 |
|
---|
195 | # Include same file multiple times
|
---|
196 |
|
---|
197 | run_make_test(q!
|
---|
198 | default:; @echo DEFAULT
|
---|
199 | include inc1
|
---|
200 | inc1:; echo > $@
|
---|
201 | include inc1
|
---|
202 | !,
|
---|
203 | '', "echo > inc1\nDEFAULT\n");
|
---|
204 |
|
---|
205 | rmfiles('inc1');
|
---|
206 |
|
---|
207 | # Included file has a prerequisite that fails to build
|
---|
208 |
|
---|
209 | run_make_test(q!
|
---|
210 | default:; @echo DEFAULT
|
---|
211 | include inc1
|
---|
212 | inc1: foo; echo > $@
|
---|
213 | foo:; exit 1
|
---|
214 | !,
|
---|
215 | '', "exit 1\n#MAKEFILE#:3: inc1: No such file or directory\n#MAKE#: *** [#MAKEFILE#:5: foo] Error 1\n", 512);
|
---|
216 |
|
---|
217 | rmfiles('inc1');
|
---|
218 |
|
---|
219 | # Included file has a prerequisite we don't know how to build
|
---|
220 |
|
---|
221 | run_make_test(q!
|
---|
222 | default:; @echo DEFAULT
|
---|
223 | include inc1
|
---|
224 | inc1: foo; echo > $@
|
---|
225 | !,
|
---|
226 | '', "#MAKEFILE#:3: inc1: No such file or directory\n#MAKE#: *** No rule to make target 'foo', needed by 'inc1'. Stop.\n", 512);
|
---|
227 |
|
---|
228 | rmfiles('inc1');
|
---|
229 |
|
---|
230 | # include a directory
|
---|
231 |
|
---|
232 | if ($all_tests) {
|
---|
233 | # Test that include of a rebuild-able file doesn't show a warning
|
---|
234 | # Savannah bug #102
|
---|
235 | run_make_test(q!
|
---|
236 | include foo
|
---|
237 | foo: ; @echo foo = bar > $@
|
---|
238 | !,
|
---|
239 | '', "#MAKE#: 'foo' is up to date.\n");
|
---|
240 | rmfiles('foo');
|
---|
241 | }
|
---|
242 |
|
---|
243 | 1;
|
---|