05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

It grabs all the config.m4 files and creates a single configure script that contains all the<br />

configure switches. This means that each extension needs to implement its own<br />

configure checks to check for whatever dependencies and system-level features might<br />

be needed to build the extension.<br />

These checks are done through autoconf macros and general m4 scripting in the<br />

config.m4 file. Your best bet is probably to look at some of the existing config.m4<br />

files in the various <strong>PHP</strong> extensions to see how different types of checks are done.<br />

No External Dependencies<br />

Here is a sample from the simple EXIF extension, which has no external dependencies:<br />

dnl config.m4 for extension exif<br />

<strong>PHP</strong>_ARG_ENABLE(exif, whether to enable exif support,<br />

[ --enable-exif Enable exif support])<br />

if test "$<strong>PHP</strong>_EXIF" != "no"; then<br />

AC_DEFINE(HAVE_EXIF, 1, [Whether you want exif support])<br />

<strong>PHP</strong>_EXTENSION(exif, $ext_shared)<br />

fi<br />

The dnl string indicates a comment line. Here we define HAVE_EXIF if --enable-exif<br />

was given. In our exif.c code, we then surround the whole file with:<br />

#if HAVE_EXIF<br />

...<br />

#endif<br />

This ensures that no EXIF functionality is compiled in unless the feature was<br />

requested. The <strong>PHP</strong>_EXTENSION line enables this extension to be compiled as a shared,<br />

dynamically loadable extension using --enable-exif=shared.<br />

External Dependencies<br />

The libswf extension (which builds Flash animations) requires the libswf library. To<br />

enable it, configure <strong>PHP</strong> with --with-swf. The config.m4 file for libswf must find the<br />

library if it wasn’t supplied via --with-swf=/path/to/lib: for the libswf extension.<br />

dnl config.m4 for extension libswf<br />

<strong>PHP</strong>_ARG_WITH(swf, for libswf support,<br />

[ --with-swf[=DIR] Include swf support])<br />

if test "$<strong>PHP</strong>_SWF" != "no"; then<br />

if test -r $<strong>PHP</strong>_SWF/lib/libswf.a; then<br />

SWF_DIR=$<strong>PHP</strong>_SWF<br />

else<br />

AC_MSG_CHECKING(for libswf in default path)<br />

for i in /usr/local /usr; do<br />

if test -r $i/lib/libswf.a; then<br />

328 | Chapter 14: Extending <strong>PHP</strong><br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!