Thu Jun 11 20:13:22 2020 UTC ()
mk/subst.mk: remove unnecessary SUBST_VARS definition

This is a package-settable variable, and if a package leaves it
undefined, "bmake show-all-subst" should show exactly this.


(rillig)
diff -r1.98 -r1.99 pkgsrc/mk/subst.mk

cvs diff -r1.98 -r1.99 pkgsrc/mk/subst.mk (switch to unified diff)

--- pkgsrc/mk/subst.mk 2020/06/11 19:38:40 1.98
+++ pkgsrc/mk/subst.mk 2020/06/11 20:13:22 1.99
@@ -1,235 +1,234 @@ @@ -1,235 +1,234 @@
1# $NetBSD: subst.mk,v 1.98 2020/06/11 19:38:40 rillig Exp $ 1# $NetBSD: subst.mk,v 1.99 2020/06/11 20:13:22 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
15# SUBST_FILES.prefix= ./configure doc/*.html 15# SUBST_FILES.prefix= ./configure doc/*.html
16# SUBST_SED.prefix= -e 's,/usr/local,${PREFIX},g' 16# SUBST_SED.prefix= -e 's,/usr/local,${PREFIX},g'
17# 17#
18# User-settable variables: 18# User-settable variables:
19# 19#
20# SUBST_SHOW_DIFF 20# SUBST_SHOW_DIFF
21# Whether to log each changed file as a unified diff, for all 21# Whether to log each changed file as a unified diff, for all
22# SUBST classes. Defaults to "no". 22# SUBST classes. Defaults to "no".
23# 23#
24# SUBST_NOOP_OK 24# SUBST_NOOP_OK
25# Whether it is ok to have patterns in SUBST_FILES that don't 25# Whether it is ok to have patterns in SUBST_FILES that don't
26# contain any of the patterns from SUBST_SED or SUBST_VARS and 26# contain any of the patterns from SUBST_SED or SUBST_VARS and
27# thus are not modified at all. 27# thus are not modified at all.
28# 28#
29# This setting only detects redundant filename patterns. It does 29# This setting only detects redundant filename patterns. It does
30# not detect redundant patterns in SUBST_SED. 30# not detect redundant patterns in SUBST_SED.
31# 31#
32# Identity substitutions like s|man|man| do not count as no-ops 32# Identity substitutions like s|man|man| do not count as no-ops
33# since their replacement part usually comes from a variable, such 33# since their replacement part usually comes from a variable, such
34# as PKGMANDIR. 34# as PKGMANDIR.
35# 35#
36# Defaults to no. Will be removed after 2020Q3. 36# Defaults to no. Will be removed after 2020Q3.
37# 37#
38# Package-settable variables: 38# Package-settable variables:
39# 39#
40# SUBST_CLASSES 40# SUBST_CLASSES
41# A list of class names. When adding new classes to this list, be 41# A list of class names. When adding new classes to this list, be
42# sure to append them (+=) instead of overriding them (=). 42# sure to append them (+=) instead of overriding them (=).
43# The order in which the classes are applied is unspecified. 43# The order in which the classes are applied is unspecified.
44# 44#
45# SUBST_STAGE.<class> 45# SUBST_STAGE.<class>
46# "stage" at which we do the text replacement. Should be one of 46# "stage" at which we do the text replacement. Should be one of
47# {pre,do,post}-{extract,configure,build,install}. 47# {pre,do,post}-{extract,configure,build,install}.
48# 48#
49# SUBST_MESSAGE.<class> 49# SUBST_MESSAGE.<class>
50# The message to display before doing the substitution. 50# The message to display before doing the substitution.
51# 51#
52# SUBST_FILES.<class> 52# SUBST_FILES.<class>
53# A list of file patterns on which to run the substitution; 53# A list of file patterns on which to run the substitution;
54# the filenames are either absolute or relative to ${WRKSRC}. 54# the filenames are either absolute or relative to ${WRKSRC}.
55# 55#
56# Starting with 2020Q1, it is an error if any of these patterns 56# Starting with 2020Q1, it is an error if any of these patterns
57# has no effect at all, to catch typos and outdated definitions. 57# has no effect at all, to catch typos and outdated definitions.
58# To prevent this, see SUBST_NOOP_OK.<class> below. 58# To prevent this, see SUBST_NOOP_OK.<class> below.
59# 59#
60# In most cases the filename patterns are given directly. 60# In most cases the filename patterns are given directly.
61# If that is not flexible enough, use the :sh variable modifier. 61# If that is not flexible enough, use the :sh variable modifier.
62# See mk/configure/replace-localedir.mk for an example. 62# See mk/configure/replace-localedir.mk for an example.
63# 63#
64# SUBST_SED.<class> 64# SUBST_SED.<class>
65# List of sed(1) arguments to run on the specified files. 65# List of sed(1) arguments to run on the specified files.
66# Multiple commands can be specified using the -e option of sed. 66# Multiple commands can be specified using the -e option of sed.
67# Do not use non-standard sed options (e.g. -E). 67# Do not use non-standard sed options (e.g. -E).
68# 68#
69# SUBST_VARS.<class> 69# SUBST_VARS.<class>
70# List of variables that are substituted whenever they appear in 70# List of variables that are substituted whenever they appear in
71# the form @VARNAME@. This is basically a shortcut for 71# the form @VARNAME@. This is basically a shortcut for
72# 72#
73# -e 's,@VARNAME@,${VARNAME},g' 73# -e 's,@VARNAME@,${VARNAME},g'
74# 74#
75# that even works when ${VARNAME} contains arbitrary characters. 75# that even works when ${VARNAME} contains arbitrary characters.
76# SUBST_SED and SUBST_VARS can be combined freely. 76# SUBST_SED and SUBST_VARS can be combined freely.
77# 77#
78# SUBST_FILTER_CMD.<class> 78# SUBST_FILTER_CMD.<class>
79# Filter used to perform the actual substitution on the specified 79# Filter used to perform the actual substitution on the specified
80# files. Defaults to ${SED} ${SUBST_SED.<class>}. 80# files. Defaults to ${SED} ${SUBST_SED.<class>}.
81# 81#
82# SUBST_SKIP_TEXT_CHECK.<class> 82# SUBST_SKIP_TEXT_CHECK.<class>
83# By default, each file is checked whether it really is a text file 83# By default, each file is checked whether it really is a text file
84# before any substitutions are done to it. Since that test is not 84# before any substitutions are done to it. Since that test is not
85# perfect, it can be disabled by setting this variable to "yes". 85# perfect, it can be disabled by setting this variable to "yes".
86# 86#
87# SUBST_SHOW_DIFF.<class> 87# SUBST_SHOW_DIFF.<class>
88# During development of a package, this can be set to "yes" to see 88# During development of a package, this can be set to "yes" to see
89# the actual changes as a unified diff. 89# the actual changes as a unified diff.
90# 90#
91# SUBST_NOOP_OK.<class> 91# SUBST_NOOP_OK.<class>
92# Whether to allow filename patterns in SUBST_FILES that don't 92# Whether to allow filename patterns in SUBST_FILES that don't
93# contain any of the patterns from SUBST_SED. 93# contain any of the patterns from SUBST_SED.
94# 94#
95# Defaults to no, since May 2020. 95# Defaults to no, since May 2020.
96# 96#
97# Typical reasons to change this to yes are: 97# Typical reasons to change this to yes are:
98# 98#
99# 1. SUBST_FILES is generated dynamically (e.g., via find) and 99# 1. SUBST_FILES is generated dynamically (e.g., via find) and
100# may include unaffected files. 100# may include unaffected files.
101# 101#
102# 2. There are multiple SUBST_SED patterns, and some of these 102# 2. There are multiple SUBST_SED patterns, and some of these
103# do not count as identity substitution since they contain 103# do not count as identity substitution since they contain
104# ".*" or similar parts. 104# ".*" or similar parts.
105# 105#
106# See also: 106# See also:
107# PLIST_SUBST 107# PLIST_SUBST
108# 108#
109# Keywords: subst 109# Keywords: subst
110# 110#
111 111
112SUBST_SHOW_DIFF?= no 112SUBST_SHOW_DIFF?= no
113SUBST_NOOP_OK?= no # since May 2020 113SUBST_NOOP_OK?= no # since May 2020
114 114
115_VARGROUPS+= subst 115_VARGROUPS+= subst
116_USER_VARS.subst= SUBST_SHOW_DIFF SUBST_NOOP_OK 116_USER_VARS.subst= SUBST_SHOW_DIFF SUBST_NOOP_OK
117_PKG_VARS.subst= SUBST_CLASSES 117_PKG_VARS.subst= SUBST_CLASSES
118.for c in ${SUBST_CLASSES} 118.for c in ${SUBST_CLASSES}
119. for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \ 119. for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \
120 SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK 120 SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK
121_PKG_VARS.subst+= ${pv}.${c} 121_PKG_VARS.subst+= ${pv}.${c}
122. endfor 122. endfor
123.endfor 123.endfor
124_DEF_VARS.subst= ECHO_SUBST_MSG 124_DEF_VARS.subst= ECHO_SUBST_MSG
125_USE_VARS.subst= WRKDIR WRKSRC 125_USE_VARS.subst= WRKDIR WRKSRC
126_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD 126_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD
127_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.* 127_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.*
128_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.* 128_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.*
129 129
130ECHO_SUBST_MSG?= ${STEP_MSG} 130ECHO_SUBST_MSG?= ${STEP_MSG}
131 131
132# _SUBST_IS_TEXT_FILE_CMD exits successfully if $$file is a text file. 132# _SUBST_IS_TEXT_FILE_CMD exits successfully if $$file is a text file.
133_SUBST_IS_TEXT_FILE_CMD= \ 133_SUBST_IS_TEXT_FILE_CMD= \
134 [ -z "`LC_ALL=C ${TR} -cd '\\0' < \"$$file\" | ${TR} '\\0' 'x'`" ] 134 [ -z "`LC_ALL=C ${TR} -cd '\\0' < \"$$file\" | ${TR} '\\0' 'x'`" ]
135 135
136.if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u} 136.if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u}
137PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}" 137PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}"
138.endif 138.endif
139 139
140.for class in ${SUBST_CLASSES:O:u} 140.for class in ${SUBST_CLASSES:O:u}
141_SUBST_COOKIE.${class}= ${WRKDIR}/.subst_${class}_done 141_SUBST_COOKIE.${class}= ${WRKDIR}/.subst_${class}_done
142 142
143.if defined(SUBST_FILTER_CMD.${class}) && (defined(SUBST_SED.${class}) || defined(SUBST_VARS.${class})) 143.if defined(SUBST_FILTER_CMD.${class}) && (defined(SUBST_SED.${class}) || defined(SUBST_VARS.${class}))
144PKG_FAIL_REASON+= "[subst.mk:${class}] SUBST_FILTER_CMD and SUBST_SED/SUBST_VARS cannot be combined." 144PKG_FAIL_REASON+= "[subst.mk:${class}] SUBST_FILTER_CMD and SUBST_SED/SUBST_VARS cannot be combined."
145.endif 145.endif
146 146
147SUBST_FILTER_CMD.${class}?= LC_ALL=C ${SED} ${SUBST_SED.${class}} 147SUBST_FILTER_CMD.${class}?= LC_ALL=C ${SED} ${SUBST_SED.${class}}
148SUBST_VARS.${class}?= # none 
149SUBST_MESSAGE.${class}?= Substituting "${class}" in ${SUBST_FILES.${class}} 148SUBST_MESSAGE.${class}?= Substituting "${class}" in ${SUBST_FILES.${class}}
150. for v in ${SUBST_VARS.${class}} 149. for v in ${SUBST_VARS.${class}}
151SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[.[\\*^]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g 150SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[.[\\*^]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g
152. endfor 151. endfor
153. if ${SUBST_SHOW_DIFF.${class}:U${SUBST_SHOW_DIFF}:tl} == yes 152. if ${SUBST_SHOW_DIFF.${class}:U${SUBST_SHOW_DIFF}:tl} == yes
154_SUBST_KEEP.${class}?= LC_ALL=C ${DIFF} -u "$$file" "$$tmpfile" || true 153_SUBST_KEEP.${class}?= LC_ALL=C ${DIFF} -u "$$file" "$$tmpfile" || true
155. endif 154. endif
156_SUBST_KEEP.${class}?= ${DO_NADA} 155_SUBST_KEEP.${class}?= ${DO_NADA}
157SUBST_SKIP_TEXT_CHECK.${class}?= \ 156SUBST_SKIP_TEXT_CHECK.${class}?= \
158 no 157 no
159SUBST_NOOP_OK.${class}?= ${SUBST_NOOP_OK} 158SUBST_NOOP_OK.${class}?= ${SUBST_NOOP_OK}
160_SUBST_WARN.${class}= ${${SUBST_NOOP_OK.${class}:tl} == yes:?${INFO_MSG}:${WARNING_MSG}} "[subst.mk:${class}]" 159_SUBST_WARN.${class}= ${${SUBST_NOOP_OK.${class}:tl} == yes:?${INFO_MSG}:${WARNING_MSG}} "[subst.mk:${class}]"
161 160
162. if !empty(SUBST_SKIP_TEXT_CHECK.${class}:M[Yy][Ee][Ss]) 161. if !empty(SUBST_SKIP_TEXT_CHECK.${class}:M[Yy][Ee][Ss])
163_SUBST_IS_TEXT_FILE_CMD.${class}= ${TRUE} 162_SUBST_IS_TEXT_FILE_CMD.${class}= ${TRUE}
164. else 163. else
165_SUBST_IS_TEXT_FILE_CMD.${class}= ${_SUBST_IS_TEXT_FILE_CMD} 164_SUBST_IS_TEXT_FILE_CMD.${class}= ${_SUBST_IS_TEXT_FILE_CMD}
166. endif 165. endif
167 166
168. if defined(SUBST_STAGE.${class}) 167. if defined(SUBST_STAGE.${class})
169${SUBST_STAGE.${class}}: subst-${class} 168${SUBST_STAGE.${class}}: subst-${class}
170. else 169. else
171# SUBST_STAGE.* does not need to be defined. 170# SUBST_STAGE.* does not need to be defined.
172#PKG_FAIL_REASON+= "SUBST_STAGE missing for ${class}." 171#PKG_FAIL_REASON+= "SUBST_STAGE missing for ${class}."
173. endif 172. endif
174 173
175.PHONY: subst-${class} 174.PHONY: subst-${class}
176subst-${class}: ${_SUBST_COOKIE.${class}} 175subst-${class}: ${_SUBST_COOKIE.${class}}
177 176
178${_SUBST_COOKIE.${class}}: 177${_SUBST_COOKIE.${class}}:
179 ${RUN} set -u; \ 178 ${RUN} set -u; \
180 message=${SUBST_MESSAGE.${class}:Q}; \ 179 message=${SUBST_MESSAGE.${class}:Q}; \
181 [ "$$message" ] && ${ECHO_SUBST_MSG} "$$message"; \ 180 [ "$$message" ] && ${ECHO_SUBST_MSG} "$$message"; \
182 \ 181 \
183 cd ${WRKSRC}; \ 182 cd ${WRKSRC}; \
184 patterns=${SUBST_FILES.${class}:Q}; \ 183 patterns=${SUBST_FILES.${class}:Q}; \
185 set -f; \ 184 set -f; \
186 noop_count=''; \ 185 noop_count=''; \
187 noop_patterns=''; \ 186 noop_patterns=''; \
188 noop_sep=''; \ 187 noop_sep=''; \
189 for pattern in $$patterns; do \ 188 for pattern in $$patterns; do \
190 set +f; \ 189 set +f; \
191 found_any=no; \ 190 found_any=no; \
192 for file in $$pattern; do \ 191 for file in $$pattern; do \
193 case $$file in ([!A-Za-z0-9/]*) file="./$$file";; esac; \ 192 case $$file in ([!A-Za-z0-9/]*) file="./$$file";; esac; \
194 tmpfile="$$file.subst.sav"; \ 193 tmpfile="$$file.subst.sav"; \
195 [ -d "$$file" ] && continue; \ 194 [ -d "$$file" ] && continue; \
196 [ -f "$$file" ] || { \ 195 [ -f "$$file" ] || { \
197 ${_SUBST_WARN.${class}} "Ignoring nonexistent file \"$$file\"."; \ 196 ${_SUBST_WARN.${class}} "Ignoring nonexistent file \"$$file\"."; \
198 continue; \ 197 continue; \
199 }; \ 198 }; \
200 ${_SUBST_IS_TEXT_FILE_CMD.${class}} || { \ 199 ${_SUBST_IS_TEXT_FILE_CMD.${class}} || { \
201 ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ 200 ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \
202 continue; \ 201 continue; \
203 }; \ 202 }; \
204 ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile"; \ 203 ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile"; \
205 ${CMP} -s "$$tmpfile" "$$file" && { \ 204 ${CMP} -s "$$tmpfile" "$$file" && { \
206 ${AWK} -f ${PKGSRCDIR}/mk/scripts/subst-identity.awk -- ${SUBST_SED.${class}} \ 205 ${AWK} -f ${PKGSRCDIR}/mk/scripts/subst-identity.awk -- ${SUBST_SED.${class}} \
207 && found_text=$$(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") \
208 && [ -n "$$found_text" ] \ 207 && [ -n "$$found_text" ] \
209 && found_any=yes \ 208 && found_any=yes \
210 || ${_SUBST_WARN.${class}} "Nothing changed in \"$$file\"."; \ 209 || ${_SUBST_WARN.${class}} "Nothing changed in \"$$file\"."; \
211 ${RM} -f "$$tmpfile"; \ 210 ${RM} -f "$$tmpfile"; \
212 continue; \ 211 continue; \
213 }; \ 212 }; \
214 [ -x "$$file" ] && ${CHMOD} +x "$$tmpfile"; \ 213 [ -x "$$file" ] && ${CHMOD} +x "$$tmpfile"; \
215 found_any=yes; \ 214 found_any=yes; \
216 ${_SUBST_KEEP.${class}}; \ 215 ${_SUBST_KEEP.${class}}; \
217 ${MV} -f "$$tmpfile" "$$file"; \ 216 ${MV} -f "$$tmpfile" "$$file"; \
218 ${ECHO} "$$file" >> ${.TARGET}.tmp; \ 217 ${ECHO} "$$file" >> ${.TARGET}.tmp; \
219 done; \ 218 done; \
220 \ 219 \
221 [ "$$found_any,${SUBST_NOOP_OK.${class}:tl}" = no,no ] && { \ 220 [ "$$found_any,${SUBST_NOOP_OK.${class}:tl}" = no,no ] && { \
222 noop_count="$$noop_count+"; \ 221 noop_count="$$noop_count+"; \
223 noop_patterns="$$noop_patterns$$noop_sep$$pattern"; \ 222 noop_patterns="$$noop_patterns$$noop_sep$$pattern"; \
224 noop_sep=" "; \ 223 noop_sep=" "; \
225 }; \ 224 }; \
226 done; \ 225 done; \
227 \ 226 \
228 case $$noop_count in \ 227 case $$noop_count in \
229 ('') ;; \ 228 ('') ;; \
230 (+) ${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.";; \
231 (*) ${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.";; \
232 esac; \ 231 esac; \
233 ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp; \ 232 ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp; \
234 ${MV} ${.TARGET}.tmp ${.TARGET} 233 ${MV} ${.TARGET}.tmp ${.TARGET}
235.endfor 234.endfor