make/tests/scripts/targets/NOTINTERMEDIATE
Dmitry Goncharov 33468b3f31 [SV 60297] Add .NOTINTERMEDIATE special target
Support a new special target, .NOTINTERMEDIATE.  Any file or pattern
prerequisite of this target will never be considered intermediate.
This differs from .SECONDARY in that .SECONDARY files won't be deleted
but they will still not be built if they are missing.

.NOTINTERMEDIATE files are treated the same way as a target which is
explicitly mentioned in the makefile.  This is mostly useful with
patterns; obviously mentioning a target explicitly here is enough in
and of itself to make something not intermediate.

Some adjustments made by psmith@gnu.org

* NEWS: Announce the new feature.
* doc/make.texi (Special Targets): Document .NOTINTERMEDIATE.
(Chained Rules): Describe how to use .NOTINTERMEDIATE.
* src/main.c (main): Add "notintermediate" to the .FEATURES variable.
* src/filedef.h (struct file): Add "notintermediate" flag.
* src/file.c (no_intermediates): Mark global .NOTINTERMEDIATE.
(snap_file): Support .NOTINTERMEDIATE special target.  Throw an error
if the same target is marked both .NOTINTERMEDIATE and .SECONDARY or
.INTERMEDIATE.
(rehash_file): Merge intermediate, notintermediate, secondary flags.
(remove_intermediates): Check notintermediate flag before removing.
(print_file):
* src/implicit.c (pattern_search): Set notintermediate based on the
pattern.
* tests/scripts/targets/NOTINTERMEDIATE: Add a new test suite.
2021-07-25 17:15:38 -04:00

119 lines
2.8 KiB
Perl

# -*-perl-*-
$description = "Test the behaviour of the .NOTINTERMEDIATE target.";
$details = "\
Test the behavior of the .NOTINTERMEDIATE special target.\n";
touch('hello.z');
unlink('hello.x');
# Test 1. A file which matches a .NOTINTERMEDIATE pattern is not intermediate.
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.NOTINTERMEDIATE: %.q %.x
!, '', "touch hello.z\n");
# Test 2. .NOTINTERMEDIATE: %.q pattern has no effect on hello.x.
touch('hello.z');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.NOTINTERMEDIATE: %.q
!, '', "#MAKE#: 'hello.z' is up to date.\n");
# Test 3. A file which is a prereq of .NOTINTERMEDIATE is not intermediate.
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.NOTINTERMEDIATE: %.q hello.x
!, '', "touch hello.z\n");
# Test 4. .NOTINTERMEDIATE without prerequisites makes everything
# notintermediate.
unlink('hello.z');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.NOTINTERMEDIATE:
!, '', "touch hello.z\n");
# Test 5. Same file cannot be intermediate and notintermediate.
run_make_test(q!
.INTERMEDIATE: hello.x
.NOTINTERMEDIATE: hello.x
!, '', "#MAKE#: *** hello.x cannot be both .NOTINTERMEDIATE and .INTERMEDIATE.. Stop.\n", 512);
# Test 6. Same file cannot be secondary and notintermediate.
run_make_test(q!
.SECONDARY: hello.x
.NOTINTERMEDIATE: hello.x
!, '', "#MAKE#: *** hello.x cannot be both .NOTINTERMEDIATE and .SECONDARY.. Stop.\n", 512);
# Test 7. All .SECONDARY and all .NOTINTERMEDIATE are mutually exclusive.
run_make_test(q!
.SECONDARY:
.NOTINTERMEDIATE:
!, '', "#MAKE#: *** .NOTINTERMEDIATE and .SECONDARY are mutually exclusive. Stop.\n", 512);
# Test 8. .INTERMEDIATE file takes priority over a .NOTINTERMEDIATE pattern.
unlink('hello.x');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.INTERMEDIATE: hello.x
.NOTINTERMEDIATE: %.q %.x
!, '', "#MAKE#: 'hello.z' is up to date.\n");
# Test 9. Everything is notintermediate, except hello.x.
unlink('hello.x');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.INTERMEDIATE: hello.x
.NOTINTERMEDIATE:
!, '', "#MAKE#: 'hello.z' is up to date.\n");
# Test 10. Everything is notintermediate, except hello.x.
unlink('hello.x');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.SECONDARY: hello.x
.NOTINTERMEDIATE:
!, '', "#MAKE#: 'hello.z' is up to date.\n");
# Test 11. Everything is secondary, except %.q, hello.x.
unlink('hello.x');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.NOTINTERMEDIATE: %.q hello.x
.SECONDARY:
!, '', "touch hello.z\n");
# Test 12. Everything is secondary, except %.q %.x.
unlink('hello.x');
run_make_test(q!
hello.z:
%.z: %.x; touch $@
%.x: ;
.NOTINTERMEDIATE: %.q %.x
.SECONDARY:
!, '', "touch hello.z\n");
unlink('hello.z');
# This tells the test driver that the perl test script executed properly.
1;