Subject: Re: *_OPTIONS for package options
To: Dieter Baron <dillo@danbala.ifoer.tuwien.ac.at>
From: Johnny C. Lam <jlam@NetBSD.org>
List: tech-pkg
Date: 07/24/2004 21:44:11
--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sat, Jul 24, 2004 at 10:55:09AM +0200, Dieter Baron wrote:
> In article <20040724054337.GT11135@fang> grant wrote:
> : maybe even better is to use ${PKGBASE} in PKG_OPTIONS (or
> : PKG_DEFAULT_OPTIONS, whatever) for the defaults and override them
> : per-pkg with PKG_OPTIONS.${PKGBASE}. we've used PKGBASE in that way
> : in some other parts of pkgsrc already :)
> 
>   Sounds good.  It might also be good to have a way to disable a
> certain option for a certain package, without overriding all other
> global settings.  Maybe prepend the option with ``-''?
> 
> # use default settings, but disable bar
> PKG_OPTION.foo= -bar

This is an excellent idea.  I've added this to bsd.options.mk.  The
latest bsd.options.mk plus ancillary changes to pkgsrc/mk files are
attached.

	Cheers,

	-- Johnny Lam <jlam@NetBSD.org>

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="bsd.options.mk"

# $NetBSD$
#
# This Makefile fragment provides boilerplate code for standard naming
# conventions for handling per-package build options.
#
# Before including this file, the following variables should be defined:
#
#	PKG_SUPPORTED_OPTIONS
#		This is a list of build options supported by the package.
#		This variable should be set in a package Makefile.
#
#	PKG_FAIL_UNSUPPORTED_OPTIONS
#		If this is set to "yes", then the presence of unsupported
#		options in PKG_OPTIONS.<pkg> (see below) causes the build
#		to fail.  Set this to "no" to silently ignore unsupported
#		options.  Default: "yes".
#
# Optionally, the following variables may also be defined:
#
#	PKG_DEFAULT_OPTIONS
#		This is a list the options that should be built into
#		every package, if that option is supported.  This
#		variable should be set in /etc/mk.conf.
#
#	PKG_OPTIONS.<pkg>
#		This is a list of selected build options that overrides
#		any default options given in PKG_DEFAULT_OPTIONS.  If
#		any of the options begin with a '-', then that option
#		is always removed from the selected build options, e.g.
#
#		PKG_DEFAULT_OPTIONS=	kerberos ldap sasl
#		PKG_OPTIONS.wibble=	-sasl
#		# implies PKG_OPTIONS == "kerberos ldap"
#
#		and:
#			
#		PKG_OPTIONS.wibble=	kerberos -ldap ldap
#		# implies PKG_OPTIONS == "kerberos"
#
#		This variable should be set in /etc/mk.conf.
#
# After including this file, the following variables are defined:
#
#	PKG_OPTIONS
#		This is the list of the selected build options, properly
#		filtered to remove unsupported and duplicate options.
#
# Example usage:
#
# -------------8<-------------8<-------------8<-------------8<-------------
# # Global and legacy options
# .if defined(USE_OPENLDAP) || defined(USE_SASL2)
# .  if !defined(PKG_OPTIONS.wibble)
# .    if defined(USE_OPENLDAP) && !empty(USE_OPENLDAP:M[yY][eE][sS])
# PKG_OPTIONS.wibble+=	ldap
# .    endif
# .    if defined(USE_SASL2) && !empty(USE_SASL2:M[yY][eE][sS])
# PKG_OPTIONS.wibble+=	sasl
# .    endif
# .  endif
# .endif
#
# PKG_SUPPORTED_OPTIONS=	ldap sasl
# .include "../../mk/bsd.options.mk"
#
# # Package-specific option-handling
#
# ###
# ### LDAP support
# ###
# .if !empty(PKG_OPTIONS:Mldap)
# .  include "../../databases/openldap/buildlink3.mk"
# CONFIGURE_ARGS+=	--enable-ldap=${BUILDLINK_PREFIX.openldap}
# .endif
#
# ###
# ### SASL authentication
# ###
# .if !empty(PKG_OPTIONS:Msasl)
# .  include "../../security/cyrus-sasl2/buildlink3.mk"
# CONFIGURE_ARGS+=	--enable-sasl=${BUILDLINK_PREFIX.sasl}
# .endif
# -------------8<-------------8<-------------8<-------------8<-------------

.include "../../mk/bsd.prefs.mk"

# PKG_SUPPORTED_OPTIONS lists all of the supported build options.
# PKG_OPTIONS.${PKGBASE} lists of the build options that will be used.
#
PKG_SUPPORTED_OPTIONS?=	# empty

# By default, use the global options provided in ${PKG_DEFAULT_OPTIONS}.
.if !defined(PKG_OPTIONS.${PKGBASE})
.  for _opt_ in ${PKG_DEFAULT_OPTIONS}
.    if !empty(PKG_SUPPORTED_OPTIONS:M${_opt_})
PKG_OPTIONS.${PKGBASE}+=	${_opt_}
.    endif
.  endfor
.endif

