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

Contents of /eclass/confutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations) (download)
Sat Sep 15 16:16:53 2012 UTC (22 months, 1 week ago) by zmedico
Branch: MAIN
CVS Tags: HEAD
Changes since 1.22: +2 -4 lines
Remove redundant DESCRIPTION variable settings.

1 zmedico 1.23 # Copyright 1999-2012 Gentoo Foundation
2 stuart 1.1 # Distributed under the terms of the GNU General Public License v2
3 zmedico 1.23 # $Header: /var/cvsroot/gentoo-x86/eclass/confutils.eclass,v 1.22 2008/02/27 09:53:04 hollow Exp $
4 hollow 1.21
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 stuart 1.1 #
13 hollow 1.21 # Based on the PHP5 eclass by Stuart Herbert <stuart@stuartherbert.com>
14 stuart 1.1
15 drac 1.20 inherit eutils
16    
17 hollow 1.21 # @VARIABLE: EBUILD_SUPPORTS_SHAREDEXT
18     # @DESCRIPTION:
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 stuart 1.18 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then
22     IUSE="sharedext"
23     fi
24 stuart 1.1
25 hollow 1.21 # @FUNCTION: confutils_init
26     # @USAGE: [value]
27     # @DESCRIPTION:
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
30     # by default.
31     confutils_init() {
32     if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]] && use sharedext; then
33     shared="=${1:-shared}"
34 stuart 1.1 else
35     shared=
36     fi
37     }
38    
39 hollow 1.22 # @FUNCTION: confutils_require_one
40     # @USAGE: <flag> [more flags ...]
41     # @DESCRIPTION:
42     # Use this function to ensure exactly one of the specified USE flags have been
43     # enabled
44     confutils_require_one() {
45     local required_flags="$@"
46     local success=0
47    
48     for flag in ${required_flags}; do
49     use ${flag} && ((success++))
50     done
51    
52     [[ ${success} -eq 1 ]] && return
53    
54     echo
55     eerror "You *must* enable *exactly* one of the following USE flags:"
56     eerror " ${required_flags}"
57     eerror
58     eerror "You can do this by enabling *one* of these flag in /etc/portage/package.use:"
59    
60     set -- ${required_flags}
61     eerror " =${CATEGORY}/${PN}-${PVR} ${1}"
62     shift
63    
64     for flag in $@; do
65     eerror " OR =${CATEGORY}/${PN}-${PVR} ${flag}"
66     done
67    
68     echo
69     die "Missing or conflicting USE flags"
70     }
71    
72 hollow 1.21 # @FUNCTION: confutils_require_any
73     # @USAGE: <flag> [more flags ...]
74     # @DESCRIPTION:
75     # Use this function to ensure one or more of the specified USE flags have been
76     # enabled
77     confutils_require_any() {
78     local required_flags="$@"
79     local success=0
80 stuart 1.18
81 hollow 1.21 for flag in ${required_flags}; do
82     use ${flag} && success=1
83 stuart 1.18 done
84    
85 hollow 1.21 [[ ${success} -eq 1 ]] && return
86 stuart 1.18
87     echo
88     eerror "You *must* enable one or more of the following USE flags:"
89 hollow 1.21 eerror " ${required_flags}"
90 stuart 1.18 eerror
91     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
92 hollow 1.21 eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
93     echo
94     die "Missing USE flags"
95     }
96    
97     # @FUNCTION: confutils_require_built_with_all
98     # @USAGE: <foreign> <flag> [more flags ...]
99     # @DESCRIPTION:
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="$@"
105    
106     built_with_use ${foreign} ${required_flags} && return
107    
108     echo
109     eerror "You *must* enable all of the following USE flags in ${foreign}:"
110     eerror " ${required_flags}"
111 stuart 1.18 eerror
112 hollow 1.21 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
113     eerror " ${foreign} ${required_flags}"
114     echo
115     die "Missing USE flags in ${foreign}"
116 stuart 1.18 }
117    
118 hollow 1.21 # @FUNCTION: confutils_require_built_with_any
119     # @USAGE: <foreign> <flag> [more flags ...]
120     # @DESCRIPTION:
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="$@"
126     local success=0
127    
128     for flag in ${required_flags}; do
129     built_with_use ${foreign} ${flag} && success=1
130     done
131    
132     [[ ${success} -eq 1 ]] && return
133 stuart 1.1
134 hollow 1.21 echo
135     eerror "You *must* enable one or more of the following USE flags in ${foreign}:"
136     eerror " ${required_flags}"
137     eerror
138     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
139     eerror " ${foreign} ${required_flags}"
140     echo
141     die "Missing USE flags in ${foreign}"
142     }
143 stuart 1.1
144 hollow 1.21 # @FUNCTION: confutils_use_conflict
145     # @USAGE: <enabled flag> <conflicting flag> [more conflicting flags ...]
146     # @DESCRIPTION:
147     # Use this function to automatically complain to the user if conflicting USE
148     # flags have been enabled
149     confutils_use_conflict() {
150     use $1 || return
151 stuart 1.1
152 hollow 1.21 local my_flag="$1" && shift
153 stuart 1.1 local my_present=
154     local my_remove=
155    
156 hollow 1.21 for flag in "$@"; do
157     if use ${flag}; then
158     my_present="${my_present} ${flag}"
159     my_remove="${my_remove} -${flag}"
160 stuart 1.1 fi
161     done
162    
163 hollow 1.21 [[ -z "${my_present}" ]] && return
164    
165     echo
166     eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
167     eerror " ${my_present}"
168     eerror
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}"
172     eerror
173     eerror "You could disable this flag instead in /etc/portage/package.use:"
174     eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
175     echo
176     die "Conflicting USE flags"
177 stuart 1.1 }
178    
179 hollow 1.21 # @FUNCTION: confutils_use_depend_all
180     # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
181     # @DESCRIPTION:
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() {
185     use $1 || return
186 stuart 1.1
187 hollow 1.21 local my_flag="$1" && shift
188 stuart 1.1 local my_missing=
189    
190 hollow 1.21 for flag in "$@"; do
191     use ${flag} || my_missing="${my_missing} ${flag}"
192 stuart 1.1 done
193    
194 hollow 1.21 [[ -z "${my_missing}" ]] && return
195 stuart 1.1
196 hollow 1.21 echo
197     eerror "USE flag '${my_flag}' needs these additional flag(s) set:"
198     eerror " ${my_missing}"
199     eerror
200     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
201     eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
202     eerror
203     eerror "You could disable this flag instead in /etc/portage/package.use:"
204     eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
205     echo
206     die "Need missing USE flags"
207 stuart 1.1 }
208    
209 hollow 1.21 # @FUNCTION: confutils_use_depend_any
210     # @USAGE: <enabled flag> <needed flag> [more needed flags ...]
211     # @DESCRIPTION:
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() {
215     use $1 || return
216 stuart 1.1
217 hollow 1.21 local my_flag="$1" && shift
218 stuart 1.1 local my_found=
219     local my_missing=
220    
221 hollow 1.21 for flag in "$@"; do
222     if use ${flag}; then
223     my_found="${my_found} ${flag}"
224 stuart 1.1 else
225 hollow 1.21 my_missing="${my_missing} ${flag}"
226 stuart 1.1 fi
227     done
228    
229 hollow 1.21 [[ -n "${my_found}" ]] && return
230    
231     echo
232     eerror "USE flag '${my_flag}' needs one or more of these additional flag(s) set:"
233     eerror " ${my_missing}"
234     eerror
235     eerror "You can do this by enabling one of these flags in /etc/portage/package.use:"
236     eerror " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
237     eerror
238     eerror "You could disable this flag instead in /etc/portage/package.use:"
239     eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
240     echo
241     die "Need missing USE flag(s)"
242 stuart 1.1 }
243    
244 hollow 1.21 # @FUNCTION: confutils_use_depend_built_with_all
245     # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
246     # @DESCRIPTION:
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() {
250     use $1 || return
251    
252     local my_flag="$1" && shift
253     local foreign=$1 && shift
254     local required_flags="$@"
255    
256     built_with_use ${foreign} ${required_flags} && return
257 stuart 1.1
258 hollow 1.21 echo
259     eerror "USE flag '${my_flag}' needs the following USE flags in ${foreign}:"
260     eerror " ${required_flags}"
261     eerror
262     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
263     eerror " ${foreign} ${required_flags}"
264     eerror
265     eerror "You could disable this flag instead in /etc/portage/package.use:"
266     eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
267     echo
268     die "Missing USE flags in ${foreign}"
269 stuart 1.1 }
270    
271 hollow 1.21 # @FUNCTION: confutils_use_depend_built_with_any
272     # @USAGE: <enabled flag> <foreign> <needed flag> [more needed flags ...]
273     # @DESCRIPTION:
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() {
277     use $1 || return
278    
279     local my_flag="$1" && shift
280     local foreign=$1 && shift
281     local required_flags="$@"
282     local success=0
283 stuart 1.1
284 hollow 1.21 for flag in ${required_flags}; do
285     built_with_use ${foreign} ${flag} && success=1
286     done
287 stuart 1.1
288 hollow 1.21 [[ ${success} -eq 1 ]] && return
289 stuart 1.1
290 hollow 1.21 echo
291     eerror "USE flag '${my_flag}' needs one or more of the following USE flags in ${foreign}:"
292     eerror " ${required_flags}"
293     eerror
294     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
295     eerror " ${foreign} ${required_flags}"
296     eerror
297     eerror "You could disable this flag instead in /etc/portage/package.use:"
298     eerror " =${CATEGORY}/${PN}-${PVR} -${my_flag}"
299     echo
300     die "Missing USE flags in ${foreign}"
301 stuart 1.1 }
302    
303 stuart 1.13
304 hollow 1.21 # internal function constructs the configure values for optional shared module
305     # support and extra arguments
306     _confutils_shared_suffix() {
307     local my_shared=
308 stuart 1.13
309 hollow 1.21 if [[ "$1" == "1" ]]; then
310     if [[ -n "${shared}" ]]; then
311 stuart 1.13 my_shared="${shared}"
312 hollow 1.21 if [[ -n "$2" ]]; then
313     my_shared="${my_shared},$2"
314 stuart 1.13 fi
315 hollow 1.21 elif [[ -n "$2" ]]; then
316     my_shared="=$2"
317 stuart 1.13 fi
318     else
319 hollow 1.21 if [[ -n "$2" ]]; then
320     my_shared="=$2"
321 stuart 1.13 fi
322     fi
323    
324 hollow 1.21 echo "${my_shared}"
325     }
326    
327     # @FUNCTION: enable_extension_disable
328     # @USAGE: <extension> <flag> [msg]
329     # @DESCRIPTION:
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}
335    
336     if use "$2" ; then
337     einfo " Enabling ${my_msg}"
338 stuart 1.13 else
339 hollow 1.21 my_conf="${my_conf} --disable-$1"
340     einfo " Disabling ${my_msg}"
341 stuart 1.13 fi
342     }
343 stuart 1.1
344 hollow 1.21 # @FUNCTION: enable_extension_enable
345     # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
346     # @DESCRIPTION:
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
349     # switch.
350     enable_extension_enable() {
351     local my_shared=$(_confutils_shared_suffix $3 $4)
352     local my_msg=${5:-$1}
353    
354     if use $2; then
355     my_conf="${my_conf} --enable-${1}${my_shared}"
356     einfo " Enabling ${my_msg}"
357 stuart 1.13 else
358 hollow 1.21 my_conf="${my_conf} --disable-$1"
359     einfo " Disabling ${my_msg}"
360 stuart 1.1 fi
361     }
362    
363 hollow 1.21 # @FUNCTION: enable_extension_enableonly
364     # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
365     # @DESCRIPTION:
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}
373 stuart 1.1
374 drac 1.20 if use $2 ; then
375 hollow 1.21 my_conf="${my_conf} --enable-${1}${my_shared}"
376     einfo " Enabling ${my_msg}"
377 stuart 1.1 else
378 hollow 1.21 # note: we deliberately do *not* use a --disable switch here
379     einfo " Disabling ${my_msg}"
380 stuart 1.13 fi
381     }
382    
383 hollow 1.21 # @FUNCTION: enable_extension_without
384     # @USAGE: <extension> <flag> [msg]
385     # @DESCRIPTION:
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}
391 stuart 1.13
392 hollow 1.21 if use "$2"; then
393     einfo " Enabling ${my_msg}"
394 stuart 1.13 else
395 hollow 1.21 my_conf="${my_conf} --without-$1"
396     einfo " Disabling ${my_msg}"
397 stuart 1.13 fi
398 hollow 1.21 }
399 stuart 1.13
400 hollow 1.21 # @FUNCTION: enable_extension_with
401     # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
402     # @DESCRIPTION:
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}
408    
409     if use $2; then
410     my_conf="${my_conf} --with-${1}${my_shared}"
411     einfo " Enabling ${my_msg}"
412 stuart 1.13 else
413 hollow 1.21 my_conf="${my_conf} --without-$1"
414     einfo " Disabling ${my_msg}"
415 stuart 1.1 fi
416     }
417 stuart 1.2
418 hollow 1.21 # @FUNCTION: enable_extension_withonly
419     # @USAGE: <extension> <flag> [shared] [extra conf] [msg]
420     # @DESCRIPTION:
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}
428    
429     if use $2; then
430     my_conf="${my_conf} --with-${1}${my_shared}"
431     einfo " Enabling ${my_msg}"
432     else
433     # note: we deliberately do *not* use a --without switch here
434     einfo " Disabling ${my_msg}"
435 stuart 1.2 fi
436     }
437 stuart 1.18
438 hollow 1.21 # @FUNCTION: enable_extension_enable_built_with
439     # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
440     # @DESCRIPTION:
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}
446    
447     if built_with_use $1 $2; then
448     my_conf="${my_conf} --enable-${3}${my_shared}"
449     einfo " Enabling ${my_msg}"
450 stuart 1.18 else
451     my_conf="${my_conf} --disable-$3"
452 hollow 1.21 einfo " Disabling ${my_msg}"
453 stuart 1.18 fi
454     }
455    
456 hollow 1.21 # @FUNCTION: enable_extension_with_built_with ()
457     # @USAGE: <foreign> <flag> <extension> [shared] [extra conf] [msg]
458     # @DESCRIPTION:
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() {
462     # legacy workaround
463     if [[ "$4" != "0" && "$4" != "1" ]]; then
464     enable_extension_with_built_with "$1" "$2" "$3" 0 "$4" "$5"
465     return
466     fi
467    
468     local my_shared=$(_confutils_shared_suffix $4 $5)
469     local my_msg=${6:-$3}
470    
471     if built_with_use $1 $2; then
472     my_conf="${my_conf} --with-${3}${my_shared}"
473     einfo " Enabling ${my_msg}"
474 stuart 1.18 else
475     my_conf="${my_conf} --disable-$3"
476 hollow 1.21 einfo " Disabling ${my_msg}"
477 stuart 1.18 fi
478     }

  ViewVC Help
Powered by ViewVC 1.1.20