| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: subst.mk,v 1.96 2020/06/11 18:04:41 rillig Exp $ | | 1 | # $NetBSD: subst.mk,v 1.97 2020/06/11 19:27:56 rillig Exp $ |
2 | # | | 2 | # |
3 | # The subst framework replaces text in one or more files in the WRKSRC | | 3 | # The subst framework replaces text in one or more files in the WRKSRC |
4 | # directory. Packages can define several ``classes'' of replacements. | | 4 | # directory. Packages can define several ``classes'' of replacements. |
5 | # Each such class defines: | | 5 | # Each such class defines: |
6 | # | | 6 | # |
7 | # - in which stage of the build process the replacement happens | | 7 | # - in which stage of the build process the replacement happens |
8 | # - which files are affected by the replacement | | 8 | # - which files are affected by the replacement |
9 | # - which text or pattern is replaced by which replacement text | | 9 | # - which text or pattern is replaced by which replacement text |
10 | # | | 10 | # |
11 | # A typical example is: | | 11 | # A typical example is: |
12 | # | | 12 | # |
13 | # SUBST_CLASSES+= prefix | | 13 | # SUBST_CLASSES+= prefix |
14 | # SUBST_STAGE.prefix= pre-configure | | 14 | # SUBST_STAGE.prefix= pre-configure |
| @@ -177,57 +177,57 @@ subst-${class}: ${_SUBST_COOKIE.${class} | | | @@ -177,57 +177,57 @@ subst-${class}: ${_SUBST_COOKIE.${class} |
177 | ${_SUBST_COOKIE.${class}}: | | 177 | ${_SUBST_COOKIE.${class}}: |
178 | ${RUN} set -u; \ | | 178 | ${RUN} set -u; \ |
179 | message=${SUBST_MESSAGE.${class}:Q}; \ | | 179 | message=${SUBST_MESSAGE.${class}:Q}; \ |
180 | [ "$$message" ] && ${ECHO_SUBST_MSG} "$$message"; \ | | 180 | [ "$$message" ] && ${ECHO_SUBST_MSG} "$$message"; \ |
181 | \ | | 181 | \ |
182 | cd ${WRKSRC}; \ | | 182 | cd ${WRKSRC}; \ |
183 | patterns=${SUBST_FILES.${class}:Q}; \ | | 183 | patterns=${SUBST_FILES.${class}:Q}; \ |
184 | set -f; \ | | 184 | set -f; \ |
185 | noop_count=''; \ | | 185 | noop_count=''; \ |
186 | noop_patterns=''; \ | | 186 | noop_patterns=''; \ |
187 | noop_sep=''; \ | | 187 | noop_sep=''; \ |
188 | for pattern in $$patterns; do \ | | 188 | for pattern in $$patterns; do \ |
189 | set +f; \ | | 189 | set +f; \ |
190 | changed=no; \ | | 190 | found_any=no; \ |
191 | for file in $$pattern; do \ | | 191 | for file in $$pattern; do \ |
192 | case $$file in ([!A-Za-z0-9/]*) file="./$$file";; esac; \ | | 192 | case $$file in ([!A-Za-z0-9/]*) file="./$$file";; esac; \ |
193 | tmpfile="$$file.subst.sav"; \ | | 193 | tmpfile="$$file.subst.sav"; \ |
194 | [ -d "$$file" ] && continue; \ | | 194 | [ -d "$$file" ] && continue; \ |
195 | [ -f "$$file" ] || { \ | | 195 | [ -f "$$file" ] || { \ |
196 | ${_SUBST_WARN.${class}} "Ignoring nonexistent file \"$$file\"."; \ | | 196 | ${_SUBST_WARN.${class}} "Ignoring nonexistent file \"$$file\"."; \ |
197 | continue; \ | | 197 | continue; \ |
198 | }; \ | | 198 | }; \ |
199 | ${_SUBST_IS_TEXT_FILE_CMD.${class}} || { \ | | 199 | ${_SUBST_IS_TEXT_FILE_CMD.${class}} || { \ |
200 | ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ | | 200 | ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ |
201 | continue; \ | | 201 | continue; \ |
202 | }; \ | | 202 | }; \ |
203 | ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile"; \ | | 203 | ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile"; \ |
204 | ${CMP} -s "$$tmpfile" "$$file" && { \ | | 204 | ${CMP} -s "$$tmpfile" "$$file" && { \ |
205 | ${AWK} -f ${PKGSRCDIR}/mk/scripts/subst-identity.awk -- ${SUBST_SED.${class}} \ | | 205 | ${AWK} -f ${PKGSRCDIR}/mk/scripts/subst-identity.awk -- ${SUBST_SED.${class}} \ |
206 | && found=$$(LC_ALL=C ${SED} -n ${SUBST_SED.${class}:C,^['"]?s.*,&p,} "$$file") \ | | 206 | && found_text=$$(LC_ALL=C ${SED} -n ${SUBST_SED.${class}:C,^['"]?s.*,&p,} "$$file") \ |
207 | && [ -n "$$found" ] \ | | 207 | && [ -n "$$found_text" ] \ |
208 | && changed=yes \ | | 208 | && found_any=yes \ |
209 | || ${_SUBST_WARN.${class}} "Nothing changed in \"$$file\"."; \ | | 209 | || ${_SUBST_WARN.${class}} "Nothing changed in \"$$file\"."; \ |
210 | ${RM} -f "$$tmpfile"; \ | | 210 | ${RM} -f "$$tmpfile"; \ |
211 | continue; \ | | 211 | continue; \ |
212 | }; \ | | 212 | }; \ |
213 | [ -x "$$file" ] && ${CHMOD} +x "$$tmpfile"; \ | | 213 | [ -x "$$file" ] && ${CHMOD} +x "$$tmpfile"; \ |
214 | changed=yes; \ | | 214 | found_any=yes; \ |
215 | ${_SUBST_KEEP.${class}}; \ | | 215 | ${_SUBST_KEEP.${class}}; \ |
216 | ${MV} -f "$$tmpfile" "$$file"; \ | | 216 | ${MV} -f "$$tmpfile" "$$file"; \ |
217 | ${ECHO} "$$file" >> ${.TARGET}.tmp; \ | | 217 | ${ECHO} "$$file" >> ${.TARGET}.tmp; \ |
218 | done; \ | | 218 | done; \ |
219 | \ | | 219 | \ |
220 | [ "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no ] && { \ | | 220 | [ "$$found_any,${SUBST_NOOP_OK.${class}:tl}" = no,no ] && { \ |
221 | noop_count="$$noop_count+"; \ | | 221 | noop_count="$$noop_count+"; \ |
222 | noop_patterns="$$noop_patterns$$noop_sep$$pattern"; \ | | 222 | noop_patterns="$$noop_patterns$$noop_sep$$pattern"; \ |
223 | noop_sep=" "; \ | | 223 | noop_sep=" "; \ |
224 | }; \ | | 224 | }; \ |
225 | done; \ | | 225 | done; \ |
226 | \ | | 226 | \ |
227 | case $$noop_count in \ | | 227 | case $$noop_count in \ |
228 | ('') ;; \ | | 228 | ('') ;; \ |
229 | (+) ${FAIL_MSG} "[subst.mk:${class}] The filename pattern \"$$noop_patterns\" has no effect.";; \ | | 229 | (+) ${FAIL_MSG} "[subst.mk:${class}] The filename pattern \"$$noop_patterns\" has no effect.";; \ |
230 | (*) ${FAIL_MSG} "[subst.mk:${class}] The filename patterns \"$$noop_patterns\" have no effect.";; \ | | 230 | (*) ${FAIL_MSG} "[subst.mk:${class}] The filename patterns \"$$noop_patterns\" have no effect.";; \ |
231 | esac; \ | | 231 | esac; \ |
232 | ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp; \ | | 232 | ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp; \ |
233 | ${MV} ${.TARGET}.tmp ${.TARGET} | | 233 | ${MV} ${.TARGET}.tmp ${.TARGET} |