aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2024-08-10 10:17:35 +0100
committerRon Yorston <rmy@pobox.com>2024-08-10 10:57:21 +0100
commit770bad1fe3c369da32b53d790a26f82c012666e7 (patch)
tree1c9e679163ffe86fa69cf52b556b01fc9bae3414
parentc80a8e246d340af8a5e0a9254c5c7042bf141192 (diff)
downloadbusybox-w32-770bad1fe3c369da32b53d790a26f82c012666e7.tar.gz
busybox-w32-770bad1fe3c369da32b53d790a26f82c012666e7.tar.bz2
busybox-w32-770bad1fe3c369da32b53d790a26f82c012666e7.zip
make: disallow inference rules for phony targets
GNU make doesn't allow inference rules or the .DEFAULT target to be used for phony targets. POSIX is unclear on the matter but there doesn't seem to be an explicit prohibition of inference rules or .DEFAULT. Follow the GNU make behaviour as a non-POSIX extension. Adds 48-80 bytes. (pdpmake GitHub issue 56)
-rw-r--r--miscutils/make.c13
-rwxr-xr-xtestsuite/make.tests14
2 files changed, 22 insertions, 5 deletions
diff --git a/miscutils/make.c b/miscutils/make.c
index 1dfbd8c44..8c74d7113 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -2611,9 +2611,10 @@ make(struct name *np, int level)
2611 2611
2612 if (!(np->n_flag & N_DOUBLE)) { 2612 if (!(np->n_flag & N_DOUBLE)) {
2613 // Find the commands needed for a single-colon rule, using 2613 // Find the commands needed for a single-colon rule, using
2614 // an inference rule or .DEFAULT rule if necessary 2614 // an inference rule or .DEFAULT rule if necessary (but,
2615 // as an extension, not for phony targets)
2615 sc_cmd = getcmd(np); 2616 sc_cmd = getcmd(np);
2616 if (!sc_cmd) { 2617 if (!sc_cmd && (posix || !(np->n_flag & N_PHONY))) {
2617 impdep = dyndep(np, &imprule); 2618 impdep = dyndep(np, &imprule);
2618 if (impdep) { 2619 if (impdep) {
2619 sc_cmd = imprule.r_cmd; 2620 sc_cmd = imprule.r_cmd;
@@ -2623,7 +2624,8 @@ make(struct name *np, int level)
2623 2624
2624 // As a last resort check for a default rule 2625 // As a last resort check for a default rule
2625 if (!(np->n_flag & N_TARGET) && np->n_tim.tv_sec == 0) { 2626 if (!(np->n_flag & N_TARGET) && np->n_tim.tv_sec == 0) {
2626 sc_cmd = getcmd(findname(".DEFAULT")); 2627 if (posix || !(np->n_flag & N_PHONY))
2628 sc_cmd = getcmd(findname(".DEFAULT"));
2627 if (!sc_cmd) { 2629 if (!sc_cmd) {
2628 if (doinclude) 2630 if (doinclude)
2629 return 1; 2631 return 1;
@@ -2634,10 +2636,11 @@ make(struct name *np, int level)
2634 } 2636 }
2635 else { 2637 else {
2636 // If any double-colon rule has no commands we need 2638 // If any double-colon rule has no commands we need
2637 // an inference rule 2639 // an inference rule (but, as an extension, not for phony targets)
2638 for (rp = np->n_rule; rp; rp = rp->r_next) { 2640 for (rp = np->n_rule; rp; rp = rp->r_next) {
2639 if (!rp->r_cmd) { 2641 if (!rp->r_cmd) {
2640 impdep = dyndep(np, &imprule); 2642 if (posix || !(np->n_flag & N_PHONY))
2643 impdep = dyndep(np, &imprule);
2641 if (!impdep) { 2644 if (!impdep) {
2642 if (doinclude) 2645 if (doinclude)
2643 return 1; 2646 return 1;
diff --git a/testsuite/make.tests b/testsuite/make.tests
index 5485233f6..c92c69340 100755
--- a/testsuite/make.tests
+++ b/testsuite/make.tests
@@ -738,4 +738,18 @@ file1:
738' 738'
739cd .. || exit 1; rm -rf make.tempdir 2>/dev/null 739cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
740 740
741# GNU make and BSD make don't allow the use of inference rules
742# for phony targets. In POSIX mode the output is "phony.xyz\n".
743mkdir make.tempdir && cd make.tempdir || exit 1
744touch phony.xyz
745testing "make don't use inference rule for phony target" \
746 "make -f -" "make: nothing to be done for phony\n" "" '
747.PHONY: phony
748.SUFFIXES: .xyz
749.xyz:
750 @echo $<
751phony:
752'
753cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
754
741exit $FAILCOUNT 755exit $FAILCOUNT