BIN     ?= bin
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
PKG     := github.com/iceBear67/simplepages
LDFLAGS := -s -w -X $(PKG)/internal/version.Version=$(VERSION)
GOFLAGS := -trimpath

.PHONY: all build server cli test race atomicity vet fmt tidy clean

all: build

build: server cli

server:
	go build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(BIN)/pages-server ./cmd/pages-server

# The CLI is downloaded by CI runners, so its size is a feature: keep it small
# and keep server-side dependencies out of it (enforced by cmd/pages/deps_test.go).
cli:
	CGO_ENABLED=0 go build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o $(BIN)/pages ./cmd/pages

test:
	go test ./...

race:
	go test -race ./...

atomicity:
	go test -race -count=20 ./internal/deploy -run TestActivationAtomicity

vet:
	go vet ./...

fmt:
	gofmt -l -w .

tidy:
	go mod tidy

clean:
	rm -rf $(BIN)
