PREFIX    ?= /usr
DESTDIR   ?=
# Where the release binaries live. 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
UDEVDIR    = $(DESTDIR)$(PREFIX)/lib/udev/rules.d

BINARIES   = eydos-camera eydos-camera-render

.PHONY: all deps arm64 arm64-deps start start-desktop install uninstall clean distclean deb deb-arm64 debs

all:
	cargo build --release

deps:
	sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-pipewire gstreamer1.0-libcamera

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 libgstreamer1.0-dev:arm64 libgstreamer-plugins-base1.0-dev:arm64

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

start: all
	EYDOS_CAMERA_BOARDS=data/boards LTK_THEMES_DIR=/home/pechanove/liberux/git/ltk/themes ./target/release/eydos-camera --windowsize 480x960

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

install:
	for b in $(BINARIES); do install -Dm755 $(RELEASE_DIR)/$$b $(BINDIR)/$$b; done
	install -Dm644 data/io.eydos.Camera.desktop $(DATADIR)/applications/io.eydos.Camera.desktop
	install -Dm644 icon.svg $(DATADIR)/icons/hicolor/scalable/apps/io.eydos.Camera.svg
	install -Dm644 data/70-eydos-camera.rules $(UDEVDIR)/70-eydos-camera.rules
	install -Dm644 -t $(DATADIR)/eydos-camera/boards data/boards/*.json

uninstall:
	for b in $(BINARIES); do rm -f $(BINDIR)/$$b; done
	rm -f $(DATADIR)/applications/io.eydos.Camera.desktop
	rm -f $(DATADIR)/icons/hicolor/scalable/apps/io.eydos.Camera.svg
	rm -f $(UDEVDIR)/70-eydos-camera.rules
	rm -rf $(DATADIR)/eydos-camera

# 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`);
# `debs` produces both.
deb:
	dpkg-buildpackage -us -uc -b

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

debs: deb deb-arm64

clean:
	cargo clean

distclean: clean
	rm -f Cargo.lock
