<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >PHP's Automatic Build System</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="Manual PHP" HREF="index.html"><LINK REL="UP" TITLE="Zend API" HREF="zend.html"><LINK REL="PREVIOUS" TITLE="Complex Types" HREF="zend.layout.complex-types.html"><LINK REL="NEXT" TITLE="Creating Extensions" HREF="zend.creating.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-2"></HEAD ><BODY CLASS="chapter" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="zend.layout.complex-types.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="zend.creating.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="chapter" ><H1 ><A NAME="zend.build" >Cap. 29. PHP's Automatic Build System</A ></H1 ><P > PHP 4 features an automatic build system that's very flexible. All modules reside in a subdirectory of the <TT CLASS="filename" >ext</TT > directory. In addition to its own sources, each module consists of a config.m4 file, for extension configuration. (for example, see <A HREF="http://www.gnu.org/manual/m4/html_mono/m4.html" TARGET="_top" >http://www.gnu.org/manual/m4/html_mono/m4.html</A >) </P ><P > All these stub files are generated automatically, along with <TT CLASS="filename" >.cvsignore</TT >, by a little shell script named <TT CLASS="filename" >ext_skel</TT > that resides in the <TT CLASS="filename" >ext</TT > directory. As argument it takes the name of the module that you want to create. The shell script then creates a directory of the same name, along with the appropriate stub files. </P ><P > Step by step, the process looks like this: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >:~/cvs/php4/ext:> ./ext_skel --extname=my_module Creating directory my_module Creating basic files: config.m4 .cvsignore my_module.c php_my_module.h CREDITS EXPERIMENTAL tests/001.phpt my_module.php [done]. To use your new extension, you will have to execute the following steps: 1. $ cd .. 2. $ vi ext/my_module/config.m4 3. $ ./buildconf 4. $ ./configure --[with|enable]-my_module 5. $ make 6. $ ./php -f ext/my_module/my_module.php 7. $ vi ext/my_module/my_module.c 8. $ make Repeat steps 3-6 until you are satisfied with ext/my_module/config.m4 and step 6 confirms that your module is compiled into PHP. Then, start writing code and repeat the last two steps as often as necessary.</PRE ></TD ></TR ></TABLE > This instruction creates the aforementioned files. To include the new module in the automatic configuration and build process, you have to run <TT CLASS="filename" >buildconf</TT >, which regenerates the <TT CLASS="filename" >configure</TT > script by searching through the <TT CLASS="filename" >ext</TT > directory and including all found <TT CLASS="filename" >config.m4</TT > files. </P ><P > The default <TT CLASS="filename" >config.m4</TT > shown in <A HREF="zend.build.html#example.config.m4" >Exemplu 29-1</A > is a bit more complex: </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="example.config.m4" ></A ><P ><B >Exemplu 29-1. The default <TT CLASS="filename" >config.m4</TT >.</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >dnl $Id: Extending_Zend_Build.xml,v 1.8 2002/10/10 18:13:11 imajes Exp $ dnl config.m4 for extension my_module dnl Comments in this file start with the string 'dnl'. dnl Remove where necessary. This file will not work dnl without editing. dnl If your extension references something external, use with: dnl PHP_ARG_WITH(my_module, for my_module support, dnl Make sure that the comment is aligned: dnl [ --with-my_module Include my_module support]) dnl Otherwise use enable: dnl PHP_ARG_ENABLE(my_module, whether to enable my_module support, dnl Make sure that the comment is aligned: dnl [ --enable-my_module Enable my_module support]) if test "$PHP_MY_MODULE" != "no"; then dnl Write more examples of tests here... dnl # --with-my_module -> check with-path dnl SEARCH_PATH="/usr/local /usr" # you might want to change this dnl SEARCH_FOR="/include/my_module.h" # you most likely want to change this dnl if test -r $PHP_MY_MODULE/; then # path given as parameter dnl MY_MODULE_DIR=$PHP_MY_MODULE dnl else # search default path list dnl AC_MSG_CHECKING([for my_module files in default path]) dnl for i in $SEARCH_PATH ; do dnl if test -r $i/$SEARCH_FOR; then dnl MY_MODULE_DIR=$i dnl AC_MSG_RESULT(found in $i) dnl fi dnl done dnl fi dnl dnl if test -z "$MY_MODULE_DIR"; then dnl AC_MSG_RESULT([not found]) dnl AC_MSG_ERROR([Please reinstall the my_module distribution]) dnl fi dnl # --with-my_module -> add include path dnl PHP_ADD_INCLUDE($MY_MODULE_DIR/include) dnl # --with-my_module -> chech for lib and symbol presence dnl LIBNAME=my_module # you may want to change this dnl LIBSYMBOL=my_module # you most likely want to change this dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, dnl [ dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $MY_MODULE_DIR/lib, MY_MODULE_SHARED_LIBADD) dnl AC_DEFINE(HAVE_MY_MODULELIB,1,[ ]) dnl ],[ dnl AC_MSG_ERROR([wrong my_module lib version or lib not found]) dnl ],[ dnl -L$MY_MODULE_DIR/lib -lm -ldl dnl ]) dnl dnl PHP_SUBST(MY_MODULE_SHARED_LIBADD) PHP_NEW_EXTENSION(my_module, my_module.c, $ext_shared) fi</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P > If you're unfamiliar with M4 files (now is certainly a good time to get familiar), this might be a bit confusing at first; but it's actually quite easy. </P ><P > <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Note:</I ></SPAN > Everything prefixed with <VAR CLASS="literal" >dnl</VAR > is treated as a comment and is not parsed. </P ><P > The <TT CLASS="filename" >config.m4</TT > file is responsible for parsing the command-line options passed to <TT CLASS="filename" >configure</TT > at configuration time. This means that it has to check for required external files and do similar configuration and setup tasks. </P ><P > The default file creates two configuration directives in the <TT CLASS="filename" >configure</TT > script: <VAR CLASS="literal" >--with-my_module</VAR > and <VAR CLASS="literal" >--enable-my_module</VAR >. Use the first option when referring external files (such as the <VAR CLASS="literal" >--with-apache</VAR > directive that refers to the Apache directory). Use the second option when the user simply has to decide whether to enable your extension. Regardless of which option you use, you should uncomment the other, unnecessary one; that is, if you're using <VAR CLASS="literal" >--enable-my_module</VAR >, you should remove support for <VAR CLASS="literal" >--with-my_module</VAR >, and vice versa. </P ><P > By default, the <TT CLASS="filename" >config.m4</TT > file created by <TT CLASS="filename" >ext_skel</TT > accepts both directives and automatically enables your extension. Enabling the extension is done by using the <VAR CLASS="literal" >PHP_EXTENSION</VAR > macro. To change the default behavior to include your module into the PHP binary when desired by the user (by explicitly specifying <VAR CLASS="literal" >--enable-my_module</VAR > or <VAR CLASS="literal" >--with-my_module</VAR >), change the test for <VAR CLASS="literal" >$PHP_MY_MODULE</VAR > to <VAR CLASS="literal" >== "yes"</VAR >: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="programlisting" >if test "$PHP_MY_MODULE" == "yes"; then dnl Action.. PHP_EXTENSION(my_module, $ext_shared) fi</PRE ></TD ></TR ></TABLE >This would require you to use <VAR CLASS="literal" >--enable-my_module</VAR > each time when reconfiguring and recompiling PHP. </P ><P > <SPAN CLASS="emphasis" ><I CLASS="emphasis" >Note:</I ></SPAN > Be sure to run <TT CLASS="filename" >buildconf</TT > every time you change <TT CLASS="filename" >config.m4</TT >! </P ><P > We'll go into more details on the M4 macros available to your configuration scripts later in this chapter. For now, we'll simply use the default files. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="zend.layout.complex-types.html" ACCESSKEY="P" >Înapoi</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Acasã</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="zend.creating.html" ACCESSKEY="N" >Înainte</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Complex Types</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="zend.html" ACCESSKEY="U" >Sus</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Creating Extensions</TD ></TR ></TABLE ></DIV ></BODY ></HTML >