將 PECL 增加庫靜態編譯入 PHP

有時可能需要將增加庫靜態編譯到 PHP 中。這需要將增加庫源程式放入 php-src/ext/ 目錄中去並告訴 PHP 編譯系統來建立其配置腳本。

$ cd /your/phpsrcdir/ext
$ pear download extname
$ gzip -d < extname.tgz | tar -xvf -
$ mv extname-x.x.x extname

這將產生以下目錄:

/your/phpsrcdir/ext/extname

此時強制 PHP 重新建立配置腳本,然後標準編譯 PHP:

$ cd /your/phpsrcdir
$ rm configure
$ ./buildconf --force
$ ./configure --help
$ ./configure --with-extname --enable-someotherext --with-foobar
$ make
$ make install

注: 要運行「buildconf」腳本,需要 autoconf 2.13 和 automake 1.4+(更新版本的 autoconf 也許能工作,但不被支援)。

是否用 --enable-extname--with-extname 取決於增加庫。通常不需要外部庫檔案的增加庫使用 --enable。要確認的話,在 buildconf 之後運行:

$ ./configure --help | grep extname