From ee167c650e53bde545f67152092b4669c76186ef Mon Sep 17 00:00:00 2001 From: Mike Haboustak Date: Thu, 11 Jul 2019 21:08:38 -0400 Subject: [PATCH] [SV 28456] Don't override $< when no default rule has been defined 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 | 2 +- tests/scripts/features/se_explicit | 10 ++++++ tests/scripts/features/se_implicit | 56 ++++++++++++++---------------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/commands.c b/src/commands.c index dd47851d..ddb66431 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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; diff --git a/tests/scripts/features/se_explicit b/tests/scripts/features/se_explicit index fad3da01..c28641c1 100644 --- a/tests/scripts/features/se_explicit +++ b/tests/scripts/features/se_explicit @@ -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; diff --git a/tests/scripts/features/se_implicit b/tests/scripts/features/se_implicit index ec09d8da..a01b385c 100644 --- a/tests/scripts/features/se_implicit +++ b/tests/scripts/features/se_implicit @@ -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;