#!/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 gtk3" \
		--with-qt5-qmake=$(QT5_BIN_DIR)/qmake \
		--with-qt5-moc=$(QT5_BIN_DIR)/moc \
		--with-qt5-uic=$(QT5_BIN_DIR)/uic \
		--enable-system-certs \
		--disable-network-checks

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; \
		rm -v apidoc/jquery.js; \
	else \
		mkdir apidoc; \
	fi

override_dh_auto_install:
	dh_auto_install
	# Remove upstream's poorly maintained CA bundle. The AqBanking build is
	# configured to use the system certificates (--enable-system-certs).
	rm -v debian/tmp/usr/share/gwenhywfar/ca-bundle.crt

override_dh_strip:
	dh_strip --dbgsym-migration='libgwenhywfar60-dbg (<< 4.17.0-3~)'

override_dh_makeshlibs:
	dh_makeshlibs -Xgwenhywfar/plugins

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
