app-admin/lastpass-cli: serve man from devspace #654846
[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 # @ECLASS-VARIABLE: PEAR-P
40 # @INTERNAL
41 # @DESCRIPTION: Combines PHP_PEAR_PKG_NAME and PEAR_PV
42 PEAR_P="${PHP_PEAR_PKG_NAME}-${PEAR_PV}"
43
44 # @ECLASS-VARIABLE: PHP_PEAR_DOMAIN
45 # @DESCRIPTION:
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}
49
50 # @ECLASS-VARIABLE: PHP_PEAR_CHANNEL
51 # @DEFAULT_UNSET
52 # @DESCRIPTION:
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
56
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"
60 fi
61
62 : ${HOMEPAGE:=https://${PHP_PEAR_DOMAIN}/package/${PHP_PEAR_PKG_NAME}}
63
64 S="${WORKDIR}/${PEAR_P}"
65
66 # @FUNCTION: php-pear-r2_install_packagexml
67 # @DESCRIPTION:
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"
77         fi
78
79         if [[ -f "${PHP_PEAR_CHANNEL}" ]] ; then
80                 newins "${PHP_PEAR_CHANNEL}" "${PEAR_P}-channel.xml"
81         fi
82 }
83
84 # @FUNCTION: php-pear-r2_src_install
85 # @DESCRIPTION:
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
94         einstalldocs
95 }
96
97 # @FUNCTION: php-pear-r2_pkg_postinst
98 # @DESCRIPTION:
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"
108                 fi
109         fi
110
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"
117         fi
118 }
119
120 # @FUNCTION: php-pear-r2_pkg_postrm
121 # @DESCRIPTION:
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}"
126 }