1 # $NetBSD: bsd.options.mk,v 1.8 2004/08/22 19:42:10 jlam Exp $
3 # This Makefile fragment provides boilerplate code for standard naming
4 # conventions for handling per-package build options.
6 # Before including this file, the following variables should be defined:
9 # This is a list of the name of the make(1) variables that
10 # contain the options the user wishes to select. This
11 # variable should be set in a package Makefile. E.g.,
13 # PKG_OPTIONS_VAR= WIBBLE_OPTIONS
15 # PKG_OPTIONS_VAR= FOO_OPTIONS BAR_OPTIONS
17 # PKG_SUPPORTED_OPTIONS
18 # This is a list of build options supported by the package.
19 # This variable should be set in a package Makefile. E.g.,
21 # PKG_SUPPORTED_OPTIONS= kerberos ldap ssl
23 # Optionally, the following variables may also be defined:
26 # This is a list the options that should be built into
27 # every package, if that option is supported. This
28 # variable should be set in /etc/mk.conf.
30 # ${PKG_OPTIONS_VAR} (the variables named in PKG_OPTIONS_VAR)
31 # These variables list the selected build options and
32 # override any default options given in PKG_DEFAULT_OPTIONS.
33 # If any of the options begin with a '-', then that option
34 # is always removed from the selected build options, e.g.
36 # PKG_DEFAULT_OPTIONS= kerberos ldap sasl
37 # PKG_OPTIONS_VAR= WIBBLE_OPTIONS
38 # WIBBLE_OPTIONS= ${PKG_DEFAULT_OPTIONS} -sasl
39 # # implies PKG_OPTIONS == "kerberos ldap"
41 # PKG_OPTIONS_VAR= WIBBLE_OPTIONS
42 # WIBBLE_OPTIONS= kerberos -ldap ldap
43 # # implies PKG_OPTIONS == "kerberos"
45 # This variable should be set in /etc/mk.conf.
47 # PKG_FAIL_UNSUPPORTED_OPTIONS
48 # If this is set to "yes", then the presence of unsupported
49 # options in PKG_OPTIONS.<pkg> (see below) causes the build
50 # to fail. Set this to "no" to silently ignore unsupported
51 # options. Default: "no".
53 # After including this file, the following variables are defined:
56 # This is the list of the selected build options, properly
57 # filtered to remove unsupported and duplicate options.
61 # -------------8<-------------8<-------------8<-------------8<-------------
62 # # Global and legacy options
63 # .if defined(WIBBLE_USE_OPENLDAP) && !empty(WIBBLE_USE_OPENLDAP:M[yY][eE][sS])
64 # PKG_DEFAULT_OPTIONS+= ldap
66 # .if defined(WIBBLE_USE_SASL2) && !empty(WIBBLE_USE_SASL2:M[yY][eE][sS])
67 # PKG_DEFAULT_OPTIONS+= sasl
70 # PKG_OPTIONS_VAR= PKG_OPTIONS.wibble
71 # PKG_SUPPORTED_OPTIONS= ldap sasl
73 # # Default options for ``wibble'' package.
75 # .if !defined(PKG_OPTIONS.wibble)
76 # PKG_DEFAULT_OPTIONS+= sasl
78 # .include "../../mk/bsd.options.mk"
80 # # Package-specific option-handling
85 # .if !empty(PKG_OPTIONS:Mldap)
86 # . include "../../databases/openldap/buildlink3.mk"
87 # CONFIGURE_ARGS+= --enable-ldap=${BUILDLINK_PREFIX.openldap}
91 # ### SASL authentication
93 # .if !empty(PKG_OPTIONS:Msasl)
94 # . include "../../security/cyrus-sasl2/buildlink3.mk"
95 # CONFIGURE_ARGS+= --enable-sasl=${BUILDLINK_PREFIX.sasl}
97 # -------------8<-------------8<-------------8<-------------8<-------------
99 .include "../../mk/bsd.prefs.mk"
101 # Check for variable definitions required before including this file.
102 .if !defined(PKG_SUPPORTED_OPTIONS)
103 PKG_FAIL_REASON+= "bsd.options.mk: PKG_SUPPORTED_OPTIONS is not defined."
105 .if !defined(PKG_OPTIONS_VAR)
106 PKG_FAIL_REASON+= "bsd.options.mk: PKG_OPTIONS_VAR is not defined."
109 # If none of the variables listed in PKG_OPTIONS_VAR is defined, then use
110 # the global options provided in ${PKG_DEFAULT_OPTIONS}.
112 _PKG_DEFAULT_OPTIONS= # empty
113 .for _opt_ in ${PKG_DEFAULT_OPTIONS}
114 . if !empty(PKG_SUPPORTED_OPTIONS:M${_opt_})
115 _PKG_DEFAULT_OPTIONS+= ${_opt_}
119 _PKG_OPTIONS_VAR= # empty
120 .for _var_ in ${PKG_OPTIONS_VAR}
121 . if defined(${_var_})
122 _PKG_OPTIONS_VAR+= ${_var_}
126 .if empty(_PKG_OPTIONS_VAR)
127 _PKG_OPTIONS_VAR= _PKG_DEFAULT_OPTIONS
130 # If this is set to "yes", then the presence of unsupported options in
131 # the variable named by ${PKG_OPTIONS_VAR} causes the build to fail. Set
132 # this to "no" to silently ignore unsupported options.
134 PKG_FAIL_UNSUPPORTED_OPTIONS?= no
136 # Separate out the selected options into "positive" and "negative" lists.
137 _PKG_YES_OPTIONS= # contains the "positive" options
138 .for _var_ in ${_PKG_OPTIONS_VAR}
139 _PKG_YES_OPTIONS+= ${${_var_}:N-*}
141 _PKG_NO_OPTIONS= # contains the "negative" options
142 .for _var_ in ${_PKG_OPTIONS_VAR}
143 _PKG_NO_OPTIONS+= ${${_var_}:M-*:S/^-//}
147 # Filter out unsupported and duplicate build options and store the result
148 # in PKG_OPTIONS. We keep all of the "positive" options first, then remove
149 # all of the "negative" options last, so "negative" options always have
150 # the strongest effect.
153 .for _opt_ in ${_PKG_YES_OPTIONS}
154 . if empty(_PKG_NO_OPTIONS:M${_opt_}) && empty(PKG_OPTIONS:M${_opt_})
155 . if !empty(PKG_SUPPORTED_OPTIONS:M${_opt_})
156 PKG_OPTIONS+= ${_opt_}
157 . elif !empty(PKG_FAIL_UNSUPPORTED_OPTIONS:M[yY][eE][sS])
158 PKG_FAIL_REASON+= "\"${_opt_}\" is not a supported build option."
163 .PHONY: pre-install-depends supported-options-message
164 pre-install-depends: supported-options-message
165 .if !defined(PKG_SUPPORTED_OPTIONS)
166 supported-options-message: # do nothing
168 supported-options-message: ${WRKDIR}/.som_done
169 ${WRKDIR}/.som_done: ${WRKDIR}
170 . if !empty(PKG_SUPPORTED_OPTIONS)
171 @${ECHO} "=========================================================================="
172 @${ECHO} "The supported build options for this package are:"
174 @${ECHO} "${PKG_SUPPORTED_OPTIONS}" | ${XARGS} -n 1 | ${SORT} | \
176 BEGIN { printwidth = 40; line = "" } \
178 if (length(line) > 0) \
182 if (length(line) > 40) { \
187 END { if (length(line) > 0) print " "line } \
190 @${ECHO} "You can select which build options to use by setting the following"
191 @${ECHO} "variables. Their current value is shown:"
193 . for _var_ in ${PKG_OPTIONS_VAR}
194 . if !defined(${_var_})
195 @${ECHO} " ${_var_} (not defined)"
197 @${ECHO} " ${_var_} = ${${_var_}}"
202 @${ECHO} "=========================================================================="