#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

SHELL := sh -e

export JAVA_HOME = /usr/lib/jvm/default-java
export GRADLE_USER_HOME = /tmp
LIBEUFIN_HOME = /usr/share/libeufin
DEV =
FULLVER = $(DEB_VERSION_UPSTREAM)$(DEV)

%:
	dh ${@} --no-parallel

clean:
	rm -rf libeufin-bank-$(FULLVER)
	rm -rf libeufin-nexus-$(FULLVER)

override_dh_auto_test:
	true

override_dh_auto_configure:
	./configure --prefix=/usr

# Since this step is run under fakeroot and gradle
# doesn't work under fakeroot, we must make sure
# that everything is built by gradle before.
# The install-nobuild target installs under the assumption
# that everything is already built.
override_dh_auto_install:
	make -j1 install-nobuild DESTDIR=$(CURDIR)/debian/tmp

# Override this step because it's very slow and likely
# unnecessary for us.
override_dh_strip_nondeterminism:
	true

override_dh_install:
	dh_install
# Needs to be called manually for debhelper-compat < 13
	dh_installtmpfiles

override_dh_installsystemd:
	# Need to specify units manually, since we have multiple
	# and dh_installsystemd by default only looks for "<package>.service".
	dh_installsystemd -plibeufin-bank --name=libeufin-bank --no-start --no-enable
	dh_installsystemd -plibeufin-nexus --name=libeufin-nexus-ebics-submit --no-start --no-enable
	dh_installsystemd -plibeufin-nexus --name=libeufin-nexus-ebics-fetch --no-start --no-enable
	# final invocation to generate daemon reload
	dh_installsystemd

get-orig-source:
	uscan --force-download --rename
