#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

JAVA_HOME=/usr/lib/jvm/default-java
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)


%:
	dh $@ --buildsystem=maven

override_dh_auto_clean:
	dh_auto_clean
	if [ -e VERSION.old ]; then mv VERSION.old VERSION; fi
	if [ -e debian/maven.properties ]; then rm debian/maven.properties; fi
	# Cleaning the native part.
	$(MAKE) clean

override_dh_auto_configure:
	# Setting the version of installed sqlite3 lib in the VERSION file, using dpkg
	# to get this version number.
	# Also putting it in d/maven.properties...
	cp VERSION VERSION.old
	sqliteVersion=$$(dpkg -s libsqlite3-dev | grep "Version" | sed 's/Version: \(.*\)-.*/\1/') && \
	        echo "version=$$sqliteVersion" > VERSION && \
	        echo "sqlite.version=$$sqliteVersion" > debian/maven.properties
	# Together with the architecture.
	echo "build.architecture=$$(arch)" >> debian/maven.properties
	dh_auto_configure

override_dh_auto_build-arch:
	# Build JNI
	export JAVA_HOME=$(JAVA_HOME) && \
	        export DEB_HOST_MULTIARCH=$(DEB_HOST_MULTIARCH) && \
	        $(MAKE)

override_dh_auto_test-arch:

override_dh_auto_test-indep: override_dh_auto_build-arch
	# ensure the native library is run before running the tests.
	dh_auto_test -i

override_dh_auto_install-arch:
	dh_install -p libxerial-sqlite-jdbc-jni
