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

Contents of /eclass/phpconfutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Thu May 10 20:26:45 2007 UTC (7 years, 4 months ago) by chtekk
Branch: MAIN
Changes since 1.4: +2 -2 lines
Fix error msg level.

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

  ViewVC Help
Powered by ViewVC 1.1.20