OPTIONSFILE path [HEADS UP: New bsd.*.mk changes]

Oliver Eikemeier eikemeier at fillmore-labs.com
Wed Jan 21 08:36:32 PST 2004


Joe Marcus Clarke wrote:

> On Tue, 2004-01-20 at 13:41, Eivind Eklund wrote:
> 
>>On Tue, Jan 20, 2004 at 01:20:45PM -0500, Joe Marcus Clarke wrote:
>>
>>>>I totally agree that nobody want to use a variable called 'LATEST_LINK' used for that
>>>>purpose, but, hey, it's just a name. If we use something like
>>>>OPTIONSNAME?=${LATEST_LINK}
>>>>we have to use an workaround only for the port that build no packages, the rest should
>>>>be automagically right. All the work of thinking of an unique name has already been done
>>>>for a lot of ports.
>>>
>>>Yes, sorry I've missed some of these points.  I'm trying to balance real
>>>work and this discussion.  You're right that we could just "borrow"
>>>LATEST_LINK for the options purpose, but it will require your
>>>re-ordering patch that will require testing on bento.
>>>
>>>So, the way I see it, we could keep things the way they are and wait for
>>>the next experimental build cycle, or commit a UNIQUENAME patch that is
>>>temporary until LATEST_LINK can be evaluated.  Once that gets decided,
>>>we can PR the patch we want tested.
>>
>>We take a hit if we put OPTIONS into production without a final settlement
>>on this, as the options are saved and the users would lose the options they
>>have set in the meantime.
> 
> I just committed this patch.  Oliver, if you want to modify your patch,
> and send-pr it, we can evaluate that during the next experimental
> patches build.  Also, if anyone wants to fix the target logic with
> persisting options, please send-pr any patches you come up with.

I admit that I'm not very happy with what seems to be making a mountain out of
a molehill, but OPTIONSFILE still doesn't work the way we want it to:

- We need OPTIONSFILE in bsd.port.pre.mk to check for existing options.
- WITH_*/WITHOUT_* options are available *after* bsd.port.pre.mk
- Some ports set their PKGNAMESUFFIX depending on the options,
  like -apache2 in www/mod_jk, or -nox11
- Some ports need a different set of options depending on PKGNAMESUFFIX,
  like -client and -server

I can offer a patch which does the following:

- Uses ${PORT_DBDIR}/${UNIQUENAME}/options
  if UNIQUENAME is defined
- Uses ${PORT_DBDIR}/${LATEST_LINK}/options
  if UNIQUENAME is undefined and LATEST_LINK is defined
- Uses ${PORT_DBDIR}/${PKGNAMEPREFIX}${PORTNAME}/options
  if UNIQUENAME and LATEST_LINK are undefined

This requires PKGNAMEPREFIX, UNIQUENAME and LATEST_LINK to be defined
*before* including bsd.port.pre.mk. In the case of LATEST_LINK this
still may be a source of confusion, because it normally depends on
PKGNAMEPREFIX, e.g. if someone does:

LATEST_LINK=	myport123${PKGNAMESUFFIX}

.include <bsd.port.pre.mk>

.if defined(CLIENT_ONLY)
PKGNAMESUFFIX=	-client
.else
PKGNAMESUFFIX=	-server
.endif

