Sat Apr 18 11:42:34 2020 UTC ()
mk/subst.mk: fix pkglint warnings and notes


(rillig)
diff -r1.75 -r1.76 pkgsrc/mk/subst.mk

cvs diff -r1.75 -r1.76 pkgsrc/mk/subst.mk (expand / switch to unified diff)

--- pkgsrc/mk/subst.mk 2020/04/18 11:32:01 1.75
+++ pkgsrc/mk/subst.mk 2020/04/18 11:42:34 1.76
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: subst.mk,v 1.75 2020/04/18 11:32:01 rillig Exp $ 1# $NetBSD: subst.mk,v 1.76 2020/04/18 11:42:34 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
@@ -87,72 +87,73 @@ @@ -87,72 +87,73 @@
87# 87#
88# Default: no (up to 2019Q4), yes (starting with 2020Q1) 88# Default: no (up to 2019Q4), yes (starting with 2020Q1)
89# 89#
90# See also: 90# See also:
91# PLIST_SUBST 91# PLIST_SUBST
92# 92#
93# Keywords: subst 93# Keywords: subst
94# 94#
95 95
96SUBST_SHOW_DIFF?= no 96SUBST_SHOW_DIFF?= no
97SUBST_NOOP_OK?= yes # only for backwards compatiblity 97SUBST_NOOP_OK?= yes # only for backwards compatiblity
98 98
99_VARGROUPS+= subst 99_VARGROUPS+= subst
100_USR_VARS.subst= SUBST_SHOW_DIFF SUBST_NOOP_OK 100_USER_VARS.subst= SUBST_SHOW_DIFF SUBST_NOOP_OK
101_PKG_VARS.subst= SUBST_CLASSES 101_PKG_VARS.subst= SUBST_CLASSES
102.for c in ${SUBST_CLASSES} 102.for c in ${SUBST_CLASSES}
103. for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \ 103. for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \
104 SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK 104 SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK
105_PKG_VARS.subst+= ${pv}.${c} 105_PKG_VARS.subst+= ${pv}.${c}
106. endfor 106. endfor
107.endfor 107.endfor
108_DEF_VARS.subst= ECHO_SUBST_MSG 108_DEF_VARS.subst= ECHO_SUBST_MSG
109_USE_VARS.subst= WRKDIR WRKSRC 109_USE_VARS.subst= WRKDIR WRKSRC
110_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD 110_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD
111_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.* 111_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.*
112_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.* 112_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.*
113 113
114ECHO_SUBST_MSG?= ${STEP_MSG} 114ECHO_SUBST_MSG?= ${STEP_MSG}
115 115
116# _SUBST_IS_TEXT_FILE_CMD returns 0 if $$file is a text file. 116# _SUBST_IS_TEXT_FILE_CMD exits successfully if $$file is a text file.
117_SUBST_IS_TEXT_FILE_CMD?= \ 117_SUBST_IS_TEXT_FILE_CMD= \
118 [ -z "`LC_ALL=C ${TR} -cd '\\0' < "$$file" | ${TR} '\\0' 'x'`" ] 118 [ -z "`LC_ALL=C ${TR} -cd '\\0' < \"$$file\" | ${TR} '\\0' 'x'`" ]
119 119
120.if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u} 120.if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u}
121PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}" 121PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}"
122.endif 122.endif
123 123
124.for class in ${SUBST_CLASSES:O:u} 124.for class in ${SUBST_CLASSES:O:u}
125_SUBST_COOKIE.${class}= ${WRKDIR}/.subst_${class}_done 125_SUBST_COOKIE.${class}= ${WRKDIR}/.subst_${class}_done
126 126
127SUBST_FILTER_CMD.${class}?= LC_ALL=C ${SED} ${SUBST_SED.${class}} 127SUBST_FILTER_CMD.${class}?= LC_ALL=C ${SED} ${SUBST_SED.${class}}
128SUBST_VARS.${class}?= # none 128SUBST_VARS.${class}?= # none
129SUBST_MESSAGE.${class}?= Substituting "${class}" in ${SUBST_FILES.${class}} 129SUBST_MESSAGE.${class}?= Substituting "${class}" in ${SUBST_FILES.${class}}
130. for v in ${SUBST_VARS.${class}} 130. for v in ${SUBST_VARS.${class}}
131SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[^A-Za-z0-9_]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g 131SUBST_FILTER_CMD.${class}+= -e s,@${v:C|[^A-Za-z0-9_]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g
132. endfor 132. endfor
133. if ${SUBST_SHOW_DIFF.${class}:U${SUBST_SHOW_DIFF}:tl} == yes 133. if ${SUBST_SHOW_DIFF.${class}:U${SUBST_SHOW_DIFF}:tl} == yes
134_SUBST_KEEP.${class}?= LC_ALL=C ${DIFF} -u "$$file" "$$tmpfile" || true 134_SUBST_KEEP.${class}?= LC_ALL=C ${DIFF} -u "$$file" "$$tmpfile" || true
135. endif 135. endif
136_SUBST_KEEP.${class}?= ${DO_NADA} 136_SUBST_KEEP.${class}?= ${DO_NADA}
137SUBST_SKIP_TEXT_CHECK.${class}?= no 137SUBST_SKIP_TEXT_CHECK.${class}?= \
 138 no
138SUBST_NOOP_OK.${class}?= ${SUBST_NOOP_OK} 139SUBST_NOOP_OK.${class}?= ${SUBST_NOOP_OK}
139_SUBST_WARN.${class}= ${${SUBST_NOOP_OK.${class}:tl} == yes:?${INFO_MSG}:${WARNING_MSG}} "[subst.mk:${class}]" 140_SUBST_WARN.${class}= ${${SUBST_NOOP_OK.${class}:tl} == yes:?${INFO_MSG}:${WARNING_MSG}} "[subst.mk:${class}]"
140 141
141.if !empty(SUBST_SKIP_TEXT_CHECK.${class}:M[Yy][Ee][Ss]) 142. if !empty(SUBST_SKIP_TEXT_CHECK.${class}:M[Yy][Ee][Ss])
142_SUBST_IS_TEXT_FILE_CMD.${class}= ${TRUE} 143_SUBST_IS_TEXT_FILE_CMD.${class}= ${TRUE}
143.else 144. else
144_SUBST_IS_TEXT_FILE_CMD.${class}= ${_SUBST_IS_TEXT_FILE_CMD} 145_SUBST_IS_TEXT_FILE_CMD.${class}= ${_SUBST_IS_TEXT_FILE_CMD}
145.endif 146. endif
146 147
147. if defined(SUBST_STAGE.${class}) 148. if defined(SUBST_STAGE.${class})
148${SUBST_STAGE.${class}}: subst-${class} 149${SUBST_STAGE.${class}}: subst-${class}
149. else 150. else
150# SUBST_STAGE.* does not need to be defined. 151# SUBST_STAGE.* does not need to be defined.
151#PKG_FAIL_REASON+= "SUBST_STAGE missing for ${class}." 152#PKG_FAIL_REASON+= "SUBST_STAGE missing for ${class}."
152. endif 153. endif
153 154
154.PHONY: subst-${class} 155.PHONY: subst-${class}
155subst-${class}: ${_SUBST_COOKIE.${class}} 156subst-${class}: ${_SUBST_COOKIE.${class}}
156 157
157${_SUBST_COOKIE.${class}}: 158${_SUBST_COOKIE.${class}}:
158 ${RUN} message=${SUBST_MESSAGE.${class}:Q}; \ 159 ${RUN} message=${SUBST_MESSAGE.${class}:Q}; \
@@ -181,20 +182,20 @@ ${_SUBST_COOKIE.${class}}: @@ -181,20 +182,20 @@ ${_SUBST_COOKIE.${class}}:
181 ${_SUBST_WARN.${class}} "Nothing changed in $$file."; \ 182 ${_SUBST_WARN.${class}} "Nothing changed in $$file."; \
182 ${RM} -f "$$tmpfile"; \ 183 ${RM} -f "$$tmpfile"; \
183 else \ 184 else \
184 changed=yes; \ 185 changed=yes; \
185 ${_SUBST_KEEP.${class}}; \ 186 ${_SUBST_KEEP.${class}}; \
186 ${MV} -f "$$tmpfile" "$$file"; \ 187 ${MV} -f "$$tmpfile" "$$file"; \
187 ${ECHO} "$$file" >> ${.TARGET}.tmp; \ 188 ${ECHO} "$$file" >> ${.TARGET}.tmp; \
188 fi; \ 189 fi; \
189 else \ 190 else \
190 ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ 191 ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \
191 fi; \ 192 fi; \
192 done; \ 193 done; \
193 \ 194 \
194 if test "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no; then \ 195 if ${TEST} "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no; then \
195 ${FAIL_MSG} "[subst.mk:${class}] The pattern $$pattern has no effect."; \ 196 ${FAIL_MSG} "[subst.mk:${class}] The pattern $$pattern has no effect."; \
196 fi; \ 197 fi; \
197 done; \ 198 done; \
198 cd ${WRKDIR}; ${RMDIR} "$$emptydir" 199 cd ${WRKDIR}; ${RMDIR} "$$emptydir"
199 ${RUN} ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} 200 ${RUN} ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET}
200.endfor 201.endfor