Subject: Re: *_OPTIONS for package options
To: grant beattie <grant@NetBSD.org>
From: Johnny C. Lam <jlam@NetBSD.org>
List: tech-pkg
Date: 07/24/2004 07:50:10
--X1bOJ3K7DJ5YkBrT
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sat, Jul 24, 2004 at 03:43:37PM +1000, grant beattie wrote:
> On Sat, Jul 24, 2004 at 07:27:31AM +0200, Juan RP wrote:
> 
> > have to use something like:
> > 
> > 	PKG_OPTIONS+=	databases/openldap security/cyrus-sasl2
> 
> 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 :)

I've attached a file that contains implements this idea.  By following
the example givin in the file, I was able to successfully convert
several package in my local pkgsrc tree (postfix, mutt-devel, openldap,
cyrus-sasl, and cyrus-saslauthd) to use this.

	Cheers,

	-- Johnny Lam <jlam@NetBSD.org>

--X1bOJ3K7DJ5YkBrT
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.
#
# 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.  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.  This
#				is a read-only variable.
#
# 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 optional modules that
#	*may* be built.
#
# PKG_OPTIONS.${PKGBASE} is a list of the modules that *will* be built.
#
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
BUILD_DEFS+=		PKG_OPTIONS.${PKGBASE}

PKG_OPTIONS=		# empty
.for _opt_ in ${PKG_OPTIONS.${PKGBASE}}
.  if empty(PKG_OPTIONS:M${_opt_})
.    if !empty(PKG_SUPPORTED_OPTIONS:M${_opt_})
PKG_OPTIONS+=		${_opt_}
.    else
PKG_FAIL_REASON+=	"\"${_opt_}\" is not a supported build option."
.    endif
.  endif
.endfor

--X1bOJ3K7DJ5YkBrT--