Tue Apr 2 00:28:57 2013 UTC ()
add some tricks to handle #!/usr/bin/env, do please improve


(mspo)
diff -r1.11 -r1.12 pkgsrc/mk/configure/replace-interpreter.mk

cvs diff -r1.11 -r1.12 pkgsrc/mk/configure/replace-interpreter.mk (expand / switch to unified diff)

--- pkgsrc/mk/configure/replace-interpreter.mk 2012/02/06 06:18:36 1.11
+++ pkgsrc/mk/configure/replace-interpreter.mk 2013/04/02 00:28:57 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: replace-interpreter.mk,v 1.11 2012/02/06 06:18:36 sbd Exp $ 1# $NetBSD: replace-interpreter.mk,v 1.12 2013/04/02 00:28:57 mspo Exp $
2 2
3# This file provides common templates for replacing #! interpreters 3# This file provides common templates for replacing #! interpreters
4# in script files. 4# in script files.
5# 5#
6# The following variables may be set by a package: 6# The following variables may be set by a package:
7# 7#
8# REPLACE_AWK 8# REPLACE_AWK
9# REPLACE_BASH 9# REPLACE_BASH
10# REPLACE_CSH 10# REPLACE_CSH
11# REPLACE_KSH 11# REPLACE_KSH
12# REPLACE_PERL 12# REPLACE_PERL
13# REPLACE_SH 13# REPLACE_SH
14# Lists of files relative to WRKSRC in which the #! interpreter 14# Lists of files relative to WRKSRC in which the #! interpreter
@@ -89,27 +89,28 @@ REPLACE.sys-sh.old= [^[:space:]]*sh @@ -89,27 +89,28 @@ REPLACE.sys-sh.old= [^[:space:]]*sh
89REPLACE.sys-sh.new= ${SH} 89REPLACE.sys-sh.new= ${SH}
90REPLACE_FILES.sys-sh= ${REPLACE_SH} 90REPLACE_FILES.sys-sh= ${REPLACE_SH}
91.endif 91.endif
92 92
93.PHONY: replace-interpreter 93.PHONY: replace-interpreter
94replace-interpreter: 94replace-interpreter:
95.for _lang_ in ${REPLACE_INTERPRETER} 95.for _lang_ in ${REPLACE_INTERPRETER}
96. if defined(REPLACE_FILES.${_lang_}) && !empty(REPLACE_FILES.${_lang_}:M*) 96. if defined(REPLACE_FILES.${_lang_}) && !empty(REPLACE_FILES.${_lang_}:M*)
97 @${STEP_MSG} "Replacing ${_lang_:S/^sys-//} interpreter in "${REPLACE_FILES.${_lang_}:M*:Q}"." 97 @${STEP_MSG} "Replacing ${_lang_:S/^sys-//} interpreter in "${REPLACE_FILES.${_lang_}:M*:Q}"."
98 ${RUN} set -u; \ 98 ${RUN} set -u; \
99 cd ${WRKSRC}; \ 99 cd ${WRKSRC}; \
100 for f in ${REPLACE_FILES.${_lang_}}; do \ 100 for f in ${REPLACE_FILES.${_lang_}}; do \
101 if [ -f "$${f}" ]; then \ 101 if [ -f "$${f}" ]; then \
102 ${SED} -e '1s|^#![[:space:]]*${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \ 102 ${SED} -e '1{ /env -i/!s|^#![[:space:]]*/usr/bin/env|#!|;}' \
 103 -e '1s|^#![[:space:]]*${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \
103 < "$${f}" > "$${f}.new"; \ 104 < "$${f}" > "$${f}.new"; \
104 if [ -x "$${f}" ]; then \ 105 if [ -x "$${f}" ]; then \
105 ${CHMOD} a+x "$${f}.new"; \ 106 ${CHMOD} a+x "$${f}.new"; \
106 fi; \ 107 fi; \
107 ${MV} -f "$${f}.new" "$${f}"; \ 108 ${MV} -f "$${f}.new" "$${f}"; \
108 elif [ -d "$$f" ]; then \ 109 elif [ -d "$$f" ]; then \
109 ${SHCOMMENT} "Ignore it, most probably comes from shell globs"; \ 110 ${SHCOMMENT} "Ignore it, most probably comes from shell globs"; \
110 else \ 111 else \
111 ${WARNING_MSG} "[replace-interpreter] Skipping non-existent file \"$$f\"."; \ 112 ${WARNING_MSG} "[replace-interpreter] Skipping non-existent file \"$$f\"."; \
112 fi; \ 113 fi; \
113 done 114 done
114. else 115. else
115 @${WARNING_MSG} "[replace-interpreter] Empty list of files for ${_lang_}." 116 @${WARNING_MSG} "[replace-interpreter] Empty list of files for ${_lang_}."