diff options
-rw-r--r-- | miscutils/make.c | 13 | ||||
-rwxr-xr-x | testsuite/make.tests | 14 |
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 | ' |
739 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | 739 | cd .. || 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". | ||
743 | mkdir make.tempdir && cd make.tempdir || exit 1 | ||
744 | touch phony.xyz | ||
745 | testing "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 $< | ||
751 | phony: | ||
752 | ' | ||
753 | cd .. || exit 1; rm -rf make.tempdir 2>/dev/null | ||
754 | |||
741 | exit $FAILCOUNT | 755 | exit $FAILCOUNT |