#!/usr/bin/make -f

export DH_VERBOSE=1
# Attempt to harden the build
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# Remove remove "-z,now" LDFLAGS because mumble-overlay (libmumble.so)
# needs to be able to resolve OpenGL symbols at runtime rather than linking
# to a specific libGL implementation
export DEB_LDFLAGS_MAINT_STRIP = -r,now
# NOTE: there seems to be difficulties with build hardening for packages using
#       CMake; see: https://wiki.debian.org/Hardening#Notes_for_packages_using_CMake

MAKEFILE = $(firstword $(MAKEFILE_LIST))
SOURCE_DIR = $(dir $(MAKEFILE))..
VERSION := $(shell dpkg-parsechangelog -l$(dir $(MAKEFILE))changelog | sed -ne 's/^Version: \(.*\)-.*/\1/p')
MUMBLE_DEB_VERSION := $(shell dpkg-parsechangelog -l$(dir $(MAKEFILE))changelog | sed -ne 's/^Version: \(.*\).*/\1/p')
# qtchooser will try to use qmake from qt4 even if it's not installed
export QT_SELECT=qt5

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif

export DH_OPTIONS

%:
	dh  $@ --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- \
	-DBUILD_NUMBER=517 \
	-DCMAKE_BUILD_TYPE=Release \
	-Dsymbols=ON \
	-Dupdate=OFF \
	-Doverlay=ON \
	-Doverlay-xcompile=OFF \
	-Dbundle-qt-translations=OFF \
	-Dsymbols=ON \
	-Dtests=OFF \
	-Dupdate=OFF \
	-Dwarnings-as-errors=OFF

override_dh_clean:
	rm -rfv Ice
	# logratate and init file have both been removed
	#rm -fv $(CURDIR)/debian/mumble-server.logrotate $(CURDIR)/mumble-server.init
	debconf-updatepo
	dh_clean

override_dh_auto_build:
	# Create Ice HTML files and place in Ice/ directory to be installed with mumble-server.docs
	slice2html -I/usr/share/ice/slice -I/usr/share/slice src/murmur/MumbleServer.ice --output-dir Ice
	dh_auto_build

# No init file right now so commenting this out for the moment
#override_dh_installinit:
	# init and logrotate files removed
	#install -m 0755 $(CURDIR)/scripts/murmur.init $(CURDIR)/debian/mumble-server.init
	#install -m 0755 $(CURDIR)/scripts/murmur.logrotate $(CURDIR)/debian/mumble-server.logrotate
	# These
	#install -m 0644 -D $(CURDIR)/scripts/murmur.conf $(CURDIR)/debian/mumble-server/etc/dbus-1/system.d/mumble-server.conf
	#install -m 0644 -D $(CURDIR)/scripts/murmur.ini.system $(CURDIR)/debian/mumble-server/etc/mumble-server.ini
	#dh_installinit -- defaults 95
