scc

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

commit d6a9def79cde77ddd1750b4e49a01a8383e8112c
parent 7cde34f9285a940a998c32f70e523783b98aa15c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 19 Jan 2025 09:45:28 +0100

make: Fix inference updating

The inference() function was used for two different things.
Checking if there was an inference rule that required a
rebuild of a target, and to rebuild a target. Could happen
that a target had to be rebuilt because some other dependency
required it (for example a .o depending of a .h, but the
.c being older than the .o). Adding a parameter to inference()
allows to differentiate between these two cases.

Diffstat:
Msrc/cmd/scc-make/rules.c | 19+++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/cmd/scc-make/rules.c b/src/cmd/scc-make/rules.c @@ -6,6 +6,8 @@ #include "make.h" #define TABSIZ 128 +#define FORCE 1 +#define NOFORCE 0 static Target *htab[TABSIZ], *deftarget; @@ -382,7 +384,7 @@ enabled(char *suffix) } static Target * -inference(Target *tp) +inference(Target *tp, int force) { time_t t; int tolen, r; @@ -430,8 +432,17 @@ inference(Target *tp) debug("\tsearching prerequisite %s", fname); t = stamp(fname); - if (t == -1 || t <= tp->stamp) + if (t == -1) { + debug("\tprerequisite %s not found", fname); continue; + } + + if (!force && t <= tp->stamp) { + debug("\tdiscarded because is newer"); + debug("\t%s: %s", tp->name, ctime(&tp->stamp)); + debug("\t%s: %s", fname, ctime(&t)); + continue; + } free(q->req); q->req = estrdup(fname); @@ -458,7 +469,7 @@ update(Target *tp) return run(tp); } - if ((p = inference(tp)) != NULL) { + if ((p = inference(tp, FORCE)) != NULL) { debug("using inference rule %s", p->name); return run(p); } @@ -517,7 +528,7 @@ rebuild(Target *tp, int *buildp) if (tp->stamp == -1) need = 1; - else if (!def && inference(tp)) + else if (!def && inference(tp, NOFORCE)) need = 1; if (err) {