Table of Contents
Many packages have the ability to be built to support
different sets of features. bsd.options.mk
is a framework in pkgsrc that
provides generic handling of those options that determine
different ways in which the packages can be built. It's
possible for the user to specify exactly which sets of options
will be built into a package or to allow a set of global
default options apply.
Global default options are listed in PKG_DEFAULT_OPTIONS
, which is a list of the
options that should be built into every package if that
option is supported. This variable should be set in
/etc/mk.conf
.
The following example shows how bsd.options.mk
should be use in a package
Makefile
, or in a file, e.g.
options.mk
, that is included by
the main package Makefile
.
# Global and legacy options .if defined(WIBBLE_USE_OPENLDAP) && !empty(WIBBLE_USE_OPENLDAP:M[yY][eE][sS]) PKG_DEFAULT_OPTIONS+= ldap .endif .if defined(USE_SASL2) && !empty(USE_SASL2:M[yY][eE][sS]) PKG_DEFAULT_OPTIONS+= sasl .endif PKG_OPTIONS_VAR= PKG_OPTIONS.wibble PKG_SUPPORTED_OPTIONS= ldap sasl # # Default options for "wibble" package. # .if !defined(PKG_OPTIONS.wibble) PKG_DEFAULT_OPTIONS+= sasl endif .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
The first section only exists if you are converting a
package that had its own ad-hoc options handling to use
bsd.options.mk
. It converts
global or legacy options variables into an equivalent
PKG_OPTIONS.
value. These
sections will be removed over time as the old options are in
turn deprecated and removed.pkg
The second section contains the information about which build options are supported by the package, and any default options settings if needed.
PKG_OPTIONS_VAR
is a
list of the name of the
make(1) variables
that contain the options the user wishes to select. The
recommended value is “PKG_OPTIONS.pkg
” but
any package-specific value may be used. This variable
should be set in a package Makefile.
PKG_SUPPORTED_OPTIONS
is a list of build options supported by the package.
This variable should be set in a package Makefile.
${PKG_OPTIONS_VAR}
(the
variables named in PKG_OPTIONS_VAR
) are variables that
list the selected build options and override 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_VAR= WIBBLE_OPTIONS WIBBLE_OPTIONS= ${PKG_DEFAULT_OPTIONS} -sasl # implies PKG_OPTIONS == "kerberos ldap"
or
PKG_OPTIONS_VAR= WIBBLE_OPTIONS WIBBLE_OPTIONS= kerberos -ldap ldap # implies PKG_OPTIONS == "kerberos"
This variable should be set in /etc/mk.conf
.
After the inclusion of bsd.options.mk, the following variables are set:
PKG_OPTIONS
contains
the list of the selected build options, properly
filtered to remove unsupported and duplicate
options.
The remaining sections contain the logic that is specific
to each option. There should be a check for every option
listed in PKG_SUPPORTED_OPTIONS
,
and there should be clear documentation on what turning on
the option will do in the comments preceding each section.
The correct way to check for an option is to check whether it
is listed in PKG_OPTIONS
.