

# ━━━ cmsctl build + install ━━━
# Builds the cmsctl CLI. Pure Go, no cgo/build tags needed.
#
#   make cmsctl           # build to ./bin/cmsctl
#   make install-cmsctl   # build + install to ~/.local/bin
#
# Override BIN_DIR to install elsewhere: make install-cmsctl BIN_DIR=/usr/local/bin
BIN_DIR ?= $(HOME)/.local/bin

.PHONY: cmsctl install-cmsctl
cmsctl:
	@mkdir -p bin
	CGO_ENABLED=0 go build -trimpath -ldflags "-s -w" -o bin/cmsctl ./cmd/cmsctl
	@echo "Built bin/cmsctl"

install-cmsctl: cmsctl
	@mkdir -p $(BIN_DIR)
	@cp bin/cmsctl $(BIN_DIR)/cmsctl
	@chmod 0755 $(BIN_DIR)/cmsctl
	@echo "Installed $(BIN_DIR)/cmsctl"

# ━━━ Pre-commit hook (forbid root binaries) ━━━
.PHONY: install-hooks
install-hooks:
	@if [ "$$(git config core.hooksPath 2>/dev/null)" != "hooks/" ]; then \
		git config core.hooksPath hooks/; \
		echo "Configured git core.hooksPath=hooks/"; \
	fi
	@chmod +x hooks/pre-commit
	@echo "Pre-commit hook installed. (Bypass with: git commit --no-verify)"
