#!/usr/bin/make -f

JAVA_HOME=/usr/lib/jvm/default-java
DEBPKGNAME:=lib$(shell dpkg-parsechangelog | awk '/^Source:/ {print $$2}')-java
BINDIR=debian/$(DEBPKGNAME)/usr/bin
MPJ_HOME=/usr/share/mpj
LIBDIR=debian/$(DEBPKGNAME)/$(MPJ_HOME)

%:
	dh $@ --with javahelper

#override_dh_auto_build:
#	dh_auto_build -- -Dant.build.javac.source=1.8 -Dant.build.javac.target=1.8

override_dh_install:
	dh_install
	mkdir -p $(BINDIR)
	for bin in bin/* ; do \
	    realbin=`basename $${bin} .sh` ; \
	    sed '1a export MPJ_HOME=$(MPJ_HOME)' $${bin} > $(BINDIR)/$${realbin} ; \
	done

override_jh_installlibs:
	jh_installlibs
	# Amongst the resulting JARs we have /usr/share/java/mpi.jar which is
        # also in libopenmpi-java.  So all JARs will go into private MPJ_HOME
	# and only /usr/share/java/mpj.jar will be exposed in /usr/share/java
	mkdir -p $(LIBDIR)/lib
	mv debian/$(DEBPKGNAME)/usr/share/java/* $(LIBDIR)/lib
	mkdir -p debian/$(DEBPKGNAME)/usr/share/java/
	for lib in $(LIBDIR)/lib/mpj[-.0-9]*jar ; do \
	    echo "linking $${lib}" ; \
	    ln -s ../mpj/lib/`basename $${lib}` debian/$(DEBPKGNAME)/usr/share/java/`basename $${lib}` ; \
	done

override_dh_fixperms:
	dh_fixperms
	chmod -x debian/$(DEBPKGNAME)/etc/mpj/local2.conf

#override_dh_auto_test:
#	ant -f test/build.xml
#
# Needs more work:
#   
#    [javac] /build/mpj-0.44+dfsg/test/build.xml:7: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
#    [javac] Compiling 5 source files
#    [javac] Note: /build/mpj-0.44+dfsg/test/jgf_mpj_benchmarks/jgfutil/JGFInstrumentor.java uses unchecked or unsafe operations.
#    [javac] Note: Recompile with -Xlint:unchecked for details.
#    [javac] /build/mpj-0.44+dfsg/test/build.xml:10: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
#    [javac] Compiling 9 source files
#    [javac] /build/mpj-0.44+dfsg/test/jgf_mpj_benchmarks/section1/JGFAlltoallBench.java:28: error: cannot find symbol
#    [javac] public class JGFAlltoallBench implements JGFSection1{
#    [javac]                                          ^
#    [javac]   symbol: class JGFSection1
#    [javac] /build/mpj-0.44+dfsg/test/jgf_mpj_benchmarks/section1/JGFBarrierBench.java:27: error: cannot find symbol
#    [javac] public class JGFBarrierBench implements JGFSection1{
#    [javac]                                         ^
#    [javac]   symbol: class JGFSection1
#    [javac] /build/mpj-0.44+dfsg/test/jgf_mpj_benchmarks/section1/JGFBcastBench.java:28: error: cannot find symbol
#    [javac] public class JGFBcastBench implements JGFSection1{
#    [javac]                                       ^
#
