From 73ca192b94f06c24d9638aebf271eaf2a6bd92d5 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 16 Jan 2025 14:07:13 +0000 Subject: make: phony targets and double colon rules Commit 770bad1fe (make: disallow inference rules for phony targets) added the GNU/BSD make feature that inference rules aren't used for phony targets. Normally a double-colon rule without associated commands causes an inference rule search. If the target of the double-colon rule was phony no search was carried out and the rule failed. As a result of this perl failed to build (on Linux, I didn't try on Windows). When a double-colon rule has no commands and a phony target the prerequisites should be built and the rule should succeed. Adds 32 bytes. (pdpmake GitHub issue #70) --- miscutils/make.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'miscutils') diff --git a/miscutils/make.c b/miscutils/make.c index 333f8bf12..ceac1d91d 100644 --- a/miscutils/make.c +++ b/miscutils/make.c @@ -2838,11 +2838,13 @@ make(struct name *np, int level) } } else { // If any double-colon rule has no commands we need - // an inference rule (but, as an extension, not for phony targets) + // an inference rule. for (rp = np->n_rule; rp; rp = rp->r_next) { if (!rp->r_cmd) { - if (posix || !(np->n_flag & N_PHONY)) - impdep = dyndep(np, &infrule, &tsuff); + // Phony targets don't need an inference rule. + if (!posix && (np->n_flag & N_PHONY)) + continue; + impdep = dyndep(np, &infrule, &tsuff); if (!impdep) { if (doinclude) return 1; @@ -2868,11 +2870,14 @@ make(struct name *np, int level) // Each double-colon rule is handled separately. if ((np->n_flag & N_DOUBLE)) { // If the rule has no commands use the inference rule. + // Unless there isn't one, as allowed for phony targets. if (!rp->r_cmd) { - locdep = impdep; - infrule.r_dep->d_next = rp->r_dep; - rp->r_dep = infrule.r_dep; - rp->r_cmd = infrule.r_cmd; + if (impdep) { + locdep = impdep; + infrule.r_dep->d_next = rp->r_dep; + rp->r_dep = infrule.r_dep; + rp->r_cmd = infrule.r_cmd; + } } // A rule with no prerequisities is executed unconditionally. if (!rp->r_dep) -- cgit v1.2.3-55-g6feb