#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_MULTIARCH	?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

CXXFLAGS := -g -DVERSION_EXTRA=\"+deb$(shell head -1 debian/changelog | sed 's/.*(//;s/).*//;s/.*-//')\"

DEB_CONFIGURE_EXTRA_FLAGS := \
	--prefix=/usr \
	--libdir=/usr/lib \
	--enable-tcl \
	--enable-cyrus \
	--enable-perl \
	--enable-python \
	--with-gtest=/usr/src/googletest/googletest \
	--with-gmock=/usr/src/googletest/googlemock

%:
	dh $@ --with python3

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)

override_dh_auto_build:
	$(MAKE) VERBOSE=1

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

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

override_dh_install:
	dh_install --list-missing
	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;-Wdate-time ;;" \
		-e "s;-I/usr/include/$(DEB_HOST_MULTIARCH) ;;" \
		-i $(CURDIR)/debian/znc-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/znc.pc
