| 1 | # Copyright 1999-2005 Gentoo Foundation |
1 | # Copyright 1999-2005 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/depend.php.eclass,v 1.2 2005/09/04 15:15:37 swegener Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/depend.php.eclass,v 1.3 2005/09/11 16:39:10 hollow Exp $ |
| 4 | # |
4 | # |
| 5 | # ======================================================================== |
5 | # ======================================================================== |
| 6 | # |
6 | # |
| 7 | # depend.php.eclass |
7 | # depend.php.eclass |
| 8 | # functions to allow ebuilds to depend on php4 and/or php5 |
8 | # functions to allow ebuilds to depend on php4 and/or php5 |
| … | |
… | |
| 116 | # |
116 | # |
| 117 | # this function will disappear when USE-based deps are supported by |
117 | # this function will disappear when USE-based deps are supported by |
| 118 | # Portage |
118 | # Portage |
| 119 | # |
119 | # |
| 120 | # $1 ... a list of SAPI USE flags (eg cli, cgi, apache2) |
120 | # $1 ... a list of SAPI USE flags (eg cli, cgi, apache2) |
| 121 | # |
121 | # |
| 122 | # returns if any one of the listed SAPIs has been installed |
122 | # returns if any one of the listed SAPIs has been installed |
| 123 | # dies if none of the listed SAPIs has been installed |
123 | # dies if none of the listed SAPIs has been installed |
| 124 | |
124 | |
| 125 | require_php_sapi_from() { |
125 | require_php_sapi_from() |
|
|
126 | { |
| 126 | has_php |
127 | has_php |
| 127 | |
128 | |
| 128 | local has_sapi=0 |
129 | local has_sapi=0 |
| 129 | local x |
130 | local x |
| 130 | |
131 | |
| … | |
… | |
| 155 | # |
156 | # |
| 156 | # this function will disappear when USE-based deps are supported by |
157 | # this function will disappear when USE-based deps are supported by |
| 157 | # Portage |
158 | # Portage |
| 158 | # |
159 | # |
| 159 | # $1 ... a list of USE flags |
160 | # $1 ... a list of USE flags |
| 160 | # |
161 | # |
| 161 | # returns if all of the listed USE flags are set |
162 | # returns if all of the listed USE flags are set |
| 162 | # dies if any of the listed USE flags are not set |
163 | # dies if any of the listed USE flags are not set |
| 163 | |
164 | |
| 164 | require_php_with_use() { |
165 | require_php_with_use() |
|
|
166 | { |
| 165 | has_php |
167 | has_php |
| 166 | |
168 | |
| 167 | local missing_use= |
169 | local missing_use= |
| 168 | local x |
170 | local x |
| 169 | |
171 | |
| … | |
… | |
| 187 | eerror " $@" |
189 | eerror " $@" |
| 188 | eerror |
190 | eerror |
| 189 | die "Re-install ${PHP_PKG}" |
191 | die "Re-install ${PHP_PKG}" |
| 190 | } |
192 | } |
| 191 | |
193 | |
| 192 | # call this function from your src_compile & src_install methods |
194 | # call this function from your pkg_setup, src_compile & src_install methods |
| 193 | # if you need to know where the PHP binaries are installed |
195 | # if you need to know where the PHP binaries are installed and their data |
| 194 | |
196 | |
| 195 | has_php() |
197 | has_php() |
| 196 | { |
198 | { |
| 197 | # if PHP_PKG is set, then we have remembered our PHP settings |
199 | # if PHP_PKG is set, then we have remembered our PHP settings |
| 198 | # from last time |
200 | # from last time |
|
|
201 | |
| 199 | if [[ -n ${PHP_PKG} ]]; then |
202 | if [[ -n ${PHP_PKG} ]]; then |
| 200 | return |
203 | return |
| 201 | fi |
204 | fi |
| 202 | |
205 | |
| 203 | if [[ -z ${PHP_VERSION} ]]; then |
206 | if [[ -z ${PHP_VERSION} ]]; then |
| … | |
… | |
| 221 | # has_*() functions |
224 | # has_*() functions |
| 222 | # |
225 | # |
| 223 | # these functions return 0 if the condition is satisfied, or 1 otherwise |
226 | # these functions return 0 if the condition is satisfied, or 1 otherwise |
| 224 | # ======================================================================== |
227 | # ======================================================================== |
| 225 | |
228 | |
|
|
229 | # check if our PHP was compiled with ZTS (Zend Thread Safety) |
|
|
230 | |
| 226 | has_zts() |
231 | has_zts() |
| 227 | { |
232 | { |
| 228 | has_php |
233 | has_php |
| 229 | |
234 | |
| 230 | if built_with_use =${PHP_PKG} apache2 threads ; then |
235 | if built_with_use =${PHP_PKG} apache2 threads ; then |
| … | |
… | |
| 232 | fi |
237 | fi |
| 233 | |
238 | |
| 234 | return 1 |
239 | return 1 |
| 235 | } |
240 | } |
| 236 | |
241 | |
|
|
242 | # check if our PHP was built with Hardened-PHP active |
|
|
243 | |
|
|
244 | has_hardenedphp() |
|
|
245 | { |
|
|
246 | has_php |
|
|
247 | |
|
|
248 | if built_with_use =${PHP_PKG} hardenedphp ; then |
|
|
249 | return 0 |
|
|
250 | fi |
|
|
251 | |
|
|
252 | return 1 |
|
|
253 | } |
|
|
254 | |
| 237 | # ======================================================================== |
255 | # ======================================================================== |
| 238 | # require_*() functions |
256 | # require_*() functions |
| 239 | # |
257 | # |
| 240 | # These functions die() if PHP was built without the required USE flag(s) |
258 | # These functions die() if PHP was built without the required USE flag(s) |
| 241 | # ======================================================================== |
259 | # ======================================================================== |
|
|
260 | |
|
|
261 | # require a PHP built with PDO support for PHP5 |
| 242 | |
262 | |
| 243 | require_pdo() |
263 | require_pdo() |
| 244 | { |
264 | { |
| 245 | has_php |
265 | has_php |
| 246 | |
266 | |
| 247 | # do we have php5.1 installed? |
267 | # do we have php5.1 installed? |
| 248 | |
268 | |
| 249 | if [[ ${PHP_VERSION} == 4 ]] ; then |
269 | if [[ ${PHP_VERSION} == 4 ]] ; then |
| 250 | eerror |
270 | eerror |
|
|
271 | eerror "This package requires PDO." |
| 251 | eerror "This package requires PDO. PDO is only available for PHP 5." |
272 | eerror "PDO is only available for PHP 5." |
| 252 | eerror "Please install dev-lang/php-5*" |
273 | eerror "Please install dev-lang/php-5*" |
| 253 | eerror |
274 | eerror |
| 254 | die "PHP 5 not installed" |
275 | die "PHP 5 not installed" |
| 255 | fi |
276 | fi |
| 256 | |
277 | |
| … | |
… | |
| 264 | |
285 | |
| 265 | if built_with_use =${PHP_PKG} pdo-external && has_version dev-php5/pecl-pdo ; then |
286 | if built_with_use =${PHP_PKG} pdo-external && has_version dev-php5/pecl-pdo ; then |
| 266 | return |
287 | return |
| 267 | fi |
288 | fi |
| 268 | |
289 | |
| 269 | # it suffices that pecl-pdo was installed to have PDO support |
290 | # ok, as last resort, it suffices that pecl-pdo was installed to have PDO support |
| 270 | |
291 | |
| 271 | if has_version dev-php5/pecl-pdo ; then |
292 | if has_version dev-php5/pecl-pdo ; then |
| 272 | return |
293 | return |
| 273 | fi |
294 | fi |
| 274 | |
295 | |
| 275 | # if we get here, then we have no PDO support :( |
296 | # if we get here, then we have no PDO support |
| 276 | |
297 | |
| 277 | eerror |
298 | eerror |
| 278 | eerror "No PDO extension for PHP found." |
299 | eerror "No PDO extension for PHP found." |
| 279 | eerror "Please note that PDO only exists for PHP 5." |
300 | eerror "Please note that PDO only exists for PHP 5." |
| 280 | eerror "Please install a PDO extension for PHP 5," |
301 | eerror "Please install a PDO extension for PHP 5," |
| … | |
… | |
| 282 | eerror "the 'pdo-external' USE flag or you must" |
303 | eerror "the 'pdo-external' USE flag or you must" |
| 283 | eerror "install dev-lang/php-5.1* with either" |
304 | eerror "install dev-lang/php-5.1* with either" |
| 284 | eerror "the 'pdo' or the 'pdo-external' USE flags" |
305 | eerror "the 'pdo' or the 'pdo-external' USE flags" |
| 285 | eerror "turned on." |
306 | eerror "turned on." |
| 286 | eerror |
307 | eerror |
| 287 | die "No PDO extension found for PHP" |
308 | die "No PDO extension found for PHP 5" |
| 288 | } |
309 | } |
| 289 | |
310 | |
| 290 | # determines which installed PHP version has the CLI sapi |
311 | # determines which installed PHP version has the CLI sapi |
| 291 | # useful for PEAR eclass, or anything which needs to run PHP |
312 | # useful for PEAR eclass, or anything which needs to run PHP |
| 292 | # scripts |
313 | # scripts depending on the cli sapi |
| 293 | |
314 | |
| 294 | require_php_cli() |
315 | require_php_cli() |
| 295 | { |
316 | { |
| 296 | # if PHP_PKG is set, then we have remembered our PHP settings |
317 | # if PHP_PKG is set, then we have remembered our PHP settings |
| 297 | # from last time |
318 | # from last time |
|
|
319 | |
| 298 | if [[ -n ${PHP_PKG} ]]; then |
320 | if [[ -n ${PHP_PKG} ]]; then |
| 299 | return |
321 | return |
| 300 | fi |
322 | fi |
| 301 | |
323 | |
| 302 | # detect which PHP version installed |
324 | # detect which PHP version installed |
| … | |
… | |
| 318 | die "No PHP CLI installed" |
340 | die "No PHP CLI installed" |
| 319 | fi |
341 | fi |
| 320 | |
342 | |
| 321 | # if we get here, then PHP_VERSION tells us which version of PHP we |
343 | # if we get here, then PHP_VERSION tells us which version of PHP we |
| 322 | # want to use |
344 | # want to use |
|
|
345 | |
| 323 | uses_php${PHP_VERSION} |
346 | uses_php${PHP_VERSION} |
| 324 | } |
347 | } |
| 325 | |
348 | |
|
|
349 | # determines which installed PHP version has the CGI sapi |
|
|
350 | # useful for anything which needs to run PHP scripts |
|
|
351 | # depending on the cgi sapi |
|
|
352 | |
|
|
353 | require_php_cgi() |
|
|
354 | { |
|
|
355 | # if PHP_PKG is set, then we have remembered our PHP settings |
|
|
356 | # from last time |
|
|
357 | |
|
|
358 | if [[ -n ${PHP_PKG} ]]; then |
|
|
359 | return |
|
|
360 | fi |
|
|
361 | |
|
|
362 | # detect which PHP version installed |
|
|
363 | if has_version '=dev-lang/php-5*' ; then |
|
|
364 | pkg="`best_version '=dev-lang/php-5*'`" |
|
|
365 | if built_with_use =${pkg} cgi ; then |
|
|
366 | PHP_VERSION=5 |
|
|
367 | fi |
|
|
368 | elif has_version '=dev-lang/php-4*' ; then |
|
|
369 | pkg="`best_version '=dev-lang/php-4*'`" |
|
|
370 | if built_with_use =${pkg} cgi ; then |
|
|
371 | PHP_VERSION=4 |
|
|
372 | fi |
|
|
373 | else |
|
|
374 | die "Unable to find an installed dev-lang/php package" |
|
|
375 | fi |
|
|
376 | |
|
|
377 | if [[ -z ${PHP_VERSION} ]]; then |
|
|
378 | die "No PHP CGI installed" |
|
|
379 | fi |
|
|
380 | |
|
|
381 | # if we get here, then PHP_VERSION tells us which version of PHP we |
|
|
382 | # want to use |
|
|
383 | |
|
|
384 | uses_php${PHP_VERSION} |
|
|
385 | } |
|
|
386 | |
| 326 | # require a PHP built with sqlite support |
387 | # require a PHP built with sqlite support |
| 327 | |
388 | |
| 328 | require_sqlite() |
389 | require_sqlite() |
| 329 | { |
390 | { |
| 330 | has_php |
391 | has_php |
| 331 | |
392 | |
| 332 | # has our PHP been built w/ sqlite? |
393 | # has our PHP been built with sqlite? |
|
|
394 | |
| 333 | if built_with_use =${PHP_PKG} sqlite ; then |
395 | if built_with_use =${PHP_PKG} sqlite ; then |
| 334 | return |
396 | return |
| 335 | fi |
397 | fi |
| 336 | |
398 | |
| 337 | # do we have pecl-sqlite installed for PHP4? |
399 | # do we have pecl-sqlite installed for PHP 4? |
|
|
400 | |
| 338 | if [[ ${PHP_VERSION} == 4 ]] ; then |
401 | if [[ ${PHP_VERSION} == 4 ]] ; then |
| 339 | if has_version dev-php4/pecl-sqlite ; then |
402 | if has_version dev-php4/pecl-sqlite ; then |
| 340 | return |
403 | return |
| 341 | fi |
404 | fi |
| 342 | fi |
405 | fi |
| 343 | |
406 | |
| 344 | # if we get here, then we don't have any php/sqlite support installed |
407 | # if we get here, then we don't have any sqlite support for PHP installed |
|
|
408 | |
| 345 | eerror |
409 | eerror |
| 346 | eerror "No sqlite extension for PHP found." |
410 | eerror "No sqlite extension for PHP found." |
| 347 | eerror "Please install an sqlite extension for PHP," |
411 | eerror "Please install an sqlite extension for PHP," |
| 348 | eerror "this is done best by simply adding the" |
412 | eerror "this is done best by simply adding the" |
| 349 | eerror "'sqlite' USE flag when emerging dev-lang/php." |
413 | eerror "'sqlite' USE flag when emerging dev-lang/php." |
| 350 | eerror |
414 | eerror |
| 351 | die "No sqlite extension for PHP found" |
415 | die "No sqlite extension for PHP found" |
| 352 | } |
416 | } |
|
|
417 | |
|
|
418 | require_gd() |
|
|
419 | { |
|
|
420 | has_php |
|
|
421 | |
|
|
422 | # do we have the internal GD support installed? |
|
|
423 | |
|
|
424 | if built_with_use =${PHP_PKG} gd ; then |
|
|
425 | return |
|
|
426 | fi |
|
|
427 | |
|
|
428 | # ok, maybe GD was built using the external support? |
|
|
429 | |
|
|
430 | if built_with_use =${PHP_PKG} gd-external ; then |
|
|
431 | return |
|
|
432 | fi |
|
|
433 | |
|
|
434 | # if we get here, then we have no GD support |
|
|
435 | |
|
|
436 | eerror |
|
|
437 | eerror "No GD support for PHP found." |
|
|
438 | eerror "Please install the GD support for PHP," |
|
|
439 | eerror "you must install dev-lang/php with either" |
|
|
440 | eerror "the 'gd' or the 'gd-external' USE flags" |
|
|
441 | eerror "turned on." |
|
|
442 | eerror |
|
|
443 | die "No GD support found for PHP" |
|
|
444 | } |