She gets /var/db/ports/myport123/options for both -client and -server parts.
`make config' sees /var/db/ports/myport123-server/options, though. Of course
I can play the same game with UNIQUENAME, so setting LATEST_LINK aside does
not really buy anything.

This patch tries to guard against this by evaluating OPTIONSFILE early and
checking if this value does not change.

Some more changes are:

- bring the ===> messages in line with the existing ones by using PKGNAME
  instead of PORTNAME
- the same for the dialog title
- use ECHO_CMD instead of ECHO_MSG to write the OPTIONSFILE comment,
  add a line with the PKGNAME
- issue a note during compiling that user-specified options have been found
- make the output of the showconfig target a little more user friendly, even
  though unformatted.
- eliminate some verbatim uses of dirname, rm and id

Sorry for making all the fuss about the OPTIONS macro, but I think it's *bad*
if somehow ports get compiled with unexpected options, and currently that is
more than likely.

-Oliver

Index: /usr/ports/Mk/bsd.port.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.480
diff -u -r1.480 bsd.port.mk
--- /usr/ports/Mk/bsd.port.mk	20 Jan 2004 22:27:01 -0000	1.480
+++ /usr/ports/Mk/bsd.port.mk	21 Jan 2004 16:23:26 -0000
@@ -70,7 +70,7 @@
 # PKGNAMESUFFIX	- Suffix to specify compilation options.  Optional.
 #				  Do not define this in your Makefile.
 # UNIQUENAME	- A name for your port that is globally unique.  By default,
-# 				  this is set to ${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}
+# 				  this is set to ${LATEST_LINK} when set, ${PKGNAMEPREFIX}${PORTNAME} else
 # DISTNAME		- Name of port or distribution used in generating
 #				  WRKSRC and DISTFILES below (default:
 #				  ${PORTNAME}-${PORTVERSION}).
@@ -899,6 +899,7 @@
 CUT?=		/usr/bin/cut
 DC?=		/usr/bin/dc
 DIALOG?=	/usr/bin/dialog
+DIRNAME?=	/usr/bin/dirname
 EGREP?=		/usr/bin/egrep
 EXPR?=		/bin/expr
 FALSE?=		false				# Shell builtin
@@ -1019,13 +1020,18 @@
 # where 'make config' records user configuration options
 PORT_DBDIR?=	/var/db/ports
 
-UNIQUENAME?=${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}
-OPTIONSFILE?=${PORT_DBDIR}/${UNIQUENAME}/options
-.if exists(${OPTIONSFILE})
-.include "${OPTIONSFILE}"
+.if defined(LATEST_LINK)
+UNIQUENAME?=	${LATEST_LINK}
+.else
+UNIQUENAME?=	${PKGNAMEPREFIX}${PORTNAME}
+.endif
+OPTIONSFILE?=	${PORT_DBDIR}/${UNIQUENAME}/options
+_OPTIONSFILE!=	${ECHO_CMD} "${OPTIONSFILE}"
+.if exists(${_OPTIONSFILE}) && !make(rmconfig)
+.include "${_OPTIONSFILE}"
 .endif
-.if exists(${OPTIONSFILE}.local)
-.include "${OPTIONSFILE}.local"
+.if exists(${_OPTIONSFILE}.local)
+.include "${_OPTIONSFILE}.local"
 .endif
 
 # check for old, crufty, makefile types, part 1:
@@ -1950,7 +1956,7 @@
 MTREE_ARGS?=	-U ${MTREE_FOLLOWS_SYMLINKS} -f ${MTREE_FILE} -d -e -p
 
 # Determine whether or not we can use rootly owner/group functions.
-UID!=	id -u
+UID!=	${ID} -u
 .if ${UID} == 0
 _BINOWNGRP=	-o ${BINOWN} -g ${BINGRP}
 _SHROWNGRP=	-o ${SHAREOWN} -g ${SHAREGRP}
@@ -2888,7 +2894,7 @@
 ################################################################
 .if (!defined(OPTIONS) || defined(CONFIG_DONE) || \
 	defined(PACKAGE_BUILDING) || defined(BATCH) || \
-	exists(${OPTIONSFILE}) || exists(${OPTIONSFILE}.local))
+	exists(${_OPTIONSFILE}) || exists(${_OPTIONSFILE}.local))
 _OPTIONS_OK=yes
 .endif
 
@@ -2965,6 +2971,13 @@
 .else
 	@${DO_NADA}
 .endif
+.if defined(_OPTIONS_READ)
+	@${ECHO_MSG} "===>  Found saved options for ${_OPTIONS_READ}"
+.if ${OPTIONSFILE} != ${_OPTIONSFILE}
+	@${ECHO_MSG} "===>  *** CAUTION *** Using wrong configuration file ${_OPTIONSFILE}"
+.endif
+.endif
+
 
 # Warn user about deprecated packages.  Advisory only.
 
@@ -3125,7 +3138,7 @@
 		fi \
 	done
 .if !defined(EXTRACT_PRESERVE_OWNERSHIP)
-	@if [ `id -u` = 0 ]; then \
+	@if [ `${ID} -u` = 0 ]; then \
 		${CHMOD} -R ug-s ${WRKDIR}; \
 		${CHOWN} -R 0:0 ${WRKDIR}; \
 	fi
@@ -3217,7 +3230,7 @@
 	fi
 .if defined(GNU_CONFIGURE)
 	@CONFIG_GUESS_DIRS=$$(${FIND} ${WRKDIR} -name config.guess -o -name config.sub \
-		| ${XARGS} -n 1 /usr/bin/dirname); \
+		| ${XARGS} -n 1 ${DIRNAME}); \
 	for _D in $${CONFIG_GUESS_DIRS}; do \
 		${CP} -f ${TEMPLATES}/config.guess $${_D}/config.guess; \
 		${CHMOD} a+rx $${_D}/config.guess; \
@@ -3462,7 +3475,7 @@
 .if !target(install-mtree)
 install-mtree:
 	@${MKDIR} ${PREFIX}
-	@if [ `id -u` != 0 ]; then \
+	@if [ `${ID} -u` != 0 ]; then \
 		if [ -w ${PREFIX}/ ]; then \
 			${ECHO_MSG} "Warning: not superuser, you may get some errors during installation."; \
 		else \
@@ -3471,7 +3484,7 @@
 		fi; \
 	fi
 .if !defined(NO_MTREE)
-	@if [ `id -u` = 0 ]; then \
+	@if [ `${ID} -u` = 0 ]; then \
 		if [ ! -f ${MTREE_FILE} ]; then \
 			${ECHO_CMD} "Error: mtree file \"${MTREE_FILE}\" is missing."; \
 			${ECHO_CMD} "Copy it from a suitable location (e.g., /usr/src/etc/mtree) and try again."; \
@@ -3554,7 +3567,7 @@
 #   4.  startup scripts, in conjunction with 2.
 #   5.  world-writable files/dirs
 #
-	- at rm -f ${WRKDIR}/.PLIST.setuid ${WRKDIR}/.PLIST.stupid \
+	-@${RM} -f ${WRKDIR}/.PLIST.setuid ${WRKDIR}/.PLIST.stupid \
 		${WRKDIR}/.PLIST.network ${WRKDIR}/.PLIST.writable; \
 	if [ -n "$$PORTS_AUDIT" ]; then \
 		stupid_functions_regexp=' (gets|mktemp|tempnam|tmpnam|strcpy|strcat|sprintf)$$'; \
@@ -4629,7 +4642,7 @@
 
 .if !target(readme)
 readme:
-	@rm -f ${.CURDIR}/README.html
+	@${RM} -f ${.CURDIR}/README.html
 	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} ${.CURDIR}/README.html
 .endif
 
@@ -4684,7 +4697,7 @@
 .if !target(generate-plist)
 generate-plist:
 	@${ECHO_MSG} "===>   Generating temporary packing list"
-	@${MKDIR} `dirname ${TMPPLIST}`
+	@${MKDIR} `${DIRNAME} ${TMPPLIST}`
 	@if [ ! -f ${DESCR} ]; then ${ECHO_CMD} "** Missing pkg-descr for ${PKGNAME}."; exit 1; fi
 	@>${TMPPLIST}
 	@for file in ${PLIST_FILES}; do \
@@ -4903,10 +4916,14 @@
 .if !defined(OPTIONS)
 	@${ECHO_MSG} "===> No options to configure"
 .else
-	@(${MKDIR} ${PORT_DBDIR}/${UNIQUENAME} 2> /dev/null) || \
-		(${ECHO_MSG} "===> Cannot create ${PORT_DBDIR}/${UNIQUENAME}, check permissions"; exit 1)
-	- at if [ -e ${OPTIONSFILE} ]; then \
-		. ${OPTIONSFILE}; \
+.if ${OPTIONSFILE} != ${_OPTIONSFILE}
+	@${ECHO_MSG} "===> Using wrong configuration file ${_OPTIONSFILE}"
+	@exit 1
+.endif
+	@(${MKDIR} `${DIRNAME} ${_OPTIONSFILE}` 2> /dev/null) || \
+		(${ECHO_MSG} "===> Cannot create `${DIRNAME} ${_OPTIONSFILE}`, check permissions"; exit 1)
+	- at if [ -e ${_OPTIONSFILE} ]; then \
+		. ${_OPTIONSFILE}; \
 	fi; \
 	set ${OPTIONS} XXX; \
 	while [ $$# -gt 3 ]; do \
@@ -4916,7 +4933,6 @@
 		withoutvar=WITHOUT_$$1; \
 		withval=$$(eval ${ECHO_CMD} $$\{$${withvar}\}); \
 		withoutval=$$(eval ${ECHO_CMD} $$\{$${withoutvar}\}); \
-		${ECHO_CMD} $${withval}; \
 		if [ ! -z "$${withval}" ]; then \
 			val=on; \
 		elif [ ! -z "$${withoutval}" ]; then \
@@ -4926,10 +4942,10 @@
 		fi; \
 		DEFOPTIONS="$${DEFOPTIONS} $$1 \"$$2\" $${val}"; \
 		shift 3; \
-	done > /dev/null; \
+	done; \
 	TMPOPTIONSFILE=$$(mktemp -t portoptions); \
 	trap "${RM} -f $${TMPOPTIONSFILE}; exit 1" 1 2 3 5 10 13 15; \
-	${SH} -c "${DIALOG} --checklist \"Options for ${PORTNAME} ${PORTVERSION}\" 21 70 15 $${DEFOPTIONS} 2> $${TMPOPTIONSFILE}"; \
+	${SH} -c "${DIALOG} --checklist \"Options for ${PKGNAME:C/-([^-]+)$/ \1/}\" 21 70 15 $${DEFOPTIONS} 2> $${TMPOPTIONSFILE}"; \
 	status=$$?; \
 	if [ $${status} -ne 0 ] ; then \
 		${RM} -f $${TMPOPTIONSFILE}; \
@@ -4937,19 +4953,21 @@
 		exit 0; \
 	fi; \
 	if [ ! -e ${TMPOPTIONSFILE} ]; then \
-		${ECHO_MSG} "===> No user-specified options to save for ${PORTNAME}"; \
+		${ECHO_MSG} "===> No user-specified options to save for ${PKGNAME}"; \
 		exit 0; \
 	fi; \
 	SELOPTIONS=$$(${CAT} $${TMPOPTIONSFILE}); \
 	${RM} -f $${TMPOPTIONSFILE}; \
-	${ECHO_MSG} "# This file is auto-generated by 'make config'.  No user-servicable parts" > ${OPTIONSFILE}; \
-	${ECHO_MSG} "# inside!" >> ${OPTIONSFILE}; \
+	${ECHO_CMD} "# This file is auto-generated by 'make config'." > ${_OPTIONSFILE}; \
+	${ECHO_CMD} "# No user-servicable parts inside!" >> ${_OPTIONSFILE}; \
+	${ECHO_CMD} "# Options for ${PKGNAME}" >> ${_OPTIONSFILE}; \
+	${ECHO_CMD} "_OPTIONS_READ=${PKGNAME}" >> ${_OPTIONSFILE}; \
 	for i in $${OPTIONSLIST}; do \
 		${ECHO_CMD} $${SELOPTIONS} | ${GREP} -qw $${i}; \
 		if [ $$? -eq 0 ]; then \
-			${ECHO_CMD} WITH_$${i}=true >> ${OPTIONSFILE}; \
+			${ECHO_CMD} WITH_$${i}=true >> ${_OPTIONSFILE}; \
 		else \
-			${ECHO_CMD} WITHOUT_$${i}=true >> ${OPTIONSFILE}; \
+			${ECHO_CMD} WITHOUT_$${i}=true >> ${_OPTIONSFILE}; \
 		fi; \
 	done
 .endif
@@ -4957,9 +4975,28 @@
 
 .if !target(showconfig)
 showconfig:
-.if exists(${OPTIONSFILE})
-	@${ECHO_MSG} "===> The following configuration options are set for ${PORTNAME}"; \
-	${GREP} -v ^# ${OPTIONSFILE}
+.if exists(${_OPTIONSFILE})
+	@${ECHO_MSG} "===> The following configuration options are set for ${PKGNAME}:"
+	- at if [ -e ${_OPTIONSFILE} ]; then \
+		. ${_OPTIONSFILE}; \
+	fi; \
+	set ${OPTIONS} XXX; \
+	while [ $$# -gt 3 ]; do \
+		defaultval=$$3; \
+		withvar=WITH_$$1; \
+		withoutvar=WITHOUT_$$1; \
+		withval=$$(eval ${ECHO_CMD} $$\{$${withvar}\}); \
+		withoutval=$$(eval ${ECHO_CMD} $$\{$${withoutvar}\}); \
+		if [ ! -z "$${withval}" ]; then \
+			val=on; \
+		elif [ ! -z "$${withoutval}" ]; then \
+			val=off; \
+		else \
+			val="$$3 (default)"; \
+		fi; \
+		${ECHO_MSG} "     $$1=$${val} \"$$2\""; \
+		shift 3; \
+	done
 .else
 	@${ECHO_MSG} "===> No configuration options are set for this port"
 .if defined(OPTIONS)
@@ -4970,12 +5007,12 @@
 
 .if !target(rmconfig)
 rmconfig:
-.if exists(${OPTIONSFILE})
-	-@${ECHO_MSG} "===> Removing user-configured options for ${PORTNAME}"; \
-	${RM} -f ${OPTIONSFILE}; \
-	${RMDIR} ${PORT_DBDIR}/${UNIQUENAME}
+.if exists(${_OPTIONSFILE})
+	-@${ECHO_MSG} "===> Removing user-configured options for ${PKGNAME}"; \
+	${RM} -f ${_OPTIONSFILE}; \
+	${RMDIR} `${DIRNAME} ${_OPTIONSFILE}`
 .else
-	@${ECHO_MSG} "===> No user-specified options configured for ${PORTNAME}"
+	@${ECHO_MSG} "===> No user-specified options configured for ${PKGNAME}"
 .endif
 .endif
 



More information about the freebsd-ports mailing list