How to use the file config.m4 in PHP

伊谢尔伦
Release: 2016-11-21 14:38:53
Original
1774 people have browsed it

config.m4文件用于指定正在开发的扩展在类unix系统下构建时支持的选项,指定此扩展需要哪些库以及哪些源文件;使用 GNU autoconf 语法编写。
注意需要重新执行phpize,config.m4的修改才会生效;
在执行./configure时,所有的输出将记录到config.log里,通过查看此文件可以调试config.m4。

如何从零开始创建一个PHP扩展可以参见文章PHP扩展-扩展的生成和编译,

config.m4文件常用的语句和宏

以下将以”myext”作为正在开发的扩展名称进行举例:

1. 由用户输入配置选项
比如–enable-myext, –with-myext-includedir=DIR

PHP_ARG_ENABLE(myext, whether to enable myext support,
[ --enable-ext Enable ext support])

在configure –help时将输出:–enable-ext Enable ext support

PHP_ARG_WITH(myext-includedir, for myext header,
[ --with-myext-includedir=DIR myext header files], no, no)

在configure –help时将输出:–with-myext-includedir=DIR myext header files

2. 输出信息
AC_MSG_CHECKING(message), 在执行configure命令时输出”checking “;

AC_MSG_RESULT(value), 输出check的结果;

AC_MSG_ERROR(message), 输出一条消息并退出configure的执行;

3. 添加包含路径
PHP_ADD_INCLUDE(path), 添加编译时的包含路径;

4. 链接第三方库
PHP_ADD_LIBRARY_WITH_PATH(),添加编译时的链接库路径
PHP_ADD_LIBRARY(), 添加链接库;

5. 其他
AC_DEFINE(name,value,description), 向php_config.h添加一个define:#define name value // description;

AC_TRY_COMPILE (includes, function-body, [action-if-found [, action-if-not-found]])

示例如下:

...
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)
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!