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

Contents of /eclass/phpconfutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations) (download)
Mon Aug 22 04:46:32 2011 UTC (3 years ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +5 -10 lines
fix random bugs in eclass documentation, and convert to new @AUTHOR tag

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

  ViewVC Help
Powered by ViewVC 1.1.20