#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export DH_VERBOSE=1

# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# 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

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@ --buildsystem=cmake


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

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