2005-12-06 18:17:30 +01:00
|
|
|
# $NetBSD: subst.mk,v 1.26 2005/12/06 17:17:30 rillig Exp $
|
2003-08-27 13:24:37 +02:00
|
|
|
#
|
2004-03-01 10:57:10 +01:00
|
|
|
# This Makefile fragment implements a general text replacement facility.
|
2005-06-09 21:49:48 +02:00
|
|
|
# Package makefiles define a ``class'', for each of which a particular
|
2004-03-01 10:57:10 +01:00
|
|
|
# substitution description can be defined. For each class of files, a
|
|
|
|
# target subst-<class> is created to perform the text replacement.
|
2003-08-27 13:24:37 +02:00
|
|
|
#
|
|
|
|
# The following variables are used:
|
|
|
|
#
|
2004-03-01 10:57:10 +01:00
|
|
|
# SUBST_CLASSES
|
|
|
|
# A list of class names. A new class name must be appended (+=).
|
|
|
|
#
|
2003-08-27 13:24:37 +02:00
|
|
|
# SUBST_STAGE.<class>
|
2005-08-22 00:00:07 +02:00
|
|
|
# "stage" at which we do the text replacement. Should be one of
|
|
|
|
# {pre,do,post}-{extract,patch,configure,build,install}.
|
2003-08-27 13:24:37 +02:00
|
|
|
#
|
|
|
|
# SUBST_MESSAGE.<class>
|
2005-08-22 00:00:07 +02:00
|
|
|
# The message to display when the substitution is done.
|
2004-06-06 06:22:23 +02:00
|
|
|
#
|
2003-08-27 13:24:37 +02:00
|
|
|
# SUBST_FILES.<class>
|
2005-08-22 00:00:07 +02:00
|
|
|
# A list of file patterns on which to run the substitution;
|
|
|
|
# the filenames are relative to ${WRKSRC}.
|
2003-08-27 13:24:37 +02:00
|
|
|
#
|
|
|
|
# SUBST_SED.<class>
|
2005-08-22 00:00:07 +02:00
|
|
|
# sed(1) substitution expression to run on the specified files.
|
2003-10-07 12:19:09 +02:00
|
|
|
#
|
|
|
|
# SUBST_FILTER_CMD.<class>
|
2005-08-22 00:00:07 +02:00
|
|
|
# Filter used to perform the actual substitution on the specified
|
2003-10-07 12:19:09 +02:00
|
|
|
# files. Defaults to ${SED} ${SUBST_SED.<class>}.
|
2004-06-06 06:22:23 +02:00
|
|
|
#
|
|
|
|
# SUBST_POSTCMD.<class>
|
2005-08-22 00:00:07 +02:00
|
|
|
# Command to clean up after sed(1). Defaults to ${RM} -f
|
2004-08-23 18:35:11 +02:00
|
|
|
# $$file${_SUBST_BACKUP_SUFFIX}. For debugging, set it to ${DO_NADA}.
|
2003-08-27 13:24:37 +02:00
|
|
|
|
|
|
|
ECHO_SUBST_MSG?= ${ECHO}
|
|
|
|
|
2003-12-28 18:28:26 +01:00
|
|
|
# _SUBST_IS_TEXT_FILE returns 0 if $${file} is a text file.
|
|
|
|
_SUBST_IS_TEXT_FILE?= \
|
2005-05-17 21:01:36 +02:00
|
|
|
{ ${TEST} -f "$$file" \
|
|
|
|
&& ${FILE_CMD} "$$file" \
|
|
|
|
| ${EGREP} "(executable .* script|shell script|text)"; \
|
|
|
|
} >/dev/null 2>&1
|
2003-12-28 18:28:26 +01:00
|
|
|
|
2004-08-23 18:35:11 +02:00
|
|
|
_SUBST_BACKUP_SUFFIX= .subst.sav
|
|
|
|
|
2003-08-27 13:24:37 +02:00
|
|
|
.for _class_ in ${SUBST_CLASSES}
|
|
|
|
_SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done
|
|
|
|
|
2003-10-07 12:19:09 +02:00
|
|
|
SUBST_FILTER_CMD.${_class_}?= ${SED} ${SUBST_SED.${_class_}}
|
2005-05-20 23:36:05 +02:00
|
|
|
SUBST_POSTCMD.${_class_}?= ${RM} -f "$$tmpfile"
|
2003-10-07 12:19:09 +02:00
|
|
|
|
2003-08-27 13:24:37 +02:00
|
|
|
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_}}
|
|
|
|
|
2003-10-07 12:19:09 +02:00
|
|
|
. if defined(SUBST_STAGE.${_class_})
|
2003-08-27 13:24:37 +02:00
|
|
|
${SUBST_STAGE.${_class_}}: subst-${_class_}
|
2003-10-07 12:19:09 +02:00
|
|
|
. endif
|
2003-08-27 13:24:37 +02:00
|
|
|
|
|
|
|
.PHONY: subst-${_class_}
|
|
|
|
subst-${_class_}: ${_SUBST_TARGETS.${_class_}}
|
|
|
|
|
|
|
|
.PHONY: subst-${_class_}-message
|
|
|
|
subst-${_class_}-message:
|
2004-03-01 10:57:10 +01:00
|
|
|
. if defined(SUBST_MESSAGE.${_class_})
|
2003-08-27 13:24:37 +02:00
|
|
|
${_PKG_SILENT}${_PKG_DEBUG} \
|
2005-05-18 05:33:51 +02:00
|
|
|
${ECHO_SUBST_MSG} "=> "${SUBST_MESSAGE.${_class_}}
|
2004-03-01 10:57:10 +01:00
|
|
|
. endif
|
2003-08-27 13:24:37 +02:00
|
|
|
|
|
|
|
.PHONY: subst-${_class_}-cookie
|
|
|
|
subst-${_class_}-cookie:
|
|
|
|
${_PKG_SILENT}${_PKG_DEBUG} \
|
|
|
|
${TOUCH} ${TOUCH_FLAGS} ${_SUBST_COOKIE.${_class_}}
|
|
|
|
|
|
|
|
${_SUBST_COOKIE.${_class_}}:
|
|
|
|
${_PKG_SILENT}${_PKG_DEBUG} \
|
2005-05-20 23:36:05 +02:00
|
|
|
cd ${WRKSRC:Q}; \
|
|
|
|
files=${SUBST_FILES.${_class_}:Q}; \
|
|
|
|
for file in $$files; do \
|
2005-12-06 18:17:30 +01:00
|
|
|
case $$file in /*) ;; *) file="./$$file";; esac; \
|
2005-05-20 23:36:05 +02:00
|
|
|
tmpfile="$$file"${_SUBST_BACKUP_SUFFIX:Q}; \
|
|
|
|
if ${_SUBST_IS_TEXT_FILE}; then \
|
|
|
|
${MV} -f "$$file" "$$tmpfile" || exit 1; \
|
|
|
|
${CAT} "$$tmpfile" \
|
|
|
|
| ${SUBST_FILTER_CMD.${_class_}} \
|
|
|
|
> "$$file"; \
|
|
|
|
if ${TEST} -x "$$tmpfile"; then \
|
|
|
|
${CHMOD} +x "$$file"; \
|
2003-08-27 13:24:37 +02:00
|
|
|
fi; \
|
2005-05-20 23:36:05 +02:00
|
|
|
if ${CMP} -s "$$tmpfile" "$$file"; then \
|
|
|
|
${MV} -f "$$tmpfile" "$$file"; \
|
|
|
|
else \
|
|
|
|
${SUBST_POSTCMD.${_class_}}; \
|
|
|
|
${ECHO} "$$file" >> ${.TARGET}; \
|
|
|
|
fi; \
|
2005-11-24 21:02:40 +01:00
|
|
|
elif ${TEST} -f "$$file"; then \
|
2005-11-18 00:17:02 +01:00
|
|
|
${ECHO_SUBST_MSG} "[subst.mk] WARNING: Ignoring non-text file \"$$file\"." 1>&2; \
|
2005-11-24 21:02:40 +01:00
|
|
|
else \
|
|
|
|
${ECHO_SUBST_MSG} "[subst.mk] WARNING: Ignoring non-existant file \"$$file\"." 1>&2; \
|
2005-05-20 23:36:05 +02:00
|
|
|
fi; \
|
|
|
|
done
|
2003-08-27 13:24:37 +02:00
|
|
|
.endfor
|