Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 May 2004 02:02:47 +0200 (CEST)
From:      Florent Thoumie <flz@xbsd.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/67151: Mk/bsd.port.mk - Add a way to handle PLIST_SUB like substitutions to a given file list.
Message-ID:  <20040525000247.ED5F6CD4@gw.xbsd.org>
Resent-Message-ID: <200405250010.i4P0AHCF023018@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         67151
>Category:       ports
>Synopsis:       Mk/bsd.port.mk - Add a way to handle PLIST_SUB like substitutions to a given file list.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon May 24 17:10:16 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Florent Thoumie
>Release:        FreeBSD 4.9-RC i386
>Organization:
Xbsd.org
>Environment:

System: FreeBSD gw 4.9-RC FreeBSD 4.9-RC #4: Sun Oct 5 14:25:09 CEST 2003 rf@gw:/usr/src/sys/compile/GW i386

>Description:

Rationale:

x A lot of Makefiles are using %%...%% substitutions for pkg-* files (and
other files).
x These modified files are written to ${WRKDIR}.
x Makefiles defines some related variables (PKGMESSAGE, PKGINSTALL, ...)
for these files to be included in the port distribution.

Goal:

x Create a target that modifies a given list of files, and copy them in
${WRKDIR}.
x If these files are specific files (ie. matching pkg-*), set some
variables automatically.

How:

x Create a SUB_FILES variable to handle the list of files to be modified.
x Create a SUB_LIST variable to handle substitutions to do.
x Apply the substitution list to each file $i in ${SUB_FILES} and redirect
output to ${WRKDIR}/$i.
x Detect special files and set variables.

Example:

SUB_FILES=	pkg-message pkg-install
SUB_LIST+=	"VERSION=${VERSION}"

This looks for ${FILESDIR}/pkg-message.in and ${FILESDIR}/pkg-install.in
Substitutions in SUB_LIST are applied to these files and the output is redirected
to ${WRKDIR}/
PKGMESSAGE is set to ${WRKDIR}/pkg-message.
PKGINSTALL is set to ${WRKDIR}/pkg-install.

As I am introducing two new variables, there shouldn't be any breakage.


Note: I haven't found a better name than apply-slist (for substitution list) for the
new target name, so any proposition is welcome.

>How-To-Repeat:

N/A

>Fix:

--- apply-slist.diff begins here ---
--- bsd.port.mk.old	Tue May 25 00:34:45 2004
+++ bsd.port.mk	Tue May 25 01:12:09 2004
@@ -718,6 +718,17 @@
 #				  (default: ${WRKDIR}/.PLIST.mktmp).
 # PLIST_SUB		- List of "variable=value" pair for substitution in ${PLIST}
 # 				  (default: see below).
+#
+# SUB_FILES		- Files that should be passed through sed and redirected to ${WRKDIR}.
+#				- For each file specified in SUB_FILES, there must be a corresponding
+#				  file in ${FILESDIR} whose suffix is ".in". For instance,
+#				  if the Makefile specifies "SUB_FILES= pkg-message" then there must be
+#				  a file called pkg-message.in in ${FILESDIR}.
+#				- The substitution process is the same as PLIST_FILES, as described
+#				  below
+# SUB_LIST		- List of "variable=value" pair for substitution in ${SUB_FILES}
+# 				  (some pair are added by default: eg. PREFIX=${PREFIX}).
+#
 # INSTALLS_SHLIB - If set, bsd.port.mk will automatically run ldconfig commands
 #				  from post-install and also add appropriate @exec/@unexec
 #				  directives to directories listed in LDCONFIG_DIRS.
@@ -1206,6 +1217,8 @@
 INSTALL_WRKSRC?=${WRKSRC}
 
 PLIST_SUB+=	OSREL=${OSREL} PREFIX=%D LOCALBASE=${LOCALBASE} X11BASE=${X11BASE}
+SUB_LIST+=	PREFIX=${PREFIX} LOCALBASE=${LOCALBASE} X11BASE=${X11BASE}	\
+			DATADIR=${DATADIR} DOCSDIR=${DOCSDIR} EXAMPLESDIR=${EXAMPLESDIR}
 
 .if defined(WITHOUT_CPU_CFLAGS)
 .if defined(_CPUCFLAGS)
@@ -3489,7 +3502,7 @@
 _INSTALL_DEP=	build
 _INSTALL_SEQ=	install-message check-conflicts \
 			    run-depends lib-depends pre-install pre-install-script \
-				generate-plist check-already-installed
+				apply-slist generate-plist check-already-installed
 _INSTALL_SUSEQ= check-umask install-mtree pre-su-install \
 				pre-su-install-script do-install post-install add-plist-info \
 				post-install-script add-plist-docs compress-man run-ldconfig fake-pkg \
@@ -4478,6 +4491,26 @@
 	@${ECHO_CMD} '" to run.'
 .endif
 .endif
+
+_SUB_LIST_TEMP=	${SUB_LIST:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/}
+.if !target(apply-slist)
+apply-slist:
+.if defined(SUB_FILES)
+.for file in ${SUB_FILES}
+.if !exists(${FILESDIR}/${file}.in)
+	@${ECHO_CMD} "** Missing ${FILESDIR}/${file}.in for ${PKGNAME}."; exit 1
+.else
+	@${CAT} ${FILESDIR}/${file}.in | ${SED} ${_SUB_LIST_TEMP} > ${WRKDIR}/${file}
+.endif
+.endfor
+.for i in pkg-message pkg-install pkg-deinstall pkg-req
+.if ${SUB_FILES:M${i}*}!=""
+${i:S/-//:U}=	${WRKDIR}/${SUB_FILES:M${i}*}
+.endif
+.endfor
+.endif
+.endif
+
 
 # Generate packing list.  Also tests to make sure all required package
 # files exist.
--- apply-slist.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040525000247.ED5F6CD4>