# If this is set to "yes", then the presence of unsupported options in
# PKG_OPTIONS.<pkg> causes the build to fail.  Set this to "no" to
# silently ignore unsupported options.
#
PKG_FAIL_UNSUPPORTED_OPTIONS?=	yes

# Filter out unsupported and duplicate build options and store the result
# in PKG_OPTIONS.  We keep all of the "positive" options first, then remove
# all of the "negative" options last, so "negative" options always have
# the strongest effect.
#
PKG_OPTIONS=		# empty
_PKG_YES_OPTIONS=	${PKG_OPTIONS.${PKGBASE}:N-*}
_PKG_NO_OPTIONS=	${PKG_OPTIONS.${PKGBASE}:M-*:S/^-//}
.for _opt_ in ${_PKG_YES_OPTIONS}
.  if empty(_PKG_NO_OPTIONS:M${_opt_}) && empty(PKG_OPTIONS:M${_opt_})
.    if !empty(PKG_SUPPORTED_OPTIONS:M${_opt_})
PKG_OPTIONS+=		${_opt_}
.    elif !empty(PKG_FAIL_UNSUPPORTED_OPTIONS:M[yY][eE][sS])
PKG_FAIL_REASON+=	"\"${_opt_}\" is not a supported build option."
.    endif
.  endif
.endfor

# Store the result in the +BUILD_INFO file so we can query for the build
# options using "pkg_info -Q PKG_OPTIONS <pkg>".
#
BUILD_DEFS+=		PKG_OPTIONS

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="mk.diff"

Index: bsd.pkg.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.1475
diff -u -r1.1475 bsd.pkg.mk
--- bsd.pkg.mk	6 Jul 2004 22:49:16 -0000	1.1475
+++ bsd.pkg.mk	24 Jul 2004 21:41:00 -0000
@@ -99,10 +99,6 @@
 SHLIB_HANDLING?=	YES	# do automatic shared lib handling
 NOCLEAN?=		NO	# don't clean up after update
 
-PKGBASE?=		${PKGNAME:C/-[^-]*$//}
-PKGVERSION?=		${PKGNAME:C/^.*-//}
-PKGWILDCARD?=		${PKGBASE}-[0-9]*
-
 _DISTDIR?=		${DISTDIR}/${DIST_SUBDIR}
 
 INTERACTIVE_STAGE?=	none
@@ -970,19 +966,13 @@
 
 # Derived names so that they're easily overridable.
 DISTFILES?=		${DISTNAME}${EXTRACT_SUFX}
-.if defined(PKGREVISION) && ${PKGREVISION} != "" && ${PKGREVISION} != "0"
-.  if defined(PKGNAME)
+.if defined(PKGREVISION) && !empty(PKGREVISION) && (${PKGREVISION} != "0")
 PKGNAME_NOREV:=		${PKGNAME}
 PKGNAME:=		${PKGNAME}nb${PKGREVISION}
-.  else
-PKGNAME?=		${DISTNAME}nb${PKGREVISION}
-PKGNAME_NOREV=		${DISTNAME}
-.  endif
-.else
-PKGNAME?=		${DISTNAME}
-PKGNAME_NOREV=		${PKGNAME}
-.endif
-SVR4_PKGNAME?=		${PKGNAME}
+.else                                 
+PKGNAME_NOREV=		${PKGNAME}    
+.endif                                
+SVR4_PKGNAME?=		${PKGNAME}    
 
 MAINTAINER?=		tech-pkg@NetBSD.org
 
Index: bsd.pkg.obsolete.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.obsolete.mk,v
retrieving revision 1.14
diff -u -r1.14 bsd.pkg.obsolete.mk
--- bsd.pkg.obsolete.mk	21 Jul 2004 16:19:26 -0000	1.14
+++ bsd.pkg.obsolete.mk	24 Jul 2004 21:41:00 -0000
@@ -50,45 +50,77 @@
 PKG_SYSCONFDIR.priv?=	${PRIV_CONF_DIR}
 .endif
 
-##
-## The following Postfix-related section will be removed after the
-## pkgsrc-2004Q3 branch is released.
-##
-.if defined(POSTFIX_USE_INET6) || defined(POSTFIX_USE_TLS) || \
-    defined(POSTFIX_USE_PCRE) || defined(POSTFIX_USE_MYSQL) || \
-    defined(POSTFIX_USE_PGSQL) || defined(POSTFIX_USE_VERP) || \
-    defined(POSTFIX_USE_SASL_AUTH) || defined(USE_SASL) || \
-    defined(USE_SASL2) || defined(USE_OPENLDAP)
-.  if !defined(POSTFIX_OPTIONS)
-.    if defined(POSTFIX_USE_INET6) && !empty(POSTFIX_USE_INET6:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	inet6
-.    endif
-.    if defined(POSTFIX_USE_TLS) && !empty(POSTFIX_USE_TLS:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	tls
-.    endif
-.    if defined(POSTFIX_USE_PCRE) && !empty(POSTFIX_USE_PCRE:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	pcre 
-.    endif
-.    if defined(POSTFIX_USE_MYSQL) && !empty(POSTFIX_USE_MYSQL:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	mysql
-.    endif
-.    if defined(POSTFIX_USE_PGSQL) && !empty(POSTFIX_USE_PGSQL:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	pgsql
-.    endif
-.    if defined(POSTFIX_USE_VERP) && !empty(POSTFIX_USE_VERP:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	verp
-.    endif
-.    if defined(USE_OPENLDAP) && !empty(USE_OPENLDAP:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	ldap
-.    endif
-.    if defined(POSTFIX_USE_SASL_AUTH) && defined(POSTFIX_USE_SASL_AUTH)
-USE_SASL=		YES
-.    endif
-.    if defined(USE_SASL) && !empty(USE_SASL:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	sasl
-.    endif
-.    if defined(USE_SASL2) && !empty(USE_SASL2:M[yY][eE][sS])
-POSTFIX_OPTIONS+=	sasl
-.    endif
+###
+### Set PKG_DEFAULT_OPTIONS based on global variable settings.
+###
+.if defined(KERBEROS)
+.  if ${KERBEROS} == "4"
+PKG_DEFAULT_OPTIONS+=	kerberos4
+.  else
+PKG_DEFAULT_OPTIONS+=	kerberos
 .  endif
 .endif
+.if defined(USE_CANNA) && !empty(USE_CANNA:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	canna
+.endif
+.if defined(USE_CUPS) && !empty(USE_CUPS:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	cups
+.endif
+.if defined(USE_DB4) && !empty(USE_DB4:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	db4
+.endif
+.if defined(USE_ESOUND) && !empty(USE_ESOUND:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	esound
+.endif
+.if defined(USE_GIF)
+PKG_DEFAULT_OPTIONS+=	gif
+.endif
+.if defined(USE_I586) && !empty(USE_I586:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	i586
+.endif
+.if defined(USE_IDEA) && !empty(USE_IDEA:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	idea
+.endif
+.if defined(USE_INN) && !empty(USE_INN:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	inn
+.endif
+.if defined(USE_LIBCRACK) && !empty(USE_LIBCRACK:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	libcrack
+.endif
+.if defined(USE_MMX) && !empty(USE_MMX:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	mmx
+.endif
+.if defined(USE_OPENLDAP) && !empty(USE_OPENLDAP:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	openldap
+.endif
+.if defined(USE_OSS)
+PKG_DEFAULT_OPTIONS+=	oss
+.endif
+.if defined(USE_PAM)
+PKG_DEFAULT_OPTIONS+=	pam
+.endif
+.if defined(USE_RSAREF2)
+PKG_DEFAULT_OPTIONS+=	rsaref
+.endif
+.if defined(USE_SASL) && !empty(USE_SASL:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	sasl
+.endif
+.if defined(USE_SASL2) && !empty(USE_SASL2:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	sasl
+.endif
+.if defined(USE_SJ3) && !empty(USE_SJ3:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	sj3
+.endif
+.if defined(USE_SOCKS)
+.  if ${USE_SOCKS} == "4"
+PKG_DEFAULT_OPTIONS+=	socks4
+.  elif ${USE_SOCKS} == "5"
+PKG_DEFAULT_OPTIONS+=	socks5
+.  endif
+.endif
+.if defined(USE_WNN4) && !empty(USE_WNN4:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	wnn4
+.endif
+.if defined(USE_XFACE) && !empty(USE_XFACE:M[yY][eE][sS])
+PKG_DEFAULT_OPTIONS+=	xface
+.endif
Index: bsd.prefs.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.prefs.mk,v
retrieving revision 1.162
diff -u -r1.162 bsd.prefs.mk
--- bsd.prefs.mk	6 Jul 2004 22:49:16 -0000	1.162
+++ bsd.prefs.mk	24 Jul 2004 21:41:00 -0000
@@ -453,7 +453,6 @@
 
 _PKGSRCDIR?=		${.CURDIR:C|/[^/]*/[^/]*$||}
 PKGPATH?=		${.CURDIR:C|.*/([^/]*/[^/]*)$|\1|}
-
 DISTDIR?=		${_PKGSRCDIR}/distfiles
 PACKAGES?=		${_PKGSRCDIR}/packages
 TEMPLATES?=		${_PKGSRCDIR}/templates
@@ -463,6 +462,11 @@
 FILESDIR?=		${.CURDIR}/files
 PKGDIR?=		${.CURDIR}
 
+PKGNAME?=		${DISTNAME}
+PKGBASE?=		${PKGNAME:C/-[^-]*$//} 
+PKGVERSION?=		${PKGNAME:C/^.*-//}
+PKGWILDCARD?=		${PKGBASE}-[0-9]*
+
 _PKGSRC_DEPS?=		# empty
 
 # If WRKOBJDIR is set, use that tree to build
@@ -496,4 +500,7 @@
 #
 WRKLOG?=		${WRKDIR}/.work.log
 
+PKG_DEFAULT_OPTIONS?=	# empty
+PKG_OPTIONS?=		# empty
+
 .endif	# BSD_PKG_MK

--HcAYCG3uE/tztfnV--