1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 # @ECLASS: depend.php.eclass
8 # Gentoo PHP team <php-bugs@gentoo.org>
10 # Author: Stuart Herbert <stuart@gentoo.org>
11 # Author: Luca Longinotti <chtekk@gentoo.org>
12 # Author: Jakub Moc <jakub@gentoo.org> (documentation)
13 # @BLURB: Functions to allow ebuilds to depend on php5 and check for specific features.
15 # This eclass provides functions that allow ebuilds to depend on php5 and check
16 # for specific PHP features, SAPIs etc. Also provides dodoc-php wrapper to install
17 # documentation for PHP packages to php-specific location.
18 # This eclass is deprecated and is set to be removed 30 days after bug 552836 is resolved
20 inherit eutils multilib
22 # PHP5-only depend functions
24 # @FUNCTION: need_php5
26 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP5
29 DEPEND="${DEPEND} =dev-lang/php-5*"
30 RDEPEND="${RDEPEND} =dev-lang/php-5*"
35 # common settings go in here
40 PHPIZE="/usr/${libdir}/php5/bin/phpize"
41 PHPCONFIG="/usr/${libdir}/php5/bin/php-config"
42 PHPCLI="/usr/${libdir}/php5/bin/php"
43 PHPCGI="/usr/${libdir}/php5/bin/php-cgi"
44 PHP_PKG="$(best_version =dev-lang/php-5*)"
45 PHPPREFIX="/usr/${libdir}/php5"
46 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
49 einfo "Using ${PHP_PKG}"
53 # general PHP depend functions
55 # @FUNCTION: need_php_httpd
57 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP
58 # (any version) with either cgi or apache2 SAPI.
60 DEPEND="${DEPEND} virtual/httpd-php"
61 RDEPEND="${RDEPEND} virtual/httpd-php"
66 # Set this after setting DEPEND/RDEPEND in your ebuild if the ebuild requires PHP
67 # (any version with any SAPI).
69 DEPEND="${DEPEND} dev-lang/php"
70 RDEPEND="${RDEPEND} dev-lang/php"
76 # Call this function from your pkg_setup, src_compile, src_install etc. if you
77 # need to know which PHP version is being used and where the PHP binaries/data
80 # Detect which PHP version we have installed
81 if has_version '=dev-lang/php-5*' ; then
84 die "Unable to find an installed dev-lang/php package"
87 # If we get here, then PHP_VERSION tells us which version of PHP we
89 uses_php${PHP_VERSION}
92 # @FUNCTION: require_php_with_use
93 # @USAGE: <list of USE flags>
95 # Call this function from pkg_setup if your package requires PHP compiled
96 # with specific USE flags. Returns if all of the listed USE flags are enabled.
97 # Dies if any of the listed USE flags are disabled.
99 # @VARIABLE: PHPCHECKNODIE
101 # You can set PHPCHECKNODIE to non-empty value in your ebuild to chain multiple
102 # require_php_with_(any)_use checks without making the ebuild die on every failure.
103 # This is useful in cases when certain PHP features are only required if specific
104 # USE flag(s) are enabled for that ebuild.
108 # local flags="pcre session snmp sockets wddx"
109 # use mysql && flags="${flags} mysql"
110 # use postgres && flags="${flags} postgres"
111 # if ! PHPCHECKNODIE="yes" require_php_with_use ${flags} \
112 # || ! PHPCHECKNODIE="yes" require_php_with_any_use gd gd-external ; then
113 # die "Re-install ${PHP_PKG} with ${flags} and either gd or gd-external"
116 require_php_with_use() {
122 einfo "Checking for required PHP feature(s) ..."
126 pcre|spl|reflection|mhash)
127 eqawarn "require_php_with_use MUST NOT check for the pcre, spl, mhash or reflection USE flag."
128 eqawarn "These USE flags are removed from >=dev-lang/php-5.3 and your ebuild will break"
129 eqawarn "if you check the USE flags against PHP 5.3 ebuilds."
130 eqawarn "Please use USE dependencies from EAPI 2 instead"
134 if ! built_with_use =${PHP_PKG} ${x} ; then
135 einfo " Discovered missing USE flag: ${x}"
136 missing_use="${missing_use} ${x}"
140 if [[ -z "${missing_use}" ]] ; then
141 if [[ -z "${PHPCHECKNODIE}" ]] ; then
148 if [[ -z "${PHPCHECKNODIE}" ]] ; then
150 eerror "${PHP_PKG} needs to be re-installed with all of the following"
151 eerror "USE flags enabled:"
155 die "Missing PHP USE flags found"
162 # ========================================================================
163 # require_*() functions
165 # These functions die() if PHP was built without the required features
166 # ========================================================================
168 # @FUNCTION: require_php_cgi
170 # Determines which installed PHP version has the CGI SAPI enabled.
171 # Useful for anything which needs to run PHP scripts depending on the CGI SAPI.
172 # @RETURN: die if feature is missing
174 # If PHP_PKG is set, then we have remembered our PHP settings
176 if [[ -n ${PHP_PKG} ]] ; then
180 local PHP_PACKAGE_FOUND=""
182 if has_version '=dev-lang/php-5*' ; then
183 PHP_PACKAGE_FOUND="1"
184 pkg="$(best_version '=dev-lang/php-5*')"
185 if built_with_use =${pkg} cgi ; then
190 if [[ -z ${PHP_PACKAGE_FOUND} ]] ; then
191 die "Unable to find an installed dev-lang/php package"
194 if [[ -z ${PHP_VERSION} ]] ; then
195 die "No PHP CGI installed. Re-emerge dev-lang/php with USE=cgi."
198 # If we get here, then PHP_VERSION tells us which version of PHP we
200 uses_php${PHP_VERSION}
203 # ========================================================================
206 # These functions provide miscellaneous checks and functionality.
207 # ========================================================================
209 # @FUNCTION: dodoc-php
210 # @USAGE: <list of docs>
212 # Alternative to dodoc function for use in our PHP eclasses and ebuilds.
213 # Stored here because depend.php gets always sourced everywhere in the PHP
214 # ebuilds and eclasses. It simply is dodoc with a changed path to the docs.
215 # NOTE: No support for docinto is provided!
217 if [[ $# -lt 1 ]] ; then
218 echo "$0: at least one argument needed" 1>&2
222 phpdocdir="/usr/share/doc/${CATEGORY}/${PF}/"
225 if [[ -s "${x}" ]] ; then
226 insinto "${phpdocdir}"
228 gzip -f -9 "${D}/${phpdocdir}/${x##*/}"
229 elif [[ ! -e "${x}" ]] ; then
230 echo "dodoc-php: ${x} does not exist" 1>&2
235 # @FUNCTION: dohtml-php
236 # @USAGE: <list of html docs>
238 # Alternative to dohtml function for use in our PHP eclasses and ebuilds.
239 # Stored here because depend.php gets always sourced everywhere in the PHP
240 # ebuilds and eclasses. It simply is dohtml with a changed path to the docs.
241 # NOTE: No support for [-a|-A|-p|-x] options is provided!
243 if [[ $# -lt 1 ]] ; then
244 echo "$0: at least one argument needed" 1>&2
248 phphtmldir="/usr/share/doc/${CATEGORY}/${PF}/html"
251 if [[ -s "${x}" ]] ; then
252 insinto "${phphtmldir}"
254 elif [[ ! -e "${x}" ]] ; then
255 echo "dohtml-php: ${x} does not exist" 1>&2