PREFIX    ?= /usr
DESTDIR   ?=
# Where the release binary lives. The Debian arm64 cross-build overrides this
# to the per-target dir that `make arm64` produces.
RELEASE_DIR ?= target/release

BINDIR     = $(DESTDIR)$(PREFIX)/bin
DATADIR    = $(DESTDIR)$(PREFIX)/share

.PHONY: all start start-root start-desktop start-desktop-root start-full install uninstall clean distclean deb deb-arm64

all:
	cargo build --release

arm64-deps:
	sudo apt-get install libstd-rust-dev:arm64 libstd-rust-1.85:arm64 libwayland-dev:arm64 libwayland-egl1:arm64 libxkbcommon-dev:arm64 libegl-dev:arm64 libgles2-mesa-dev:arm64 libdbus-1-dev:arm64 libssl-dev:arm64

arm64:
	cargo build --release --target aarch64-unknown-linux-gnu

start: all
	EYDOS_CALLS_MOCK=1 LTK_THEMES_DIR=/home/pechanove/liberux/git/ltk/themes ./target/release/eydos-calls --windowsize 480x960

start-root: all
	sudo -E env \
		WAYLAND_DISPLAY="$$WAYLAND_DISPLAY" \
		XDG_RUNTIME_DIR="$$XDG_RUNTIME_DIR" \
		LTK_THEMES_DIR=/home/pechanove/liberux/git/ltk/themes \
		./target/release/eydos-calls --windowsize 480x960

start-desktop: all
	LTK_THEMES_DIR=/home/pechanove/liberux/git/ltk/themes ./target/release/eydos-calls --windowsize 1600x900

start-desktop-root: all
	sudo -E env \
		WAYLAND_DISPLAY="$$WAYLAND_DISPLAY" \
		XDG_RUNTIME_DIR="$$XDG_RUNTIME_DIR" \
		LTK_THEMES_DIR=/home/pechanove/liberux/git/ltk/themes \
		./target/release/eydos-calls --windowsize 1600x900


start-full: all
	LTK_THEMES_DIR=/home/pechanove/liberux/git/ltk/themes ./target/release/eydos-calls

install:
	install -Dm755 $(RELEASE_DIR)/eydos-calls $(BINDIR)/eydos-calls
	install -Dm644 data/io.eydos.Calls.desktop $(DATADIR)/applications/io.eydos.Calls.desktop
	install -Dm644 res/sounds/ring.ogg $(DATADIR)/eydos-calls/sounds/ring.ogg

uninstall:
	rm -f $(BINDIR)/eydos-calls
	rm -f $(DATADIR)/applications/io.eydos.Calls.desktop
	rm -f $(DATADIR)/eydos-calls/sounds/ring.ogg

# Build the Debian package. `deb` for the host arch; `deb-arm64` cross-builds an
# arm64 package from amd64 (needs the arm64 cross deps — `make arm64-deps`).
deb:
	dpkg-buildpackage -us -uc -b

deb-arm64:
	dpkg-buildpackage -us -uc -b -a arm64

clean:
	cargo clean

distclean: clean
	rm -f Cargo.lock
