In a simple application, you'd probably just add something to your Makefile's CFLAGS and LDFLAGS lines like of the following:
CFLAGS = ${CFLAGS} -I/usr/local/foobar/include LDFLAGS = ${LDFLAGS} -lfoobar -L/usr/local/foobar/lib
Anyone else building your application who doesn't have libfoobar, or has it installed in another location, would get treated to a cryptic error message and left to his own devices to determine what went wrong.
Most OSS applications developed in the past decade or soPHP includedtake advantage of a utility called autoconf to generate a complicated configure script from a set of simple macros. This generated script then does the work of looking for where those dependent libraries and their headers are installed. Based on this information, a package can customize that build line, or provide meaningful error messages before compilation time has been wasted on a configuration that won't work.
In building PHP extensions, whether or not you plan to release them to the public, you'll take advantage of this same autoconf mechanism. Even if you're already familiar with autoconf, take a minute to read through this chapter as PHP includes several custom macros not found in the usual autoconf setup.
Unlike traditional autoconf setups, where a central configure.in file at the base of the package contains all configuration macros, PHP only uses configure.in to manage the coordination of several smaller config.m4 scripts located throughout the source tree, including one for every extension, SAPI, the Core itself, and the Zend Engine.
You've already seen a very simple version of this config.m4 script in previous chapters. In the coming pages, you'll add additional autoconf syntax to this file, allowing more configuration time information to be collected by your extension.
Looking for Libraries |
The PHP Life Cycle
Variables from the Inside Out
Memory Management
Setting Up a Build Environment
Your First Extension
Returning Values
Accepting Parameters
Working with Arrays and HashTables
The Resource Data Type
PHP4 Objects
PHP5 Objects
Startup, Shutdown, and a Few Points in Between
INI Settings
Accessing Streams
Implementing Streams
Diverting the Stream
Configuration and Linking
Extension Generators
Setting Up a Host Environment
Advanced Embedding
Appendix A. A Zend API Reference
Appendix B. PHPAPI
Appendix C. Extending and Embedding Cookbook
Appendix D. Additional Resources