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

Contents of /eclass/phpconfutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations) (download)
Fri Mar 24 23:05:49 2006 UTC (8 years, 4 months ago) by chtekk
Branch: MAIN
Use phpconfutils, fix bug #120088, fix bug #122379.

1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4 #
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 local success="0"
97
98 while [[ -n "$1" ]] ; do
99 if useq "$1" ; then
100 einfo "${success_msg} $1"
101 success="1"
102 else
103 ewarn "${fail_msg} $1"
104 fi
105 shift
106 done
107
108 # Did we find what we are looking for?
109 if [[ "${success}" == "1" ]] ; then
110 return
111 fi
112
113 # If we get here, then none of the required USE flags were enabled
114 eerror
115 eerror "You *must* enable one or more of the following USE flags:"
116 eerror " ${required_flags}"
117 eerror
118 eerror "You can do this by enabling these flags in /etc/portage/package.use:"
119 eerror " =${CATEGORY}/${PN}-${PVR} ${required_flags}"
120 eerror
121 die "Missing USE flags found"
122 }
123
124 # ========================================================================
125 # phpconfutils_use_conflict()
126 #
127 # Use this function to automatically complain to the user if USE flags
128 # that directly conflict have been enabled
129 #
130 # $1 - flag that conflicts with other flags
131 # $2 .. - flags that conflict
132 #
133
134 phpconfutils_use_conflict() {
135 phpconfutils_sort_flags
136
137 if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
138 return
139 fi
140
141 local my_flag="$1"
142 shift
143
144 local my_present=""
145 local my_remove=""
146
147 while [[ "$1+" != "+" ]] ; do
148 if useq "$1" || phpconfutils_usecheck "$1" ; then
149 my_present="${my_present} $1"
150 my_remove="${my_remove} -$1"
151 fi
152 shift
153 done
154
155 if [[ -n "${my_present}" ]] ; then
156 eerror
157 eerror "USE flag '${my_flag}' conflicts with these USE flag(s):"
158 eerror " ${my_present}"
159 eerror
160 eerror "You must disable these conflicting flags before you can emerge this package."
161 eerror "You can do this by disabling these flags in /etc/portage/package.use:"
162 eerror " =${CATEGORY}/${PN}-${PVR} ${my_remove}"
163 eerror
164 die "Conflicting USE flags found"
165 fi
166 }
167
168 # ========================================================================
169 # phpconfutils_use_depend_all()
170 #
171 # Use this function to specify USE flags that depend on eachother,
172 # they will be automatically enabled and used for checks later
173 #
174 # $1 - flag that depends on other flags
175 # $2 .. - the flags that must be set for $1 to be valid
176 #
177
178 phpconfutils_use_depend_all() {
179 phpconfutils_sort_flags
180
181 if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
182 return
183 fi
184
185 local my_flag="$1"
186 shift
187
188 local my_missing=""
189
190 while [[ "$1+" != "+" ]] ; do
191 if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
192 my_missing="${my_missing} $1"
193 fi
194 shift
195 done
196
197 if [[ -n "${my_missing}" ]] ; then
198 PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_missing}"
199 ewarn
200 ewarn "USE flag '${my_flag}' needs these additional flag(s) set:"
201 ewarn " ${my_missing}"
202 ewarn
203 ewarn "'${my_missing}' was automatically enabled and the required extensions will be"
204 ewarn "built. In any case it is recommended to enable those flags for"
205 ewarn "future reference, by adding the following to /etc/portage/package.use:"
206 ewarn " =${CATEGORY}/${PN}-${PVR} ${my_missing}"
207 ewarn
208 fi
209 }
210
211 # ========================================================================
212 # phpconfutils_use_depend_any()
213 #
214 # Use this function to automatically complain to the user if a USE flag
215 # depends on another USE flag that hasn't been enabled
216 #
217 # $1 - flag that depends on other flags
218 # $2 - flag that is used as default if none is enabled
219 # $3 .. - flags that must be set for $1 to be valid
220 #
221
222 phpconfutils_use_depend_any() {
223 phpconfutils_sort_flags
224
225 if ! useq "$1" && ! phpconfutils_usecheck "$1" ; then
226 return
227 fi
228
229 local my_flag="$1"
230 shift
231
232 local my_default_flag="$1"
233 shift
234
235 local my_found=""
236 local my_missing=""
237
238 while [[ "$1+" != "+" ]] ; do
239 if useq "$1" || phpconfutils_usecheck "$1" ; then
240 my_found="${my_found} $1"
241 else
242 my_missing="${my_missing} $1"
243 fi
244 shift
245 done
246
247 if [[ -z "${my_found}" ]] ; then
248 PHPCONFUTILS_AUTO_USE="${PHPCONFUTILS_AUTO_USE} ${my_default_flag}"
249 ewarn
250 ewarn "USE flag '${my_flag}' needs one of these additional flag(s) set:"
251 ewarn " ${my_missing}"
252 ewarn
253 ewarn "'${my_default_flag}' was automatically selected and enabled."
254 ewarn "You can change that by enabling/disabling those flags accordingly"
255 ewarn "in /etc/portage/package.use."
256 ewarn
257 fi
258 }
259
260 # ========================================================================
261 # phpconfutils_extension_disable()
262 #
263 # Use this function to disable an extension that is enabled by default.
264 # This is provided for those rare configure scripts that don't support
265 # a --enable for the corresponding --disable
266 #
267 # $1 - extension name
268 # $2 - USE flag
269 # $3 - optional message to einfo() to the user
270 #
271
272 phpconfutils_extension_disable() {
273 if ! useq "$2" && ! phpconfutils_usecheck "$2" ; then
274 my_conf="${my_conf} --disable-$1"
275 [[ -n "$3" ]] && einfo " Disabling $1"
276 else
277 [[ -n "$3" ]] && einfo " Enabling $1"
278 fi
279 }
280
281 # ========================================================================
282 # phpconfutils_extension_enable()
283 #
284 # This function is like use_enable(), except that it knows about
285 # enabling modules as shared libraries, and it supports passing
286 # additional data with the switch
287 #
288 # $1 - extension name
289 # $2 - USE flag
290 # $3 - 1 = support shared, 0 = never support shared
291 # $4 - additional setting for configure
292 # $5 - additional message to einfo out to the user
293 #
294
295 phpconfutils_extension_enable() {
296 local my_shared
297
298 if [[ "$3" == "1" ]] ; then
299 if [[ "${shared}+" != "+" ]] ; then
300 my_shared="${shared}"
301 if [[ "$4+" != "+" ]] ; then
302 my_shared="${my_shared},$4"
303 fi
304 elif [[ "$4+" != "+" ]] ; then
305 my_shared="=$4"
306 fi
307 else
308 if [[ "$4+" != "+" ]] ; then
309 my_shared="=$4"
310 fi
311 fi
312
313 if useq "$2" || phpconfutils_usecheck "$2" ; then
314 my_conf="${my_conf} --enable-$1${my_shared}"
315 einfo " Enabling $1"
316 else
317 my_conf="${my_conf} --disable-$1"
318 einfo " Disabling $1"
319 fi
320 }
321
322 # ========================================================================
323 # phpconfutils_extension_without()
324 #
325 # Use this function to disable an extension that is enabled by default
326 # This function is provided for those rare configure scripts that support
327 # --without but not the corresponding --with
328 #
329 # $1 - extension name
330 # $2 - USE flag
331 # $3 - optional message to einfo() to the user
332 #
333
334 phpconfutils_extension_without() {
335 if ! useq "$2" && ! phpconfutils_usecheck "$2" ; then
336 my_conf="${my_conf} --without-$1"
337 einfo " Disabling $1"
338 else
339 einfo " Enabling $1"
340 fi
341 }
342
343 # ========================================================================
344 # phpconfutils_extension_with()
345 #
346 # This function is a replacement for use_with. It supports building
347 # extensions as shared libraries,
348 #
349 # $1 - extension name
350 # $2 - USE flag
351 # $3 - 1 = support shared, 0 = never support shared
352 # $4 - additional setting for configure
353 # $5 - optional message to einfo() out to the user
354 #
355
356 phpconfutils_extension_with() {
357 local my_shared
358
359 if [[ "$3" == "1" ]] ; then
360 if [[ "${shared}+" != "+" ]] ; then
361 my_shared="${shared}"
362 if [[ "$4+" != "+" ]] ; then
363 my_shared="${my_shared},$4"
364 fi
365 elif [[ "$4+" != "+" ]] ; then
366 my_shared="=$4"
367 fi
368 else
369 if [[ "$4+" != "+" ]] ; then
370 my_shared="=$4"
371 fi
372 fi
373
374 if useq "$2" || phpconfutils_usecheck "$2" ; then
375 my_conf="${my_conf} --with-$1${my_shared}"
376 einfo " Enabling $1"
377 else
378 my_conf="${my_conf} --without-$1"
379 einfo " Disabling $1"
380 fi
381 }
382
383 # ========================================================================
384 # phpconfutils_warn_about_external_deps()
385 #
386 # This will output a warning to the user if he enables commercial or other
387 # software not currently present in Portage
388 #
389
390 phpconfutils_warn_about_external_deps() {
391 phpconfutils_sort_flags
392
393 local x
394 local my_found="0"
395
396 for x in ${CONFUTILS_MISSING_DEPS} ; do
397 if useq "${x}" || phpconfutils_usecheck "${x}" ; then
398 ewarn "USE flag ${x} enables support for software not present in Portage"
399 my_found="1"
400 fi
401 done
402
403 if [[ "${my_found}" == "1" ]] ; then
404 ewarn
405 ewarn "This ebuild will continue, but if you haven't already installed the"
406 ewarn "software required to satisfy the list above, this package will probably"
407 ewarn "fail to compile later on."
408 ewarn
409 sleep 5
410 fi
411 }
412
413 # ========================================================================
414 # phpconfutils_built_with_use()
415 #
416 # Sobstitute for built_with_use() to support the magically enabled USE flags
417 #
418
419 phpconfutils_built_with_use() {
420 local opt="$1"
421 [[ ${opt:0:1} = "-" ]] && shift || opt="-a"
422
423 local PHP_PKG=$(best_version $1)
424 shift
425
426 local PHP_USEFILE="${ROOT}/var/lib/php-pkg/${PHP_PKG}/PHP_USEFILE"
427
428 [[ ! -e "${PHP_USEFILE}" ]] && return 0
429
430 local PHP_USE_BUILT=$(<${PHP_USEFILE})
431 while [[ $# -gt 0 ]] ; do
432 if [[ ${opt} = "-o" ]] ; then
433 has $1 ${PHP_USE_BUILT} && return 0
434 else
435 has $1 ${PHP_USE_BUILT} || return 1
436 fi
437 shift
438 done
439 [[ ${opt} = "-a" ]]
440 }
441
442 # ========================================================================
443 # phpconfutils_generate_usefile()
444 #
445 # Generate the file used by phpconfutils_built_with_use() to check it's
446 # USE flags
447 #
448
449 phpconfutils_generate_usefile() {
450 phpconfutils_sort_flags
451
452 local PHP_USEFILE="${D}/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/PHP_USEFILE"
453
454 # Write the auto-enabled USEs into the correct file
455 dodir "/var/lib/php-pkg/${CATEGORY}/${PN}-${PVR}/"
456 echo "${PHPCONFUTILS_AUTO_USE}" > "${PHP_USEFILE}"
457 }

  ViewVC Help
Powered by ViewVC 1.1.20