#!/usr/bin/make -f

export DH_VERBOSE=1
export DH_OPTIONS

include /usr/share/dpkg/pkg-info.mk

%:
	dh  $@ --buildsystem=gradle --with javahelper,jh_maven_repo_helper

override_dh_auto_clean:
	dh_auto_clean
	-rm debian/pom-barclay.xml

override_dh_auto_configure:
	# As we provide a Debian-made POM file, we have to update the version number
	# that is inside each time the upstream version changes. This is done
	# automatically with this tiny hack.
	sed 's/@VERSION@/$(DEB_VERSION_UPSTREAM)/ ; s/\+dfsg[[:digit:]]*//' debian/pom-barclay.xml.in > debian/pom-barclay.xml
	dh_auto_configure

override_dh_auto_build:
	dh_auto_build -- jar

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Tests do not work with locales with a different decimal separator
	# (for example ',')
	LC_ALL=C.UTF-8 dh_auto_test
endif

override_dh_clean:
	dh_clean
	$(RM) debian/bd-temp-substvars
	$(RM) debian/bd.substvars

override_dh_gencontrol:
	cat debian/control \
	| sed -e '/^Build-.*Depends:/,/^[^[:space:]#]/{s/^Build-.*Depends:/ /;p};d' \
	| grep '^[[:space:]]' \
	| tr ',' '\n' \
	> debian/bd-temp-substvars
	echo -n "bd:barclay-java=" > debian/bd.substvars
	grep 'libbarclay-java ' debian/bd-temp-substvars \
	| tr "\n" "," \
	| sed -e 's/[[:space:]]\+/ /g;s/,$$/\n/' \
	>> debian/bd.substvars
	dh_gencontrol -O--buildsystem=gradle -- -Tdebian/bd.substvars
