The config.m4 File

The config.m4 file contains the code that will go into the configure script. This includes the switch that enables the extension (e.g., --enable-rot13 or --with-rot13), the name of the shared library to build, code to search for prerequisite libraries, and much more. The skeletal config.m4 file contains sample code for the various things you might want to do, but it is commented out.

There are conventions governing the configure switch to enable your extension. If your extension does not rely on any external components, use --enable-foo. If it does have some non-bundled dependencies , such as a library, use --with-foo. Optionally, you can specify a base path using --with-foo=/some/path, which helps configure find the dependencies.

PHP uses the grand unifying scheme of autoconf, automake, and libtool to build extensions. These three tools, used together, can be extremely powerful, but they can also be extremely frustrating. Getting this stuff right is a bit of a black art. When an extension is part of the PHP source tree and you run the buildconf script in the top directory of the tree, it scans through all its subdirectories looking for config.m4 files. It grabs all the config.m4 files and creates a single configure script that contains all the configure switches. This means that each extension needs to implement its own configure checks to check for whatever dependencies and system-level features might be needed to build the extension.

These checks are done through ...

Get Programming PHP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.