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

Contents of /eclass/depend.php.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Sat Sep 1 15:58:17 2007 UTC (6 years, 7 months ago) by jokey
Branch: MAIN
Changes since 1.20: +148 -65 lines
Bunch of php eclass docification

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

  ViewVC Help
Powered by ViewVC 1.1.20