diff --git a/SWIG/Examples/Makefile.in b/SWIG/Examples/Makefile.in index 8aa2a1364..f04ef2b4c 100644 --- a/SWIG/Examples/Makefile.in +++ b/SWIG/Examples/Makefile.in @@ -231,6 +231,34 @@ python_static_cpp: $(SRCS) $(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET) +################################################################## +##### JAVA ###### +################################################################## + +# You need to set this variable to the java directories containing the +# files "jni.h" and "md.h" +# usually something like /usr/java/include and /usr/java/include/. + +JAVA_INCLUDE= @JAVAINC@ + +# ---------------------------------------------------------------- +# Build a java dynamically loadable module (C) +# ---------------------------------------------------------------- + +java: $(SRCS) + $(SWIG) -java $(SWIGOPT) $(INTERFACE) + $(CC) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(JAVA_INCLUDE) + $(LDSHARED) $(OBJS) $(IOBJS) $(LIBS) -o $(TARGET)$(SO) + +# ---------------------------------------------------------------- +# Build a java dynamically loadable module (C++) +# ---------------------------------------------------------------- + +java_cpp: $(SRCS) + $(SWIG) -java -c++ $(SWIGOPT) $(INTERFACE) + $(CXX) -c $(CCSHARED) $(CFLAGS) $(SRCS) $(ISRCS) $(INCLUDE) $(JAVA_INCLUDE) + $(CXXSHARED) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(TARGET)$(SO) + ################################################################## ##### SWIG ###### ################################################################## diff --git a/SWIG/Examples/java/simple/Makefile b/SWIG/Examples/java/simple/Makefile new file mode 100644 index 000000000..d62e5bfeb --- /dev/null +++ b/SWIG/Examples/java/simple/Makefile @@ -0,0 +1,13 @@ +TOP = ../.. +SWIG = $(TOP)/../swig +SRCS = example.c +TARGET = libexample +INTERFACE = example.i +SWIGOPT = +all:: + $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \ + SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java + +clean:: + rm -f *_wrap* *.o core *~ *.so *.pm myperl + diff --git a/SWIG/Examples/java/simple/README b/SWIG/Examples/java/simple/README new file mode 100644 index 000000000..07e8da069 --- /dev/null +++ b/SWIG/Examples/java/simple/README @@ -0,0 +1 @@ +Simple example from users manual. diff --git a/SWIG/Examples/java/simple/example.i b/SWIG/Examples/java/simple/example.i new file mode 100644 index 000000000..b7b678776 --- /dev/null +++ b/SWIG/Examples/java/simple/example.i @@ -0,0 +1,11 @@ +/* File : example.i */ +%module example +%{ +/* Put headers and other declarations here */ +%} + + +extern double My_variable; +extern int fact(int); +%name(mod) extern int my_mod(int n, int m); +extern char *get_time(); diff --git a/SWIG/Examples/java/simple/main.java b/SWIG/Examples/java/simple/main.java new file mode 100644 index 000000000..bbebfb660 --- /dev/null +++ b/SWIG/Examples/java/simple/main.java @@ -0,0 +1,32 @@ +import example; + +public class main { + + static { + try { + System.loadLibrary("example"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Cannot load the example native code.\nMake sure your LD_LIBRARY_PATH contains \'.\'\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + System.out.println(example.get_time()); + + System.out.println("My Variable = " + example.get_My_variable()); + + for(int i=0; i<14; i++) { + System.out.println("" + i + " factorial is " + example.fact(i)); + } + + for(int i=1; i<100; i++) { + for(int j=1; j<100; j++) { + int n = example.mod(i, j); + example.set_My_variable(example.get_My_variable() + n); + } + } + + System.out.println("My_variable = " + example.get_My_variable()); + } +} diff --git a/SWIG/configure.in b/SWIG/configure.in index 9dfc33654..d9d7ec730 100644 --- a/SWIG/configure.in +++ b/SWIG/configure.in @@ -430,8 +430,7 @@ AC_SUBST(PYLINK) PERLBIN=nope -AC_ARG_WITH(perl5,[ --with-perl5=path Set location of Perl5 executable],[ - PERLBIN="$withval"], [PERLBIN=nope]) +AC_ARG_WITH(perl5,[ --with-perl5=path Set location of Perl5 executable],[ PERLBIN="$withval"], [PERLBIN=nope]) # First figure out what the name of Perl5 is @@ -468,6 +467,61 @@ if test "$PERL" != nope; then AC_SUBST(PERL5EXT) +#---------------------------------------------------------------- +# Look for java +#---------------------------------------------------------------- + +AC_ARG_WITH(java, [ --with-java=path Set location of java executable],[JAVABIN="$withval"], [JAVABIN=nope]) +AC_ARG_WITH(javac, [ --with-javac=path Set location of javac executable],[JAVACBIN="$withval"], [JAVACBIN=nope]) + +if test "$JAVABIN" = nope ; then + AC_CHECK_PROGS(JAVA, java kaffe guavac, nope) +else + JAVA="$JAVABIN" +fi + +if test "$JAVACBIN" = nope ; then + AC_CHECK_PROGS(JAVAC, javac, nope) +else + JAVAC="$JAVACBIN" +fi + +AC_MSG_CHECKING(for java include file jni.h) +AC_ARG_WITH(java, [ --with-java-include=path Set location of java include files], [JAVAINCDIR="$withval"], [JAVAINCDIR=nope]) + +if test "$JAVAINCDIR" = nope; then + dirs="/usr/java/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/include/kaffe /usr/local/include/kaffe" + for d in $dirs ; do + if test -r $d/jni.h ; then + AC_MSG_RESULT($d) + JAVAINCDIR=$d + JAVAINC="-I$d" + break + fi + done +fi + +if test "$JAVAINCDIR" = nope ; then + AC_MSG_RESULT(not found) +else + # now look for /md.h + AC_MSG_CHECKING(for java include file md.h) + JAVAMDDIR=`find $JAVAINCDIR -name md.h -print` + if test "$JAVAMDDIR" = "" ; then + AC_MSG_RESULT(not found) + else + JAVAMDDIR=`dirname $JAVAMDDIR` + JAVAINC="${JAVAINC} -I$JAVAMDDIR" + AC_MSG_RESULT($JAVAMDDIR) + fi +fi + +AC_SUBST(JAVA) +AC_SUBST(JAVAC) +AC_SUBST(JAVAINC) + +AC_SUBST(ROOT_DIR)ROOT_DIR=`pwd` + #---------------------------------------------------------------- # Look for Guile #----------------------------------------------------------------