# okf-builder — Go toolchain
#
# The Go binaries in dist/scripts/ are the canonical implementation;
# the legacy bash scripts are stored in dist/scripts/legacy/ (committed
# to the repo — they're source files, just kept next to the binaries
# they parallel because that's where they ship in the release archive).

DIST ?= dist

GO      ?= go
GOFLAGS ?=

BINS := okf-validate okf-regenerate-index okf-check-links okf-migrate-v01-to-v02

.PHONY: all clean test fmt vet $(BINS)

all: $(BINS)

# Pattern rule for the per-binary targets: `make okf-validate` builds only that
# binary; `make` builds all four.
$(BINS): %: FORCE
	@mkdir -p $(DIST)/scripts
	cd src && $(GO) build $(GOFLAGS) -o ../$(DIST)/scripts/$@ ./cmd/$@

# Always rebuild (binaries have no source prerequisites in this shape).
.PHONY: FORCE
FORCE:

test:
	cd src && $(GO) test ./...

fmt:
	cd src && gofmt -w $$(find . -name '*.go')

vet:
	cd src && $(GO) vet ./...

# Remove only the built binaries. The legacy/ subdir under dist/scripts/
# holds tracked source files — leave them alone.
clean:
	rm -f $(DIST)/scripts/okf-* $(DIST)/scripts/*.exe
