#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

%:
	dh $@ --with autoreconf


CFLAGS := -Wall -fstack-protector -fPIE $(shell dpkg-buildflags --get CFLAGS)
LDFLAGS := -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -pie $(shell dpkg-buildflags --get LDFLAGS)

override_dh_auto_configure:
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	dh_auto_configure -- CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
		--libdir=\$${prefix}/../lib/$(DEB_HOST_MULTIARCH)
else
	dh_auto_configure -B build-dbus-tool/ -- CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
		--libdir=/lib/$(DEB_BUILD_MULTIARCH) \
		--host=$(DEB_BUILD_GNU_TYPE)
	dh_auto_build -B build-dbus-tool/ --parallel
	dh_auto_configure -- CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
		NIH_DBUS_TOOL=$(CURDIR)/build-dbus-tool/nih-dbus-tool/nih-dbus-tool \
		--libdir=/lib/$(DEB_HOST_MULTIARCH)
endif

override_dh_auto_build:
	dh_auto_build --parallel

override_dh_auto_test:
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	dh_auto_test
endif

override_dh_auto_install:
	dh_auto_install -- pkgconfigdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH)/pkgconfig

override_dh_makeshlibs:
	dh_makeshlibs -plibnih1 -V 'libnih1 (>= 1.0.0)'
	dh_makeshlibs -plibnih-dbus1 -V 'libnih-dbus1 (>= 1.0.0)'
	dh_makeshlibs -Nlibnih1 -Nlibnih-dbus1

override_dh_shlibdeps:
	dh_shlibdeps
	sed -i 's/2\.14/2.15/' debian/*.substvars
	sed -i 's/>= 2.15)/>= 2.15~)/g' debian/*.substvars


# Symlink /usr/share/doc directories together
override_dh_installdocs:
	dh_installdocs --link-doc=libnih1

override_dh_clean:
	rm -rf build-dbus-tool/
	dh_clean
