diff options
author | rillig <rillig@pkgsrc.org> | 2008-01-18 11:16:08 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2008-01-18 11:16:08 +0000 |
commit | 212334d5a8cd7f705a9b39998b3fead43d1d9c72 (patch) | |
tree | e5a27171d44b518b2576acc4edb4c93d5c75ef5f /mk | |
parent | 494c8050fe10e41660a5162fa2732a15aa39ebbd (diff) | |
download | pkgsrc-212334d5a8cd7f705a9b39998b3fead43d1d9c72.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.mk | 10 |
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 |