|
| 1 | +# Waza-Go Build System |
| 2 | +.PHONY: all build clean test lint fmt install help |
| 3 | + |
| 4 | +# Build configuration |
| 5 | +BINARY_NAME=waza |
| 6 | +BUILD_DIR=. |
| 7 | +GO_FILES=$(shell find . -name '*.go' -not -path './vendor/*') |
| 8 | +VERSION?=0.1.0 |
| 9 | +LDFLAGS=-ldflags "-X main.version=$(VERSION)" |
| 10 | + |
| 11 | +# Default target |
| 12 | +all: fmt lint test build |
| 13 | + |
| 14 | +# Build the binary |
| 15 | +build: |
| 16 | + @echo "Building $(BINARY_NAME)..." |
| 17 | + @go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/waza |
| 18 | + |
| 19 | +# Run tests |
| 20 | +test: |
| 21 | + @echo "Running tests..." |
| 22 | + @go test -v -race -coverprofile=coverage.out ./... |
| 23 | + @go tool cover -func=coverage.out | tail -1 |
| 24 | + |
| 25 | +# Run linter |
| 26 | +lint: |
| 27 | + @echo "Running linter..." |
| 28 | + @if command -v golangci-lint >/dev/null 2>&1; then \ |
| 29 | + golangci-lint run ./...; \ |
| 30 | + else \ |
| 31 | + echo "golangci-lint not installed, skipping..."; \ |
| 32 | + echo "Install: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b \$$(go env GOPATH)/bin v1.64.8"; \ |
| 33 | + fi |
| 34 | + |
| 35 | +# Format code |
| 36 | +fmt: |
| 37 | + @echo "Formatting code..." |
| 38 | + @gofmt -w $(GO_FILES) |
| 39 | + @go mod tidy |
| 40 | + |
| 41 | +# Install binary to GOPATH |
| 42 | +install: |
| 43 | + @echo "Installing $(BINARY_NAME)..." |
| 44 | + @go install $(LDFLAGS) ./cmd/waza |
| 45 | + |
| 46 | +# Clean build artifacts |
| 47 | +clean: |
| 48 | + @echo "Cleaning..." |
| 49 | + @rm -f $(BUILD_DIR)/$(BINARY_NAME) |
| 50 | + @rm -f coverage.out |
| 51 | + @go clean -cache -testcache |
| 52 | + |
| 53 | +# Show help |
| 54 | +help: |
| 55 | + @echo "Waza-Go Makefile Targets:" |
| 56 | + @echo " all - Format, lint, test, and build (default)" |
| 57 | + @echo " build - Compile the binary" |
| 58 | + @echo " test - Run all tests with coverage" |
| 59 | + @echo " lint - Run golangci-lint" |
| 60 | + @echo " fmt - Format Go code and tidy modules" |
| 61 | + @echo " install - Install binary to GOPATH" |
| 62 | + @echo " clean - Remove build artifacts" |
| 63 | + @echo " help - Show this help message" |
0 commit comments