From eikemeier@fillmore-labs.com  Sat Mar 13 14:13:55 2004
Return-Path: <eikemeier@fillmore-labs.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4838E16A4CE
	for <FreeBSD-gnats-submit@FreeBSD.org>; Sat, 13 Mar 2004 14:13:55 -0800 (PST)
Received: from postman.arcor.de (postman2.arcor-online.net [151.189.0.152])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 85FBF43D1F
	for <FreeBSD-gnats-submit@FreeBSD.org>; Sat, 13 Mar 2004 14:13:54 -0800 (PST)
	(envelope-from eikemeier@fillmore-labs.com)
Received: from fillmore.dyndns.org (port-212-202-51-138.reverse.qsc.de [212.202.51.138])
	(authenticated bits=0)
	by postman.arcor.de (8.13.0.PreAlpha4/8.13.0.PreAlpha4) with ESMTP id i2DMDmko025856
	(version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO)
	for <FreeBSD-gnats-submit@FreeBSD.org>; Sat, 13 Mar 2004 23:13:49 +0100 (MET)
Received: from [172.16.0.2] (helo=fillmore-labs.com)
	by fillmore.dyndns.org with esmtp (Exim 4.30; FreeBSD)
	id 1B2HO3-0002fs-OW
	for FreeBSD-gnats-submit@FreeBSD.org; Sat, 13 Mar 2004 23:13:43 +0100
Message-Id: <40538796.90306@fillmore-labs.com>
Date: Sat, 13 Mar 2004 23:13:42 +0100
From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: FreeBSD-gnats-submit@FreeBSD.org
Subject: [PATCH] bsd.port.mk: improved OPTIONS handling

>Number:         64233
>Category:       ports
>Synopsis:       [PATCH] bsd.port.mk: improved OPTIONS handling
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 13 14:20:15 PST 2004
>Closed-Date:    Sat Jun 26 09:08:03 GMT 2004
>Last-Modified:  Sat Jun 26 09:08:03 GMT 2004
>Originator:     Oliver Eikemeier
>Release:        FreeBSD 4.9-STABLE i386
>Organization:
Fillmore Labs - http://www.fillmore-labs.com
>Environment:
System: FreeBSD nuuk.fillmore-labs.com 4.9-STABLE

>Description:

This patch addresses multiple problems with current OPTIONS
handling, including PR 63293, and incorporates PR 63682.

Features:

- tell the user that saved options are read and how to
  change them

- enable `make WITH_*=yes' again, even when ABC is an
  OPTION. IMHO WITHOUT_xxx should be deprecated.

- create a default OPTIONS files when none exist, to enable
  builds with BATCH or PACKAGE_BUILDING defined.

- introduce OPTIONS_VERSION, to enable port maintainers to
  invalidate incompatible previously saved OPTIONS. We need
  some guidelines when to do this.

- move OPTIONS processing to bsd.port.post.mk, so that
    .include <bsd.port.pre.mk>
    .if ${OSVERSION} >= ...
    OPTIONS += ...
    .endif
    .include <bsd.port.post.mk>
  is possible

- include OPTIONSFILE *before* anything else, so that
    .if defined(WITH_OPENSSL)
    USE_OPENSSL=    yes
    .endif
    .include <bsd.port.mk>
  is possible

>How-To-Repeat:
>Fix:

This patch needs thorough testing. Also, two known caveats:

- `make describe' pops up an configuration dialog

- options message is output multiple times if USE_SUBMAKE is set

I'll rework that part before it is committed.


Index: bsd.port.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.484
diff -u -r1.484 bsd.port.mk
--- bsd.port.mk	4 Feb 2004 04:27:04 -0000	1.484
+++ bsd.port.mk	13 Mar 2004 21:41:01 -0000
@@ -1032,25 +1032,6 @@
 USE_SUBMAKE=	yes
 .endif
 
-# where 'make config' records user configuration options
-PORT_DBDIR?=	/var/db/ports
-
-.if defined(LATEST_LINK)
-UNIQUENAME?=	${LATEST_LINK}
-.else
-UNIQUENAME?=	${PKGNAMEPREFIX}${PORTNAME}
-.endif
-OPTIONSFILE?=	${PORT_DBDIR}/${UNIQUENAME}/options
-_OPTIONSFILE!=	${ECHO_CMD} "${OPTIONSFILE}"
-.if defined(OPTIONS)
-.if exists(${_OPTIONSFILE}) && !make(rmconfig)
-.include "${_OPTIONSFILE}"
-.endif
-.if exists(${_OPTIONSFILE}.local)
-.include "${_OPTIONSFILE}.local"
-.endif
-.endif
-
 # check for old, crufty, makefile types, part 1:
 .if !defined(PORTNAME) || !defined(PORTVERSION) || defined(PKGNAME)
 check-makefile::
