php-pear-r2.eclass 4.0 KB

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