-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
130 lines (112 loc) · 4.23 KB
/
Makefile
File metadata and controls
130 lines (112 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.PHONY: build build-all build-darwin build-linux install test lint clean run
# Variables
BINARY_NAME=cfctl
VERSION=1.0.0
BUILD_DIR=bin
MAIN_PATH=./cmd/cfctl
# Build for current platform
# Smart build (detects if Go is installed)
build:
@if command -v go >/dev/null 2>&1; then \
$(MAKE) build-local; \
else \
echo "Go not found locally, using Docker..."; \
$(MAKE) docker-build; \
fi
# Build for current platform (Local)
build-local:
@echo "Building $(BINARY_NAME) for current platform..."
@mkdir -p $(BUILD_DIR)
go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PATH)
@echo "✓ Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
# Build using Docker (fallback if Go is missing)
docker-build:
@echo "Building using Docker (golang:1.24)..."
docker run --rm -v "$$(pwd):/app" -w /app golang:1.24 make build-all
@echo "✓ Docker build complete"
# Build for all platforms
build-all: build-darwin build-linux build-windows
@echo "✓ All builds complete"
# Build for macOS (Intel + Apple Silicon)
build-darwin:
@echo "Building for macOS..."
@mkdir -p $(BUILD_DIR)
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 $(MAIN_PATH)
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 $(MAIN_PATH)
@echo "✓ macOS builds complete"
# Build for Linux
build-linux:
@echo "Building for Linux..."
@mkdir -p $(BUILD_DIR)
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 $(MAIN_PATH)
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 $(MAIN_PATH)
@echo "✓ Linux builds complete"
# Build for Windows
build-windows:
@echo "Building for Windows..."
@mkdir -p $(BUILD_DIR)
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe $(MAIN_PATH)
GOOS=windows GOARCH=arm64 go build -ldflags="-s -w -X main.version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME)-windows-arm64.exe $(MAIN_PATH)
@echo "✓ Windows builds complete"
# Install locally
install: build
@echo "Installing $(BINARY_NAME)..."
@cp $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
@echo "✓ Installed to /usr/local/bin/$(BINARY_NAME)"
# Uninstall locally
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@rm -f /usr/local/bin/$(BINARY_NAME)
@echo "✓ Uninstalled from /usr/local/bin/$(BINARY_NAME)"
# Run the application
run: build
@$(BUILD_DIR)/$(BINARY_NAME)
# Run tests
test:
@echo "Running tests..."
go test -v ./...
# Run tests with coverage
test-coverage:
@echo "Running tests with coverage..."
go test -v -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
@echo "✓ Coverage report generated: coverage.html"
# Run linter (requires golangci-lint)
lint:
@echo "Running linter..."
@which golangci-lint > /dev/null || (echo "golangci-lint not found. Install: https://golangci-lint.run/usage/install/" && exit 1)
golangci-lint run
# Format code
fmt:
@echo "Formatting code..."
go fmt ./...
@echo "✓ Code formatted"
# Tidy dependencies
tidy:
@echo "Tidying dependencies..."
go mod tidy
@echo "✓ Dependencies tidied"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
@echo "✓ Clean complete"
# Display help
help:
@echo "Available targets:"
@echo " build - Build for current platform"
@echo " build-all - Build for all platforms"
@echo " build-darwin - Build for macOS (Intel + ARM)"
@echo " build-linux - Build for Linux (AMD64 + ARM64)"
@echo " build-windows - Build for Windows (AMD64 + ARM64)"
@echo " install - Build and install locally"
@echo " uninstall - Uninstall locally"
@echo " run - Build and run the application"
@echo " test - Run tests"
@echo " test-coverage - Run tests with coverage report"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " tidy - Tidy dependencies"
@echo " clean - Remove build artifacts"
@echo " help - Display this help message"