#!/usr/bin/make -f

# Ensure at build time that the library has no dependencies on undefined
# symbols, and speed up loading.
DEB_BUILD_MAINT_OPTIONS = hardening=+pie,+bindnow
DEB_LDFLAGS_MAINT_APPEND=-Wl,-z,defs -Wl,-O1 -Wl,--as-needed
include /usr/share/dpkg/default.mk

%:
	dh $@ --with gnome

DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

ifneq ($(DEB_HOST_ARCH_OS), hurd)
ENABLE_TDB=--enable-tdb
endif

override_dh_autoreconf:
	dh_autoreconf debian/autogen.sh

DEB_CONFIGURE_EXTRA_FLAGS = 			\
	--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
	--enable-pulse				\
	--enable-gstreamer			\
	--enable-gtk				\
	--enable-gtk-doc 			\
	$(ENABLE_TDB) 				\
	--with-builtin=dso

# Linux-specific flags:
ifeq ($(DEB_HOST_ARCH_OS), linux)
DEB_CONFIGURE_EXTRA_FLAGS += --enable-alsa --disable-oss
else
DEB_CONFIGURE_EXTRA_FLAGS += --disable-alsa --enable-oss
endif

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_EXTRA_FLAGS)

DEB_DH_MAKESHLIBS_ARGS_ALL += --exclude=usr/lib/$(DEB_HOST_MULTIARCH)/gtk-2.0/modules
DEB_DH_MAKESHLIBS_ARGS_ALL += --exclude=usr/lib/$(DEB_HOST_MULTIARCH)/gtk-3.0/modules
DEB_DH_MAKESHLIBS_ARGS_ALL += --exclude=usr/lib/$(DEB_HOST_MULTIARCH)/libcanberra-0.30

override_dh_makeshlibs:
	dh_makeshlibs -plibcanberra0 $(DEB_DH_MAKESHLIBS_ARGS_ALL) -- -c4
	dh_makeshlibs -plibcanberra-gtk0 $(DEB_DH_MAKESHLIBS_ARGS_ALL) -- -c4
	dh_makeshlibs -plibcanberra-gtk3-0 $(DEB_DH_MAKESHLIBS_ARGS_ALL) -- -c4
	dh_makeshlibs --remaining-packages $(DEB_DH_MAKESHLIBS_ARGS_ALL)

override_dh_strip:
	dh_strip -plibcanberra0 --dbgsym-migration='libcanberra0-dbg (<< 0.30-3~)'
	dh_strip -plibcanberra-pulse --dbgsym-migration='libcanberra-pulse-dbg (<< 0.30-3~)'
	dh_strip -plibcanberra-gstreamer --dbgsym-migration='libcanberra-gstreamer-dbg (<< 0.30-3~)'
	dh_strip -plibcanberra-gtk0 --dbgsym-migration='libcanberra-gtk0-dbg (<< 0.30-3~)'
	dh_strip -plibcanberra-gtk-module --dbgsym-migration='libcanberra-gtk-module-dbg (<< 0.30-3~)'
	dh_strip -plibcanberra-gtk3-0 --dbgsym-migration='libcanberra-gtk3-0-dbg (<< 0.30-3~)'
	dh_strip -plibcanberra-gtk3-module --dbgsym-migration='libcanberra-gtk3-module-dbg (<< 0.30-3~)'
	dh_strip --remaining-packages

override_dh_auto_install:
	dh_auto_install
	cp -a src/canberra-gtk-module.desktop \
	      debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/gnome-settings-daemon-3.0/gtk-modules/canberra-gtk3-module.desktop
	find debian/tmp -name "*.la" | xargs rm -f
