.PHONY: build test lint fmt clean run release help

BINARY := bin/orca
GOFLAGS := -trimpath
LDFLAGS := -s -w -X main.version=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") \
           -X main.gitCommit=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown") \
           -X main.buildTime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)

help:
	@echo "orca — make targets"
	@echo "  build    Build binary to $(BINARY)"
	@echo "  test     Run tests with race detection"
	@echo "  lint     Run gofmt + go vet"
	@echo "  fmt      Format code"
	@echo "  clean    Remove build artifacts"
	@echo "  run      Build and run with args (use: make run ARGS='version')"
	@echo "  release  Build release artifact with version injection"

build:
	@mkdir -p bin
	go build $(GOFLAGS) -o $(BINARY) ./cmd/orca

test:
	go test -race -coverprofile=coverage.out ./...

lint:
	gofmt -l .
	go vet ./...

fmt:
	gofmt -w .

clean:
	rm -rf bin coverage.out

run: build
	./$(BINARY) $(ARGS)

release:
	@mkdir -p bin
	go build $(GOFLAGS) -ldflags="$(LDFLAGS)" -o $(BINARY) ./cmd/orca
	@echo "Release build complete: $(BINARY)"
