SHELL := /bin/bash
BINARY := nexus
PKG := gitea.thetempleofdoom.com/drjones/mcp-gateway-nexus
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo 0.1.0-dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
	-X '$(PKG)/internal/version.Version=$(VERSION)' \
	-X '$(PKG)/internal/version.Commit=$(COMMIT)' \
	-X '$(PKG)/internal/version.Date=$(DATE)'

.PHONY: all build test vet fmt tidy run clean

all: vet test build

build: ## Build the nexus binary into ./bin
	@mkdir -p bin
	go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/nexus

test: ## Run all tests
	go test ./...

vet: ## Static analysis
	go vet ./...

fmt: ## Format code
	gofmt -s -w .

tidy: ## Tidy go.mod
	go mod tidy

run: build ## Build and run the gateway with the example config
	./bin/$(BINARY) serve -config config.example.yaml

clean:
	rm -rf bin
