Skip to content

Latest commit

 

History

History
79 lines (59 loc) · 3.73 KB

6.PHP5构建系统 [ The PHP 5 build system ].md

File metadata and controls

79 lines (59 loc) · 3.73 KB
/*
|----------------------------------------
| The PHP 5 build system
| @weiChen translate, <farwish@live.com>
| @MIT License
*/

http://php.net/manual/en/internals2.buildsys.php

PHP5有所有的功能和灵活性,所以它包含数千行个文件和超过一百万行源码并不奇怪。
此外,管理如此多数据的构建系统是必要的。这节描述了如何针对扩展开发设置PHP,
PHP源码树中的扩展布局,和如何用构建系统结合你的扩展。

针对扩展开发构建PHP [ Building PHP for extension development ]

===

在一个典型的PHP安装中,高性能的需求大部分总是以调试机制为代价做优化。
这是针对生产使用的合理的折中,但当开发一个扩展时,它已经不能适应。
我们需要的是构建PHP遇到错误时能给我们一些提示。

Zend引擎提供一个内存管理器,它对追踪扩展中的内存泄露和提供调试细节信息提供可能。
这个追踪默认是关闭的,由于线程安全。要开启它们,configure 需要传递 --enable-debug
--enable-maintainer-zts 选项,和平常使用的选项一起。
从源码构建PHP的介绍在 http://php.net/manual/en/install.general.php。
一个典型的 configure 像这样:

./configure --prefix=/where/to/install/php --enable-debug  
--enable-maintainer-zts --enable-cgi --with-mysql=/path/to/mysql

ext_skel脚本 [ The ext_skel script ]

===

一个PHP扩展由几个所有扩展共同的文件组成。扩展间许多文件的细节是相似的,
为每一个扩展复制这些内容是艰难的。幸运地,有一个可以做所有初始化设置的脚本给你。
它是 ext_skel,自PHP4.0开始分发。

在PHP5.2.2中不带参数运行ext_skel输出这些:

php-5.2.2/ext$ ./ext_skel 
./ext_skel --extname=module [--proto=file] [--stubs=file] [--xml[=file]]
           [--skel=dir] [--full-xml] [--no-help]

  --extname=module   module is the name of your extension
  --proto=file       file contains prototypes of functions to create
  --stubs=file       generate only function stubs in file
  --xml              generate xml documentation to be added to phpdoc-cvs
  --skel=dir         path to the skeleton directory
  --full-xml         generate xml documentation for a self-contained extension
                     (not yet implemented)
  --no-help          don't try to be nice and create comments in the code
                     and helper functions to test if the module compiled

一般地,当开发一个新的扩展时,你需要插入的唯一参数是 --extname--no-help
除非你已经对一个扩展的结构有经验了,你可以不使用 --no-help; 具体就是 ext_skel 会在生成的文件中忽略许多帮助信息。
使用 --extname,告诉 ext_skel 扩展的名字。这个名字是仅包含字母和下划线的全小写的标示符,
并且在发布的PHP ext/ 目录内唯一。

--proto 选项允许开发者指定创建的PHP函数的头文件,表面上是为了基于一个库开发扩展,
但往往用现代化头文件功能不是很好。测试运行头文件 zlib.h 将在 ext_skel 生成许多空的和无意义的原型。
--xml--full-xml 选项到目前为止完全没用。--skel 选项可以用来指定要使用的要修改的骨架文件,此话题超出了这节的范围。

UNIX构建系统:config.m4 [ Talking to the UNIX build system: config.m4 ]

===

扩展的 config.m4 文件告诉UNIX构建系统你的扩展支持哪些 configure 选项,需要哪些外部库和包含,
哪些源文件将编译为扩展的一部分。

Windows构建系统:config.w32 [ Talking to the Windows build system: config.w32 ]

===