2006-12-10 03:25:13 +01:00
|
|
|
# $NetBSD: subst.mk,v 1.38 2006/12/10 02:25:13 reed 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
|
|
|
#
|
2006-11-09 03:06:29 +01:00
|
|
|
# Package-settable variables:
|
2003-08-27 13:24:37 +02:00
|
|
|
#
|
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;
|
2006-01-06 00:16:01 +01:00
|
|
|
# the filenames are either absolute or relative to ${WRKSRC}.
|
2003-08-27 13:24:37 +02:00
|
|
|
#
|
|
|
|
# SUBST_SED.<class>
|
2006-07-02 11:35:05 +02:00
|
|
|
# List of sed(1) arguments to run on the specified files. Multiple
|
|
|
|
# commands can be specified using the -e option of sed.
|
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
|
|
|
|
2006-06-18 00:42:00 +02:00
|
|
|
ECHO_SUBST_MSG?= ${STEP_MSG}
|
2003-08-27 13:24:37 +02:00
|
|
|
|
2006-01-08 02:07:35 +01:00
|
|
|
# _SUBST_IS_TEXT_FILE returns 0 if $${file} is a text file.
|
|
|
|
_SUBST_IS_TEXT_FILE?= \
|
|
|
|
{ ${TEST} -f "$$file" \
|
|
|
|
&& ${FILE_CMD} "$$file" \
|
2006-12-10 03:25:13 +01:00
|
|
|
| ${EGREP} "(executable .* script|shell script|text|Assembler source|libtool)"; \
|
2006-01-08 02:07:35 +01:00
|
|
|
} >/dev/null 2>&1
|
|
|
|
|
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_}
|
|
|
|
|
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_}
|
2006-06-18 00:42:00 +02:00
|
|
|
. else
|
2006-06-22 22:45:48 +02:00
|
|
|
# SUBST_STAGE.* does not need to be defined.
|
|
|
|
#PKG_FAIL_REASON+= "SUBST_STAGE missing for ${_class_}."
|
2003-10-07 12:19:09 +02:00
|
|
|
. endif
|
2003-08-27 13:24:37 +02:00
|
|
|
|
|
|
|
.PHONY: subst-${_class_}
|
2006-06-18 00:42:00 +02:00
|
|
|
subst-${_class_}: ${_SUBST_COOKIE.${_class_}}
|
2003-08-27 13:24:37 +02:00
|
|
|
|
2006-06-18 00:42:00 +02:00
|
|
|
${_SUBST_COOKIE.${_class_}}:
|
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} \
|
2006-06-18 00:42:00 +02:00
|
|
|
${ECHO_SUBST_MSG} ${SUBST_MESSAGE.${_class_}:Q}
|
2004-03-01 10:57:10 +01:00
|
|
|
. endif
|
2006-01-01 23:52:16 +01:00
|
|
|
${_PKG_SILENT}${_PKG_DEBUG} set -e; \
|
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}; \
|
2006-01-08 02:07:35 +01:00
|
|
|
if ${_SUBST_IS_TEXT_FILE}; then \
|
2005-05-20 23:36:05 +02:00
|
|
|
${MV} -f "$$file" "$$tmpfile" || exit 1; \
|
2006-01-01 23:52:16 +01:00
|
|
|
${SUBST_FILTER_CMD.${_class_}} \
|
|
|
|
< "$$tmpfile" \
|
2005-05-20 23:36:05 +02:00
|
|
|
> "$$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; \
|
2006-01-08 02:07:35 +01:00
|
|
|
elif ${TEST} -f "$$file"; then \
|
2006-06-18 00:42:00 +02:00
|
|
|
${WARNING_MSG} "[subst.mk] Ignoring non-text file \"$$file\"." 1>&2; \
|
2005-11-24 21:02:40 +01:00
|
|
|
else \
|
2006-06-18 00:42:00 +02:00
|
|
|
${WARNING_MSG} "[subst.mk] Ignoring non-existent file \"$$file\"." 1>&2; \
|
2005-05-20 23:36:05 +02:00
|
|
|
fi; \
|
|
|
|
done
|
2006-06-18 00:42:00 +02:00
|
|
|
${_PKG_SILENT}${_PKG_DEBUG} set -e; \
|
|
|
|
${TOUCH} ${TOUCH_FLAGS} ${.TARGET:Q}
|
2003-08-27 13:24:37 +02:00
|
|
|
.endfor
|