#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export LC_ALL=C.UTF-8

JAVA_HOME=/usr/lib/jvm/default-java

%:
	dh $@  --with javahelper

override_dh_auto_configure:
	dh_auto_configure
	sed -e 's/BJLIB/biojava4-forester/g' debian/build.xml > biojava-forester/build.xml
	sed -e 's/BJLIB/biojava4-aa-prop/g' debian/build.xml > biojava-aa-prop/build.xml
	sed -e 's/BJLIB/biojava4-core/g' debian/build.xml > biojava-core/build.xml
	sed -e 's/BJLIB/biojava4-alignment/g' debian/build.xml > biojava-alignment/build.xml
	sed -e 's/BJLIB/biojava4-genome/g' debian/build.xml > biojava-genome/build.xml
	sed -e 's/BJLIB/biojava4-modfinder/g' debian/build.xml > biojava-modfinder/build.xml
	sed -e 's/BJLIB/biojava4-phylo/g' debian/build.xml > biojava-phylo/build.xml
	sed -e 's/BJLIB/biojava4-sequencing/g' debian/build.xml > biojava-sequencing/build.xml
	sed -e 's/BJLIB/biojava4-protein-disorder/g' debian/build.xml > biojava-protein-disorder/build.xml
	sed -e 's/BJLIB/biojava4-structure/g' debian/build.xml > biojava-structure/build.xml
	sed -e 's/BJLIB/biojava4-ws/g' debian/build.xml > biojava-ws/build.xml
	sed -e 's/BJLIB/biojava4-structure-gui/g' debian/build.xml > biojava-structure-gui/build.xml
	sed -e 's/BJLIB/biojava4-ontology/g' debian/build.xml > biojava-ontology/build.xml
	sed -e 's/BJLIB/biojava4-protein-comparison-tool/g' debian/build.xml > biojava-protein-comparison-tool/build.xml
	sed -e 's/BJLIB/biojava4-survival/g' debian/build.xml > biojava-survival/build.xml
	sed -e 's/BJLIB/biojava4-jcolorbrewer/g' debian/build.xml > biojava-jcolorbrewer/build.xml

override_dh_auto_build:
	cd biojava-jcolorbrewer && ant jar
	cd biojava-forester && ant jar
	cd biojava-core && ant jar
	cd biojava-phylo && ant jar
	cd biojava-alignment && ant jar
	cd biojava-aa-prop && ant jar
	cd biojava-genome && ant jar
	cd biojava-sequencing && ant jar
	cd biojava-structure && ant jar
	cd biojava-structure-gui && ant jar
	cd biojava-modfinder && ant jar
	cd biojava-ontology && ant jar
	cd biojava-protein-disorder && ant jar
	cd biojava-protein-comparison-tool && ant jar
	cd biojava-ws && ant jar
	cd biojava-survival && ant jar
	# make doc
	rm -rf biojavadoc
	mkdir biojavadoc
	cp -r biojava-*/src biojavadoc/
	sed -e 's/BJLIB/biojava/g' debian/build.xml > biojavadoc/build.xml
	cd biojavadoc && ant javadocs
	# rm -rf biojavadoc

override_dh_auto_test:
	echo '*********************************************************************************'
	echo '* The following test is ignored since under certain circumstances it might fail *'
	echo '* Please check the result!                                                      *'
	echo '* More information can be found in the Debian BTS at                            *'
	echo '*      https://bugs.debian.org/843712                                           *'
	echo '*********************************************************************************'
	cd biojava-core && (ant test || true)
	cd biojava-alignment && ant test
	# Investigate test failure
	cd biojava-aa-prop && ant test
	# Skip, missing dependency junitx
	#cd biojava-genome && ant test
	cd biojava-phylo && ant test
	# Native errors may cause issue on NFS...; skipping
	cd biojava-sequencing && ant test
	# Serialization failure in pbuilder mode
	#cd biojava-modfinder && ant test
	# Investigate test failure
	#cd biojava-protein-disorder && ant test
	# Requires remote access and tmp directory write access
	#cd biojava-structure && ant test
	cd biojava-structure-gui && ant test
	cd biojava-ontology && ant test

override_dh_clean:
	dh_clean
	rm -rf build
	rm -rf dist
	rm -rf javadoc
	rm -rf test
	rm -f biojava-*/build.xml
	rm -rf biojavadoc
	rm -rf doc
	find . -name "*.class" -delete
	rm -rf buildtest

get-orig-source:
	debian/get-orig-source

