diff options
author | Jamie Bullock <jamie@postlude.co.uk> | 2007-09-05 14:32:17 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@postlude.co.uk> | 2007-09-05 14:32:17 +0000 |
commit | 801d1fff596e07a747b1558d85eaab9bcf01f982 (patch) | |
tree | 8dcde81047f79a92223243c17d0ed101d30cc7b5 /swig | |
parent | 280bf6f6ba2c6ad6d4f470573ca23d72541813c1 (diff) | |
download | LibXtract-801d1fff596e07a747b1558d85eaab9bcf01f982.tar.gz LibXtract-801d1fff596e07a747b1558d85eaab9bcf01f982.tar.bz2 LibXtract-801d1fff596e07a747b1558d85eaab9bcf01f982.zip |
Added java bindings. Everything seems to work OK, except test.java won't compile. Some kind of path error, but I can't work out how to fix it.
Diffstat (limited to 'swig')
-rw-r--r-- | swig/Makefile.am | 23 | ||||
-rw-r--r-- | swig/java/Makefile.am | 69 | ||||
-rw-r--r-- | swig/java/test.java | 23 | ||||
-rw-r--r-- | swig/python/Makefile.am | 18 | ||||
-rw-r--r-- | swig/python/test.py (renamed from swig/test.py) | 7 | ||||
-rw-r--r-- | swig/python/xtract.i | 12 | ||||
-rw-r--r-- | swig/xtract.i | 3 |
7 files changed, 134 insertions, 21 deletions
diff --git a/swig/Makefile.am b/swig/Makefile.am index 6214909..536bfed 100644 --- a/swig/Makefile.am +++ b/swig/Makefile.am @@ -1,18 +1,11 @@ -MAINTAINERCLEANFILES = xtract.py xtract_wrap.c Makefile.in _xtract.so +MAINTAINERCLEANFILES = Makefile.in -BUILT_SOURCES = $(srcdir)/xtract_wrap.c -SWIG_SOURCES = xtract.i +if BUILD_JAVA +JAVA_BUILD_DIR = java +endif -pkgpython_PYTHON = xtract.py -pkgpyexec_LTLIBRARIES = _xtract.la -_xtract_la_SOURCES = $(srcdir)/xtract_wrap.c $(SWIG_SOURCES) -_xtract_la_CFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src -_xtract_la_LDFLAGS = -module -lxtract -_xtract_la_LIBADD = ../src/libxtract.la - -xtract_wrap.c : $(SWIG_SOURCES) - $(SWIG) $(SWIG_PYTHON_OPT) -I$(top_srcdir) -o $@ $< - -clean-local: - -rm -f _xtract.so xtract.py xtract_wrap.c xtract.pyc +if BUILD_PYTHON +PYTHON_BUILD_DIR = python +endif +SUBDIRS = $(JAVA_BUILD_DIR) $(PYTHON_BUILD_DIR) diff --git a/swig/java/Makefile.am b/swig/java/Makefile.am new file mode 100644 index 0000000..5ced699 --- /dev/null +++ b/swig/java/Makefile.am @@ -0,0 +1,69 @@ +SWIG_JAVA_DIR = $(top_srcdir)/swig/java + +SWIG_CMD = $(SWIG) -I$(SWIG_JAVA_DIR) -I$(top_srcdir) -java + +swigjavafiles = \ + xtractJNI.java \ + xtract.java \ + floatArray.java \ + SWIGTYPE_p_float.java \ + SWIGTYPE_p_void.java + +swigcfiles = xtractjavac_wrap.c + +swiggenfiles = $(swigjavafiles) $(swigcfiles) + +javafiles = $(swigjavafiles) + +# Note : the order of these is important since there is no formal +# dependency checking. +javaclasses = \ + xtractJNI.class \ + xtract.class \ + floatArray.class \ + SWIGTYPE_p_float.class \ + SWIGTYPE_p_void.class + +$(swiggenfiles): ../xtract.i + $(SWIG_CMD) -package xtract.core -o xtractjavac_wrap.c ../xtract.i + +# Must have "exec" in the name. +execjavawrapperdir = ${libdir} + +libxtract = $(top_builddir)/src/libxtract$(LIB_TAG).la + +AM_CPPFLAGS = -I$(top_srcdir)/include $(INCLTDL) $(JAVAINCCMD) + +nodist_xtractjavac_wrap_la_SOURCES = xtractjavac_wrap.c + +xtractjavac_wrap_la_LDFLAGS = \ + -rpath $(execjavawrapperdir) \ + -module \ + -avoid-version \ + -no-undefined \ + $(libxtract) + +.java.class: + $(JAVAC) $(AM_JAVACFLAGS) $(JAVACFLAGS) $(swigjavafiles) -d . -classpath . + cp xtract/core/$@ . + +noinst_DATA = jar-stamp +# +jar-stamp: $(javaclasses) $(javafiles) + $(mkdir_p) xtract/core + $(mkdir_p) xtract/core/src + cp $(javafiles) xtract/core/src + touch jar-stamp +# +execjavawrapper_LTLIBRARIES = xtractjavac_wrap.la + +install-exec-hook: + ( cd $(DESTDIR)$(execjavawrapperdir) ; \ + rm -f *.a *.la ) + +clean-local: + rm -rf xtract + +CLEANFILES = $(javaclasses) jar-stamp + +MAINTAINERCLEANFILES = $(swiggenfiles) Makefile.in diff --git a/swig/java/test.java b/swig/java/test.java new file mode 100644 index 0000000..d20461a --- /dev/null +++ b/swig/java/test.java @@ -0,0 +1,23 @@ + +import xtract.core.*; + +public class test { + public static void main(String argv[]) { +// System.loadLibrary("xtract"); + + int len = 5; + int retval = 0; + float result[]; + floatArray a = new floatArray(len); + SWIGTYPE_p_void myvoid = null; + + result = new float[1]; + + for (int i = 0; i < len; i++) + a.setitem(i, i * 2); + + retval = xtract.xtract_mean(a.cast(), len, myvoid, result); + + System.out.println(result); + } +} diff --git a/swig/python/Makefile.am b/swig/python/Makefile.am new file mode 100644 index 0000000..e9b6747 --- /dev/null +++ b/swig/python/Makefile.am @@ -0,0 +1,18 @@ +MAINTAINERCLEANFILES = xtract.py xtract_wrap.c Makefile.in _xtract.so + +BUILT_SOURCES = $(srcdir)/xtract_wrap.c +SWIG_SOURCES = ../xtract.i + +pkgpython_PYTHON = xtract.py +pkgpyexec_LTLIBRARIES = _xtract.la +_xtract_la_SOURCES = $(srcdir)/xtract_wrap.c $(SWIG_SOURCES) +_xtract_la_CFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src +_xtract_la_LDFLAGS = -module -lxtract +_xtract_la_LIBADD = $(top_srcdir)/src/libxtract.la + +xtract_wrap.c : $(SWIG_SOURCES) + $(SWIG) $(SWIG_PYTHON_OPT) -I$(top_srcdir) -o $@ $< + +clean-local: + -rm -f _xtract.so xtract.py xtract_wrap.c xtract.pyc + diff --git a/swig/test.py b/swig/python/test.py index e98755d..f491a39 100644 --- a/swig/test.py +++ b/swig/python/test.py @@ -4,15 +4,12 @@ import xtract len = 5 -a = xtract.new_floatArray(len) +a = xtract.floatArray(len) for i in range(0, len): - xtract.floatArray_setitem(a, i, 2*i) + a[i] = 2 * i retval,result = xtract.xtract_mean(a,len,None) print result - - - diff --git a/swig/python/xtract.i b/swig/python/xtract.i new file mode 100644 index 0000000..b363f2e --- /dev/null +++ b/swig/python/xtract.i @@ -0,0 +1,12 @@ +%module xtract +%include carrays.i +%include typemaps.i + +%{ +#include "xtract/xtract_scalar.h" +%} + +%array_functions(float, floatArray); +%apply float *OUTPUT { float *result }; + +%include "xtract/xtract_scalar.h" diff --git a/swig/xtract.i b/swig/xtract.i index b363f2e..58c9f18 100644 --- a/swig/xtract.i +++ b/swig/xtract.i @@ -6,7 +6,8 @@ #include "xtract/xtract_scalar.h" %} -%array_functions(float, floatArray); +%array_class(float, floatArray); %apply float *OUTPUT { float *result }; +/* %apply float *INPUT { float *data }; */ %include "xtract/xtract_scalar.h" |