AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/src/include

JAVADEST = src/com/wiredtiger/db
JAVADESTFULL = $(srcdir)/$(JAVADEST)
JAVAEXAMPLES = $(top_srcdir)/examples/java/com/wiredtiger/examples
JAVATEST = $(top_srcdir)/test/java/com/wiredtiger/test
BUILT_SOURCES = wiredtiger_wrap.c
SWIG_SOURCES = wiredtiger.i

JDOCDIR = $(top_srcdir)/docs/java
# The Java documentation is currently generated by Doxygen - disable javadoc
#java_DATA = $(JDOCDIR)/index.html

javadir = $(datadir)/java/$(PACKAGE)-$(PACKAGE_VERSION)
JAVA_SRC = \
		$(JAVADESTFULL)/AsyncCallback.java \
		$(JAVADESTFULL)/AsyncOp.java \
		$(JAVADESTFULL)/AsyncOpType.java \
		$(JAVADESTFULL)/Connection.java \
		$(JAVADESTFULL)/Cursor.java \
		$(JAVADESTFULL)/Modify.java \
		$(JAVADESTFULL)/SearchStatus.java \
		$(JAVADESTFULL)/PackFormatInputStream.java \
		$(JAVADESTFULL)/PackInputStream.java \
		$(JAVADESTFULL)/PackOutputStream.java \
		$(JAVADESTFULL)/PackUtil.java \
		$(JAVADESTFULL)/Session.java \
		$(JAVADESTFULL)/WiredTigerException.java \
		$(JAVADESTFULL)/WiredTigerPackingException.java \
		$(JAVADESTFULL)/WiredTigerPanicException.java \
		$(JAVADESTFULL)/WiredTigerRollbackException.java \
		$(JAVADESTFULL)/wiredtiger.java \
		$(JAVADESTFULL)/wiredtigerConstants.java \
		$(JAVADESTFULL)/wiredtigerJNI.java \
		$(JAVADESTFULL)/WT_MODIFY_LIST.java \
		$(JAVAEXAMPLES)/ex_access.java \
		$(JAVAEXAMPLES)/ex_all.java \
		$(JAVAEXAMPLES)/ex_async.java \
		$(JAVAEXAMPLES)/ex_call_center.java \
		$(JAVAEXAMPLES)/ex_cursor.java \
		$(JAVAEXAMPLES)/ex_log.java \
		$(JAVAEXAMPLES)/ex_schema.java \
		$(JAVAEXAMPLES)/ex_stat.java \
		$(JAVAEXAMPLES)/ex_thread.java

JAVA_JUNIT = \
		$(JAVATEST)/AutoCloseTest.java \
		$(JAVATEST)/AsyncTest.java \
		$(JAVATEST)/BackupCursorTest.java \
		$(JAVATEST)/ConfigTest.java \
		$(JAVATEST)/ConcurrentCloseTest.java \
		$(JAVATEST)/CursorTest.java \
		$(JAVATEST)/CursorTest02.java \
		$(JAVATEST)/CursorTest03.java \
		$(JAVATEST)/ExceptionTest.java \
		$(JAVATEST)/PackTest.java \
		$(JAVATEST)/PackTest02.java \
		$(JAVATEST)/PackTest03.java \
		$(JAVATEST)/WiredTigerSuite.java

dist_java_JAVA = $(JAVA_SRC) @JAVA_JUNIT@
dist_java_DATA = wiredtiger.jar

EXTRA_JAVA = $(JAVA_JUNIT)

java_LTLIBRARIES = libwiredtiger_java.la

TESTS_JUNIT = AllJunitTests

TESTS       = @TESTS_JUNIT@

AllJunitTests:
	echo "#! /bin/sh" > $@
	echo 'SCRIPT_DIR=`dirname $$0`' >> $@
	echo 'env LD_LIBRARY_PATH=$$SCRIPT_DIR/../../.libs:$$SCRIPT_DIR/.libs DYLD_LIBRARY_PATH=$$SCRIPT_DIR/../../.libs JAVA_LIBRARY_PATH=$$SCRIPT_DIR/.libs @JUNIT@ com.wiredtiger.test.WiredTigerSuite' >> $@
	chmod +x $@
	mkdir -p WT_HOME

CPPFLAGS += $(JNI_CPPFLAGS)
# Some warnings when compiling the generated code are unavoidable
CFLAGS += -w
libwiredtiger_java_la_SOURCES = $(BUILT_SOURCES) $(SWIG_SOURCES)
#libwiredtiger_java_la_LDFLAGS = -module
libwiredtiger_java_la_LIBADD = $(abs_top_builddir)/libwiredtiger.la

all-local: wiredtiger.jar

$(srcdir)/wiredtiger_wrap.c: $(top_srcdir)/src/include/wiredtiger.in $(SWIG_SOURCES)
	(cd $(srcdir) && \
	    $(SWIG) -Wall -v -java -nodefaultctor -nodefaultdtor -package com.wiredtiger.db -I$(abs_top_builddir) -outdir $(JAVADEST) -o wiredtiger_wrap.c wiredtiger.i)

$(JDOCDIR)/index.html:	$(dist_java_JAVA)
	mkdir -p $(JDOCDIR)
	javadoc -public -d $(JDOCDIR) -link http://docs.oracle.com/javase/6/docs/api $(JAVADESTFULL)/wiredtiger.java $(JAVADESTFULL)/wiredtigerConstants.java $(JAVADESTFULL)/[A-Z]*.java

wiredtiger.jar: $(dist_java_JAVA) classjava.stamp
	(cd $(top_builddir) && \
	    $(JAR) -cf wiredtiger.jar com/)
	cp $(top_builddir)/wiredtiger.jar .
