BINARY := bin/wikijs-mcp
VERSION ?= $(shell git describe --tags --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)

.PHONY: build test test-race vet fmt check run run-http docker-up docker-down clean help

build:
	@mkdir -p bin
	go build -trimpath -ldflags '$(LDFLAGS)' -o $(BINARY) ./cmd/wikijs-mcp

test:
	go test ./...

test-race:
	go test -race ./...

vet:
	go vet ./...

fmt:
	gofmt -w .

check: vet test-race

run: build
	./$(BINARY)

run-http: build
	./$(BINARY) -transport http -addr 127.0.0.1:8080 -path /mcp

docker-up:
	docker compose up -d

docker-down:
	docker compose down

clean:
	rm -rf bin

help:
	@echo "Targets:"
	@echo "  build       build $(BINARY)"
	@echo "  test        run unit tests"
	@echo "  test-race   run unit tests with the race detector"
	@echo "  vet         run go vet"
	@echo "  check       vet + race tests"
	@echo "  run         build and run with the stdio transport"
	@echo "  run-http    build and run with the HTTP transport on 127.0.0.1:8080"
	@echo "  docker-up   start a local WikiJS stack"
	@echo "  docker-down stop the local WikiJS stack"
	@echo "  clean       remove build artifacts"
