PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
DESTDIR ?=

TARGET ?= release
CARGO_FLAGS := --$(TARGET) --features gui

BINARIES := temperlux temperlux-gui
DESKTOP_FILE := temperlux.desktop

.PHONY: all build install uninstall clean test

all: build

build:
	cargo build $(CARGO_FLAGS)

test:
	cargo test

install: build
	@for bin in $(BINARIES); do \
		echo "Installing $$bin → $(DESTDIR)$(BINDIR)/"; \
		install -Dm755 target/$(TARGET)/$$bin $(DESTDIR)$(BINDIR)/$$bin; \
	done
	install -Dm644 contrib/$(DESKTOP_FILE) $(DESTDIR)$(DATADIR)/applications/$(DESKTOP_FILE)
	install -Dm644 data/icons/scalable/apps/dev.angussoftware.temperlux.svg \
		$(DESTDIR)$(DATADIR)/icons/hicolor/scalable/apps/dev.angussoftware.temperlux.svg

uninstall:
	@for bin in $(BINARIES); do \
		echo "Removing $(DESTDIR)$(BINDIR)/$$bin"; \
		rm -f $(DESTDIR)$(BINDIR)/$$bin; \
	done
	rm -f $(DESTDIR)$(DATADIR)/applications/$(DESKTOP_FILE)
	rm -f $(DESTDIR)$(DATADIR)/icons/hicolor/scalable/apps/dev.angussoftware.temperlux.svg

clean:
	cargo clean
