PREFIX    ?= /usr
DESTDIR   ?=

# Backend daemons live under libexec — not on $PATH, only D-Bus / systemd
# activation needs to reach them. Matches the upstream convention used by
# `xdg-desktop-portal-gnome`, `-kde`, `-hyprland`, etc.
LIBEXECDIR = $(DESTDIR)$(PREFIX)/libexec
DATADIR    = $(DESTDIR)$(PREFIX)/share
SYSTEMDDIR = $(DESTDIR)$(PREFIX)/lib/systemd/user

PORTAL_DIR  = $(DATADIR)/xdg-desktop-portal/portals
DBUS_DIR    = $(DATADIR)/dbus-1/services

.PHONY: all start install uninstall clean distclean

all:
	cargo build --release

start: all
	./target/release/xdg-desktop-portal-crustace

install:
	install -Dm755 target/release/xdg-desktop-portal-crustace                   $(LIBEXECDIR)/xdg-desktop-portal-crustace
	install -Dm644 data/crustace.portal                                       $(PORTAL_DIR)/crustace.portal
	install -Dm644 data/org.freedesktop.impl.portal.desktop.crustace.service  $(DBUS_DIR)/org.freedesktop.impl.portal.desktop.crustace.service
	install -Dm644 data/xdg-desktop-portal-crustace.service                      $(SYSTEMDDIR)/xdg-desktop-portal-crustace.service

uninstall:
	rm -f $(LIBEXECDIR)/xdg-desktop-portal-crustace
	rm -f $(PORTAL_DIR)/crustace.portal
	rm -f $(DBUS_DIR)/org.freedesktop.impl.portal.desktop.crustace.service
	rm -f $(SYSTEMDDIR)/xdg-desktop-portal-crustace.service

clean:
	cargo clean

distclean: clean
	dh_clean
	rm -f Cargo.lock
