#!/usr/bin/make -f

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

# Create versioned jar file; strip off the debian source revision and package revision
VERSION=$(shell dpkg-parsechangelog | sed -n 's/Version: \([0-9.]*\).*/\1/p')

# If the user has not explicitly set JAVA_HOME, export sensible value
# to make sure that the correct compiler is used by ant.
JAVA_HOME ?= /usr/lib/jvm/java-gcj
export JAVA_HOME

PREFIX=debian/libmalai-java

%:
	dh $@

override_dh_auto_clean:
	find . -name \*.jar -exec rm -f {} \;
	find . -name \*.class -exec rm -f {} \;
	rm -rf out bin api

override_dh_auto_build:
	mkdir out bin
	ant -Dbasedir=. -f debian/build.xml compile
	ant -Dbasedir=. -f debian/build.xml jar doc

override_dh_install:
	cp out/malai.jar $(PREFIX)/usr/share/java/org.malai-$(VERSION).jar

override_dh_link:
	dh_link usr/share/java/org.malai-$(VERSION).jar usr/share/java/org.malai.jar

# Be explicit given that there is plenty of confusion about what this target means
get-orig-source: get-latest-source

get-latest-source:
	cd $(dir $_).. && \
	uscan=$$(uscan --report --dehs --upstream-version 0) && \
	uver=$$(echo "$$uscan" | sed -n 's,<upstream-version>\(.*\)</.*>,\1,p') && \
	uurl=$$(echo "$$uscan" | sed -n 's,<upstream-url>\(.*\)</.*>,\1,p') && \
	echo debian/repackage --upstream-version "$${uver}" "$${uurl}" $(CURDIR) &&\
	sh debian/repackage --upstream-version "$${uver}" "$${uurl}" $(CURDIR)
