#-------------------------------------------------------------------------------
# Define Program, Program Directory, Program Version, Install Directories, and
# Target Names ... set mode to default (empty)
#-------------------------------------------------------------------------------

CV = @

PROGRAM				= SLBM_JNI
PROG_NAM			= SLBM_JNI

JSOURCE_DIR			= gov\sandia\gnem\slbmjni\\
CCSOURCE_DIR		= cc\src\\
CCINCLUDE_DIR		= cc\include\\

JNIINCLUDE_DIR		= ${JAVA_HOME}include
SLBMINCLUDE_DIR		= ..\SLBM\include

GEO_INC				= ../GeoTessCPP/include
GEO_LIB				= ../GeoTessCPP/lib

LIB_DIR				= ..\lib\\
CLASSPATH_DIR		= src\gov\sandia\gnem\slbmjni\\

CCSOURCES			= cc\src\pglJavaUtil.cc cc\src\SlbmInterfaceJNI.cc


CCOBJECTS			= pglJavaUtil.o SlbmInterfaceJNI.o

ifeq ($(ARCH),32bit)
MACHINE=/MACHINE:X86
else
MACHINE=/MACHINE:X64
endif

CC = cl
RM = del
CD = chdir /D 
JNIINCLUDEOS_DIR = ${JAVA_HOME}include\win32\\
CCFLAGS = /EHsc /nologo /Fo"$@" /Od /D "WIN32" /D "_WINDOWS" /D "_USRDLL" /D "SLBM_JNI_EXPORTS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /Gm /RTC1 /MDd /W1 /Zi /errorReport:prompt
COMMAND = ${CV} ${CC} ${CCFLAGS} ${CCOBJECTS} /link /MANIFEST /dll /OUT:"${LIB_DIR}slbmjni.dll" -LIBPATH:"${LIB_DIR}" ${LIB_DIR}\libslbm.lib $(MACHINE) /LIBPATH:$(GEO_LIB) libgeotesscpp.lib \
		  && cd ..\lib && mt /nologo -manifest slbmjni.dll.manifest -outputresource:slbmjni.dll;2
COMPILE = ${CC} ${CCFLAGS} /I"$(GEO_INC)" -I"${INCLUDE}" -I"${CCINCLUDE_DIR}" -I"${JNIINCLUDE_DIR}" -I"${JNIINCLUDEOS_DIR}" -I"${SLBMINCLUDE_DIR}" -c 
VERSION_FLAG =

#-------------------------------------------------------------------------------
# targets
#-------------------------------------------------------------------------------

# build the c++ jni library and the java jar file.
all : info slbmjnilib cleanobjs javajar done

pglJavaUtil.o :
	${CV} echo "Compiling pglJavaUtil.cc"
	$(CV) $(COMPILE) cc/src/pglJavaUtil.cc
	${CV} echo ""

SlbmInterfaceJNI.o:
	${CV} echo "Compiling SlbmInterfaceJNI.cc"
	${CV} ${COMPILE} ${CCSOURCE_DIR}SlbmInterfaceJNI.cc
	${CV} echo ""

# build the c++ jni library but not the java jar file.
slbmjni : info slbmjnilib clean done

slbmjnilib: ${CCOBJECTS}
	${CV} echo "building shared library libslbmjni.so"
	${COMMAND}

cleanobjs :
	${CV} echo "removing object files"
	${RM} pglJavaUtil.o
	${RM} SlbmInterfaceJNI.o
	${CV} echo ""

# build the java jar file.
 javajar:
	${CV} echo "Building slbmjni.jar file"
	${CV} ${CD} java\SlbmInterface\src\ && \
	javac -classpath ${CLASSPATH_DIR} ${JSOURCE_DIR}GreatCircleData.java \
	${JSOURCE_DIR}GridProfile.java \
	${JSOURCE_DIR}GridWeight.java \
	${JSOURCE_DIR}QueryProfile.java \
	${JSOURCE_DIR}ZhaoParameters.java \
	${JSOURCE_DIR}SLBMException.java \
	$(JSOURCE_DIR)Point.java \
	${JSOURCE_DIR}QueryNeighborInfo.java \
	${JSOURCE_DIR}SlbmInterface.java
	${CV} ${CD} java\SlbmInterface\src\ && \
	jar -cf ..\..\..\..\lib\slbmjni.jar ${JSOURCE_DIR}SLBMException.class ${JSOURCE_DIR}GridProfile.class ${JSOURCE_DIR}QueryProfile.class \
	${JSOURCE_DIR}ZhaoParameters.class ${JSOURCE_DIR}SLBMException.class ${JSOURCE_DIR}SlbmInterface.class ${JSOURCE_DIR}GridWeight.class $(JSOURCE_DIR)Point.class \
	${JSOURCE_DIR}GreatCircleData.class ${JSOURCE_DIR}QueryNeighborInfo.class
	${CV} ${CD} java\SlbmInterface\src\ && \
	${RM} ${JSOURCE_DIR}GreatCircleData.class && \
	${RM} ${JSOURCE_DIR}GridProfile.class && \
	${RM} ${JSOURCE_DIR}GridWeight.class && \
	${RM} ${JSOURCE_DIR}QueryProfile.class && \
	${RM} $(JSOURCE_DIR)Point.class \
	${RM} ${JSOURCE_DIR}ZhaoParameters.class && \
	${RM} ${JSOURCE_DIR}SLBMException.class && \
	${RM} ${JSOURCE_DIR}SlbmInterface.class && \
	${RM} ${JSOURCE_DIR}QueryNeighborInfo.class
	${CV} echo ""

info :
	@ echo "========================================="
	@ echo "Building" $(PROG_NAM) "on" ${OS} "with"
	@ $(CC) $(VERSION_FLAG)
	$(CV) echo JAVA_HOME = $(JAVA_HOME)
	$(CV) java -version
	@ echo ""

done :
	@echo "Done building" $(PROG_NAM)
	@ echo ""