# Per-user install: the binary and the desktop entry for the window.

PREFIX  ?= $(HOME)/.local
BINDIR  := $(PREFIX)/bin
APPDIR  := $(or $(XDG_DATA_HOME),$(HOME)/.local/share)/applications

.PHONY: build gate install uninstall

build:
	cargo build --release

# Formatting, lints with and without the window, tests, and the desktop entry. Offline once
# dependencies are fetched.
gate:
	cargo fmt --check
	cargo clippy --all-targets -- -D warnings
	cargo clippy --all-targets --no-default-features -- -D warnings
	cargo test
	desktop-file-validate dist/tailnew.desktop
	@echo "gate: ok"

# dist/tailnew.desktop carries an @BINDIR@ placeholder so it points wherever PREFIX put the binary.
install: build
	install -Dm755 target/release/tailnew $(BINDIR)/tailnew
	install -d $(APPDIR)
	sed 's|@BINDIR@|$(BINDIR)|' dist/tailnew.desktop > $(APPDIR)/tailnew.desktop
	-update-desktop-database $(APPDIR)

uninstall:
	rm -f $(BINDIR)/tailnew $(APPDIR)/tailnew.desktop
	-update-desktop-database $(APPDIR)
