1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: php-ext-source-r2.eclass
7 # Gentoo PHP team <php-bugs@gentoo.org>
9 # Author: Tal Peer <coredumb@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 # Author: Ole Markus With <olemarkus@gentoo.org>
14 # @BLURB: A unified interface for compiling and installing standalone PHP extensions.
16 # This eclass provides a unified interface for compiling and installing standalone
17 # PHP extensions (modules).
19 inherit flag-o-matic autotools multilib eutils
21 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
23 DEPEND=">=sys-devel/m4-1.4.3
24 >=sys-devel/libtool-1.5.18"
27 # Because of USE deps, we require at least EAPI 2
31 die "php-ext-source-r2 is not compatible with EAPI=${EAPI}"
34 # @ECLASS-VARIABLE: PHP_EXT_NAME
37 # The extension name. This must be set, otherwise the eclass dies.
38 # Only automagically set by php-ext-pecl-r2.eclass, so unless your ebuild
39 # inherits that eclass, you must set this manually before inherit.
40 [[ -z "${PHP_EXT_NAME}" ]] && die "No module name specified for the php-ext-source-r2 eclass"
42 # @ECLASS-VARIABLE: PHP_EXT_INI
44 # Controls whether or not to add a line to php.ini for the extension.
45 # Defaults to "yes" and should not be changed in most cases.
46 [[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes"
48 # @ECLASS-VARIABLE: PHP_EXT_ZENDEXT
50 # Controls whether the extension is a ZendEngine extension or not.
51 # Defaults to "no" and if you don't know what is it, you don't need it.
52 [[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no"
54 # @ECLASS-VARIABLE: USE_PHP
57 # Lists the PHP slots compatibile the extension is compatibile with
60 # USE_PHP="php5-5 php5-6"
62 [[ -z "${USE_PHP}" ]] && die "USE_PHP is not set for the php-ext-source-r2 eclass"
64 # @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE
66 # If set, this is the USE flag that the PHP dependencies are behind
67 # Most commonly set as PHP_EXT_OPTIONAL_USE=php to get the dependencies behind
70 # @ECLASS-VARIABLE: PHP_EXT_S
72 # The relative location of the temporary build directory for the PHP extension within
73 # the source package. This is useful for packages that bundle the PHP extension.
75 [[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}"
77 #Make sure at least one target is installed.
78 REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( "
79 for target in ${USE_PHP}; do
80 IUSE="${IUSE} php_targets_${target}"
82 REQUIRED_USE+="php_targets_${target} "
85 PHPDEPEND="${PHPDEPEND}
86 php_targets_${target}? ( dev-lang/php:${slot} )"
88 REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}"
91 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
93 ${PHP_EXT_OPTIONAL_USE:+ )}"
96 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
98 ${PHP_EXT_OPTIONAL_USE:+ )}
101 # @FUNCTION: php-ext-source-r2_src_unpack
103 # runs standard src_unpack + _phpize
105 # @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE
107 # phpize will be run by default for all ebuilds that use
108 # php-ext-source-r2_src_unpack
109 # Set PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run phpize.
111 php-ext-source-r2_src_unpack() {
113 local slot orig_s="${PHP_EXT_S}"
114 for slot in $(php_get_slots); do
115 cp -r "${orig_s}" "${WORKDIR}/${slot}" || die "Failed to copy source ${orig_s} to PHP target directory"
119 php-ext-source-r2_src_prepare() {
120 local slot orig_s="${PHP_EXT_S}"
121 for slot in $(php_get_slots); do
122 php_init_slot_env ${slot}
123 php-ext-source-r2_phpize
127 # @FUNCTION: php-ext-source-r2_phpize
129 # Runs phpize and autotools in addition to the standard src_unpack
130 php-ext-source-r2_phpize() {
131 if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
132 # Create configure out of config.m4. We use autotools_run_tool
133 # to avoid some warnings about WANT_AUTOCONF and
134 # WANT_AUTOMAKE (see bugs #329071 and #549268).
135 autotools_run_tool ${PHPIZE}
136 # force run of libtoolize and regeneration of related autotools
143 # @FUNCTION: php-ext-source-r2_src_configure
145 # Takes care of standard configure for PHP extensions (modules).
147 # @ECLASS-VARIABLE: my_conf
149 # Set this in the ebuild to pass configure options to econf.
151 php-ext-source-r2_src_configure() {
152 # net-snmp creates this file #385403
153 addpredict /usr/share/snmp/mibs/.index
154 addpredict /var/lib/net-snmp/mib_indexes
157 for slot in $(php_get_slots); do
158 php_init_slot_env ${slot}
159 # Set the correct config options
160 econf --with-php-config=${PHPCONFIG} ${my_conf} || die "Unable to configure code to compile"
164 # @FUNCTION: php-ext-source-r2_src_compile
166 # Takes care of standard compile for PHP extensions (modules).
167 php-ext-source-r2_src_compile() {
168 # net-snmp creates this file #324739
169 addpredict /usr/share/snmp/mibs/.index
170 addpredict /var/lib/net-snmp/mib_indexes
172 # shm extension createss a semaphore file #173574
173 addpredict /session_mm_cli0.sem
175 for slot in $(php_get_slots); do
176 php_init_slot_env ${slot}
177 emake || die "Unable to make code"
182 # @FUNCTION: php-ext-source-r2_src_install
184 # Takes care of standard install for PHP extensions (modules).
186 # @ECLASS-VARIABLE: DOCS
188 # Set in ebuild if you wish to install additional, package-specific documentation.
189 php-ext-source-r2_src_install() {
191 for slot in $(php_get_slots); do
192 php_init_slot_env ${slot}
194 # Let's put the default module away. Strip $EPREFIX from
195 # $EXT_DIR before calling newins (which handles EPREFIX itself).
196 insinto "${EXT_DIR#$EPREFIX}"
197 newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so" || die "Unable to install extension"
200 for doc in ${DOCS} ; do
201 [[ -s ${doc} ]] && dodoc ${doc}
204 INSTALL_ROOT="${D}" emake install-headers
206 php-ext-source-r2_createinifiles
212 for slot in ${USE_PHP}; do
213 use php_targets_${slot} && s+=" ${slot/-/.}"
218 php_init_slot_env() {
221 PHPIZE="${EPREFIX}/usr/${libdir}/${1}/bin/phpize"
222 PHPCONFIG="${EPREFIX}/usr/${libdir}/${1}/bin/php-config"
223 PHPCLI="${EPREFIX}/usr/${libdir}/${1}/bin/php"
224 PHPCGI="${EPREFIX}/usr/${libdir}/${1}/bin/php-cgi"
225 PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
226 PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}"
227 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
228 PHP_CURRENTSLOT=${1:3}
230 PHP_EXT_S="${WORKDIR}/${1}"
234 php-ext-source-r2_buildinilist() {
235 # Work out the list of <ext>.ini files to edit/add to
236 if [[ -z "${PHPSAPILIST}" ]] ; then
237 PHPSAPILIST="apache2 cli cgi fpm embed phpdbg"
242 for x in ${PHPSAPILIST} ; do
243 if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then
244 PHPINIFILELIST="${PHPINIFILELIST} etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
247 PHPFULLINIFILELIST="${PHPFULLINIFILELIST} ${PHPINIFILELIST}"
250 # @FUNCTION: php-ext-source-r2_createinifiles
252 # Builds ini files for every enabled slot and SAPI
253 php-ext-source-r2_createinifiles() {
255 for slot in $(php_get_slots); do
256 php_init_slot_env ${slot}
257 # Pull in the PHP settings
259 # Build the list of <ext>.ini files to edit/add to
260 php-ext-source-r2_buildinilist ${slot}
263 # Add the needed lines to the <ext>.ini files
265 if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
266 for file in ${PHPINIFILELIST}; do
267 php-ext-source-r2_addextension "${PHP_EXT_NAME}.so" "${file}"
271 # Symlink the <ext>.ini files from ext/ to ext-active/
273 for inifile in ${PHPINIFILELIST} ; do
274 if [[ -n "${PHP_EXT_INIFILE}" ]]; then
275 cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${inifile}"
276 einfo "Added content of ${FILESDIR}/${PHP_EXT_INIFILE} to ${inifile}"
278 inidir="${inifile/${PHP_EXT_NAME}.ini/}"
279 inidir="${inidir/ext/ext-active}"
281 dosym "/${inifile}" "/${inifile/ext/ext-active}"
284 # Add support for installing PHP files into a version dependant directory
285 PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}"
289 php-ext-source-r2_addextension() {
290 if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
291 # We need the full path for ZendEngine extensions
292 # and we need to check for debugging enabled!
293 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[threads]" ; then
294 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]" ; then
295 ext_type="zend_extension_debug_ts"
297 ext_type="zend_extension_ts"
299 ext_file="${EXT_DIR}/${1}"
301 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]"; then
302 ext_type="zend_extension_debug"
304 ext_type="zend_extension"
306 ext_file="${EXT_DIR}/${1}"
309 # php-5.3 unifies zend_extension loading and just requires the
310 # zend_extension keyword with no suffix
311 # TODO: drop previous code and this check once <php-5.3 support is
313 if has_version '>=dev-lang/php-5.3' ; then
314 ext_type="zend_extension"
317 # We don't need the full path for normal extensions!
322 php-ext-source-r2_addtoinifile "${ext_type}" "${ext_file}" "${2}" "Extension added"
327 # $3 - File to add to
328 # $4 - Sanitized text to output
329 php-ext-source-r2_addtoinifile() {
330 local inifile="${WORKDIR}/${3}"
331 if [[ ! -d $(dirname ${inifile}) ]] ; then
332 mkdir -p $(dirname ${inifile})
335 # Are we adding the name of a section?
336 if [[ ${1:0:1} == "[" ]] ; then
337 echo "${1}" >> "${inifile}"
340 echo "${1}=${2}" >> "${inifile}"
344 if [[ -z "${4}" ]] ; then
345 einfo "Added '${my_added}' to /${3}"
347 einfo "${4} to /${3}"
350 insinto /$(dirname ${3})
354 # @FUNCTION: php-ext-source-r2_addtoinifiles
355 # @USAGE: <setting name> <setting value> [message to output]; or just [section name]
357 # Add value settings to php.ini file installed by the extension (module).
358 # You can also add a [section], see examples below.
361 # Add some settings for the extension:
363 # php-ext-source-r2_addtoinifiles "zend_optimizer.optimization_level" "15"
364 # php-ext-source-r2_addtoinifiles "zend_optimizer.enable_loader" "0"
365 # php-ext-source-r2_addtoinifiles "zend_optimizer.disable_licensing" "0"
367 # Adding values to a section in php.ini file installed by the extension:
369 # php-ext-source-r2_addtoinifiles "[Debugger]"
370 # php-ext-source-r2_addtoinifiles "debugger.enabled" "on"
371 # php-ext-source-r2_addtoinifiles "debugger.profiler_enabled" "on"
373 php-ext-source-r2_addtoinifiles() {
375 for x in ${PHPFULLINIFILELIST} ; do
376 php-ext-source-r2_addtoinifile "${1}" "${2}" "${x}" "${3}"