.PHONY: all bootstrap setup build lint fmt fmt-check test check clean run debug docker hooks ensure-web-dist

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

# The standard targets are thin shims; the implementations live in
# script/ per the scripts-to-rule-them-all pattern (see the Entrypoints
# section of README.md).

all: check build

bootstrap:
	@script/bootstrap

setup:
	@script/setup

# ensure-web-dist creates placeholder files so //go:embed dist/* in
# web/embed.go resolves without a full Node.js build.  The real SPA is
# built by the web-builder Docker stage; these placeholders let
# "make build" work outside Docker.
ensure-web-dist:
	@if [ ! -d web/dist ]; then \
		mkdir -p web/dist && \
		touch web/dist/index.html web/dist/style.css web/dist/app.js && \
		echo "==> Created placeholder web/dist/ for go:embed"; \
	fi

build: ensure-web-dist
	go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/neoircd

test:
	@script/test

lint:
	@script/lint

fmt:
	@script/fmt

fmt-check:
	@script/fmt-check

check:
	@script/check

run: build
	./bin/$(BINARY)

debug: build
	DEBUG=1 GOTRACEBACK=all ./bin/$(BINARY)

clean:
	rm -rf bin/ neoircd

docker:
	@script/docker

hooks:
	@script/install-precommit
