#!/usr/bin/make -f
# Copyright  2002,2003 Colin Walters <walters@verbum.org>
# Copyright  2003 Daniel Stone <daniels@debian.org>
# Copyright  2006 Sjoerd Simons <sjoerd@debian.org>
# Copyright  2011 Michael Biebl <biebl@debian.org>

%:
	dh $@

export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed

libdbusN := $(shell sed -rn 's/Package:[[:space:]]*(libdbus-[0-9-]+)[[:space:]]*$$/\1/p' debian/control | head -n 1)

override_dh_auto_configure:
	dh_auto_configure -- \
		--exec-prefix=/ \
		--enable-xml-docs \
		--enable-doxygen-docs \
		--disable-libaudit \
		--libexecdir=/lib/dbus-1.0 \
		--libdir=\$${exec_prefix}/lib/$(DEB_HOST_MULTIARCH) \
		--with-systemdsystemunitdir=/lib/systemd/system

override_dh_auto_build:
	dh_auto_build
	xsltproc -o dbus.devhelp debian/doxygen_to_devhelp.xsl doc/api/xml/index.xml

override_dh_link:
	dh_link -plibdbus-1-dev lib/$(DEB_HOST_MULTIARCH)/$$(basename $$(readlink debian/tmp/lib/$(DEB_HOST_MULTIARCH)/libdbus-1.so)) usr/lib/$(DEB_HOST_MULTIARCH)/libdbus-1.so
	dh_link --remaining-packages

override_dh_install:
	for file in libdbus-1-dev.install; \
	do \
		sed -e"s,\$${DEB_HOST_MULTIARCH},${DEB_HOST_MULTIARCH},g" \
			debian/$${file}.in > debian/$$file; \
	done
	dh_install
	install -m 644 -D debian/dbus-Xsession debian/dbus-x11/etc/X11/Xsession.d/75dbus_dbus-launch
	sed -e 's@\$${exec_prefix}/lib@\$${prefix}/lib@' debian/tmp/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/dbus-1.pc > debian/libdbus-1-dev/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/dbus-1.pc

override_dh_installinit:
	dh_installinit --error-handler=: -pdbus -r -- start 12 2 3 4 5 .

# we don't want docs for the debug symbols, just symlink to the library docs
override_dh_installdocs:
	dh_installdocs -pdbus-1-dbg --link-doc=$(libdbusN)
	dh_installdocs --remaining-packages --all AUTHORS NEWS README

override_dh_strip:
	dh_strip --dbg-package=dbus-1-dbg

override_dh_makeshlibs:
	dh_makeshlibs -V '$(libdbusN) (>= 1.3.1)'

override_dh_auto_clean:
	dh_auto_clean
	rm -f test/data/valid-config-files/session.conf
	rm -f test/data/valid-config-files/system.conf
	rm -f dbus.devhelp


