/[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 - (hide annotations) (download)
Sun Jan 9 00:05:10 2011 UTC (3 years, 6 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 olemarkus 1.1 # Copyright 1999-2007 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 robbat2 1.7 # $Header: /var/cvsroot/gentoo-x86/eclass/php-ext-source-r2.eclass,v 1.6 2010/12/27 22:19:51 darkside Exp $
4 olemarkus 1.1 #
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 olemarkus 1.5 inherit flag-o-matic autotools
20 olemarkus 1.1
21 olemarkus 1.4 EXPORT_FUNCTIONS src_unpack src_prepare src_configure src_compile src_install
22 olemarkus 1.1
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 olemarkus 1.3 [[ -z "${USE_PHP}" ]] && USE_PHP="php5-2 php5-3"
64 olemarkus 1.1
65 robbat2 1.7 # @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 olemarkus 1.2 #Make sure at least one target is installed. Abuses USE dependencies.
72 olemarkus 1.3 for target in ${USE_PHP}; do
73     IUSE="${IUSE} php_targets_${target}"
74 olemarkus 1.1 target=${target/+}
75 olemarkus 1.3 SELFDEPEND="${SELFDEPEND} =${CATEGORY}/${PF}[php_targets_${target}]"
76 olemarkus 1.1 slot=${target/php}
77     slot=${slot/-/.}
78 darkside 1.6 PHPDEPEND="${PHPDEPEND}
79 olemarkus 1.3 php_targets_${target}? ( dev-lang/php:${slot} )"
80 olemarkus 1.1 done
81 darkside 1.6
82     RDEPEND="${RDEPEND}
83 robbat2 1.7 ${PHP_EXT_OPTIONAL_USE}${PHP_EXT_OPTIONAL_USE:+? ( }
84 olemarkus 1.3 || ( ${SELFDEPEND} )
85 robbat2 1.7 ${PHPDEPEND}
86     ${PHP_EXT_OPTIONAL_USE:+ )}"
87 olemarkus 1.1
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 darkside 1.6 # php-ext-source-r2_src_unpack
97 olemarkus 1.1 # 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 olemarkus 1.3 cp -r "${orig_s}" "${WORKDIR}/${slot}"
103 olemarkus 1.4 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 olemarkus 1.3 php_init_slot_env ${slot}
110 olemarkus 1.4 php-ext-source-r2_phpize
111 olemarkus 1.1 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 olemarkus 1.4 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 darkside 1.6 fi
128 olemarkus 1.1 }
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 olemarkus 1.3 php_init_slot_env ${slot}
141 olemarkus 1.1 # 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 darkside 1.6 local slot
157 olemarkus 1.1 for slot in $(php_get_slots); do
158 olemarkus 1.3 php_init_slot_env ${slot}
159 olemarkus 1.1 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 olemarkus 1.3 php_init_slot_env ${slot}
175 olemarkus 1.1
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 olemarkus 1.3 local doc
181 olemarkus 1.1 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 olemarkus 1.3 local s slot
192     for slot in ${USE_PHP}; do
193     use php_targets_${slot} && s+=" ${slot/-/.}"
194 olemarkus 1.1 done
195     echo $s
196     }
197    
198     php_init_slot_env() {
199     libdir=$(get_libdir)
200    
201 olemarkus 1.3 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 olemarkus 1.1 PHP_PKG="$(best_version =dev-lang/php-${1:3}*)"
206 olemarkus 1.3 PHPPREFIX="/usr/${libdir}/${slot}"
207 olemarkus 1.1 EXT_DIR="$(${PHPCONFIG} --extension-dir 2>/dev/null)"
208 olemarkus 1.5 PHP_CURRENTSLOT=${1:3}
209 olemarkus 1.1
210 olemarkus 1.3 S="${WORKDIR}/${1}"
211     cd "${S}"
212 olemarkus 1.1 }
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 olemarkus 1.3 local x
222 olemarkus 1.1 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 darkside 1.6 for slot in $(php_get_slots); do
235 olemarkus 1.3 php_init_slot_env ${slot}
236 olemarkus 1.1 # Pull in the PHP settings
237    
238     # Build the list of <ext>.ini files to edit/add to
239 olemarkus 1.3 php-ext-source-r2_buildinilist ${slot}
240 olemarkus 1.1
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 olemarkus 1.5 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[threads]" ; then
264     if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]" ; then
265 olemarkus 1.1 ext_type="zend_extension_debug_ts"
266     else
267     ext_type="zend_extension_ts"
268     fi
269 olemarkus 1.3 ext_file="${EXT_DIR}/${1}"
270 olemarkus 1.1 else
271 olemarkus 1.5 if has_version "dev-lang/php:${PHP_CURRENTSLOT}[debug]"; then
272 olemarkus 1.1 ext_type="zend_extension_debug"
273     else
274     ext_type="zend_extension"
275     fi
276 olemarkus 1.3 ext_file="${EXT_DIR}/${1}"
277 olemarkus 1.1 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 olemarkus 1.3 ext_file="${1}"
290 olemarkus 1.1 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 olemarkus 1.3 if [[ ! -d $(dirname ${3}) ]] ; then
301     mkdir -p $(dirname ${3})
302 olemarkus 1.1 fi
303    
304     # Are we adding the name of a section?
305     if [[ ${1:0:1} == "[" ]] ; then
306 olemarkus 1.3 echo "${1}" >> "${3}"
307     my_added="${1}"
308 olemarkus 1.1 else
309 olemarkus 1.3 echo "${1}=${2}" >> "${3}"
310     my_added="${1}=${2}"
311 olemarkus 1.1 fi
312    
313 olemarkus 1.3 if [[ -z "${4}" ]] ; then
314     einfo "Added '${my_added}' to /${3}"
315 olemarkus 1.1 else
316 olemarkus 1.3 einfo "${4} to /${3}"
317 olemarkus 1.1 fi
318    
319 olemarkus 1.3 insinto /$(dirname ${3})
320     doins "${3}"
321 olemarkus 1.1 }
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 olemarkus 1.3 local x
344 olemarkus 1.1 for x in ${PHPINIFILELIST} ; do
345 olemarkus 1.3 php-ext-source-r2_addtoinifile "${1}" "${2}" "${x}" "${3}"
346 olemarkus 1.1 done
347     }

  ViewVC Help
Powered by ViewVC 1.1.20