1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: confutils.eclass
6 # No maintainer <maintainer-needed@gentoo.org>
7 # @BLURB: utility functions to help with configuring a package
9 # The confutils eclass contains functions to handle use flag dependencies and
10 # extended --with-*/--enable-* magic.
12 # Based on the PHP5 eclass by Stuart Herbert <stuart@stuartherbert.com>
16 # @VARIABLE: EBUILD_SUPPORTS_SHAREDEXT
18 # Set this variable to 1 if your ebuild supports shared extensions. You need to
19 # call confutils_init() in pkg_setup() if you use this variable.
20 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then
24 # @FUNCTION: confutils_init
27 # Call this function from your pkg_setup() function to initialize this eclass
28 # if EBUILD_SUPPORTS_SHAREDEXT is enabled. If no value is given `shared' is used
31 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]] && use sharedext; then
32 shared="=${1:-shared}"
38 # @FUNCTION: confutils_require_one
39 # @USAGE: <flag> [more flags ...]
41 # Use this function to ensure exactly one of the specified USE flags have been
43 confutils_require_one() {
44 local required_flags="$@"
47 for flag in ${required_flags}; do
48 use ${flag} && ((success++))
51 [[ ${success} -eq 1 ]] && return
54 eerror "You *must* enable *exactly* one of the following USE flags:"
55 eerror " ${required_flags}"
57 eerror "You can do this by enabling *one* of these flag in /etc/portage/package.use:"
59 set -- ${required_flags}
60 eerror " =${CATEGORY}/${PN}-${PVR} ${1}"
64 eerror " OR =${CATEGORY}/${PN}-${PVR} ${flag}"
68 die "Missing or conflicting USE flags"
71 # @FUNCTION: confutils_require_any
72 # @USAGE: <flag> [more flags ...]
74 # Use this function to ensure one or more of the specified USE flags have been
76 confutils_require_any() {
77 local required_flags="$@"
80 for flag in ${required_flags}; do
81 use ${flag} && success=1
84 [[ ${success} -eq 1 ]] && return
87 eerror "You *must* enable one or more of the following USE flags:"
88 eerror " ${required_flags}"
90 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
91 eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
93 die "Missing USE flags"
96 # @FUNCTION: confutils_require_built_with_all
97 # @USAGE: <foreign> <flag> [more flags ...]
99 # Use this function to ensure all of the specified USE flags have been enabled
100 # in the specified foreign package
101 confutils_require_built_with_all() {
102 local foreign=$1 && shift
103 local required_flags="$@"
105 built_with_use ${foreign} ${required_flags} && return
108 eerror "You *must* enable all of the following USE flags in ${foreign}:"
109 eerror " ${required_flags}"
111 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
112 eerror " ${foreign} ${required_flags}"
114 die "Missing USE flags in ${foreign}"
117 # @FUNCTION: confutils_require_built_with_any
118 # @USAGE: <foreign> <flag> [more flags ...]
120 # Use this function to ensure one or more of the specified USE flags have been
121 # enabled in the specified foreign package
122 confutils_require_built_with_any() {
123 local foreign=$1 && shift
124 local required_flags="$@"
127 for flag in ${required_flags}; do
128 built_with_use ${foreign} ${flag} && success=1
131 [[ ${success} -eq 1 ]] && return
134 eerror "You *must* enable one or more of the following USE flags in ${foreign}:"
135 eerror " ${required_flags}"
137 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
138 eerror " ${foreign} ${required_flags}"
140 die "Missing USE flags in ${foreign}"
143 # @FUNCTION: confutils_use_conflict
144 # @USAGE: <enabled flag> <conflicting flag> [more conflicting flags ...]
146 # Use this function to automatically complain to the user if conflicting USE
147 # flags have been enabled
148 confutils_use_conflict() {
151 local my_flag="$1" && shift
157 my_present="${my_present} ${flag}"
158 my_remove="${my_remove} -${flag}"
162 [[ -z "${my_present}" ]] && return
165 eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
166 eerror " ${my_present}"
168 eerror "You must disable these conflicting flags before you can emerge this package."
169 eerror "You can do this by disabling these flags in /etc/portage/package.use:"
170 eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}"
172 eerror "You could disable this flag instead in /etc/portage/package.use:"
173 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
175 die "Conflicting USE flags"
178 # @FUNCTION: confutils_use_depend_all
179 # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
181 # Use this function to automatically complain to the user if a USE flag depends
182 # on another USE flag that hasn't been enabled
183 confutils_use_depend_all() {
186 local my_flag="$1" && shift
190 use ${flag} || my_missing="${my_missing} ${flag}"
193 [[ -z "${my_missing}" ]] && return
196 eerror "USE flag '${my_flag}' needs these additional flag(s) set:"
197 eerror " ${my_missing}"
199 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
200 eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
202 eerror "You could disable this flag instead in /etc/portage/package.use:"
203 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
205 die "Need missing USE flags"
208 # @FUNCTION: confutils_use_depend_any
209 # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
211 # Use this function to automatically complain to the user if a USE flag depends
212 # on another USE flag that hasn't been enabled
213 confutils_use_depend_any() {
216 local my_flag="$1" && shift
222 my_found="${my_found} ${flag}"
224 my_missing="${my_missing} ${flag}"
228 [[ -n "${my_found}" ]] && return
231 eerror "USE flag '${my_flag}' needs one or more of these additional flag(s) set:"
232 eerror " ${my_missing}"
234 eerror "You can do this by enabling one of these flags in /etc/portage/package.use:"
235 eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
237 eerror "You could disable this flag instead in /etc/portage/package.use:"
238 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
240 die "Need missing USE flag(s)"
243 # @FUNCTION: confutils_use_depend_built_with_all
244 # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
246 # Use this function to automatically complain to the user if a USE flag depends
247 # on a USE flag in another package that hasn't been enabled
248 confutils_use_depend_built_with_all() {
251 local my_flag="$1" && shift
252 local foreign=$1 && shift
253 local required_flags="$@"
255 built_with_use ${foreign} ${required_flags} && return
258 eerror "USE flag '${my_flag}' needs the following USE flags in ${foreign}:"
259 eerror " ${required_flags}"
261 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
262 eerror " ${foreign} ${required_flags}"
264 eerror "You could disable this flag instead in /etc/portage/package.use:"
265 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
267 die "Missing USE flags in ${foreign}"
270 # @FUNCTION: confutils_use_depend_built_with_any
271 # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
273 # Use this function to automatically complain to the user if a USE flag depends
274 # on a USE flag in another package that hasn't been enabled
275 confutils_use_depend_built_with_any() {
278 local my_flag="$1" && shift
279 local foreign=$1 && shift
280 local required_flags="$@"
283 for flag in ${required_flags}; do
284 built_with_use ${foreign} ${flag} && success=1
287 [[ ${success} -eq 1 ]] && return
290 eerror "USE flag '${my_flag}' needs one or more of the following USE flags in ${foreign}:"
291 eerror " ${required_flags}"
293 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
294 eerror " ${foreign} ${required_flags}"
296 eerror "You could disable this flag instead in /etc/portage/package.use:"
297 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
299 die "Missing USE flags in ${foreign}"
303 # internal function constructs the configure values for optional shared module
304 # support and extra arguments
305 _confutils_shared_suffix() {
308 if [[ "$1" == "1" ]]; then
309 if [[ -n "${shared}" ]]; then
310 my_shared="${shared}"
311 if [[ -n "$2" ]]; then
312 my_shared="${my_shared},$2"
314 elif [[ -n "$2" ]]; then
318 if [[ -n "$2" ]]; then
326 # @FUNCTION: enable_extension_disable
327 # @USAGE: <extension> <flag> [msg]
329 # Use this function to disable an extension that is enabled by default. This is
330 # provided for those rare configure scripts that don't support a --enable for
331 # the corresponding --disable.
332 enable_extension_disable() {
333 local my_msg=${3:-$1}
336 einfo " Enabling ${my_msg}"
338 my_conf="${my_conf} --disable-$1"
339 einfo " Disabling ${my_msg}"
343 # @FUNCTION: enable_extension_enable
344 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
346 # This function is like use_enable(), except that it knows about enabling
347 # modules as shared libraries, and it supports passing additional data with the
349 enable_extension_enable() {
350 local my_shared=$(_confutils_shared_suffix $3 $4)
351 local my_msg=${5:-$1}
354 my_conf="${my_conf} --enable-${1}${my_shared}"
355 einfo " Enabling ${my_msg}"
357 my_conf="${my_conf} --disable-$1"
358 einfo " Disabling ${my_msg}"
362 # @FUNCTION: enable_extension_enableonly
363 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
365 # This function is like use_enable(), except that it knows about enabling
366 # modules as shared libraries, and it supports passing additional data with the
367 # switch. This function is provided for those rare configure scripts that support
368 # --enable but not the corresponding --disable.
369 enable_extension_enableonly() {
370 local my_shared=$(_confutils_shared_suffix $3 $4)
371 local my_msg=${5:-$1}
374 my_conf="${my_conf} --enable-${1}${my_shared}"
375 einfo " Enabling ${my_msg}"
377 # note: we deliberately do *not* use a --disable switch here
378 einfo " Disabling ${my_msg}"
382 # @FUNCTION: enable_extension_without
383 # @USAGE: <extension> <flag> [msg]
385 # Use this function to disable an extension that is enabled by default. This
386 # function is provided for those rare configure scripts that support --without
387 # but not the corresponding --with
388 enable_extension_without() {
389 local my_msg=${3:-$1}
392 einfo " Enabling ${my_msg}"
394 my_conf="${my_conf} --without-$1"
395 einfo " Disabling ${my_msg}"
399 # @FUNCTION: enable_extension_with
400 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
402 # This function is like use_with(), except that it knows about enabling modules
403 # as shared libraries, and it supports passing additional data with the switch.
404 enable_extension_with() {
405 local my_shared=$(_confutils_shared_suffix $3 $4)
406 local my_msg=${5:-$1}
409 my_conf="${my_conf} --with-${1}${my_shared}"
410 einfo " Enabling ${my_msg}"
412 my_conf="${my_conf} --without-$1"
413 einfo " Disabling ${my_msg}"
417 # @FUNCTION: enable_extension_withonly
418 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
420 # This function is like use_with(), except that it knows about enabling modules
421 # as shared libraries, and it supports passing additional data with the switch.
422 # This function is provided for those rare configure scripts that support --enable
423 # but not the corresponding --disable.
424 enable_extension_withonly() {
425 local my_shared=$(_confutils_shared_suffix $3 $4)
426 local my_msg=${5:-$1}
429 my_conf="${my_conf} --with-${1}${my_shared}"
430 einfo " Enabling ${my_msg}"
432 # note: we deliberately do *not* use a --without switch here
433 einfo " Disabling ${my_msg}"
437 # @FUNCTION: enable_extension_enable_built_with
438 # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
440 # This function is like enable_extension_enable(), except that it
441 # enables/disables modules based on a USE flag in a foreign package.
442 enable_extension_enable_built_with() {
443 local my_shared=$(_confutils_shared_suffix $4 $5)
444 local my_msg=${6:-$3}
446 if built_with_use $1 $2; then
447 my_conf="${my_conf} --enable-${3}${my_shared}"
448 einfo " Enabling ${my_msg}"
450 my_conf="${my_conf} --disable-$3"
451 einfo " Disabling ${my_msg}"
455 # @FUNCTION: enable_extension_with_built_with
456 # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
458 # This function is like enable_extension_with(), except that it
459 # enables/disables modules based on a USE flag in a foreign package.
460 enable_extension_with_built_with() {
462 if [[ "$4" != "0" && "$4" != "1" ]]; then
463 enable_extension_with_built_with "$1" "$2" "$3" 0 "$4" "$5"
467 local my_shared=$(_confutils_shared_suffix $4 $5)
468 local my_msg=${6:-$3}
470 if built_with_use $1 $2; then
471 my_conf="${my_conf} --with-${3}${my_shared}"
472 einfo " Enabling ${my_msg}"
474 my_conf="${my_conf} --disable-$3"
475 einfo " Disabling ${my_msg}"