#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

include /usr/share/javahelper/java-vars.mk
include /usr/share/dpkg/pkg-info.mk

export LEIN_HOME=$(CURDIR)/.lein
export LEIN_OFFLINE=true
NAME=puppetdb

%:
	dh $@ --with=javahelper --with maven_repo_helper

override_dh_auto_configure:
	cd debian && ln -sf /usr/share/maven-repo .

override_dh_auto_build:
	lein pom debian/pom.xml
	lein jar
	cd target && mv $(NAME)-$(DEB_VERSION_UPSTREAM).jar $(NAME).jar

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	export pg_ver=$$(/usr/share/postgresql-common/supported-versions --installed); \
	export PATH=$$PATH:$(CURDIR)/debian/bin && \
	./ext/bin/with-pdbbox \
		--box $$(mktemp -d "core-test-XXXXXX")/box \
		--pgbin /usr/lib/postgresql/$$pg_ver/bin \
		--pgport 5432 \
		-- lein test
endif

execute_after_dh_install:
	rm debian/puppetdb/etc/puppetdb/conf.d/database.ini

override_dh_installsystemd:
	dh_installsystemd --no-enable

override_dh_clean:
	rm -f debian/maven-repo
	rm -Rf target
	rm -f debian/pom.xml
	dh_clean
