Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 107 lines (68 sloc) 3.168 kb
dd497bd First try at explaining how to create a self-contained extension
Sascha Schumann authored
1 HOW TO CREATE A SELF-CONTAINED PHP EXTENSION
2 $Id$
3
4 A self-contained extension can be distributed independently of
5 the PHP source. To create such an extension, three things are
6 required:
7
8 - Makefile template (Makefile.in)
9 - Configuration file (config.m4)
10 - Source code for your module
11
12 We will describe now how to create these and how to put things
13 together.
14
15
16 SPECIFYING THE EXTENSION
17
18 Our demo extension is called "foobar".
19
20 It consists of two source files "foo.c" and "bar.c"
21 (and any arbitrary amount of header files, but that is not
22 important here).
23
24 The demo extension does not reference any external
25 libraries (that is important, because the user does not
26 need to specify anything).
27
28
29 CREATING THE MAKEFILE TEMPLATE
30
31 The Makefile Template (Makefile.in) contains three lines:
32
33 ------------------------------------------------------------------------------
34 LTLIBRARY_SHARED_NAME = foobar.la
35 LTLIBRARY_SOURCES = foo.c bar.c
36
37 include $(top_srcdir)/build/rules.mk
38 ------------------------------------------------------------------------------
39
40 LTLIBRARY_SHARED_NAME specifies the name of the extension.
41 It must be of the form `ext-name.la'.
42
43 LTLIBRARY_SOURCES specifies the names of the sources files. You can
44 name an arbitrary number of source files here.
45
46 The final include directive includes the build rules (you usually
47 don't need to care about what happens there). rules.mk and other
48 files are installed by phpize which we will cover later.
49
50
51 CREATING THE M4 CONFIGURATION FILE
52
53 The m4 configuration can perform additional checks. For a
54 self-contained extension, you do not need more than a few
55 macro calls.
56
57 ------------------------------------------------------------------------------
58 PHP_ARG_ENABLE(foobar,whether to enable foobar,
59 [ --enable-foobar Enable foobar])
60
61 PHP_EXTENSION(foobar, $ext_shared)
62 ------------------------------------------------------------------------------
63
64 PHP_ARG_ENABLE will automatically set the correct variables, so
65 that the extension will be enabled by PHP_EXTENSION in shared mode.
66
67
68 CREATING SOURCE FILES
69
70 [You are currently alone here. There are a lot of existing modules,
71 use a simply module as a starting point and add your own code.]
72
73
74 CREATING THE SELF-CONTAINED EXTENSION
75
76 Put Makefile.in, config.m4 and the source files into one directory.
77 Then run phpize (this is installed during make install by PHP 4.0).
78 For example, if you configured PHP with --prefix=/php, you would run
79
80 $ /php/bin/phpize
81
82 This will automatically copy the necessary build files and create
83 configure from your config.m4.
84
85 And that's it. You now have a self-contained extension.
86
87 It can be installed by running:
88
89 $ ./configure [--with-php-config=/path/to/php-config]
90 $ make install
91
92 CONVERTING AN EXISTING EXTENSION
93
94 If you want to distribute an extension from the PHP repository, copy
95 all files from the extension's directory to a new directory and
96 run phpize as described above. That's all!
97
98 For example:
99
100 $ dir=/tmp/new_moduke
101 $ cd php4/ext/mysql
102 $ mkdir $dir
103 $ cp -rp * $dir
104 $ cd $dir
105 $ phpize
106
Something went wrong with that request. Please try again.