-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
162 lines (142 loc) · 4.7 KB
/
Copy pathMakefile
File metadata and controls
162 lines (142 loc) · 4.7 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Makefile for agent project
# Go version 1.24.5
# Note: This project uses CGO dependencies (robotgo), cross-compilation is not supported
# Variables
BINARY_NAME=agent
BUILD_DIR=build
GO=go
GOFLAGS=-v
LDFLAGS=-s -w
CGO_ENABLED=1
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION_FLAGS=-X main.version=$(VERSION) -X main.buildTime=$(BUILD_TIME) -X main.binaryName=$(BINARY_NAME)
# Colors for output
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[0;33m
BLUE=\033[0;34m
NC=\033[0m # No Color
.PHONY: all
all: clean build
## build: Build the application
.PHONY: build
build:
@echo "$(BLUE)Building $(BINARY_NAME)...$(NC)"
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS) $(VERSION_FLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) .
@echo "$(GREEN)Build complete: $(BUILD_DIR)/$(BINARY_NAME) (version: $(VERSION))$(NC)"
## run: Run the application
.PHONY: run
run:
@echo "$(BLUE)Running $(BINARY_NAME)...$(NC)"
$(GO) run .
## clean: Clean build artifacts
.PHONY: clean
clean:
@echo "$(YELLOW)Cleaning build artifacts...$(NC)"
@rm -rf $(BUILD_DIR)
@rm -f $(BINARY_NAME)
@rm -f coverage.out coverage.html
@echo "$(GREEN)Clean complete$(NC)"
## test: Run tests
.PHONY: test
test:
@echo "$(BLUE)Running tests...$(NC)"
$(GO) test -v ./...
## test-coverage: Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "$(BLUE)Running tests with coverage...$(NC)"
$(GO) test -v -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "$(GREEN)Coverage report generated: coverage.html$(NC)"
## test-race: Run tests with race detection
.PHONY: test-race
test-race:
@echo "$(BLUE)Running tests with race detection...$(NC)"
$(GO) test -race -v ./...
@echo "$(GREEN)Race detection tests complete$(NC)"
## bench: Run benchmarks
.PHONY: bench
bench:
@echo "$(BLUE)Running benchmarks...$(NC)"
$(GO) test -bench=. -benchmem ./...
@echo "$(GREEN)Benchmark tests complete$(NC)"
## fmt: Format code
.PHONY: fmt
fmt:
@echo "$(BLUE)Formatting code...$(NC)"
$(GO) fmt ./...
@echo "$(GREEN)Formatting complete$(NC)"
## vet: Run go vet
.PHONY: vet
vet:
@echo "$(BLUE)Running go vet...$(NC)"
$(GO) vet ./...
@echo "$(GREEN)Vet complete$(NC)"
## lint: Run golangci-lint (requires golangci-lint installed)
.PHONY: lint
lint:
@echo "$(BLUE)Running linter...$(NC)"
@if command -v golangci-lint > /dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "$(YELLOW)golangci-lint not found. Install it from: https://golangci-lint.run/usage/install/$(NC)"; \
fi
## deps: Download dependencies
.PHONY: deps
deps:
@echo "$(BLUE)Downloading dependencies...$(NC)"
$(GO) mod download
$(GO) mod tidy
@echo "$(GREEN)Dependencies updated$(NC)"
## deps-verify: Verify dependencies
.PHONY: deps-verify
deps-verify:
@echo "$(BLUE)Verifying dependencies...$(NC)"
$(GO) mod verify
## deps-update: Update dependencies
.PHONY: deps-update
deps-update:
@echo "$(BLUE)Updating dependencies...$(NC)"
$(GO) get -u ./...
$(GO) mod tidy
@echo "$(GREEN)Dependencies updated$(NC)"
## install: Install the application to GOPATH/bin
.PHONY: install
install:
@echo "$(BLUE)Installing $(BINARY_NAME)...$(NC)"
$(GO) install $(GOFLAGS) -ldflags "$(LDFLAGS)" .
@echo "$(GREEN)Installation complete$(NC)"
## build-pure: Build without CGO (for testing only, limited functionality)
.PHONY: build-pure
build-pure:
@echo "$(YELLOW)Building without CGO (limited functionality)...$(NC)"
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=0 $(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-pure .
@echo "$(GREEN)Pure Go build complete: $(BUILD_DIR)/$(BINARY_NAME)-pure$(NC)"
@echo "$(YELLOW)Note: CGO-dependent features (robotgo) will not work$(NC)"
## build-debug: Build with debug symbols
.PHONY: build-debug
build-debug:
@echo "$(BLUE)Building with debug symbols...$(NC)"
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-debug .
@echo "$(GREEN)Debug build complete: $(BUILD_DIR)/$(BINARY_NAME)-debug$(NC)"
## help: Show this help message
.PHONY: help
help:
@echo "$(BLUE)Available targets:$(NC)"
@grep -E '^##' Makefile | sed 's/## / /' | column -t -s ':'
@echo ""
@echo "$(YELLOW)Examples:$(NC)"
@echo " make build - Build the application (requires CGO)"
@echo " make run - Run the application"
@echo " make test - Run tests"
@echo " make test-race - Run tests with race detection"
@echo " make clean - Clean build artifacts"
@echo " make build-pure - Build without CGO (limited functionality)"
@echo ""
@echo "$(YELLOW)Note:$(NC) This project uses CGO dependencies (robotgo),"
@echo " so cross-compilation is not supported. Build on the target platform."