PHP extension-how to use file config. m4 config. the m4 file is used to specify the options that are supported when developing extensions are built on unix-like systems, specify the libraries and source files required for this extension, and write them using the GNU autoconf syntax.
Note that you need to re-execute phpize to make the modification of config. m4 take effect;
When you execute./configure, all the output will be recorded in config. log. you can debug config. m4 by viewing this file.
For details about how to create a PHP extension from scratch, refer to the article "PHP extension-generation and compilation of extensions,
Common statements and macros of config. m4 files
The following example uses "myext" as the name of the extension being developed:
1. users enter configuration options
For example,-enable-myext,-with-myext-includedir = DIR
PHP_ARG_ENABLE (myext, whether to enable myext support,
[-- Enable-ext Enable ext support])
In configure-help, the output is-enable-ext Enable ext support.
PHP_ARG_WITH (myext-includedir, for myext header,
[-- With-myext-includedir = DIR myext header files], no, no)
In configure-help, the output is-with-myext-includedir = DIR myext header files.
2. output information
AC_MSG_CHECKING (message), which outputs "checking" when executing the configure Command;
AC_MSG_RESULT (value), which outputs the check result;
AC_MSG_ERROR (message): output a message and exit configure execution;
3. Add include path
PHP_ADD_INCLUDE (path) to add the inclusion path during compilation;
4. link to a third-party library
PHP_ADD_LIBRARY_WITH_PATH () to add the link library path during compilation.
PHP_ADD_LIBRARY (), add a link Library;
5. others
AC_DEFINE (name, value, description), add a define to php_config.h: # define name value // description;
AC_TRY_COMPILE (includes, function-body, [action-if-found [, action-if-not-found])
Example:
...AC_MSG_CHECKING(PHP version)...AC_MSG_RESULT([$PHP_VERSION])...PHP_MAJOR_VERSION=`echo $PHP_VERSION | sed -e 's/\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\).*/ \1/g' 2>/dev/null`if test $PHP_MAJOR_VERSION -lt 5; thenAC_MSG_ERROR([need at least PHP 5 or newer])fi...PHP_ADD_INCLUDE([$ext_srcdir/snappy])...PHP_ADD_LIBRARY_WITH_PATH(snappy, $LIBSNAPPY_LIBDIR, SNAPPY_SHARED_LIBADD)...LIBNAME=stdc++PHP_ADD_LIBRARY($LIBNAME, , SNAPPY_SHARED_LIBADD)