#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)

include /usr/share/dpkg/architecture.mk
# be REALLY noisy
export DH_VERBOSE=1
export DH_OPTIONS=-v

export DEB_BUILD_OPTIONS=noautodbgsym
PACKAGE=kanidm
PKGDIR=debian/${PACKAGE}
BINDIR=${PKGDIR}/usr/bin/
SHARED_DIR=${PKGDIR}/usr/share/${PACKAGE}
DISTRIBUTOR_ID=$(shell lsb_release -is)
DISTRIBUTOR_RELEASE=$(shell lsb_release -rs)
DISTRIBUTOR=$(DISTRIBUTOR_ID)_$(DISTRIBUTOR_RELEASE)

#GitHub enforces NTFS compatible filenames for artifacts so we need to drop the EPOCH field
DEB_VERSION_FULL=$(shell dpkg-parsechangelog --show-field Version | sed -E 's/^[0-9]+://')

%:
	dh $@

override_dh_auto_clean:

override_dh_auto_configure:

override_dh_auto_build:
	KANIDM_BUILD_PROFILE=release_suse_generic dh_auto_build -- release/${PACKAGE}

override_dh_auto_test:
override_dh_shlibdeps:
override_dh_strip:

override_dh_auto_install:
	mkdir -p ${BINDIR}
	install -D \
		-g root \
		-o root \
		--mode 755 \
		target/release/kanidm \
		${BINDIR}

override_dh_installexamples:
	mkdir -p ${SHARED_DIR}
	install -D \
	    -g root \
		-o root \
		--mode 644 \
		examples/config \
		${SHARED_DIR}/kanidm

override_dh_builddeb:
	dh_builddeb --filename ${PACKAGE}_${DISTRIBUTOR}_${DEB_VERSION_FULL}_${DEB_HOST_GNU_CPU}.deb
