1 # -*-mode: perl; rm-trailing-spaces: nil-*-
3 $description = "Test various forms of the GNU make 'include' command.";
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.";
11 create_file('incl.mk', "ANOTHER: ; \@echo This is another included makefile\n");
13 run_make_test(qq!#Extra space at the end of the following file name
14 include incl.mk ! . q!
15 all: ; @echo There should be no errors for this makefile.
17 -include nonexistent.mk
18 -include nonexistent.mk
19 sinclude nonexistent.mk
20 sinclude nonexistent-2.mk
26 "all", "There should be no errors for this makefile.\n");
28 run_make_test(undef, "ANOTHER", "This is another included makefile\n");
32 # Try to build the "error" target; this will fail since we don't know
33 # how to create makeit.mk, but we should also get a message (even though
34 # the -include suppressed it during the makefile read phase, we should
35 # see one during the makefile run phase).
40 error: foo.mk ; @echo $@
43 "#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
47 # The same as above with an additional include directory.
49 mkdir('hellod', 0777);
54 error: foo.mk ; @echo $@
57 "#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
63 # Make sure that target-specific variables don't impact things. This could
64 # happen because a file record is created when a target-specific variable is
78 # Test inheritance of dontcare flag when rebuilding makefiles.
90 # Make sure that we don't die when the command fails but we dontcare.
91 # (Savannah bug #13216).
104 # Check include, sinclude, -include with no filenames.
105 # (Savannah bug #1761).
115 # Test that the diagnostics is issued even if the target has been
116 # tried before with the dontcare flag (direct dependency case).
127 "#MAKE#: *** No rule to make target 'baz', needed by 'bar'. Stop.\n",
130 # Test that the diagnostics is issued even if the target has been
131 # tried before with the dontcare flag (indirect dependency case).
143 "#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
146 # Test include of make-able file doesn't show an error (Savannah #102)
156 '', "echo > inc1\necho > inc2\nDONE\n");
158 rmfiles('inc1', 'inc2');
160 # Test include of make-able file doesn't show an error.
161 # Specify an additional include directory.
163 mkdir('hellod', 0777);
174 '-Ihellod', "echo > inc1\necho > inc2\nDONE\n");
176 rmfiles('inc1', 'inc2');
178 # Test include of make-able file doesn't show an error.
179 # inc1 and inc2 are present in the specified include directory.
180 touch('hellod/inc1');
181 touch('hellod/inc2');
192 '-Ihellod', "DONE\n");
194 rmfiles('inc1', 'inc2', 'hellod/inc1', 'hellod/inc2');
198 # No target gets correct error
199 run_make_test("\n", '', '#MAKE#: *** No targets. Stop.', 512);
201 # No target in included file either, still gets correct error.
203 run_make_test('include inc1.mk', '', '#MAKE#: *** No targets. Stop.', 512);
206 # Include same file multiple times
209 default:; @echo DEFAULT
214 '', "echo > inc1\nDEFAULT\n");
218 if (defined $ERR_no_such_file) {
220 # Test that the diagnostics is issued even if the target has been
221 # tried before with the dontcare flag (include/-include case).
234 "#MAKEFILE#:2: bar: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
237 # Test include of non-make-able file does show an error (Savannah #102)
246 '', "echo > inc1\n#MAKEFILE#:7: inc2: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'inc2'. Stop.\n", 512);
250 # Included file has a prerequisite that fails to build
253 default:; @echo DEFAULT
258 '', "exit 1\n#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: foo] Error 1\n", 512);
262 # Included file has a prerequisite we don't know how to build
265 default:; @echo DEFAULT
269 '', "#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'foo', needed by 'inc1'. Stop.\n", 512);
273 # Check that included double-colon targets with no prerequisites aren't
274 # built. This should fail as hello.mk doesn't exist
278 default:;@echo 'FOO=$(FOO)'
280 hello.mk:: ; echo 'FOO=bar' > $@
282 '', "#MAKEFILE#:4: hello.mk: $ERR_no_such_file", 512);
284 # Check that included phony targets aren't built.
285 # This should fail as hello.mk doesn't exist
289 default:;@echo 'FOO=$(FOO)'
291 hello.mk: ; echo 'FOO=bar' > $@
294 '', "#MAKEFILE#:4: hello.mk: $ERR_no_such_file", 512);
297 if (defined $ERR_unreadable_file) {
298 # Including files that can't be read should show an error
300 create_file('inc1', 'FOO := foo');
307 '', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512);
309 # Including files that can't be read should show an error, even when there
310 # is a readable file in a subsequent include directory.
311 mkdir('hellod', 0777);
312 touch("hellod/inc1");
318 '-Ihellod', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512);
320 # Unreadable files that we know how to successfully recreate should work
322 run_make_test(sprintf(q!
325 inc1:; @%s $@ && echo FOO := bar > $@
329 # Unreadable files that we know how to successfully recreate should work.
330 # Even when there is a readable file in an additional include directory.
333 create_file('inc1', 'FOO := foo');
336 run_make_test(sprintf(q!
339 inc1:; @%s $@ && echo FOO := bar > $@
343 rmfiles('inc1', 'hellod/inc1');
347 # Check that the order of remaking include files is correct: should remake
348 # them in the same order they were encountered in the makefile. SV 58735
357 '', "i1\ni2\ni3\ni4\n#MAKE#: 'all' is up to date.\n");
359 # Check that included files work if created after the first include failed
360 # https://savannah.gnu.org/bugs/?57676
363 default:; @echo $(hello)
365 $(shell echo hello=world >hello.mk)
372 # Check that included double-colon targets with no prerequisites aren't built.
373 # This should succeed since hello.mk already exists
379 default:;@echo 'FOO=$(FOO)'
381 hello.mk:: ; echo 'FOO=bar' > $@
387 # Check that included double-colon targets with no prerequisites aren't built.
388 # This should succeed due to -include
392 default:;@echo 'FOO=$(FOO)'
394 hello.mk:: ; echo 'FOO=bar' > $@
398 # Check that phony targets aren't built.
399 # This should succeed since hello.mk already exists
405 default:;@echo 'FOO=$(FOO)'
407 hello.mk: ; echo 'FOO=bar' > $@
414 # Check that included double-colon targets with no prerequisites aren't built.
415 # This should succeed due to -include
419 default:;@echo 'FOO=$(FOO)'
421 hello.mk: ; echo 'FOO=bar' > $@
426 # SV 56301 Verify pattern rules creating optional includes.
427 # -k shouldn't matter when creating include files.
433 %_a.mk %_b.mk:; exit 1
435 '', "exit 1\n#MAKEFILE#:4: Failed to remake makefile 'inc_b.mk'.\n", 512);
437 run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:4: Failed to remake makefile 'inc_b.mk'.\n", 512);
439 # It seems wrong to me that this gives a different error message, but at
440 # least it doesn't keep going.
445 %_a.mk %_b.mk:; exit 1
447 '', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n", 512);
449 run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n#MAKEFILE#:3: Failed to remake makefile 'inc_a.mk'.\n", 512);
451 # Check the default makefiles... this requires us to invoke make with no
452 # arguments. Also check MAKEFILES
454 if ($port_type eq 'W32') {
455 $defaults = "GNUmakefile\nmakefile\nMakefile\nmakefile.mak";
457 $defaults = "GNUmakefile\nmakefile\nMakefile";
460 $ENV{MAKEFILES} = 'foobar barfoo';
461 run_make_with_options(undef, ['-E', '%:;@echo $@', '-E', 'all:;', '-E', '-include bizbaz', '-E', '-include bazbiz'], get_logfile(0));
462 $answer = "bizbaz\nbazbiz\nfoobar\nbarfoo\n$defaults\n#MAKE#: 'all' is up to date.\n";
463 &compare_output(subst_make_string($answer), &get_logfile(1));