# aerie Makefile
#
# Operational scaffolding for the aerie repo. Wraps standard Go workflows so
# hopper, CI, and contributors share a single entry point. The build flags
# default to the pure-Go static path aerie ships (CGO_ENABLED=0) — see Lode 1
# of the engineering plan for the modernc.org/sqlite swap that makes this work
# fully clean.
#
# Targets:
#   install  fetch Go module dependencies
#   build    build the knot binary as a pure-Go static executable
#   test     run the full upstream test suite
#   test-dual run the test suite with both SQLite driver flavors
#   lint     run L0 repo-governance lint gates and their self-tests
#   ci       install + lint + test + build
#   build-image build the Cloudflare Containers Docker image
#   ci-image full CI plus operator-side image build
#   clean    remove build artifacts

GO          ?= go
CGO_ENABLED ?= 0
BUILD_FLAGS ?=
BUILD_TAGS  ?= modernc
BUILD_TAG_FLAGS = $(if $(BUILD_TAGS),-tags $(BUILD_TAGS))
KNOT_BIN    ?= bin/knot

.PHONY: install build test test-dual lint ci build-image ci-image clean

install:
	$(GO) mod download

build:
	mkdir -p bin
	CGO_ENABLED=$(CGO_ENABLED) $(GO) build $(BUILD_TAG_FLAGS) $(BUILD_FLAGS) -o $(KNOT_BIN) ./cmd/knot

test:
	$(GO) test ./...

# Run the test suite under both SQLite driver flavors (default mattn/CGO and modernc/pure-Go).
# See L1d in the aerie engineering plan.
test-dual:
	$(GO) test ./...
	$(GO) test -tags modernc ./...

lint:
	bash scripts/lint-ssh-dormant.sh
	bash scripts/lint-ssh-dormant.sh --self-test
	bash scripts/lint-lexicon-namespace.sh
	bash scripts/lint-lexicon-namespace.sh --self-test
	bash scripts/check-literal-blocks.sh
	bash scripts/check-literal-blocks.sh --self-test
	bash scripts/lint-wrangler-toml.sh
	bash scripts/lint-wrangler-toml.sh --self-test
	bash scripts/lint-no-cf-in-core.sh
	bash scripts/lint-no-cf-in-core.sh --self-test
	bash scripts/lint-no-ssh-in-image.sh
	bash scripts/lint-no-ssh-in-image.sh --self-test
	bash scripts/lint-upstreamable-core.sh
	bash scripts/lint-upstreamable-core.sh --self-test

ci: install lint test build

build-image: ## Build the Cloudflare Containers Docker image (post-ship VPE-direct)
	docker build -f deploy/cloudflare/Dockerfile -t aerie:local .

ci-image: ci build-image ## Full CI plus image build (operator-side)

clean:
	rm -rf bin
