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

Contents of /eclass/phpconfutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download)
Thu Apr 20 12:15:35 2006 UTC (8 years, 8 months ago) by chtekk
Branch: MAIN
Changes since 1.2: +5 -2 lines
Don't die on USE=-*, eclass part.

1 chtekk 1.1 # Copyright 1999-2006 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 chtekk 1.2 # $Header: /var/cvsroot/gentoo-x86/eclass/phpconfutils.eclass,v 1.1 2006/03/24 23:05:49 chtekk Exp $
4 chtekk 1.1 #
5     # ########################################################################
6     #
7     # eclass/phpconfutils.eclass
8     # Utility functions to help with configuring PHP
9     #
10     # Based on stuart's work on the original confutils eclass
11     #
12     # Author(s) Luca Longinotti
13     # <chtekk@gentoo.org>
14     #
15     # Maintained by the PHP Herd <php-bugs@gentoo.org>
16     #
17     # ========================================================================
18    
19     if [[ "${EBUILD_SUPPORTS_SHAREDEXT}" == "1" ]] ; then
20     IUSE="sharedext"
21     fi
22    
23     # ========================================================================
24     # List of USE flags that need deps that aren't yet in Portage
25     # or that can't be (fex. certain commercial apps)
26     #
27     # You must define CONFUTILS_MISSING_DEPS if you need this
28    
29     # ========================================================================
30     # phpconfutils_sort_flags()
31     #
32     # Sort and remove duplicates of the auto-enabled USE flags
33     #
34    
35     phpconfutils_sort_flags() {
36     # Sort the list of auto-magically enabled USE flags
37     PHPCONFUTILS_AUTO_USE="`echo ${PHPCONFUTILS_AUTO_USE} | tr '\040\010' '\012\012' | sort -u`"
38     }
39    
40     # ========================================================================
41     # phpconfutils_init()
42     #
43     # Call this function from your src_compile() function to initialise
44     # this eclass first
45     #
46    
47     phpconfutils_init() {
48     # Define wheter we shall support shared extensions or not
49     if [[ "${EBUILD_SUPPORTS_SHAREDEXT}" == "1" ]] && useq "sharedext" ; then
50     shared="=shared"
51     else
52     shared=""
53     fi
54    
55     phpconfutils_sort_flags
56     }
57    
58     # ========================================================================
59     # phpconfutils_usecheck()
60     #
61     # Check if the USE flag we want enabled is part of the auto-magical ones
62     #
63    
64     phpconfutils_usecheck() {
65     local x
66     local use="$1"
67    
68     for x in ${PHPCONFUTILS_AUTO_USE} ; do
69     if [[ "${use}+" == "${x}+" ]] ; then
70     return 0
71     fi
72     done
73    
74     # If we get here, the USE is not among the auto-enabled ones
75     return 1
76     }
77    
78     # ========================================================================
79     # phpconfutils_require_any()
80     #
81     # Use this function to ensure one or more of the specified USE flags have
82     # been enabled and output the results
83     #
84     # $1 - message to output everytime a flag is found
85     # $2 - message to output everytime a flag is not found
86     # $3 .. - flags to check
87     #
88    
89     phpconfutils_require_any() {
90     local success_msg="$1"
91     shift
92     local fail_msg="$1"
93     shift
94    
95     local required_flags="$@"
96 chtekk 1.3 local default_flag="$1"
97 chtekk 1.1 local success="0"
98    
99     while [[ -n "$1" ]] ; do
100     if useq "$1" ; then
101     einfo "${success_msg} $1"
102     success="1"
103     else
104     ewarn "${fail_msg} $1"
105     fi
106     shift
107     done
108    
109     # Did we find what we are looking for?
110     if [[ "${success}" == "1" ]] ; then
111     return
112     fi
113    
114     # If we get here, then none of the required USE flags were enabled
115     eerror
116 chtekk 1.3 eerror "You should enable one or more of the following USE flags:"
117 chtekk 1.1 eerror " ${required_flags}"
118     eerror
119     eerror "You can do this by enabling these flags in /etc/portage/package.use:"
120     eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
121     eerror
122 chtekk 1.3 eerror "The ${default_flag} USE flag was automatically enabled now."
123     eerror
124     PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${default_flag}"
125 chtekk 1.1 }
126    
127     # ========================================================================
128     # phpconfutils_use_conflict()
129     #
130     # Use this function to automatically complain to the user if USE flags
131     # that directly conflict have been enabled
132     #
133     # $1 - flag that conflicts with other flags
134     # $2 .. - flags that conflict
135     #
136    
137     phpconfutils_use_conflict() {
138     phpconfutils_sort_flags
139    
140     if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
141     return
142     fi
143    
144     local my_flag="$1"
145     shift
146    
147     local my_present=""
148     local my_remove=""
149    
150     while [[ "$1+" != "+" ]] ; do
151     if useq "$1" || phpconfutils_usecheck "$1" ; then
152     my_present="${my_present} $1"
153     my_remove="${my_remove} -$1"
154     fi
155     shift
156     done
157    
158     if [[ -n "${my_present}" ]] ; then
159     eerror
160     eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
161     eerror " ${my_present}"
162     eerror
163     eerror "You must disable these conflicting flags before you can emerge this package."
164     eerror "You can do this by disabling these flags in /etc/portage/package.use:"
165     eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}"
166     eerror
167     die "Conflicting USE flags found"
168     fi
169     }
170    
171     # ========================================================================
172     # phpconfutils_use_depend_all()
173     #
174     # Use this function to specify USE flags that depend on eachother,
175     # they will be automatically enabled and used for checks later
176     #
177     # $1 - flag that depends on other flags
178     # $2 .. - the flags that must be set for $1 to be valid
179     #
180    
181     phpconfutils_use_depend_all() {
182     phpconfutils_sort_flags
183    
184     if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
185     return
186     fi
187    
188     local my_flag="$1"
189     shift
190    
191     local my_missing=""
192    
193     while [[ "$1+" != "+" ]] ; do
194     if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
195     my_missing="${my_missing} $1"
196     fi
197     shift
198     done
199    
200     if [[ -n "${my_missing}" ]] ; then
201     PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_missing}"
202     ewarn
203     ewarn "USE flag '${my_flag}' needs these additional flag(s) set:"
204     ewarn " ${my_missing}"
205     ewarn
206     ewarn "'${my_missing}' was automatically enabled and the required extensions will be"
207     ewarn "built. In any case it is recommended to enable those flags for"
208     ewarn "future reference, by adding the following to /etc/portage/package.use:"
209     ewarn " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
210     ewarn
211     fi
212     }
213    
214     # ========================================================================
215     # phpconfutils_use_depend_any()
216     #
217     # Use this function to automatically complain to the user if a USE flag
218     # depends on another USE flag that hasn't been enabled
219     #
220     # $1 - flag that depends on other flags
221     # $2 - flag that is used as default if none is enabled
222     # $3 .. - flags that must be set for $1 to be valid
223     #
224    
225     phpconfutils_use_depend_any() {
226     phpconfutils_sort_flags
227    
228     if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
229     return
230     fi
231    
232     local my_flag="$1"
233     shift
234    
235     local my_default_flag="$1"
236     shift
237    
238     local my_found=""
239     local my_missing=""
240    
241     while [[ "$1+" != "+" ]] ; do
242     if useq "$1" || phpconfutils_usecheck "$1" ; then
243     my_found="${my_found} $1"
244     else
245     my_missing="${my_missing} $1"
246     fi
247     shift
248     done
249    
250     if [[ -z "${my_found}" ]] ; then
251     PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_default_flag}"
252     ewarn
253     ewarn "USE flag '${my_flag}' needs one of these additional flag(s) set:"
254     ewarn " ${my_missing}"
255     ewarn
256     ewarn "'${my_default_flag}' was automatically selected and enabled."
257     ewarn "You can change that by enabling/disabling those flags accordingly"
258     ewarn "in /etc/portage/package.use."
259     ewarn
260     fi
261     }
262    
263     # ========================================================================
264     # phpconfutils_extension_disable()
265     #
266     # Use this function to disable an extension that is enabled by default.
267     # This is provided for those rare configure scripts that don't support
268     # a --enable for the corresponding --disable
269     #
270     # $1 - extension name
271     # $2 - USE flag
272     # $3 - optional message to einfo() to the user
273     #
274    
275     phpconfutils_extension_disable() {
276     if ! useq "$2" && ! phpconfutils_usecheck "$2" ; then
277     my_conf="${my_conf} --disable-$1"
278     [[ -n "$3" ]] && einfo " Disabling $1"
279     else
280     [[ -n "$3" ]] && einfo " Enabling $1"
281     fi
282     }
283    
284     # ========================================================================
285     # phpconfutils_extension_enable()
286     #
287     # This function is like use_enable(), except that it knows about
288     # enabling modules as shared libraries, and it supports passing
289     # additional data with the switch
290     #
291     # $1 - extension name
292     # $2 - USE flag
293     # $3 - 1 = support shared, 0 = never support shared
294     # $4 - additional setting for configure
295     # $5 - additional message to einfo out to the user
296     #
297    
298     phpconfutils_extension_enable() {
299     local my_shared
300    
301     if [[ "$3" == "1" ]] ; then
302     if [[ "${shared}+" != "+" ]] ; then
303     my_shared="${shared}"
304     if [[ "$4+" != "+" ]] ; then
305     my_shared="${my_shared},$4"
306     fi
307     elif [[ "$4+" != "+" ]] ; then
308     my_shared="=$4"
309     fi
310     else
311     if [[ "$4+" != "+" ]] ; then
312     my_shared="=$4"
313     fi
314     fi
315    
316     if useq "$2" || phpconfutils_usecheck "$2" ; then
317     my_conf="${my_conf} --enable-$1${my_shared}"
318     einfo " Enabling $1"
319     else
320     my_conf="${my_conf} --disable-$1"
321     einfo " Disabling $1"
322     fi
323     }
324    
325     # ========================================================================
326     # phpconfutils_extension_without()
327     #
328     # Use this function to disable an extension that is enabled by default
329     # This function is provided for those rare configure scripts that support
330     # --without but not the corresponding --with
331     #
332     # $1 - extension name
333     # $2 - USE flag
334     # $3 - optional message to einfo() to the user
335     #
336    
337     phpconfutils_extension_without() {
338     if ! useq "$2" && ! phpconfutils_usecheck "$2" ; then
339     my_conf="${my_conf} --without-$1"
340     einfo " Disabling $1"
341     else
342     einfo " Enabling $1"
343     fi
344     }
345    
346     # ========================================================================
347     # phpconfutils_extension_with()
348     #
349     # This function is a replacement for use_with. It supports building
350     # extensions as shared libraries,
351     #
352     # $1 - extension name
353     # $2 - USE flag
354     # $3 - 1 = support shared, 0 = never support shared
355     # $4 - additional setting for configure
356     # $5 - optional message to einfo() out to the user
357     #
358    
359     phpconfutils_extension_with() {
360     local my_shared
361    
362     if [[ "$3" == "1" ]] ; then
363     if [[ "${shared}+" != "+" ]] ; then
364     my_shared="${shared}"
365     if [[ "$4+" != "+" ]] ; then
366     my_shared="${my_shared},$4"
367     fi
368     elif [[ "$4+" != "+" ]] ; then
369     my_shared="=$4"
370     fi
371     else
372     if [[ "$4+" != "+" ]] ; then
373     my_shared="=$4"
374     fi
375     fi
376    
377     if useq "$2" || phpconfutils_usecheck "$2" ; then
378     my_conf="${my_conf} --with-$1${my_shared}"
379     einfo " Enabling $1"
380     else
381     my_conf="${my_conf} --without-$1"
382     einfo " Disabling $1"
383     fi
384     }
385    
386     # ========================================================================
387     # phpconfutils_warn_about_external_deps()
388     #
389     # This will output a warning to the user if he enables commercial or other
390     # software not currently present in Portage
391     #
392    
393     phpconfutils_warn_about_external_deps() {
394     phpconfutils_sort_flags
395    
396     local x
397     local my_found="0"
398    
399     for x in ${CONFUTILS_MISSING_DEPS} ; do
400     if useq "${x}" || phpconfutils_usecheck "${x}" ; then
401 chtekk 1.2 ewarn "USE flag ${x} enables support for software not present in Portage!"
402 chtekk 1.1 my_found="1"
403     fi
404     done
405    
406     if [[ "${my_found}" == "1" ]] ; then
407     ewarn
408     ewarn "This ebuild will continue, but if you haven't already installed the"
409     ewarn "software required to satisfy the list above, this package will probably"
410     ewarn "fail to compile later on."
411 chtekk 1.2 ewarn "*DO NOT* file bugs about compile failures or issues you're having"
412     ewarn "when using one of those flags, as we aren't able to support them."
413     ewarn "|=|=|=|=|=|=| You are on your own if you use them! |=|=|=|=|=|=|"
414 chtekk 1.1 ewarn
415     sleep 5
416     fi
417     }
418    
419     # ========================================================================
420     # phpconfutils_built_with_use()
421     #
422     # Sobstitute for built_with_use() to support the magically enabled USE flags
423     #
424    
425     phpconfutils_built_with_use() {
426     local opt="$1"
427     [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
428    
429     local PHP_PKG=$(best_version $1)
430     shift
431    
432     local PHP_USEFILE="${ROOT}/var/lib/php-pkg/${PHP_PKG}/PHP_USEFILE"
433    
434     [[ ! -e "${PHP_USEFILE}" ]] && return 0
435    
436     local PHP_USE_BUILT=$(<${PHP_USEFILE})
437     while [[ $# -gt 0 ]] ; do
438     if [[ ${opt} = "-o" ]] ; then
439     has $1 ${PHP_USE_BUILT} && return 0
440     else
441     has $1 ${PHP_USE_BUILT} || return 1
442     fi
443     shift
444     done
445     [[ ${opt} = "-a" ]]
446     }
447    
448     # ========================================================================
449     # phpconfutils_generate_usefile()
450     #
451     # Generate the file used by phpconfutils_built_with_use() to check it's
452     # USE flags
453     #
454    
455     phpconfutils_generate_usefile() {
456     phpconfutils_sort_flags
457    
458     local PHP_USEFILE="${D}/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/PHP_USEFILE"
459    
460     # Write the auto-enabled USEs into the correct file
461     dodir "/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/"
462     echo "${PHPCONFUTILS_AUTO_USE}" > "${PHP_USEFILE}"
463     }

  ViewVC Help
Powered by ViewVC 1.1.20