summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2019-09-08 09:06:06 +0000
committerrillig <rillig@pkgsrc.org>2019-09-08 09:06:06 +0000
commit07db460d01d534bf09c0bf82dbdd04d406323513 (patch)
treed1e3cb0799f4bde252bfaac952dab29c09e03184 /mk
parent55723b56f341f6c882e22a80b439fdb59a75c6ba (diff)
downloadpkgsrc-07db460d01d534bf09c0bf82dbdd04d406323513.tar.gz
mk/subst.mk: document variables used in the file, remove SUBST_TARGETS
All variables that are used or defined in the file are now listed in the _VARGROUPS section. The "is text file" command variable has been renamed since pkglint thought the former variable name would specify a filename, not a shell command. The "is text file" command has been rewritten to only rely on tr(1) instead of both tr(1) and wc(1). This makes it both simpler and maybe also a little faster, since the file only has to be read once. The SUBST_TARGETS variable has been removed since it is used nowhere else. To get the list of all subst targets (should that ever be necessary), use the expression ${SUBST_CLASSES:S,^,subst-,}.
Diffstat (limited to 'mk')
-rw-r--r--mk/subst.mk26
1 files changed, 11 insertions, 15 deletions
diff --git a/mk/subst.mk b/mk/subst.mk
index c45ff3b2262..4817d01d7ed 100644
--- a/mk/subst.mk
+++ b/mk/subst.mk
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.60 2019/04/28 12:31:15 rillig Exp $
+# $NetBSD: subst.mk,v 1.61 2019/09/08 09:06:06 rillig Exp $
#
# The subst framework replaces text in one or more files in the WRKSRC
# directory. Packages can define several ``classes'' of replacements.
@@ -73,19 +73,17 @@ _PKG_VARS.subst= SUBST_CLASSES
_PKG_VARS.subst+= ${pv}.${c}
. endfor
.endfor
+_DEF_VARS.subst= ECHO_SUBST_MSG
+_USE_VARS.subst= WRKDIR WRKSRC
+_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD
_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.*
_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.*
ECHO_SUBST_MSG?= ${STEP_MSG}
-# _SUBST_IS_TEXT_FILE returns 0 if $${file} is a text file.
-_SUBST_IS_TEXT_FILE?= \
- { nchars=`${WC} -c < "$$file"`; \
- notnull=`LC_ALL=C ${TR} -d '\\0' < "$$file" | ${WC} -c`; \
- [ "$$nchars" = "$$notnull" ] || ${FALSE} ; \
- }
-
-_SUBST_BACKUP_SUFFIX= .subst.sav
+# _SUBST_IS_TEXT_FILE_CMD returns 0 if $$file is a text file.
+_SUBST_IS_TEXT_FILE_CMD?= \
+ [ -z "`${TR} -cd '\\0' < "$$file" | ${TR} '\\0' 'x'`" ]
.for _class_ in ${SUBST_CLASSES}
_SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done
@@ -103,13 +101,11 @@ _SUBST_KEEP.${_class_}?= ${DO_NADA}
SUBST_SKIP_TEXT_CHECK.${_class_}?= no
.if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss])
-_SUBST_IS_TEXT_FILE.${_class_}= ${TRUE}
+_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${TRUE}
.else
-_SUBST_IS_TEXT_FILE.${_class_}= ${_SUBST_IS_TEXT_FILE}
+_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${_SUBST_IS_TEXT_FILE_CMD}
.endif
-SUBST_TARGETS+= subst-${_class_}
-
. if defined(SUBST_STAGE.${_class_})
${SUBST_STAGE.${_class_}}: subst-${_class_}
. else
@@ -128,10 +124,10 @@ ${_SUBST_COOKIE.${_class_}}:
files=${SUBST_FILES.${_class_}:Q}; \
for file in $$files; do \
case $$file in /*) ;; *) file="./$$file";; esac; \
- tmpfile="$$file"${_SUBST_BACKUP_SUFFIX:Q}; \
+ tmpfile="$$file.subst.sav"; \
if [ ! -f "$$file" ]; then \
${WARNING_MSG} "[subst.mk:${_class_}] Ignoring non-existent file \"$$file\"."; \
- elif ${_SUBST_IS_TEXT_FILE.${_class_}}; then \
+ elif ${_SUBST_IS_TEXT_FILE_CMD.${_class_}}; then \
${SUBST_FILTER_CMD.${_class_}} \
< "$$file" \
> "$$tmpfile"; \