| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | # $NetBSD: replace-interpreter.mk,v 1.17 2019/02/18 14:10:37 bsiegert Exp $ | | 1 | # $NetBSD: replace-interpreter.mk,v 1.18 2020/03/22 21:31:21 rillig 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_PERL6 | | 13 | # REPLACE_PERL6 |
14 | # REPLACE_SH | | 14 | # REPLACE_SH |
| @@ -89,26 +89,27 @@ REPLACE_FILES.sys-Perl= ${REPLACE_PERL} | | | @@ -89,26 +89,27 @@ REPLACE_FILES.sys-Perl= ${REPLACE_PERL} |
89 | PERL6?= ${PREFIX}/bin/perl6 | | 89 | PERL6?= ${PREFIX}/bin/perl6 |
90 | REPLACE_INTERPRETER+= sys-Perl6 | | 90 | REPLACE_INTERPRETER+= sys-Perl6 |
91 | REPLACE.sys-Perl6.old= .*perl6[^[:space:]]* | | 91 | REPLACE.sys-Perl6.old= .*perl6[^[:space:]]* |
92 | REPLACE.sys-Perl6.new= ${PERL6} | | 92 | REPLACE.sys-Perl6.new= ${PERL6} |
93 | REPLACE_FILES.sys-Perl6=${REPLACE_PERL6} | | 93 | REPLACE_FILES.sys-Perl6=${REPLACE_PERL6} |
94 | .endif | | 94 | .endif |
95 | | | 95 | |
96 | .if !empty(REPLACE_SH:M*) | | 96 | .if !empty(REPLACE_SH:M*) |
97 | REPLACE_INTERPRETER+= sys-sh | | 97 | REPLACE_INTERPRETER+= sys-sh |
98 | REPLACE.sys-sh.old= [^[:space:]]*sh | | 98 | REPLACE.sys-sh.old= [^[:space:]]*sh |
99 | REPLACE.sys-sh.new= ${SH} | | 99 | REPLACE.sys-sh.new= ${SH} |
100 | REPLACE_FILES.sys-sh= ${REPLACE_SH} | | 100 | REPLACE_FILES.sys-sh= ${REPLACE_SH} |
101 | .endif | | 101 | .endif |
| | | 102 | |
102 | # sed regexp to match optional "/usr/bin/env" followed by one or more spaces | | 103 | # sed regexp to match optional "/usr/bin/env" followed by one or more spaces |
103 | REPLACE.optional-env-space= \(/usr/bin/env[[:space:]][[:space:]]*\)\{0,1\} | | 104 | REPLACE.optional-env-space= \(/usr/bin/env[[:space:]][[:space:]]*\)\{0,1\} |
104 | | | 105 | |
105 | .PHONY: replace-interpreter | | 106 | .PHONY: replace-interpreter |
106 | replace-interpreter: | | 107 | replace-interpreter: |
107 | .for _lang_ in ${REPLACE_INTERPRETER} | | 108 | .for _lang_ in ${REPLACE_INTERPRETER} |
108 | . if defined(REPLACE_FILES.${_lang_}) && !empty(REPLACE_FILES.${_lang_}:M*) | | 109 | . if defined(REPLACE_FILES.${_lang_}) && !empty(REPLACE_FILES.${_lang_}:M*) |
109 | @${STEP_MSG} "Replacing ${_lang_:S/^sys-//} interpreter in "${REPLACE_FILES.${_lang_}:M*:Q}"." | | 110 | @${STEP_MSG} "Replacing ${_lang_:S/^sys-//} interpreter in "${REPLACE_FILES.${_lang_}:M*:Q}"." |
110 | ${RUN} set -u; \ | | 111 | ${RUN} set -u; \ |
111 | cd ${WRKSRC}; \ | | 112 | cd ${WRKSRC}; \ |
112 | for f in ${REPLACE_FILES.${_lang_}}; do \ | | 113 | for f in ${REPLACE_FILES.${_lang_}}; do \ |
113 | if [ -f "$${f}" ]; then \ | | 114 | if [ -f "$${f}" ]; then \ |
114 | ${SED} -e '1s|^#![[:space:]]*${REPLACE.optional-env-space}${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \ | | 115 | ${SED} -e '1s|^#![[:space:]]*${REPLACE.optional-env-space}${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \ |