1999-09-14 10:03:19 +08:00
|
|
|
# -*-mode: perl; rm-trailing-spaces: nil-*-
|
|
|
|
|
2012-03-04 08:24:20 +08:00
|
|
|
$description = "Test various forms of the GNU make 'include' command.";
|
1999-09-14 10:03:19 +08:00
|
|
|
|
2004-05-17 03:16:52 +08:00
|
|
|
$details = "\
|
|
|
|
Test include, -include, sinclude and various regressions involving them.
|
1999-09-14 10:03:19 +08:00
|
|
|
Test extra whitespace at the end of the include, multiple -includes and
|
|
|
|
sincludes (should not give an error) and make sure that errors are reported
|
|
|
|
for targets that were also -included.";
|
|
|
|
|
|
|
|
$makefile2 = &get_tmpfile;
|
|
|
|
|
|
|
|
open(MAKEFILE,"> $makefile");
|
|
|
|
|
|
|
|
# The contents of the Makefile ...
|
|
|
|
|
|
|
|
print MAKEFILE <<EOF;
|
|
|
|
\#Extra space at the end of the following file name
|
2004-09-29 02:13:55 +08:00
|
|
|
include $makefile2
|
1999-09-14 10:03:19 +08:00
|
|
|
all: ; \@echo There should be no errors for this makefile.
|
|
|
|
|
|
|
|
-include nonexistent.mk
|
|
|
|
-include nonexistent.mk
|
|
|
|
sinclude nonexistent.mk
|
|
|
|
sinclude nonexistent-2.mk
|
|
|
|
-include makeit.mk
|
|
|
|
sinclude makeit.mk
|
|
|
|
|
|
|
|
error: makeit.mk
|
|
|
|
EOF
|
|
|
|
|
|
|
|
close(MAKEFILE);
|
|
|
|
|
|
|
|
|
|
|
|
open(MAKEFILE,"> $makefile2");
|
|
|
|
|
|
|
|
print MAKEFILE "ANOTHER: ; \@echo This is another included makefile\n";
|
|
|
|
|
|
|
|
close(MAKEFILE);
|
|
|
|
|
|
|
|
# Create the answer to what should be produced by this Makefile
|
|
|
|
&run_make_with_options($makefile, "all", &get_logfile);
|
|
|
|
$answer = "There should be no errors for this makefile.\n";
|
|
|
|
&compare_output($answer, &get_logfile(1));
|
|
|
|
|
|
|
|
&run_make_with_options($makefile, "ANOTHER", &get_logfile);
|
|
|
|
$answer = "This is another included makefile\n";
|
|
|
|
&compare_output($answer, &get_logfile(1));
|
|
|
|
|
2004-05-17 03:16:52 +08:00
|
|
|
$makefile = undef;
|
|
|
|
|
1999-09-14 10:03:19 +08:00
|
|
|
# Try to build the "error" target; this will fail since we don't know
|
|
|
|
# how to create makeit.mk, but we should also get a message (even though
|
|
|
|
# the -include suppressed it during the makefile read phase, we should
|
|
|
|
# see one during the makefile run phase).
|
|
|
|
|
2004-05-17 03:16:52 +08:00
|
|
|
run_make_test
|
|
|
|
('
|
|
|
|
-include foo.mk
|
|
|
|
error: foo.mk ; @echo $@
|
|
|
|
',
|
|
|
|
'',
|
2012-03-04 08:24:20 +08:00
|
|
|
"#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
|
2004-05-17 03:16:52 +08:00
|
|
|
512
|
|
|
|
);
|
|
|
|
|
2021-09-07 08:20:28 +08:00
|
|
|
# The same as above with an additional include directory.
|
|
|
|
|
|
|
|
mkdir('hellod', 0777);
|
|
|
|
|
|
|
|
run_make_test
|
|
|
|
('
|
|
|
|
-include foo.mk
|
|
|
|
error: foo.mk ; @echo $@
|
|
|
|
',
|
|
|
|
'-Ihellod',
|
|
|
|
"#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
|
|
|
|
512
|
|
|
|
);
|
|
|
|
|
|
|
|
rmdir('hellod');
|
|
|
|
|
2004-05-17 03:16:52 +08:00
|
|
|
# Make sure that target-specific variables don't impact things. This could
|
|
|
|
# happen because a file record is created when a target-specific variable is
|
|
|
|
# set.
|
|
|
|
|
|
|
|
run_make_test
|
|
|
|
('
|
|
|
|
bar.mk: foo := baz
|
|
|
|
-include bar.mk
|
|
|
|
hello: ; @echo hello
|
|
|
|
',
|
|
|
|
'',
|
|
|
|
"hello\n"
|
|
|
|
);
|
2000-01-23 15:05:16 +08:00
|
|
|
|
2005-06-01 04:54:30 +08:00
|
|
|
|
2004-09-29 02:13:55 +08:00
|
|
|
# Test inheritance of dontcare flag when rebuilding makefiles.
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
.PHONY: all
|
|
|
|
all: ; @:
|
|
|
|
|
|
|
|
-include foo
|
|
|
|
|
|
|
|
foo: bar; @:
|
|
|
|
', '', '');
|
1999-09-14 10:03:19 +08:00
|
|
|
|
2005-06-01 04:54:30 +08:00
|
|
|
|
|
|
|
# Make sure that we don't die when the command fails but we dontcare.
|
|
|
|
# (Savannah bug #13216).
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
.PHONY: all
|
|
|
|
all:; @:
|
|
|
|
|
|
|
|
-include foo
|
|
|
|
|
|
|
|
foo: bar; @:
|
|
|
|
|
2005-07-04 11:50:59 +08:00
|
|
|
bar:; @exit 1
|
2005-06-01 04:54:30 +08:00
|
|
|
', '', '');
|
|
|
|
|
2005-06-27 09:01:07 +08:00
|
|
|
# Check include, sinclude, -include with no filenames.
|
|
|
|
# (Savannah bug #1761).
|
|
|
|
|
|
|
|
run_make_test('
|
|
|
|
.PHONY: all
|
|
|
|
all:; @:
|
|
|
|
include
|
|
|
|
-include
|
|
|
|
sinclude', '', '');
|
|
|
|
|
2009-09-30 17:54:26 +08:00
|
|
|
|
|
|
|
# Test that the diagnostics is issued even if the target has been
|
|
|
|
# tried before with the dontcare flag (direct dependency case).
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
-include foo
|
|
|
|
|
|
|
|
all: bar
|
|
|
|
|
|
|
|
foo: baz
|
|
|
|
bar: baz
|
|
|
|
',
|
|
|
|
'',
|
2012-03-04 08:24:20 +08:00
|
|
|
"#MAKE#: *** No rule to make target 'baz', needed by 'bar'. Stop.\n",
|
2009-09-30 17:54:26 +08:00
|
|
|
512);
|
|
|
|
|
|
|
|
# Test that the diagnostics is issued even if the target has been
|
|
|
|
# tried before with the dontcare flag (indirect dependency case).
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
-include foo
|
|
|
|
|
|
|
|
all: bar
|
|
|
|
|
|
|
|
foo: baz
|
|
|
|
bar: baz
|
|
|
|
baz: end
|
|
|
|
',
|
|
|
|
'',
|
2012-03-04 08:24:20 +08:00
|
|
|
"#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
|
2009-09-30 17:54:26 +08:00
|
|
|
512);
|
|
|
|
|
2016-04-10 07:49:27 +08:00
|
|
|
# Test include of make-able file doesn't show an error (Savannah #102)
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:; @echo DONE
|
|
|
|
|
|
|
|
inc1:; echo > $@
|
|
|
|
include inc1
|
|
|
|
include inc2
|
|
|
|
inc2:; echo > $@
|
|
|
|
!,
|
2020-07-20 01:56:23 +08:00
|
|
|
'', "echo > inc1\necho > inc2\nDONE\n");
|
2016-04-10 07:49:27 +08:00
|
|
|
|
|
|
|
rmfiles('inc1', 'inc2');
|
|
|
|
|
2021-09-07 08:20:28 +08:00
|
|
|
# Test include of make-able file doesn't show an error.
|
|
|
|
# Specify an additional include directory.
|
|
|
|
|
|
|
|
mkdir('hellod', 0777);
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:; @echo DONE
|
|
|
|
|
|
|
|
inc1:; echo > $@
|
|
|
|
include inc1
|
|
|
|
include inc2
|
|
|
|
inc2:; echo > $@
|
|
|
|
!,
|
|
|
|
'-Ihellod', "echo > inc1\necho > inc2\nDONE\n");
|
|
|
|
|
|
|
|
rmfiles('inc1', 'inc2');
|
|
|
|
|
|
|
|
# Test include of make-able file doesn't show an error.
|
|
|
|
# inc1 and inc2 are present in the specified include directory.
|
|
|
|
touch('hellod/inc1');
|
|
|
|
touch('hellod/inc2');
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:; @echo DONE
|
|
|
|
|
|
|
|
inc1:; echo > $@
|
|
|
|
include inc1
|
|
|
|
include inc2
|
|
|
|
inc2:; echo > $@
|
|
|
|
!,
|
|
|
|
'-Ihellod', "DONE\n");
|
|
|
|
|
|
|
|
rmfiles('inc1', 'inc2', 'hellod/inc1', 'hellod/inc2');
|
|
|
|
|
|
|
|
rmdir('hellod');
|
|
|
|
|
2016-12-23 05:35:47 +08:00
|
|
|
# No target gets correct error
|
2022-02-27 06:19:42 +08:00
|
|
|
run_make_test("\n", '', '#MAKE#: *** No targets. Stop.', 512);
|
2016-12-23 05:35:47 +08:00
|
|
|
|
|
|
|
# No target in included file either, still gets correct error.
|
|
|
|
touch('inc1.mk');
|
|
|
|
run_make_test('include inc1.mk', '', '#MAKE#: *** No targets. Stop.', 512);
|
|
|
|
rmfiles('inc1.mk');
|
|
|
|
|
2016-04-10 07:49:27 +08:00
|
|
|
# Include same file multiple times
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
default:; @echo DEFAULT
|
|
|
|
include inc1
|
|
|
|
inc1:; echo > $@
|
|
|
|
include inc1
|
|
|
|
!,
|
|
|
|
'', "echo > inc1\nDEFAULT\n");
|
|
|
|
|
|
|
|
rmfiles('inc1');
|
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
if (defined $ERR_no_such_file) {
|
2016-04-10 07:49:27 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
# Test that the diagnostics is issued even if the target has been
|
|
|
|
# tried before with the dontcare flag (include/-include case).
|
|
|
|
#
|
|
|
|
run_make_test('
|
|
|
|
include bar
|
|
|
|
-include foo
|
|
|
|
|
|
|
|
all:
|
|
|
|
|
|
|
|
foo: baz
|
|
|
|
bar: baz
|
|
|
|
baz: end
|
|
|
|
',
|
|
|
|
'',
|
|
|
|
"#MAKEFILE#:2: bar: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
|
|
|
|
512);
|
|
|
|
|
|
|
|
# Test include of non-make-able file does show an error (Savannah #102)
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:; @echo DONE
|
|
|
|
|
|
|
|
inc1:; echo > $@
|
|
|
|
include inc1
|
|
|
|
include inc2
|
|
|
|
!,
|
2020-07-20 01:56:23 +08:00
|
|
|
'', "echo > inc1\n#MAKEFILE#:7: inc2: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'inc2'. Stop.\n", 512);
|
2017-04-18 03:37:57 +08:00
|
|
|
|
|
|
|
rmfiles('inc1');
|
|
|
|
|
|
|
|
# Included file has a prerequisite that fails to build
|
|
|
|
|
|
|
|
run_make_test(q!
|
2016-04-10 07:49:27 +08:00
|
|
|
default:; @echo DEFAULT
|
|
|
|
include inc1
|
|
|
|
inc1: foo; echo > $@
|
|
|
|
foo:; exit 1
|
|
|
|
!,
|
2019-09-23 05:02:57 +08:00
|
|
|
'', "exit 1\n#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: foo] Error 1\n", 512);
|
2016-04-10 07:49:27 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
rmfiles('inc1');
|
2016-04-10 07:49:27 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
# Included file has a prerequisite we don't know how to build
|
2016-04-10 07:49:27 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
run_make_test(q!
|
2016-04-10 07:49:27 +08:00
|
|
|
default:; @echo DEFAULT
|
|
|
|
include inc1
|
|
|
|
inc1: foo; echo > $@
|
|
|
|
!,
|
2017-04-18 03:37:57 +08:00
|
|
|
'', "#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'foo', needed by 'inc1'. Stop.\n", 512);
|
2016-04-10 07:49:27 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
rmfiles('inc1');
|
2021-09-07 05:47:04 +08:00
|
|
|
|
|
|
|
# Check that included double-colon targets with no prerequisites aren't
|
|
|
|
# built. This should fail as hello.mk doesn't exist
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:;@echo 'FOO=$(FOO)'
|
|
|
|
include hello.mk
|
|
|
|
hello.mk:: ; echo 'FOO=bar' > $@
|
|
|
|
!,
|
|
|
|
'', "#MAKEFILE#:4: hello.mk: $ERR_no_such_file", 512);
|
|
|
|
|
|
|
|
# Check that included phony targets aren't built.
|
|
|
|
# This should fail as hello.mk doesn't exist
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:;@echo 'FOO=$(FOO)'
|
|
|
|
include hello.mk
|
|
|
|
hello.mk: ; echo 'FOO=bar' > $@
|
|
|
|
.PHONY: hello.mk
|
|
|
|
!,
|
|
|
|
'', "#MAKEFILE#:4: hello.mk: $ERR_no_such_file", 512);
|
2017-04-18 03:37:57 +08:00
|
|
|
}
|
2016-04-10 07:49:27 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
if (defined $ERR_unreadable_file) {
|
2020-12-06 04:06:25 +08:00
|
|
|
# Including files that can't be read should show an error
|
2021-09-07 08:20:28 +08:00
|
|
|
unlink('inc1');
|
2017-04-18 03:37:57 +08:00
|
|
|
create_file('inc1', 'FOO := foo');
|
|
|
|
chmod 0000, 'inc1';
|
2016-12-26 06:41:50 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
run_make_test(q!
|
2016-12-26 06:41:50 +08:00
|
|
|
include inc1
|
|
|
|
all:;@echo $(FOO)
|
2009-10-04 04:08:20 +08:00
|
|
|
!,
|
2017-04-18 03:37:57 +08:00
|
|
|
'', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512);
|
2016-12-26 06:41:50 +08:00
|
|
|
|
2021-09-07 08:20:28 +08:00
|
|
|
# Including files that can't be read should show an error, even when there
|
|
|
|
# is a readable file in a subsequent include directory.
|
|
|
|
mkdir('hellod', 0777);
|
|
|
|
touch("hellod/inc1");
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
include inc1
|
|
|
|
all:;@echo $(FOO)
|
|
|
|
!,
|
|
|
|
'-Ihellod', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512);
|
|
|
|
|
|
|
|
# Unreadable files that we know how to successfully recreate should work
|
2016-12-26 06:41:50 +08:00
|
|
|
|
2017-04-18 03:37:57 +08:00
|
|
|
run_make_test(sprintf(q!
|
2016-12-26 06:41:50 +08:00
|
|
|
all:;@echo $(FOO)
|
|
|
|
include inc1
|
|
|
|
inc1:; @%s $@ && echo FOO := bar > $@
|
|
|
|
!, $CMD_rmfile),
|
2017-04-18 03:37:57 +08:00
|
|
|
'', "bar");
|
2016-12-26 06:41:50 +08:00
|
|
|
|
2021-09-07 08:20:28 +08:00
|
|
|
# Unreadable files that we know how to successfully recreate should work.
|
|
|
|
# Even when there is a readable file in an additional include directory.
|
|
|
|
|
|
|
|
unlink('inc1');
|
|
|
|
create_file('inc1', 'FOO := foo');
|
|
|
|
chmod 0000, 'inc1';
|
|
|
|
|
|
|
|
run_make_test(sprintf(q!
|
|
|
|
all:;@echo $(FOO)
|
|
|
|
include inc1
|
|
|
|
inc1:; @%s $@ && echo FOO := bar > $@
|
|
|
|
!, $CMD_rmfile),
|
|
|
|
'-Ihellod', "bar");
|
|
|
|
|
|
|
|
rmfiles('inc1', 'hellod/inc1');
|
|
|
|
rmdir('hellod');
|
2017-04-18 03:37:57 +08:00
|
|
|
}
|
2009-10-04 04:08:20 +08:00
|
|
|
|
2020-07-20 01:56:23 +08:00
|
|
|
# Check that the order of remaking include files is correct: should remake
|
|
|
|
# them in the same order they were encountered in the makefile. SV 58735
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
-include i1 i2
|
|
|
|
-include i3
|
|
|
|
-include i4
|
|
|
|
%:;@echo $@
|
|
|
|
all:;
|
|
|
|
!,
|
|
|
|
'', "i1\ni2\ni3\ni4\n#MAKE#: 'all' is up to date.\n");
|
2020-12-06 04:06:25 +08:00
|
|
|
|
|
|
|
# Check that included files work if created after the first include failed
|
|
|
|
# https://savannah.gnu.org/bugs/?57676
|
|
|
|
|
|
|
|
run_make_test(q!
|
2021-09-07 05:47:04 +08:00
|
|
|
default:; @echo $(hello)
|
2020-12-06 04:06:25 +08:00
|
|
|
-include hello.mk
|
|
|
|
$(shell echo hello=world >hello.mk)
|
|
|
|
include hello.mk
|
|
|
|
!,
|
|
|
|
'', "world\n");
|
|
|
|
|
|
|
|
unlink('hello.mk');
|
2020-07-20 01:56:23 +08:00
|
|
|
|
2021-09-07 05:47:04 +08:00
|
|
|
# Check that included double-colon targets with no prerequisites aren't built.
|
|
|
|
# This should succeed since hello.mk already exists
|
|
|
|
|
|
|
|
touch('hello.mk');
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:;@echo 'FOO=$(FOO)'
|
|
|
|
include hello.mk
|
|
|
|
hello.mk:: ; echo 'FOO=bar' > $@
|
|
|
|
!,
|
|
|
|
'', 'FOO=');
|
|
|
|
|
|
|
|
unlink('hello.mk');
|
|
|
|
|
|
|
|
# Check that included double-colon targets with no prerequisites aren't built.
|
|
|
|
# This should succeed due to -include
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:;@echo 'FOO=$(FOO)'
|
|
|
|
-include hello.mk
|
|
|
|
hello.mk:: ; echo 'FOO=bar' > $@
|
|
|
|
!,
|
|
|
|
'', 'FOO=');
|
|
|
|
|
|
|
|
# Check that phony targets aren't built.
|
|
|
|
# This should succeed since hello.mk already exists
|
|
|
|
|
|
|
|
touch('hello.mk');
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:;@echo 'FOO=$(FOO)'
|
|
|
|
include hello.mk
|
|
|
|
hello.mk: ; echo 'FOO=bar' > $@
|
|
|
|
.PHONY: hello.mk
|
|
|
|
!,
|
|
|
|
'', 'FOO=');
|
|
|
|
|
|
|
|
unlink('hello.mk');
|
|
|
|
|
|
|
|
# Check that included double-colon targets with no prerequisites aren't built.
|
|
|
|
# This should succeed due to -include
|
|
|
|
|
|
|
|
run_make_test(q!
|
|
|
|
.PHONY: default
|
|
|
|
default:;@echo 'FOO=$(FOO)'
|
|
|
|
-include hello.mk
|
|
|
|
hello.mk: ; echo 'FOO=bar' > $@
|
|
|
|
.PHONY: hello.mk
|
|
|
|
!,
|
|
|
|
'', 'FOO=');
|
|
|
|
|
2020-07-20 01:56:23 +08:00
|
|
|
# Check the default makefiles... this requires us to invoke make with no
|
|
|
|
# arguments. Also check MAKEFILES
|
|
|
|
|
2021-03-29 04:22:57 +08:00
|
|
|
if ($port_type eq 'W32') {
|
|
|
|
$defaults = "GNUmakefile\nmakefile\nMakefile\nmakefile.mak";
|
|
|
|
} else {
|
|
|
|
$defaults = "GNUmakefile\nmakefile\nMakefile";
|
|
|
|
}
|
|
|
|
|
2020-07-20 01:56:23 +08:00
|
|
|
$ENV{MAKEFILES} = 'foobar barfoo';
|
2021-03-29 04:22:57 +08:00
|
|
|
run_make_with_options(undef, ['-E', '%:;@echo $@', '-E', 'all:;', '-E', '-include bizbaz', '-E', '-include bazbiz'], get_logfile(0));
|
|
|
|
$answer = "bizbaz\nbazbiz\nfoobar\nbarfoo\n$defaults\n#MAKE#: 'all' is up to date.\n";
|
2020-07-20 01:56:23 +08:00
|
|
|
&compare_output(subst_make_string($answer), &get_logfile(1));
|
|
|
|
|
2005-06-01 04:54:30 +08:00
|
|
|
1;
|