summaryrefslogtreecommitdiff
path: root/mk
diff options
context:
space:
mode:
authorrillig <rillig>2008-01-18 11:16:08 +0000
committerrillig <rillig>2008-01-18 11:16:08 +0000
commit1981bf5e74664e845b93f81b034c6f49afa51b42 (patch)
treee5a27171d44b518b2576acc4edb4c93d5c75ef5f /mk
parent9837d11f86ecf043f9293b2df3f47979e624bbc6 (diff)
downloadpkgsrc-1981bf5e74664e845b93f81b034c6f49afa51b42.tar.gz
Don't rely on file(1) to distinguish text files from binary files. This
has proven too unreliable in the past. For example, some Makefile.in files were classified as "Quake I or II world or extension", just because they happen to start with the letters "PACK". This method was also subject to subtle differences in the locale. The new method counts the number of NUL bytes in the file. It does not depend on the locale settings. The -c option of wc(1) counts bytes, not characters, and tr(1), which may interpret multibyte sequences, is protected by LC_ALL. It should also work with the historical implementations of tr(1) that could not handle NUL bytes and discarded them, since this is exactly the intention. See also: * http://mail-index.netbsd.org/tech-pkg/2006/07/05/0000.html * PR 37793
Diffstat (limited to 'mk')
-rw-r--r--mk/subst.mk10
1 files changed, 5 insertions, 5 deletions
diff --git a/mk/subst.mk b/mk/subst.mk
index b1052aa1545..d9ff56f50f0 100644
--- a/mk/subst.mk
+++ b/mk/subst.mk
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.49 2008/01/18 10:41:05 rillig Exp $
+# $NetBSD: subst.mk,v 1.50 2008/01/18 11:16:08 rillig Exp $
#
# This Makefile fragment implements a general text replacement facility.
# Package makefiles define a ``class'', for each of which a particular
@@ -63,10 +63,10 @@ ECHO_SUBST_MSG?= ${STEP_MSG}
# _SUBST_IS_TEXT_FILE returns 0 if $${file} is a text file.
_SUBST_IS_TEXT_FILE?= \
- { ${TEST} -f "$$file" \
- && ${FILE_CMD} "$$file" \
- | ${EGREP} "(executable .* script|shell script|text|Assembler source|libtool|Quake I or II world or extension|XML)"; \
- } >/dev/null 2>&1
+ { nchars=`${WC} -c < "$$file"`; \
+ notnull=`LC_ALL=C ${TR} -d '\\0' < "$$file" | ${WC} -c`; \
+ [ "$$nchars" = "$$notnull" ] || ${FALSE} ; \
+ }
_SUBST_BACKUP_SUFFIX= .subst.sav