# gui/Makefile — the Odin + raylib renderer (the interactive 3D universe map).
#
# This is the Odin sub-project. It is normally invoked from the repo root via
# `make run`, `make build`, etc. (which delegate here through the root
# Makefile), but it can also be driven directly with `make -C gui <target>`.
#
# `lib/` (third-party Odin deps) lives under `gui/lib`; the `bin/` / `build/`
# output dirs live at the repo root and are referenced through `$(ROOT)`.

ODIN         ?= odin
ROOT         := ..
BIN          := $(ROOT)/bin
BINARY       := $(BIN)/desi_explorer
ODIN_FLAGS   := -collection:lib=lib/local
WASM_DEFINE  := RAYLIB_WASM_LIB=env.o

.PHONY: help run build build-debug build-web test clean fmt

help: ## List available targets
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
		awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-18s\033[0m %s\n", $$1, $$2}'

run: ## Run the native app
	@mkdir -p lib/local
	$(ODIN) run src $(ODIN_FLAGS)

build: ## Release build -> bin/desi_explorer
	@mkdir -p lib/local $(BIN)
	$(ODIN) build src $(ODIN_FLAGS) -o:speed -out:$(BINARY)

build-debug: ## Debug build -> bin/desi_explorer
	@mkdir -p lib/local $(BIN)
	$(ODIN) build src $(ODIN_FLAGS) -o:none -debug -out:$(BINARY)

build-web: ## WebAssembly build -> build/web (needs emscripten)
	@scripts/build_web.sh

test: ## Run Odin unit tests
	@mkdir -p lib/local
	$(ODIN) test src $(ODIN_FLAGS)

clean: ## Remove build artifacts
	rm -rf $(BIN) build

fmt: ## Format Odin sources with odinfmt
	odinfmt src
