.PHONY: bootstrap setup test lint fmt fmt-check check docker hooks \
	build install tidy clean

# Makefile targets are thin shims; the implementations live in script/
# per the scripts-to-rule-them-all pattern (see the Entrypoints section
# of README.md). The targets after the shims are this repo's own.

bootstrap:
	@script/bootstrap

setup:
	@script/setup

test:
	@script/test

lint:
	@script/lint

fmt:
	@script/fmt

fmt-check:
	@script/fmt-check

check:
	@script/check

docker:
	@script/docker

hooks:
	@script/install-precommit

# This repository's own targets.

BINARY := sutil
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo unknown)
GOLDFLAGS := -X main.Version=$(VERSION)

# cgo stays off everywhere: builds are static, and the test phase of the
# Dockerfile runs without -race, which would need a C toolchain.
export CGO_ENABLED := 0

# Build the sutil binary in the repo root with the git version embedded.
build:
	go build -trimpath -ldflags "$(GOLDFLAGS)" -o $(BINARY) ./cmd/$(BINARY)

# Install sutil into $(go env GOBIN) (or $GOPATH/bin).
install:
	go install -trimpath -ldflags "$(GOLDFLAGS)" ./cmd/$(BINARY)

# Tidy go.mod and go.sum; script/precommit refuses a commit that needs it.
tidy:
	go mod tidy

clean:
	rm -f $(BINARY)
