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

Contents of /eclass/confutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (hide annotations) (download)
Wed Feb 20 13:07:50 2008 UTC (6 years, 6 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 hollow 1.21 # Copyright 1999-2008 Gentoo Foundation
2 stuart 1.1 # Distributed under the terms of the GNU General Public License v2
3 hollow 1.21 # $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 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 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 stuart 1.18 if [[ ${EBUILD_SUPPORTS_SHAREDEXT} == 1 ]]; then
24     IUSE="sharedext"
25     fi
26 stuart 1.1
27 hollow 1.21 # @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 stuart 1.1 else
37     shared=
38     fi
39     }
40    
41 hollow 1.21 # @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 stuart 1.18
50 hollow 1.21 for flag in ${required_flags}; do
51     use ${flag} && success=1
52 stuart 1.18 done
53    
54 hollow 1.21 [[ ${success} -eq 1 ]] && return
55 stuart 1.18
56     echo
57     eerror "You *must* enable one or more of the following USE flags:"
58 hollow 1.21 eerror " ${required_flags}"
59 stuart 1.18 eerror
60     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
61 hollow 1.21 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 stuart 1.18 eerror
81 hollow 1.21 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 stuart 1.18 }
86    
87 hollow 1.21 # @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 stuart 1.1
103 hollow 1.21 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 stuart 1.1
113 hollow 1.21 # @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 stuart 1.1
121 hollow 1.21 local my_flag="$1" && shift
122 stuart 1.1 local my_present=
123     local my_remove=
124    
125 hollow 1.21 for flag in "$@"; do
126     if use ${flag}; then
127     my_present="${my_present} ${flag}"
128     my_remove="${my_remove} -${flag}"
129 stuart 1.1 fi
130     done
131    
132 hollow 1.21 [[ -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 stuart 1.1 }
147    
148 hollow 1.21 # @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 stuart 1.1
156 hollow 1.21 local my_flag="$1" && shift
157 stuart 1.1 local my_missing=
158    
159 hollow 1.21 for flag in "$@"; do
160     use ${flag} || my_missing="${my_missing} ${flag}"
161 stuart 1.1 done
162    
163 hollow 1.21 [[ -z "${my_missing}" ]] && return
164 stuart 1.1
165 hollow 1.21 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 stuart 1.1 }
177    
178 hollow 1.21 # @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 stuart 1.1
186 hollow 1.21 local my_flag="$1" && shift
187 stuart 1.1 local my_found=
188     local my_missing=
189    
190 hollow 1.21 for flag in "$@"; do
191     if use ${flag}; then
192     my_found="${my_found} ${flag}"
193 stuart 1.1 else
194 hollow 1.21 my_missing="${my_missing} ${flag}"
195 stuart 1.1 fi
196     done
197    
198 hollow 1.21 [[ -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 stuart 1.1 }
212    
213 hollow 1.21 # @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 stuart 1.1
227 hollow 1.21 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 stuart 1.1 }
239    
240 hollow 1.21 # @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 stuart 1.1
253 hollow 1.21 for flag in ${required_flags}; do
254     built_with_use ${foreign} ${flag} && success=1
255     done
256 stuart 1.1
257 hollow 1.21 [[ ${success} -eq 1 ]] && return
258 stuart 1.1
259 hollow 1.21 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 stuart 1.1 }
271    
272 stuart 1.13
273 hollow 1.21 # internal function constructs the configure values for optional shared module
274     # support and extra arguments
275     _confutils_shared_suffix() {
276     local my_shared=
277 stuart 1.13
278 hollow 1.21 if [[ "$1" == "1" ]]; then
279     if [[ -n "${shared}" ]]; then
280 stuart 1.13 my_shared="${shared}"
281 hollow 1.21 if [[ -n "$2" ]]; then
282     my_shared="${my_shared},$2"
283 stuart 1.13 fi
284 hollow 1.21 elif [[ -n "$2" ]]; then
285     my_shared="=$2"
286 stuart 1.13 fi
287     else
288 hollow 1.21 if [[ -n "$2" ]]; then
289     my_shared="=$2"
290 stuart 1.13 fi
291     fi
292    
293 hollow 1.21 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 stuart 1.13 else
308 hollow 1.21 my_conf="${my_conf} --disable-$1"
309     einfo " Disabling ${my_msg}"
310 stuart 1.13 fi
311     }
312 stuart 1.1
313 hollow 1.21 # @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 stuart 1.13 else
327 hollow 1.21 my_conf="${my_conf} --disable-$1"
328     einfo " Disabling ${my_msg}"
329 stuart 1.1 fi
330     }
331    
332 hollow 1.21 # @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 stuart 1.1
343 drac 1.20 if use $2 ; then
344 hollow 1.21 my_conf="${my_conf} --enable-${1}${my_shared}"
345     einfo " Enabling ${my_msg}"
346 stuart 1.1 else
347 hollow 1.21 # note: we deliberately do *not* use a --disable switch here
348     einfo " Disabling ${my_msg}"
349 stuart 1.13 fi
350     }
351    
352 hollow 1.21 # @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 stuart 1.13
361 hollow 1.21 if use "$2"; then
362     einfo " Enabling ${my_msg}"
363 stuart 1.13 else
364 hollow 1.21 my_conf="${my_conf} --without-$1"
365     einfo " Disabling ${my_msg}"
366 stuart 1.13 fi
367 hollow 1.21 }
368 stuart 1.13
369 hollow 1.21 # @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 stuart 1.13 else
382 hollow 1.21 my_conf="${my_conf} --without-$1"
383     einfo " Disabling ${my_msg}"
384 stuart 1.1 fi
385     }
386 stuart 1.2
387 hollow 1.21 # @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 stuart 1.2 fi
405     }
406 stuart 1.18
407 hollow 1.21 # @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 stuart 1.18 else
420     my_conf="${my_conf} --disable-$3"
421 hollow 1.21 einfo " Disabling ${my_msg}"
422 stuart 1.18 fi
423     }
424    
425 hollow 1.21 # @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 stuart 1.18 else
444     my_conf="${my_conf} --disable-$3"
445 hollow 1.21 einfo " Disabling ${my_msg}"
446 stuart 1.18 fi
447     }

  ViewVC Help
Powered by ViewVC 1.1.20