diff options
author | jlam <jlam> | 2003-08-27 11:24:37 +0000 |
---|---|---|
committer | jlam <jlam> | 2003-08-27 11:24:37 +0000 |
commit | 58bc673bf70e14821b5f844a1b2379742badabd6 (patch) | |
tree | 5fb31785221f1f5f2df4f268c3378e5dfd948b3b /mk/subst.mk | |
parent | 30041b7c736b39fa3013e195e4ea56c554672380 (diff) | |
download | pkgsrc-58bc673bf70e14821b5f844a1b2379742badabd6.tar.gz |
subst.mk is a Makefile fragment that implements a general text replacement
facility for different classes of files in ${WRKSRC}. For each class of
files, a target <class>-subst is created to perform the text replacement.
The following variables are used:
SUBST_STAGE.<class>
"stage" at which we do the text replacement, e.g. pre-configure,
post-build, etc.
SUBST_MESSAGE.<class>
message to display, noting what is being substituted
SUBST_FILES.<class>
files on which to run the substitution; these are relative to
${WRKSRC}
SUBST_SED.<class>
sed(1) substitution expression to run on the specified files
This basically extracts a useful piece of code from bsd.buildlink2.mk and
puts it in a place that allows it to be more widely used, and so that the
functionality doesn't depend on USE_BUILDLINK2 being defined.
Diffstat (limited to 'mk/subst.mk')
-rw-r--r-- | mk/subst.mk | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/mk/subst.mk b/mk/subst.mk new file mode 100644 index 00000000000..e360d39677a --- /dev/null +++ b/mk/subst.mk @@ -0,0 +1,80 @@ +# $NetBSD: subst.mk,v 1.1 2003/08/27 11:24:37 jlam Exp $ +# +# This Makefile fragment implements a general text replacement facility +# for different classes of files in ${WRKSRC}. For each class of files, +# a target <class>-subst is created to perform the text replacement. +# +# The following variables are used: +# +# SUBST_STAGE.<class> +# "stage" at which we do the text replacement, e.g. pre-configure, +# post-build, etc. +# +# SUBST_MESSAGE.<class> +# message to display, noting what is being substituted +# +# SUBST_FILES.<class> +# files on which to run the substitution; these are relative to +# ${WRKSRC} +# +# SUBST_SED.<class> +# sed(1) substitution expression to run on the specified files + +ECHO_SUBST_MSG?= ${ECHO} + +# _SUBST_IS_TEXT_FILE returns 0 if $${file} is a text file. +_SUBST_IS_TEXT_FILE?= \ + ${FILE_CMD} $${file} | ${EGREP} "(shell script|text)" >/dev/null 2>&1 + +.for _class_ in ${SUBST_CLASSES} +_SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done + +SUBST_TARGETS+= subst-${_class_} +_SUBST_TARGETS.${_class_}= subst-${_class_}-message +_SUBST_TARGETS.${_class_}+= ${_SUBST_COOKIE.${_class_}} +_SUBST_TARGETS.${_class_}+= subst-${_class_}-cookie + +.ORDER: ${_SUBST_TARGETS.${_class_}} + +.if defined(SUBST_STAGE.${_class_}) +${SUBST_STAGE.${_class_}}: subst-${_class_} +.endif + +.PHONY: subst-${_class_} +subst-${_class_}: ${_SUBST_TARGETS.${_class_}} + +.PHONY: subst-${_class_}-message + subst-${_class_}-message: + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${ECHO_SUBST_MSG} "=> ${SUBST_MESSAGE.${_class_}}" + +.PHONY: subst-${_class_}-cookie + subst-${_class_}-cookie: + ${_PKG_SILENT}${_PKG_DEBUG} \ + ${TOUCH} ${TOUCH_FLAGS} ${_SUBST_COOKIE.${_class_}} + +${_SUBST_COOKIE.${_class_}}: +. if !empty(SUBST_SED.${_class_}) + ${_PKG_SILENT}${_PKG_DEBUG} \ + cd ${WRKSRC}; \ + files="${SUBST_FILES.${_class_}}"; \ + case "$$files" in \ + "") ;; \ + *) for file in $${files}; do \ + if ${_SUBST_IS_TEXT_FILE}; then \ + ${MV} -f $$file $$file.subst.sav; \ + ${SED} ${SUBST_SED.${_class_}} \ + $$file.subst.sav > $$file; \ + if [ -x $$file.subst.sav ]; then \ + ${CHMOD} +x $$file; \ + fi; \ + if ${CMP} -s $$file.subst.sav $$file; then \ + ${MV} -f $$file.subst.sav $$file; \ + else \ + ${ECHO} $$file >> ${.TARGET}; \ + fi; \ + fi; \ + done ;; \ + esac +. endif +.endfor |