Mercurial > hg > libxtract
changeset 92:35a3bb5c3ffd
Java bindings (with simple test) now working. Unified Python and Java bindings tests.
author | Jamie Bullock <jamie@postlude.co.uk> |
---|---|
date | Thu, 06 Sep 2007 14:05:37 +0000 |
parents | 84fea00d8509 |
children | 61fe1af213cd |
files | configure.in src/scalar.c swig/java/Makefile.am swig/java/test.java swig/python/test.py xtract/xtract_scalar.h |
diffstat | 6 files changed, 66 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in Wed Sep 05 17:57:09 2007 +0000 +++ b/configure.in Thu Sep 06 14:05:37 2007 +0000 @@ -85,6 +85,15 @@ echo ]) +dnl set a specific java compiler +AC_ARG_WITH(javac, + [ --with-javac=compiler set a specific java compiler (determined automatically if not set) ], + [JAVAC="$withval" + echo + echo "JAVAC is set to $withval" + echo + ]) + dnl If --enable-swig, make with java bindings AC_ARG_WITH(java, [ --with-java If --enable-swig - make with java bindings (default=no) ], @@ -150,12 +159,14 @@ fi if [[ "$with_java" = "true" ]] ; then - AC_PROG_JAVAC + if test "$JAVAC" = "" + then + AC_PROG_JAVAC + fi if test "$JAVAC" = "javac" then AC_JNI_INCLUDE_DIR - for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS do CFLAGS="$CFLAGS -I$JNI_INCLUDE_DIR"
--- a/src/scalar.c Wed Sep 05 17:57:09 2007 +0000 +++ b/src/scalar.c Thu Sep 06 14:05:37 2007 +0000 @@ -36,7 +36,7 @@ #define expf exp #endif -int test(void){ +void test(void){ printf("Hello world"); }
--- a/swig/java/Makefile.am Wed Sep 05 17:57:09 2007 +0000 +++ b/swig/java/Makefile.am Thu Sep 06 14:05:37 2007 +0000 @@ -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 @@ 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 + -rm -f libjxtract.so xtract_wrap.c $(javasources) $(javaclasses) test.class + -rm -rf xtract -CLEANFILES = $(javaclasses) jar-stamp - -MAINTAINERCLEANFILES = $(swiggenfiles) Makefile.in
--- a/swig/java/test.java Wed Sep 05 17:57:09 2007 +0000 +++ b/swig/java/test.java Thu Sep 06 14:05:37 2007 +0000 @@ -3,7 +3,16 @@ 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 @@ 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"); + } }
--- a/swig/python/test.py Wed Sep 05 17:57:09 2007 +0000 +++ b/swig/python/test.py Thu Sep 06 14:05:37 2007 +0000 @@ -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 'The mean of ' + ', '.join(temp) + ' is: %.2f' % \ + xtract.xtract_mean(a,len,None)[1] -print result - +print '\nFinished!\n'