diff --git a/Makefile b/Makefile index bfe215d..f817798 100644 --- a/Makefile +++ b/Makefile @@ -20,32 +20,60 @@ GOVET := $(GOCMD) vet # Cross-compilation targets TARGETS := linux-amd64 linux-arm64 darwin-arm64 windows-amd64 windows-arm64 -# Platform detection -GOOS := $(shell go env GOOS) -GOARCH := $(shell go env GOARCH) +# Platform detection (noiseless fallback — true check happens in check-go target) +GOOS := $(shell go env GOOS 2>/dev/null || echo "unknown") +GOARCH := $(shell go env GOARCH 2>/dev/null || echo "unknown") + +# ────────────────────────────────────────────── +# Friendly Go-not-found guard +check-go: + @if ! command -v go >/dev/null 2>&1; then \ + echo ""; \ + echo " ╭──────────────────────────────────────────────╮"; \ + echo " │ ⚠ Go is not installed on this machine! │"; \ + echo " ├──────────────────────────────────────────────┤"; \ + echo " │ │"; \ + echo " │ This is a Go project. You need the │"; \ + echo " │ Go language toolchain to build from source. │"; \ + echo " │ │"; \ + echo " │ Install Go: │"; \ + echo " │ Linux: your package manager │"; \ + echo " │ or https://go.dev/dl/ │"; \ + echo " │ │"; \ + echo " │ macOS: brew install go │"; \ + echo " │ │"; \ + echo " │ Windows: https://go.dev/dl/ │"; \ + echo " │ │"; \ + echo " │ Or use the obm full install script: │"; \ + echo " │ ./scripts/install.sh │"; \ + echo " │ │"; \ + echo " ╰──────────────────────────────────────────────╯"; \ + echo ""; \ + exit 1; \ + fi all: lint test build -build: +build: check-go @echo "Building $(BINARY) v$(VERSION) for $(GOOS)/$(GOARCH)..." $(GOBUILD) $(LDFLAGS) -o $(BINARY) ./cmd/obm -test: +test: check-go @echo "Running tests..." $(GOTEST) -v -race -coverprofile=coverage.out ./... lint: vet fmt @echo "✓ Lint pass" -vet: +vet: check-go @echo "Running go vet..." $(GOVET) ./... -fmt: +fmt: check-go @echo "Formatting code..." gofmt -l -s -w . -clean: +clean: check-go @echo "Cleaning..." rm -f $(BINARY) rm -f coverage.out @@ -67,7 +95,7 @@ version: @echo "$(VERSION)" # Cross-compilation -cross-compile: +cross-compile: check-go @echo "Cross-compiling for all platforms..." @mkdir -p bin @for target in $(TARGETS); do \ @@ -84,23 +112,23 @@ cross-compile: @echo "✓ Cross-compilation complete" # Build specific platform -build-linux-amd64: +build-linux-amd64: check-go @mkdir -p bin GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/linux-amd64/$(BINARY) ./cmd/obm -build-linux-arm64: +build-linux-arm64: check-go @mkdir -p bin GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/linux-arm64/$(BINARY) ./cmd/obm -build-darwin-arm64: +build-darwin-arm64: check-go @mkdir -p bin GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/darwin-arm64/$(BINARY) ./cmd/obm -build-windows-amd64: +build-windows-amd64: check-go @mkdir -p bin GOOS=windows GOARCH=amd64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/windows-amd64/$(BINARY).exe ./cmd/obm -build-windows-arm64: +build-windows-arm64: check-go @mkdir -p bin GOOS=windows GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/windows-arm64/$(BINARY).exe ./cmd/obm @@ -140,10 +168,10 @@ dev: build test @echo "✓ Development build complete" # Quick test during development -quick-test: +quick-test: check-go $(GOTEST) -race ./... # Coverage report -coverage: test +coverage: check-go test $(GOCMD) tool cover -html=coverage.out -o coverage.html @echo "Coverage report: coverage.html" \ No newline at end of file