Add files from parent branch HEAD:
[pkgsrc.git] / mk / bsd.options.mk
1 # $NetBSD: bsd.options.mk,v 1.8 2004/08/22 19:42:10 jlam 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 should be defined:
7 #
8 #       PKG_OPTIONS_VAR
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.,
12 #
13 #                       PKG_OPTIONS_VAR=        WIBBLE_OPTIONS
14 #               or
15 #                       PKG_OPTIONS_VAR=        FOO_OPTIONS BAR_OPTIONS
16 #
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.,
20 #
21 #                       PKG_SUPPORTED_OPTIONS=  kerberos ldap ssl
22 #
23 # Optionally, the following variables may also be defined:
24 #
25 #       PKG_DEFAULT_OPTIONS
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.
29 #
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.
35 #
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"
40 #               or
41 #                       PKG_OPTIONS_VAR=        WIBBLE_OPTIONS
42 #                       WIBBLE_OPTIONS=         kerberos -ldap ldap
43 #                       # implies PKG_OPTIONS == "kerberos"
44 #
45 #               This variable should be set in /etc/mk.conf.
46 #
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".
52 #
53 # After including this file, the following variables are defined:
54 #
55 #       PKG_OPTIONS
56 #               This is the list of the selected build options, properly
57 #               filtered to remove unsupported and duplicate options.
58 #
59 # Example usage:
60 #
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
65 # .endif
66 # .if defined(WIBBLE_USE_SASL2) && !empty(WIBBLE_USE_SASL2:M[yY][eE][sS])
67 # PKG_DEFAULT_OPTIONS+= sasl
68 # .endif
69 #
70 # PKG_OPTIONS_VAR=              PKG_OPTIONS.wibble
71 # PKG_SUPPORTED_OPTIONS=        ldap sasl
72 # #
73 # # Default options for ``wibble'' package.
74 # #
75 # .if !defined(PKG_OPTIONS.wibble)
76 # PKG_DEFAULT_OPTIONS+=         sasl
77 # endif
78 # .include "../../mk/bsd.options.mk"
79 #
80 # # Package-specific option-handling
81 #
82 # ###
83 # ### LDAP support
84 # ###
85 # .if !empty(PKG_OPTIONS:Mldap)
86 # .  include "../../databases/openldap/buildlink3.mk"
87 # CONFIGURE_ARGS+=      --enable-ldap=${BUILDLINK_PREFIX.openldap}
88 # .endif
89 #
90 # ###
91 # ### SASL authentication
92 # ###
93 # .if !empty(PKG_OPTIONS:Msasl)
94 # .  include "../../security/cyrus-sasl2/buildlink3.mk"
95 # CONFIGURE_ARGS+=      --enable-sasl=${BUILDLINK_PREFIX.sasl}
96 # .endif
97 # -------------8<-------------8<-------------8<-------------8<-------------
98
99 .include "../../mk/bsd.prefs.mk"
100
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."
104 .endif
105 .if !defined(PKG_OPTIONS_VAR)
106 PKG_FAIL_REASON+=       "bsd.options.mk: PKG_OPTIONS_VAR is not defined."
107 .endif
108
109 # If none of the variables listed in PKG_OPTIONS_VAR is defined, then use
110 # the global options provided in ${PKG_DEFAULT_OPTIONS}.
111 #
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_}
116 .  endif
117 .endfor
118 .undef _opt_
119 _PKG_OPTIONS_VAR=       # empty
120 .for _var_ in ${PKG_OPTIONS_VAR}
121 .  if defined(${_var_})
122 _PKG_OPTIONS_VAR+=      ${_var_}
123 .  endif
124 .endfor
125 .undef _var_
126 .if empty(_PKG_OPTIONS_VAR)
127 _PKG_OPTIONS_VAR=       _PKG_DEFAULT_OPTIONS
128 .endif
129
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.
133 #
134 PKG_FAIL_UNSUPPORTED_OPTIONS?=  no
135
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-*}
140 .endfor
141 _PKG_NO_OPTIONS=        # contains the "negative" options
142 .for _var_ in ${_PKG_OPTIONS_VAR}
143 _PKG_NO_OPTIONS+=       ${${_var_}:M-*:S/^-//}
144 .endfor
145 .undef _var_
146
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.
151 #
152 PKG_OPTIONS=            # empty
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."
159 .    endif
160 .  endif
161 .endfor
162
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
167 .else
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:"
173         @${ECHO} ""
174         @${ECHO} "${PKG_SUPPORTED_OPTIONS}" | ${XARGS} -n 1 | ${SORT} | \
175         ${AWK} '                                                        \
176                 BEGIN { printwidth = 40; line = "" }                    \
177                 {                                                       \
178                         if (length(line) > 0)                           \
179                                 line = line" "$$0;                      \
180                         else                                            \
181                                 line = $$0;                             \
182                         if (length(line) > 40) {                        \
183                                 print " "line;                          \
184                                 line = "";                              \
185                         }                                               \
186                 }                                                       \
187                 END { if (length(line) > 0) print "     "line }         \
188         '
189         @${ECHO} ""
190         @${ECHO} "You can select which build options to use by setting the following"
191         @${ECHO} "variables.  Their current value is shown:"
192         @${ECHO} ""
193 .    for _var_ in ${PKG_OPTIONS_VAR}
194 .      if !defined(${_var_})
195         @${ECHO} "      ${_var_} (not defined)"
196 .      else
197         @${ECHO} "      ${_var_} = ${${_var_}}"
198 .      endif
199 .    endfor
200 .    undef _var_
201         @${ECHO} ""
202         @${ECHO} "=========================================================================="
203         @${TOUCH} ${.TARGET}
204 .  endif
205 .endif