# Build configuration for the vm-migration Go binary.
# Injects git-hash/date into internal/cli via -ldflags -X so the
# `version` subcommand and logs report the build provenance.

GO ?= go
PACKAGE := github.com/tidbcloud/observability/vm-migration
BINARY := vm-migration
VERSION ?= $(shell git rev-parse HEAD 2>/dev/null || echo dev)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)

LDFLAGS := \
	-X $(PACKAGE)/internal/cli.Version=$(VERSION) \
	-X $(PACKAGE)/internal/cli.Date=$(DATE)

.PHONY: build install test clean lint dev-tools

build:
	$(GO) build -ldflags "$(LDFLAGS)" -o $(BINARY) ./cmd/vm-migration

install: build
	mv $(BINARY) /usr/local/bin/$(BINARY)

test:
	./control.sh unittest

clean:
	rm -f $(BINARY)

lint:
	gofmt -r 'interface{} -> any' -w .
	goimports-reviser -project-name "github.com/tidbcloud/observability/vm-migration" ./...
	gofumpt -w .
	golangci-lint run --fix --config .golangci.yml

dev-tools:
	test -s golangci-lint || $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
	test -s goimports-reviser || $(GO) install github.com/incu6us/goimports-reviser/v3@latest
	test -s gofumpt || $(GO) install mvdan.cc/gofumpt@v0.5.0
