#!/usr/bin/make -f
#export DH_VERBOSE = 1
#for gen-orig-tgz:
DEBVERS			?= $(shell dpkg-parsechangelog | sed -n -e 's/^Version: //p')
VERSION			?= $(shell echo '$(DEBVERS)' | sed -e 's/^[[:digit:]]*://' -e 's/[-].*//')
DEBFLAVOR		?= $(shell dpkg-parsechangelog | grep -E ^Distribution: | cut -d" " -f2)
DEBPKGNAME		?= $(shell dpkg-parsechangelog | grep -E ^Source: | cut -d" " -f2)
GIT_TAG			?= upstream/$(shell echo '$(VERSION)' | sed -e 's/~/_/')
DEBIAN_BRANCH	?= $(shell cat debian/gbp.conf | grep debian-branch | cut -d'=' -f2 | awk '{print $1}')

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export QT_SELECT = qt5

# Qt insists on using -fPIC
export DEB_CXXFLAGS_MAINT_APPEND = -fPIC

CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) -Wl,-rpath=/usr/lib/$(DEB_HOST_MULTIARCH)/usbguard

%:
	dh ${@} --parallel --with=autoreconf,systemd

override_dh_auto_configure:
	dh_auto_configure -- \
	  --enable-static \
	  --without-bundled-catch \
	  --without-bundled-pegtl \
	  --enable-systemd \
	  --sysconfdir=/etc \
	  --with-gui-qt=qt5 \
	  --enable-bash_completion

override_dh_install:
	dh_install --list-missing

override_dh_makeshlibs:
	dh_makeshlibs -n


gen-orig-tgz:
	if [ ! -f ../$(DEBPKGNAME)_$(VERSION).orig.tar.gz ] ; then \
		git archive --format=tar.gz --prefix=$(DEBPKGNAME)-$(VERSION)/ \
		   $(GIT_TAG) >../$(DEBPKGNAME)_$(VERSION).orig.tar.gz ; \
	fi