@@ -1281,6 +1262,24 @@
 
 _POSTMKINCLUDED=	yes
 
+# where 'make config' records user configuration options
+PORT_DBDIR?=	/var/db/ports
+
+.if defined(LATEST_LINK)
+UNIQUENAME?=	${LATEST_LINK}
+.else
+UNIQUENAME?=	${PKGNAMEPREFIX}${PORTNAME}
+.endif
+.if !defined(_OPTIONSFILE)
+OPTIONSFILE?=	${PORT_DBDIR}/${UNIQUENAME}/options
+_OPTIONSFILE!=	${ECHO_CMD} "${OPTIONSFILE}"
+.endif
+_OPTIONSFLAGS=	-D_CONFIG_DONE _OPTIONSFILE=${_OPTIONSFILE:Q} -f ${_OPTIONSFILE:Q}
+.if exists(${_OPTIONSFILE:Q}.local)
+_OPTIONSFLAGS+=	-f ${_OPTIONSFILE:Q}.local
+.endif
+_OPTIONSFLAGS+=	-f Makefile
+
 WRKDIR?=		${WRKDIRPREFIX}${.CURDIR}/work
 .if defined(NO_WRKSUBDIR)
 WRKSRC?=		${WRKDIR}
@@ -2944,18 +2943,6 @@
 .endif
 
 ################################################################
-#
-# Do preliminary work to detect if we need to run the config
-# target or not.
-#
-################################################################
-.if (!defined(OPTIONS) || defined(CONFIG_DONE) || \
-	defined(PACKAGE_BUILDING) || defined(BATCH) || \
-	exists(${_OPTIONSFILE}) || exists(${_OPTIONSFILE}.local))
-_OPTIONS_OK=yes
-.endif
-
-################################################################
 # The following are used to create easy dummy targets for
 # disabling some bit of default target behavior you don't want.
 # They still check to see if the target exists, and if so don't
@@ -2965,25 +2952,25 @@
 ################################################################
 
 # Disable checksum
-.if defined(NO_CHECKSUM) && !target(checksum) && defined(_OPTIONS_OK)
+.if defined(NO_CHECKSUM) && !target(checksum)
 checksum: fetch
 	@${DO_NADA}
 .endif
 
 # Disable build
-.if defined(NO_BUILD) && !target(build) && defined(_OPTIONS_OK)
+.if defined(NO_BUILD) && !target(build)
 build: configure
 	@${TOUCH} ${TOUCH_FLAGS} ${BUILD_COOKIE}
 .endif
 
 # Disable install
-.if defined(NO_INSTALL) && !target(install) && defined(_OPTIONS_OK)
+.if defined(NO_INSTALL) && !target(install)
 install: build
 	@${TOUCH} ${TOUCH_FLAGS} ${INSTALL_COOKIE}
 .endif
 
 # Disable package
-.if defined(NO_PACKAGE) && !target(package) && defined(_OPTIONS_OK)
+.if defined(NO_PACKAGE) && !target(package)
 package:
 .if defined(IGNORE_SILENT)
 	@${DO_NADA}
@@ -3025,14 +3012,18 @@
 	@for m in ${GNOME_OPTION_MSG}; do \
 		${ECHO_MSG} $$m; \
 	done
-.else
-	@${DO_NADA}
 .endif
 .if defined(_OPTIONS_READ)
-	@${ECHO_MSG} "===>  Found saved configuration for ${_OPTIONS_READ}"
-.if ${OPTIONSFILE} != ${_OPTIONSFILE}
-	@${ECHO_MSG} "===>  *** CAUTION *** Using wrong configuration file ${_OPTIONSFILE}"
-.endif
+	@if [ "${_OPTIONS_VERSION}" -lt "${OPTIONS_VERSION}" ]; then \
+		${ECHO_MSG} "===>  Incompatible saved configuration for ${_OPTIONS_READ} detected,"; \
+		${ECHO_MSG} "      use \`make config' to change or \`make rmconfig' to reset"; \
+		${FALSE}; \
+	else \
+		${ECHO_MSG} "===>  Building with saved configuration for ${_OPTIONS_READ},"; \
+		${ECHO_MSG} "      use \`make config' to change or \`make showconfig' to view"; \
+	fi
+.else
+	@${DO_NADA}
 .endif
 
 
