#!/usr/bin/make -f
include /usr/share/dpkg/architecture.mk

export DESTDIR=debian/tmp
SYSTEMDUSERDIR=/usr/lib/systemd/user

%:
	dh $@ --buildsystem cargo

override_dh_auto_test:
	dh_auto_test -- test --all

override_dh_auto_install:
	dh_auto_install --destdir=$(DESTDIR) -O--buildsystem=cargo
	mv "$(DESTDIR)/usr/bin/notification-proxy-client" \
	   "$(DESTDIR)/usr/bin/qubes-notification-proxy-client"
	mv "$(DESTDIR)/usr/bin/notification-proxy-server" \
	   "$(DESTDIR)/usr/bin/qubes-notification-proxy-server"
	# dh-cargo defines substvars only to one subpackage, fix it
	cp debian/qubes-notification-daemon.substvars \
		debian/qubes-notification-agent.substvars
	install -d -- "$(DESTDIR)/etc/qubes-rpc/" "$(DESTDIR)$(SYSTEMDUSERDIR)" "$(DESTDIR)$(SYSTEMDUSERDIR)-preset"
	install -d -- "$(DESTDIR)/etc/qubes/rpc-config"
	install -m0644 -- src/qubes-notification-agent.service "$(DESTDIR)$(SYSTEMDUSERDIR)"
	install -m0644 -- src/90-qubes-notification-agent.preset "$(DESTDIR)$(SYSTEMDUSERDIR)-preset"
	ln -s -- ../../usr/bin/qubes-notification-proxy-server "$(DESTDIR)/etc/qubes-rpc/qubes.Notifications"
	echo "wait-for-session=1" > "$(DESTDIR)/etc/qubes/rpc-config/qubes.Notifications"
