1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: confutils.eclass
7 # Benedikt Böhm <hollow@gentoo.org>
8 # @BLURB: utility functions to help with configuring a package
10 # The confutils eclass contains functions to handle use flag dependencies and
11 # extended --with-*/--enable-* magic.
13 # Based on the PHP5 eclass by Stuart Herbert <stuart@stuartherbert.com>
17 # @VARIABLE: EBUILD_SUPPORTS_SHAREDEXT
19 # Set this variable to 1 if your ebuild supports shared extensions. You need to
20 # call confutils_init() in pkg_setup() if you use this variable.
21 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then
25 # @FUNCTION: confutils_init
28 # Call this function from your pkg_setup() function to initialize this eclass
29 # if EBUILD_SUPPORTS_SHAREDEXT is enabled. If no value is given `shared' is used
32 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]] && use sharedext; then
33 shared="=${1:-shared}"
39 # @FUNCTION: confutils_require_one
40 # @USAGE: <flag> [more flags ...]
42 # Use this function to ensure exactly one of the specified USE flags have been
44 confutils_require_one() {
45 local required_flags="$@"
48 for flag in ${required_flags}; do
49 use ${flag} && ((success++))
52 [[ ${success} -eq 1 ]] && return
55 eerror "You *must* enable *exactly* one of the following USE flags:"
56 eerror " ${required_flags}"
58 eerror "You can do this by enabling *one* of these flag in /etc/portage/package.use:"
60 set -- ${required_flags}
61 eerror " =${CATEGORY}/${PN}-${PVR} ${1}"
65 eerror " OR =${CATEGORY}/${PN}-${PVR} ${flag}"
69 die "Missing or conflicting USE flags"
72 # @FUNCTION: confutils_require_any
73 # @USAGE: <flag> [more flags ...]
75 # Use this function to ensure one or more of the specified USE flags have been
77 confutils_require_any() {
78 local required_flags="$@"
81 for flag in ${required_flags}; do
82 use ${flag} && success=1
85 [[ ${success} -eq 1 ]] && return
88 eerror "You *must* enable one or more of the following USE flags:"
89 eerror " ${required_flags}"
91 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
92 eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
94 die "Missing USE flags"
97 # @FUNCTION: confutils_require_built_with_all
98 # @USAGE: <foreign> <flag> [more flags ...]
100 # Use this function to ensure all of the specified USE flags have been enabled
101 # in the specified foreign package
102 confutils_require_built_with_all() {
103 local foreign=$1 && shift
104 local required_flags="$@"
106 built_with_use ${foreign} ${required_flags} && return
109 eerror "You *must* enable all of the following USE flags in ${foreign}:"
110 eerror " ${required_flags}"
112 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
113 eerror " ${foreign} ${required_flags}"
115 die "Missing USE flags in ${foreign}"
118 # @FUNCTION: confutils_require_built_with_any
119 # @USAGE: <foreign> <flag> [more flags ...]
121 # Use this function to ensure one or more of the specified USE flags have been
122 # enabled in the specified foreign package
123 confutils_require_built_with_any() {
124 local foreign=$1 && shift
125 local required_flags="$@"
128 for flag in ${required_flags}; do
129 built_with_use ${foreign} ${flag} && success=1
132 [[ ${success} -eq 1 ]] && return
135 eerror "You *must* enable one or more of the following USE flags in ${foreign}:"
136 eerror " ${required_flags}"
138 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
139 eerror " ${foreign} ${required_flags}"
141 die "Missing USE flags in ${foreign}"
144 # @FUNCTION: confutils_use_conflict
145 # @USAGE: <enabled flag> <conflicting flag> [more conflicting flags ...]
147 # Use this function to automatically complain to the user if conflicting USE
148 # flags have been enabled
149 confutils_use_conflict() {
152 local my_flag="$1" && shift
158 my_present="${my_present} ${flag}"
159 my_remove="${my_remove} -${flag}"
163 [[ -z "${my_present}" ]] && return
166 eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
167 eerror " ${my_present}"
169 eerror "You must disable these conflicting flags before you can emerge this package."
170 eerror "You can do this by disabling these flags in /etc/portage/package.use:"
171 eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}"
173 eerror "You could disable this flag instead in /etc/portage/package.use:"
174 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
176 die "Conflicting USE flags"
179 # @FUNCTION: confutils_use_depend_all
180 # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
182 # Use this function to automatically complain to the user if a USE flag depends
183 # on another USE flag that hasn't been enabled
184 confutils_use_depend_all() {
187 local my_flag="$1" && shift
191 use ${flag} || my_missing="${my_missing} ${flag}"
194 [[ -z "${my_missing}" ]] && return
197 eerror "USE flag '${my_flag}' needs these additional flag(s) set:"
198 eerror " ${my_missing}"
200 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
201 eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
203 eerror "You could disable this flag instead in /etc/portage/package.use:"
204 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
206 die "Need missing USE flags"
209 # @FUNCTION: confutils_use_depend_any
210 # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
212 # Use this function to automatically complain to the user if a USE flag depends
213 # on another USE flag that hasn't been enabled
214 confutils_use_depend_any() {
217 local my_flag="$1" && shift
223 my_found="${my_found} ${flag}"
225 my_missing="${my_missing} ${flag}"
229 [[ -n "${my_found}" ]] && return
232 eerror "USE flag '${my_flag}' needs one or more of these additional flag(s) set:"
233 eerror " ${my_missing}"
235 eerror "You can do this by enabling one of these flags in /etc/portage/package.use:"
236 eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
238 eerror "You could disable this flag instead in /etc/portage/package.use:"
239 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
241 die "Need missing USE flag(s)"
244 # @FUNCTION: confutils_use_depend_built_with_all
245 # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
247 # Use this function to automatically complain to the user if a USE flag depends
248 # on a USE flag in another package that hasn't been enabled
249 confutils_use_depend_built_with_all() {
252 local my_flag="$1" && shift
253 local foreign=$1 && shift
254 local required_flags="$@"
256 built_with_use ${foreign} ${required_flags} && return
259 eerror "USE flag '${my_flag}' needs the following USE flags in ${foreign}:"
260 eerror " ${required_flags}"
262 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
263 eerror " ${foreign} ${required_flags}"
265 eerror "You could disable this flag instead in /etc/portage/package.use:"
266 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
268 die "Missing USE flags in ${foreign}"
271 # @FUNCTION: confutils_use_depend_built_with_any
272 # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
274 # Use this function to automatically complain to the user if a USE flag depends
275 # on a USE flag in another package that hasn't been enabled
276 confutils_use_depend_built_with_any() {
279 local my_flag="$1" && shift
280 local foreign=$1 && shift
281 local required_flags="$@"
284 for flag in ${required_flags}; do
285 built_with_use ${foreign} ${flag} && success=1
288 [[ ${success} -eq 1 ]] && return
291 eerror "USE flag '${my_flag}' needs one or more of the following USE flags in ${foreign}:"
292 eerror " ${required_flags}"
294 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
295 eerror " ${foreign} ${required_flags}"
297 eerror "You could disable this flag instead in /etc/portage/package.use:"
298 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
300 die "Missing USE flags in ${foreign}"
304 # internal function constructs the configure values for optional shared module
305 # support and extra arguments
306 _confutils_shared_suffix() {
309 if [[ "$1" == "1" ]]; then
310 if [[ -n "${shared}" ]]; then
311 my_shared="${shared}"
312 if [[ -n "$2" ]]; then
313 my_shared="${my_shared},$2"
315 elif [[ -n "$2" ]]; then
319 if [[ -n "$2" ]]; then
327 # @FUNCTION: enable_extension_disable
328 # @USAGE: <extension> <flag> [msg]
330 # Use this function to disable an extension that is enabled by default. This is
331 # provided for those rare configure scripts that don't support a --enable for
332 # the corresponding --disable.
333 enable_extension_disable() {
334 local my_msg=${3:-$1}
337 einfo " Enabling ${my_msg}"
339 my_conf="${my_conf} --disable-$1"
340 einfo " Disabling ${my_msg}"
344 # @FUNCTION: enable_extension_enable
345 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
347 # This function is like use_enable(), except that it knows about enabling
348 # modules as shared libraries, and it supports passing additional data with the
350 enable_extension_enable() {
351 local my_shared=$(_confutils_shared_suffix $3 $4)
352 local my_msg=${5:-$1}
355 my_conf="${my_conf} --enable-${1}${my_shared}"
356 einfo " Enabling ${my_msg}"
358 my_conf="${my_conf} --disable-$1"
359 einfo " Disabling ${my_msg}"
363 # @FUNCTION: enable_extension_enableonly
364 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
366 # This function is like use_enable(), except that it knows about enabling
367 # modules as shared libraries, and it supports passing additional data with the
368 # switch. This function is provided for those rare configure scripts that support
369 # --enable but not the corresponding --disable.
370 enable_extension_enableonly() {
371 local my_shared=$(_confutils_shared_suffix $3 $4)
372 local my_msg=${5:-$1}
375 my_conf="${my_conf} --enable-${1}${my_shared}"
376 einfo " Enabling ${my_msg}"
378 # note: we deliberately do *not* use a --disable switch here
379 einfo " Disabling ${my_msg}"
383 # @FUNCTION: enable_extension_without
384 # @USAGE: <extension> <flag> [msg]
386 # Use this function to disable an extension that is enabled by default. This
387 # function is provided for those rare configure scripts that support --without
388 # but not the corresponding --with
389 enable_extension_without() {
390 local my_msg=${3:-$1}
393 einfo " Enabling ${my_msg}"
395 my_conf="${my_conf} --without-$1"
396 einfo " Disabling ${my_msg}"
400 # @FUNCTION: enable_extension_with
401 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
403 # This function is like use_with(), except that it knows about enabling modules
404 # as shared libraries, and it supports passing additional data with the switch.
405 enable_extension_with() {
406 local my_shared=$(_confutils_shared_suffix $3 $4)
407 local my_msg=${5:-$1}
410 my_conf="${my_conf} --with-${1}${my_shared}"
411 einfo " Enabling ${my_msg}"
413 my_conf="${my_conf} --without-$1"
414 einfo " Disabling ${my_msg}"
418 # @FUNCTION: enable_extension_withonly
419 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
421 # This function is like use_with(), except that it knows about enabling modules
422 # as shared libraries, and it supports passing additional data with the switch.
423 # This function is provided for those rare configure scripts that support --enable
424 # but not the corresponding --disable.
425 enable_extension_withonly() {
426 local my_shared=$(_confutils_shared_suffix $3 $4)
427 local my_msg=${5:-$1}
430 my_conf="${my_conf} --with-${1}${my_shared}"
431 einfo " Enabling ${my_msg}"
433 # note: we deliberately do *not* use a --without switch here
434 einfo " Disabling ${my_msg}"
438 # @FUNCTION: enable_extension_enable_built_with
439 # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
441 # This function is like enable_extension_enable(), except that it
442 # enables/disables modules based on a USE flag in a foreign package.
443 enable_extension_enable_built_with() {
444 local my_shared=$(_confutils_shared_suffix $4 $5)
445 local my_msg=${6:-$3}
447 if built_with_use $1 $2; then
448 my_conf="${my_conf} --enable-${3}${my_shared}"
449 einfo " Enabling ${my_msg}"
451 my_conf="${my_conf} --disable-$3"
452 einfo " Disabling ${my_msg}"
456 # @FUNCTION: enable_extension_with_built_with ()
457 # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
459 # This function is like enable_extension_with(), except that it
460 # enables/disables modules based on a USE flag in a foreign package.
461 enable_extension_with_built_with() {
463 if [[ "$4" != "0" && "$4" != "1" ]]; then
464 enable_extension_with_built_with "$1" "$2" "$3" 0 "$4" "$5"
468 local my_shared=$(_confutils_shared_suffix $4 $5)
469 local my_msg=${6:-$3}
471 if built_with_use $1 $2; then
472 my_conf="${my_conf} --with-${3}${my_shared}"
473 einfo " Enabling ${my_msg}"
475 my_conf="${my_conf} --disable-$3"
476 einfo " Disabling ${my_msg}"