#!/usr/bin/make -f

include /usr/share/dpkg/default.mk
export JAVA_HOME=/usr/lib/jvm/default-java

%:
	dh $@ --with javahelper

override_dh_auto_build:
	cd src && ant release -Dant.build.javac.source=1.5 -Dant.build.javac.target=1.5
	tar zxf dist/castor-*-doc.tgz -C target
	rm -f target/doc/*license*

override_dh_install:
	dh_install -Xjavadoc
	# XML module
	mh_installpom -plibcastor-xml-java --no-parent xml/pom.xml
	mh_installjar -plibcastor-xml-java -l xml/pom.xml \
		dist/castor-xml-$(DEB_VERSION_UPSTREAM).jar
	# Core module
	mh_installpom -plibcastor-core-java --no-parent core/pom.xml
	mh_installjar -plibcastor-core-java -l core/pom.xml \
		dist/castor-core-$(DEB_VERSION_UPSTREAM).jar
	# JDO module
	mh_installpom -plibcastor-jdo-java --no-parent cpa/pom.xml
	mh_installjar -plibcastor-jdo-java -l cpa/pom.xml \
		dist/castor-jdo-$(DEB_VERSION_UPSTREAM).jar
	# Codegen module
	mh_installpom -plibcastor-codegen-java --no-parent codegen/pom.xml
	mh_installjar -plibcastor-codegen-java -l codegen/pom.xml \
		dist/castor-codegen-$(DEB_VERSION_UPSTREAM).jar
	# Ant tasks
	mh_installpom -plibcastor-anttasks-java --no-parent anttask/pom.xml
	mh_installjar -plibcastor-anttasks-java -l anttask/pom.xml \
		dist/castor-anttasks-$(DEB_VERSION_UPSTREAM).jar
	# DDLgen module
	mh_installpom -plibcastor-ddlgen-java --no-parent ddlgen/pom.xml
	mh_installjar -plibcastor-ddlgen-java -l ddlgen/pom.xml \
		dist/castor-ddlgen-$(DEB_VERSION_UPSTREAM).jar
	# XML Schema module
	mh_installpom -plibcastor-xml-schema-java --no-parent schema/pom.xml
	mh_installjar -plibcastor-xml-schema-java -l schema/pom.xml \
		dist/castor-xml-schema-$(DEB_VERSION_UPSTREAM).jar

override_dh_auto_clean:
	-cd src && ant distclean
	mh_clean
	cd cpa/target/generated-sources && rm -rf jjtree javacc

get-orig-source:
	cd $(dir $(firstword $(MAKEFILE_LIST)))../ && \
	uscan \
		--verbose \
		--no-symlink \
		--destdir $(CURDIR)      \
		--watchfile debian/watch \
		--force-download
