[PHP] The deprecated command line option "-phpfull" has been

removed.  We recommend building your extension as a dynamically
loadable module.


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10637 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2008-07-03 02:32:11 +00:00
commit 7893f114a4
3 changed files with 63 additions and 412 deletions

View file

@ -1,6 +1,11 @@
Version 1.3.36 (in progress)
=============================
2008-07-03: olly
[PHP] The deprecated command line option "-phpfull" has been
removed. We recommend building your extension as a dynamically
loadable module.
2008-07-02: olly
[PHP4] Support for PHP4 has been removed. The PHP developers are
no longer making new PHP4 releases, and won't even be patching
@ -10,5 +15,6 @@ Version 1.3.36 (in progress)
[Python] Import the C extension differently for Python 2.6 and
later so that an implicit relative import doesn't produce a
deprecation warning for 2.6 and a failure for 2.7 and later.
Patch from Richard Boulton in SF#2008229.
Patch from Richard Boulton in SF#2008229, plus follow-up patches
from Richard and Haoyu Bai.

View file

@ -91,7 +91,7 @@ you wish to statically link the extension into the php interpreter.
The third file,
<tt>example.php</tt> can be included by PHP scripts. It attempts to
dynamically load the extension and contains extra php code specified
in the interface file. If wrapping C++ code for PHP5, it will
in the interface file. If wrapping C++ code with PHP classes, it will
also contain PHP5 class wrappers.
</p>
@ -103,7 +103,8 @@ more detail in <a href="#Php_nn2_6">section 27.2.6</a>.
<p>
The usual (and recommended) way is to build the extension as a separate
dynamically loaded module. You can then specify that this be loaded
dynamically loaded module (which is supported by all modern operating
systems). You can then specify that this be loaded
automatically in <tt>php.ini</tt> or load it explicitly for any script which
needs it.
</p>
@ -113,17 +114,15 @@ It is also possible to rebuild PHP from source so that your module is
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.
this approach, or provide explicit support for it.
</p>
<H3><a name="Php_nn1_1"></a>28.1.1 Building a loadable extension</H3>
<p>
To build your module as a dynamically loadable extension, use compilation
commands like these (if you aren't using GCC, the commands will be different,
and there may be so variation between platforms - these commands should at
and there may be some variation between platforms - these commands should at
least work for Linux though):
</p>
@ -141,128 +140,9 @@ 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>28.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>
It is possible to rebuild PHP itself with your module statically linked
in. To do this, you can use the <tt>-phpfull</tt> command line option to
swig. Using this option will generate three additional files. The first
extra file, <tt>config.m4</tt> contains the m4 and shell code needed to
enable the extension as part of the PHP build process. The second
extra file, <tt>Makefile.in</tt> contains the information needed to
build the final Makefile after substitutions. The third and final
extra file, <tt>CREDITS</tt> should contain the credits for the
extension.
</p>
<p>
To build with phpize, after you have run swig you will need to run the
'phpize' command (installed as part of php) in the same
directory. This re-creates the php build environment in that
directory. It also creates a configure file which includes the shell
code from the config.m4 that was generated by SWIG, this configure
script will accept a command line argument to enable the extension to
be run (by default the command line argument is --enable-modulename,
however you can edit the config.m4 file before running phpize to
accept --with-modulename. You can also add extra tests in config.m4 to
check that a correct library version is installed or correct header
files are included, etc, but you must edit this file before running
phpize.) You can also get SWIG to generate simple extra tests for
libraries and header files for you.
</p>
<div class="code"><pre>
swig -php -phpfull
</pre></div>
<p>
If you depend on source files not generated by SWIG, before generating
the configure file, you may need to edit the <tt>Makefile.in</tt>
file. This contains the names of the source files to compile (just the
wrapper file by default) and any additional libraries needed to be
linked in. If there are extra C files to compile, you will need to add
them to the <tt>Makefile.in</tt>, or add the names of libraries if they are
needed. In simple cases SWIG is pretty good at generating a complete
<tt>Makefile.in</tt> and <tt>config.m4</tt> which need no further editing.
</p>
<p>
You then run the configure script with the command line argument needed
to enable the extension. Then run make, which builds the extension.
The extension object file will be left in the modules sub directory, you can
move it to wherever it is convenient to call from your php script.
</p>
<p>
When using <tt>-phpfull</tt>, swig also accepts the following
additional optional arguments:
</p>
<ul>
<li><tt>-withincs "&lt;incs&gt;"</tt> Adds include files to the config.m4 file.
<li><tt>-withlibs "&lt;libs&gt;"</tt> Links with the specified libraries.
<li><tt>-withc "&lt;files&gt;"</tt> Compiles and links the additional specified C files.
<li><tt>-withcxx "&lt;files&gt;"</tt> Compiles and links the additional specified C++ files.
</ul>
<p>
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
to move these files to a subdirectory within the php source tree, this subdirectory you will need to create under the ext directory, with the name of the extension (e.g. <tt>mkdir php-4.0.6/ext/modulename</tt>).
</p>
<p>
After moving the files into this directory, you will need to run the 'buildall'
script in the php source directory. This rebuilds the configure script
and includes the extra command line arguments from the module you have added.
</p>
<p>
Before running the generated configure file, you may need to edit the <tt>
Makefile.in</tt>. This contains the names of the source files to compile (
just the wrapper file by default) and any additional libraries needed to
link in. If there are extra C files to compile you will need to add them
to the Makefile, or add the names of libraries if they are needed.
In most cases <tt>Makefile.in</tt> will be complete, especially if you
make use of <tt>-withlibs</tt> and <tt>-withincs</tt>
</p>
<div class="code"><pre>
swig -php -phpfull -withlibs "xapian omquery" --withincs "om.h"
</pre></div>
<p>
Will include in the <tt>config.m4</tt> and <tt>Makefile.in</tt> search for
<tt>libxapian.a</tt> or <tt>libxapian.so</tt> and search for
<tt>libomquery.a</tt> or <tt>libomquery.so</tt> as well as a
search for <tt>om.h</tt>.
</p>
<p>
You then need to run the configure command and pass the necessary command
line arguments to enable your module (by default this is --enable-modulename,
but this can be changed by editing the config.m4 file in the modules directory
before running the buildall script. In addition, extra tests can be added to
the config.m4 file to ensure the correct libraries and header files are
installed.)
</p>
<p>
Once configure has completed, you can run make to build php. If this all
compiles correctly, you should end up with a php executable/library
which contains your new module. You can test it with a php script which
does not have the 'dl' command as used above.
</p>
<H3><a name="Php_nn1_3"></a>28.1.3 Using PHP Extensions</H3>
<p>
To test the extension from a PHP script, you need to load it first. You
can load it for every script by adding this line the <tt>[PHP]</tt> section of

