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 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
|
# -*-mode: perl-*-
$description = "Test various forms of the GNU Make 'include' command.";
$details = "\
Test include, -include, sinclude and various regressions involving them.
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.";
create_file('incl.mk', "ANOTHER: ; \@echo This is another included makefile\n");
run_make_test(qq!#Extra space at the end of the following file name
include incl.mk ! . q!
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
!,
"all", "There should be no errors for this makefile.\n");
run_make_test(undef, "ANOTHER", "This is another included makefile\n");
unlink('incl.mk');
# 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).
run_make_test
('
-include foo.mk
error: foo.mk ; @echo $@
',
'',
"#MAKE#: *** No rule to make target 'foo.mk', needed by 'error'. Stop.\n",
512
);
# 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');
# 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"
);
# Test inheritance of dontcare flag when rebuilding makefiles.
#
run_make_test('
.PHONY: all
all: ; @:
-include foo
foo: bar; @:
', '', '');
# 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; @:
bar:; @exit 1
', '', '');
# Check include, sinclude, -include with no filenames.
# (Savannah bug #1761).
run_make_test('
.PHONY: all
all:; @:
include
-include
sinclude', '', '');
# 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
',
'',
"#MAKE#: *** No rule to make target 'baz', needed by 'bar'. Stop.\n",
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
',
'',
"#MAKE#: *** No rule to make target 'end', needed by 'baz'. Stop.\n",
512);
# 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 > $@
!,
'', "echo > inc1\necho > inc2\nDONE\n");
rmfiles('inc1', 'inc2');
# 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');
# No target gets correct error
run_make_test("\n", '', '#MAKE#: *** No targets. Stop.', 512);
# 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');
# Include same file multiple times
run_make_test(q!
default:; @echo DEFAULT
include inc1
inc1:; echo > $@
include inc1
!,
'', "echo > inc1\nDEFAULT\n");
rmfiles('inc1');
if (defined $ERR_no_such_file) {
# 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
!,
'', "echo > inc1\n#MAKEFILE#:7: inc2: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'inc2'. Stop.\n", 512);
rmfiles('inc1');
# Included file has a prerequisite that fails to build
run_make_test(q!
default:; @echo DEFAULT
include inc1
inc1: foo; echo > $@
foo:; exit 1
!,
'', "exit 1\n#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: foo] Error 1\n", 512);
rmfiles('inc1');
# Included file has a prerequisite we don't know how to build
run_make_test(q!
default:; @echo DEFAULT
include inc1
inc1: foo; echo > $@
!,
'', "#MAKEFILE#:3: inc1: $ERR_no_such_file\n#MAKE#: *** No rule to make target 'foo', needed by 'inc1'. Stop.\n", 512);
rmfiles('inc1');
# 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);
}
if (defined $ERR_unreadable_file) {
# Including files that can't be read should show an error
unlink('inc1');
create_file('inc1', 'FOO := foo');
chmod 0000, 'inc1';
run_make_test(q!
include inc1
all:;@echo $(FOO)
!,
'', "#MAKEFILE#:2: inc1: $ERR_unreadable_file\n#MAKE#: *** No rule to make target 'inc1'. Stop.", 512);
# 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
run_make_test(sprintf(q!
all:;@echo $(FOO)
include inc1
inc1:; @%s $@ && echo FOO := bar > $@
!, $CMD_rmfile),
'', "bar");
# 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');
}
# 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");
# Check that included files work if created after the first include failed
# https://savannah.gnu.org/bugs/?57676
run_make_test(q!
default:; @echo $(hello)
-include hello.mk
$(shell echo hello=world >hello.mk)
include hello.mk
!,
'', "world\n");
unlink('hello.mk');
# 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=');
# SV 56301 Verify pattern rules creating optional includes.
# -k shouldn't matter when creating include files.
run_make_test(q!
all:; @echo hello
-include inc_a.mk
include inc_b.mk
%_a.mk %_b.mk:; exit 1
!,
'', "exit 1\n#MAKEFILE#:4: Failed to remake makefile 'inc_b.mk'.\n", 512);
run_make_test(undef, '-k', "exit 1\n#MAKEFILE#:4: Failed to remake makefile 'inc_b.mk'.\n", 512);
# It seems wrong to me that this gives a different error message, but at
# least it doesn't keep going.
run_make_test(q!
all:; @echo hello
include inc_a.mk
-include inc_b.mk
%_a.mk %_b.mk:; exit 1
!,
'', "exit 1\n#MAKEFILE#:3: inc_a.mk: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#:5: inc_a.mk] Error 1\n", 512);
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);
# Check the default makefiles... this requires us to invoke make with no
# arguments. Also check MAKEFILES
if ($port_type eq 'W32') {
$defaults = "GNUmakefile\nmakefile\nMakefile\nmakefile.mak";
} else {
$defaults = "GNUmakefile\nmakefile\nMakefile";
}
$ENV{MAKEFILES} = 'foobar barfoo';
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";
&compare_output(subst_make_string($answer), &get_logfile(1));
# SV 63516
if (exists $FEATURES{'dospaths'}) {
run_make_test(q!
include C:__foobar
%bar: ; @echo $@
all: ;
!,
'', "C:__foobar\n#MAKE#: 'all' is up to date.");
}
# sv 63484.
# Test that included makefiles are not intermediate.
# Here 'test.foo' is mentioned explicitly and cannot be considered
# intermediate.
utouch(-10, 'test.foo');
utouch(-5, 'test.x');
touch('test');
run_make_test(q!
.PHONY: force
include test.foo
%.foo: force; @echo force $@
%.x: %.foo; touch $@
test: test.x; touch $@
!, '', "force test.foo\n#MAKE#: 'test' is up to date.\n");
unlink('test.foo', 'test.x', 'test');
1;
|