#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

built_binaries := $(shell dh_listpackages)
LIB_PKG := $(filter-out %-dev %-bin,$(filter lib%,$(shell awk '/^Package: / { print $$2 }' debian/control)))

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-z,defs
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

export GD_LIBNAME = $(LIB_PKG)
export GD_SOVERSION = $(shell echo $(GD_LIBNAME) | rev | cut -f1 -d- | rev)
export GD_API_VERSION = $(shell echo $(GD_LIBNAME) | rev | cut -f2 -d- | rev)

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dgnome_distributor=$(shell dpkg-vendor --query vendor) \
		-Ddate_in_gnome_version=false \
		-Dgtk_doc=true \
		-Dinstalled_tests=true \
		-Ddesktop_docs=true

override_dh_auto_test:
	debian/tests/run-with-locales \
		--generate en_US.UTF-8 \
		--generate he_IL.UTF-8 \
		--generate ja_JP.UTF-8 \
		-- \
	env \
		NO_AT_BRIDGE=1 \
		G_MESSAGES_DEBUG=all \
	dh_auto_test -- --wrap="xvfb-run -a"

# debhelper >= 13.4 makes all of /usr/libexec executable, which is not
# quite right for installed-tests
override_dh_fixperms:
	dh_fixperms -Xusr/libexec/installed-tests
ifneq ($(filter %-tests,$(built_binaries)),)
	chmod --recursive --changes a+rX,u+w,og-w debian/*-tests/usr/libexec/installed-tests
endif

# Ubuntu-specific
override_dh_translations:
	dh_translations --domain=gnome-desktop-3.0