View file

@ -53,11 +53,6 @@ PHP Options (available with -php5)\n\
-noproxy - Don't generate proxy classes.\n\
-prefix <prefix> - Prepend <prefix> to all class names in PHP5 wrappers\n\
-make - Create simple makefile\n\
-phpfull - Create full make files\n\
-withincs <incs> - With -phpfull writes needed incs in config.m4\n\
-withlibs <libs> - With -phpfull writes needed libs in config.m4\n\
-withc <files> - With -phpfull makes extra C files in Makefile.in\n\
-withcxx <files> - With -phpfull makes extra C++ files in Makefile.in\n\
\n";
/* The original class wrappers for PHP4 store the pointer to the C++ class in
@ -74,14 +69,11 @@ static Node *classnode = 0;
static String *module = 0;
static String *cap_module = 0;
static String *prefix = 0;
static String *withlibs = 0;
static String *withincs = 0;
static String *withc = 0;
static String *withcxx = 0;
static String *shadow_classname = 0;
static int gen_extra = 0;
static int gen_make = 0;
static File *f_runtime = 0;
@ -215,76 +207,58 @@ public:
SWIG_config_cppext("cpp");
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i], "-phpfull") == 0) {
gen_extra = 1;
if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-dlname") == 0) {
Printf(stderr, "*** -dlname is no longer supported\n*** if you want to change the module name, use -module instead.\n");
SWIG_exit(EXIT_FAILURE);
} else if (strcmp(argv[i], "-prefix") == 0) {
if (argv[i + 1]) {
prefix = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-withlibs") == 0) {
if (argv[i + 1]) {
withlibs = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-withincs") == 0) {
if (argv[i + 1]) {
withincs = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-withc") == 0) {
if (argv[i + 1]) {
withc = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-withcxx") == 0) {
if (argv[i + 1]) {
withcxx = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-cppext") == 0) {
if (argv[i + 1]) {
SWIG_config_cppext(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if ((strcmp(argv[i], "-noshadow") == 0) || (strcmp(argv[i], "-noproxy") == 0)) {
shadow = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-make") == 0) {
gen_make = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-withc") == 0) {
if (argv[i + 1]) {
withc = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-withcxx") == 0) {
if (argv[i + 1]) {
withcxx = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-cppext") == 0) {
if (argv[i + 1]) {
SWIG_config_cppext(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
} else if ((strcmp(argv[i], "-noshadow") == 0) || (strcmp(argv[i], "-noproxy") == 0)) {
shadow = 0;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-make") == 0) {
gen_make = 1;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
} else if (strcmp(argv[i], "-phpfull") == 0 ||
strcmp(argv[i], "-withlibs") == 0 ||
strcmp(argv[i], "-withincs") == 0) {
Printf(stderr, "*** %s is no longer supported.\n*** We recommend building as a dynamically loadable module.\n", argv[i]);
SWIG_exit(EXIT_FAILURE);
} else if (strcmp(argv[i], "-dlname") == 0) {
Printf(stderr, "*** -dlname is no longer supported.\n*** If you want to change the module name, use -module instead.\n");
SWIG_exit(EXIT_FAILURE);
}
}
@ -326,206 +300,6 @@ public:
Close(f_make);
}
void create_extra_files(String *outfile) {
File *f_extra;
static String *configm4 = 0;
static String *makefilein = 0;
static String *credits = 0;
configm4 = NewStringEmpty();
Printv(configm4, SWIG_output_directory(), "config.m4", NIL);
makefilein = NewStringEmpty();
Printv(makefilein, SWIG_output_directory(), "Makefile.in", NIL);
credits = NewStringEmpty();
Printv(credits, SWIG_output_directory(), "CREDITS", NIL);
// are we a --with- or --enable-
int with = (withincs || withlibs) ? 1 : 0;
// Note Makefile.in only copes with one source file
// also withincs and withlibs only take one name each now
// the code they generate should be adapted to take multiple lines
/* Write out Makefile.in */
f_extra = NewFile(makefilein, "w");
if (!f_extra) {
FileErrorDisplay(makefilein);
SWIG_exit(EXIT_FAILURE);
}
Printf(f_extra, "# $Id$\n\n" "LTLIBRARY_NAME = %s.la\n", module);
// C++ has more and different entries to C in Makefile.in
if (!CPlusPlus) {
Printf(f_extra, "LTLIBRARY_SOURCES = %s %s\n", Swig_file_filename(outfile), withc);
Printf(f_extra, "LTLIBRARY_SOURCES_CPP = %s\n", withcxx);
} else {
Printf(f_extra, "LTLIBRARY_SOURCES = %s\n", withc);
Printf(f_extra, "LTLIBRARY_SOURCES_CPP = %s %s\n", Swig_file_filename(outfile), withcxx);
Printf(f_extra, "LTLIBRARY_OBJECTS_X = $(LTLIBRARY_SOURCES_CPP:.cpp=.lo) $(LTLIBRARY_SOURCES_CPP:.cxx=.lo)\n");
}
Printf(f_extra, "LTLIBRARY_SHARED_NAME = %s.la\n", module);
Printf(f_extra, "LTLIBRARY_SHARED_LIBADD = $(%s_SHARED_LIBADD)\n\n", cap_module);
Printf(f_extra, "include $(top_srcdir)/build/dynlib.mk\n");
Printf(f_extra, "\n# patch in .cxx support to php build system to work like .cpp\n");
Printf(f_extra, ".SUFFIXES: .cxx\n\n");
Printf(f_extra, ".cxx.o:\n");
Printf(f_extra, "\t$(CXX_COMPILE) -c $<\n\n");
Printf(f_extra, ".cxx.lo:\n");
Printf(f_extra, "\t$(CXX_PHP_COMPILE)\n\n");
Printf(f_extra, ".cxx.slo:\n");
Printf(f_extra, "\t$(CXX_SHARED_COMPILE)\n\n");
Printf(f_extra, "\n# make it easy to test module\n");
Printf(f_extra, "testmodule:\n");
Printf(f_extra, "\tphp -q -d extension_dir=modules %s\n\n", Swig_file_filename(phpfilename));
Close(f_extra);
/* Now config.m4 */
// Note: # comments are OK in config.m4 if you don't mind them
// appearing in the final ./configure file
// (which can help with ./configure debugging)
// NOTE2: phpize really ought to be able to write out a sample
// config.m4 based on some simple data, I'll take this up with
// the php folk!
f_extra = NewFile(configm4, "w");
if (!f_extra) {
FileErrorDisplay(configm4);
SWIG_exit(EXIT_FAILURE);
}
Printf(f_extra, "dnl $Id$\n");
Printf(f_extra, "dnl ***********************************************************************\n");
Printf(f_extra, "dnl ** THIS config.m4 is provided for PHPIZE and PHP's consumption NOT\n");
Printf(f_extra, "dnl ** for any part of the rest of the %s build system\n", module);
Printf(f_extra, "dnl ***********************************************************************\n\n");
if (!with) { // must be enable then
Printf(f_extra, "PHP_ARG_ENABLE(%s, whether to enable %s support,\n", module, module);
Printf(f_extra, "[ --enable-%s Enable %s support])\n\n", module, module);
} else {
Printf(f_extra, "PHP_ARG_WITH(%s, for %s support,\n", module, module);
Printf(f_extra, "[ --with-%s[=DIR] Include %s support.])\n\n", module, module);
// These tests try and file the library we need
Printf(f_extra, "dnl THESE TESTS try and find the library and header files\n");
Printf(f_extra, "dnl your new php module needs. YOU MAY NEED TO EDIT THEM\n");
Printf(f_extra, "dnl as written they assume your header files are all in the same place\n\n");
Printf(f_extra, "dnl ** are we looking for %s_lib.h or something else?\n", module);
if (withincs)
Printf(f_extra, "HNAMES=\"%s\"\n\n", withincs);
else
Printf(f_extra, "HNAMES=\"\"; # %s_lib.h ?\n\n", module);
Printf(f_extra, "dnl ** Are we looking for lib%s.a or lib%s.so or something else?\n", module, module);
if (withlibs)
Printf(f_extra, "LIBNAMES=\"%s\"\n\n", withlibs);
else
Printf(f_extra, "LIBNAMES=\"\"; # lib%s.so ?\n\n", module);
Printf(f_extra, "dnl IF YOU KNOW one of the symbols in the library and you\n");
Printf(f_extra, "dnl specify it below then we can have a link test to see if it works\n");
Printf(f_extra, "LIBSYMBOL=\"\"\n\n");
}
// Now write out tests to find thing.. they may need to extend tests
Printf(f_extra, "if test \"$PHP_%s\" != \"no\"; then\n\n", cap_module);
// Ready for when we add libraries as we find them
Printf(f_extra, " PHP_SUBST(%s_SHARED_LIBADD)\n\n", cap_module);
if (withlibs) { // find more than one library
Printf(f_extra, " for LIBNAME in $LIBNAMES ; do\n");
Printf(f_extra, " LIBDIR=\"\"\n");
// For each path element to try...
Printf(f_extra, " for i in $PHP_%s $PHP_%s/lib /usr/lib /usr/local/lib ; do\n", cap_module, cap_module);
Printf(f_extra, " if test -r $i/lib$LIBNAME.a -o -r $i/lib$LIBNAME.so ; then\n");
Printf(f_extra, " LIBDIR=\"$i\"\n");
Printf(f_extra, " break\n");
Printf(f_extra, " fi\n");
Printf(f_extra, " done\n\n");
Printf(f_extra, " dnl ** and $LIBDIR should be the library path\n");
Printf(f_extra, " if test \"$LIBNAME\" != \"\" -a -z \"$LIBDIR\" ; then\n");
Printf(f_extra, " AC_MSG_RESULT(Library files $LIBNAME not found)\n");
Printf(f_extra, " AC_MSG_ERROR(Is the %s distribution installed properly?)\n", module);
Printf(f_extra, " else\n");
Printf(f_extra, " AC_MSG_RESULT(Library files $LIBNAME found in $LIBDIR)\n");
Printf(f_extra, " PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBDIR, %s_SHARED_LIBADD)\n", cap_module);
Printf(f_extra, " fi\n");
Printf(f_extra, " done\n\n");
}
if (withincs) { // Find more than once include
Printf(f_extra, " for HNAME in $HNAMES ; do\n");
Printf(f_extra, " INCDIR=\"\"\n");
// For each path element to try...
Printf(f_extra, " for i in $PHP_%s $PHP_%s/include $PHP_%s/includes $PHP_%s/inc $PHP_%s/incs /usr/local/include /usr/include; do\n", cap_module,
cap_module, cap_module, cap_module, cap_module);
// Try and find header files
Printf(f_extra, " if test \"$HNAME\" != \"\" -a -r $i/$HNAME ; then\n");
Printf(f_extra, " INCDIR=\"$i\"\n");
Printf(f_extra, " break\n");
Printf(f_extra, " fi\n");
Printf(f_extra, " done\n\n");
Printf(f_extra, " dnl ** Now $INCDIR should be the include file path\n");
Printf(f_extra, " if test \"$HNAME\" != \"\" -a -z \"$INCDIR\" ; then\n");
Printf(f_extra, " AC_MSG_RESULT(Include files $HNAME not found)\n");
Printf(f_extra, " AC_MSG_ERROR(Is the %s distribution installed properly?)\n", module);
Printf(f_extra, " else\n");
Printf(f_extra, " AC_MSG_RESULT(Include files $HNAME found in $INCDIR)\n");
Printf(f_extra, " PHP_ADD_INCLUDE($INCDIR)\n");
Printf(f_extra, " fi\n\n");
Printf(f_extra, " done\n\n");
}
if (CPlusPlus) {
Printf(f_extra, " # As this is a C++ module..\n");
}
Printf(f_extra, " PHP_REQUIRE_CXX\n");
Printf(f_extra, " AC_CHECK_LIB(stdc++, cin)\n");
if (with) {
Printf(f_extra, " if test \"$LIBSYMBOL\" != \"\" ; then\n");
Printf(f_extra, " old_LIBS=\"$LIBS\"\n");
Printf(f_extra, " LIBS=\"$LIBS -L$TEST_DIR/lib -lm -ldl\"\n");
Printf(f_extra, " AC_CHECK_LIB($LIBNAME, $LIBSYMBOL, [AC_DEFINE(HAVE_TESTLIB,1, [ ])],\n");
Printf(f_extra, " [AC_MSG_ERROR(wrong test lib version or lib not found)])\n");
Printf(f_extra, " LIBS=\"$old_LIBS\"\n");
Printf(f_extra, " fi\n\n");
}
Printf(f_extra, " AC_DEFINE(HAVE_%s, 1, [ ])\n", cap_module);
Printf(f_extra, "dnl AC_DEFINE_UNQUOTED(PHP_%s_DIR, \"$%s_DIR\", [ ])\n", cap_module, cap_module);
Printf(f_extra, " PHP_EXTENSION(%s, $ext_shared)\n", module);
// and thats all!
Printf(f_extra, "fi\n");
Close(f_extra);
/* CREDITS */
f_extra = NewFile(credits, "w");
if (!f_extra) {
FileErrorDisplay(credits);
SWIG_exit(EXIT_FAILURE);
}
Printf(f_extra, "%s\n", module);
Close(f_extra);
}
/* ------------------------------------------------------------
* top()
* ------------------------------------------------------------ */
@ -715,9 +489,6 @@ public:
Printf(s_init, "};\n");
Printf(s_init, "zend_module_entry* SWIG_module_entry = &%s_module_entry;\n\n", module);
if (gen_extra) {
Printf(s_init, "#ifdef COMPILE_DL_%s\n", cap_module);
}
Printf(s_init, "#ifdef __cplusplus\n");
Printf(s_init, "extern \"C\" {\n");
Printf(s_init, "#endif\n");
@ -728,10 +499,6 @@ public:
Printf(s_init, "}\n");
Printf(s_init, "#endif\n\n");
if (gen_extra) {
Printf(s_init, "#endif\n\n");
}
/* We have to register the constants before they are (possibly) used
* by the pointer typemaps. This all needs re-arranging really as
* things are being called in the wrong order
@ -828,9 +595,7 @@ public:
Printf(f_phpcode, "%s\n?>\n", s_phpclasses);
Close(f_phpcode);
if (gen_extra) {
create_extra_files(outfile);
} else if (gen_make) {
if (gen_make) {
create_simple_make();
}