From 801d1fff596e07a747b1558d85eaab9bcf01f982 Mon Sep 17 00:00:00 2001 From: Jamie Bullock Date: Wed, 5 Sep 2007 14:32:17 +0000 Subject: 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. --- swig/Makefile.am | 23 ++++++----------- swig/java/Makefile.am | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ swig/java/test.java | 23 +++++++++++++++++ swig/python/Makefile.am | 18 +++++++++++++ swig/python/test.py | 15 +++++++++++ swig/python/xtract.i | 12 +++++++++ swig/test.py | 18 ------------- swig/xtract.i | 3 ++- 8 files changed, 147 insertions(+), 34 deletions(-) create mode 100644 swig/java/Makefile.am create mode 100644 swig/java/test.java create mode 100644 swig/python/Makefile.am create mode 100644 swig/python/test.py create mode 100644 swig/python/xtract.i delete mode 100644 swig/test.py (limited to 'swig') 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/python/test.py b/swig/python/test.py new file mode 100644 index 0000000..f491a39 --- /dev/null +++ b/swig/python/test.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +import xtract + +len = 5 + +a = xtract.floatArray(len) + +for i in range(0, len): + 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/test.py b/swig/test.py deleted file mode 100644 index e98755d..0000000 --- a/swig/test.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python - -import xtract - -len = 5 - -a = xtract.new_floatArray(len) - -for i in range(0, len): - xtract.floatArray_setitem(a, i, 2*i) - -retval,result = xtract.xtract_mean(a,len,None) - -print result - - - - 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" -- cgit v1.2.3