Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Dec 2012 10:14:05 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r308598 - in head: . Mk
Message-ID:  <201212101014.qBAAE5xX084461@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Mon Dec 10 10:14:05 2012
New Revision: 308598
URL: http://svnweb.freebsd.org/changeset/ports/308598

Log:
  Extend the options framework providing 2 new macros:
  
  OPTIONS_RADIO: a more user friendly way to allow selecting only 0 or 1 options
                 among a list of options
  OPTIONS_GROUP: this macros should be used to group options by theme allowing the
                 user to select 0 or N options among a list of options
  
  With hat:	portmgr
  Reviewed by:	beat

Modified:
  head/CHANGES
  head/Mk/bsd.options.mk
  head/Mk/bsd.port.mk

Modified: head/CHANGES
==============================================================================
--- head/CHANGES	Mon Dec 10 10:05:43 2012	(r308597)
+++ head/CHANGES	Mon Dec 10 10:14:05 2012	(r308598)
@@ -10,6 +10,13 @@ in the release notes and/or placed into 
 
 All ports committers are allowed to commit to this file.
 
+20121210:
+AUTHOR: bapt@FreeBSD.org
+  * OPTIONS has been extended 2 new macros are available:
+
+    OPTIONS_RADIO - allows only 0 or 1 options to be selected
+    OPTIONS_GROUP - allows 0 or N options among to be selected
+
 20121010:
 AUTHOR: bapt@FreeBSD.org
 

Modified: head/Mk/bsd.options.mk
==============================================================================
--- head/Mk/bsd.options.mk	Mon Dec 10 10:05:43 2012	(r308597)
+++ head/Mk/bsd.options.mk	Mon Dec 10 10:14:05 2012	(r308598)
@@ -12,15 +12,28 @@
 # OPTIONS_EXCLUDE_${ARCH}	- List of options unsupported on a given ${ARCH}
 # ${OPTION}_DESC		- Description the the ${OPTION}
 #
-# OPTIONS_SINGLE		- List of radio choice grouped options
-# OPTIONS_MULTI			- List of multiple-choice grouped options
+# OPTIONS_SINGLE		- List of single-choice grouped options: 1 and
+# 				  only 1 among N
+# OPTIONS_RADIO			- List of radio-choice grouped options: 0 or 1
+#				  among N
+# OPTIONS_MULTI			- List of multiple-choice grouped options: at
+#				  least 1 among N
+# OPTIONS_GROUP			- List of group-choice grouped options: 0 or
+#				  more among N
 #
-# OPTIONS_SINGLE_${NAME}	- List of OPTIONS grouped as radio choice (for
+# OPTIONS_SINGLE_${NAME}	- List of OPTIONS grouped as single choice (for
 #				the single named as ${NAME} as defined in
 #				OPTIONS_SINGLE)
-# OTPIONS_MULTI_${NAME}		- List of OPTIONS grouped as multiple-choice
-#				(for the multi named as ${NAME} as defined in 
+# OPTIONS_RADIO_${NAME}		- List of OPTIONS grouped as radio choice (for
+#				the radio named as ${NAME} as defined in
+#				OPTIONS_RADIO)
+# OPTIONS_MULTI_${NAME}		- List of OPTIONS grouped as multiple-choice
+#				(for the multi named as ${NAME} as defined in
 #				OPTIONS_MULTI)
+# OPTIONS_GROUP_${NAME}		- List of OPTIONS grouped as group-choice (for
+#				the group named as ${NAME} as defined in
+#				OPTIONS_GROUP)
+#
 # WITH				Set options from the command line
 # WITHOUT			Unset options from the command line
 
@@ -28,6 +41,8 @@
 # Set all the options available for the ports, beginning with the
 # global ones and ending with the ones decided by the maintainer.
 # Options global to the entire ports tree
+.if !defined(OPTIONSMKINCLUDED)
+OPTIONSMKINCLUDED=	bsd.options.mk
 
 OPTIONSFILE?=	${PORT_DBDIR}/${UNIQUENAME}/options
 
@@ -127,9 +142,15 @@ COMPLETE_OPTIONS_LIST=	${ALL_OPTIONS}
 .for single in ${OPTIONS_SINGLE}
 COMPLETE_OPTIONS_LIST+=	${OPTIONS_SINGLE_${single}}
 .endfor