@@ -3812,12 +3955,13 @@
 
 .for target in extract patch configure build install package
 
-.if !target(${target}) && defined(_OPTIONS_OK)
+.if !target(${target})
+.if defined(OPTIONS) && !defined(_CONFIG_DONE)
+${target}: ${_OPTIONSFILE:Q}
+	@cd ${.CURDIR} && ${MAKE} ${_OPTIONSFLAGS} ${__softMAKEFLAGS} ${target}
+.else
 ${target}: ${${target:U}_COOKIE}
-.elif !target(${target})
-${target}: config
-	@cd ${.CURDIR} && ${MAKE} CONFIG_DONE=1 ${__softMAKEFLAGS} ${${target:U}_COOKIE}
-.elif target(${target}) && defined(IGNORE)
+.endif
 .endif
 
 .if !exists(${${target:U}_COOKIE})
@@ -3825,7 +3969,11 @@
 .if ${UID} != 0 && defined(_${target:U}_SUSEQ) && !defined(INSTALL_AS_USER)
 .if defined(USE_SUBMAKE)
 ${${target:U}_COOKIE}: ${_${target:U}_DEP}
+.if defined(OPTIONS) && defined(_CONFIG_DONE)
+	@cd ${.CURDIR} && ${MAKE} ${_OPTIONSFLAGS} ${__softMAKEFLAGS} ${_${target:U}_SEQ}
+.else
 	@cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} ${_${target:U}_SEQ}
+.endif
 .else
 ${${target:U}_COOKIE}: ${_${target:U}_DEP} ${_${target:U}_SEQ}
 .endif
