1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: php-ext-source-r2.eclass
6 # Gentoo PHP team <php-bugs@gentoo.org>
8 # Author: Tal Peer <coredumb@gentoo.org>
9 # Author: Stuart Herbert <stuart@gentoo.org>
10 # Author: Luca Longinotti <chtekk@gentoo.org>
11 # Author: Jakub Moc <jakub@gentoo.org> (documentation)
12 # Author: Ole Markus With <olemarkus@gentoo.org>
13 # @BLURB: A unified interface for compiling and installing standalone PHP extensions.
15 # This eclass provides a unified interface for compiling and installing standalone
16 # PHP extensions (modules).
18 inherit flag-o-matic autotools multilib eutils
20 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
22 DEPEND=">=sys-devel/m4-1.4.3
23 >=sys-devel/libtool-1.5.18"
26 # Because of USE deps, we require at least EAPI 2
30 die "php-ext-source-r2 is not compatible with EAPI=${EAPI}"
33 # @ECLASS-VARIABLE: PHP_EXT_NAME
36 # The extension name. This must be set, otherwise the eclass dies.
37 # Only automagically set by php-ext-pecl-r2.eclass, so unless your ebuild
38 # inherits that eclass, you must set this manually before inherit.
39 [[ -z "${PHP_EXT_NAME}" ]] && die "No module name specified for the php-ext-source-r2 eclass"
41 # @ECLASS-VARIABLE: PHP_EXT_INI
43 # Controls whether or not to add a line to php.ini for the extension.
44 # Defaults to "yes" and should not be changed in most cases.
45 [[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes"
47 # @ECLASS-VARIABLE: PHP_EXT_ZENDEXT
49 # Controls whether the extension is a ZendEngine extension or not.
50 # Defaults to "no" and if you don't know what is it, you don't need it.
51 [[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no"
53 # @ECLASS-VARIABLE: USE_PHP
56 # Lists the PHP slots compatibile the extension is compatibile with
59 # USE_PHP="php5-5 php5-6"
61 [[ -z "${USE_PHP}" ]] && die "USE_PHP is not set for the php-ext-source-r2 eclass"
63 # @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE
65 # If set, this is the USE flag that the PHP dependencies are behind
66 # Most commonly set as PHP_EXT_OPTIONAL_USE=php to get the dependencies behind
69 # @ECLASS-VARIABLE: PHP_EXT_S
71 # The relative location of the temporary build directory for the PHP extension within
72 # the source package. This is useful for packages that bundle the PHP extension.
74 [[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}"
76 #Make sure at least one target is installed.
77 REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( "
78 for target in ${USE_PHP}; do
79 IUSE="${IUSE} php_targets_${target}"
81 REQUIRED_USE+="php_targets_${target} "
84 PHPDEPEND="${PHPDEPEND}
85 php_targets_${target}? ( dev-lang/php:${slot} )"
87 REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}"
90 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
92 ${PHP_EXT_OPTIONAL_USE:+ )}"
95 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
97 ${PHP_EXT_OPTIONAL_USE:+ )}
100 # @FUNCTION: php-ext-source-r2_src_unpack
102 # runs standard src_unpack + _phpize
104 # @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE
106 # phpize will be run by default for all ebuilds that use
107 # php-ext-source-r2_src_unpack
108 # Set PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run phpize.
110 php-ext-source-r2_src_unpack() {
112 local slot orig_s="${PHP_EXT_S}"
113 for slot in $(php_get_slots); do
114 cp -r "${orig_s}" "${WORKDIR}/${slot}" || die "Failed to copy source ${orig_s} to PHP target directory"
118 php-ext-source-r2_src_prepare() {
119 local slot orig_s="${PHP_EXT_S}"
120 for slot in $(php_get_slots); do
121 php_init_slot_env ${slot}
122 php-ext-source-r2_phpize
126 # @FUNCTION: php-ext-source-r2_phpize
128 # Runs phpize and autotools in addition to the standard src_unpack
129 php-ext-source-r2_phpize() {
130 if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
131 # Create configure out of config.m4. We use autotools_run_tool
132 # to avoid some warnings about WANT_AUTOCONF and
133 # WANT_AUTOMAKE (see bugs #329071 and #549268).
134 autotools_run_tool ${PHPIZE}
135 # force run of libtoolize and regeneration of related autotools
142 # @FUNCTION: php-ext-source-r2_src_configure
144 # Takes care of standard configure for PHP extensions (modules).
146 # @ECLASS-VARIABLE: my_conf
148 # Set this in the ebuild to pass configure options to econf.
150 php-ext-source-r2_src_configure() {
151 # net-snmp creates this file #385403
152 addpredict /usr/share/snmp/mibs/.index
153 addpredict /var/lib/net-snmp/mib_indexes
156 for slot in $(php_get_slots); do
157 php_init_slot_env ${slot}
158 # Set the correct config options
159 econf --with-php-config=${PHPCONFIG} ${my_conf} || die "Unable to configure code to compile"
163 # @FUNCTION: php-ext-source-r2_src_compile
165 # Takes care of standard compile for PHP extensions (modules).
166 php-ext-source-r2_src_compile() {
167 # net-snmp creates this file #324739
168 addpredict /usr/share/snmp/mibs/.index
169 addpredict /var/lib/net-snmp/mib_indexes
171 # shm extension createss a semaphore file #173574
172 addpredict /session_mm_cli0.sem
174 for slot in $(php_get_slots); do
175 php_init_slot_env ${slot}
176 emake || die "Unable to make code"
181 # @FUNCTION: php-ext-source-r2_src_install
183 # Takes care of standard install for PHP extensions (modules).
185 # @ECLASS-VARIABLE: DOCS
187 # Set in ebuild if you wish to install additional, package-specific documentation.
188 php-ext-source-r2_src_install() {
190 for slot in $(php_get_slots); do
191 php_init_slot_env ${slot}
193 # Let's put the default module away. Strip $EPREFIX from
194 # $EXT_DIR before calling newins (which handles EPREFIX itself).
195 insinto "${EXT_DIR#$EPREFIX}"
196 newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so" || die "Unable to install extension"
199 for doc in ${DOCS} ; do
200 [[ -s ${doc} ]] && dodoc ${doc}
203 INSTALL_ROOT="${D}" emake install-headers
205 php-ext-source-r2_createinifiles
211 for slot in ${USE_PHP}; do
212 use php_targets_${slot} && s+=" ${slot/-/.}"
217 php_init_slot_env() {
220 PHPIZE="${EPREFIX}/usr/${libdir}/${1}/bin/phpize"
221 PHPCONFIG="${EPREFIX}/usr/${libdir}/${1}/bin/php-config"
222 PHPCLI="${EPREFIX}/usr/${libdir}/${1}/bin/php"
223 PHPCGI="${EPREFIX}/usr/${libdir}/${1}/bin/php-cgi"
224 PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
225 PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}"
226 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
227 PHP_CURRENTSLOT=${1:3}
229 PHP_EXT_S="${WORKDIR}/${1}"
233 php-ext-source-r2_buildinilist() {
234 # Work out the list of <ext>.ini files to edit/add to
235 if [[ -z "${PHPSAPILIST}" ]] ; then
236 PHPSAPILIST="apache2 cli cgi fpm embed phpdbg"
241 for x in ${PHPSAPILIST} ; do
242 if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then
243 PHPINIFILELIST="${PHPINIFILELIST} etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
246 PHPFULLINIFILELIST="${PHPFULLINIFILELIST} ${PHPINIFILELIST}"
249 # @FUNCTION: php-ext-source-r2_createinifiles
251 # Builds ini files for every enabled slot and SAPI
252 php-ext-source-r2_createinifiles() {
254 for slot in $(php_get_slots); do
255 php_init_slot_env ${slot}
256 # Pull in the PHP settings
258 # Build the list of <ext>.ini files to edit/add to
259 php-ext-source-r2_buildinilist ${slot}
262 # Add the needed lines to the <ext>.ini files
264 if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
265 for file in ${PHPINIFILELIST}; do
266 php-ext-source-r2_addextension "${PHP_EXT_NAME}.so" "${file}"
270 # Symlink the <ext>.ini files from ext/ to ext-active/
272 for inifile in ${PHPINIFILELIST} ; do
273 if [[ -n "${PHP_EXT_INIFILE}" ]]; then
274 cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${inifile}"
275 einfo "Added content of ${FILESDIR}/${PHP_EXT_INIFILE} to ${inifile}"
277 inidir="${inifile/${PHP_EXT_NAME}.ini/}"
278 inidir="${inidir/ext/ext-active}"
280 dosym "/${inifile}" "/${inifile/ext/ext-active}"
283 # Add support for installing PHP files into a version dependant directory
284 PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}"
288 php-ext-source-r2_addextension() {
289 if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
290 # We need the full path for ZendEngine extensions
291 # and we need to check for debugging enabled!
292 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[threads]" ; then
293 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]" ; then
294 ext_type="zend_extension_debug_ts"
296 ext_type="zend_extension_ts"
298 ext_file="${EXT_DIR}/${1}"
300 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]"; then
301 ext_type="zend_extension_debug"
303 ext_type="zend_extension"
305 ext_file="${EXT_DIR}/${1}"
308 # php-5.3 unifies zend_extension loading and just requires the
309 # zend_extension keyword with no suffix
310 # TODO: drop previous code and this check once <php-5.3 support is
312 if has_version '>=dev-lang/php-5.3' ; then
313 ext_type="zend_extension"
316 # We don't need the full path for normal extensions!
321 php-ext-source-r2_addtoinifile "${ext_type}" "${ext_file}" "${2}" "Extension added"
326 # $3 - File to add to
327 # $4 - Sanitized text to output
328 php-ext-source-r2_addtoinifile() {
329 local inifile="${WORKDIR}/${3}"
330 if [[ ! -d $(dirname ${inifile}) ]] ; then
331 mkdir -p $(dirname ${inifile})
334 # Are we adding the name of a section?
335 if [[ ${1:0:1} == "[" ]] ; then
336 echo "${1}" >> "${inifile}"
339 echo "${1}=${2}" >> "${inifile}"
343 if [[ -z "${4}" ]] ; then
344 einfo "Added '${my_added}' to /${3}"
346 einfo "${4} to /${3}"
349 insinto /$(dirname ${3})
353 # @FUNCTION: php-ext-source-r2_addtoinifiles
354 # @USAGE: <setting name> <setting value> [message to output]; or just [section name]
356 # Add value settings to php.ini file installed by the extension (module).
357 # You can also add a [section], see examples below.
360 # Add some settings for the extension:
362 # php-ext-source-r2_addtoinifiles "zend_optimizer.optimization_level" "15"
363 # php-ext-source-r2_addtoinifiles "zend_optimizer.enable_loader" "0"
364 # php-ext-source-r2_addtoinifiles "zend_optimizer.disable_licensing" "0"
366 # Adding values to a section in php.ini file installed by the extension:
368 # php-ext-source-r2_addtoinifiles "[Debugger]"
369 # php-ext-source-r2_addtoinifiles "debugger.enabled" "on"
370 # php-ext-source-r2_addtoinifiles "debugger.profiler_enabled" "on"
372 php-ext-source-r2_addtoinifiles() {
374 for x in ${PHPFULLINIFILELIST} ; do
375 php-ext-source-r2_addtoinifile "${1}" "${2}" "${x}" "${3}"