Files
wild-cloud/wild-cli/Makefile

113 lines
3.2 KiB
Makefile

# Wild CLI Makefile
.DEFAULT_GOAL := help
# Build variables
BINARY_NAME := wild
BUILD_DIR := build
VERSION := 0.1.0-dev
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go variables
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
# Linker flags
LDFLAGS := -ldflags "-X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.buildTime=$(BUILD_TIME)"
.PHONY: help
help: ## Show this help message
@echo "Wild CLI Build System"
@echo ""
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: build
build: ## Build the binary
@echo "Building $(BINARY_NAME) for $(GOOS)/$(GOARCH)..."
@mkdir -p $(BUILD_DIR)
@go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/wild
.PHONY: install
install: ## Install the binary to GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
@go install $(LDFLAGS) ./cmd/wild
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
.PHONY: test
test: ## Run tests
@echo "Running tests..."
@go test -v ./...
.PHONY: test-coverage
test-coverage: ## Run tests with coverage
@echo "Running tests with coverage..."
@go test -v -coverprofile=coverage.out ./...
@go tool cover -html=coverage.out -o coverage.html
.PHONY: lint
lint: ## Run linter (requires golangci-lint)
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not installed, skipping lint check"; \
echo "Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
.PHONY: fmt
fmt: ## Format code
@echo "Formatting code..."
@go fmt ./...
.PHONY: mod-tidy
mod-tidy: ## Tidy go modules
@echo "Tidying go modules..."
@go mod tidy
.PHONY: deps
deps: ## Download dependencies
@echo "Downloading dependencies..."
@go mod download
.PHONY: build-all
build-all: ## Build for all platforms
@echo "Building for all platforms..."
@mkdir -p $(BUILD_DIR)
@echo "Building for linux/amd64..."
@GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 ./cmd/wild
@echo "Building for linux/arm64..."
@GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 ./cmd/wild
@echo "Building for darwin/amd64..."
@GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 ./cmd/wild
@echo "Building for darwin/arm64..."
@GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 ./cmd/wild
@echo "Building for windows/amd64..."
@GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe ./cmd/wild
.PHONY: dev
dev: build ## Build and run in development mode
@echo "Running $(BINARY_NAME) in development mode..."
@$(BUILD_DIR)/$(BINARY_NAME) --help
.PHONY: check
check: fmt lint test ## Run all checks (format, lint, test)
# Development workflow targets
.PHONY: quick
quick: fmt build ## Quick development build
.PHONY: watch
watch: ## Watch for changes and rebuild (requires entr)
@echo "Watching for changes... (requires 'entr' to be installed)"
@find . -name "*.go" | entr -r make quick