@@ -3836,8 +3984,13 @@
 	@${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
 .elif defined(USE_SUBMAKE)
 ${${target:U}_COOKIE}: ${_${target:U}_DEP}
+.if defined(OPTIONS) && defined(_CONFIG_DONE)
+	@cd ${.CURDIR} && \
+		${MAKE} ${_OPTIONSFLAGS} ${__softMAKEFLAGS} ${_${target:U}_SEQ} ${_${target:U}_SUSEQ}
+.else
 	@cd ${.CURDIR} && \
 		${MAKE} ${__softMAKEFLAGS} ${_${target:U}_SEQ} ${_${target:U}_SUSEQ}
+.endif
 	@${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
 .else
 ${${target:U}_COOKIE}: ${_${target:U}_DEP} ${_${target:U}_SEQ} ${_${target:U}_SUSEQ}
@@ -3849,7 +4002,7 @@
 	@if [ -e ${.TARGET} ]; then \
 		${DO_NADA}; \
 	else \
-		cd ${.CURDIR} && ${MAKE} ${__softMAKEFLAGS} ${.TARGET}; \
+		cd ${.CURDIR} && ${MAKE} ABC=x ${__softMAKEFLAGS} ${.TARGET}; \
 	fi
 .endif
 
@@ -4697,6 +4850,10 @@
 #  description-file|maintainer|categories|build deps|run deps|www site
 
 .if !target(describe)
+.if defined(OPTIONS) && !defined(_CONFIG_DONE)
+describe: ${_OPTIONSFILE:Q}
+	@cd ${.CURDIR} && ${MAKE} ${_OPTIONSFLAGS} ${__softMAKEFLAGS} describe
+.else
 describe:
 	@${ECHO_CMD} -n '${PKGNAME}|${.CURDIR}|${PREFIX}|'
 .if defined(COMMENT)
@@ -4746,6 +4903,7 @@
 		} \
 		print qq{\n};'`"
 .endif
+.endif
 
 www-site:
 .if exists(${DESCR})
@@ -5029,15 +5187,16 @@
 .endif
 
 .if !target(config)
-config:
-	@${MKDIR} ${WRKDIR}
-.if !defined(OPTIONS)
-	@${ECHO_MSG} "===> No options to configure"
-.else
-.if ${OPTIONSFILE} != ${_OPTIONSFILE}
-	@${ECHO_MSG} "===> Using wrong configuration file ${_OPTIONSFILE}"
-	@exit 1
+config: create-config
 .endif
+
+${_OPTIONSFILE:Q}: create-config
+
+OPTIONS_VERSION?=	0
+
+.if !target(create-config)
+create-config: .USE
+.if defined(OPTIONS)
 .if ${UID} != 0 && !defined(INSTALL_AS_USER)
 	@${ECHO_MSG} "===>  Switching to root credentials to create `${DIRNAME} ${_OPTIONSFILE}`"
 	@(${SU_CMD} "${MKDIR} `${DIRNAME} ${_OPTIONSFILE}` 2> /dev/null") || \
@@ -5047,8 +5206,8 @@
 	@(${MKDIR} `${DIRNAME} ${_OPTIONSFILE}` 2> /dev/null) || \
 		(${ECHO_MSG} "===> Cannot create `${DIRNAME} ${_OPTIONSFILE}`, check permissions"; exit 1)
 .endif
-	-@if [ -e ${_OPTIONSFILE} ]; then \
-		. ${_OPTIONSFILE}; \
+	-@if [ -r "${_OPTIONSFILE}" ]; then \
+		. "${_OPTIONSFILE}"; \
 	fi; \
 	set ${OPTIONS} XXX; \
 	while [ $$# -gt 3 ]; do \
@@ -5065,17 +5224,25 @@
 		else \
 			val=$$3; \
 		fi; \
+		if ${EXPR} "$$3" : '[Oo][Nn]$$' >/dev/null; then \
+			DEFAULT_OPTIONS="$${DEFAULT_OPTIONS} $$1"; \
+		fi; \
 		DEFOPTIONS="$${DEFOPTIONS} $$1 \"$$2\" $${val}"; \
 		shift 3; \
 	done; \
 	TMPOPTIONSFILE=$$(mktemp -t portoptions); \
 	trap "${RM} -f $${TMPOPTIONSFILE}; exit 1" 1 2 3 5 10 13 15; \
-	${SH} -c "${DIALOG} --checklist \"Options for ${PKGNAME:C/-([^-]+)$/ \1/}\" 21 70 15 $${DEFOPTIONS} 2> $${TMPOPTIONSFILE}"; \
-	status=$$?; \
-	if [ $${status} -ne 0 ] ; then \
-		${RM} -f $${TMPOPTIONSFILE}; \
-		${ECHO_MSG} "===> Options unchanged"; \
-		exit 0; \
+	if [ -z "${PACKAGE_BUILDING}" -a -z "${BATCH}" ]; then \
+		${SH} -c "${DIALOG} --checklist \"Options for ${PKGNAME:C/-([^-]+)$/ \1/}\" 21 70 15 $${DEFOPTIONS} 2> $${TMPOPTIONSFILE}"; \
+		status=$$?; \
+		if [ $${status} -ne 0 ] ; then \
+			${RM} -f $${TMPOPTIONSFILE}; \
+			${ECHO_MSG} "===> Options unchanged"; \
+			exit 0; \
+		fi; \
+	else \
+		${ECHO_MSG} "===> Saving default options for ${PKGNAME}"; \
+		${ECHO_CMD} $${DEFAULT_OPTIONS} > $${TMPOPTIONSFILE}; \
 	fi; \
 	if [ ! -e ${TMPOPTIONSFILE} ]; then \
 		${ECHO_MSG} "===> No user-specified options to save for ${PKGNAME}"; \
@@ -5089,6 +5256,7 @@
 	${ECHO_CMD} "# No user-servicable parts inside!" >> $${TMPOPTIONSFILE}; \
 	${ECHO_CMD} "# Options for ${PKGNAME}" >> $${TMPOPTIONSFILE}; \
 	${ECHO_CMD} "_OPTIONS_READ=${PKGNAME}" >> $${TMPOPTIONSFILE}; \
+	${ECHO_CMD} "_OPTIONS_VERSION=${OPTIONS_VERSION}" >> $${TMPOPTIONSFILE}; \
 	for i in $${OPTIONSLIST}; do \
 		${ECHO_CMD} $${SELOPTIONS} | ${GREP} -qw $${i}; \
 		if [ $$? -eq 0 ]; then \
@@ -5105,53 +5273,55 @@
 		${CAT} $${TMPOPTIONSFILE} > ${_OPTIONSFILE}; \
 	fi; \
 	${RM} -f $${TMPOPTIONSFILE}
+.else
+	@${ECHO_MSG} "===> No options to configure"
 .endif
 .endif
 
 .if !target(showconfig)
 showconfig:
-.if defined(OPTIONS) && exists(${_OPTIONSFILE})
-	@${ECHO_MSG} "===> The following configuration options are set for ${PKGNAME}:"
-	-@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)
-	@${ECHO_MSG} "	Use 'make config' to set default values"
-.endif
+	@if [ -r "${_OPTIONSFILE}" ]; then \
+		${ECHO_MSG} "===> The following configuration options are set for ${PKGNAME}:"; \
+		. "${_OPTIONSFILE}"; \
+		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; \
+			${PRINTF} "%-16s = %-3s - %s\n" "$$1" "$${val}" "$$2"; \
+			shift 3; \
+		done; \
+	else \
+		${ECHO_MSG} "===> No configuration options are set for this port"; \
+		${ECHO_MSG} "	Use 'make config' to set default values"; \
+	fi
+.else
+	@${ECHO_MSG} "===> No configuration options are set for this port";
 .endif
 .endif
 
 .if !target(rmconfig)
 rmconfig:
-.if defined(OPTIONS) && exists(${_OPTIONSFILE})
-	-@${ECHO_MSG} "===> Removing user-configured options for ${PKGNAME}"; \
+.if defined(OPTIONS)
+	@${ECHO_MSG} "===> Removing user-configured configuration for ${PKGNAME}"; \
 	if [ `${ID} -u` != 0 -a "x${INSTALL_AS_USER}" = "x" ]; then \
 		${ECHO_MSG} "===> Switching to root credentials to remove ${_OPTIONSFILE} and `${DIRNAME} ${_OPTIONSFILE}`"; \
-		${SU_CMD} "${RM} -f ${_OPTIONSFILE} ; \
-			${RMDIR} `${DIRNAME} ${_OPTIONSFILE}`"; \
+		${SU_CMD} "${RM} -f \"${_OPTIONSFILE}\" ; \
+			${RMDIR} `${DIRNAME} \"${_OPTIONSFILE}\"` || ${TRUE}"; \
 		${ECHO_MSG} "===> Returning to user credentials"; \
 	else \
-		${RM} -f ${_OPTIONSFILE}; \
-		${RMDIR} `${DIRNAME} ${_OPTIONSFILE}`; \
+		[ -f "${_OPTIONSFILE}" ] && ${RM} -f "${_OPTIONSFILE}"; \
+		${RMDIR} `${DIRNAME} "${_OPTIONSFILE}"` || ${TRUE}; \
 	fi
 .else
 	@${ECHO_MSG} "===> No user-specified options configured for ${PKGNAME}"

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->portmgr 
Responsible-Changed-By: eik 
Responsible-Changed-When: Sat Mar 13 23:20:16 CET 2004 
Responsible-Changed-Why:  
ports infrastructure 

http://www.freebsd.org/cgi/query-pr.cgi?pr=64233 

From: Kris Kennaway <kris@obsecurity.org>
To: Oliver Eikemeier <eik@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: ports/64233: [PATCH] bsd.port.mk: improved OPTIONS handling
Date: Fri, 25 Jun 2004 19:02:14 -0700

 On Sat, Mar 13, 2004 at 02:22:04PM -0800, Oliver Eikemeier wrote:
 > Old Synopsis: [PATCH] bsd.port.mk: OPTIONS handling proposal
 > New Synopsis: [PATCH] bsd.port.mk: improved OPTIONS handling
 > 
 > Responsible-Changed-From-To: freebsd-ports-bugs->portmgr
 > Responsible-Changed-By: eik
 > Responsible-Changed-When: Sat Mar 13 23:20:16 CET 2004
 > Responsible-Changed-Why: 
 > ports infrastructure
 > 
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=64233
 
 This PR says "...incorporates PR 63682" -- I tested that PR recently,
 and it was found to cause problems (see the audit trail).  However,
 the submitter subsequently closed the PR with the annotation "Too much
 has changed in bsd.port.mk to get this patch working.".  Can you
 please investigate?
 
 Kris
State-Changed-From-To: open->closed 
State-Changed-By: eik 
State-Changed-When: Sat Jun 26 11:05:48 CEST 2004 
State-Changed-Why:  
I'm not working on an OPTIONS patch any longer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=64233 
>Unformatted:
