# Copyright 1999-2016 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ # @ECLASS: php-ext-source-r3.eclass # @MAINTAINER: # Gentoo PHP team # @BLURB: # A unified interface for compiling and installing standalone PHP # extensions. # @DESCRIPTION: # A unified interface for compiling and installing standalone PHP # extensions. inherit autotools EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install DEPEND=">=sys-devel/m4-1.4.3 >=sys-devel/libtool-1.5.18" RDEPEND="" case ${EAPI} in 6) ;; *) die "php-ext-source-r3 is not compatible with EAPI=${EAPI}" esac # @ECLASS-VARIABLE: PHP_EXT_NAME # @REQUIRED # @DESCRIPTION: # The extension name. This must be set, otherwise the eclass dies. # Only automagically set by php-ext-pecl-r3.eclass, so unless your ebuild # inherits that eclass, you must set this manually before inherit. [[ -z "${PHP_EXT_NAME}" ]] && \ die "no extension name specified for the php-ext-source-r3 eclass" # @ECLASS-VARIABLE: PHP_EXT_INI # @DESCRIPTION: # Controls whether or not to add a line to php.ini for the extension. # Defaults to "yes" and should not be changed in most cases. [[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes" # @ECLASS-VARIABLE: PHP_EXT_ZENDEXT # @DESCRIPTION: # Controls whether the extension is a ZendEngine extension or not. # Defaults to "no". If you don't know what this is, you don't need it. [[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no" # @ECLASS-VARIABLE: USE_PHP # @REQUIRED # @DESCRIPTION: # Lists the PHP slots compatibile the extension is compatibile with # Example: # @CODE # USE_PHP="php5-6 php7-0" # @CODE [[ -z "${USE_PHP}" ]] && \ die "USE_PHP is not set for the php-ext-source-r3 eclass" # @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE # @DESCRIPTION: # If set, all of the dependencies added by this eclass will be # conditional on USE=${PHP_EXT_OPTIONAL_USE}. This is needed when # ebuilds have to inherit this eclass unconditionally, but only # actually use it when (for example) the user has USE=php. # @ECLASS-VARIABLE: PHP_EXT_S # @DESCRIPTION: # The relative location of the temporary build directory for the PHP # extension within the source package. This is useful for packages that # bundle the PHP extension. Defaults to ${S}. [[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}" # @ECLASS-VARIABLE: PHP_EXT_SAPIS # @DESCRIPTION: # A list of SAPIs for which we'll install this extension. Formerly # called PHPSAPILIST. [[ -z "${PHP_EXT_SAPIS}" ]] && PHP_EXT_SAPIS="apache2 cli cgi fpm embed phpdbg" # Make sure at least one target is installed. First, start a USE # conditional like "php?", but only when PHP_EXT_OPTIONAL_USE is # non-null. The option group "|| (..." is always started here. REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( " for target in ${USE_PHP}; do # Now loop through each USE_PHP target and add the corresponding # dev-lang/php slot to PHPDEPEND. IUSE="${IUSE} php_targets_${target}" # Strip "+" characters from USE_PHP??? # target=${target/+} REQUIRED_USE+="php_targets_${target} " slot=${target/php} slot=${slot/-/.} PHPDEPEND="${PHPDEPEND} php_targets_${target}? ( dev-lang/php:${slot} )" done # Finally, end the optional group that we started before the loop. Close # the USE-conditional if PHP_EXT_OPTIONAL_USE is non-null. REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}" RDEPEND="${RDEPEND} ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( } ${PHPDEPEND} ${PHP_EXT_OPTIONAL_USE:+ )}" DEPEND="${DEPEND} ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( } ${PHPDEPEND} ${PHP_EXT_OPTIONAL_USE:+ )} " # @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE # @DESCRIPTION: # phpize will be run by default for all ebuilds that use # php-ext-source-r3_src_unpack # Set PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run # phpize and autoreconf. # @FUNCTION: php-ext-source-r3_src_unpack # @DESCRIPTION: # Runs the default src_unpack and then makes a copy for each PHP slot. php-ext-source-r3_src_unpack() { default_src_unpack local slot orig_s="${PHP_EXT_S}" for slot in $(php_get_slots); do cp -r "${orig_s}" "${WORKDIR}/${slot}" || \ die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}" done } # @FUNCTION: php-ext-source-r3_src_prepare # @DESCRIPTION: # Runs php-ext-source-r3_phpize for each PHP slot. php-ext-source-r3_src_prepare() { for slot in $(php_get_slots); do php_init_slot_env "${slot}" php-ext-source-r3_phpize done } # @FUNCTION: php-ext-source-r3_phpize # @DESCRIPTION: # Runs eapply_user, phpize, and then autoreconf in a manner that avoids # warnings. php-ext-source-r3_phpize() { eapply_user if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then # Create configure out of config.m4. We use autotools_run_tool # to avoid some warnings about WANT_AUTOCONF and # WANT_AUTOMAKE (see bugs #329071 and #549268). autotools_run_tool "${PHPIZE}" # Force libtoolize to run and regenerate autotools files (bug # #220519). rm aclocal.m4 || die "failed to remove aclocal.m4" eautoreconf fi } # @ECLASS-VARIABLE: PHP_EXT_EXTRA_ECONF # @DESCRIPTION: # Set this in the ebuild to pass configure options to econf. Formerly # called my_conf. # @FUNCTION: php-ext-source-r3_src_configure # @DESCRIPTION: # Takes care of standard configure for PHP extensions (modules). php-ext-source-r3_src_configure() { # net-snmp creates these, bug #385403. addpredict /usr/share/snmp/mibs/.index addpredict /var/lib/net-snmp/mib_indexes local slot for slot in $(php_get_slots); do php_init_slot_env "${slot}" # Set the correct config options econf --with-php-config=${PHPCONFIG} ${PHP_EXT_EXTRA_ECONF} done } # @FUNCTION: php-ext-source-r3_src_compile # @DESCRIPTION: # Compile a standard standalone PHP extension. php-ext-source-r3_src_compile() { # net-snmp creates these, bug #324739. addpredict /usr/share/snmp/mibs/.index addpredict /var/lib/net-snmp/mib_indexes # shm extension creates a semaphore file, bug #173574. addpredict /session_mm_cli0.sem local slot for slot in $(php_get_slots); do php_init_slot_env "${slot}" emake done } # @ECLASS-VARIABLE: DOCS # @DESCRIPTION: # Set in ebuild if you wish to install additional, package-specific # documentation. # @FUNCTION: php-ext-source-r3_src_install # @DESCRIPTION: # Install a standard standalone PHP extensions. php-ext-source-r3_src_install() { local slot for slot in $(php_get_slots); do php_init_slot_env "${slot}" # Let's put the default module away. Strip $EPREFIX from # $EXT_DIR before calling newins (which handles EPREFIX itself). insinto "${EXT_DIR#$EPREFIX}" newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so" INSTALL_ROOT="${D}" emake install-headers done einstalldocs php-ext-source-r3_createinifiles } # @FUNCTION: php_get_slots # @DESCRIPTION: # Get a list of PHP slots contained in both the ebuild's USE_PHP and the # user's PHP_TARGETS. php_get_slots() { local s="" local slot for slot in ${USE_PHP}; do use php_targets_${slot} && s+=" ${slot/-/.}" done echo $s } # @FUNCTION: php_init_slot_env # @DESCRIPTION: # Takes a slot name, and initializes some global variables to values # corresponding to that slot. For example, it sets the path to the "php" # and "phpize" binaries, which will differ for each slot. This function # is intended to be called while looping through a list of slots # obtained from php_get_slots(). php_init_slot_env() { local libdir=$(get_libdir) PHPIZE="${EPREFIX}/usr/${libdir}/${1}/bin/phpize" PHPCONFIG="${EPREFIX}/usr/${libdir}/${1}/bin/php-config" PHPCLI="${EPREFIX}/usr/${libdir}/${1}/bin/php" PHPCGI="${EPREFIX}/usr/${libdir}/${1}/bin/php-cgi" PHP_PKG="$(best_version =dev-lang/php-${1:3}*)" PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}" EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)" PHP_CURRENTSLOT=${1:3} PHP_EXT_S="${WORKDIR}/${1}" cd "${PHP_EXT_S}" || die "failed to change directory to ${PHP_EXT_S}" } # @FUNCTION: php_slot_ini_files # @DESCRIPTION: # Output a list of relative paths to INI files for the given # slot. Usually there will be one INI file per SAPI. php_slot_ini_files() { local slot_ini_files="" local x for x in ${PHP_EXT_SAPIS} ; do if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then slot_ini_files+=" etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini" fi done echo "${slot_ini_files}" } # @FUNCTION: php-ext-source-r3_createinifiles # @DESCRIPTION: # Builds INI files for every enabled slot and SAPI. php-ext-source-r3_createinifiles() { local slot for slot in $(php_get_slots); do php_init_slot_env "${slot}" local file for file in $(php_slot_ini_files "${slot}") ; do if [[ "${PHP_EXT_INI}" = "yes" ]] ; then # Add the needed lines to the .ini files php-ext-source-r3_addextension "${PHP_EXT_NAME}.so" "${file}" fi if [[ -n "${PHP_EXT_INIFILE}" ]] ; then cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${file}" einfo "Added contents of ${FILESDIR}/${PHP_EXT_INIFILE}" \ "to ${file}" fi inidir="${file/${PHP_EXT_NAME}.ini/}" inidir="${inidir/ext/ext-active}" dodir "/${inidir}" dosym "/${file}" "/${file/ext/ext-active}" done # Add support for installing PHP files into a version dependent # directory PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}" done } php-ext-source-r3_addextension() { if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then ext_type="zend_extension" ext_file="${EXT_DIR}/${1}" # Zend extensions need the path... else ext_type="extension" ext_file="${1}" fi php-ext-source-r3_addtoinifile "${2}" "${ext_type}" "${ext_file}" } # @FUNCTION: php-ext-source-r3_addtoinifile # @DESCRIPTION: # Add a setting=value to one INI file. The first argument is the # relative path to the INI file. The second argument is the setting # name, and the third argument is its value. # # You can also pass "[Section]" as the first parameter, to create a new # section in the INI file. In that case, the second parameter (which # would otherwise be the value of the setting) is ignored. php-ext-source-r3_addtoinifile() { local inifile="${WORKDIR}/${1}" local inidir="$(dirname ${inifile})" if [[ ! -d "${inidir}" ]] ; then mkdir -p "${inidir}" || die "failed to create INI directory ${inidir}" fi # Are we adding the name of a section? if [[ ${2:0:1} == "[" ]] ; then echo "${2}" >> "${inifile}" my_added="${2}" else echo "${2}=${3}" >> "${inifile}" my_added="${2}=${3}" fi einfo "Added '${my_added}' to /${1}" insinto /$(dirname "${1}") doins "${inifile}" } # @FUNCTION: php-ext-source-r3_addtoinifiles # @USAGE: [message to output]; or just [section name] # @DESCRIPTION: # Add settings to every php.ini file installed by this extension. # You can also add new [Section]s -- see the example below. # # @CODE # Add some settings for the extension: # # php-ext-source-r3_addtoinifiles "zend_optimizer.optimization_level" "15" # php-ext-source-r3_addtoinifiles "zend_optimizer.enable_loader" "0" # php-ext-source-r3_addtoinifiles "zend_optimizer.disable_licensing" "0" # # Adding values to a section in php.ini file installed by the extension: # # php-ext-source-r3_addtoinifiles "[Debugger]" # php-ext-source-r3_addtoinifiles "debugger.enabled" "on" # php-ext-source-r3_addtoinifiles "debugger.profiler_enabled" "on" # @CODE php-ext-source-r3_addtoinifiles() { local slot for slot in $(php_get_slots); do for file in $(php_slot_ini_files "${slot}") ; do php-ext-source-r3_addtoinifile "${file}" "${1}" "${2}" done done }