| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: subst.mk,v 1.82 2020/04/23 19:16:49 rillig Exp $ | | 1 | # $NetBSD: subst.mk,v 1.83 2020/04/23 19:30:29 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 |
| @@ -146,33 +146,36 @@ _SUBST_IS_TEXT_FILE_CMD.${class}= ${_SUB | | | @@ -146,33 +146,36 @@ _SUBST_IS_TEXT_FILE_CMD.${class}= ${_SUB |
146 | . endif | | 146 | . endif |
147 | | | 147 | |
148 | . if defined(SUBST_STAGE.${class}) | | 148 | . if defined(SUBST_STAGE.${class}) |
149 | ${SUBST_STAGE.${class}}: subst-${class} | | 149 | ${SUBST_STAGE.${class}}: subst-${class} |
150 | . else | | 150 | . else |
151 | # SUBST_STAGE.* does not need to be defined. | | 151 | # SUBST_STAGE.* does not need to be defined. |
152 | #PKG_FAIL_REASON+= "SUBST_STAGE missing for ${class}." | | 152 | #PKG_FAIL_REASON+= "SUBST_STAGE missing for ${class}." |
153 | . endif | | 153 | . endif |
154 | | | 154 | |
155 | .PHONY: subst-${class} | | 155 | .PHONY: subst-${class} |
156 | subst-${class}: ${_SUBST_COOKIE.${class}} | | 156 | subst-${class}: ${_SUBST_COOKIE.${class}} |
157 | | | 157 | |
158 | ${_SUBST_COOKIE.${class}}: | | 158 | ${_SUBST_COOKIE.${class}}: |
159 | ${RUN} \ | | 159 | ${RUN} set -u; \ |
160 | message=${SUBST_MESSAGE.${class}:Q}; \ | | 160 | message=${SUBST_MESSAGE.${class}:Q}; \ |
161 | [ "$$message" ] && ${ECHO_SUBST_MSG} "$$message"; \ | | 161 | [ "$$message" ] && ${ECHO_SUBST_MSG} "$$message"; \ |
162 | \ | | 162 | \ |
163 | cd ${WRKSRC}; \ | | 163 | cd ${WRKSRC}; \ |
164 | patterns=${SUBST_FILES.${class}:Q}; \ | | 164 | patterns=${SUBST_FILES.${class}:Q}; \ |
165 | set -f; \ | | 165 | set -f; \ |
| | | 166 | noop_count=''; \ |
| | | 167 | noop_patterns=''; \ |
| | | 168 | noop_sep=''; \ |
166 | for pattern in $$patterns; do \ | | 169 | for pattern in $$patterns; do \ |
167 | set +f; \ | | 170 | set +f; \ |
168 | changed=no; \ | | 171 | changed=no; \ |
169 | for file in $$pattern; do \ | | 172 | for file in $$pattern; do \ |
170 | case $$file in ([!A-Za-z0-9/]*) file="./$$file";; esac; \ | | 173 | case $$file in ([!A-Za-z0-9/]*) file="./$$file";; esac; \ |
171 | tmpfile="$$file.subst.sav"; \ | | 174 | tmpfile="$$file.subst.sav"; \ |
172 | [ -d "$$file" ] && continue; \ | | 175 | [ -d "$$file" ] && continue; \ |
173 | [ -f "$$file" ] || { \ | | 176 | [ -f "$$file" ] || { \ |
174 | ${_SUBST_WARN.${class}} "Ignoring non-existent file \"$$file\"."; \ | | 177 | ${_SUBST_WARN.${class}} "Ignoring non-existent file \"$$file\"."; \ |
175 | continue; \ | | 178 | continue; \ |
176 | }; \ | | 179 | }; \ |
177 | ${_SUBST_IS_TEXT_FILE_CMD.${class}} || { \ | | 180 | ${_SUBST_IS_TEXT_FILE_CMD.${class}} || { \ |
178 | ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ | | 181 | ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ |
| @@ -181,20 +184,28 @@ ${_SUBST_COOKIE.${class}}: | | | @@ -181,20 +184,28 @@ ${_SUBST_COOKIE.${class}}: |
181 | ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile"; \ | | 184 | ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile"; \ |
182 | ${CMP} -s "$$tmpfile" "$$file" && { \ | | 185 | ${CMP} -s "$$tmpfile" "$$file" && { \ |
183 | ${_SUBST_WARN.${class}} "Nothing changed in \"$$file\"."; \ | | 186 | ${_SUBST_WARN.${class}} "Nothing changed in \"$$file\"."; \ |
184 | ${RM} -f "$$tmpfile"; \ | | 187 | ${RM} -f "$$tmpfile"; \ |
185 | continue; \ | | 188 | continue; \ |
186 | }; \ | | 189 | }; \ |
187 | [ -x "$$file" ] && ${CHMOD} +x "$$tmpfile"; \ | | 190 | [ -x "$$file" ] && ${CHMOD} +x "$$tmpfile"; \ |
188 | changed=yes; \ | | 191 | changed=yes; \ |
189 | ${_SUBST_KEEP.${class}}; \ | | 192 | ${_SUBST_KEEP.${class}}; \ |
190 | ${MV} -f "$$tmpfile" "$$file"; \ | | 193 | ${MV} -f "$$tmpfile" "$$file"; \ |
191 | ${ECHO} "$$file" >> ${.TARGET}.tmp; \ | | 194 | ${ECHO} "$$file" >> ${.TARGET}.tmp; \ |
192 | done; \ | | 195 | done; \ |
193 | \ | | 196 | \ |
194 | [ "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no ] \ | | 197 | [ "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no ] && { \ |
195 | && ${FAIL_MSG} "[subst.mk:${class}] The filename pattern \"$$pattern\" has no effect."; \ | | 198 | noop_count="$$noop_count+"; \ |
196 | done; \ | | 199 | noop_patterns="$$noop_patterns$$noop_sep$$pattern"; \ |
| | | 200 | noop_sep=" "; \ |
| | | 201 | }; \ |
| | | 202 | done; \ |
197 | \ | | 203 | \ |
| | | 204 | case $$noop_count in \ |
| | | 205 | ('') ;; \ |
| | | 206 | (+) ${FAIL_MSG} "[subst.mk:${class}] The filename pattern \"$$noop_patterns\" has no effect.";; \ |
| | | 207 | (*) ${FAIL_MSG} "[subst.mk:${class}] The filename patterns \"$$noop_patterns\" have no effect."; \ |
| | | 208 | esac; \ |
198 | ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp; \ | | 209 | ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp; \ |
199 | ${MV} ${.TARGET}.tmp ${.TARGET} | | 210 | ${MV} ${.TARGET}.tmp ${.TARGET} |
200 | .endfor | | 211 | .endfor |