1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: php-pear-r2.eclass
6 # Gentoo PHP Team <php-bugs@gentoo.org>
8 # Author: Brian Evans <grknight@gentoo.org>
9 # @BLURB: Provides means for an easy installation of PEAR packages.
11 # This eclass provides means for an easy installation of PEAR packages.
12 # For more information on PEAR, see https://pear.php.net/
13 # Note that this eclass doesn't handle dependencies of PEAR packages
14 # on purpose; please use (R)DEPEND to define them correctly!
16 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
22 die "Unsupported EAPI=${EAPI} for ${ECLASS}"
26 RDEPEND=">=dev-php/pear-1.8.1"
28 # @ECLASS-VARIABLE: PHP_PEAR_PKG_NAME
30 # Set this if the PEAR package name differs from ${PN/PEAR-/}
31 # (generally shouldn't be the case).
32 : ${PHP_PEAR_PKG_NAME:=${PN/PEAR-/}}
34 # @ECLASS-VARIABLE: PEAR_PV
36 # Set in ebuild if the ${PV} breaks SRC_URI for alpha/beta/rc versions
39 # @ECLASS-VARIABLE: PEAR-P
41 # @DESCRIPTION: Combines PHP_PEAR_PKG_NAME and PEAR_PV
42 PEAR_P="${PHP_PEAR_PKG_NAME}-${PEAR_PV}"
44 # @ECLASS-VARIABLE: PHP_PEAR_DOMAIN
46 # Set in ebuild to the domain name of the channel if not pear.php.net
47 # When the domain is not pear.php.net, setting the SRC_URI is required
48 : ${PHP_PEAR_DOMAIN:=pear.php.net}
50 # @ECLASS-VARIABLE: PHP_PEAR_CHANNEL
53 # Set in ebuild to the path of channel.xml file which is necessary for
54 # 3rd party pear channels (besides pear.php.net) to be added to PEAR
55 # Default is unset to do nothing
57 # set default SRC_URI for pear.php.net packages
58 if [[ "${PHP_PEAR_DOMAIN}" == "pear.php.net" ]] ; then
59 SRC_URI="https://pear.php.net/get/${PEAR_P}.tgz"
62 : ${HOMEPAGE:=https://${PHP_PEAR_DOMAIN}/package/${PHP_PEAR_PKG_NAME}}
64 S="${WORKDIR}/${PEAR_P}"
66 # @FUNCTION: php-pear-r2_install_packagexml
68 # Copies the package2.xml or package.xml file and, optionally, the channel.xml
69 # file to a Gentoo-specific location so that pkg_postinst can install the package
70 # to the local PEAR database
71 php-pear-r2_install_packagexml() {
72 insinto /usr/share/php/.packagexml
73 if [[ -f "${WORKDIR}/package2.xml" ]] ; then
74 newins "${WORKDIR}/package2.xml" "${PEAR_P}.xml"
75 elif [[ -f "${WORKDIR}/package.xml" ]] ; then
76 newins "${WORKDIR}/package.xml" "${PEAR_P}.xml"
79 if [[ -f "${PHP_PEAR_CHANNEL}" ]] ; then
80 newins "${PHP_PEAR_CHANNEL}" "${PEAR_P}-channel.xml"
84 # @FUNCTION: php-pear-r2_src_install
86 # Takes care of standard install for PEAR packages.
87 # Override src_install if the package installs more than "${PHP_PEAR_PKG_NAME}.php"
88 # or "${PHP_PEAR_PKG_NAME%%_*}/" as a directory
89 php-pear-r2_src_install() {
90 insinto /usr/share/php
91 [[ -f "${PHP_PEAR_PKG_NAME}.php" ]] && doins "${PHP_PEAR_PKG_NAME}.php"
92 [[ -d "${PHP_PEAR_PKG_NAME%%_*}" ]] && doins -r "${PHP_PEAR_PKG_NAME%%_*}/"
93 php-pear-r2_install_packagexml
97 # @FUNCTION: php-pear-r2_pkg_postinst
99 # Register package with the local PEAR database.
100 php-pear-r2_pkg_postinst() {
101 # Add unknown channels
102 if [[ -f "${EROOT}usr/share/php/.packagexml/${PEAR_P}-channel.xml" ]] ; then
103 "${EROOT}usr/bin/peardev" channel-info "${PHP_PEAR_DOMAIN}" &> /dev/null
104 if [[ $? -ne 0 ]]; then
105 "${EROOT}usr/bin/peardev" channel-add \
106 "${EROOT}usr/share/php/.packagexml/${PEAR_P}-channel.xml" \
107 || einfo "Ignore any errors about existing channels"
111 # Register the package from the package{,2}.xml file
112 # It is not critical to complete so only warn on failure
113 if [[ -f "${EROOT}usr/share/php/.packagexml/${PEAR_P}.xml" ]] ; then
114 "${EROOT}usr/bin/peardev" install -nrO --force \
115 "${EROOT}usr/share/php/.packagexml/${PEAR_P}.xml" 2> /dev/null \
116 || ewarn "Failed to insert package into local PEAR database"
120 # @FUNCTION: php-pear-r2_pkg_postrm
122 # Deregister package from the local PEAR database
123 php-pear-r2_pkg_postrm() {
124 # Uninstall known dependency
125 "${EROOT}usr/bin/peardev" uninstall -nrO "${PHP_PEAR_DOMAIN}/${PHP_PEAR_PKG_NAME}"