2018-04-17 11:31:41 +02:00
|
|
|
# $NetBSD: replace-interpreter.mk,v 1.16 2018/04/17 09:31:41 adam Exp $
|
2006-07-15 11:52:00 +02:00
|
|
|
|
|
|
|
# This file provides common templates for replacing #! interpreters
|
|
|
|
# in script files.
|
|
|
|
#
|
|
|
|
# The following variables may be set by a package:
|
|
|
|
#
|
2007-03-09 00:58:20 +01:00
|
|
|
# REPLACE_AWK
|
|
|
|
# REPLACE_BASH
|
2012-02-06 07:18:36 +01:00
|
|
|
# REPLACE_CSH
|
2007-07-28 02:42:33 +02:00
|
|
|
# REPLACE_KSH
|
2007-03-09 00:58:20 +01:00
|
|
|
# REPLACE_PERL
|
|
|
|
# REPLACE_SH
|
|
|
|
# Lists of files relative to WRKSRC in which the #! interpreter
|
|
|
|
# should be replaced by the pkgsrc one. If any directories
|
2006-07-15 11:52:00 +02:00
|
|
|
# appear in the lists, they are silenty skipped, assuming that
|
|
|
|
# they result from shell globbing expressions.
|
|
|
|
#
|
|
|
|
# Use REPLACE_SH for shell programs that don't need any
|
|
|
|
# special features from bash, and REPLACE_BASH for the
|
|
|
|
# others.
|
|
|
|
#
|
|
|
|
# Note that in all the above cases, you have to add the needed
|
|
|
|
# tools manually to USE_TOOLS, since there is no way to detect
|
|
|
|
# automatically whether a tool should be a build-time or a
|
|
|
|
# run-time dependency.
|
|
|
|
#
|
|
|
|
# Packages may also add their own interpreter replacements, which should
|
|
|
|
# just look like the examples below. For the REPLACE_INTERPRETER
|
|
|
|
# variable, all identifiers starting with "sys-" are reserved for the
|
|
|
|
# pkgsrc infrastructure. All others may be used freely.
|
|
|
|
#
|
2018-03-11 15:59:14 +01:00
|
|
|
# Keywords: replace_interpreter interpreter interp hashbang #!
|
|
|
|
# Keywords: awk bash csh ksh perl sh
|
2006-07-05 08:09:15 +02:00
|
|
|
|
|
|
|
######################################################################
|
|
|
|
### replace-interpreter (PRIVATE)
|
|
|
|
######################################################################
|
|
|
|
### replace-interpreter replaces paths to interpreters in scripts with
|
|
|
|
### the paths to the pkgsrc-managed interpreters.
|
|
|
|
###
|
|
|
|
do-configure-pre-hook: replace-interpreter
|
|
|
|
|
2006-07-15 11:52:00 +02:00
|
|
|
REPLACE_INTERPRETER?= # none
|
|
|
|
REPLACE_AWK?= # none
|
|
|
|
REPLACE_BASH?= # none
|
2012-02-06 07:18:36 +01:00
|
|
|
REPLACE_CSH?= # none
|
2007-07-28 02:42:33 +02:00
|
|
|
REPLACE_KSH?= # none
|
2006-07-15 11:52:00 +02:00
|
|
|
REPLACE_PERL?= # none
|
|
|
|
REPLACE_SH?= # none
|
|
|
|
|
|
|
|
.if !empty(REPLACE_AWK:M*)
|
|
|
|
REPLACE_INTERPRETER+= sys-AWK
|
|
|
|
REPLACE.sys-AWK.old= .*awk
|
|
|
|
REPLACE.sys-AWK.new= ${AWK}
|
|
|
|
REPLACE_FILES.sys-AWK= ${REPLACE_AWK}
|
|
|
|
.endif
|
|
|
|
|
|
|
|
.if !empty(REPLACE_BASH:M*)
|
|
|
|
REPLACE_INTERPRETER+= sys-bash
|
2006-07-27 16:51:54 +02:00
|
|
|
REPLACE.sys-bash.old= .*sh
|
2006-07-15 11:52:00 +02:00
|
|
|
REPLACE.sys-bash.new= ${BASH}
|
|
|
|
REPLACE_FILES.sys-bash= ${REPLACE_BASH}
|
|
|
|
.endif
|
|
|
|
|
2012-02-06 07:18:36 +01:00
|
|
|
.if !empty(REPLACE_CSH:M*)
|
|
|
|
REPLACE_INTERPRETER+= sys-csh
|
|
|
|
REPLACE.sys-csh.old= .*csh
|
|
|
|
REPLACE.sys-csh.new= ${CSH}
|
|
|
|
REPLACE_FILES.sys-csh= ${REPLACE_CSH}
|
|
|
|
.endif
|
|
|
|
|
2007-07-28 02:42:33 +02:00
|
|
|
.if !empty(REPLACE_KSH:M*)
|
|
|
|
REPLACE_INTERPRETER+= sys-ksh
|
|
|
|
REPLACE.sys-ksh.old= [^[:space:]]*sh
|
|
|
|
REPLACE.sys-ksh.new= ${TOOLS_PATH.ksh}
|
|
|
|
REPLACE_FILES.sys-ksh= ${REPLACE_KSH}
|
|
|
|
.endif
|
|
|
|
|
2006-07-15 11:52:00 +02:00
|
|
|
.if !empty(REPLACE_PERL:M*)
|
|
|
|
REPLACE_INTERPRETER+= sys-Perl
|
|
|
|
REPLACE.sys-Perl.old= .*perl[^[:space:]]*
|
|
|
|
REPLACE.sys-Perl.new= ${PERL5}
|
|
|
|
REPLACE_FILES.sys-Perl= ${REPLACE_PERL}
|
|
|
|
.endif
|
|
|
|
|
|
|
|
.if !empty(REPLACE_SH:M*)
|
|
|
|
REPLACE_INTERPRETER+= sys-sh
|
|
|
|
REPLACE.sys-sh.old= [^[:space:]]*sh
|
|
|
|
REPLACE.sys-sh.new= ${SH}
|
|
|
|
REPLACE_FILES.sys-sh= ${REPLACE_SH}
|
2006-07-05 08:09:15 +02:00
|
|
|
.endif
|
2013-04-18 02:24:48 +02:00
|
|
|
# sed regexp to match optional "/usr/bin/env" followed by one or more spaces
|
|
|
|
REPLACE.optional-env-space= \(/usr/bin/env[[:space:]][[:space:]]*\)\{0,1\}
|
2006-07-05 08:09:15 +02:00
|
|
|
|
|
|
|
.PHONY: replace-interpreter
|
|
|
|
replace-interpreter:
|
|
|
|
.for _lang_ in ${REPLACE_INTERPRETER}
|
2006-07-15 11:52:00 +02:00
|
|
|
. if defined(REPLACE_FILES.${_lang_}) && !empty(REPLACE_FILES.${_lang_}:M*)
|
|
|
|
@${STEP_MSG} "Replacing ${_lang_:S/^sys-//} interpreter in "${REPLACE_FILES.${_lang_}:M*:Q}"."
|
2008-02-07 22:36:13 +01:00
|
|
|
${RUN} set -u; \
|
2006-07-05 08:09:15 +02:00
|
|
|
cd ${WRKSRC}; \
|
2006-07-15 11:52:00 +02:00
|
|
|
for f in ${REPLACE_FILES.${_lang_}}; do \
|
|
|
|
if [ -f "$${f}" ]; then \
|
2013-04-18 02:24:48 +02:00
|
|
|
${SED} -e '1s|^#![[:space:]]*${REPLACE.optional-env-space}${REPLACE.${_lang_}.old}|#!${REPLACE.${_lang_}.new}|' \
|
2006-07-15 11:52:00 +02:00
|
|
|
< "$${f}" > "$${f}.new"; \
|
|
|
|
if [ -x "$${f}" ]; then \
|
|
|
|
${CHMOD} a+x "$${f}.new"; \
|
|
|
|
fi; \
|
2018-04-17 11:31:41 +02:00
|
|
|
if ${CMP} -s "$${f}.new" "$${f}"; then \
|
|
|
|
${INFO_MSG} "[replace-interpreter] Nothing changed in $${f}."; \
|
|
|
|
${RM} -f "$${f}.new"; \
|
|
|
|
else \
|
|
|
|
${MV} -f "$${f}.new" "$${f}"; \
|
|
|
|
fi; \
|
2006-07-15 11:52:00 +02:00
|
|
|
elif [ -d "$$f" ]; then \
|
|
|
|
${SHCOMMENT} "Ignore it, most probably comes from shell globs"; \
|
|
|
|
else \
|
|
|
|
${WARNING_MSG} "[replace-interpreter] Skipping non-existent file \"$$f\"."; \
|
2006-07-05 08:09:15 +02:00
|
|
|
fi; \
|
|
|
|
done
|
2006-07-15 11:52:00 +02:00
|
|
|
. else
|
|
|
|
@${WARNING_MSG} "[replace-interpreter] Empty list of files for ${_lang_}."
|
|
|
|
. endif
|
2006-07-05 08:09:15 +02:00
|
|
|
.endfor
|
2018-03-11 16:07:45 +01:00
|
|
|
|
|
|
|
_VARGROUPS+= interp
|
|
|
|
.for varname in REPLACE_AWK REPLACE_BASH REPLACE_CSH REPLACE_KSH REPLACE_PERL REPLACE_SH
|
|
|
|
_PKG_VARS.interp+= ${varname}
|
|
|
|
.endfor
|
|
|
|
_PKG_VARS.interp+= REPLACE_INTERPRETER
|
|
|
|
.for interp in ${REPLACE_INTERPRETER}
|
|
|
|
_DEF_VARS.interp+= REPLACE.${interp}.old REPLACE.${interp}.new REPLACE_FILES.${interp}
|
|
|
|
.endfor
|