1 # Copyright 1999-2018 Gentoo Authors
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 # @SUPPORTED_EAPIS: 6 7
10 # @BLURB: Provides means for an easy installation of PEAR packages.
12 # This eclass provides means for an easy installation of PEAR packages.
13 # For more information on PEAR, see https://pear.php.net/
14 # Note that this eclass doesn't handle dependencies of PEAR packages
15 # on purpose; please use (R)DEPEND to define them correctly!
17 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
23 die "Unsupported EAPI=${EAPI} for ${ECLASS}"
27 RDEPEND=">=dev-php/pear-1.8.1"
29 # @ECLASS-VARIABLE: PHP_PEAR_PKG_NAME
31 # Set this if the PEAR package name differs from ${PN/PEAR-/}
32 # (generally shouldn't be the case).
33 : ${PHP_PEAR_PKG_NAME:=${PN/PEAR-/}}
35 # @ECLASS-VARIABLE: PEAR_PV
37 # Set in ebuild if the ${PV} breaks SRC_URI for alpha/beta/rc versions
40 # @ECLASS-VARIABLE: PEAR-P
42 # @DESCRIPTION: Combines PHP_PEAR_PKG_NAME and PEAR_PV
43 PEAR_P="${PHP_PEAR_PKG_NAME}-${PEAR_PV}"
45 # @ECLASS-VARIABLE: PHP_PEAR_DOMAIN
47 # Set in ebuild to the domain name of the channel if not pear.php.net
48 # When the domain is not pear.php.net, setting the SRC_URI is required
49 : ${PHP_PEAR_DOMAIN:=pear.php.net}
51 # @ECLASS-VARIABLE: PHP_PEAR_CHANNEL
54 # Set in ebuild to the path of channel.xml file which is necessary for
55 # 3rd party pear channels (besides pear.php.net) to be added to PEAR
56 # Default is unset to do nothing
58 # set default SRC_URI for pear.php.net packages
59 if [[ "${PHP_PEAR_DOMAIN}" == "pear.php.net" ]] ; then
60 SRC_URI="https://pear.php.net/get/${PEAR_P}.tgz"
63 : ${HOMEPAGE:=https://${PHP_PEAR_DOMAIN}/package/${PHP_PEAR_PKG_NAME}}
65 S="${WORKDIR}/${PEAR_P}"
67 # @FUNCTION: php-pear-r2_install_packagexml
69 # Copies the package2.xml or package.xml file and, optionally, the channel.xml
70 # file to a Gentoo-specific location so that pkg_postinst can install the package
71 # to the local PEAR database
72 php-pear-r2_install_packagexml() {
73 insinto /usr/share/php/.packagexml
74 if [[ -f "${WORKDIR}/package2.xml" ]] ; then
75 newins "${WORKDIR}/package2.xml" "${PEAR_P}.xml"
76 elif [[ -f "${WORKDIR}/package.xml" ]] ; then
77 newins "${WORKDIR}/package.xml" "${PEAR_P}.xml"
80 if [[ -f "${PHP_PEAR_CHANNEL}" ]] ; then
81 newins "${PHP_PEAR_CHANNEL}" "${PEAR_P}-channel.xml"
85 # @FUNCTION: php-pear-r2_src_install
87 # Takes care of standard install for PEAR packages.
88 # Override src_install if the package installs more than "${PHP_PEAR_PKG_NAME}.php"
89 # or "${PHP_PEAR_PKG_NAME%%_*}/" as a directory
90 php-pear-r2_src_install() {
91 insinto /usr/share/php
92 [[ -f "${PHP_PEAR_PKG_NAME}.php" ]] && doins "${PHP_PEAR_PKG_NAME}.php"
93 [[ -d "${PHP_PEAR_PKG_NAME%%_*}" ]] && doins -r "${PHP_PEAR_PKG_NAME%%_*}/"
94 php-pear-r2_install_packagexml
98 # @FUNCTION: php-pear-r2_pkg_postinst
100 # Register package with the local PEAR database.
101 php-pear-r2_pkg_postinst() {
102 # Add unknown channels
103 if [[ -f "${EROOT%/}/usr/share/php/.packagexml/${PEAR_P}-channel.xml" ]] ; then
104 "${EROOT%/}/usr/bin/peardev" channel-info "${PHP_PEAR_DOMAIN}" &> /dev/null
105 if [[ $? -ne 0 ]]; then
106 "${EROOT%/}/usr/bin/peardev" channel-add \
107 "${EROOT%/}/usr/share/php/.packagexml/${PEAR_P}-channel.xml" \
108 || einfo "Ignore any errors about existing channels"
112 # Register the package from the package{,2}.xml file
113 # It is not critical to complete so only warn on failure
114 if [[ -f "${EROOT%/}/usr/share/php/.packagexml/${PEAR_P}.xml" ]] ; then
115 "${EROOT%/}/usr/bin/peardev" install -nrO --force \
116 "${EROOT%/}/usr/share/php/.packagexml/${PEAR_P}.xml" 2> /dev/null \
117 || ewarn "Failed to insert package into local PEAR database"
121 # @FUNCTION: php-pear-r2_pkg_postrm
123 # Deregister package from the local PEAR database
124 php-pear-r2_pkg_postrm() {
125 # Uninstall known dependency
126 "${EROOT%/}/usr/bin/peardev" uninstall -nrO "${PHP_PEAR_DOMAIN}/${PHP_PEAR_PKG_NAME}"