diff options
-rw-r--r-- | configure.in | 43 | ||||
-rw-r--r-- | src/scalar.c | 4 | ||||
-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 |
9 files changed, 177 insertions, 25 deletions
diff --git a/configure.in b/configure.in index 285ab37..5518067 100644 --- a/configure.in +++ b/configure.in @@ -85,6 +85,19 @@ AC_ARG_WITH(fftw3_dir, 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 @@ AC_ARG_ENABLE(swig, 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_SUBST(PD_SOURCES) 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 @@ else echo "PD external: no" fi if test "$swig" == "true"; then - echo "SWIG Python bindings: yes" + echo "SWIG bindings: yes" +else + echo "SWIG bindings: no" +fi +if test "$with_java" == "true"; then + echo "with JAVA module: yes" else - echo "SWIG Python bindings: no" + echo "with JAVA module: no" fi echo echo "**************************************************************" diff --git a/src/scalar.c b/src/scalar.c index fef1e6e..9be6ec6 100644 --- a/src/scalar.c +++ b/src/scalar.c @@ -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; 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" |