/[gentoo-x86]/eclass/depend.php.eclass
Gentoo

Contents of /eclass/depend.php.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.30 - (show annotations) (download)
Mon Aug 22 04:46:31 2011 UTC (3 years, 3 months ago) by vapier
Branch: MAIN
Changes since 1.29: +6 -7 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/depend.php.eclass,v 1.29 2011/03/18 15:59:25 olemarkus Exp $
4
5 # @ECLASS: depend.php.eclass
6 # @MAINTAINER:
7 # Gentoo PHP team <php-bugs@gentoo.org>
8 # @AUTHOR:
9 # Author: Stuart Herbert <stuart@gentoo.org>
10 # Author: Luca Longinotti <chtekk@gentoo.org>
11 # Author: Jakub Moc <jakub@gentoo.org> (documentation)
12 # @BLURB: Functions to allow ebuilds to depend on php5 and check for specific features.
13 # @DESCRIPTION:
14 # This eclass provides functions that allow ebuilds to depend on php5 and check
15 # for specific PHP features, SAPIs etc. Also provides dodoc-php wrapper to install
16 # documentation for PHP packages to php-specific location.
17
18 inherit eutils phpconfutils
19
20 # PHP5-only depend functions
21
22 # @FUNCTION: need_php5_cli
23 # @DESCRIPTION:
24 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP5
25 # with cli SAPI.
26 need_php5_cli() {
27 DEPEND="${DEPEND} =dev-lang/php-5*"
28 RDEPEND="${RDEPEND} =dev-lang/php-5*"
29 PHP_VERSION="5"
30 }
31
32 # @FUNCTION: need_php5_httpd
33 # @DESCRIPTION:
34 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP5
35 # with either cgi or apache2 SAPI.
36 need_php5_httpd() {
37 DEPEND="${DEPEND} =virtual/httpd-php-5*"
38 RDEPEND="${RDEPEND} =virtual/httpd-php-5*"
39 PHP_VERSION="5"
40 }
41
42 # @FUNCTION: need_php5
43 # @DESCRIPTION:
44 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP5
45 # (with any SAPI).
46 need_php5() {
47 DEPEND="${DEPEND} =dev-lang/php-5*"
48 RDEPEND="${RDEPEND} =dev-lang/php-5*"
49 PHP_VERSION="5"
50 PHP_SHARED_CAT="php5"
51 }
52
53 # common settings go in here
54 uses_php5() {
55 # cache this
56 libdir=$(get_libdir)
57
58 PHPIZE="/usr/${libdir}/php5/bin/phpize"
59 PHPCONFIG="/usr/${libdir}/php5/bin/php-config"
60 PHPCLI="/usr/${libdir}/php5/bin/php"
61 PHPCGI="/usr/${libdir}/php5/bin/php-cgi"
62 PHP_PKG="$(best_version =dev-lang/php-5*)"
63 PHPPREFIX="/usr/${libdir}/php5"
64 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
65
66 einfo
67 einfo "Using ${PHP_PKG}"
68 einfo
69 }
70
71 # general PHP depend functions
72
73 # @FUNCTION: need_php_cli
74 # @DESCRIPTION:
75 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP
76 # (any version) with cli SAPI.
77 need_php_cli() {
78 DEPEND="${DEPEND} dev-lang/php"
79 RDEPEND="${RDEPEND} dev-lang/php"
80 }
81
82 # @FUNCTION: need_php_httpd
83 # @DESCRIPTION:
84 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP
85 # (any version) with either cgi or apache2 SAPI.
86 need_php_httpd() {
87 DEPEND="${DEPEND} virtual/httpd-php"
88 RDEPEND="${RDEPEND} virtual/httpd-php"
89 }
90
91 # @FUNCTION: need_php
92 # @DESCRIPTION:
93 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP
94 # (any version with any SAPI).
95 need_php() {
96 DEPEND="${DEPEND} dev-lang/php"
97 RDEPEND="${RDEPEND} dev-lang/php"
98 PHP_SHARED_CAT="php"
99 }
100
101 # @FUNCTION: need_php_by_category
102 # @DESCRIPTION:
103 # Set this after setting DEPEND/RDEPEND in your ebuild to depend on PHP version
104 # determined by ${CATEGORY} - any PHP version or PHP5 for dev-php or
105 # dev-php5, respectively.
106 need_php_by_category() {
107 case "${CATEGORY}" in
108 dev-php) need_php ;;
109 dev-php5) need_php5 ;;
110 *) die "Version of PHP required by packages in category ${CATEGORY} unknown"
111 esac
112 }
113
114
115 # @FUNCTION: has_php
116 # @DESCRIPTION:
117 # Call this function from your pkg_setup, src_compile, src_install etc. if you
118 # need to know which PHP version is being used and where the PHP binaries/data
119 # are installed.
120 has_php() {
121 # Detect which PHP version we have installed
122 if has_version '=dev-lang/php-5*' ; then
123 PHP_VERSION="5"
124 else
125 die "Unable to find an installed dev-lang/php package"
126 fi
127
128 # If we get here, then PHP_VERSION tells us which version of PHP we
129 # want to use
130 uses_php${PHP_VERSION}
131 }
132
133 # @FUNCTION: require_php_sapi_from
134 # @USAGE: <list of SAPIs>
135 # @DESCRIPTION:
136 # Call this function from pkg_setup if your package only works with
137 # specific SAPI(s) and specify a list of PHP SAPI USE flags that are
138 # required (one or more from cli, cgi, apache2) as arguments.
139 # Returns if any of the listed SAPIs have been installed, dies if none
140 # of them is available.
141 #
142 # Unfortunately, if you want to be really sure that the required SAPI is
143 # provided by PHP, you will have to use this function or similar ones (like
144 # require_php_cli or require_php_cgi) in pkg_setup until we are able to
145 # depend on USE flags being enabled. The above described need_php[45]_cli
146 # and need_php[45]_httpd functions cannot guarantee these requirements.
147 # See Bug 2272 for details.
148 require_php_sapi_from() {
149 has_php
150
151 local has_sapi="0"
152 local x
153
154 einfo "Checking for compatible SAPI(s)"
155
156 for x in $@ ; do
157 if built_with_use =${PHP_PKG} ${x} || phpconfutils_built_with_use =${PHP_PKG} ${x} ; then
158 einfo " Discovered compatible SAPI ${x}"
159 has_sapi="1"
160 fi
161 done
162
163 if [[ "${has_sapi}" == "1" ]] ; then
164 return
165 fi
166
167 eerror
168 eerror "${PHP_PKG} needs to be re-installed with one of the following"
169 eerror "USE flags enabled:"
170 eerror
171 eerror " $@"
172 eerror
173 die "No compatible PHP SAPIs found"
174 }
175
176 # @FUNCTION: require_php_with_use
177 # @USAGE: <list of USE flags>
178 # @DESCRIPTION:
179 # Call this function from pkg_setup if your package requires PHP compiled
180 # with specific USE flags. Returns if all of the listed USE flags are enabled.
181 # Dies if any of the listed USE flags are disabled.
182
183 # @VARIABLE: PHPCHECKNODIE
184 # @DESCRIPTION:
185 # You can set PHPCHECKNODIE to non-empty value in your ebuild to chain multiple
186 # require_php_with_(any)_use checks without making the ebuild die on every failure.
187 # This is useful in cases when certain PHP features are only required if specific
188 # USE flag(s) are enabled for that ebuild.
189 # @CODE
190 # Example:
191 #
192 # local flags="pcre session snmp sockets wddx"
193 # use mysql && flags="${flags} mysql"
194 # use postgres && flags="${flags} postgres"
195 # if ! PHPCHECKNODIE="yes" require_php_with_use ${flags} \
196 # || ! PHPCHECKNODIE="yes" require_php_with_any_use gd gd-external ; then
197 # die "Re-install ${PHP_PKG} with ${flags} and either gd or gd-external"
198 # fi
199 # @CODE
200 require_php_with_use() {
201 has_php
202
203 local missing_use=""
204 local x
205
206 einfo "Checking for required PHP feature(s) ..."
207
208 for x in $@ ; do
209 case $x in
210 pcre|spl|reflection|mhash)
211 eqawarn "require_php_with_use MUST NOT check for the pcre, spl, mhash or reflection USE flag."
212 eqawarn "These USE flags are removed from >=dev-lang/php-5.3 and your ebuild will break"
213 eqawarn "if you check the USE flags against PHP 5.3 ebuilds."
214 eqawarn "Please use USE dependencies from EAPI 2 instead"
215 ;;
216 esac
217
218 if ! built_with_use =${PHP_PKG} ${x} && ! phpconfutils_built_with_use =${PHP_PKG} ${x} ; then
219 einfo " Discovered missing USE flag: ${x}"
220 missing_use="${missing_use} ${x}"
221 fi
222 done
223
224 if [[ -z "${missing_use}" ]] ; then
225 if [[ -z "${PHPCHECKNODIE}" ]] ; then
226 return
227 else
228 return 0
229 fi
230 fi
231
232 if [[ -z "${PHPCHECKNODIE}" ]] ; then
233 eerror
234 eerror "${PHP_PKG} needs to be re-installed with all of the following"
235 eerror "USE flags enabled:"
236 eerror
237 eerror " $@"
238 eerror
239 die "Missing PHP USE flags found"
240 else
241 return 1
242 fi
243 }
244
245 # @FUNCTION: require_php_with_any_use
246 # @USAGE: <list of USE flags>
247 # @DESCRIPTION:
248 # Call this function from pkg_setup if your package requires PHP compiled with
249 # any of specified USE flags. Returns if any of the listed USE flags are enabled.
250 # Dies if all of the listed USE flags are disabled.
251 require_php_with_any_use() {
252 has_php
253
254 local missing_use=""
255 local x
256
257 einfo "Checking for required PHP feature(s) ..."
258
259 for x in $@ ; do
260 if built_with_use =${PHP_PKG} ${x} || phpconfutils_built_with_use =${PHP_PKG} ${x} ; then
261 einfo " USE flag ${x} is enabled, ok ..."
262 return
263 else
264 missing_use="${missing_use} ${x}"
265 fi
266 done
267
268 if [[ -z "${missing_use}" ]] ; then
269 if [[ -z "${PHPCHECKNODIE}" ]] ; then
270 return
271 else
272 return 0
273 fi
274 fi
275
276 if [[ -z "${PHPCHECKNODIE}" ]] ; then
277 eerror
278 eerror "${PHP_PKG} needs to be re-installed with any of the following"
279 eerror "USE flags enabled:"
280 eerror
281 eerror " $@"
282 eerror
283 die "Missing PHP USE flags found"
284 else
285 return 1
286 fi
287 }
288
289 # ========================================================================
290 # has_*() functions
291 #
292 # These functions return 0 if the condition is satisfied, 1 otherwise
293 # ========================================================================
294
295 # @FUNCTION: has_zts
296 # @DESCRIPTION:
297 # Check if our PHP was compiled with ZTS (Zend Thread Safety) enabled.
298 # @RETURN: 0 if true, 1 otherwise
299 has_zts() {
300 has_php
301
302 if built_with_use =${PHP_PKG} apache2 threads || phpconfutils_built_with_use =${PHP_PKG} apache2 threads ; then
303 return 0
304 fi
305
306 return 1
307 }
308
309 # @FUNCTION: has_debug
310 # @DESCRIPTION:
311 # Check if our PHP was built with debug support enabled.
312 # @RETURN: 0 if true, 1 otherwise
313 has_debug() {
314 has_php
315
316 if built_with_use =${PHP_PKG} debug || phpconfutils_built_with_use =${PHP_PKG} debug ; then
317 return 0
318 fi
319
320 return 1
321 }
322
323 # @FUNCTION: has_concurrentmodphp
324 # @DESCRIPTION:
325 # Check if our PHP was built with the concurrentmodphp support enabled.
326 # @RETURN: 0 if true, 1 otherwise
327 has_concurrentmodphp() {
328 has_php
329
330 if built_with_use =${PHP_PKG} apache2 concurrentmodphp || phpconfutils_built_with_use =${PHP_PKG} apache2 concurrentmodphp ; then
331 return 0
332 fi
333
334 return 1
335 }
336
337 # ========================================================================
338 # require_*() functions
339 #
340 # These functions die() if PHP was built without the required features
341 # ========================================================================
342
343 # @FUNCTION: require_pdo
344 # @DESCRIPTION:
345 # Require a PHP built with PDO support (PHP5 only).
346 # This function is now redundant and DEPRECATED since
347 # pdo-external use flag and pecl-pdo-* ebuilds were removed.
348 # You should use require_php_with_use pdo instead now.
349 # @RETURN: die if feature is missing
350 require_pdo() {
351 has_php
352
353 # Was PHP5 compiled with internal PDO support?
354 if built_with_use =${PHP_PKG} pdo || phpconfutils_built_with_use =${PHP_PKG} pdo ; then
355 return
356 else
357 eerror
358 eerror "No PDO extension for PHP found."
359 eerror "Please note that PDO only exists for PHP 5."
360 eerror "Please install a PDO extension for PHP 5."
361 eerror "You must install >=dev-lang/php-5.1 with USE=\"pdo\"."
362 eerror
363 die "No PDO extension for PHP 5 found"
364 fi
365 }
366
367 # @FUNCTION: require_php_cli
368 # @DESCRIPTION:
369 # Determines which installed PHP version has the CLI SAPI enabled.
370 # Useful for PEAR stuff, or anything which needs to run PHP script
371 # depending on the CLI SAPI.
372 # @RETURN: die if feature is missing
373 require_php_cli() {
374 # If PHP_PKG is set, then we have remembered our PHP settings
375 # from last time
376 if [[ -n ${PHP_PKG} ]] ; then
377 return
378 fi
379
380 local PHP_PACKAGE_FOUND=""
381
382 if has_version '=dev-lang/php-5*' ; then
383 PHP_PACKAGE_FOUND="1"
384 pkg="$(best_version '=dev-lang/php-5*')"
385 if built_with_use =${pkg} cli || phpconfutils_built_with_use =${pkg} cli ; then
386 PHP_VERSION="5"
387 fi
388 fi
389
390 if [[ -z ${PHP_PACKAGE_FOUND} ]] ; then
391 die "Unable to find an installed dev-lang/php package"
392 fi
393
394 if [[ -z ${PHP_VERSION} ]] ; then
395 die "No PHP CLI installed. Re-emerge dev-lang/php with USE=cli."
396 fi
397
398 # If we get here, then PHP_VERSION tells us which version of PHP we
399 # want to use
400 uses_php${PHP_VERSION}
401 }
402
403 # @FUNCTION: require_php_cgi
404 # @DESCRIPTION:
405 # Determines which installed PHP version has the CGI SAPI enabled.
406 # Useful for anything which needs to run PHP scripts depending on the CGI SAPI.
407 # @RETURN: die if feature is missing
408 require_php_cgi() {
409 # If PHP_PKG is set, then we have remembered our PHP settings
410 # from last time
411 if [[ -n ${PHP_PKG} ]] ; then
412 return
413 fi
414
415 local PHP_PACKAGE_FOUND=""
416
417 if has_version '=dev-lang/php-5*' ; then
418 PHP_PACKAGE_FOUND="1"
419 pkg="$(best_version '=dev-lang/php-5*')"
420 if built_with_use =${pkg} cgi || phpconfutils_built_with_use =${pkg} cgi ; then
421 PHP_VERSION="5"
422 fi
423 fi
424
425 if [[ -z ${PHP_PACKAGE_FOUND} ]] ; then
426 die "Unable to find an installed dev-lang/php package"
427 fi
428
429 if [[ -z ${PHP_VERSION} ]] ; then
430 die "No PHP CGI installed. Re-emerge dev-lang/php with USE=cgi."
431 fi
432
433 # If we get here, then PHP_VERSION tells us which version of PHP we
434 # want to use
435 uses_php${PHP_VERSION}
436 }
437
438 # @FUNCTION: require_sqlite
439 # @DESCRIPTION:
440 # Require a PHP built with SQLite support
441 # @RETURN: die if feature is missing
442 require_sqlite() {
443 has_php
444
445 # Has our PHP been built with SQLite support?
446 if built_with_use =${PHP_PKG} sqlite || phpconfutils_built_with_use =${PHP_PKG} sqlite ; then
447 return
448 fi
449
450 # If we get here, then we don't have any SQLite support for PHP installed
451 eerror
452 eerror "No SQLite extension for PHP found."
453 eerror "Please install an SQLite extension for PHP,"
454 eerror "this is done best by simply adding the"
455 eerror "'sqlite' USE flag when emerging dev-lang/php."
456 eerror
457 die "No SQLite extension for PHP found"
458 }
459
460 # @FUNCTION: require_gd
461 # @DESCRIPTION:
462 # Require a PHP built with GD support
463 # @RETURN: die if feature is missing
464 require_gd() {
465 has_php
466
467 # Do we have the internal GD support installed?
468 if built_with_use =${PHP_PKG} gd || phpconfutils_built_with_use =${PHP_PKG} gd ; then
469 return
470 fi
471
472 # Ok, maybe GD was built using the external library support?
473 if built_with_use =${PHP_PKG} gd-external || phpconfutils_built_with_use =${PHP_PKG} gd-external ; then
474 return
475 fi
476
477 # If we get here, then we have no GD support
478 eerror
479 eerror "No GD support for PHP found."
480 eerror "Please install the GD support for PHP,"
481 eerror "you must install dev-lang/php with either"
482 eerror "the 'gd' or the 'gd-external' USE flags"
483 eerror "turned on."
484 eerror
485 die "No GD support found for PHP"
486 }
487
488 # ========================================================================
489 # Misc functions
490 #
491 # These functions provide miscellaneous checks and functionality.
492 # ========================================================================
493
494 # @FUNCTION: php_binary_extension
495 # @DESCRIPTION:
496 # Executes some checks needed when installing a binary PHP extension.
497 php_binary_extension() {
498 has_php
499
500 local PUSE_ENABLED=""
501
502 # Binary extensions do not support the change of PHP
503 # API version, so they can't be installed when USE flags
504 # are enabled which change the PHP API version, they also
505 # don't provide correctly versioned symbols for our use
506
507 if has_debug ; then
508 eerror
509 eerror "You cannot install binary PHP extensions"
510 eerror "when the 'debug' USE flag is enabled!"
511 eerror "Please reemerge dev-lang/php with the"
512 eerror "'debug' USE flag turned off."
513 eerror
514 PUSE_ENABLED="1"
515 fi
516
517 if has_concurrentmodphp ; then
518 eerror
519 eerror "You cannot install binary PHP extensions when"
520 eerror "the 'concurrentmodphp' USE flag is enabled!"
521 eerror "Please reemerge dev-lang/php with the"
522 eerror "'concurrentmodphp' USE flag turned off."
523 eerror
524 PUSE_ENABLED="1"
525 fi
526
527 if [[ -n ${PUSE_ENABLED} ]] ; then
528 die "'debug' and/or 'concurrentmodphp' USE flags turned on!"
529 fi
530 }
531
532 # @FUNCTION: dodoc-php
533 # @USAGE: <list of docs>
534 # @DESCRIPTION:
535 # Alternative to dodoc function for use in our PHP eclasses and ebuilds.
536 # Stored here because depend.php gets always sourced everywhere in the PHP
537 # ebuilds and eclasses. It simply is dodoc with a changed path to the docs.
538 # NOTE: No support for docinto is provided!
539 dodoc-php() {
540 if [[ $# -lt 1 ]] ; then
541 echo "$0: at least one argument needed" 1>&2
542 exit 1
543 fi
544
545 phpdocdir="/usr/share/doc/${CATEGORY}/${PF}/"
546
547 for x in $@ ; do
548 if [[ -s "${x}" ]] ; then
549 insinto "${phpdocdir}"
550 doins "${x}"
551 gzip -f -9 "${D}/${phpdocdir}/${x##*/}"
552 elif [[ ! -e "${x}" ]] ; then
553 echo "dodoc-php: ${x} does not exist" 1>&2
554 fi
555 done
556 }
557
558 # @FUNCTION: dohtml-php
559 # @USAGE: <list of html docs>
560 # @DESCRIPTION:
561 # Alternative to dohtml function for use in our PHP eclasses and ebuilds.
562 # Stored here because depend.php gets always sourced everywhere in the PHP
563 # ebuilds and eclasses. It simply is dohtml with a changed path to the docs.
564 # NOTE: No support for [-a|-A|-p|-x] options is provided!
565 dohtml-php() {
566 if [[ $# -lt 1 ]] ; then
567 echo "$0: at least one argument needed" 1>&2
568 exit 1
569 fi
570
571 phphtmldir="/usr/share/doc/${CATEGORY}/${PF}/html"
572
573 for x in $@ ; do
574 if [[ -s "${x}" ]] ; then
575 insinto "${phphtmldir}"
576 doins "${x}"
577 elif [[ ! -e "${x}" ]] ; then
578 echo "dohtml-php: ${x} does not exist" 1>&2
579 fi
580 done
581 }

  ViewVC Help
Powered by ViewVC 1.1.20