# DESI Explorer — root Makefile
#
# Orchestrates the Odin renderer (src/) and the Go/Pulumi infrastructure
# (infra/). Intended to be called directly by Gitea Actions CI.

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

.PHONY: help setup run build build-debug build-web test clean fmt \
        infra-preview infra-up infra-down infra-refresh infra-static \
        renovate-validate

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

## ---- Setup ---------------------------------------------------------------

setup: ## Pull submodules + tidy Go deps
	@git submodule update --init --recursive
	@mkdir -p lib/local
	@cd infra && go mod tidy

## ---- Renderer (Odin) -----------------------------------------------------

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 tests (Odin src/ + Go infra/)
	@mkdir -p lib/local
	$(ODIN) test src $(ODIN_FLAGS)
	@cd infra && go test ./...

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

fmt: ## Format Odin sources with odinfmt
	odinfmt src

## ---- Infrastructure (Go + Pulumi) ----------------------------------------

infra-preview: ## Preview infra changes against the cluster
	@pulumi preview --cwd infra

infra-up: ## Deploy/update infra
	@pulumi up --cwd infra

infra-down: ## Tear down the stack's resources
	@pulumi destroy --cwd infra

infra-refresh: ## Refresh Pulumi state against the live cluster
	@pulumi refresh --cwd infra

infra-static: ## Typecheck + vet the Go infra without Pulumi
	@cd infra && go build -o /dev/null . && go vet ./...

## ---- Tooling -------------------------------------------------------------

renovate-validate: ## Validate renovate.json
	npx --yes renovate-config-validator