+.for radio in ${OPTIONS_RADIO}
+COMPLETE_OPTIONS_LIST+=	${OPTIONS_RADIO_${radio}}
+.endfor
 .for multi in ${OPTIONS_MULTI}
 COMPLETE_OPTIONS_LIST+=	${OPTIONS_MULTI_${multi}}
 .endfor
+.for group in ${OPTIONS_GROUP}
+COMPLETE_OPTIONS_LIST+= ${OPTIONS_GROUP_${group}}
+.endfor
 
 ## Now create the list of activated options
 .if defined(OPTIONS_OVERRIDE)
@@ -255,4 +276,5 @@ WITH_${opt}:=  true
 .endif
 .      undef opt
 .endfor
+.endif
 ###

Modified: head/Mk/bsd.port.mk
==============================================================================
--- head/Mk/bsd.port.mk	Mon Dec 10 10:05:43 2012	(r308597)
+++ head/Mk/bsd.port.mk	Mon Dec 10 10:14:05 2012	(r308598)
@@ -3309,6 +3309,7 @@ DEPENDS_ARGS+=	NOCLEANDEPENDS=yes
 #
 ################################################################
 .if ((!defined(OPTIONS_DEFINE) && !defined(OPTIONS_SINGLE) && !defined(OPTIONS_MULTI)) \
+	&& !defined(OPTIONS_GROUP) && !defined(OPTIONS_RADIO) \
 	|| defined(CONFIG_DONE_${UNIQUENAME:U}) || \
 	defined(PACKAGE_BUILDING) || defined(BATCH))
 _OPTIONS_OK=yes
@@ -6004,6 +6005,19 @@ OPTIONS_WRONG_SINGLE+=	${single}
 .endfor
 .undef single
 
+.for radio in ${OPTIONS_RADIO}
+.  for opt in ${OPTIONS_RADIO_${radio}}
+.    if !empty(PORT_OPTIONS:M${opt})
+.      if defined(OPTFOUND)
+OPTIONS_WRONG_RADIO+=	${radio}
+.      else
+OPTFOUND=	true
+.      endif
+.    endif
+.  endfor
+.  undef OPTFOUND
+.endfor
+
 .for multi in ${OPTIONS_MULTI}
 .  for opt in ${OPTIONS_MULTI_${multi}}
 .    if empty(ALL_OPTIONS:M${multi}) || !empty(PORT_OPTIONS:M${multi})
@@ -6035,7 +6049,10 @@ _check-config: pre-check-config
 .for single in ${OPTIONS_WRONG_SINGLE}
 	@${ECHO_MSG} "====> You must select one and only one option from the ${single} single"
 .endfor
-.if !empty(OPTIONS_WRONG_MULTI) || !empty(OPTIONS_WRONG_SINGLE)
+.for radio in ${OPTIONS_WRONG_RADIO}
+	@${ECHO_MSG} "====> You cannot select multiple options from the ${radio} radio"
+.endfor
+.if !empty(OPTIONS_WRONG_MULTI) || !empty(OPTIONS_WRONG_SINGLE) || !empty(OPTIONS_WRONG_RADIO)
 _CHECK_CONFIG_ERROR=	true
 .endif
 .endif # _check-config
