פרק 28. PHP's Automatic Build System

In addition to its own sources , each module consists of an M4 file ( for example , see http : / /www.gnu.org / manual / m4 / html_mono / m4.html ) for configuration and a Makefile.in file , which is responsible for compilation (the results of autoconf and automake ; for example , see http : / /sourceware.cygnus.com / autoconf / autoconf.html and http : / /sourceware.cygnus.com / automake / automake.html ) .

Both files are generated automatically , along with .cvsignore , by a little shell script named ext_skel that resides in the ext directory . The shell script then creates a directory of the same name , along with the appropriate config.m4 and Makefile.in files .

 
root@dev

 
:

 
/

 
usr

 
/

 
local

 
/

 
src

 
/

 
php4

 
/

 
ext

 
.

 
/

 
ext_skel

 
my_module

 
Creating

 
directory

 
Creating

 
basic

 
files

 
:

 
config.m4

 
Makefile.in

 
.cvsignore

 
[

 
done

 
]

 
.




 
To

 
use

 
your

 
new

 
extension

 
,

 
you

 
will

 
have

 
to

 
execute

 
the

 
following

 
steps

 
:

 
$

 
cd

 
.

 
.

 
$

 
.

 
/

 
buildconf

 
$

 
.

 
/

 
configure

 
#

 
(

 
your

 
extension

 
is

 
automatically

 
enabled

 
)

 
$

 
vi

 
ext

 
/

 
my_module

 
/

 
my_module.c

 
$

 
make

 
Repeat

 
the

 
last

 
two

 
steps

 
as

 
often

 
as

 
necessary

 
.



This instruction creates the aforementioned files. To include the new module in the automatic configuration and build process, you have to run buildconf , which regenerates the configure script by searching through the ext directory and including all found config.m4 files.

Finally , running configure parses all configuration options and generates a makefile based on those options and the options you specify in Makefile.in .

דוגמה 28-1 shows the previously generated Makefile.in :

דוגמה 28-1 . The default Makefile.in .

 
#

 
$Id

 
:




 
Extending_Zend_Build.xml,v

 
1.6 2002

 
/

 
03

 
/

 
25 08:13:46

 
hholzgra

 
Exp

 
$

 
LTLIBRARY_NAME

 
=

 
libmy_module.la

 
LTLIBRARY_SOURCES

 
=

 
my_module.c

 
LTLIBRARY_SHARED_NAME

 
=

 
my_module.la

 
include

 
$(

 
top_srcdir

 
)

 
/

 
build

 
/

 
dynlib.mk



There ' s not much to tell about this one : It contains the names of the input and output files . You could also specify build instructions for other files if your module is built from multiple source files .

The default config.m4 shown in דוגמה 28-2 ' / is a bit more complex :

דוגמה 28-2 .





 
Extending_Zend_Build.xml,v

 
1.6 2002

 
/

 
03

 
/

 
25 08:13:46

 
hholzgra

 
Exp

 
$

 
dnl

 
config.m4

 
for

 
extension

 
my_module

 
dnl

 
don'

 
t

 
forget

 
to

 
call

 
PHP_EXTENSION(my_module

 
)

 
dnl

 
If

 
your

 
extension

 
references

 
something

 
external

 
,

 
use

 
with

 
:




 
PHP_ARG_WITH(

 
my_module

 
,

 
for

 
my_module

 
support

 
,

 
dnl

 
Make

 
sure

 
that

 
the

 
comment

 
is

 
aligned

 
:

 
[

 
--with-my_module

 
Include

 
my_module

 
support]

 
)

 
dnl

 
Otherwise

 
use

 
enable

 
:




 
PHP_ARG_ENABLE(

 
my_module

 
,

 
whether

 
to

 
enable

 
my_module

 
support

 
,

 
dnl

 
Make

 
sure

 
that

 
the

 
comment

 
is

 
aligned

 
:

 
[

 
--enable-my_module

 
Enable

 
my_module

 
support]

 
)

 
if

 
test

 
"$PHP_MY_MODULE

 
"

 
!=

 
"no"

 
;

 
then

 
dnl

 
Action.

 
.














This would require you to use --enable-my_module each time when reconfiguring and recompiling PHP.

The sample sources on the CD-ROM all have working config.m4 The sample sources on the CD-ROM all have working config.m4 files . To include them into the PHP build process , simply copy the source directories to your PHP ext directory , run buildconf , and then include the sample modules you want by using the appropriate --enable-* directives with configure .