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

Contents of /eclass/confutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Wed Feb 20 13:07:50 2008 UTC (6 years, 4 months ago) by hollow
Branch: MAIN
Changes since 1.20: +342 -385 lines
major confutils.eclass cleanup:
 * add built_with_use helpers
 * implement all documented features
 * document all implemented features
 * add standard eclass documentation
 * code DRY up

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

  ViewVC Help
Powered by ViewVC 1.1.20