x11-libs/libXpresent: add ~arm64, bug #616260
[gentoo.git] / eclass / php-pear-r2.eclass
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: php-pear-r2.eclass
5 # @MAINTAINER:
6 # Gentoo PHP Team <php-bugs@gentoo.org>
7 # @AUTHOR:
8 # Author: Brian Evans <grknight@gentoo.org>
9 # @BLURB: Provides means for an easy installation of PEAR packages.
10 # @DESCRIPTION:
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!
15
16 EXPORT_FUNCTIONS src_install pkg_postinst pkg_postrm
17
18 case "${EAPI:-0}" in
19         6)
20                 ;;
21         *)
22                 die "Unsupported EAPI=${EAPI} for ${ECLASS}"
23                 ;;
24 esac
25
26 RDEPEND=">=dev-php/pear-1.8.1"
27
28 # @ECLASS-VARIABLE: PHP_PEAR_PKG_NAME
29 # @DESCRIPTION:
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-/}}
33
34 # @ECLASS-VARIABLE: PEAR_PV
35 # @DESCRIPTION:
36 # Set in ebuild if the ${PV} breaks SRC_URI for alpha/beta/rc versions
37 : ${PEAR_PV:=${PV}}
38
39 PEAR_P="${PHP_PEAR_PKG_NAME}-${PEAR_PV}"
40
41 # @ECLASS-VARIABLE: PHP_PEAR_DOMAIN
42 # @DESCRIPTION:
43 # Set in ebuild to the domain name of the channel if not pear.php.net
44 # When the domain is not pear.php.net, setting the SRC_URI is required
45 : ${PHP_PEAR_DOMAIN:=pear.php.net}
46
47 # @ECLASS-VARIABLE: PHP_PEAR_CHANNEL
48 # @DEFAULT_UNSET
49 # @DESCRIPTION:
50 # Set in ebuild to the path of channel.xml file which is necessary for
51 # 3rd party pear channels (besides pear.php.net) to be added to PEAR
52 # Default is unset to do nothing
53
54 # set default SRC_URI for pear.php.net packages
55 if [[ "${PHP_PEAR_DOMAIN}" == "pear.php.net" ]] ; then
56         SRC_URI="https://pear.php.net/get/${PEAR_P}.tgz"
57 fi
58
59 : ${HOMEPAGE:=https://${PHP_PEAR_DOMAIN}/package/${PHP_PEAR_PKG_NAME}}
60
61 S="${WORKDIR}/${PEAR_P}"
62
63 # @FUNCTION php-pear-r2_install_packagexml
64 # @DESCRIPTION:
65 # Copies the package2.xml or package.xml file and, optionally, the channel.xml
66 # file to a Gentoo-specific location so that pkg_postinst can install the package
67 # to the local PEAR database
68 php-pear-r2_install_packagexml() {
69         insinto /usr/share/php/.packagexml
70         if [[ -f "${WORKDIR}/package2.xml" ]] ; then
71                 newins "${WORKDIR}/package2.xml" "${PEAR_P}.xml"
72         elif [[ -f "${WORKDIR}/package.xml" ]] ; then
73                 newins "${WORKDIR}/package.xml" "${PEAR_P}.xml"
74         fi
75
76         if [[ -f "${PHP_PEAR_CHANNEL}" ]] ; then
77                 newins "${PHP_PEAR_CHANNEL}" "${PEAR_P}-channel.xml"
78         fi
79 }
80
81 # @FUNCTION: php-pear-r2_src_install
82 # @DESCRIPTION:
83 # Takes care of standard install for PEAR packages.
84 # Override src_install if the package installs more than "${PHP_PEAR_PKG_NAME}.php"
85 # or "${PHP_PEAR_PKG_NAME%%_*}/" as a directory
86 php-pear-r2_src_install() {
87         insinto /usr/share/php
88         [[ -f "${PHP_PEAR_PKG_NAME}.php" ]] && doins "${PHP_PEAR_PKG_NAME}.php"
89         [[ -d "${PHP_PEAR_PKG_NAME%%_*}" ]] && doins -r "${PHP_PEAR_PKG_NAME%%_*}/"
90         php-pear-r2_install_packagexml
91         einstalldocs
92 }
93
94 # @FUNCTION: php-pear-r2_pkg_postinst
95 # @DESCRIPTION:
96 # Register package with the local PEAR database.
97 php-pear-r2_pkg_postinst() {
98         # Add unknown channels
99         if [[ -f "${EROOT}usr/share/php/.packagexml/${PEAR_P}-channel.xml" ]] ; then
100                 if "${EROOT}usr/bin/peardev" channel-info "${PHP_PEAR_DOMAIN}" &> /dev/null; then
101                         "${EROOT}usr/bin/peardev" channel-add \
102                                 "${EROOT}usr/share/php/.packagexml/${PEAR_PN}-channel.xml" \
103                                 || einfo "Ignore any errors about existing channels"
104                 fi
105         fi
106
107         # Register the package from the package{,2}.xml file
108         # It is not critical to complete so only warn on failure
109         if [[ -f "${EROOT}usr/share/php/.packagexml/${PEAR_P}.xml" ]] ; then
110                 "${EROOT}usr/bin/peardev" install -nrO --force \
111                         "${EROOT}usr/share/php/.packagexml/${PEAR_P}.xml" 2> /dev/null \
112                         || ewarn "Failed to insert package into local PEAR database"
113         fi
114 }
115
116 # @FUNCTION: php-pear-r2_pkg_postrm
117 # @DESCRIPTION:
118 # Deregister package from the local PEAR database
119 php-pear-r2_pkg_postrm() {
120         # Uninstall known dependency
121         "${EROOT}usr/bin/peardev" uninstall -nrO "${PHP_PEAR_DOMAIN}/${PHP_PEAR_PKG_NAME}"
122 }