/[gentoo-x86]/eclass/confutils.eclass
Gentoo

Contents of /eclass/confutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (show annotations) (download)
Wed Feb 27 09:53:04 2008 UTC (6 years, 10 months ago) by hollow
Branch: MAIN
Changes since 1.21: +34 -1 lines
add confutils_require_one

1 # Copyright 1999-2008 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/confutils.eclass,v 1.21 2008/02/20 13:07:50 hollow Exp $
4
5 # @ECLASS: confutils.eclass
6 # @MAINTAINER:
7 # Benedikt Böhm <hollow@gentoo.org>
8 # @BLURB: utility functions to help with configuring a package
9 # @DESCRIPTION:
10 # The confutils eclass contains functions to handle use flag dependencies and
11 # extended --with-*/--enable-* magic.
12 #
13 # Based on the PHP5 eclass by Stuart Herbert <stuart@stuartherbert.com>
14
15 inherit eutils
16
17 DESCRIPTION="Based on the ${ECLASS} eclass"
18
19 # @VARIABLE: EBUILD_SUPPORTS_SHAREDEXT
20 # @DESCRIPTION:
21 # Set this variable to 1 if your ebuild supports shared extensions. You need to
22 # call confutils_init() in pkg_setup() if you use this variable.
23 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then
24 IUSE="sharedext"
25 fi
26
27 # @FUNCTION: confutils_init
28 # @USAGE: [value]
29 # @DESCRIPTION:
30 # Call this function from your pkg_setup() function to initialize this eclass
31 # if EBUILD_SUPPORTS_SHAREDEXT is enabled. If no value is given `shared' is used
32 # by default.
33 confutils_init() {
34 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]] && use sharedext; then
35 shared="=${1:-shared}"
36 else
37 shared=
38 fi
39 }
40
41 # @FUNCTION: confutils_require_one
42 # @USAGE: <flag> [more flags ...]
43 # @DESCRIPTION:
44 # Use this function to ensure exactly one of the specified USE flags have been
45 # enabled
46 confutils_require_one() {
47 local required_flags="$@"
48 local success=0
49
50 for flag in ${required_flags}; do
51 use ${flag} && ((success++))
52 done
53
54 [[ ${success} -eq 1 ]] && return
55
56 echo
57 eerror "You *must* enable *exactly* one of the following USE flags:"
58 eerror " ${required_flags}"
59 eerror
60 eerror "You can do this by enabling *one* of these flag in /etc/portage/package.use:"
61
62 set -- ${required_flags}
63 eerror " =${CATEGORY}/${PN}-${PVR} ${1}"
64 shift
65
66 for flag in $@; do
67 eerror " OR =${CATEGORY}/${PN}-${PVR} ${flag}"
68 done
69
70 echo
71 die "Missing or conflicting USE flags"
72 }
73
74 # @FUNCTION: confutils_require_any
75 # @USAGE: <flag> [more flags ...]
76 # @DESCRIPTION:
77 # Use this function to ensure one or more of the specified USE flags have been
78 # enabled
79 confutils_require_any() {
80 local required_flags="$@"
81 local success=0
82
83 for flag in ${required_flags}; do
84 use ${flag} && success=1
85 done
86
87 [[ ${success} -eq 1 ]] && return
88
89 echo
90 eerror "You *must* enable one or more of the following USE flags:"
91 eerror " ${required_flags}"
92 eerror
93 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
94 eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
95 echo
96 die "Missing USE flags"
97 }
98
99 # @FUNCTION: confutils_require_built_with_all
100 # @USAGE: <foreign> <flag> [more flags ...]
101 # @DESCRIPTION:
102 # Use this function to ensure all of the specified USE flags have been enabled
103 # in the specified foreign package
104 confutils_require_built_with_all() {
105 local foreign=$1 && shift
106 local required_flags="$@"
107
108 built_with_use ${foreign} ${required_flags} && return
109
110 echo
111 eerror "You *must* enable all of the following USE flags in ${foreign}:"
112 eerror " ${required_flags}"
113 eerror
114 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
115 eerror " ${foreign} ${required_flags}"
116 echo
117 die "Missing USE flags in ${foreign}"
118 }
119
120 # @FUNCTION: confutils_require_built_with_any
121 # @USAGE: <foreign> <flag> [more flags ...]
122 # @DESCRIPTION:
123 # Use this function to ensure one or more of the specified USE flags have been
124 # enabled in the specified foreign package
125 confutils_require_built_with_any() {
126 local foreign=$1 && shift
127 local required_flags="$@"
128 local success=0
129
130 for flag in ${required_flags}; do
131 built_with_use ${foreign} ${flag} && success=1
132 done
133
134 [[ ${success} -eq 1 ]] && return
135
136 echo
137 eerror "You *must* enable one or more of the following USE flags in ${foreign}:"
138 eerror " ${required_flags}"
139 eerror
140 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
141 eerror " ${foreign} ${required_flags}"
142 echo
143 die "Missing USE flags in ${foreign}"
144 }
145
146 # @FUNCTION: confutils_use_conflict
147 # @USAGE: <enabled flag> <conflicting flag> [more conflicting flags ...]
148 # @DESCRIPTION:
149 # Use this function to automatically complain to the user if conflicting USE
150 # flags have been enabled
151 confutils_use_conflict() {
152 use $1 || return
153
154 local my_flag="$1" && shift
155 local my_present=
156 local my_remove=
157
158 for flag in "$@"; do
159 if use ${flag}; then
160 my_present="${my_present} ${flag}"
161 my_remove="${my_remove} -${flag}"
162 fi
163 done
164
165 [[ -z "${my_present}" ]] && return
166
167 echo
168 eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
169 eerror " ${my_present}"
170 eerror
171 eerror "You must disable these conflicting flags before you can emerge this package."
172 eerror "You can do this by disabling these flags in /etc/portage/package.use:"
173 eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}"
174 eerror
175 eerror "You could disable this flag instead in /etc/portage/package.use:"
176 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
177 echo
178 die "Conflicting USE flags"
179 }
180
181 # @FUNCTION: confutils_use_depend_all
182 # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
183 # @DESCRIPTION:
184 # Use this function to automatically complain to the user if a USE flag depends
185 # on another USE flag that hasn't been enabled
186 confutils_use_depend_all() {
187 use $1 || return
188
189 local my_flag="$1" && shift
190 local my_missing=
191
192 for flag in "$@"; do
193 use ${flag} || my_missing="${my_missing} ${flag}"
194 done
195
196 [[ -z "${my_missing}" ]] && return
197
198 echo
199 eerror "USE flag '${my_flag}' needs these additional flag(s) set:"
200 eerror " ${my_missing}"
201 eerror
202 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
203 eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
204 eerror
205 eerror "You could disable this flag instead in /etc/portage/package.use:"
206 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
207 echo
208 die "Need missing USE flags"
209 }
210
211 # @FUNCTION: confutils_use_depend_any
212 # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
213 # @DESCRIPTION:
214 # Use this function to automatically complain to the user if a USE flag depends
215 # on another USE flag that hasn't been enabled
216 confutils_use_depend_any() {
217 use $1 || return
218
219 local my_flag="$1" && shift
220 local my_found=
221 local my_missing=
222
223 for flag in "$@"; do
224 if use ${flag}; then
225 my_found="${my_found} ${flag}"
226 else
227 my_missing="${my_missing} ${flag}"
228 fi
229 done
230
231 [[ -n "${my_found}" ]] && return
232
233 echo
234 eerror "USE flag '${my_flag}' needs one or more of these additional flag(s) set:"
235 eerror " ${my_missing}"
236 eerror
237 eerror "You can do this by enabling one of these flags in /etc/portage/package.use:"
238 eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
239 eerror
240 eerror "You could disable this flag instead in /etc/portage/package.use:"
241 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
242 echo
243 die "Need missing USE flag(s)"
244 }
245
246 # @FUNCTION: confutils_use_depend_built_with_all
247 # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
248 # @DESCRIPTION:
249 # Use this function to automatically complain to the user if a USE flag depends
250 # on a USE flag in another package that hasn't been enabled
251 confutils_use_depend_built_with_all() {
252 use $1 || return
253
254 local my_flag="$1" && shift
255 local foreign=$1 && shift
256 local required_flags="$@"
257
258 built_with_use ${foreign} ${required_flags} && return
259
260 echo
261 eerror "USE flag '${my_flag}' needs the following USE flags in ${foreign}:"
262 eerror " ${required_flags}"
263 eerror
264 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
265 eerror " ${foreign} ${required_flags}"
266 eerror
267 eerror "You could disable this flag instead in /etc/portage/package.use:"
268 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
269 echo
270 die "Missing USE flags in ${foreign}"
271 }
272
273 # @FUNCTION: confutils_use_depend_built_with_any
274 # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
275 # @DESCRIPTION:
276 # Use this function to automatically complain to the user if a USE flag depends
277 # on a USE flag in another package that hasn't been enabled
278 confutils_use_depend_built_with_any() {
279 use $1 || return
280
281 local my_flag="$1" && shift
282 local foreign=$1 && shift
283 local required_flags="$@"
284 local success=0
285
286 for flag in ${required_flags}; do
287 built_with_use ${foreign} ${flag} && success=1
288 done
289
290 [[ ${success} -eq 1 ]] && return
291
292 echo
293 eerror "USE flag '${my_flag}' needs one or more of the following USE flags in ${foreign}:"
294 eerror " ${required_flags}"
295 eerror
296 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
297 eerror " ${foreign} ${required_flags}"
298 eerror
299 eerror "You could disable this flag instead in /etc/portage/package.use:"
300 eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
301 echo
302 die "Missing USE flags in ${foreign}"
303 }
304
305
306 # internal function constructs the configure values for optional shared module
307 # support and extra arguments
308 _confutils_shared_suffix() {
309 local my_shared=
310
311 if [[ "$1" == "1" ]]; then
312 if [[ -n "${shared}" ]]; then
313 my_shared="${shared}"
314 if [[ -n "$2" ]]; then
315 my_shared="${my_shared},$2"
316 fi
317 elif [[ -n "$2" ]]; then
318 my_shared="=$2"
319 fi
320 else
321 if [[ -n "$2" ]]; then
322 my_shared="=$2"
323 fi
324 fi
325
326 echo "${my_shared}"
327 }
328
329 # @FUNCTION: enable_extension_disable
330 # @USAGE: <extension> <flag> [msg]
331 # @DESCRIPTION:
332 # Use this function to disable an extension that is enabled by default. This is
333 # provided for those rare configure scripts that don't support a --enable for
334 # the corresponding --disable.
335 enable_extension_disable() {
336 local my_msg=${3:-$1}
337
338 if use "$2" ; then
339 einfo " Enabling ${my_msg}"
340 else
341 my_conf="${my_conf} --disable-$1"
342 einfo " Disabling ${my_msg}"
343 fi
344 }
345
346 # @FUNCTION: enable_extension_enable
347 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
348 # @DESCRIPTION:
349 # This function is like use_enable(), except that it knows about enabling
350 # modules as shared libraries, and it supports passing additional data with the
351 # switch.
352 enable_extension_enable() {
353 local my_shared=$(_confutils_shared_suffix $3 $4)
354 local my_msg=${5:-$1}
355
356 if use $2; then
357 my_conf="${my_conf} --enable-${1}${my_shared}"
358 einfo " Enabling ${my_msg}"
359 else
360 my_conf="${my_conf} --disable-$1"
361 einfo " Disabling ${my_msg}"
362 fi
363 }
364
365 # @FUNCTION: enable_extension_enableonly
366 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
367 # @DESCRIPTION:
368 # This function is like use_enable(), except that it knows about enabling
369 # modules as shared libraries, and it supports passing additional data with the
370 # switch. This function is provided for those rare configure scripts that support
371 # --enable but not the corresponding --disable.
372 enable_extension_enableonly() {
373 local my_shared=$(_confutils_shared_suffix $3 $4)
374 local my_msg=${5:-$1}
375
376 if use $2 ; then
377 my_conf="${my_conf} --enable-${1}${my_shared}"
378 einfo " Enabling ${my_msg}"
379 else
380 # note: we deliberately do *not* use a --disable switch here
381 einfo " Disabling ${my_msg}"
382 fi
383 }
384
385 # @FUNCTION: enable_extension_without
386 # @USAGE: <extension> <flag> [msg]
387 # @DESCRIPTION:
388 # Use this function to disable an extension that is enabled by default. This
389 # function is provided for those rare configure scripts that support --without
390 # but not the corresponding --with
391 enable_extension_without() {
392 local my_msg=${3:-$1}
393
394 if use "$2"; then
395 einfo " Enabling ${my_msg}"
396 else
397 my_conf="${my_conf} --without-$1"
398 einfo " Disabling ${my_msg}"
399 fi
400 }
401
402 # @FUNCTION: enable_extension_with
403 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
404 # @DESCRIPTION:
405 # This function is like use_with(), except that it knows about enabling modules
406 # as shared libraries, and it supports passing additional data with the switch.
407 enable_extension_with() {
408 local my_shared=$(_confutils_shared_suffix $3 $4)
409 local my_msg=${5:-$1}
410
411 if use $2; then
412 my_conf="${my_conf} --with-${1}${my_shared}"
413 einfo " Enabling ${my_msg}"
414 else
415 my_conf="${my_conf} --without-$1"
416 einfo " Disabling ${my_msg}"
417 fi
418 }
419
420 # @FUNCTION: enable_extension_withonly
421 # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
422 # @DESCRIPTION:
423 # This function is like use_with(), except that it knows about enabling modules
424 # as shared libraries, and it supports passing additional data with the switch.
425 # This function is provided for those rare configure scripts that support --enable
426 # but not the corresponding --disable.
427 enable_extension_withonly() {
428 local my_shared=$(_confutils_shared_suffix $3 $4)
429 local my_msg=${5:-$1}
430
431 if use $2; then
432 my_conf="${my_conf} --with-${1}${my_shared}"
433 einfo " Enabling ${my_msg}"
434 else
435 # note: we deliberately do *not* use a --without switch here
436 einfo " Disabling ${my_msg}"
437 fi
438 }
439
440 # @FUNCTION: enable_extension_enable_built_with
441 # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
442 # @DESCRIPTION:
443 # This function is like enable_extension_enable(), except that it
444 # enables/disables modules based on a USE flag in a foreign package.
445 enable_extension_enable_built_with() {
446 local my_shared=$(_confutils_shared_suffix $4 $5)
447 local my_msg=${6:-$3}
448
449 if built_with_use $1 $2; then
450 my_conf="${my_conf} --enable-${3}${my_shared}"
451 einfo " Enabling ${my_msg}"
452 else
453 my_conf="${my_conf} --disable-$3"
454 einfo " Disabling ${my_msg}"
455 fi
456 }
457
458 # @FUNCTION: enable_extension_with_built_with ()
459 # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
460 # @DESCRIPTION:
461 # This function is like enable_extension_with(), except that it
462 # enables/disables modules based on a USE flag in a foreign package.
463 enable_extension_with_built_with() {
464 # legacy workaround
465 if [[ "$4" != "0" && "$4" != "1" ]]; then
466 enable_extension_with_built_with "$1" "$2" "$3" 0 "$4" "$5"
467 return
468 fi
469
470 local my_shared=$(_confutils_shared_suffix $4 $5)
471 local my_msg=${6:-$3}
472
473 if built_with_use $1 $2; then
474 my_conf="${my_conf} --with-${3}${my_shared}"
475 einfo " Enabling ${my_msg}"
476 else
477 my_conf="${my_conf} --disable-$3"
478 einfo " Disabling ${my_msg}"
479 fi
480 }

  ViewVC Help
Powered by ViewVC 1.1.20