#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/default.mk
export INSTALL_DIR=$(CURDIR)/debian/phrog

%:
	dh $@

# The custom build.rs works under $HOME to ensure the glib schemas
# compile cleanly, so let's ensure there's a valid/writable $HOME
# during build and delete it afterwards
override_dh_auto_build:
	HOME=$(CURDIR)/debian/tmp_home cargo build

override_dh_auto_install:
	install -D -m0755 target/$(DEB_HOST_RUST_TYPE)/debug/phrog \
		$(INSTALL_DIR)/usr/bin/phrog
	install -D -m0755 data/phrog-greetd-session \
		$(INSTALL_DIR)/usr/libexec/phrog-greetd-session

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	mkdir -p $(CURDIR)/debian/tmp_home $(CURDIR)/debian/tmp_run
	LC_ALL=C.UTF-8 XDG_RUNTIME_DIR=$(CURDIR)/debian/tmp_run \
		HOME=$(CURDIR)/debian/tmp_home dbus-run-session xvfb-run -a \
			phoc -C $(CURDIR)/debian/config/phoc.ini -E "cargo test"
endif

execute_after_dh_auto_clean:
	rm -rf $(CURDIR)/debian/tmp_home $(CURDIR)/debian/tmp_run
