.PHONY: build test vet lint proto proto-lint clean docker push all devserver

MCR     := mcr.svc.mcp.metacircular.net:8443
VERSION := $(shell git describe --tags --always --dirty)
LDFLAGS := -trimpath -ldflags="-s -w -X main.version=$(VERSION)"

mcq:
	CGO_ENABLED=0 go build $(LDFLAGS) -o mcq ./cmd/mcq

build:
	go build ./...

test:
	go test ./...

vet:
	go vet ./...

lint:
	golangci-lint run ./...

proto:
	protoc --go_out=. --go_opt=module=git.wntrmute.dev/mc/mcq \
		--go-grpc_out=. --go-grpc_opt=module=git.wntrmute.dev/mc/mcq \
		proto/mcq/v1/*.proto

proto-lint:
	buf lint
	buf breaking --against '.git#branch=master,subdir=proto'

clean:
	rm -f mcq

docker:
	docker build --build-arg VERSION=$(VERSION) -t $(MCR)/mcq:$(VERSION) -f Dockerfile .

push: docker
	docker push $(MCR)/mcq:$(VERSION)

devserver: mcq
	@mkdir -p srv
	@if [ ! -f srv/mcq.toml ]; then cp deploy/examples/mcq.toml.example srv/mcq.toml; echo "Created srv/mcq.toml from example — edit before running."; fi
	./mcq server --config srv/mcq.toml

all: vet lint test mcq
