]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 28456] Don't override $< when no default rule has been defined
authorMike Haboustak <haboustak@gmail.com>
Fri, 12 Jul 2019 01:08:38 +0000 (21:08 -0400)
committerPaul Smith <psmith@gnu.org>
Sat, 13 Jul 2019 15:47:26 +0000 (11:47 -0400)
The check for matching a file's command to the default rule's command
does not account for null. If no .DEFAULT is defined a rule with no
recipe has it's $< variable set to the value of $@. This breaks second
expansion, particularly when used with pattern rules.

* src/commands.c [set_file_variables]: Check that cmds is set
* tests/scripts/features/se_explicit: Test case
* tests/scripts/features/se_implicit: Test case

Copyright-paperwork-exempt: yes

src/commands.c
tests/scripts/features/se_explicit
tests/scripts/features/se_implicit

index dd47851ddb359e7f3cdeeb1b4497d67904ab1505..ddb664316bc61472099557a88a507b661df42508 100644 (file)
@@ -140,7 +140,7 @@ set_file_variables (struct file *file)
         break;
       }
 
-  if (file->cmds == default_file->cmds)
+  if (file->cmds != 0 && file->cmds == default_file->cmds)
     /* This file got its commands from .DEFAULT.
        In this case $< is the same as $@.  */
     less = at;
index fad3da01c5e2e300bc4445a031164417af040edc..c28641c124981d41decd6392014706614402839b 100644 (file)
@@ -190,4 +190,14 @@ libcat.a: ; @touch $@
 #MAKEFILE#:16: Recipe for 'libcat.a' will be ignored in favor of the one for '-lcat'.!);
 unlink('libcat.a');
 
+# SV 28456 : Don't reset $$< for default recipes
+run_make_test(q!
+.SECONDEXPANSION:
+
+.PHONY: biz baz
+biz: baz ;
+biz: $$(info $$<)
+!,
+              '', "baz\n#MAKE#: Nothing to be done for 'biz'.\n");
+
 1;
index ec09d8daae51ad6b4e21fba4fc82ad5a5ee40f6f..a01b385c4c234cb8a7efdb3dd5d031b228df17c2 100644 (file)
@@ -1,5 +1,5 @@
 #                                                                    -*-perl-*-
-$description = "Test second expansion in ordinary rules.";
+$description = "Test second expansion in implicit rules.";
 
 $details = "";
 
@@ -24,8 +24,7 @@ foo.%: 1.$$@ \
        $$(addprefix 3.,$$^) \
        $$(addprefix 4.,$$+) \
        5.$$| \
-       6.$$*
-       @:
+       6.$$* ; @:
 
 1.foo.a \
 2.bar \
@@ -36,8 +35,7 @@ foo.%: 1.$$@ \
 4.baz \
 4.biz \
 5.buz \
-6.a:
-       @echo '$@'
+6.a: ; @echo '$@'
 
 !,
 '',
@@ -64,8 +62,7 @@ run_make_test(q!
 .SECONDEXPANSION:
 foo.x:
 
-foo.%: $$(%_a) $$(%_b) bar
-       @:
+foo.%: $$(%_a) $$(%_b) bar ; @:
 
 foo.x: x_a := bar
 
@@ -137,8 +134,7 @@ $(dir)/tmp/foo/bar.c: ; @echo '$@'
 $(dir)/tmp/bar/bar.c: ; @echo '$@'
 foo.h: ; @echo '$@'
 
-%.o: $$(addsuffix /%.c,foo bar) foo.h
-       @echo '$@: {$<} $^'
+%.o: $$(addsuffix /%.c,foo bar) foo.h ; @echo '$@: {$<} $^'
 !,
               "dir=$dir", "$dir/tmp/foo/bar.c
 $dir/tmp/bar/bar.c
@@ -155,8 +151,7 @@ $(dir)/tmp/foo.o: $(dir)/tmp/foo.c
 $(dir)/tmp/foo.c: ; @echo '$@'
 bar.h: ; @echo '$@'
 
-%.o: %.c|bar.h
-       @echo '$@: {$<} {$|} $^'
+%.o: %.c|bar.h ; @echo '$@: {$<} {$|} $^'
 
 !,
               "dir=$dir", "$dir/tmp/foo.c
@@ -172,8 +167,7 @@ run_make_test(q!
 foo.o: foo.c
 foo.c: ; @echo '$@'
 
-%.o:
-       @echo '$@: {$<} $^'
+%.o: ; @echo '$@: {$<} $^'
 !,
               '', "foo.c\nfoo.o: {foo.c} foo.c\n");
 
@@ -184,11 +178,9 @@ run_make_test(q!
 .SECONDEXPANSION:
 foobarbaz:
 
-foo%baz: % $$*.1
-       @echo '$*'
+foo%baz: % $$*.1 ; @echo '$*'
 
-bar bar.1:
-       @echo '$@'
+bar bar.1: ; @echo '$@'
 !,
               '', "bar\nbar.1\nbar\n");
 
@@ -199,11 +191,9 @@ run_make_test(q!
 .SECONDEXPANSION:
 foo$$bar:
 
-f%r: % $$*.1
-       @echo '$*'
+f%r: % $$*.1 ; @echo '$*'
 
-oo$$ba oo$$ba.1:
-       @echo '$@'
+oo$$ba oo$$ba.1: ; @echo '$@'
 !,
               '', 'oo$ba
 oo$ba.1
@@ -230,15 +220,12 @@ run_make_test(q!
 sim_base_rgg := just_a_name
 sim_base_src := a
 sim_base_f := a a a
-sim_%.f: $${sim_$$*_f}
-       echo $@
-sim_%.src: $${sim_$$*_src}
-       echo $@
+sim_%.f: $${sim_$$*_f} ; echo $@
+sim_%.src: $${sim_$$*_src} ; echo $@
 sim_%: \
-       $$(if $$(sim_$$*_src),sim_%.src) \
-       $$(if $$(sim_$$*_f),sim_%.f) \
-       $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s)
-       echo $@
+        $$(if $$(sim_$$*_src),sim_%.src) \
+        $$(if $$(sim_$$*_f),sim_%.f) \
+        $$(if $$(sim_$$*_rgg),$$(sim_$$*_rgg).s) ; echo $@
 !,
               '-s sim_base', "#MAKE#: *** No rule to make target 'sim_base'.  Stop.", 512);
 
@@ -256,5 +243,16 @@ p% : ; : $@
 !,
               "", ": p1\n: p2\nfoo from p1 and p2\nbar from p1 and p2\n");
 
+# SV 28456 : Don't reset $$< for default recipes
+run_make_test(q!
+.SECONDEXPANSION:
+
+.PHONY: foo bar
+foo: bar
+foo: $$(info $$<)
+%oo: ;
+!,
+              '', "bar\n#MAKE#: Nothing to be done for 'foo'.\n");
+
 # This tells the test driver that the perl test script executed properly.
 1;