#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export LC_ALL := C.UTF-8
export LANG := C.UTF-8
export LANGUAGE := C.UTF-8

WITH_TESTS :=$(if $(findstring nocheck,$(DEB_BUILD_OPTIONS)),OFF,ON)
DH_FULL := --builddirectory=obj-$(DEB_HOST_GNU_TYPE)-full

%:
	dh $@

override_dh_auto_configure:
#	if [ -e src/zxcvbn/ ]; then rm -r src/zxcvbn/ ; fi
	dh_auto_configure --  -DWITH_TESTS=$(WITH_TESTS) \
	                      -DWITH_GUI_TESTS=OFF \
	                      -DWITH_XC_UPDATECHECK=OFF \
	                      -DWITH_XC_YUBIKEY=ON \
	                      -DWITH_XC_ALL=OFF
	dh_auto_configure $(DH_FULL) --  -DWITH_TESTS=$(WITH_TESTS) \
	                                    -DWITH_GUI_TESTS=OFF \
	                                    -DWITH_XC_UPDATECHECK=OFF \
	                                    -DWITH_XC_ALL=ON

override_dh_auto_build:
	dh_auto_build
	dh_auto_build $(DH_FULL)

override_dh_auto_clean:
	dh_auto_clean
	dh_auto_clean $(DH_FULL)

override_dh_auto_install:
	dh_auto_install --destdir=debian/keepassxc-minimal
	dh_auto_install $(DH_FULL) --destdir=debian/keepassxc-full
	sed -i s#https://cdnjs.cloudflare.com/ajax/libs/font-awesome/.*/font-awesome.min.css#../../fonts-font-awesome/css/font-awesome.min.css#g $$(find debian/ -name '*.html')

override_dh_auto_test:
	dh_auto_test -- ARGS+="-E 'test(cli|gui)'"
	dh_auto_test $(DH_FULL) -- ARGS+="-E 'test(cli|gui)'"
	# testcli and testgui use X, and have horrible X clipboard tests that
	# randomly fail, so ignore failures
#	xvfb-run -a --server-args="-screen 0 800x600x24" dh_auto_test --no-parallel -- ARGS+="-R 'test(cli|gui)'" || true
#	xvfb-run -a --server-args="-screen 0 800x600x24" dh_auto_test $(DH_FULL) --no-parallel -- ARGS+="-R 'test(cli|gui)'" || true

override_dh_makeshlibs:
	# keepassxc only ships plugins
	dh_makeshlibs -p keepassxc-minimal -X/usr/lib/$(DEB_HOST_MULTIARCH)/keepassxc
	dh_makeshlibs -p keepassxc-full -X/usr/lib/$(DEB_HOST_MULTIARCH)/keepassxc

# No dbgsym packages:
override_dh_strip:
	@echo "NO--THANKS ANYWAY--but not building dbgsym packages for MX Linux"
	dh_strip --no-automatic-dbgsym
