diff options
author | Jamie Bullock <jamie@postlude.co.uk> | 2007-09-06 14:05:37 +0000 |
---|---|---|
committer | Jamie Bullock <jamie@postlude.co.uk> | 2007-09-06 14:05:37 +0000 |
commit | 1f22cd5a7ddd3030c0c47f0528f5b2068f6b5283 (patch) | |
tree | ca4cb41e59e4c8b2a98df3a166e48d38df526d3a /swig | |
parent | 29e943f0788bff5a51005241574cb881fbf26ac7 (diff) | |
download | LibXtract-1f22cd5a7ddd3030c0c47f0528f5b2068f6b5283.tar.gz LibXtract-1f22cd5a7ddd3030c0c47f0528f5b2068f6b5283.tar.bz2 LibXtract-1f22cd5a7ddd3030c0c47f0528f5b2068f6b5283.zip |
Java bindings (with simple test) now working. Unified Python and Java bindings tests.
Diffstat (limited to 'swig')
-rw-r--r-- | swig/java/Makefile.am | 65 | ||||
-rw-r--r-- | swig/java/test.java | 24 | ||||
-rw-r--r-- | swig/python/test.py | 15 |
3 files changed, 50 insertions, 54 deletions
diff --git a/swig/java/Makefile.am b/swig/java/Makefile.am index 27a4f93..4ff926d 100644 --- a/swig/java/Makefile.am +++ b/swig/java/Makefile.am @@ -1,22 +1,10 @@ -SWIG_JAVA_DIR = $(top_srcdir)/swig/java - -SWIG_CMD = $(SWIG) -I$(SWIG_JAVA_DIR) -I$(top_srcdir) -java - -swigjavafiles = \ +javasources = \ 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 \ @@ -24,46 +12,29 @@ javaclasses = \ SWIGTYPE_p_float.class \ SWIGTYPE_p_void.class -$(swiggenfiles): ../xtract.i - $(SWIG_CMD) -package xtract.core -o xtractjavac_wrap.c ../xtract.i +MAINTAINERCLEANFILES = $(javasources) Makefile.in -# Must have "exec" in the name. -execjavawrapperdir = ${libdir} +BUILT_SOURCES = $(srcdir)/xtract_wrap.c +SWIG_SOURCES = ../xtract.i -libxtract = $(top_builddir)/src/libxtract$(LIB_TAG).la +lib_LTLIBRARIES = libjxtract.la +libjxtract_la_SOURCES = $(srcdir)/xtract_wrap.c $(SWIG_SOURCES) +libjxtract_la_CFLAGS = $(SWIG_PYTHON_CPPFLAGS) -I$(top_srcdir)/src +ibjxtract_la_LDFLAGS = -module -lxtract +libjxtract_la_LIBADD = $(top_srcdir)/src/libxtract.la -AM_CPPFLAGS = -I$(top_srcdir)/include $(INCLTDL) $(JAVAINCCMD) +SWIG_JAVA_OPT = -java -package xtract.core -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) - -noinst_DATA = jar-stamp -# -jar-stamp: $(javaclasses) $(javafiles) +xtract_wrap.c : $(SWIG_SOURCES) + $(SWIG) $(SWIG_JAVA_OPT) -I$(top_srcdir) -o $@ $< + $(JAVAC) $(javasources) mkdir -p xtract/core mkdir -p xtract/core/src - cp $(javafiles) xtract/core/src - cp $(javaclasses) xtract/core - touch jar-stamp -# -execjavawrapper_LTLIBRARIES = xtractjavac_wrap.la - -install-exec-hook: - ( cd $(DESTDIR)$(execjavawrapperdir) ; \ - rm -f *.a *.la ) + mv $(javasources) xtract/core/src + mv $(javaclasses) xtract/core + $(JAVAC) test.java clean-local: - rm -rf xtract - -CLEANFILES = $(javaclasses) jar-stamp + -rm -f libjxtract.so xtract_wrap.c $(javasources) $(javaclasses) test.class + -rm -rf xtract -MAINTAINERCLEANFILES = $(swiggenfiles) Makefile.in diff --git a/swig/java/test.java b/swig/java/test.java index d20461a..8949826 100644 --- a/swig/java/test.java +++ b/swig/java/test.java @@ -3,7 +3,16 @@ import xtract.core.*; public class test { public static void main(String argv[]) { -// System.loadLibrary("xtract"); + + try { + System.loadLibrary("jxtract"); + } + catch (UnsatisfiedLinkError e) { + System.out.println("Failed to load the library \"jxtract\""); + System.out.println(e.toString()); + } + + System.out.println("\nRunning libxtract Java bindings test...\n"); int len = 5; int retval = 0; @@ -13,11 +22,20 @@ public class test { result = new float[1]; - for (int i = 0; i < len; i++) + System.out.print("The mean of: "); + + for (int i = 0; i < len; i++){ + System.out.print(i * 2 + ", "); a.setitem(i, i * 2); + } + + System.out.print("is: "); retval = xtract.xtract_mean(a.cast(), len, myvoid, result); - System.out.println(result); + System.out.print(result[0] + "\n"); + + System.out.println("\nFinished!\n\n"); + } } diff --git a/swig/python/test.py b/swig/python/test.py index f491a39..4d994ac 100644 --- a/swig/python/test.py +++ b/swig/python/test.py @@ -1,15 +1,22 @@ #!/usr/bin/python -import xtract +try: + import xtract +except ImportError: + print 'Failed to load the library "jxtract"' + +print '\nRunning libxtract Python bindings test...\n' len = 5 a = xtract.floatArray(len) +temp = [] for i in range(0, len): a[i] = 2 * i + temp.append(str(a[i])) -retval,result = xtract.xtract_mean(a,len,None) - -print result +print 'The mean of ' + ', '.join(temp) + ' is: %.2f' % \ + xtract.xtract_mean(a,len,None)[1] +print '\nFinished!\n' |