| @@ -1,143 +1,144 @@ | | | @@ -1,143 +1,144 @@ |
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 |
15 | # Lists of files relative to WRKSRC in which the #! interpreter | | 15 | # Lists of files relative to WRKSRC in which the #! interpreter |
16 | # should be replaced by the pkgsrc one. If any directories | | 16 | # should be replaced by the pkgsrc one. If any directories |
17 | # appear in the lists, they are silenty skipped, assuming that | | 17 | # appear in the lists, they are silenty skipped, assuming that |
18 | # they result from shell globbing expressions. | | 18 | # they result from shell globbing expressions. |
19 | # | | 19 | # |
20 | # Use REPLACE_SH for shell programs that don't need any | | 20 | # Use REPLACE_SH for shell programs that don't need any |
21 | # special features from bash, and REPLACE_BASH for the | | 21 | # special features from bash, and REPLACE_BASH for the |
22 | # others. | | 22 | # others. |
23 | # | | 23 | # |
24 | # Note that in all the above cases, you have to add the needed | | 24 | # Note that in all the above cases, you have to add the needed |
25 | # tools manually to USE_TOOLS, since there is no way to detect | | 25 | # tools manually to USE_TOOLS, since there is no way to detect |
26 | # automatically whether a tool should be a build-time or a | | 26 | # automatically whether a tool should be a build-time or a |
27 | # run-time dependency. | | 27 | # run-time dependency. |
28 | # | | 28 | # |
29 | # Packages may also add their own interpreter replacements, which should | | 29 | # Packages may also add their own interpreter replacements, which should |
30 | # just look like the examples below. For the REPLACE_INTERPRETER | | 30 | # just look like the examples below. For the REPLACE_INTERPRETER |
31 | # variable, all identifiers starting with "sys-" are reserved for the | | 31 | # variable, all identifiers starting with "sys-" are reserved for the |
32 | # pkgsrc infrastructure. All others may be used freely. | | 32 | # pkgsrc infrastructure. All others may be used freely. |
33 | # | | 33 | # |
34 | # Keywords: replace_interpreter interpreter interp hashbang #! | | 34 | # Keywords: replace_interpreter interpreter interp hashbang #! |
35 | # Keywords: awk bash csh ksh perl sh | | 35 | # Keywords: awk bash csh ksh perl sh |
36 | | | 36 | |
37 | ###################################################################### | | 37 | ###################################################################### |
38 | ### replace-interpreter (PRIVATE) | | 38 | ### replace-interpreter (PRIVATE) |
39 | ###################################################################### | | 39 | ###################################################################### |
40 | ### replace-interpreter replaces paths to interpreters in scripts with | | 40 | ### replace-interpreter replaces paths to interpreters in scripts with |
41 | ### the paths to the pkgsrc-managed interpreters. | | 41 | ### the paths to the pkgsrc-managed interpreters. |
42 | ### | | 42 | ### |
43 | do-configure-pre-hook: replace-interpreter | | 43 | do-configure-pre-hook: replace-interpreter |
44 | | | 44 | |
45 | REPLACE_INTERPRETER?= # none | | 45 | REPLACE_INTERPRETER?= # none |
46 | REPLACE_AWK?= # none | | 46 | REPLACE_AWK?= # none |
47 | REPLACE_BASH?= # none | | 47 | REPLACE_BASH?= # none |
48 | REPLACE_CSH?= # none | | 48 | REPLACE_CSH?= # none |
49 | REPLACE_KSH?= # none | | 49 | REPLACE_KSH?= # none |
50 | REPLACE_PERL?= # none | | 50 | REPLACE_PERL?= # none |
51 | REPLACE_SH?= # none | | 51 | REPLACE_SH?= # none |
52 | | | 52 | |
53 | .if !empty(REPLACE_AWK:M*) | | 53 | .if !empty(REPLACE_AWK:M*) |
54 | REPLACE_INTERPRETER+= sys-AWK | | 54 | REPLACE_INTERPRETER+= sys-AWK |
55 | REPLACE.sys-AWK.old= .*awk | | 55 | REPLACE.sys-AWK.old= .*awk |
56 | REPLACE.sys-AWK.new= ${AWK} | | 56 | REPLACE.sys-AWK.new= ${AWK} |
57 | REPLACE_FILES.sys-AWK= ${REPLACE_AWK} | | 57 | REPLACE_FILES.sys-AWK= ${REPLACE_AWK} |
58 | .endif | | 58 | .endif |
59 | | | 59 | |
60 | .if !empty(REPLACE_BASH:M*) | | 60 | .if !empty(REPLACE_BASH:M*) |
61 | REPLACE_INTERPRETER+= sys-bash | | 61 | REPLACE_INTERPRETER+= sys-bash |
62 | REPLACE.sys-bash.old= .*sh | | 62 | REPLACE.sys-bash.old= .*sh |
63 | REPLACE.sys-bash.new= ${BASH} | | 63 | REPLACE.sys-bash.new= ${BASH} |
64 | REPLACE_FILES.sys-bash= ${REPLACE_BASH} | | 64 | REPLACE_FILES.sys-bash= ${REPLACE_BASH} |
65 | .endif | | 65 | .endif |
66 | | | 66 | |
67 | .if !empty(REPLACE_CSH:M*) | | 67 | .if !empty(REPLACE_CSH:M*) |
68 | REPLACE_INTERPRETER+= sys-csh | | 68 | REPLACE_INTERPRETER+= sys-csh |
69 | REPLACE.sys-csh.old= .*csh | | 69 | REPLACE.sys-csh.old= .*csh |
70 | REPLACE.sys-csh.new= ${CSH} | | 70 | REPLACE.sys-csh.new= ${CSH} |
71 | REPLACE_FILES.sys-csh= ${REPLACE_CSH} | | 71 | REPLACE_FILES.sys-csh= ${REPLACE_CSH} |
72 | .endif | | 72 | .endif |
73 | | | 73 | |
74 | .if !empty(REPLACE_KSH:M*) | | 74 | .if !empty(REPLACE_KSH:M*) |
75 | REPLACE_INTERPRETER+= sys-ksh | | 75 | REPLACE_INTERPRETER+= sys-ksh |
76 | REPLACE.sys-ksh.old= [^[:space:]]*sh | | 76 | REPLACE.sys-ksh.old= [^[:space:]]*sh |
77 | REPLACE.sys-ksh.new= ${TOOLS_PATH.ksh} | | 77 | REPLACE.sys-ksh.new= ${TOOLS_PATH.ksh} |
78 | REPLACE_FILES.sys-ksh= ${REPLACE_KSH} | | 78 | REPLACE_FILES.sys-ksh= ${REPLACE_KSH} |
79 | .endif | | 79 | .endif |
80 | | | 80 | |
81 | .if !empty(REPLACE_PERL:M*) | | 81 | .if !empty(REPLACE_PERL:M*) |
82 | REPLACE_INTERPRETER+= sys-Perl | | 82 | REPLACE_INTERPRETER+= sys-Perl |
83 | REPLACE.sys-Perl.old= .*perl[^[:space:]]* | | 83 | REPLACE.sys-Perl.old= .*perl[^[:space:]]* |
84 | REPLACE.sys-Perl.new= ${PERL5} | | 84 | REPLACE.sys-Perl.new= ${PERL5} |
85 | REPLACE_FILES.sys-Perl= ${REPLACE_PERL} | | 85 | REPLACE_FILES.sys-Perl= ${REPLACE_PERL} |
86 | .endif | | 86 | .endif |
87 | | | 87 | |
88 | .if !empty(REPLACE_PERL6:M*) | | 88 | .if !empty(REPLACE_PERL6:M*) |
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}|' \ |
115 | < "$${f}" > "$${f}.new"; \ | | 116 | < "$${f}" > "$${f}.new"; \ |
116 | if [ -x "$${f}" ]; then \ | | 117 | if [ -x "$${f}" ]; then \ |
117 | ${CHMOD} a+x "$${f}.new"; \ | | 118 | ${CHMOD} a+x "$${f}.new"; \ |
118 | fi; \ | | 119 | fi; \ |
119 | if ${CMP} -s "$${f}.new" "$${f}"; then \ | | 120 | if ${CMP} -s "$${f}.new" "$${f}"; then \ |
120 | ${INFO_MSG} "[replace-interpreter] Nothing changed in $${f}."; \ | | 121 | ${INFO_MSG} "[replace-interpreter] Nothing changed in $${f}."; \ |
121 | ${RM} -f "$${f}.new"; \ | | 122 | ${RM} -f "$${f}.new"; \ |
122 | else \ | | 123 | else \ |
123 | ${MV} -f "$${f}.new" "$${f}"; \ | | 124 | ${MV} -f "$${f}.new" "$${f}"; \ |
124 | fi; \ | | 125 | fi; \ |
125 | elif [ -d "$$f" ]; then \ | | 126 | elif [ -d "$$f" ]; then \ |
126 | ${SHCOMMENT} "Ignore it, most probably comes from shell globs"; \ | | 127 | ${SHCOMMENT} "Ignore it, most probably comes from shell globs"; \ |
127 | else \ | | 128 | else \ |
128 | ${WARNING_MSG} "[replace-interpreter] Skipping non-existent file \"$$f\"."; \ | | 129 | ${WARNING_MSG} "[replace-interpreter] Skipping non-existent file \"$$f\"."; \ |
129 | fi; \ | | 130 | fi; \ |
130 | done | | 131 | done |
131 | . else | | 132 | . else |
132 | @${WARNING_MSG} "[replace-interpreter] Empty list of files for ${_lang_}." | | 133 | @${WARNING_MSG} "[replace-interpreter] Empty list of files for ${_lang_}." |
133 | . endif | | 134 | . endif |
134 | .endfor | | 135 | .endfor |
135 | | | 136 | |
136 | _VARGROUPS+= interp | | 137 | _VARGROUPS+= interp |
137 | .for varname in REPLACE_AWK REPLACE_BASH REPLACE_CSH REPLACE_KSH REPLACE_PERL REPLACE_PERL6 REPLACE_SH | | 138 | .for varname in REPLACE_AWK REPLACE_BASH REPLACE_CSH REPLACE_KSH REPLACE_PERL REPLACE_PERL6 REPLACE_SH |
138 | _PKG_VARS.interp+= ${varname} | | 139 | _PKG_VARS.interp+= ${varname} |
139 | .endfor | | 140 | .endfor |
140 | _PKG_VARS.interp+= REPLACE_INTERPRETER | | 141 | _PKG_VARS.interp+= REPLACE_INTERPRETER |
141 | .for interp in ${REPLACE_INTERPRETER} | | 142 | .for interp in ${REPLACE_INTERPRETER} |
142 | _DEF_VARS.interp+= REPLACE.${interp}.old REPLACE.${interp}.new REPLACE_FILES.${interp} | | 143 | _DEF_VARS.interp+= REPLACE.${interp}.old REPLACE.${interp}.new REPLACE_FILES.${interp} |
143 | .endfor | | 144 | .endfor |