#!/usr/bin/make -f

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

# get the short name of the distro release
distrelease := $(shell lsb_release -cs)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

override_dh_auto_clean:
	dh_auto_clean
	rm -rf temp

override_dh_auto_configure:
	qmake-qt4 kvantum.pro

override_dh_auto_build:
	dh_auto_build
# copy the Qt4 plugin into a temp folder
	mkdir -p temp
	cp style/*.so temp
# build and use Qt 5 binaries and the Qt4 plugin on listed distreleases,
# otherwise use Qt 4 only
ifeq ($(distrelease),$(filter $(distrelease),stretch buster sid Horizon xenial yakkety zesty artful))
	make distclean
# a clunky way to use an unpatched kvantum.pro file for the Qt5 build,
# maybe using cmake would be more elegant?
	cp debian/kvantum-qt5.pro kvantum.pro
	/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/bin/qmake kvantum.pro
	dh_auto_build
endif

# install the qt4 style plugin from /temp
override_dh_auto_install:
	mkdir -p debian/kde-style-kvantum/usr/lib/$(DEB_HOST_MULTIARCH)/qt4/plugins/styles
	install -m 644 temp/*.so debian/kde-style-kvantum/usr/lib/$(DEB_HOST_MULTIARCH)/qt4/plugins/styles
	dh_auto_install

%:
	dh $@ --parallel
