diff options
author | Dave Beazley <dave-swig@dabeaz.com> | 2000-01-12 03:21:25 +0000 |
---|---|---|
committer | Dave Beazley <dave-swig@dabeaz.com> | 2000-01-12 03:21:25 +0000 |
commit | 63880a6e34c1c1f8c7e0850fe248f89042c3d22c (patch) | |
tree | 45c9513df85d76b4c46b62beaf60745c1d282150 | |
parent | ad3d48ca1527b066d048c980d10f24448a5161a1 (diff) | |
download | swig-63880a6e34c1c1f8c7e0850fe248f89042c3d22c.tar.gz |
*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@50 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | Examples/Makefile.in | 253 | ||||
-rw-r--r-- | Examples/perl5/simple/Makefile | 17 | ||||
-rw-r--r-- | Examples/perl5/simple/README | 1 | ||||
-rw-r--r-- | Examples/perl5/simple/example.c | 24 | ||||
-rw-r--r-- | Examples/perl5/simple/example.i | 11 | ||||
-rwxr-xr-x | Examples/perl5/simple/example.pl | 23 | ||||
-rw-r--r-- | Examples/python/simple/Makefile | 18 | ||||
-rw-r--r-- | Examples/python/simple/README | 1 | ||||
-rw-r--r-- | Examples/python/simple/example.c | 21 | ||||
-rw-r--r-- | Examples/python/simple/example.i | 8 | ||||
-rw-r--r-- | Examples/python/simple/example.py | 30 | ||||
-rw-r--r-- | Examples/tcl/simple/Makefile | 28 | ||||
-rw-r--r-- | Examples/tcl/simple/README | 10 | ||||
-rw-r--r-- | Examples/tcl/simple/example.c | 25 | ||||
-rw-r--r-- | Examples/tcl/simple/example.i | 21 | ||||
-rw-r--r-- | Examples/tcl/simple/example.tcl | 26 |
16 files changed, 517 insertions, 0 deletions
diff --git a/Examples/Makefile.in b/Examples/Makefile.in new file mode 100644 index 000000000..74db8df6a --- /dev/null +++ b/Examples/Makefile.in @@ -0,0 +1,253 @@ +# ------------------------------------------------------------ +# SWIG Makefile Template +# +# This file is used by all of the examples to build modules +# and other things. You can use this as a starting point +# for building your own modules. +# +# How to use this Makefile: +# +# 1. Assuming you ran 'configure', some values in this Makefile +# will be set automatically for you. Configure will try to +# guess how to do certain things such as build shared libraries, +# etc... Unfortunately, it's not perfect so you may need to +# change some things by hand (see next). +# +# 2. Take a look at the prefixes below. Since SWIG works with +# multiple target languages, you may need to find out where +# certain packages have been installed. Set the prefixes +# accordingly. I've set the prefixes assuming that SWIG has +# been installed in the same directory as the target languages. +# +# 3. To use this makefile, simply set SRCS, INTERFACE, INCLUDE, LIBS, +# TARGET, and do a +# $(MAKE) -f Makefile.template.in SRCS='$(SRCS)' \ +# INCLUDE='$(INCLUDE) LIBS='$(LIBS)' INTERFACE='$(INTERFACE)' \ +# TARGET='$(TARGET)' method +# +# 'method' describes what is being built. +# +#--------------------------------------------------------------- + +TARGET = +CC = @CC@ +CXX = @CXX@ +CFLAGS = +prefix = @prefix@ +exec_prefix= @exec_prefix@ +SRCS = +INCLUDE = +LIBS = +INTERFACE = +SWIGOPT = +SWIG = SWIG + +LIBM = @LIBM@ +LIBC = @LIBC@ +LIBCRYPT = @LIBCRYPT@ +SYSLIBS = $(LIBM) $(LIBC) $(LIBCRYPT) + +# X11 options + +XLIB = @XLIBSW@ +XINCLUDE = @XINCLUDES@ + +ISRCS = $(INTERFACE:.i=_wrap.c) + +################################################################## +# Dynamic loading for C++ +# If you are going to be building dynamic loadable modules in C++, +# you may need to edit this line appropriately. +# +# This line works for g++, but I'm not sure what it might be +# for other C++ compilers +################################################################## + +CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \ + -L/usr/local/lib -lg++ -lstdc++ -lgcc + + +# Symbols used for using shared libraries +SO= @SO@ +LDSHARED= @LDSHARED@ +CCSHARED= @CCSHARED@ +CXXSHARED= @LDSHARED@ + +# This is used for building shared libraries with a number of C++ +# compilers. If it doesn't work, comment it out. + +CXXSHARED= @CXX@ -shared + +OBJS = $(SRCS:.c=.o) +IOBJS = $(ISRCS:.c=.o) + +################################################################## +##### Tcl/Tk ###### +################################################################## + +# Set these to your local copy of Tcl/Tk. + +TCL_INCLUDE = @TCLINCLUDE@ +TCL_LIB = @TCLLIB@ +TCL_OPTS = -ltcl @LIBS@ +TK_OPTS = -ltk -ltcl @LIBS@ + +# ----------------------------------------------------------- +# Build a new version of the tclsh shell +# ----------------------------------------------------------- + + +tclsh: $(SRCS) + $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACE) + $(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \ + $(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET) + +tclsh_cpp: $(SRCS) + $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -ltclsh.i $(INTERFACE) + $(CXX) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \ + $(TCL_LIB) $(TCL_OPTS) $(LIBS) $(SYSLIBS) -o $(TARGET) + +# ----------------------------------------------------------- +# Build a new copy of wish +# ----------------------------------------------------------- + +wish: $(SRCS) + $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACE) + $(CC) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \ + $(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET) + + +wish_cpp: $(SRCS) + $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) -lwish.i $(INTERFACE) + $(CXX) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) \ + $(XINCLUDE) $(TCL_LIB) $(TK_OPTS) $(XLIB) $(LIBS) $(SYSLIBS) -o $(TARGET) + +# ----------------------------------------------------------- +# Build a Tcl dynamic loadable module (you might need to tweak this) +# ----------------------------------------------------------- + +tcldl: $(SRCS) + $(SWIG) -tcl8 $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACE) + $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) + $(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)$(SO) + +# ----------------------------------------------------------- +# Build a Tcl7.5 dynamic loadable module for C++ +# ----------------------------------------------------------- + +tcldl_cpp: $(SRCS) + $(SWIG) -tcl8 -c++ $(SWIGOPT) $(TCL_SWIGOPTS) $(INTERFACE) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(TCL_INCLUDE) + $(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)$(SO) + +################################################################## +##### PERL 5 ###### +################################################################## + +# You need to set this variable to the Perl5 directory containing the +# files "perl.h", "EXTERN.h" and "XSUB.h". With Perl5.003, it's +# usually something like /usr/local/lib/perl5/arch-osname/5.003/CORE. + +PERL5_INCLUDE= @PERL5EXT@ + + +# ---------------------------------------------------------------- +# Build a Perl5 dynamically loadable module (C) +# ---------------------------------------------------------------- + +perl5: $(SRCS) + $(SWIG) -perl5 $(SWIGOPT) $(INTERFACE) + $(CC) -c -Dbool=char $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE) + $(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a Perl5 dynamically loadable module (C++) +# ---------------------------------------------------------------- + +perl5_cpp: $(SRCS) + $(SWIG) -perl5 -c++ $(SWIGOPT) $(INTERFACE) + $(CXX) -c $(CCSHARED) $(CFLAGS) -Dexplicit= $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE) + $(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a module from existing XS C source code. (ie. from xsubpp). +# ---------------------------------------------------------------- +perl5_xs: $(SRCS) + $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(INCLUDE) -I$(PERL5_INCLUDE) + $(LDSHARED) $(OBJS) $(LIBS) -o $(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a statically linked Perl5 executable +# ---------------------------------------------------------------- + +PERL5_LIB = -L$(PERL5_INCLUDE) -lperl @LIBS@ $(SYSLIBS) + +perl5_static: $(SRCS) + $(SWIG) -perl5 -static -lperlmain.i $(SWIGOPT) $(INTERFACE) + $(CC) $(CFLAGS) -Dbool=char $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) + +perl5_static_cpp: $(SRCS) + $(SWIG) -perl5 -c++ -static -lperlmain.i $(SWIGOPT) $(INTERFACE) + $(CXX) $(CFLAGS) -Dexplicit= $(SRCS) $(ISRCS) $(INCLUDE) -I$(PERL5_INCLUDE) $(PERL5_LIB) $(LIBS) -o $(TARGET) + + +################################################################## +##### PYTHON ###### +################################################################## + +# Make sure these locate your Python installation +PYTHON_INCLUDE= -DHAVE_CONFIG_H @PYINCLUDE@ +PYTHON_LIB = @PYLIB@ + +# ---------------------------------------------------------------- +# Build a C dynamically loadable module +# ---------------------------------------------------------------- + +python: $(SRCS) + $(SWIG) -python $(SWIGOPT) $(INTERFACE) + $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDE) $(PYTHON_INCLUDE) + $(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)module$(SO) + +# ----------------------------------------------------------------- +# Build a C++ dynamically loadable module +# ----------------------------------------------------------------- + +python_cpp: $(SRCS) + $(SWIG) -c++ -python $(SWIGOPT) $(INTERFACE) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDE) $(PYTHON_INCLUDE) + $(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)module$(SO) + +# ----------------------------------------------------------------- +# Build statically linked Python interpreter +# +# These should only be used in conjunction with the %include embed.i +# library file +# ----------------------------------------------------------------- + +#TKINTER = -L/usr/X11R6.3/lib -L/usr/local/compat/lib -ltk4.0 -ltcl7.4 -lX11 +TKINTER = +PYTHON_LIBOPTS = @PYLINK@ @LIBS@ $(TKINTER) $(SYSLIBS) + +python_static: $(SRCS) + $(SWIG) -python -lembed.i $(SWIGOPT) $(INTERFACE) + $(CC) $(CFLAGS) @LINKFORSHARED@ $(ISRCS) $(SRCS) $(INCLUDE) \ + $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) + +python_static_cpp: $(SRCS) + $(SWIG) -c++ -python -lembed.i $(SWIGOPT) $(INTERFACE) + $(CXX) $(CFLAGS) $(ISRCS) $(SRCS) $(INCLUDE) \ + $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) + + +################################################################## +##### SWIG ###### +################################################################## + +# Build a new SWIG extension + +SWIGINCLUDE = -I${prefix}/include +SWIGLIB = -L${exec_prefix}/lib + +swig: $(SRCS) + $(CXX) $(SRCS) $(SWIGINCLUDE) $(INCLUDE) $(SWIGLIB) $(LIBS) -lswig -o $(TARGET) + diff --git a/Examples/perl5/simple/Makefile b/Examples/perl5/simple/Makefile new file mode 100644 index 000000000..c533f9aa9 --- /dev/null +++ b/Examples/perl5/simple/Makefile @@ -0,0 +1,17 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = example +INTERFACE = example.i +SWIGOPT = +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5 + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_static + +clean:: + rm -f *_wrap* *.o core *~ *.so *.pm myperl + diff --git a/Examples/perl5/simple/README b/Examples/perl5/simple/README new file mode 100644 index 000000000..07e8da069 --- /dev/null +++ b/Examples/perl5/simple/README @@ -0,0 +1 @@ +Simple example from users manual. diff --git a/Examples/perl5/simple/example.c b/Examples/perl5/simple/example.c new file mode 100644 index 000000000..f2b074781 --- /dev/null +++ b/Examples/perl5/simple/example.c @@ -0,0 +1,24 @@ +/* Simple example from documentation */ +/* File : example.c */ + +#include <time.h> + +double My_variable = 3.0; + +/* Compute factorial of n */ +int fact(int n) { + if (n <= 1) return 1; + else return n*fact(n-1); +} + +/* Compute n mod m */ +int my_mod(int n, int m) { + return (n % m); +} + + +char *get_time() { + long ltime; + time(<ime); + return ctime(<ime); +} diff --git a/Examples/perl5/simple/example.i b/Examples/perl5/simple/example.i new file mode 100644 index 000000000..b7b678776 --- /dev/null +++ b/Examples/perl5/simple/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example +%{ +/* Put headers and other declarations here */ +%} + + +extern double My_variable; +extern int fact(int); +%name(mod) extern int my_mod(int n, int m); +extern char *get_time(); diff --git a/Examples/perl5/simple/example.pl b/Examples/perl5/simple/example.pl new file mode 100755 index 000000000..a65031a5a --- /dev/null +++ b/Examples/perl5/simple/example.pl @@ -0,0 +1,23 @@ +# +# Perl5 script for testing simple example + +use example; +package example; + +print get_time(); +print "My Variable = $My_variable","\n"; +for ($i = 0; $i < 14; $i++) { + $n = fact($i); + print "$i factorial is $n\n"; +} + +for ($i = 1; $i < 250; $i++) { + for ($j = 1; $j < 250; $j++) { + $n = mod($i,$j); + $My_variable = $My_variable + $n; + } +} + +print "My_variable = ", $My_variable, "\n"; + + diff --git a/Examples/python/simple/Makefile b/Examples/python/simple/Makefile new file mode 100644 index 000000000..ecfeef983 --- /dev/null +++ b/Examples/python/simple/Makefile @@ -0,0 +1,18 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='mypython' INTERFACE='$(INTERFACE)' python_static + +clean:: + rm -f *_wrap* *.o *~ *.so mypython *.pyc .~* core + + diff --git a/Examples/python/simple/README b/Examples/python/simple/README new file mode 100644 index 000000000..a5b95cfde --- /dev/null +++ b/Examples/python/simple/README @@ -0,0 +1 @@ +Simple example from the users manual diff --git a/Examples/python/simple/example.c b/Examples/python/simple/example.c new file mode 100644 index 000000000..792884b41 --- /dev/null +++ b/Examples/python/simple/example.c @@ -0,0 +1,21 @@ +/* Simple example from documentation */ +/* File : example.c */ + +#include <time.h> + +double My_variable = 3.0; + +int fact(int n) { + if (n <= 1) return 1; + else return n*fact(n-1); +} + +int mod(int n, int m) { + return (n % m); +} + +char *get_time() { + long ltime; + time(<ime); + return ctime(<ime); +} diff --git a/Examples/python/simple/example.i b/Examples/python/simple/example.i new file mode 100644 index 000000000..987a7cd55 --- /dev/null +++ b/Examples/python/simple/example.i @@ -0,0 +1,8 @@ +/* File : example.i */ +%module example + +extern double My_variable; +extern int fact(int); +extern int mod(int n, int m); +extern char *get_time(); + diff --git a/Examples/python/simple/example.py b/Examples/python/simple/example.py new file mode 100644 index 000000000..36cf6f218 --- /dev/null +++ b/Examples/python/simple/example.py @@ -0,0 +1,30 @@ +#!/home/sci/local/bin/python +# +# Python test script. This also illustrates the use of get/set +# for C variables. + +from example import * +print get_time() +print "My Variable = ", cvar.My_variable +for i in range(0,14): + n = fact(i) + print i, "factorial is ", n + +for i in range(1,250): + for j in range(1,250): + n = mod(i,j) + cvar.My_variable = cvar.My_variable + n + +print "My_variable = ", cvar.My_variable + + + + + + + + + + + + diff --git a/Examples/tcl/simple/Makefile b/Examples/tcl/simple/Makefile new file mode 100644 index 000000000..afeb32c2f --- /dev/null +++ b/Examples/tcl/simple/Makefile @@ -0,0 +1,28 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = my_tclsh +DLTARGET = example +INTERFACE = example.i + +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcldl + +tcl8:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='-tcl8' TARGET='$(DLTARGET)' INTERFACE='$(INTERFACE)' tcldl + +static:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh + +static8:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='-tcl8' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' tclsh + + +clean:: + rm -f *_wrap* *.o my_tclsh *~ .~* core *.so *.sl + + diff --git a/Examples/tcl/simple/README b/Examples/tcl/simple/README new file mode 100644 index 000000000..031b17bc5 --- /dev/null +++ b/Examples/tcl/simple/README @@ -0,0 +1,10 @@ +This is a simple Tcl example. Type 'make' to +compile a dynamically loadable extension. + +'make tcl8' creates a dynamically loadable Tcl 8.x +extension. + +'make static' creates a statically linked 'tclsh' executable. + +'make static8' create a statically linked 'tclsh8.0' executable. + diff --git a/Examples/tcl/simple/example.c b/Examples/tcl/simple/example.c new file mode 100644 index 000000000..f132e908b --- /dev/null +++ b/Examples/tcl/simple/example.c @@ -0,0 +1,25 @@ +/* Simple example from documentation */ +/* File : example.c */ + +#ifdef SWIG +%module example +#endif + +#include <time.h> + +double My_variable = 3.0; + +int fact(int n) { + if (n <= 1) return 1; + else return n*fact(n-1); +} + +int mod(int n, int m) { + return (n % m); +} + +char *get_time() { + long ltime; + time(<ime); + return ctime(<ime); +} diff --git a/Examples/tcl/simple/example.i b/Examples/tcl/simple/example.i new file mode 100644 index 000000000..f0c76c1de --- /dev/null +++ b/Examples/tcl/simple/example.i @@ -0,0 +1,21 @@ +/* File : example.i */ +%module example +%{ +/* Put headers and other declarations here */ + +char foo[] = "Help me!"; +%} + +typedef double * DoublePtr; +typedef double Real; + +typedef Vector * Foo; + +extern double My_variable; +extern int fact(int); +extern int mod(int n, int m); +extern char *get_time(); +char foo[]; + + + diff --git a/Examples/tcl/simple/example.tcl b/Examples/tcl/simple/example.tcl new file mode 100644 index 000000000..3a6683aa7 --- /dev/null +++ b/Examples/tcl/simple/example.tcl @@ -0,0 +1,26 @@ +# +# Tcl script for testing simple example + +# Try to load as a dynamic module. If not, we'll just assume +# that it was statically linked in. + +catch { load ./example.so example} +catch { load ./example.dll example} ;# Windows + +puts [get_time] +set tcl_precision 17 +puts "My Variable = $My_variable" +for {set i 0} {$i < 14} {incr i 1} { + set n [fact $i]; + puts "$i factorial is $n" +} + +for {set i 1} {$i < 250} {incr i 1} { + for {set j 1} {$j < 250} {incr j 1} { + set n [mod $i $j] + set My_variable [expr {$My_variable + $n}] + } +} + +puts "My_variable = $My_variable" + |