#!/usr/bin/make -f

# DH_VERBOSE=1

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

CXXFLAGS += -fvisibility=hidden

# to select the qmake the package is build-depending on (according to
# <http://pkg-kde.alioth.debian.org/packagingqtbasedstuff.html>)
export QT_SELECT=qt5

%:
	dh  $@ --buildsystem=qmake

makefiles-to-safety:
	# upstream ships Makefiles that get cleaned in `make distclean`;
	# protect them to restore the original package.
	[ -e Makefile.orig ] || rename 's/Makefile/Makefile.orig/' Makefile src/Makefile example/Makefile

override_dh_auto_configure: makefiles-to-safety
	dh_auto_configure

override_dh_auto_install:
	# the build.txt file mentions that `make install` should work, but it
	# doesn't respect the usual environment parameters.

	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
	mkdir -p debian/tmp/usr/include/

	cp -a lib/* debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/
	cp -a include/* debian/tmp/usr/include/

override_dh_auto_clean: makefiles-to-safety
	dh_auto_clean

	# distclean removes the contents but not the directory
	[ ! -e lib ] || rmdir lib

	# see rename above
	rename -f 's/Makefile\.orig/Makefile/' Makefile.orig src/Makefile.orig example/Makefile.orig

override_dh_installdocs:
	dh_installdocs --link-doc=libopencsg1

override_dh_strip:
	dh_strip --dbg-package=libopencsg1-dbg
