#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DEB_HOST_MULTIARCH	?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
DEB_VERSION ?= "+deb$(shell head -1 debian/changelog | sed 's/.*(//;s/).*//;s/.*-//')"

DEB_CONFIGURE_EXTRA_FLAGS := \
	-DCMAKE_INSTALL_LIBDIR=lib \
	-DVERSION_EXTRA=$(DEB_VERSION) \
	-DGTEST_ROOT="/usr/src/googletest/googletest" \
	-DGMOCK_ROOT="/usr/src/googletest/googlemock" \
	-DWANT_SYSTEMD=true \
	-DWANT_TCL=true \
	-DWANT_CYRUS=true \
	-DWANT_PYTHON=true \
	-DWANT_PERL=true \
	-DWANT_I18N=true

export VERBOSE=1

%:
	dh $@ --with python3 --buildsystem=cmake

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)

override_dh_installsystemd:
	dh_installsystemd --no-start --no-enable --restart-after-upgrade

override_dh_python3:
	dh_python3 \
		-p znc-python \
		--exclude=znc.py \
		--exclude=znc_core.py

override_dh_install:
	dh_install
	dh_install -p znc-dev \
		usr/lib/pkgconfig/* usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/
	# Fix pkg-config file.
	sed -e "s;-fPIC ;;" \
		-e "s;-fvisibility=hidden ;;" \
		-e "s;-O. ;;" \
		-e "s;-g ;;" \
		-e "s;-W ;;" \
		-e "s;-Wall ;;" \
		-e "s;-D_FORTIFY_SOURCE=2;;" \
		-e "s;-Wshadow ;;" \
		-e "s;-Woverloaded-virtual ;;" \
		-e "s;-Wno-unused-parameter ;;" \
		-e "s;-Werror=format-security ;;" \
		-e "s;-Wformat ;;" \
		-e "s;-Wdate-time ;;" \
		-e "s;-I/usr/include/$(DEB_HOST_MULTIARCH) ;;" \
		-i $(CURDIR)/debian/znc-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/znc.pc
	dh_missing --list-missing
