GO       ?= go
BIN_DIR  ?= bin

.PHONY: all build test vet fmt tidy run clean seed

all: build

## build: compile the service and the CLI as static binaries
build:
	CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/addrkitd ./cmd/addrkitd
	CGO_ENABLED=0 $(GO) build -trimpath -o $(BIN_DIR)/addrkit ./cmd/addrkit

## test: run the full test suite with the race detector
test:
	$(GO) test -race ./...

## vet: static analysis
vet:
	$(GO) vet ./...

## fmt: format all Go sources
fmt:
	gofmt -l -w .

## tidy: sync go.mod/go.sum
tidy:
	$(GO) mod tidy

## run: build and start the service with the local config
run: build
	$(BIN_DIR)/addrkitd -config config.json

## seed: build registry.db from a registry dump (override IN=/OUT=)
IN  ?= registry.ndjson
OUT ?= registry.db
seed:
	$(BIN_DIR)/addrkit seed -in $(IN) -out $(OUT)

## clean: remove build artifacts
clean:
	rm -rf $(BIN_DIR)
