
SHELL = /bin/sh
VPATH = @srcdir@
exec_prefix = @exec_prefix@
prefix = @prefix@
bindir = @bindir@
srcdir = @srcdir@
libdir = @libdir@
subdir = java/org/greenstone/mg
top_srcdir = @top_srcdir@
transform = @program_transform_name@

AR = ar
CC = @CC@
CXX = @CXX@
JAVAC = @JAVAC@
JAR = jar
CFLAGS = @CFLAGS@ -ansi -DSILENT -DSHORT_SUFFIX
CXXFLAGS = @CXXFLAGS@ -DSILENT -DSHORT_SUFFIX
JAVACFLAGS = @JAVACFLAGS@
DEFS = @DEFS@
RANLIB = @RANLIB@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
LDFLAGS = @LDFLAGS@
LIBS =  -lstdc++ @LIBS@
TOUCH = echo timestamp >
AWK = @AWK@

MGHOME=../../../..
JAVACLASSDIR=./classes
JAVASRCDIR=../../..
JAVACOPTIONS= -deprecation -g -O
JAVACLASSPATH=$(JAVACLASSDIR)

datadir = $(prefix)/share
libexecdir = $(exec_prefix)/libexec
localedir = $(datadir)/locale
mandir = $(prefix)/man/man1


all: setup compile

setup:
	mkdir -p $(JAVACLASSDIR)

compile: setup
	"$(JAVAC)" $(JAVACFLAGS) -d "$(JAVACLASSDIR)" -sourcepath "$(JAVASRCDIR)" $(JAVACOPTIONS) *.java
	"$(JAVAC)" -h "$(MGHOME)/jni" -classpath "$(JAVACLASSPATH)" MGWrapper.java
	"$(JAVAC)" -h "$(MGHOME)/jni" -classpath "$(JAVACLASSPATH)" MGPassesWrapper.java
	"$(JAR)" cf "$(MGHOME)/mg.jar" -C "$(JAVACLASSDIR)" org

clean:
	rm -rf "$(JAVACLASSDIR)" "$(MGHOME)/mg.jar" "$(MGHOME)/jni/org_greenstone_mg_MGWrapper.h" "$(MGHOME)/jni/org_greenstone_mg_MGPassesWrapper.h"

install:

distclean: clean
	rm -f Makefile


# 'javah' existed until JDK 1.7, transitional in JDK 1.8, then removed by JDK 1.9 (use 'javac -h' instead)
# Since we are now committed to java 1.8, removing all the javah code
#JAVAH = $(JAVA_HOME)/bin/javah

# the following was under the compile target

#      	#$(eval found = $(shell which javah 2>/dev/null | wc -l))
#	$(eval found = $(shell command -v $(JAVAH) | wc -l))
#	if test "$(found)" = "1" ; then \
#	  "$(JAVAH)" -classpath "$(JAVACLASSPATH)" -d "$(MGHOME)/jni" org.greenstone.mg.MGWrapper ; \
#	  "$(JAVAH)" -classpath "$(JAVACLASSPATH)" -d "$(MGHOME)/jni" org.greenstone.mg.MGPassesWrapper ; \
#	else \
#	  "$(JAVAC)" -h "$(MGHOME)/jni" -classpath "$(JAVACLASSPATH)" MGWrapper.java ; \
#	  "$(JAVAC)" -h "$(MGHOME)/jni" -classpath "$(JAVACLASSPATH)" MGPassesWrapper.java ; \
#	fi	
