obm/Makefile
MermaidMan af0383108b
Some checks failed
CI / Test (pull_request) Failing after 47s
CI / Build (pull_request) Has been skipped
CI / Build-1 (pull_request) Has been skipped
CI / Build-2 (pull_request) Has been skipped
CI / Build-3 (pull_request) Has been skipped
CI / Build-4 (pull_request) Has been skipped
Add check-go guard with friendly message for missing Go toolchain
2026-05-22 23:56:56 +00:00

177 lines
No EOL
5.7 KiB
Makefile

.PHONY: build test lint clean fmt vet version cross-compile release install uninstall
# Version handling - override with VERSION=0.2.0 make build
VERSION := $(shell cat VERSION 2>/dev/null || echo "0.1.0")
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BINARY := obm
LDFLAGS := -ldflags "-s -w -X main.version=$(VERSION) -X main.gitCommit=$(GIT_COMMIT) -X main.buildTime=$(BUILD_TIME)"
# Go parameters
GOCMD := go
GOBUILD := $(GOCMD) build
GOCLEAN := $(GOCMD) clean
GOTEST := $(GOCMD) test
GOGET := $(GOCMD) get
GOMOD := $(GOCMD) mod
GOVET := $(GOCMD) vet
# Cross-compilation targets
TARGETS := linux-amd64 linux-arm64 darwin-arm64 windows-amd64 windows-arm64
# 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 " │ obm is a Go project. You need the Go │"; \
echo " │ 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 all-in-one script: │"; \
echo " │ ./scripts/install.sh │"; \
echo " │ │"; \
echo " ╰──────────────────────────────────────────────╯"; \
echo ""; \
exit 1; \
fi
all: lint test build
build: check-go
@echo "Building $(BINARY) v$(VERSION) for $(GOOS)/$(GOARCH)..."
$(GOBUILD) $(LDFLAGS) -o $(BINARY) ./cmd/obm
test: check-go
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
lint: vet fmt
@echo "✓ Lint pass"
vet: check-go
@echo "Running go vet..."
$(GOVET) ./...
fmt: check-go
@echo "Formatting code..."
gofmt -l -s -w .
clean: check-go
@echo "Cleaning..."
rm -f $(BINARY)
rm -f coverage.out
rm -rf bin/
$(GOCLEAN)
run: build
./$(BINARY)
install: build
@echo "Installing $(BINARY)..."
cp $(BINARY) $(GOPATH)/bin/
uninstall: clean
@echo "Uninstalling $(BINARY)..."
rm -f $(GOPATH)/bin/$(BINARY)
version:
@echo "$(VERSION)"
# Cross-compilation
cross-compile: check-go
@echo "Cross-compiling for all platforms..."
@mkdir -p bin
@for target in $(TARGETS); do \
os=$${target%-*}; \
arch=$${target#*-}; \
echo "Building for $$os/$$arch..."; \
binary="$(BINARY)"; \
ext=""; \
if [ "$$os" = "windows" ]; then \
ext=".exe"; \
fi; \
GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o "bin/$$target/$$binary$$ext" ./cmd/obm; \
done
@echo "✓ Cross-compilation complete"
# Build specific platform
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: check-go
@mkdir -p bin
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/linux-arm64/$(BINARY) ./cmd/obm
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: 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: check-go
@mkdir -p bin
GOOS=windows GOARCH=arm64 CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o bin/windows-arm64/$(BINARY).exe ./cmd/obm
# Create release archives
release-archives: cross-compile
@echo "Creating release archives..."
@cd bin && \
for dir in */; do \
platform=$${dir%/}; \
echo "Archiving $$platform..."; \
if [[ "$$platform" == windows-* ]]; then \
zip -j $$platform.zip $$platform/; \
else \
tar -czf $$platform.tar.gz -C $$platform .; \
fi; \
done
@echo "✓ Release archives created in bin/"
# Checksums
checksums:
@echo "Generating checksums..."
@cd bin && sha256sum *.tar.gz *.zip > checksums.txt 2>/dev/null || true
@echo "✓ Checksums in bin/checksums.txt"
# Full release preparation (local)
prepare-release: clean test cross-compile release-archives checksums
@echo ""
@echo "Release v$(VERSION) prepared in bin/"
@ls -la bin/
# Docker build (for containerized usage)
docker-build:
docker build -t obm:$(VERSION) -t obm:latest .
# Development
dev: build test
@echo "✓ Development build complete"
# Quick test during development
quick-test: check-go
$(GOTEST) -race ./...
# Coverage report
coverage: check-go test
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"