.PHONY: build test lint fmt vet tidy vuln check run

VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT  ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT)

build:
	go build -trimpath -ldflags "$(LDFLAGS)" -o bin/ ./cmd/...

test:
	go test -race ./...

lint:
	go tool staticcheck ./...

# gofmt and goimports take paths, not ./... package patterns.
fmt:
	gofmt -w .
	go tool goimports -w .

vet:
	go vet ./...

tidy:
	go mod tidy

vuln:
	go tool govulncheck ./...

# Everything CI runs.
check: vet lint test vuln
	@test -z "$$(gofmt -l .)" || (echo "gofmt needed:"; gofmt -l .; exit 1)

run:
	go run ./cmd/uberbringer --config config.toml
