scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 28acf8767b996d1354e71c538bd8204b6f1d29c5
parent d323767195562ff8b8784044206b1d2945160546
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 29 Oct 2024 15:29:36 +0100

make: Check inference rules for rebuild

When a target does not have a rule with actions then make has to search
for inference rules. While we were doing that for new builds we were not
checking that for targets already built.

Diffstat:
Msrc/cmd/scc-make/rules.c | 9+++++++--
Atests/make/execute/0093-inference.sh | 24++++++++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/src/cmd/scc-make/rules.c b/src/cmd/scc-make/rules.c @@ -448,13 +448,13 @@ static int rebuild(Target *tp, int *buildp) { Target **p, *q;; - int r, need, build, err; + int r, need, build, err, def; debug("checking rebuild of %s", tp->name); tp->stamp = stamp(tp->name); - err = need = 0; + def = err = need = 0; for (p = tp->deps; p && *p; ++p) { if (stop) cleanup(tp); @@ -462,6 +462,9 @@ rebuild(Target *tp, int *buildp) q = *p; debug("checking dependency %s", q->name); + if (q->actions) + def = 1; + build = 0; if (rebuild(q, &build) != 0) { err = 1; @@ -481,6 +484,8 @@ rebuild(Target *tp, int *buildp) if (tp->stamp == -1) need = 1; + else if (!def && inference(tp)) + need = 1; if (err) { warning("target %s not remade because of errors", tp->name); diff --git a/tests/make/execute/0093-inference.sh b/tests/make/execute/0093-inference.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +trap 'rm -f $tmp1 $tmp2 $tmp3 f.?' EXIT INT TERM QUIT HUP + +tmp1=tmp1.$$ +tmp2=tmp2.$$ +tmp3=tmp3.$$ + +cat >$tmp1<<EOF +c99 -O -c f.c +EOF + +cat >$tmp2 <<'EOF' +f.o: f.h + +all: f.o +EOF + +(touch f.c f.h +scc-make -f $tmp2 +touch f.c +scc-make -f $tmp2) > $tmp3 + +diff $tmp1 $tmp3