#!/usr/bin/make -f

VERSION=$(shell dpkg-parsechangelog | perl -lne 'print $$1 if /Version: (.*)-/')

debian/apgdiff.1: debian/apgdiff.1.txt
	a2x -f manpage debian/apgdiff.1.txt

build-arch:

build build-indep: build-stamp
build-stamp: debian/apgdiff.1
	ant -Dnoget=1 jar
	
	# setting up test suite
	-mkdir lib
	cp /usr/share/java/junit4.jar lib/junit.jar
	cp -a /usr/share/java/hamcrest-* lib
	ant -Dnoget=1 compile-tests
	ant -Dnoget=1 test
	touch $@

override_dh_installchangelogs:
	dh_installchangelogs README.md

install: build-stamp
	dh_prep
	install -d debian/apgdiff/usr/bin
	sed -e 's/VERSION/$(VERSION)/' debian/apgdiff.sh > debian/apgdiff/usr/bin/apgdiff
	dh install

binary-arch:

binary binary-indep: install

clean:
	ant -Dnoget=1 clean
	rm -f src/main/resources/cz/startnet/utils/pgdiff/usage.xml
	rm -f build-stamp debian/apgdiff.1 debian/apgdiff.1.xml
	dh_clean

%:
	dh $@

origtgz:
	test ! -e ../apgdiff_$(VERSION).orig.tar.gz
	test ! -d ../orig/apgdiff-$(VERSION)
	mkdir -p ../orig/apgdiff-$(VERSION)
	cp -a * ../orig/apgdiff-$(VERSION)
	rm -rf ../orig/apgdiff-$(VERSION)/debian
	find ../orig/apgdiff-$(VERSION) -name .svn | xargs -r rm -rf
	cd ../orig && tar -czf ../apgdiff_$(VERSION).orig.tar.gz apgdiff-$(VERSION)
	rm -rf ../orig/apgdiff-$(VERSION)
	rmdir ../orig

.PHONY: build build-arch build-indep clean origtgz
