Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Mar 2004 23:13:42 +0100
From:      Oliver Eikemeier <eikemeier@fillmore-labs.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/64233: [PATCH] bsd.port.mk: new variable DISTVERSION, raw distribution version
Message-ID:  <40538796.90306@fillmore-labs.com>
Resent-Message-ID: <200403132220.i2DMKFmB070239@freefall.freebsd.org>

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

>Number:         64233
>Category:       ports
>Synopsis:       [PATCH] bsd.port.mk: OPTIONS handling proposal
>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:   Sat Mar 13 14:20:15 PST 2004
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



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