/[gentoo-x86]/eclass/php-ext-source-r2.eclass
Gentoo

Contents of /eclass/php-ext-source-r2.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations) (download)
Fri Jul 22 12:13:27 2011 UTC (3 years ago) by olemarkus
Branch: MAIN
Changes since 1.11: +18 -2 lines
Fixed a few bugs and added support for supplying custom ini files

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

  ViewVC Help
Powered by ViewVC 1.1.20