Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / mk / bsd.options.mk
blob0b18d355da3a8e6a6319e1a5c6c30bcdd288afa2
1 # $NetBSD: bsd.options.mk,v 1.68 2013/05/11 18:48:52 riastradh 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
30 # is selected.
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
45 # counterparts.
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
50 # counterparts.
52 # PKG_LEGACY_OPTIONS
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:
70 # PKG_DEFAULT_OPTIONS
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.
77 # ${PKG_OPTIONS_VAR}
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:
84 # PKG_OPTIONS
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
94 # or Makefile.common.
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."
112 # .endif
114 # .include "../../mk/bsd.options.mk"
116 # # Package-specific option-handling
118 # ###
119 # ### FOO support
120 # ###
121 # .if !empty(PKG_OPTIONS:Mwibble-foo)
122 # CONFIGURE_ARGS+= --enable-foo
123 # .endif
125 # ###
126 # ### LDAP support
127 # ###
128 # .if !empty(PKG_OPTIONS:Mldap)
129 # . include "../../databases/openldap-client/buildlink3.mk"
130 # CONFIGURE_ARGS+= --enable-ldap=${BUILDLINK_PREFIX.openldap-client}
131 # .endif
133 # ###
134 # ### SASL authentication
135 # ###
136 # .if !empty(PKG_OPTIONS:Msasl)
137 # . include "../../security/cyrus-sasl/buildlink3.mk"
138 # CONFIGURE_ARGS+= --enable-sasl=${BUILDLINK_PREFIX.sasl}
139 # .endif
141 # ###
142 # ### database support
143 # ###
144 # .if !empty(PKG_OPTIONS:Mmysql)
145 # . include "../../mk/mysql.buildlink3.mk"
146 # .endif
147 # .if !empty(PKG_OPTIONS:Mpgsql)
148 # . include "../../mk/pgsql.buildlink3.mk"
149 # .endif
150 # -------------8<-------------8<-------------8<-------------8<-------------
152 # Keywords: options.mk
154 _VARGROUPS+= options
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.
167 PKG_OPTIONS= # empty
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."
172 .endif
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."
179 .endif
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."
188 . endif
189 . for _opt_ in ${PKG_OPTIONS_GROUP.${_grp_}}
190 PKG_SUPPORTED_OPTIONS+= ${_opt_}
191 _PKG_OPTIONS_GROUP_MAP.${_opt_}=${_grp_}
192 . endfor
193 .endfor
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."
202 . endif
203 . for _opt_ in ${PKG_OPTIONS_SET.${_set_}}
204 PKG_SUPPORTED_OPTIONS+= ${_opt_}
205 _PKG_OPTIONS_ALL_SETS+= ${_opt_}
206 . endfor
207 .endfor
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."
229 . else
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."
232 . endif
233 . endif
234 . endif
235 .endfor
236 .undef _var_
237 .undef _opt_
238 .undef _popt_
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_}
248 . endif
249 .endfor
250 .undef _old_
251 .undef _new_
254 # filter unsupported options from PKG_DEFAULT_OPTIONS
256 _OPTIONS_DEFAULT_SUPPORTED:= #empty
257 .for _o_ in ${PKG_DEFAULT_OPTIONS}
258 _opt_:= ${_o_}
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_}
263 . endif
264 .endfor
265 .undef _opt_
266 .undef _popt_
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}}
276 _opt_:= ${_o_}
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-*)
282 _opt_:= ${_popt_}
283 . else
284 _opt_:= -${_popt_}
285 . endif
286 . endif
287 . if empty(PKG_SUPPORTED_OPTIONS:M${_popt_})
288 . if empty(_opt_:M-*)
289 _OPTIONS_UNSUPPORTED:=${_OPTIONS_UNSUPPORTED} ${_opt_}
290 . else
291 PKG_OPTIONS_DEPRECATED_WARNINGS:=${PKG_OPTIONS_DEPRECATED_WARNINGS} "Option "${_opt_:Q}" is unsupported, so disabling it has no effect."
292 . endif
293 . else
294 . if defined(_PKG_OPTIONS_GROUP_MAP.${_popt_})
295 _grp_:= ${_PKG_OPTIONS_GROUP_MAP.${_popt_}}
296 _stk_:= _PKG_OPTIONS_GROUP_STACK.${_grp_}
297 _cnt_:= ${${_stk_}}
298 . if !empty(_opt_:M-*)
299 ${_stk_}:= ${_cnt_:N${_popt_}}
300 . else
301 ${_stk_}:= ${_cnt_} ${_popt_}
302 . endif
303 . else
304 . if !empty(_opt_:M-*)
305 PKG_OPTIONS:= ${PKG_OPTIONS:N${_popt_}}
306 . else
307 PKG_OPTIONS:= ${PKG_OPTIONS} ${_popt_}
308 . endif
309 . endif
310 . endif
311 .endfor
312 .undef _opt_
313 .undef _popt_
314 .undef _stk_
316 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS}
317 . if empty(_PKG_OPTIONS_GROUP_STACK.${_grp_})
318 PKG_FAIL_REASON+= "[bsd.options.mk] One of the following options must be selected: "${PKG_OPTIONS_GROUP.${_grp_}:O:u:Q}
319 . endif
320 .endfor
322 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS} ${PKG_OPTIONS_OPTIONAL_GROUPS}
323 . undef _opt_
324 . for _o_ in ${_PKG_OPTIONS_GROUP_STACK.${_grp_}}
325 _opt_:= ${_o_}
326 . endfor
327 . if defined(_opt_)
328 PKG_OPTIONS:= ${PKG_OPTIONS} ${_opt_}
329 . endif
330 .endfor
331 .undef _opt_
333 .for _set_ in ${PKG_OPTIONS_NONEMPTY_SETS}
334 _ISEMPTY:=true
335 . for _opt_ in ${PKG_OPTIONS_SET.${_set_}}
336 . if !empty(PKG_OPTIONS:M${_opt_})
337 _ISEMPTY:=false
338 . endif
339 . endfor
340 . if ${_ISEMPTY} == "true"
341 PKG_FAIL_REASON+= "[bsd.options.mk] At least one of the following options must be selected: "${PKG_OPTIONS_SET.${_set_}:O:u:Q}
342 . endif
343 .endfor
344 .undef _ISEMPTY
346 .if !empty(_OPTIONS_UNSUPPORTED)
347 PKG_FAIL_REASON+= "[bsd.options.mk] The following selected options are not supported: "${_OPTIONS_UNSUPPORTED:O:u:Q}"."
348 .endif
350 .undef _OPTIONS_DEFAULT_SUPPORTED
351 PKG_OPTIONS:= ${PKG_OPTIONS:O:u}
353 _PKG_OPTIONS_WORDWRAP_FILTER= \
354 ${XARGS} -n 1 | \
355 ${AWK} ' \
356 BEGIN { printwidth = 40; line = "" } \
358 if (length(line) > 0) \
359 line = line" "$$0; \
360 else \
361 line = $$0; \
362 if (length(line) > 40) { \
363 print " "line; \
364 line = ""; \
367 END { if (length(line) > 0) print " "line } \
370 .PHONY: show-options
371 show-options:
372 @${ECHO} Any of the following general options may be selected:
373 .for _opt_ in ${PKG_SUPPORTED_OPTIONS:O}
374 . if !defined(_PKG_OPTIONS_GROUP_MAP.${_opt_}) && empty(_PKG_OPTIONS_ALL_SETS:M${_opt_})
375 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
376 . endif
377 .endfor
378 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS}
379 @${ECHO} "Exactly one of the following "${_grp_:Q}" options is required:"
380 . for _opt_ in ${PKG_OPTIONS_GROUP.${_grp_}:O}
381 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
382 . endfor
383 .endfor
384 .for _grp_ in ${PKG_OPTIONS_OPTIONAL_GROUPS}
385 @${ECHO} "At most one of the following "${_grp_:Q}" options may be selected:"
386 . for _opt_ in ${PKG_OPTIONS_GROUP.${_grp_}:O}
387 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
388 . endfor
389 .endfor
390 .for _set_ in ${PKG_OPTIONS_NONEMPTY_SETS}
391 @${ECHO} "At least one of the following "${_set_:Q}" options must be selected:"
392 . for _opt_ in ${PKG_OPTIONS_SET.${_set_}:O}
393 @${ECHO} " "${_opt_:Q}" "`${SED} -n "s/^"${_opt_:Q}" //p" ../../mk/defaults/options.description`
394 . endfor
395 .endfor
396 @${ECHO}
397 @${ECHO} "These options are enabled by default:"
398 @${ECHO} ${PKG_SUGGESTED_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
399 @${ECHO} ""
400 @${ECHO} "These options are currently enabled:"
401 @${ECHO} ${PKG_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
402 @${ECHO} ""
403 @${ECHO} "You can select which build options to use by setting PKG_DEFAULT_OPTIONS"
404 @${ECHO} "or "${PKG_OPTIONS_VAR:Q}"."
405 @set args ${PKG_OPTIONS_DEPRECATED_WARNINGS}; shift; \
406 [ $$# -eq 0 ] || ${ECHO}; \
407 for l in "$$@"; do \
408 ${ECHO} "$$l"; \
409 done
411 .if defined(PKG_SUPPORTED_OPTIONS)
412 .PHONY: supported-options-message
413 pre-depends-hook: supported-options-message
414 supported-options-message:
415 . if !empty(PKG_SUPPORTED_OPTIONS)
416 @${ECHO} "=========================================================================="
417 @${ECHO} "The supported build options for ${PKGBASE} are:"
418 @${ECHO} ""
419 @${ECHO} ${PKG_SUPPORTED_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
420 . if !empty(PKG_OPTIONS)
421 @${ECHO} ""
422 @${ECHO} "The currently selected options are:"
423 @${ECHO} ""
424 @${ECHO} ${PKG_OPTIONS:O:Q} | ${XARGS} -n 1 | ${_PKG_OPTIONS_WORDWRAP_FILTER}
425 . endif
426 @${ECHO} ""
427 @${ECHO} "You can select which build options to use by setting PKG_DEFAULT_OPTIONS"
428 @${ECHO} "or the following variable. Its current value is shown:"
429 @${ECHO} ""
430 . if !defined(${PKG_OPTIONS_VAR})
431 @${ECHO} " ${PKG_OPTIONS_VAR} (not defined)"
432 . else
433 @${ECHO} " ${PKG_OPTIONS_VAR} = "${${PKG_OPTIONS_VAR}:Q}
434 . endif
435 @set args ${PKG_OPTIONS_DEPRECATED_WARNINGS}; shift; \
436 [ $$# -eq 0 ] || ${ECHO}; \
437 for l in "$$@"; do \
438 ${ECHO} "$$l"; \
439 done
440 @${ECHO} ""
441 @${ECHO} "=========================================================================="
442 . endif
443 .endif
445 .PHONY: show-depends-options
446 show-depends-options:
447 ${RUN} \
448 ${_DEPENDS_WALK_CMD} ${PKGPATH} | \
449 while read dir; do \
450 ${ECHO} "===> Options for $${dir}" && \
451 cd ${.CURDIR}/../../$$dir && \
452 ${RECURSIVE_MAKE} ${MAKEFLAGS} show-options; \
453 done
455 .endif # BSD_OPTIONS_MK