1 |
commit: 28e082bab8a150597abb570f5a4bead7db0ff601 |
2 |
Author: Michael Orlitzky <mjo <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jul 9 16:37:07 2016 +0000 |
4 |
Commit: Michael Orlitzky <mjo <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Jul 9 16:37:07 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=28e082ba |
7 |
|
8 |
php-ext-source-r3.eclass: new revision supporting EAPI=6. |
9 |
|
10 |
This is a new revision of the php-ext-source eclass that supports |
11 |
EAPI=6 (only) and cleans up some of the existing code. The list of |
12 |
user-facing changes is, |
13 |
|
14 |
* Support only EAPI=6. |
15 |
|
16 |
* PATCHES array/variable support. |
17 |
|
18 |
* DOCS array support (bug 512184). |
19 |
|
20 |
* Renamed my_conf and PHPSAPILIST variables. |
21 |
|
22 |
Some refactoring was done, but not in a way that consumers should |
23 |
notice. A migration guide can be found on the wiki: |
24 |
|
25 |
https://wiki.gentoo.org/wiki/Project:PHP/Php-ext-source-r3_migration_guide |
26 |
|
27 |
In addition, a number of improvements were suggested by Michał Górny |
28 |
on the gentoo-dev mailing list: |
29 |
|
30 |
https://archives.gentoo.org/gentoo-dev/message/9159cba2eabceb96d8ae16ced6631f1e |
31 |
|
32 |
Gentoo-Bug: 512184 |
33 |
|
34 |
eclass/php-ext-source-r3.eclass | 410 ++++++++++++++++++++++++++++++++++++++++ |
35 |
1 file changed, 410 insertions(+) |
36 |
|
37 |
diff --git a/eclass/php-ext-source-r3.eclass b/eclass/php-ext-source-r3.eclass |
38 |
new file mode 100644 |
39 |
index 0000000..3372a4b |
40 |
--- /dev/null |
41 |
+++ b/eclass/php-ext-source-r3.eclass |
42 |
@@ -0,0 +1,410 @@ |
43 |
+# Copyright 1999-2016 Gentoo Foundation |
44 |
+# Distributed under the terms of the GNU General Public License v2 |
45 |
+# $Id$ |
46 |
+ |
47 |
+# @ECLASS: php-ext-source-r3.eclass |
48 |
+# @MAINTAINER: |
49 |
+# Gentoo PHP team <php-bugs@g.o> |
50 |
+# @BLURB: Compile and install standalone PHP extensions. |
51 |
+# @DESCRIPTION: |
52 |
+# A unified interface for compiling and installing standalone PHP |
53 |
+# extensions. |
54 |
+ |
55 |
+inherit autotools |
56 |
+ |
57 |
+EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install |
58 |
+ |
59 |
+case ${EAPI} in |
60 |
+ 6) ;; |
61 |
+ *) |
62 |
+ die "${ECLASS} is not compatible with EAPI=${EAPI}" |
63 |
+esac |
64 |
+ |
65 |
+# @ECLASS-VARIABLE: PHP_EXT_NAME |
66 |
+# @REQUIRED |
67 |
+# @DESCRIPTION: |
68 |
+# The extension name. This must be set, otherwise the eclass dies. |
69 |
+# Only automagically set by php-ext-pecl-r3.eclass, so unless your ebuild |
70 |
+# inherits that eclass, you must set this manually before inherit. |
71 |
+[[ -z "${PHP_EXT_NAME}" ]] && \ |
72 |
+ die "no extension name specified for the php-ext-source-r3 eclass" |
73 |
+ |
74 |
+# @ECLASS-VARIABLE: PHP_EXT_INI |
75 |
+# @DESCRIPTION: |
76 |
+# Controls whether or not to add a line to php.ini for the extension. |
77 |
+# Defaults to "yes" and should not be changed in most cases. |
78 |
+[[ -z "${PHP_EXT_INI}" ]] && PHP_EXT_INI="yes" |
79 |
+ |
80 |
+# @ECLASS-VARIABLE: PHP_EXT_ZENDEXT |
81 |
+# @DESCRIPTION: |
82 |
+# Controls whether the extension is a ZendEngine extension or not. |
83 |
+# Defaults to "no". If you don't know what this is, you don't need it. |
84 |
+[[ -z "${PHP_EXT_ZENDEXT}" ]] && PHP_EXT_ZENDEXT="no" |
85 |
+ |
86 |
+# @ECLASS-VARIABLE: USE_PHP |
87 |
+# @REQUIRED |
88 |
+# @DESCRIPTION: |
89 |
+# Lists the PHP slots compatible the extension is compatible with. |
90 |
+# Example: |
91 |
+# @CODE |
92 |
+# USE_PHP="php5-6 php7-0" |
93 |
+# @CODE |
94 |
+[[ -z "${USE_PHP}" ]] && \ |
95 |
+ die "USE_PHP is not set for the php-ext-source-r3 eclass" |
96 |
+ |
97 |
+# @ECLASS-VARIABLE: PHP_EXT_OPTIONAL_USE |
98 |
+# @DEFAULT_UNSET |
99 |
+# @DESCRIPTION: |
100 |
+# If set, all of the dependencies added by this eclass will be |
101 |
+# conditional on USE=${PHP_EXT_OPTIONAL_USE}. This is needed when |
102 |
+# ebuilds have to inherit this eclass unconditionally, but only |
103 |
+# actually use it when (for example) the user has USE=php. |
104 |
+ |
105 |
+# @ECLASS-VARIABLE: PHP_EXT_S |
106 |
+# @DESCRIPTION: |
107 |
+# The relative location of the temporary build directory for the PHP |
108 |
+# extension within the source package. This is useful for packages that |
109 |
+# bundle the PHP extension. Defaults to ${S}. |
110 |
+[[ -z "${PHP_EXT_S}" ]] && PHP_EXT_S="${S}" |
111 |
+ |
112 |
+# @ECLASS-VARIABLE: PHP_EXT_SAPIS |
113 |
+# @DESCRIPTION: |
114 |
+# A list of SAPIs for which we will install this extension. Formerly |
115 |
+# called PHPSAPILIST. The default includes every SAPI currently used in |
116 |
+# the tree. |
117 |
+[[ -z "${PHP_EXT_SAPIS}" ]] && PHP_EXT_SAPIS="apache2 cli cgi fpm embed phpdbg" |
118 |
+ |
119 |
+ |
120 |
+# Make sure at least one target is installed. First, start a USE |
121 |
+# conditional like "php?", but only when PHP_EXT_OPTIONAL_USE is |
122 |
+# non-null. The option group "|| (..." is always started here. |
123 |
+REQUIRED_USE="${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }|| ( " |
124 |
+for _php_target in ${USE_PHP}; do |
125 |
+ # Now loop through each USE_PHP target and add the corresponding |
126 |
+ # dev-lang/php slot to PHPDEPEND. |
127 |
+ IUSE+=" php_targets_${_php_target}" |
128 |
+ REQUIRED_USE+="php_targets_${_php_target} " |
129 |
+ _php_slot=${_php_target/php} |
130 |
+ _php_slot=${_php_slot/-/.} |
131 |
+ PHPDEPEND+=" php_targets_${_php_target}? ( dev-lang/php:${_php_slot} )" |
132 |
+done |
133 |
+ |
134 |
+# Don't pollute the environment with our loop variables. |
135 |
+unset _php_slot _php_target |
136 |
+ |
137 |
+# Finally, end the optional group that we started before the loop. Close |
138 |
+# the USE-conditional if PHP_EXT_OPTIONAL_USE is non-null. |
139 |
+REQUIRED_USE+=") ${PHP_EXT_OPTIONAL_USE:+ )}" |
140 |
+ |
141 |
+RDEPEND="${RDEPEND} |
142 |
+ ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( } |
143 |
+ ${PHPDEPEND} |
144 |
+ ${PHP_EXT_OPTIONAL_USE:+ )}" |
145 |
+ |
146 |
+DEPEND="${DEPEND} |
147 |
+ sys-devel/m4 |
148 |
+ sys-devel/libtool |
149 |
+ ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( } |
150 |
+ ${PHPDEPEND} |
151 |
+ ${PHP_EXT_OPTIONAL_USE:+ )} |
152 |
+" |
153 |
+ |
154 |
+# @ECLASS-VARIABLE: PHP_EXT_SKIP_PHPIZE |
155 |
+# @DEFAULT_UNSET |
156 |
+# @DESCRIPTION: |
157 |
+# By default, we run "phpize" in php-ext-source-r3_src_unpack(). Set |
158 |
+# PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run |
159 |
+# phpize (and the autoreconf that becomes necessary afterwards). |
160 |
+ |
161 |
+# @FUNCTION: php-ext-source-r3_src_unpack |
162 |
+# @DESCRIPTION: |
163 |
+# Runs the default src_unpack and then makes a copy for each PHP slot. |
164 |
+php-ext-source-r3_src_unpack() { |
165 |
+ default |
166 |
+ |
167 |
+ local slot orig_s="${PHP_EXT_S}" |
168 |
+ for slot in $(php_get_slots); do |
169 |
+ cp --recursive --preserve "${orig_s}" "${WORKDIR}/${slot}" || \ |
170 |
+ die "failed to copy sources from ${orig_s} to ${WORKDIR}/${slot}" |
171 |
+ done |
172 |
+} |
173 |
+ |
174 |
+ |
175 |
+# @FUNCTION: php-ext-source-r3_src_prepare |
176 |
+# @DESCRIPTION: |
177 |
+# For each PHP slot, we initialize the environment, run the default |
178 |
+# src_prepare() for PATCHES/eapply_user support, and then call |
179 |
+# php-ext-source-r3_phpize. |
180 |
+php-ext-source-r3_src_prepare() { |
181 |
+ for slot in $(php_get_slots); do |
182 |
+ php_init_slot_env "${slot}" |
183 |
+ default |
184 |
+ php-ext-source-r3_phpize |
185 |
+ done |
186 |
+} |
187 |
+ |
188 |
+# @FUNCTION: php-ext-source-r3_phpize |
189 |
+# @DESCRIPTION: |
190 |
+# Subject to PHP_EXT_SKIP_PHPIZE, this function runs phpize and |
191 |
+# autoreconf in a manner that avoids warnings. |
192 |
+php-ext-source-r3_phpize() { |
193 |
+ if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then |
194 |
+ # Create configure out of config.m4. We use autotools_run_tool |
195 |
+ # to avoid some warnings about WANT_AUTOCONF and |
196 |
+ # WANT_AUTOMAKE (see bugs #329071 and #549268). |
197 |
+ autotools_run_tool "${PHPIZE}" |
198 |
+ |
199 |
+ # Force libtoolize to run and regenerate autotools files (bug |
200 |
+ # #220519). |
201 |
+ rm aclocal.m4 || die "failed to remove aclocal.m4" |
202 |
+ eautoreconf |
203 |
+ fi |
204 |
+} |
205 |
+ |
206 |
+ |
207 |
+# @ECLASS-VARIABLE: PHP_EXT_ECONF_ARGS |
208 |
+# @DEFAULT_UNSET |
209 |
+# @DESCRIPTION: |
210 |
+# Set this in the ebuild to pass additional configure options to |
211 |
+# econf. Formerly called my_conf. Either a string or an array of |
212 |
+# --flag=value parameters is supported. |
213 |
+ |
214 |
+# @FUNCTION: php-ext-source-r3_src_configure |
215 |
+# @DESCRIPTION: |
216 |
+# Takes care of standard configure for PHP extensions (modules). |
217 |
+php-ext-source-r3_src_configure() { |
218 |
+ # net-snmp creates these, bug #385403. |
219 |
+ addpredict /usr/share/snmp/mibs/.index |
220 |
+ addpredict /var/lib/net-snmp/mib_indexes |
221 |
+ |
222 |
+ # Support either a string or an array for PHP_EXT_ECONF_ARGS. |
223 |
+ local econf_args |
224 |
+ if [[ $(declare -p PHP_EXT_ECONF_ARGS) == "declare -a"* ]]; then |
225 |
+ econf_args=( "${PHP_EXT_ECONF_ARGS[@]}" ) |
226 |
+ else |
227 |
+ econf_args=( ${PHP_EXT_ECONF_ARGS} ) |
228 |
+ fi |
229 |
+ |
230 |
+ local slot |
231 |
+ for slot in $(php_get_slots); do |
232 |
+ php_init_slot_env "${slot}" |
233 |
+ econf --with-php-config="${PHPCONFIG}" "${econf_args[@]}" |
234 |
+ done |
235 |
+} |
236 |
+ |
237 |
+# @FUNCTION: php-ext-source-r3_src_compile |
238 |
+# @DESCRIPTION: |
239 |
+# Compile a standard standalone PHP extension. |
240 |
+php-ext-source-r3_src_compile() { |
241 |
+ # net-snmp creates these, bug #324739. |
242 |
+ addpredict /usr/share/snmp/mibs/.index |
243 |
+ addpredict /var/lib/net-snmp/mib_indexes |
244 |
+ |
245 |
+ # shm extension creates a semaphore file, bug #173574. |
246 |
+ addpredict /session_mm_cli0.sem |
247 |
+ local slot |
248 |
+ for slot in $(php_get_slots); do |
249 |
+ php_init_slot_env "${slot}" |
250 |
+ emake |
251 |
+ done |
252 |
+} |
253 |
+ |
254 |
+# @FUNCTION: php-ext-source-r3_src_install |
255 |
+# @DESCRIPTION: |
256 |
+# Install a standard standalone PHP extension. Uses einstalldocs() |
257 |
+# to support the DOCS variable/array. |
258 |
+php-ext-source-r3_src_install() { |
259 |
+ local slot |
260 |
+ for slot in $(php_get_slots); do |
261 |
+ php_init_slot_env "${slot}" |
262 |
+ |
263 |
+ # Strip $EPREFIX from $EXT_DIR before calling doexe (which |
264 |
+ # handles EPREFIX itself). Shared libs are +x by convention, |
265 |
+ # although nothing seems to depend on that. |
266 |
+ exeinto "${EXT_DIR#$EPREFIX}" |
267 |
+ doexe "modules/${PHP_EXT_NAME}.so" |
268 |
+ |
269 |
+ INSTALL_ROOT="${D}" emake install-headers |
270 |
+ done |
271 |
+ einstalldocs |
272 |
+ php-ext-source-r3_createinifiles |
273 |
+} |
274 |
+ |
275 |
+# @FUNCTION: php_get_slots |
276 |
+# @DESCRIPTION: |
277 |
+# Get a list of PHP slots contained in both the ebuild's USE_PHP and the |
278 |
+# user's PHP_TARGETS. |
279 |
+php_get_slots() { |
280 |
+ local s="" |
281 |
+ local slot |
282 |
+ for slot in ${USE_PHP}; do |
283 |
+ use php_targets_${slot} && s+=" ${slot/-/.}" |
284 |
+ done |
285 |
+ echo $s |
286 |
+} |
287 |
+ |
288 |
+# @FUNCTION: php_init_slot_env |
289 |
+# @USAGE: <slot> |
290 |
+# @DESCRIPTION: |
291 |
+# Takes a slot name, and initializes some global variables to values |
292 |
+# corresponding to that slot. For example, it sets the path to the "php" |
293 |
+# and "phpize" binaries, which will differ for each slot. This function |
294 |
+# is intended to be called while looping through a list of slots |
295 |
+# obtained from php_get_slots(). |
296 |
+# |
297 |
+# Calling this function will change the working directory to the |
298 |
+# temporary build directory for the given slot. |
299 |
+php_init_slot_env() { |
300 |
+ local libdir=$(get_libdir) |
301 |
+ local slot="${1}" |
302 |
+ |
303 |
+ PHPPREFIX="${EPREFIX}/usr/${libdir}/${slot}" |
304 |
+ PHPIZE="${PHPPREFIX}/bin/phpize" |
305 |
+ PHPCONFIG="${PHPPREFIX}/bin/php-config" |
306 |
+ PHPCLI="${PHPPREFIX}/bin/php" |
307 |
+ PHPCGI="${PHPPREFIX}/bin/php-cgi" |
308 |
+ PHP_PKG="$(best_version =dev-lang/php-${1:3}*)" |
309 |
+ |
310 |
+ EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)" |
311 |
+ PHP_CURRENTSLOT=${1:3} |
312 |
+ |
313 |
+ PHP_EXT_S="${WORKDIR}/${slot}" |
314 |
+ cd "${PHP_EXT_S}" || die "failed to change directory to ${PHP_EXT_S}" |
315 |
+} |
316 |
+ |
317 |
+# @FUNCTION: php_slot_ini_files |
318 |
+# @USAGE: <slot> |
319 |
+# @INTERNAL |
320 |
+# @DESCRIPTION: |
321 |
+# Output a list of relative paths to INI files for the given |
322 |
+# slot. Usually there will be one INI file per SAPI. |
323 |
+php_slot_ini_files() { |
324 |
+ local slot_ini_files="" |
325 |
+ local x |
326 |
+ for x in ${PHP_EXT_SAPIS} ; do |
327 |
+ if [[ -f "${EPREFIX}/etc/php/${x}-${1}/php.ini" ]] ; then |
328 |
+ slot_ini_files+=" etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini" |
329 |
+ fi |
330 |
+ done |
331 |
+ |
332 |
+ echo "${slot_ini_files}" |
333 |
+} |
334 |
+ |
335 |
+# @FUNCTION: php-ext-source-r3_createinifiles |
336 |
+# @DESCRIPTION: |
337 |
+# Builds INI files for every enabled slot and SAPI. |
338 |
+php-ext-source-r3_createinifiles() { |
339 |
+ local slot |
340 |
+ for slot in $(php_get_slots); do |
341 |
+ php_init_slot_env "${slot}" |
342 |
+ |
343 |
+ local file |
344 |
+ for file in $(php_slot_ini_files "${slot}") ; do |
345 |
+ if [[ "${PHP_EXT_INI}" = "yes" ]] ; then |
346 |
+ # Add the needed lines to the <ext>.ini files |
347 |
+ php-ext-source-r3_addextension "${PHP_EXT_NAME}.so" "${file}" |
348 |
+ fi |
349 |
+ |
350 |
+ if [[ -n "${PHP_EXT_INIFILE}" ]] ; then |
351 |
+ cat "${FILESDIR}/${PHP_EXT_INIFILE}" >> "${ED}/${file}" \ |
352 |
+ || die "failed to append to ${ED}/${file}" |
353 |
+ |
354 |
+ einfo "Added contents of ${FILESDIR}/${PHP_EXT_INIFILE}" \ |
355 |
+ "to ${file}" |
356 |
+ fi |
357 |
+ inidir="${file/${PHP_EXT_NAME}.ini/}" |
358 |
+ inidir="${inidir/ext/ext-active}" |
359 |
+ dodir "/${inidir}" |
360 |
+ dosym "/${file}" "/${file/ext/ext-active}" |
361 |
+ done |
362 |
+ done |
363 |
+ |
364 |
+ # A location where PHP code for this extension can be stored, |
365 |
+ # independent of the PHP or extension versions. This will be part of |
366 |
+ # PHP's include_path, configured in php.ini. For example, pecl-apcu |
367 |
+ # installs an "apc.php" file which you are supposed to load with |
368 |
+ # |
369 |
+ # require('apcu/apc.php'); |
370 |
+ # |
371 |
+ PHP_EXT_SHARED_DIR="${EPREFIX}/usr/share/php/${PHP_EXT_NAME}" |
372 |
+} |
373 |
+ |
374 |
+# @FUNCTION: php-ext-source-r3_addextension |
375 |
+# @USAGE: <extension-path> <ini-file> |
376 |
+# @INTERNAL |
377 |
+# @DESCRIPTION: |
378 |
+# Add a line to an INI file that will enable the given extension. The |
379 |
+# first parameter is the path to the extension (.so) file, and the |
380 |
+# second parameter is the name of the INI file in which it should be |
381 |
+# loaded. This function determines the setting name (either |
382 |
+# "extension=..." or "zend_extension=...") and then calls |
383 |
+# php-ext-source-r3_addtoinifile to do the actual work. |
384 |
+php-ext-source-r3_addextension() { |
385 |
+ local ext_type="extension" |
386 |
+ local ext_file="${1}" |
387 |
+ |
388 |
+ if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then |
389 |
+ ext_type="zend_extension" |
390 |
+ ext_file="${EXT_DIR}/${1}" # Zend extensions need the path... |
391 |
+ fi |
392 |
+ |
393 |
+ php-ext-source-r3_addtoinifile "${2}" "${ext_type}" "${ext_file}" |
394 |
+} |
395 |
+ |
396 |
+# @FUNCTION: php-ext-source-r3_addtoinifile |
397 |
+# @USAGE: <relative-ini-path> <setting-or-section-name> [setting-value] |
398 |
+# @INTERNAL |
399 |
+# @DESCRIPTION: |
400 |
+# Add a setting=value to one INI file. The first argument is the |
401 |
+# relative path to the INI file. The second argument is the setting |
402 |
+# name, and the third argument is its value. |
403 |
+# |
404 |
+# You can also pass "[Section]" as the second parameter, to create a new |
405 |
+# section in the INI file. In that case, the third parameter (which |
406 |
+# would otherwise be the value of the setting) is ignored. |
407 |
+php-ext-source-r3_addtoinifile() { |
408 |
+ local inifile="${WORKDIR}/${1}" |
409 |
+ local inidir="${inifile%/*}" |
410 |
+ |
411 |
+ mkdir -p "${inidir}" || die "failed to create INI directory ${inidir}" |
412 |
+ |
413 |
+ # Are we adding the name of a section? Assume not by default. |
414 |
+ local my_added="${2}=${3}" |
415 |
+ if [[ ${2:0:1} == "[" ]] ; then |
416 |
+ # Ok, it's a section name. |
417 |
+ my_added="${2}" |
418 |
+ fi |
419 |
+ echo "${my_added}" >> "${inifile}" || die "failed to append to ${inifile}" |
420 |
+ einfo "Added '${my_added}' to /${1}" |
421 |
+ |
422 |
+ insinto "/${1%/*}" |
423 |
+ doins "${inifile}" |
424 |
+} |
425 |
+ |
426 |
+# @FUNCTION: php-ext-source-r3_addtoinifiles |
427 |
+# @USAGE: <setting-or-section-name> [setting-value] [message] |
428 |
+# @DESCRIPTION: |
429 |
+# Add settings to every php.ini file installed by this extension. |
430 |
+# You can also add new [Section]s -- see the example below. |
431 |
+# |
432 |
+# @CODE |
433 |
+# Add some settings for the extension: |
434 |
+# |
435 |
+# php-ext-source-r3_addtoinifiles "zend_optimizer.optimization_level" "15" |
436 |
+# php-ext-source-r3_addtoinifiles "zend_optimizer.enable_loader" "0" |
437 |
+# php-ext-source-r3_addtoinifiles "zend_optimizer.disable_licensing" "0" |
438 |
+# |
439 |
+# Adding values to a section in php.ini file installed by the extension: |
440 |
+# |
441 |
+# php-ext-source-r3_addtoinifiles "[Debugger]" |
442 |
+# php-ext-source-r3_addtoinifiles "debugger.enabled" "on" |
443 |
+# php-ext-source-r3_addtoinifiles "debugger.profiler_enabled" "on" |
444 |
+# @CODE |
445 |
+php-ext-source-r3_addtoinifiles() { |
446 |
+ local slot |
447 |
+ for slot in $(php_get_slots); do |
448 |
+ for file in $(php_slot_ini_files "${slot}") ; do |
449 |
+ php-ext-source-r3_addtoinifile "${file}" "${1}" "${2}" |
450 |
+ done |
451 |
+ done |
452 |
+} |