@@ -6087,14 +6104,33 @@ DEFOPTIONS+=	${opt} "S(${single}): "${${
 .    endif
 .  endfor
 .endfor
+.for radio in ${OPTIONS_RADIO}
+.  for opt in ${OPTIONS_RADIO_${radio}}
+.    if empty(PORT_OPTIONS:M${opt})
+DEFOPTIONS+=	${opt} "R(${radio}): "${${opt}_DESC:Q} off
+.    else
+DEFOPTIONS+=	${opt} "R(${radio}): "${${opt}_DESC:Q} on
+.    endif
+.  endfor
+.endfor
+.for group in ${OPTIONS_GROUP}
+.  for opt in ${OPTIONS_GROUP_${group}}
+.    if empty(PORT_OPTIONS:M${opt})
+DEFOPTIONS+=	${opt} "G(${group}): "${${opt}_DESC:Q} off
+.    else
+DEFOPTIONS+=	${opt} "G(${group}): "${${opt}_DESC:Q} on
+.    endif
+.  endfor
+.endfor
 .undef multi
 .undef single
+.undef group
 .undef opt
 .endif # pre-config
 
 .if !target(do-config)
 do-config:
-.if empty(ALL_OPTIONS) && empty(OPTIONS_SINGLE) && empty(OPTIONS_MULTI)
+.if empty(ALL_OPTIONS) && empty(OPTIONS_SINGLE) && empty(OPTIONS_MULTI) && empty(OPTIONS_RADIO) && empty(OPTIONS_GROUP)
 	@${ECHO_MSG} "===> No options to configure"
 .else
 .if ${UID} != 0 && !defined(INSTALL_AS_USER)
@@ -6170,7 +6206,7 @@ config-conditional: pre-config
 .if !target(showconfig)
 .include "${PORTSDIR}/Mk/bsd.options.desc.mk"
 showconfig:
-.if !empty(ALL_OPTIONS) || !empty(OPTIONS_SINGLE) || !empty(OPTIONS_MULTI)
+.if !empty(ALL_OPTIONS) || !empty(OPTIONS_SINGLE) || !empty(OPTIONS_MULTI) || !empty(OPTIONS_RADIO) || !empty(OPTIONS_GROUP)
 	@${ECHO_MSG} "===> The following configuration options are available for ${PKGNAME}":
 .for opt in ${ALL_OPTIONS}
 .  if empty(PORT_OPTIONS:M${opt})
@@ -6215,8 +6251,40 @@ showconfig:
 .  endfor
 .endfor
 
+.for radio in ${OPTIONS_RADIO}
+	@${ECHO_MSG} "====> Options available for the radio ${radio}: you can only select none or one of them"
+.  for opt in ${OPTIONS_RADIO_${radio}}
+.    if empty(PORT_OPTIONS:M${opt})
+	@${ECHO_MSG} -n "     ${opt}=off"
+.    else
+	@${ECHO_MSG} -n "     ${opt}=on"
+.    endif
+.    if !empty(${opt}_DESC)
+	@${ECHO_MSG} -n ": "${${opt}_DESC:Q}
+.    endif
+	@${ECHO_MSG} ""
+.  endfor
+.endfor
+
+.for group in ${OPTIONS_GROUP}
+	@${ECHO_MSG} "====> Options available for the group ${group}"
+.  for opt in ${OPTIONS_GROUP_${group}}
+.    if empty(PORT_OPTIONS:M${opt})
+	@${ECHO_MSG} -n "     ${opt}=off"
+.    else
+	@${ECHO_MSG} -n "     ${opt}=on"
+.    endif
+.    if !empty(${opt}_DESC)
+	@${ECHO_MSG} -n ": "${${opt}_DESC:Q}
+.    endif
+	@${ECHO_MSG} ""
+.  endfor
+.endfor
+
 .undef multi
 .undef single
+.undef radio
+.undef group
 .undef opt
 	@${ECHO_MSG} "===> Use 'make config' to modify these settings"
 .endif
@@ -6288,8 +6356,32 @@ pretty-print-config:
 .  endfor
 	@${ECHO_MSG} -n ") "
 .endfor
+.for radio in ${OPTIONS_RADIO}
+	@${ECHO_MSG} -n "${radio}( "
+.  for opt in ${OPTIONS_RADIO_${radio}}
+.    if empty(PORT_OPTIONS:M${opt})
+	@${ECHO_MSG} -n "-${opt} "
+.    else
+	@${ECHO_MSG} -n "+${opt} "
+.    endif
+.  endfor
+	@${ECHO_MSG} -n ") "
+.endfor
+.for group in ${OPTIONS_GROUP}
+	@${ECHO_MSG} -n "${group}[ "
+.  for opt in ${OPTIONS_GROUP_${group}}
+.    if empty(PORT_OPTIONS:M${opt})
+	@${ECHO_MSG} -n "-${opt} "
+.    else
+	@${ECHO_MSG} -n "+${opt} "
+.    endif
+.  endfor
+	@${ECHO_MSG} -n "] "
+.endfor
 .undef multi
 .undef single
+.undef radio
+.undef group
 .undef opt
 	@${ECHO_MSG} ""
 .endif # pretty-print-config



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