Unix Build System配置
开发PHP扩展组件的第一步不是写实现代码,而是要先配置好Build System选项。由于我们是在Linux下开发,所以这里的配置主要与config.m4有关。
关于Build System配置这一块,要是写起来能写一大堆,而且与Unix系统很多东西相关,就算我有兴趣写估计大家也没兴趣看,所以这里我们从略,只拣关键地方说一下,关于config.m4更多细节可以参考这里。
打开生成的config.m4文件,内容大致如下:
dnl $Id$
02 dnl config.m4 for extension say_hello
03
04 dnl Comments in this file start with the string 'dnl'.
05 dnl Remove where necessary. This file will not work
06 dnl without editing.
07
08 dnl If your extension references something external, use with:
09
10 dnl PHP_ARG_WITH(say_hello, for say_hello support,
11 dnl Make sure that the comment is aligned:
12 dnl [ --with-say_hello Include say_hello support])
13
14 dnl Otherwise use enable:
15
16 dnl PHP_ARG_ENABLE(say_hello, whether to enable say_hello support,
17 dnl Make sure that the comment is aligned:
18 dnl [ --enable-say_hello Enable say_hello support])
19
20 if test "$PHP_SAY_HELLO" != "no"; then
21 dnl Write more examples of tests here...
22
23 dnl # --with-say_hello -> check with-path
24 dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
25 dnl SEARCH_FOR="/include/say_hello.h" # you most likely want to change this
26 dnl if test -r $PHP_SAY_HELLO/$SEARCH_FOR; then # path given as parameter
27 dnl SAY_HELLO_DIR=$PHP_SAY_HELLO
28 dnl else # search default path list
29 dnl AC_MSG_CHECKING([for say_hello files in default path])
30 dnl for i in $SEARCH_PATH ; do
31 dnl if test -r $i/$SEARCH_FOR; then
32 dnl SAY_HELLO_DIR=$i
33 dnl AC_MSG_RESULT(found in $i)
34 dnl fi
35 dnl done
36 dnl fi
37 dnl
38 dnl if test -z "$SAY_HELLO_DIR"; then
39 dnl AC_MSG_RESULT([not found])
40 dnl AC_MSG_ERROR([Please reinstall the say_hello distribution])
41 dnl fi
42
43 dnl # --with-say_hello -> add include path
44 dnl PHP_ADD_INCLUDE($SAY_HELLO_DIR/include)
45
46 dnl # --with-say_hello -> check for lib and symbol presence
47 dnl LIBNAME=say_hello # you may want to change this
48 dnl LIBSYMBOL=say_hello # you most likely want to change this
49
50 dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
51 dnl [
52 dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SAY_HELLO_DIR/lib, SAY_HELLO_SHARED_LIBADD)
53 dnl AC_DEFINE(HAVE_SAY_HELLOLIB,1,[ ])
54 dnl ],[
55 dnl AC_MSG_ERROR([wrong say_hello lib version or lib not found])
56 dnl ],[
57 dnl -L$SAY_HELLO_DIR/lib -lm
58 dnl ])
59 dnl
60 dnl PHP_SUBST(SAY_HELLO_SHARED_LIBADD)
61
62 PHP_NEW_EXTENSION(say_hello, say_hello.c, $ext_shared)
63 fi
02 dnl config.m4 for extension say_hello
03
04 dnl Comments in this file start with the string 'dnl'.
05 dnl Remove where necessary. This file will not work
06 dnl without editing.
07
08 dnl If your extension references something external, use with:
09
10 dnl PHP_ARG_WITH(say_hello, for say_hello support,
11 dnl Make sure that the comment is aligned:
12 dnl [ --with-say_hello Include say_hello support])
13
14 dnl Otherwise use enable:
15
16 dnl PHP_ARG_ENABLE(say_hello, whether to enable say_hello support,
17 dnl Make sure that the comment is aligned:
18 dnl [ --enable-say_hello Enable say_hello support])
19
20 if test "$PHP_SAY_HELLO" != "no"; then
21 dnl Write more examples of tests here...
22
23 dnl # --with-say_hello -> check with-path
24 dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
25 dnl SEARCH_FOR="/include/say_hello.h" # you most likely want to change this
26 dnl if test -r $PHP_SAY_HELLO/$SEARCH_FOR; then # path given as parameter
27 dnl SAY_HELLO_DIR=$PHP_SAY_HELLO
28 dnl else # search default path list
29 dnl AC_MSG_CHECKING([for say_hello files in default path])
30 dnl for i in $SEARCH_PATH ; do
31 dnl if test -r $i/$SEARCH_FOR; then
32 dnl SAY_HELLO_DIR=$i
33 dnl AC_MSG_RESULT(found in $i)
34 dnl fi
35 dnl done
36 dnl fi
37 dnl
38 dnl if test -z "$SAY_HELLO_DIR"; then
39 dnl AC_MSG_RESULT([not found])
40 dnl AC_MSG_ERROR([Please reinstall the say_hello distribution])
41 dnl fi
42
43 dnl # --with-say_hello -> add include path
44 dnl PHP_ADD_INCLUDE($SAY_HELLO_DIR/include)
45
46 dnl # --with-say_hello -> check for lib and symbol presence
47 dnl LIBNAME=say_hello # you may want to change this
48 dnl LIBSYMBOL=say_hello # you most likely want to change this
49
50 dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
51 dnl [
52 dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $SAY_HELLO_DIR/lib, SAY_HELLO_SHARED_LIBADD)
53 dnl AC_DEFINE(HAVE_SAY_HELLOLIB,1,[ ])
54 dnl ],[
55 dnl AC_MSG_ERROR([wrong say_hello lib version or lib not found])
56 dnl ],[
57 dnl -L$SAY_HELLO_DIR/lib -lm
58 dnl ])
59 dnl
60 dnl PHP_SUBST(SAY_HELLO_SHARED_LIBADD)
61
62 PHP_NEW_EXTENSION(say_hello, say_hello.c, $ext_shared)
63 fi
不要看这么多,因为所有以“dnl”开头的全是注释,所以真正起作用没几行。这里需要配置的只有下面几行:
01 dnl If your extension references something external, use with:
02
03 dnl PHP_ARG_WITH(say_hello, for say_hello support,
04 dnl Make sure that the comment is aligned:
05 dnl [ --with-say_hello Include say_hello support])
06
07 dnl Otherwise use enable:
08
09 dnl PHP_ARG_ENABLE(say_hello, whether to enable say_hello support,
10 dnl Make sure that the comment is aligned:
11 dnl [ --enable-say_hello Enable say_hello support])
02
03 dnl PHP_ARG_WITH(say_hello, for say_hello support,
04 dnl Make sure that the comment is aligned:
05 dnl [ --with-say_hello Include say_hello support])
06
07 dnl Otherwise use enable:
08
09 dnl PHP_ARG_ENABLE(say_hello, whether to enable say_hello support,
10 dnl Make sure that the comment is aligned:
11 dnl [ --enable-say_hello Enable say_hello support])
我想大家也都能看明白,意思就是“如果你的扩展引用了外部组件,使用…,否则使用…”。我们的say_hello扩展并没有引用外部组件,所以将“Otherwise use enable”下面三行的“dnl”去掉,改为:
1 dnl Otherwise use enable:
2
3 PHP_ARG_ENABLE(say_hello, whether to enable say_hello support,
4 Make sure that the comment is aligned:
5 [ --enable-say_hello Enable say_hello support])
2
3 PHP_ARG_ENABLE(say_hello, whether to enable say_hello support,
4 Make sure that the comment is aligned:
5 [ --enable-say_hello Enable say_hello support])
保存,这样关于Build System配置就大功告成了。