1 # $NetBSD: bsd.options.mk,v 1.66 2008/02/18 12:38:35 obache 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 can be defined:
8 # PKG_SUPPORTED_OPTIONS
9 # This is a list of build options supported by the package.
10 # This variable should be set in a package Makefile. E.g.,
12 # PKG_SUPPORTED_OPTIONS= kerberos ldap ssl
14 # PKG_OPTIONS_VAR (must be defined)
15 # The variable the user can set to enable or disable
16 # options specifically for this package.
18 # PKG_OPTIONS_OPTIONAL_GROUPS
19 # This is a list of names of groups of mutually exclusive
20 # options. The options in each group are listed in
21 # PKG_OPTIONS_GROUP.<groupname>. The most specific
22 # setting of any option from the group takes precedence
23 # over all other options in the group. Options from
24 # the groups will be automatically added to
25 # PKG_SUPPORTED_OPTIONS.
27 # PKG_OPTIONS_REQUIRED_GROUPS
28 # Like PKG_OPTIONS_OPTIONAL_GROUPS, but building
29 # the packages will fail if no option from the group
32 # PKG_OPTIONS_NONEMPTY_SETS
33 # This is a list of names of sets of options. At
34 # least one option from each set must be selected.
35 # The options in each set are listed in
36 # PKG_OPTIONS_SET.<setname>. Options from the sets
37 # will be automatically added to PKG_SUPPORTED_OPTIONS.
39 # PKG_SUGGESTED_OPTIONS (defaults to empty)
40 # This is a list of build options which are enabled by default.
42 # PKG_OPTIONS_LEGACY_VARS
43 # This is a list of USE_VARIABLE:option pairs that
44 # map legacy /etc/mk.conf variables to their option
47 # PKG_OPTIONS_LEGACY_OPTS
48 # This is a list of old-option:new-option pairs that
49 # map options that have been renamed to their new
53 # A list of options implied by deprecated variables
54 # used. This can be used for cases that neither
55 # PKG_OPTIONS_LEGACY_VARS nor PKG_OPTIONS_LEGACY_OPTS
56 # can handle, e. g. when PKG_OPTIONS_VAR is renamed.
58 # PKG_OPTIONS_DEPRECATED_WARNINGS
59 # A list of warnings about deprecated variables or
60 # options used, and what to use instead.
62 # If none of PKG_SUPPORTED_OPTIONS, PKG_OPTIONS_OPTIONAL_GROUPS,
63 # PKG_OPTIONS_REQUIRED_GROUPS, and PKG_OPTIONS_NONEMPTY_SETS are
64 # defined, PKG_OPTIONS is set to the empty list and the package
65 # is otherwise treated as not using the options framework.
68 # Optionally, the user may define the following variables in /etc/mk.conf:
71 # This variable can be used to override default
72 # options for every package. Options listed in this
73 # variable will be enabled in every package that
74 # supports them. If you prefix an option with `-',
75 # it will be disabled in every package.
78 # This variable can be used to override default
79 # options and options listed in PKG_DEFAULT_OPTIONS.
80 # The syntax is the same as PKG_DEFAULT_OPTIONS.
82 # After including this file, the following variables are defined:
85 # This is the list of the selected build options, properly
86 # filtered to remove unsupported and duplicate options.
89 .if !defined(BSD_OPTIONS_MK)
90 BSD_OPTIONS_MK= # defined
92 # To add options support to a package, here is an example for an
93 # options.mk file. This file should be included by the package Makefile
96 # -------------8<-------------8<-------------8<-------------8<-------------
97 # PKG_OPTIONS_VAR= PKG_OPTIONS.wibble
98 # PKG_SUPPORTED_OPTIONS= wibble-foo ldap sasl
99 # PKG_OPTIONS_OPTIONAL_GROUPS= database
100 # PKG_OPTIONS_GROUP.database= mysql pgsql
101 # PKG_SUGGESTED_OPTIONS= wibble-foo
102 # PKG_OPTIONS_LEGACY_VARS+= WIBBLE_USE_OPENLDAP:ldap
103 # PKG_OPTIONS_LEGACY_VARS+= WIBBLE_USE_SASL2:sasl
104 # PKG_OPTIONS_LEGACY_OPTS+= foo:wibble-foo
106 # .include "../../mk/bsd.prefs.mk"
108 # # this package was previously named wibble2
109 # .if defined(PKG_OPTIONS.wibble2)
110 # PKG_LEGACY_OPTIONS+= ${PKG_OPTIONS.wibble2}
111 # PKG_OPTIONS_DEPRECATED_WARNINGS+="Deprecated variable PKG_OPTIONS.wibble2 used, use "${PKG_OPTIONS_VAR:Q}" instead."
114 # .include "../../mk/bsd.options.mk"
116 # # Package-specific option-handling
121 # .if !empty(PKG_OPTIONS:Mwibble-foo)
122 # CONFIGURE_ARGS+= --enable-foo
128 # .if !empty(PKG_OPTIONS:Mldap)
129 # . include "../../databases/openldap-client/buildlink3.mk"
130 # CONFIGURE_ARGS+= --enable-ldap=${BUILDLINK_PREFIX.openldap-client}
134 # ### SASL authentication
136 # .if !empty(PKG_OPTIONS:Msasl)
137 # . include "../../security/cyrus-sasl/buildlink3.mk"
138 # CONFIGURE_ARGS+= --enable-sasl=${BUILDLINK_PREFIX.sasl}
142 # ### database support
144 # .if !empty(PKG_OPTIONS:Mmysql)
145 # . include "../../mk/mysql.buildlink3.mk"
147 # .if !empty(PKG_OPTIONS:Mpgsql)
148 # . include "../../mk/pgsql.buildlink3.mk"
150 # -------------8<-------------8<-------------8<-------------8<-------------
152 # Keywords: options.mk
155 _USER_VARS.options= PKG_DEFAULT_OPTIONS ${PKG_OPTIONS_VAR}
156 _PKG_VARS.options= PKG_SUPPORTED_OPTIONS PKG_OPTIONS_VAR \
157 PKG_OPTIONS_OPTIONAL_GROUPS PKG_OPTIONS_REQUIRED_GROUPS \
158 PKG_OPTIONS_NONEMPTY_SETS PKG_SUGGESTED_OPTIONS \
159 PKG_OPTIONS_LEGACY_VARS PKG_OPTIONS_LEGACY_OPTS \
160 PKG_LEGACY_OPTIONS PKG_OPTIONS_DEPRECATED_WARNINGS
161 _SYS_VARS.options= PKG_OPTIONS
163 .include "bsd.prefs.mk"
165 # Define PKG_OPTIONS, no matter if we have an error or not, to suppress
166 # further make(1) warnings.
169 # Check for variable definitions required before including this file.
170 .if !defined(PKG_OPTIONS_VAR)
171 PKG_FAIL_REASON+= "[bsd.options.mk] PKG_OPTIONS_VAR is not defined."
173 .if !defined(PKG_SUPPORTED_OPTIONS) \
174 && !defined(PKG_OPTIONS_OPTIONAL_GROUPS) \
175 && !defined(PKG_OPTIONS_REQUIRED_GROUPS) \
176 && !defined(PKG_OPTIONS_NONEMPTY_SETS)
177 PKG_SUPPORTED_OPTIONS?= # none
178 PKG_FAIL_REASON+= "[bsd.options.mk] The package has no options, but includes this file."
182 # create map of option to group and add group options to PKG_SUPPORTED_OPTIONS
184 .for _grp_ in ${PKG_OPTIONS_OPTIONAL_GROUPS} ${PKG_OPTIONS_REQUIRED_GROUPS}
185 _PKG_OPTIONS_GROUP_STACK.${_grp_}:=#empty
186 . if !defined(PKG_OPTIONS_GROUP.${_grp_}) || empty(PKG_OPTIONS_GROUP.${_grp_})
187 PKG_FAIL_REASON+= "[bsd.options.mk] PKG_OPTIONS_GROUP."${_grp_:Q}" must be non-empty."
189 . for _opt_ in ${PKG_OPTIONS_GROUP.${_grp_}}
190 PKG_SUPPORTED_OPTIONS+= ${_opt_}
191 _PKG_OPTIONS_GROUP_MAP.${_opt_}=${_grp_}
196 # add options from sets to PKG_SUPPORTED_OPTIONS
198 _PKG_OPTIONS_ALL_SETS:=#empty
199 .for _set_ in ${PKG_OPTIONS_NONEMPTY_SETS}
200 . if !defined(PKG_OPTIONS_SET.${_set_}) || empty(PKG_OPTIONS_SET.${_set_})
201 PKG_FAIL_REASON+= "[bsd.options.mk] PKG_OPTIONS_SET."${_set_:Q}" must be non-empty."
203 . for _opt_ in ${PKG_OPTIONS_SET.${_set_}}
204 PKG_SUPPORTED_OPTIONS+= ${_opt_}
205 _PKG_OPTIONS_ALL_SETS+= ${_opt_}
210 # include deprecated variable to options mapping
212 .include "defaults/obsolete.mk"
215 # place options implied by legacy variables in PKG_LEGACY_OPTIONS
217 .for _m_ in ${PKG_OPTIONS_LEGACY_VARS}
218 _var_:= ${_m_:C/:.*//}
219 _opt_:= ${_m_:C/.*://}
220 _popt_:=${_opt_:C/^-//}
221 . if !empty(PKG_SUPPORTED_OPTIONS:M${_popt_})
222 . if defined(${_var_})
223 . if empty(${_var_}:M[nN][oO])
224 PKG_LEGACY_OPTIONS:=${PKG_LEGACY_OPTIONS} ${_opt_}
225 PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated variable "${_var_:Q}" set to "${${_var_}:Q}", use PKG_DEFAULT_OPTIONS+="${_opt_:Q}" instead."
226 . elif empty(_opt_:M-*)
227 PKG_LEGACY_OPTIONS:=${PKG_LEGACY_OPTIONS} -${_popt_}
228 PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated variable "${_var_:Q}" set to "${${_var_}:Q}", use PKG_DEFAULT_OPTIONS+=-"${_popt_:Q}" instead."
230 PKG_LEGACY_OPTIONS:=${PKG_LEGACY_OPTIONS} ${_popt_}
231 PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated variable "${_var_:Q}" set to "${${_var_}:Q}", use PKG_DEFAULT_OPTIONS+="${_popt_:Q}" instead."
241 # create map of old option name to new option name for legacy options
243 .for _m_ in ${PKG_OPTIONS_LEGACY_OPTS}
244 _old_:= ${_m_:C/:.*//}
245 _new_:= ${_m_:C/.*://}
246 . if !empty(PKG_SUPPORTED_OPTIONS:M${_new_})
247 _PKG_LEGACY_OPTMAP.${_old_}:=${_new_}
254 # filter unsupported options from PKG_DEFAULT_OPTIONS
256 _OPTIONS_DEFAULT_SUPPORTED:= #empty
257 .for _o_ in ${PKG_DEFAULT_OPTIONS}
259 _popt_:= ${_opt_:C/^-//}
260 . if !empty(PKG_SUPPORTED_OPTIONS:M${_popt_}) \
261 || defined(_PKG_LEGACY_OPTMAP.${_popt_})
262 _OPTIONS_DEFAULT_SUPPORTED:=${_OPTIONS_DEFAULT_SUPPORTED} ${_opt_}
269 # process options from generic to specific
272 PKG_OPTIONS:= # empty
273 _OPTIONS_UNSUPPORTED:= #empty
274 .for _o_ in ${PKG_SUGGESTED_OPTIONS} ${PKG_LEGACY_OPTIONS} \
275 ${_OPTIONS_DEFAULT_SUPPORTED} ${${PKG_OPTIONS_VAR}}
277 _popt_:= ${_o_:C/^-//} # positive option
278 . if defined(_PKG_LEGACY_OPTMAP.${_popt_})
279 PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Deprecated option "${_popt_:Q}" used, use option "${_PKG_LEGACY_OPTMAP.${_popt_}:Q}" instead."
280 _popt_:= ${_PKG_LEGACY_OPTMAP.${_popt_}}
281 . if empty(_opt_:M-*)
287 . if empty(PKG_SUPPORTED_OPTIONS:M${_popt_})
288 _OPTIONS_UNSUPPORTED:=${_OPTIONS_UNSUPPORTED} ${_opt_}
290 . if defined(_PKG_OPTIONS_GROUP_MAP.${_popt_})
291 _grp_:= ${_PKG_OPTIONS_GROUP_MAP.${_popt_}}
292 _stk_:= _PKG_OPTIONS_GROUP_STACK.${_grp_}
294 . if !empty(_opt_:M-*)
295 ${_stk_}:= ${_cnt_:N${_popt_}}
297 ${_stk_}:= ${_cnt_} ${_popt_}
300 . if !empty(_opt_:M-*)
301 PKG_OPTIONS:= ${PKG_OPTIONS:N${_popt_}}
303 PKG_OPTIONS:= ${PKG_OPTIONS} ${_popt_}
312 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS}
313 . if empty(_PKG_OPTIONS_GROUP_STACK.${_grp_})
314 PKG_FAIL_REASON+= "[bsd.options.mk] One of the following options must be selected: "${PKG_OPTIONS_GROUP.${_grp_}:O:u:Q}
318 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS} ${PKG_OPTIONS_OPTIONAL_GROUPS}
320 . for _o_ in ${_PKG_OPTIONS_GROUP_STACK.${_grp_}}
324 PKG_OPTIONS:= ${PKG_OPTIONS} ${_opt_}
329 .for _set_ in ${PKG_OPTIONS_NONEMPTY_SETS}
331 . for _opt_ in ${PKG_OPTIONS_SET.${_set_}}
332 . if !empty(PKG_OPTIONS:M${_opt_})
336 . if ${_ISEMPTY} == "true"
337 PKG_FAIL_REASON+= "[bsd.options.mk] At least one of the following options must be selected: "${PKG_OPTIONS_SET.${_set_}:O:u:Q}
342 .if !empty(_OPTIONS_UNSUPPORTED)
343 PKG_FAIL_REASON+= "[bsd.options.mk] The following selected options are not supported: "${_OPTIONS_UNSUPPORTED:O:u:Q}"."
346 .undef _OPTIONS_DEFAULT_SUPPORTED
347 PKG_OPTIONS:= ${PKG_OPTIONS:O:u}
349 _PKG_OPTIONS_WORDWRAP_FILTER= \
352 BEGIN { printwidth = 40; line = "" } \
354 if (length(line) > 0) \
358 if (length(line) > 40) { \
363 END { if (length(line) > 0) print " "line } \
368 @${ECHO} Any of the following general options may be selected:
369 .for _opt_ in ${PKG_SUPPORTED_OPTIONS:O}
370 . if !defined(_PKG_OPTIONS_GROUP_MAP.${_opt_}) && empty(_PKG_OPTIONS_ALL_SETS:M${_opt_})
371 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
374 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS}
375 @${ECHO} "Exactly one of the following "${_grp_:Q}" options is required:"
376 . for _opt_ in ${PKG_OPTIONS_GROUP.${_grp_}:O}
377 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
380 .for _grp_ in ${PKG_OPTIONS_OPTIONAL_GROUPS}
381 @${ECHO} "At most one of the following "${_grp_:Q}" options may be selected:"
382 . for _opt_ in ${PKG_OPTIONS_GROUP.${_grp_}:O}
383 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
386 .for _set_ in ${PKG_OPTIONS_NONEMPTY_SETS}
387 @${ECHO} "At least one of the following "${_set_:Q}" options must be selected:"
388 . for _opt_ in ${PKG_OPTIONS_SET.${_set_}:O}
389 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
393 @${ECHO} "These options are enabled by default:"
394 @${ECHO} ${PKG_SUGGESTED_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
396 @${ECHO} "These options are currently enabled:"
397 @${ECHO} ${PKG_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
399 @${ECHO} "You can select which build options to use by setting PKG_DEFAULT_OPTIONS"
400 @${ECHO} "or "${PKG_OPTIONS_VAR:Q}"."
401 @set args ${PKG_OPTIONS_DEPRECATED_WARNINGS}; shift; \
402 [ $$# -eq 0 ] || ${ECHO}; \
407 .if defined(PKG_SUPPORTED_OPTIONS)
408 .PHONY: supported-options-message
409 pre-depends-hook: supported-options-message
410 supported-options-message:
411 . if !empty(PKG_SUPPORTED_OPTIONS)
412 @${ECHO} "=========================================================================="
413 @${ECHO} "The supported build options for ${PKGBASE} are:"
415 @${ECHO} ${PKG_SUPPORTED_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
416 . if !empty(PKG_OPTIONS)
418 @${ECHO} "The currently selected options are:"
420 @${ECHO} ${PKG_OPTIONS:O:Q} | ${XARGS} -n 1 | ${_PKG_OPTIONS_WORDWRAP_FILTER}
423 @${ECHO} "You can select which build options to use by setting PKG_DEFAULT_OPTIONS"
424 @${ECHO} "or the following variable. Its current value is shown:"
426 . if !defined(${PKG_OPTIONS_VAR})
427 @${ECHO} " ${PKG_OPTIONS_VAR} (not defined)"
429 @${ECHO} " ${PKG_OPTIONS_VAR} = "${${PKG_OPTIONS_VAR}:Q}
431 @set args ${PKG_OPTIONS_DEPRECATED_WARNINGS}; shift; \
432 [ $$# -eq 0 ] || ${ECHO}; \
437 @${ECHO} "=========================================================================="
441 .endif # BSD_OPTIONS_MK