php-ext-source-r2.eclass 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. # Copyright 1999-2015 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: php-ext-source-r2.eclass
  4. # @MAINTAINER:
  5. # Gentoo PHP team <php-bugs@gentoo.org>
  6. # @AUTHOR:
  7. # Author: Tal Peer <coredumb@gentoo.org>
  8. # Author: Stuart Herbert <stuart@gentoo.org>
  9. # Author: Luca Longinotti <chtekk@gentoo.org>
  10. # Author: Jakub Moc <jakub@gentoo.org> (documentation)
  11. # Author: Ole Markus With <olemarkus@gentoo.org>
  12. # @BLURB: A unified interface for compiling and installing standalone PHP extensions.
  13. # @DESCRIPTION:
  14. # This eclass provides a unified interface for compiling and installing standalone
  15. # PHP extensions (modules).
  16. inherit flag-o-matic autotools multilib eutils
  17. EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
  18. DEPEND=">=sys-devel/m4-1.4.3
  19. >=sys-devel/libtool-1.5.18"
  20. RDEPEND=""
  21. # Because of USE deps, we require at least EAPI 2
  22. case ${EAPI} in
  23. 4|5) ;;
  24. *)
  25. die "php-ext-source-r2 is not compatible with EAPI=${EAPI}"
  26. esac
  27. # @ECLASS-VARIABLE: PHP_EXT_NAME
  28. # @REQUIRED
  29. # @DESCRIPTION:
  30. # The extension name. This must be set, otherwise the eclass dies.
  31. # Only automagically set by php-ext-pecl-r2.eclass, so unless your ebuild
  32. # inherits that eclass, you must set this manually before inherit.
  33. [[ -z "${PHP_EXT_NAME}" ]] && die "No module name specified for the php-ext-source-r2 eclass"
  34. # @ECLASS-VARIABLE: PHP_EXT_INI
  35. # @DESCRIPTION:
  36. # Controls whether or not to add a line to php.ini for the extension.
  37. # Defaults to "yes" and should not be changed in most cases.
  38. [[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes"
  39. # @ECLASS-VARIABLE: PHP_EXT_ZENDEXT
  40. # @DESCRIPTION:
  41. # Controls whether the extension is a ZendEngine extension or not.
  42. # Defaults to "no" and if you don't know what is it, you don't need it.
  43. [[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no"
  44. # @ECLASS-VARIABLE: USE_PHP
  45. # @REQUIRED
  46. # @DESCRIPTION:
  47. # Lists the PHP slots compatibile the extension is compatibile with
  48. # Example:
  49. # @CODE
  50. # USE_PHP="php5-5 php5-6"
  51. # @CODE
  52. [[ -z "${USE_PHP}" ]] && die "USE_PHP is not set for the php-ext-source-r2 eclass"
  53. # @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE
  54. # @DESCRIPTION:
  55. # If set, this is the USE flag that the PHP dependencies are behind
  56. # Most commonly set as PHP_EXT_OPTIONAL_USE=php to get the dependencies behind
  57. # USE=php.
  58. # @ECLASS-VARIABLE: PHP_EXT_S
  59. # @DESCRIPTION:
  60. # The relative location of the temporary build directory for the PHP extension within
  61. # the source package. This is useful for packages that bundle the PHP extension.
  62. # Defaults to ${S}
  63. [[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}"
  64. #Make sure at least one target is installed.
  65. REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( "
  66. for target in ${USE_PHP}; do
  67. IUSE="${IUSE} php_targets_${target}"
  68. target=${target/+}
  69. REQUIRED_USE+="php_targets_${target} "
  70. slot=${target/php}
  71. slot=${slot/-/.}
  72. PHPDEPEND="${PHPDEPEND}
  73. php_targets_${target}? ( dev-lang/php:${slot} )"
  74. done
  75. REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}"
  76. RDEPEND="${RDEPEND}
  77. ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
  78. ${PHPDEPEND}
  79. ${PHP_EXT_OPTIONAL_USE:+ )}"
  80. DEPEND="${DEPEND}
  81. ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
  82. ${PHPDEPEND}
  83. ${PHP_EXT_OPTIONAL_USE:+ )}
  84. "
  85. # @FUNCTION: php-ext-source-r2_src_unpack
  86. # @DESCRIPTION:
  87. # runs standard src_unpack + _phpize
  88. # @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE
  89. # @DESCRIPTION:
  90. # phpize will be run by default for all ebuilds that use
  91. # php-ext-source-r2_src_unpack
  92. # Set PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run phpize.
  93. php-ext-source-r2_src_unpack() {
  94. unpack ${A}
  95. local slot orig_s="${PHP_EXT_S}"
  96. for slot in $(php_get_slots); do
  97. cp -r "${orig_s}" "${WORKDIR}/${slot}" || die "Failed to copy source ${orig_s} to PHP target directory"
  98. done
  99. }
  100. php-ext-source-r2_src_prepare() {
  101. local slot orig_s="${PHP_EXT_S}"
  102. for slot in $(php_get_slots); do
  103. php_init_slot_env ${slot}
  104. php-ext-source-r2_phpize
  105. done
  106. }
  107. # @FUNCTION: php-ext-source-r2_phpize
  108. # @DESCRIPTION:
  109. # Runs phpize and autotools in addition to the standard src_unpack
  110. php-ext-source-r2_phpize() {
  111. if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
  112. # Create configure out of config.m4. We use autotools_run_tool
  113. # to avoid some warnings about WANT_AUTOCONF and
  114. # WANT_AUTOMAKE (see bugs #329071 and #549268).
  115. autotools_run_tool ${PHPIZE}
  116. # force run of libtoolize and regeneration of related autotools
  117. # files (bug 220519)
  118. rm aclocal.m4
  119. eautoreconf
  120. fi
  121. }
  122. # @FUNCTION: php-ext-source-r2_src_configure
  123. # @DESCRIPTION:
  124. # Takes care of standard configure for PHP extensions (modules).
  125. # @ECLASS-VARIABLE: my_conf
  126. # @DESCRIPTION:
  127. # Set this in the ebuild to pass configure options to econf.
  128. php-ext-source-r2_src_configure() {
  129. # net-snmp creates this file #385403
  130. addpredict /usr/share/snmp/mibs/.index
  131. addpredict /var/lib/net-snmp/mib_indexes
  132. local slot
  133. for slot in $(php_get_slots); do
  134. php_init_slot_env ${slot}
  135. # Set the correct config options
  136. econf --with-php-config=${PHPCONFIG} ${my_conf} || die "Unable to configure code to compile"
  137. done
  138. }
  139. # @FUNCTION: php-ext-source-r2_src_compile
  140. # @DESCRIPTION:
  141. # Takes care of standard compile for PHP extensions (modules).
  142. php-ext-source-r2_src_compile() {
  143. # net-snmp creates this file #324739
  144. addpredict /usr/share/snmp/mibs/.index
  145. addpredict /var/lib/net-snmp/mib_indexes
  146. # shm extension createss a semaphore file #173574
  147. addpredict /session_mm_cli0.sem
  148. local slot
  149. for slot in $(php_get_slots); do
  150. php_init_slot_env ${slot}
  151. emake || die "Unable to make code"
  152. done
  153. }
  154. # @FUNCTION: php-ext-source-r2_src_install
  155. # @DESCRIPTION:
  156. # Takes care of standard install for PHP extensions (modules).
  157. # @ECLASS-VARIABLE: DOCS
  158. # @DESCRIPTION:
  159. # Set in ebuild if you wish to install additional, package-specific documentation.
  160. php-ext-source-r2_src_install() {
  161. local slot
  162. for slot in $(php_get_slots); do
  163. php_init_slot_env ${slot}
  164. # Let's put the default module away. Strip $EPREFIX from
  165. # $EXT_DIR before calling newins (which handles EPREFIX itself).
  166. insinto "${EXT_DIR#$EPREFIX}"
  167. newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so" || die "Unable to install extension"
  168. local doc
  169. for doc in ${DOCS} ; do
  170. [[ -s ${doc} ]] && dodoc ${doc}
  171. done
  172. INSTALL_ROOT="${D}" emake install-headers
  173. done
  174. php-ext-source-r2_createinifiles
  175. }
  176. php_get_slots() {
  177. local s slot
  178. for slot in ${USE_PHP}; do
  179. use php_targets_${slot} && s+=" ${slot/-/.}"
  180. done
  181. echo $s
  182. }
  183. php_init_slot_env() {
  184. libdir=$(get_libdir)
  185. PHPIZE="${EPREFIX}/usr/${libdir}/${1}/bin/phpize"
  186. PHPCONFIG="${EPREFIX}/usr/${libdir}/${1}/bin/php-config"
  187. PHPCLI="${EPREFIX}/usr/${libdir}/${1}/bin/php"
  188. PHPCGI="${EPREFIX}/usr/${libdir}/${1}/bin/php-cgi"
  189. PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
  190. PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}"
  191. EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
  192. PHP_CURRENTSLOT=${1:3}
  193. PHP_EXT_S="${WORKDIR}/${1}"
  194. cd "${PHP_EXT_S}"
  195. }
  196. php-ext-source-r2_buildinilist() {
  197. # Work out the list of <ext>.ini files to edit/add to
  198. if [[ -z "${PHPSAPILIST}" ]] ; then
  199. PHPSAPILIST="apache2 cli cgi fpm embed phpdbg"
  200. fi
  201. PHPINIFILELIST=""
  202. local x
  203. for x in ${PHPSAPILIST} ; do
  204. if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then
  205. PHPINIFILELIST="${PHPINIFILELIST} etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
  206. fi
  207. done
  208. PHPFULLINIFILELIST="${PHPFULLINIFILELIST} ${PHPINIFILELIST}"
  209. }
  210. # @FUNCTION: php-ext-source-r2_createinifiles
  211. # @DESCRIPTION:
  212. # Builds ini files for every enabled slot and SAPI
  213. php-ext-source-r2_createinifiles() {
  214. local slot
  215. for slot in $(php_get_slots); do
  216. php_init_slot_env ${slot}
  217. # Pull in the PHP settings
  218. # Build the list of <ext>.ini files to edit/add to
  219. php-ext-source-r2_buildinilist ${slot}
  220. # Add the needed lines to the <ext>.ini files
  221. local file
  222. if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
  223. for file in ${PHPINIFILELIST}; do
  224. php-ext-source-r2_addextension "${PHP_EXT_NAME}.so" "${file}"
  225. done
  226. fi
  227. # Symlink the <ext>.ini files from ext/ to ext-active/
  228. local inifile
  229. for inifile in ${PHPINIFILELIST} ; do
  230. if [[ -n "${PHP_EXT_INIFILE}" ]]; then
  231. cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${inifile}"
  232. einfo "Added content of ${FILESDIR}/${PHP_EXT_INIFILE} to ${inifile}"
  233. fi
  234. inidir="${inifile/${PHP_EXT_NAME}.ini/}"
  235. inidir="${inidir/ext/ext-active}"
  236. dodir "/${inidir}"
  237. dosym "/${inifile}" "/${inifile/ext/ext-active}"
  238. done
  239. # Add support for installing PHP files into a version dependant directory
  240. PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}"
  241. done
  242. }
  243. php-ext-source-r2_addextension() {
  244. if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
  245. # We need the full path for ZendEngine extensions
  246. # and we need to check for debugging enabled!
  247. if has_version "dev-lang/php:${PHP_CURRENTSLOT}[threads]" ; then
  248. if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]" ; then
  249. ext_type="zend_extension_debug_ts"
  250. else
  251. ext_type="zend_extension_ts"
  252. fi
  253. ext_file="${EXT_DIR}/${1}"
  254. else
  255. if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]"; then
  256. ext_type="zend_extension_debug"
  257. else
  258. ext_type="zend_extension"
  259. fi
  260. ext_file="${EXT_DIR}/${1}"
  261. fi
  262. # php-5.3 unifies zend_extension loading and just requires the
  263. # zend_extension keyword with no suffix
  264. # TODO: drop previous code and this check once <php-5.3 support is
  265. # discontinued
  266. if has_version '>=dev-lang/php-5.3' ; then
  267. ext_type="zend_extension"
  268. fi
  269. else
  270. # We don't need the full path for normal extensions!
  271. ext_type="extension"
  272. ext_file="${1}"
  273. fi
  274. php-ext-source-r2_addtoinifile "${ext_type}" "${ext_file}" "${2}" "Extension added"
  275. }
  276. # $1 - Setting name
  277. # $2 - Setting value
  278. # $3 - File to add to
  279. # $4 - Sanitized text to output
  280. php-ext-source-r2_addtoinifile() {
  281. local inifile="${WORKDIR}/${3}"
  282. if [[ ! -d $(dirname ${inifile}) ]] ; then
  283. mkdir -p $(dirname ${inifile})
  284. fi
  285. # Are we adding the name of a section?
  286. if [[ ${1:0:1} == "[" ]] ; then
  287. echo "${1}" >> "${inifile}"
  288. my_added="${1}"
  289. else
  290. echo "${1}=${2}" >> "${inifile}"
  291. my_added="${1}=${2}"
  292. fi
  293. if [[ -z "${4}" ]] ; then
  294. einfo "Added '${my_added}' to /${3}"
  295. else
  296. einfo "${4} to /${3}"
  297. fi
  298. insinto /$(dirname ${3})
  299. doins "${inifile}"
  300. }
  301. # @FUNCTION: php-ext-source-r2_addtoinifiles
  302. # @USAGE: <setting name> <setting value> [message to output]; or just [section name]
  303. # @DESCRIPTION:
  304. # Add value settings to php.ini file installed by the extension (module).
  305. # You can also add a [section], see examples below.
  306. #
  307. # @CODE
  308. # Add some settings for the extension:
  309. #
  310. # php-ext-source-r2_addtoinifiles "zend_optimizer.optimization_level" "15"
  311. # php-ext-source-r2_addtoinifiles "zend_optimizer.enable_loader" "0"
  312. # php-ext-source-r2_addtoinifiles "zend_optimizer.disable_licensing" "0"
  313. #
  314. # Adding values to a section in php.ini file installed by the extension:
  315. #
  316. # php-ext-source-r2_addtoinifiles "[Debugger]"
  317. # php-ext-source-r2_addtoinifiles "debugger.enabled" "on"
  318. # php-ext-source-r2_addtoinifiles "debugger.profiler_enabled" "on"
  319. # @CODE
  320. php-ext-source-r2_addtoinifiles() {
  321. local x
  322. for x in ${PHPFULLINIFILELIST} ; do
  323. php-ext-source-r2_addtoinifile "${1}" "${2}" "${x}" "${3}"
  324. done
  325. }