changeset 88:525bfdf936c6

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.
author Jamie Bullock <jamie@postlude.co.uk>
date Wed, 05 Sep 2007 14:32:17 +0000
parents 0df00d5c9269
children ee7442343cf0
files configure.in src/scalar.c swig/Makefile.am swig/java/Makefile.am swig/java/test.java swig/python/Makefile.am swig/python/test.py swig/python/xtract.i swig/test.py swig/xtract.i
diffstat 10 files changed, 190 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Tue Sep 04 19:07:55 2007 +0000
+++ b/configure.in	Wed Sep 05 14:32:17 2007 +0000
@@ -85,6 +85,19 @@
     echo
     ])
 
+dnl If --enable-swig, make with java bindings
+AC_ARG_WITH(java,
+    [ --with-java If --enable-swig - make with java bindings (default=no) ],
+    [with_java=true])
+
+AM_CONDITIONAL(BUILD_JAVA, test "x${with_java}" = 'xtrue')
+
+dnl If --enable-swig, make with java bindings
+AC_ARG_WITH(python,
+    [ --with-python If --enable-swig - make with python bindings (default=no) ],    [with_python=true])
+
+AM_CONDITIONAL(BUILD_PYTHON, test "x${with_python}" = 'xtrue')
+
 dnl Are we building with fftw?
 if [[ "$fft" = "true" ]] ; then
     LDFLAGS="$LDFLAGS -lfftw3f"
@@ -148,11 +161,27 @@
 dnl SWIG stuff
 if [[ "$swig" = "true" ]] ; then
     AC_PROG_SWIG(1.3.21)
+    AC_DEFINE([BUILD_SWIG], [1], [Build the swig bindings])
+fi
+
+if [[ "$with_java" = "true" ]] ; then
+    AC_PROG_JAVAC
+    AC_JNI_INCLUDE_DIR
+
+    for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
+    do
+	CFLAGS="$CFLAGS -I$JNI_INCLUDE_DIR"
+    done
+   dnl AC_PROG_JAVAH
+   dnl AC_PATH_PROG(JAVAH,javah)
+fi
+
+if [[ "$with_python" = "true" ]] ; then
     AM_PATH_PYTHON
     SWIG_PYTHON
-    AC_DEFINE([BUILD_SWIG], [1], [Build the swig bindings])
 fi
 
+
 AM_CONDITIONAL(BUILD_SWIG, test "x${swig}" = 'xtrue')
 
 dnl ------------------------------------------
@@ -232,7 +261,8 @@
 AC_CONFIG_FILES([doc/documentation.doxygen
 				libxtract.pc])
 
-AC_OUTPUT(Makefile src/Makefile xtract/Makefile doc/Makefile examples/Makefile examples/puredata/Makefile examples/simpletest/Makefile swig/Makefile)
+dnl There must be a better way to do this...
+AC_OUTPUT(Makefile src/Makefile xtract/Makefile doc/Makefile examples/Makefile examples/puredata/Makefile examples/simpletest/Makefile swig/Makefile swig/python/Makefile swig/java/Makefile)
 
 echo
 echo "**************************************************************"
@@ -261,9 +291,14 @@
   echo "PD external:             no"
 fi
 if test "$swig" == "true"; then
-  echo "SWIG Python bindings:                      yes"
+  echo "SWIG bindings:                      yes"
 else
-  echo "SWIG Python bindings:                      no"
+  echo "SWIG bindings:                      no"
+fi
+if test "$with_java" == "true"; then
+    echo "with JAVA module:		    yes"
+else
+    echo "with JAVA module:		    no"
 fi
 echo
 echo "**************************************************************"
--- a/src/scalar.c	Tue Sep 04 19:07:55 2007 +0000
+++ b/src/scalar.c	Wed Sep 05 14:32:17 2007 +0000
@@ -36,6 +36,10 @@
     #define expf exp
 #endif
 
+int test(void){
+    printf("Hello world");
+}
+
 int xtract_mean(const float *data, const int N, const void *argv, float *result){
 
     int n = N;
--- a/swig/Makefile.am	Tue Sep 04 19:07:55 2007 +0000
+++ b/swig/Makefile.am	Wed Sep 05 14:32:17 2007 +0000
@@ -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
+if BUILD_PYTHON
+PYTHON_BUILD_DIR = python
+endif
 
-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
-
+SUBDIRS = $(JAVA_BUILD_DIR) $(PYTHON_BUILD_DIR)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/swig/java/Makefile.am	Wed Sep 05 14:32:17 2007 +0000
@@ -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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/swig/java/test.java	Wed Sep 05 14:32:17 2007 +0000
@@ -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);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/swig/python/Makefile.am	Wed Sep 05 14:32:17 2007 +0000
@@ -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
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/swig/python/test.py	Wed Sep 05 14:32:17 2007 +0000
@@ -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
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/swig/python/xtract.i	Wed Sep 05 14:32:17 2007 +0000
@@ -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"
--- a/swig/test.py	Tue Sep 04 19:07:55 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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
-
-
-
-
--- a/swig/xtract.i	Tue Sep 04 19:07:55 2007 +0000
+++ b/swig/xtract.i	Wed Sep 05 14:32:17 2007 +0000
@@ -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"