aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2025-01-21 09:25:46 +0000
committerRon Yorston <rmy@pobox.com>2025-01-21 09:25:46 +0000
commit89b641cbb52bdc29e7e078c7f1ebcfbe7364ba18 (patch)
tree6e761dd6d6e8dd193536bd6acb57b0d383406847
parent73ca192b94f06c24d9638aebf271eaf2a6bd92d5 (diff)
downloadbusybox-w32-89b641cbb52bdc29e7e078c7f1ebcfbe7364ba18.tar.gz
busybox-w32-89b641cbb52bdc29e7e078c7f1ebcfbe7364ba18.tar.bz2
busybox-w32-89b641cbb52bdc29e7e078c7f1ebcfbe7364ba18.zip
make: fix single-suffix inference rule regression
Commit 85bbce87d (make: support GNU/BSD suffixes and inference rules) added code to handle inference rules with arbitrary suffixes. Unfortunately it failed to check for a single-suffix rule in the case where no known suffix was found. Add the necessary code and a test which would have caught the problem. Adds 48 bytes. (pdpmake GitHub issue 72)
-rw-r--r--miscutils/make.c17
-rwxr-xr-xtestsuite/make.tests10
2 files changed, 24 insertions, 3 deletions
diff --git a/miscutils/make.c b/miscutils/make.c
index ceac1d91d..39c0081ab 100644
--- a/miscutils/make.c
+++ b/miscutils/make.c
@@ -1100,22 +1100,34 @@ dyndep(struct name *np, struct rule *infrule, const char **ptsuff)
1100 // targets of the form lib.a(member.o). 1100 // targets of the form lib.a(member.o).
1101 if (!posix && member == NULL) { 1101 if (!posix && member == NULL) {
1102 struct name *xp = newname(".SUFFIXES"); 1102 struct name *xp = newname(".SUFFIXES");
1103 int found_suffix = FALSE;
1104
1103 for (struct rule *rp = xp->n_rule; rp; rp = rp->r_next) { 1105 for (struct rule *rp = xp->n_rule; rp; rp = rp->r_next) {
1104 for (struct depend *dp = rp->r_dep; dp; dp = dp->d_next) { 1106 for (struct depend *dp = rp->r_dep; dp; dp = dp->d_next) {
1105 tsuff = dp->d_name->n_name; 1107 tsuff = dp->d_name->n_name;
1106 base = has_suffix(name, tsuff); 1108 base = has_suffix(name, tsuff);
1107 if (base) { 1109 if (base) {
1110 found_suffix = TRUE;
1108 pp = dyndep0(base, tsuff, infrule); 1111 pp = dyndep0(base, tsuff, infrule);
1109 free(base); 1112 free(base);
1110 if (pp) { 1113 if (pp) {
1111 if (ptsuff)
1112 *ptsuff = tsuff;
1113 goto done; 1114 goto done;
1114 } 1115 }
1115 } 1116 }
1116 } 1117 }
1117 } 1118 }
1118 1119
1120 if (!found_suffix) {
1121 // The name didn't have a known suffix. Try single-suffix rule.
1122 tsuff = "";
1123 pp = dyndep0(name, tsuff, infrule);
1124 if (pp) {
1125 done:
1126 if (ptsuff) {
1127 *ptsuff = tsuff;
1128 }
1129 }
1130 }
1119 } else { 1131 } else {
1120 tsuff = xstrdup(suffix(name)); 1132 tsuff = xstrdup(suffix(name));
1121 base = member ? member : name; 1133 base = member ? member : name;
@@ -1124,7 +1136,6 @@ dyndep(struct name *np, struct rule *infrule, const char **ptsuff)
1124 pp = dyndep0(base, tsuff, infrule); 1136 pp = dyndep0(base, tsuff, infrule);
1125 free((void *)tsuff); 1137 free((void *)tsuff);
1126 } 1138 }
1127 done:
1128 free(name); 1139 free(name);
1129 1140
1130 return pp; 1141 return pp;
diff --git a/testsuite/make.tests b/testsuite/make.tests
index e3103c514..fabdbe45c 100755
--- a/testsuite/make.tests
+++ b/testsuite/make.tests
@@ -86,6 +86,16 @@ test.k:
86' 86'
87cd .. || exit 1; rm -rf make.tempdir 2>/dev/null 87cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
88 88
89# Check that single-suffix inference rules work.
90mkdir make.tempdir && cd make.tempdir || exit 1
91touch test.sh
92testing "make single-suffix inference rule works" \
93 "make -f - -s; echo $?" \
94 "0\n" "" '
95test:
96'
97cd .. || exit 1; rm -rf make.tempdir 2>/dev/null
98
89# There was a bug where the failure of a build command didn't result 99# There was a bug where the failure of a build command didn't result
90# in make returning a non-zero exit status. 100# in make returning a non-zero exit status.
91testing "make return error if command fails" \ 101testing "make return error if command fails" \