pullup 3232
[pkgsrcv2.git] / mk / bsd.options.mk
1 # $NetBSD: bsd.options.mk,v 1.66 2008/02/18 12:38:35 obache Exp $
2 #
3 # This Makefile fragment provides boilerplate code for standard naming
4 # conventions for handling per-package build options.
5 #
6 # Before including this file, the following variables can be defined:
7 #
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.,
11 #
12 #                       PKG_SUPPORTED_OPTIONS=  kerberos ldap ssl
13 #
14 #       PKG_OPTIONS_VAR (must be defined)
15 #               The variable the user can set to enable or disable
16 #               options specifically for this package.
17 #
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.
26 #
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.
31 #
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.
38 #
39 #       PKG_SUGGESTED_OPTIONS (defaults to empty)
40 #               This is a list of build options which are enabled by default.
41 #
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.
46 #
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.
51 #
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.
57 #
58 #       PKG_OPTIONS_DEPRECATED_WARNINGS
59 #               A list of warnings about deprecated variables or
60 #               options used, and what to use instead.
61 #
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.
66 #
67 #
68 # Optionally, the user may define the following variables in /etc/mk.conf:
69 #
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.
76 #
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.
81 #
82 # After including this file, the following variables are defined:
83 #
84 #       PKG_OPTIONS
85 #               This is the list of the selected build options, properly
86 #               filtered to remove unsupported and duplicate options.
87 #
88
89 .if !defined(BSD_OPTIONS_MK)
90 BSD_OPTIONS_MK=         # defined
91
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.
95 #
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
105 #
106 # .include "../../mk/bsd.prefs.mk"
107 #
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
113 #
114 # .include "../../mk/bsd.options.mk"
115 #
116 # # Package-specific option-handling
117 #
118 # ###
119 # ### FOO support
120 # ###
121 # .if !empty(PKG_OPTIONS:Mwibble-foo)
122 # CONFIGURE_ARGS+=      --enable-foo
123 # .endif
124
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
132 #
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
140 #
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<-------------
151 #
152 # Keywords: options.mk
153
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
162
163 .include "bsd.prefs.mk"
164
165 # Define PKG_OPTIONS, no matter if we have an error or not, to suppress
166 # further make(1) warnings.
167 PKG_OPTIONS=            # empty
168
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
180
181 #
182 # create map of option to group and add group options to PKG_SUPPORTED_OPTIONS
183 #
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
194
195 #
196 # add options from sets to PKG_SUPPORTED_OPTIONS
197 #
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
208
209 #
210 # include deprecated variable to options mapping
211 #
212 .include "defaults/obsolete.mk"
213
214 #
215 # place options implied by legacy variables in PKG_LEGACY_OPTIONS
216 #
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_
239
240 #
241 # create map of old option name to new option name for legacy options
242 #
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_
252
253 #
254 # filter unsupported options from PKG_DEFAULT_OPTIONS
255 #
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_
267
268 #
269 # process options from generic to specific
270 #
271
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 _OPTIONS_UNSUPPORTED:=${_OPTIONS_UNSUPPORTED} ${_opt_}
289 .  else
290 .    if defined(_PKG_OPTIONS_GROUP_MAP.${_popt_})
291 _grp_:= ${_PKG_OPTIONS_GROUP_MAP.${_popt_}}
292 _stk_:= _PKG_OPTIONS_GROUP_STACK.${_grp_}
293 _cnt_:= ${${_stk_}}
294 .      if !empty(_opt_:M-*)
295 ${_stk_}:=      ${_cnt_:N${_popt_}}
296 .      else
297 ${_stk_}:=      ${_cnt_} ${_popt_}
298 .      endif
299 .    else
300 .      if !empty(_opt_:M-*)
301 PKG_OPTIONS:=   ${PKG_OPTIONS:N${_popt_}}
302 .      else
303 PKG_OPTIONS:=   ${PKG_OPTIONS} ${_popt_}
304 .      endif
305 .    endif
306 .  endif
307 .endfor
308 .undef _opt_
309 .undef _popt_
310 .undef _stk_
311
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}
315 .  endif
316 .endfor
317
318 .for _grp_ in ${PKG_OPTIONS_REQUIRED_GROUPS} ${PKG_OPTIONS_OPTIONAL_GROUPS}
319 .  undef _opt_
320 .  for _o_ in ${_PKG_OPTIONS_GROUP_STACK.${_grp_}}
321 _opt_:=         ${_o_}
322 .  endfor
323 .  if defined(_opt_)
324 PKG_OPTIONS:=   ${PKG_OPTIONS} ${_opt_}
325 .  endif
326 .endfor
327 .undef _opt_
328
329 .for _set_ in ${PKG_OPTIONS_NONEMPTY_SETS}
330 _ISEMPTY:=true
331 .  for _opt_ in ${PKG_OPTIONS_SET.${_set_}}
332 .    if !empty(PKG_OPTIONS:M${_opt_})
333 _ISEMPTY:=false
334 .    endif
335 .  endfor
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}
338 .  endif
339 .endfor
340 .undef _ISEMPTY
341
342 .if !empty(_OPTIONS_UNSUPPORTED)
343 PKG_FAIL_REASON+=       "[bsd.options.mk] The following selected options are not supported: "${_OPTIONS_UNSUPPORTED:O:u:Q}"."
344 .endif
345
346 .undef _OPTIONS_DEFAULT_SUPPORTED
347 PKG_OPTIONS:=   ${PKG_OPTIONS:O:u}
348
349 _PKG_OPTIONS_WORDWRAP_FILTER=                                           \
350         ${XARGS} -n 1 |                                                 \
351         ${AWK} '                                                        \
352                 BEGIN { printwidth = 40; line = "" }                    \
353                 {                                                       \
354                         if (length(line) > 0)                           \
355                                 line = line" "$$0;                      \
356                         else                                            \
357                                 line = $$0;                             \
358                         if (length(line) > 40) {                        \
359                                 print " "line;                          \
360                                 line = "";                              \
361                         }                                               \
362                 }                                                       \
363                 END { if (length(line) > 0) print "     "line }         \
364         '
365
366 .PHONY: show-options
367 show-options:
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`
372 .  endif
373 .endfor
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`
378 .  endfor
379 .endfor
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`
384 .  endfor
385 .endfor
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`
390 .  endfor
391 .endfor
392         @${ECHO}
393         @${ECHO} "These options are enabled by default:"
394         @${ECHO} ${PKG_SUGGESTED_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
395         @${ECHO} ""
396         @${ECHO} "These options are currently enabled:"
397         @${ECHO} ${PKG_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
398         @${ECHO} ""
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}; \
403         for l in "$$@"; do \
404                 ${ECHO} "$$l"; \
405         done
406
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:"
414         @${ECHO} ""
415         @${ECHO} ${PKG_SUPPORTED_OPTIONS:O:Q} | ${_PKG_OPTIONS_WORDWRAP_FILTER}
416 .    if !empty(PKG_OPTIONS)
417         @${ECHO} ""
418         @${ECHO} "The currently selected options are:"
419         @${ECHO} ""
420         @${ECHO} ${PKG_OPTIONS:O:Q} | ${XARGS} -n 1 | ${_PKG_OPTIONS_WORDWRAP_FILTER}
421 .    endif
422         @${ECHO} ""
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:"
425         @${ECHO} ""
426 .    if !defined(${PKG_OPTIONS_VAR})
427         @${ECHO} "      ${PKG_OPTIONS_VAR} (not defined)"
428 .    else
429         @${ECHO} "      ${PKG_OPTIONS_VAR} = "${${PKG_OPTIONS_VAR}:Q}
430 .    endif
431         @set args ${PKG_OPTIONS_DEPRECATED_WARNINGS}; shift; \
432         [ $$# -eq 0 ] || ${ECHO}; \
433         for l in "$$@"; do \
434                 ${ECHO} "$$l"; \
435         done
436         @${ECHO} ""
437         @${ECHO} "=========================================================================="
438 .  endif
439 .endif
440
441 .endif  # BSD_OPTIONS_MK