#!/usr/bin/make -f

ifneq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
	DEB_BUILD_DOCS=0
else
	DEB_BUILD_DOCS=1
endif

# Let dpkg-gensymbols fail if symbols file updates are needed
DPKG_GENSYMBOLS_CHECK_LEVEL ?= 4
export DPKG_GENSYMBOLS_CHECK_LEVEL

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
QT5_BIN_DIR ?= "/usr/lib/$(DEB_HOST_MULTIARCH)/qt5/bin"

override_dh_auto_configure:
	dh_auto_configure -- \
		--with-guis="fox16 qt4 qt5 gtk2" \
		--with-qt5-qmake=$(QT5_BIN_DIR)/qmake \
		--with-qt5-moc=$(QT5_BIN_DIR)/moc \
		--with-qt5-uic=$(QT5_BIN_DIR)/uic \
		--disable-network-checks \
		$(shell dpkg-buildflags --export=configure)

override_dh_auto_build:
	dh_auto_build
	$(MAKE) -C debian/man

	# This is not an arch-indep target, as some built binaries are required to build the srcdoc
	if [ "$(DEB_BUILD_DOCS)" = "1" ]; then \
		$(MAKE) srcdoc; \
	else \
		mkdir apidoc; \
	fi

override_dh_auto_install:
	dh_auto_install
	# Remove upstream's poorly maintained CA bundle and replace it by the
	# CA bundle managed by the package ca-certificates (fixes Debian bug #748955)
	rm -v debian/tmp/usr/share/gwenhywfar/ca-bundle.crt
	ln -vs /etc/ssl/certs/ca-certificates.crt \
	      debian/tmp/usr/share/gwenhywfar/ca-bundle.crt

override_dh_strip:
	dh_strip --dbg-package=libgwenhywfar60-dbg

override_dh_auto_clean:
	rm -rvf apidoc listdoc.h gwenhywfar.tag gwenhywfar4
	$(MAKE) -C debian/man clean
	dh_auto_clean

%:
	dh $@ --with autoreconf

.PHONY:	override_dh_auto_configure override_dh_auto_build override_dh_auto_install override_dh_strip override_dh_auto_clean
