[php] Fix makefile generated by -make (SF#1633679). Update
documentation to mark "-make" as deprecated (none of the other SWIG backends seem to offer such a feature, it can't realistically generate a fully portable makefile, and the commands to build an extension are easy enough to write for the user's preferred build tool). Also recommend against the use of "-phpfull" (it's only really useful when static linking, and a dynamically loadable module is virtually always the better approach). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10098 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
92b6b2f8c0
commit
ece41d9c9f
3 changed files with 52 additions and 46 deletions
|
|
@ -1,6 +1,16 @@
|
||||||
Version 1.3.32 (in progress)
|
Version 1.3.32 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
11/10/2007: olly
|
||||||
|
[php] Fix makefile generated by -make (SF#1633679). Update
|
||||||
|
documentation to mark "-make" as deprecated (none of the other
|
||||||
|
SWIG backends seem to offer such a feature, it can't realistically
|
||||||
|
generate a fully portable makefile, and the commands to build an
|
||||||
|
extension are easy enough to write for the user's preferred build
|
||||||
|
tool). Also recommend against the use of "-phpfull" (it's only
|
||||||
|
really useful when static linking, and a dynamically loadable
|
||||||
|
module is virtually always the better approach).
|
||||||
|
|
||||||
11/09/2007: olly
|
11/09/2007: olly
|
||||||
Fix --help output to note that `export SWIG_FEATURES' is required.
|
Fix --help output to note that `export SWIG_FEATURES' is required.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,50 +99,57 @@ more detail in <a href="#Php_nn2_6">section 27.2.6</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To finish building the extension, you have two choices. The usual way is
|
The usual (and recommended) way is to build the extension as a separate
|
||||||
to build the extension as a separate dynamically loaded module. You can then
|
dynamically loaded module. You can then specify that this be loaded
|
||||||
specify that this be loaded automatically in <tt>php.ini</tt> or
|
automatically in <tt>php.ini</tt> or load it explicitly for any script which
|
||||||
load it explicitly for any script which needs it. The alternative to
|
needs it.
|
||||||
creating a dynamically loaded module is to
|
</p>
|
||||||
rebuild the entire php source tree and build
|
|
||||||
the extension into the php executable/library so it will be available in every
|
<p>
|
||||||
script. The first choice is the default, however it can be changed by passing
|
It is also possible to rebuild PHP from source so that your module is
|
||||||
the '-phpfull' command line switch to swig to select the second build method.
|
statically linked into the php executable/library. This is a lot more
|
||||||
|
work, and also requires a full rebuild of PHP to update your module,
|
||||||
|
and it doesn't play nicely with package system. We don't recommend
|
||||||
|
this approach, but if you really want to do this, the <tt>-phpfull</tt>
|
||||||
|
command line argument to swig may be of use - see below for details.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H3><a name="Php_nn1_1"></a>27.1.1 Building a loadable extension</H3>
|
<H3><a name="Php_nn1_1"></a>27.1.1 Building a loadable extension</H3>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
There are two methods to build the extension as a dynamically loaded
|
To build your module as a dynamically loadable extension, use compilation
|
||||||
module: using standard compilation utilities (make, gcc), or using
|
commands like these (if you aren't using GCC, the commands will be different,
|
||||||
PHP's <em>phpize</em> utility.
|
and there may be so variation between platforms - these commands should at
|
||||||
|
least work for Linux though):
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
|
||||||
To build manually, use a compile string similar to this (different for each
|
|
||||||
OS):
|
|
||||||
</p>
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
cc -I.. $(PHPINC) -fpic -c example_wrap.c
|
gcc `php-config --includes` -fpic -c example_wrap.c
|
||||||
cc -shared example_wrap.o -o example.so
|
gcc -shared example_wrap.o -o example.so
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The <tt>-make</tt> command line argument to swig will generate an
|
There is a deprecated <tt>-make</tt> command line argument to swig which will
|
||||||
additional file <tt>Makefile</tt> which can usually build the
|
generate an additional file <tt>makefile</tt> which can usually build the
|
||||||
extension itself (on UNIX platforms).
|
extension (at least on some UNIX platforms), but the Makefile generated isn't
|
||||||
|
very flexible, and the commands required are trivial so it is simpler to just
|
||||||
|
add them to your Makefile or other build system directly. We recommend that
|
||||||
|
you don't use <tt>-make</tt> and it's likely to be removed at some point.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<H3><a name="Php_nn1_2"></a>27.1.2 Building extensions into PHP</H3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Note that we don't recommend this approach - it's cleaner and simpler to
|
||||||
|
use dynamically loadable modules, which are supported by all modern OSes.
|
||||||
|
Support for this may be discontinued entirely in the future.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
If you want to build your extension using the <tt>phpize</tt>
|
It is possible to rebuild PHP itself with your module statically linked
|
||||||
utility, or if you want to build your module into PHP directly, you
|
in. To do this, you can use the <tt>-phpfull</tt> command line option to
|
||||||
can specify the <tt>-phpfull</tt> command line argument to swig.
|
swig. Using this option will generate three additional files. The first
|
||||||
</p>
|
extra file, <tt>config.m4</tt> contains the m4 and shell code needed to
|
||||||
|
|
||||||
<p>
|
|
||||||
The <tt>-phpfull</tt> will generate three additional files. The first
|
|
||||||
extra file, <tt>config.m4</tt> contains the shell code needed to
|
|
||||||
enable the extension as part of the PHP build process. The second
|
enable the extension as part of the PHP build process. The second
|
||||||
extra file, <tt>Makefile.in</tt> contains the information needed to
|
extra file, <tt>Makefile.in</tt> contains the information needed to
|
||||||
build the final Makefile after substitutions. The third and final
|
build the final Makefile after substitutions. The third and final
|
||||||
|
|
@ -189,26 +196,16 @@ move it to wherever it is convenient to call from your php script.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Both the <tt>-make</tt> and <tt>-phpfull</tt> arguments accept
|
When using <tt>-phpfull</tt>, swig also accepts the following
|
||||||
additional optional arguments:
|
additional optional arguments:
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><tt>-withincs "<incs>"</tt> Adds include files to the config.m4 file.
|
<li><tt>-withincs "<incs>"</tt> Adds include files to the config.m4 file.
|
||||||
<li><tt>-withlibs "<libs>"</tt> Links the libraries into the shared object.
|
<li><tt>-withlibs "<libs>"</tt> Links with the specified libraries.
|
||||||
<li><tt>-withc "<files>"</tt> Compiles and links the named C files into the shared object.
|
<li><tt>-withc "<files>"</tt> Compiles and links the additional specified C files.
|
||||||
<li><tt>-withcxx "<files>"</tt> Compiles and links the named C++ files into the shared object,
|
<li><tt>-withcxx "<files>"</tt> Compiles and links the additional specified C++ files.
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<H3><a name="Php_nn1_2"></a>27.1.2 Building extensions into PHP</H3>
|
|
||||||
|
|
||||||
|
|
||||||
<p>
|
|
||||||
This method, selected with the <tt>-phpfull</tt> command line switch, involves
|
|
||||||
rebuilding the entire php source tree. Whilst more complicated to build,
|
|
||||||
it does mean that the extension is then available without having to load it
|
|
||||||
in each script.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
After running swig with the <tt>-phpfull</tt> switch, you will be left with a shockingly
|
After running swig with the <tt>-phpfull</tt> switch, you will be left with a shockingly
|
||||||
similar set of files to the previous build process. However you will then need
|
similar set of files to the previous build process. However you will then need
|
||||||
|
|
|
||||||
|
|
@ -319,8 +319,7 @@ public:
|
||||||
Printf(f_make, "CXX_SOURCES=%s\n", withcxx);
|
Printf(f_make, "CXX_SOURCES=%s\n", withcxx);
|
||||||
Printf(f_make, "C_SOURCES=%s\n", withc);
|
Printf(f_make, "C_SOURCES=%s\n", withc);
|
||||||
Printf(f_make, "OBJS=%s_wrap.o $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cxx=.o)\n", module);
|
Printf(f_make, "OBJS=%s_wrap.o $(C_SOURCES:.c=.o) $(CXX_SOURCES:.cxx=.o)\n", module);
|
||||||
Printf(f_make, "MODULE=%s.`php -r 'switch(PHP_SHLIB_SUFFIX){case\"PHP_SHLIB_SUFFIX\":case\"dylib\":echo\"so\";break;default:echo PHP_SHLIB_SUFFIX;}'`\n",
|
Printf(f_make, "MODULE=%s.so\n", module);
|
||||||
module);
|
|
||||||
Printf(f_make, "CFLAGS=-fpic\n");
|
Printf(f_make, "CFLAGS=-fpic\n");
|
||||||
Printf(f_make, "LDFLAGS=-shared\n");
|
Printf(f_make, "LDFLAGS=-shared\n");
|
||||||
Printf(f_make, "PHP_INC=`php-config --includes`\n");
|
Printf(f_make, "PHP_INC=`php-config --includes`\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue