/[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.7 - (show annotations) (download)
Sun Jan 9 00:05:10 2011 UTC (3 years, 11 months ago) by robbat2
Branch: MAIN
Changes since 1.6: +10 -2 lines
Implement PHP_EXT_OPTIONAL_USE as a way to make the PHP dependency optional for bug #351098: Supports prevents packages USE=-php bringing in PHP when they do not need it.

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.6 2010/12/27 22:19:51 darkside 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-2 php5-3"
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 #Make sure at least one target is installed. Abuses USE dependencies.
72 for target in ${USE_PHP}; do
73 IUSE="${IUSE} php_targets_${target}"
74 target=${target/+}
75 SELFDEPEND="${SELFDEPEND} =${CATEGORY}/${PF}[php_targets_${target}]"
76 slot=${target/php}
77 slot=${slot/-/.}
78 PHPDEPEND="${PHPDEPEND}
79 php_targets_${target}? ( dev-lang/php:${slot} )"
80 done
81
82 RDEPEND="${RDEPEND}
83 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
84 || ( ${SELFDEPEND} )
85 ${PHPDEPEND}
86 ${PHP_EXT_OPTIONAL_USE:+ )}"
87
88
89 # @FUNCTION: php-ext-source-r2_src_unpack
90 # @DESCRIPTION:
91 # runs standard src_unpack + _phpize
92 #
93 # @VARIABLE: PHP_EXT_SKIP_PHPIZE
94 # @DESCRIPTION:
95 # phpize will be run by default for all ebuilds that use
96 # php-ext-source-r2_src_unpack
97 # Set PHP_EXT_SKIP_PHPIZE="yes" in your ebuild if you do not want to run phpize.
98 php-ext-source-r2_src_unpack() {
99 unpack ${A}
100 local slot orig_s="$S"
101 for slot in $(php_get_slots); do
102 cp -r "${orig_s}" "${WORKDIR}/${slot}"
103 done
104 }
105
106 php-ext-source-r2_src_prepare() {
107 local slot orig_s="$S"
108 for slot in $(php_get_slots); do
109 php_init_slot_env ${slot}
110 php-ext-source-r2_phpize
111 done
112 }
113
114 # @FUNCTION php-ext-source-r2_phpize
115 # @DESCRIPTION:
116 # Runs phpize and autotools in addition to the standard src_unpack
117 php-ext-source-r2_phpize() {
118 if [[ "${PHP_EXT_SKIP_PHPIZE}" != 'yes' ]] ; then
119 # Create configure out of config.m4
120 # I wish I could run this to solve #329071, but I cannot
121 #autotools_run_tool ${PHPIZE}
122 ${PHPIZE}
123 # force run of libtoolize and regeneration of related autotools
124 # files (bug 220519)
125 rm aclocal.m4
126 eautoreconf
127 fi
128 }
129
130 # @FUNCTION: php-ext-source-r2_src_configure
131 # @DESCRIPTION:
132 # Takes care of standard configure for PHP extensions (modules).
133 #
134 # @VARIABLE: my_conf
135 # @DESCRIPTION:
136 # Set this in the ebuild to pass configure options to econf.
137 php-ext-source-r2_src_configure() {
138 local slot
139 for slot in $(php_get_slots); do
140 php_init_slot_env ${slot}
141 # Set the correct config options
142 # We cannot use econf here, phpize/php-config deals with setting
143 # --prefix etc to whatever the php slot was configured to use
144 ./configure --with-php-config=${PHPCONFIG} ${my_conf} || die "Unable to configure code to compile"
145 done
146 }
147
148 # @FUNCTION: php-ext-source-r2_src_compile
149 # @DESCRIPTION:
150 # Takes care of standard compile for PHP extensions (modules).
151 php-ext-source-r2_src_compile() {
152 # net-snmp creates this file #324739
153 addpredict /usr/share/snmp/mibs/.index
154 # shm extension createss a semaphore file #173574
155 addpredict /session_mm_cli0.sem
156 local slot
157 for slot in $(php_get_slots); do
158 php_init_slot_env ${slot}
159 emake || die "Unable to make code"
160
161 done
162 }
163
164 # @FUNCTION: php-ext-source-r1_src_install
165 # @DESCRIPTION:
166 # Takes care of standard install for PHP extensions (modules).
167
168 # @VARIABLE: DOCS
169 # @DESCRIPTION:
170 # Set in ebuild if you wish to install additional, package-specific documentation.
171 php-ext-source-r2_src_install() {
172 local slot
173 for slot in $(php_get_slots); do
174 php_init_slot_env ${slot}
175
176 # Let's put the default module away
177 insinto "${EXT_DIR}"
178 newins "modules/${PHP_EXT_NAME}.so" "${PHP_EXT_NAME}.so" || die "Unable to install extension"
179
180 local doc
181 for doc in ${DOCS} ; do
182 [[ -s ${doc} ]] && dodoc ${doc}
183 done
184
185 done
186 php-ext-source-r2_createinifiles
187 }
188
189
190 php_get_slots() {
191 local s slot
192 for slot in ${USE_PHP}; do
193 use php_targets_${slot} && s+=" ${slot/-/.}"
194 done
195 echo $s
196 }
197
198 php_init_slot_env() {
199 libdir=$(get_libdir)
200
201 PHPIZE="/usr/${libdir}/${1}/bin/phpize"
202 PHPCONFIG="/usr/${libdir}/${1}/bin/php-config"
203 PHPCLI="/usr/${libdir}/${1}/bin/php"
204 PHPCGI="/usr/${libdir}/${1}/bin/php-cgi"
205 PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
206 PHPPREFIX="/usr/${libdir}/${slot}"
207 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
208 PHP_CURRENTSLOT=${1:3}
209
210 S="${WORKDIR}/${1}"
211 cd "${S}"
212 }
213
214 php-ext-source-r2_buildinilist() {
215 # Work out the list of <ext>.ini files to edit/add to
216 if [[ -z "${PHPSAPILIST}" ]] ; then
217 PHPSAPILIST="apache2 cli cgi fpm"
218 fi
219
220 PHPINIFILELIST=""
221 local x
222 for x in ${PHPSAPILIST} ; do
223 if [[ -f "/etc/php/${x}-${1}/php.ini" ]] ; then
224 PHPINIFILELIST="${PHPINIFILELIST} etc/php/${x}-${1}/ext/${PHP_EXT_NAME}.ini"
225 fi
226 done
227 }
228
229 # @FUNCTION: php-ext-source-r2_createinifiles
230 # @DESCRIPTION:
231 # Builds ini files for every enabled slot and SAPI
232 php-ext-source-r2_createinifiles() {
233 local slot
234 for slot in $(php_get_slots); do
235 php_init_slot_env ${slot}
236 # Pull in the PHP settings
237
238 # Build the list of <ext>.ini files to edit/add to
239 php-ext-source-r2_buildinilist ${slot}
240
241 # Add the needed lines to the <ext>.ini files
242 if [[ "${PHP_EXT_INI}" = "yes" ]] ; then
243 php-ext-source-r2_addextension "${PHP_EXT_NAME}.so"
244 fi
245
246 # Symlink the <ext>.ini files from ext/ to ext-active/
247 for inifile in ${PHPINIFILELIST} ; do
248 inidir="${inifile/${PHP_EXT_NAME}.ini/}"
249 inidir="${inidir/ext/ext-active}"
250 dodir "/${inidir}"
251 dosym "/${inifile}" "/${inifile/ext/ext-active}"
252 done
253
254 # Add support for installing PHP files into a version dependant directory
255 PHP_EXT_SHARED_DIR="/usr/share/php/${PHP_EXT_NAME}"
256 done
257 }
258
259 php-ext-source-r2_addextension() {
260 if [[ "${PHP_EXT_ZENDEXT}" = "yes" ]] ; then
261 # We need the full path for ZendEngine extensions
262 # and we need to check for debugging enabled!
263 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[threads]" ; then
264 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]" ; then
265 ext_type="zend_extension_debug_ts"
266 else
267 ext_type="zend_extension_ts"
268 fi
269 ext_file="${EXT_DIR}/${1}"
270 else
271 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]"; then
272 ext_type="zend_extension_debug"
273 else
274 ext_type="zend_extension"
275 fi
276 ext_file="${EXT_DIR}/${1}"
277 fi
278
279 # php-5.3 unifies zend_extension loading and just requires the
280 # zend_extension keyword with no suffix
281 # TODO: drop previous code and this check once <php-5.3 support is
282 # discontinued
283 if has_version '>=dev-lang/php-5.3' ; then
284 ext_type="zend_extension"
285 fi
286 else
287 # We don't need the full path for normal extensions!
288 ext_type="extension"
289 ext_file="${1}"
290 fi
291
292 php-ext-source-r2_addtoinifiles "${ext_type}" "${ext_file}" "Extension added"
293 }
294
295 # $1 - Setting name
296 # $2 - Setting value
297 # $3 - File to add to
298 # $4 - Sanitized text to output
299 php-ext-source-r2_addtoinifile() {
300 if [[ ! -d $(dirname ${3}) ]] ; then
301 mkdir -p $(dirname ${3})
302 fi
303
304 # Are we adding the name of a section?
305 if [[ ${1:0:1} == "[" ]] ; then
306 echo "${1}" >> "${3}"
307 my_added="${1}"
308 else
309 echo "${1}=${2}" >> "${3}"
310 my_added="${1}=${2}"
311 fi
312
313 if [[ -z "${4}" ]] ; then
314 einfo "Added '${my_added}' to /${3}"
315 else
316 einfo "${4} to /${3}"
317 fi
318
319 insinto /$(dirname ${3})
320 doins "${3}"
321 }
322
323 # @FUNCTION: php-ext-source-r2_addtoinifiles
324 # @USAGE: <setting name> <setting value> [message to output]; or just [section name]
325 # @DESCRIPTION:
326 # Add value settings to php.ini file installed by the extension (module).
327 # You can also add a [section], see examples below.
328 #
329 # @CODE
330 # Add some settings for the extension:
331 #
332 # php-ext-source-r2_addtoinifiles "zend_optimizer.optimization_level" "15"
333 # php-ext-source-r2_addtoinifiles "zend_optimizer.enable_loader" "0"
334 # php-ext-source-r2_addtoinifiles "zend_optimizer.disable_licensing" "0"
335 #
336 # Adding values to a section in php.ini file installed by the extension:
337 #
338 # php-ext-source-r2_addtoinifiles "[Debugger]"
339 # php-ext-source-r2_addtoinifiles "debugger.enabled" "on"
340 # php-ext-source-r2_addtoinifiles "debugger.profiler_enabled" "on"
341 # @CODE
342 php-ext-source-r2_addtoinifiles() {
343 local x
344 for x in ${PHPINIFILELIST} ; do
345 php-ext-source-r2_addtoinifile "${1}" "${2}" "${x}" "${3}"
346 done
347 }

  ViewVC Help
Powered by ViewVC 1.1.20