# Makefile template for SQLite Java wrapper

prefix =	@prefix@
CC =		@CC@
LIBTOOL =	./libtool
SQLITE_INC =	@SQLITE_INC@
SQLITE_LIB =	@SQLITE_LIB@
SQLITE3_INC =	@SQLITE3_INC@
SQLITE3_LIB =	@SQLITE3_LIB@
JAVAH =		@JAVAH@
JAVAC =		@JAVAC@
JAVADOC =	@JAVADOC@
JAR =		@JAR@
JNIINCLUDE =	@JNIINCLUDE@
INSTALL =	@INSTALL@
JAR_DIR =	@JAR_DIR@
NATIVE_LIB_DIR =	@NATIVE_LIB_DIR@

CFLAGS=	-Wall -O -fPIC $(JNIINCLUDE) $(SQLITE_INC) $(SQLITE3_INC) \
	-DHAVE_SQLITE2=@HAVE_SQLITE2@ -DHAVE_SQLITE3=@HAVE_SQLITE3@ \
	-DHAVE_SQLITE_FUNCTION_TYPE=@HAVE_SQLITE_FUNCTION_TYPE@ \
	-DHAVE_SQLITE_OPEN_AUX_FILE=@HAVE_SQLITE_OPEN_AUX_FILE@ \
	-DHAVE_SQLITE_SET_AUTHORIZER=@HAVE_SQLITE_SET_AUTHORIZER@ \
	-DHAVE_SQLITE_TRACE=@HAVE_SQLITE_TRACE@ \
	-DHAVE_SQLITE_COMPILE=@HAVE_SQLITE_COMPILE@ \
	-DHAVE_SQLITE_PROGRESS_HANDLER=@HAVE_SQLITE_PROGRESS_HANDLER@
LIBS=	@SQLITE_LIB@ @SQLITE3_LIB@

# Add new suffixes
.SUFFIXES: .java .class .lo .la .jar

#
# Rule to compile `java' files
#
.java.class:
	$(JAVAC) $(JAVAC_FLAGS) $<

CLASSES = \
	SQLite/Authorizer.class \
	SQLite/BusyHandler.class \
	SQLite/Callback.class \
	SQLite/Database.class \
	SQLite/Exception.class \
	SQLite/Shell.class \
	SQLite/TableResult.class \
	SQLite/Function.class \
	SQLite/FunctionContext.class \
	SQLite/Constants.class \
	SQLite/Trace.class \
	SQLite/Vm.class \
	SQLite/ProgressHandler.class \
	SQLite/StringEncoder.class

PRIVATE_CLASSES = \
	SQLite/DBDump.class \
	SQLite/JDBCDriver.class \
	SQLite/@JDBCVER@/JDBCConnection.class \
	SQLite/@JDBCVER@/JDBCStatement.class \
	SQLite/@JDBCVER@/JDBCResultSet.class \
	SQLite/@JDBCVER@/JDBCResultSetMetaData.class \
	SQLite/@JDBCVER@/JDBCDatabaseMetaData.class \
	SQLite/@JDBCVER@/JDBCPreparedStatement.class \
	SQLite/@JDBCVER@/TableResultX.class \
	SQLite/@JDBCVER@/DatabaseX.class

DOCSRCS = \
	SQLite/Authorizer.java \
	SQLite/BusyHandler.java \
	SQLite/Callback.java \
	SQLite/Database.java \
	SQLite/Exception.java \
	SQLite/TableResult.java \
	SQLite/Function.java \
	SQLite/FunctionContext.java \
	SQLite/Constants.java \
	SQLite/Trace.java \
	SQLite/Vm.java \
	SQLite/ProgressHandler.java \
	SQLite/StringEncoder.java

all:	sqlite.jar libsqlite_jni.la

SQLite/Constants.java:	native/mkconst
	native/mkconst > SQLite/Constants.java

sqlite.jar:	$(CLASSES) $(PRIVATE_CLASSES)
	$(JAR) cmf manifest sqlite.jar $(CLASSES) $(PRIVATE_CLASSES)

native/sqlite_jni.h:	SQLite/Database.class SQLite/Vm.class \
	SQLite/FunctionContext.class
	$(JAVAH) -o native/sqlite_jni.h SQLite.Database SQLite.Vm \
	    SQLite.FunctionContext

sqlite_jni.lo:	native/sqlite_jni.h native/sqlite_jni.c
	$(LIBTOOL) $(CC) -c $(CFLAGS) native/sqlite_jni.c

libsqlite_jni.la:	sqlite_jni.lo
	$(LIBTOOL) $(CC) -o libsqlite_jni.la sqlite_jni.lo \
	    -rpath $(NATIVE_LIB_DIR) $(LIBS)

native/mkconst:	native/mkconst.c
	$(LIBTOOL) $(CC) -I$(SQLITE_INC) -o native/mkconst native/mkconst.c \
	    $(LIBS)

test:
	$(JAVAC) test.java

clean:
	$(RM) SQLite/*.class SQLite/@JDBCVER@/*.class *.lo *.la *.o \
	    native/sqlite_jni.h native/mkconst \
	    SQLite/Constants.java \
	    test.class sqlite.jar conftest*
	$(RM) -r .libs

distclean:	clean
	$(RM) config.status config.log config.cache Makefile

javadoc:
	$(JAVADOC) -private -nodeprecated -nodeprecatedlist \
	    -noindex -nohelp -overview doc/overview.html \
	    -windowtitle "SQLite Java Wrapper" \
	    -doctitle "`cat doc/title.html`" \
	    -bottom '<small>Contact: <a HREF="mailto:chw@ch-werner.de">Christian Werner</a></small>' \
	    -d doc -sourcepath . $(DOCSRCS)
	$(INSTALL) -m 644 test.java doc/test.java

install:
	$(INSTALL) -d -m 755 $(JAR_DIR)
	$(INSTALL) -m 644 sqlite.jar $(JAR_DIR)
	$(INSTALL) -d -m 755 $(NATIVE_LIB_DIR)
	$(LIBTOOL) $(INSTALL) libsqlite_jni.la $(NATIVE_LIB_DIR)
