[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
This commit is contained in:
Mike Haboustak 2019-07-11 21:08:38 -04:00 committed by Paul Smith
parent 4d00ceba26
commit ee167c650e
3 changed files with 38 additions and 30 deletions

View 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;

View 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;

View 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;