#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-z,defs -Wl,--as-needed

# Filter out that flag for Ubuntu, it's default there but fails the build
# https://gitlab.gnome.org/GNOME/gcr/issues/43
export DEB_LDFLAGS_MAINT_STRIP = -Wl,-Bsymbolic-functions

CHECK_HOME = $(CURDIR)/debian/tmp/home

%:
	dh $@ --buildsystem=meson --without autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dgtk_doc=true \
		-Dintrospection=true \
		-Dgtk=true

override_dh_auto_test:
ifeq (, $(filter nocheck, $(DEB_BUILD_OPTIONS)))
	mkdir -p -m0700 $(CHECK_HOME)
	# Disable fakeroot as this confuses some of the tests
	env -u LD_PRELOAD XDG_RUNTIME_DIR=$(CHECK_HOME) dbus-run-session -- dh_auto_test
endif

override_dh_install:
	find debian/tmp -name '*.la' -print -delete
	# Old compatibility library no longer needed
	find debian/tmp -name 'libgcr-3.so*' -print -delete
	dh_install

override_dh_missing:
	dh_missing --fail-missing

override_dh_makeshlibs:
	dh_makeshlibs -- -c4

override_dh_clean:
	rm -rf $(CHECK_HOME)
	dh_clean
