make/tests/scripts/features/suffixrules

183 lines
3.9 KiB
Text
Raw Normal View History

# -*-perl-*-
$description = "Test suffix rules.";
$details = "";
# TEST #0: Clear all suffixes
touch('foo.c');
run_make_test(q!
.SUFFIXES:
all: foo.o ; @echo $@ $<
!,
'', "#MAKE#: *** No rule to make target 'foo.o', needed by 'all'. Stop.\n", 512);
unlink('foo.c');
# Test #1: Add a simple suffix rule
touch('foo.baz');
run_make_test(q!
.SUFFIXES: .biz .baz
.baz.biz: ; @echo make $@
!,
'foo.biz', "make foo.biz\n");
unlink('foo.baz');
# Test #2: Make sure the defaults still work
touch('foo.c');
run_make_test(undef, 'foo.o COMPILE.c=@echo OUTPUT_OPTION=', "foo.c\n");
unlink('foo.c');
# Test #3: Replacing all suffixes
touch('foo.baz');
run_make_test(q!
.SUFFIXES:
.SUFFIXES: .biz .baz
.baz.biz: ; @echo make $@
!,
'foo.biz', "make foo.biz\n");
unlink('foo.baz');
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 04:14:57 +00:00
# SV 40657: "Suffix rules" with deps are normal rules
my $prewarn = 'warning: ignoring prerequisites on suffix rule definition';
touch('foo.bar');
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 04:14:57 +00:00
# Verify warnings for single-suffix rules
run_make_test(q!
.SUFFIXES:
.SUFFIXES: .baz
.baz: foo.bar ; @echo make $@ from $<
$X.POSIX:
!,
'X=1 .baz', "#MAKEFILE#:5: $prewarn\nmake .baz from foo.bar\n");
# In POSIX mode we don't get a warning
run_make_test(undef, 'X= .baz', "make .baz from foo.bar\n");
# Test double-suffix rules
run_make_test(q!
.SUFFIXES:
.SUFFIXES: .biz .baz
$X.POSIX:
.baz.biz: foo.bar ; @echo make $@ from $<
!,
'X=1 .baz.biz', "#MAKEFILE#:7: $prewarn\nmake .baz.biz from foo.bar\n");
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 04:14:57 +00:00
# SV 40657: In POSIX mode we don't get a warning
run_make_test(undef, 'X= .baz.biz', "make .baz.biz from foo.bar\n");
unlink('foo.bar');
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 04:14:57 +00:00
# SV 40657: In POSIX mode, no pattern rules should be created
utouch(-20, 'foo.baz');
run_make_test(undef,
'X= foo.biz', "#MAKE#: *** No rule to make target 'foo.biz'. Stop.\n", 512);
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 04:14:57 +00:00
# SV 40657: In Non-POSIX mode, a pattern rule is created
run_make_test(undef,
'X=1 foo.biz', "#MAKEFILE#:7: $prewarn\nmake foo.biz from foo.baz\n");
[SV 64571] Add --print-targets option Add an option to print a list of targets defined in the makefiles. Don't print targets of implicit rules, or special targets. To support this remember which files are deemed suffix rule targets. Add a missing warning for single-suffix targets with prerequisites. Suggested by many. Sample implementation by Tim <tdhutt@gmail.com>. * NEWS: Announce the new option and single-suffix warning. * doc/make.1: Add --print-targets to the man page. * doc/make.texi: Add --print-targets to the documentation. Clean up the text around the definition of suffix rules. * src/main.c (print_targets_flag): New variable for --print-targets. (switches): Add a new long option --print-targets. (main): If the option was provided call print_targets() and exit. * src/filedef.h (struct file): Add a "suffix" boolean value. Remove print_prereqs() since it's static. Add new print_targets(). * src/file.c (rehash_file): Merge the new suffix value. (print_prereqs): Used only locally: change to static. (print_target): Print targets which are not suffix rule targets and are not special targets. (print_targets): Call print_target() on each file. * src/rule.c (convert_to_pattern): Make maxsuffix local; it doesn't need to be static. Emit ignoring prerequisites for single-suffix rules as well as double-suffix rules. Remember which files are actually suffix rules. * tests/scripts/features/suffixrules: Test single-suffix behavior. * tests/scripts/options/print-targets: Add tests for --print-targets.
2024-01-09 04:14:57 +00:00
# SV 40657: ... but any prerequisites are ignored
utouch(-10, 'foo.biz');
touch('foo.bar');
run_make_test(undef,
'X=1 foo.biz', "#MAKEFILE#:7: $prewarn\n#MAKE#: 'foo.biz' is up to date.\n");
unlink('foo.baz', 'foo.biz', 'foo.bar');
touch('hello.c');
unlink('hello.o');
# sv 63821.
# Default suffix rule .c.o.
run_make_test('all: hello.o', 'COMPILE.c=@echo OUTPUT_OPTION=', 'hello.c');
# User defined rules beat built-in rules.
run_make_test(q!
all: hello.o
.c.o:; $(info $@ user defined .c.o rule)
!, '', "hello.o user defined .c.o rule\n#MAKE#: Nothing to be done for 'all'.\n");
# sv 63821.
# The same as above, but suffixes are cleared.
run_make_test(q!
all: hello.o
.SUFFIXES:
.c.o:; $(info $@ user defined .c.o rule)
!, '', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.\n", 512);
# sv 63821.
# Suffixes are cleared and defined in the makefile.
run_make_test(q!
all: hello.o
.SUFFIXES:
.SUFFIXES: .c .o
.c.o:; $(info $@ user defined .c.o rule)
!, '', "hello.o user defined .c.o rule\n#MAKE#: Nothing to be done for 'all'.\n");
# sv 63821.
# When built-in rules are disabled, but certain suffixes are added to
# .SUFFIXES, make should exit with the 'No rule...' error message.
run_make_test(q!
.SUFFIXES: .c .o
all: hello.o
!, '-r', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.\n", 512);
# sv 63821.
# Same as above, but this time built-in rules are disabled inside the makefile.
run_make_test(q!
MAKEFLAGS += -r
.SUFFIXES: .c .o
all: hello.o
!, '', "#MAKE#: *** No rule to make target 'hello.o', needed by 'all'. Stop.\n", 512);
# sv 63821.
# Same as above, but this time there is a rule.
run_make_test(q!
all: hello.o
MAKEFLAGS += -r
.SUFFIXES: .c .o
.c.o:; $(info $@ user defined .c.o rule)
!, '', "hello.o user defined .c.o rule\n#MAKE#: Nothing to be done for 'all'.\n");
unlink('hello.c', 'hello.o');
# Complete
1;