-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
220 lines (185 loc) · 6.57 KB
/
Copy pathMakefile
File metadata and controls
220 lines (185 loc) · 6.57 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Proxy Queue Makefile
# Build for multiple platforms
APP_NAME=proxy-queue
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
GO_VERSION := $(shell go version | cut -d ' ' -f 3)
# Build flags
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME) -X main.GoVersion=$(GO_VERSION)"
# Directories
BUILD_DIR=build
DIST_DIR=dist
# Default target
.PHONY: all
all: clean build
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@go clean
# Build for current platform
.PHONY: build
build:
@echo "Building $(APP_NAME) for current platform..."
@mkdir -p $(BUILD_DIR)
@go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME) main.go
# Install dependencies
.PHONY: deps
deps:
@echo "Installing dependencies..."
@go mod download
@go mod tidy
# Run tests
.PHONY: test
test:
@echo "Running tests..."
@go test -v ./...
# Run with race detection
.PHONY: test-race
test-race:
@echo "Running tests with race detection..."
@go test -race -v ./...
# Lint the code
.PHONY: lint
lint:
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found, install it with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
fi
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
@go fmt ./...
# Vet code
.PHONY: vet
vet:
@echo "Vetting code..."
@go vet ./...
# Build for Linux (x86_64)
.PHONY: build-linux
build-linux:
@echo "Building $(APP_NAME) for Linux (x86_64)..."
@mkdir -p $(BUILD_DIR)
@GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 main.go
# Build for Linux (ARM64)
.PHONY: build-linux-arm64
build-linux-arm64:
@echo "Building $(APP_NAME) for Linux (ARM64)..."
@mkdir -p $(BUILD_DIR)
@GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-arm64 main.go
# Build for Ubuntu (same as Linux x86_64)
.PHONY: build-ubuntu
build-ubuntu: build-linux
@echo "Ubuntu build completed (same as Linux x86_64)"
# Build for macOS (x86_64)
.PHONY: build-macos
build-macos:
@echo "Building $(APP_NAME) for macOS (x86_64)..."
@mkdir -p $(BUILD_DIR)
@GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-amd64 main.go
# Build for macOS (ARM64 - Apple Silicon)
.PHONY: build-macos-arm64
build-macos-arm64:
@echo "Building $(APP_NAME) for macOS (ARM64)..."
@mkdir -p $(BUILD_DIR)
@GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64 main.go
# Build for Windows (x86_64)
.PHONY: build-windows
build-windows:
@echo "Building $(APP_NAME) for Windows (x86_64)..."
@mkdir -p $(BUILD_DIR)
@GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-windows-amd64.exe main.go
# Build for Windows (ARM64)
.PHONY: build-windows-arm64
build-windows-arm64:
@echo "Building $(APP_NAME) for Windows (ARM64)..."
@mkdir -p $(BUILD_DIR)
@GOOS=windows GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-windows-arm64.exe main.go
# Build for all platforms
.PHONY: build-all
build-all: build-linux build-linux-arm64 build-macos build-macos-arm64 build-windows build-windows-arm64
@echo "All platform builds completed"
# Create distribution packages
.PHONY: dist
dist: build-all
@echo "Creating distribution packages..."
@mkdir -p $(DIST_DIR)
# Linux x86_64
@tar -czf $(DIST_DIR)/$(APP_NAME)-$(VERSION)-linux-amd64.tar.gz -C $(BUILD_DIR) $(APP_NAME)-linux-amd64
# Linux ARM64
@tar -czf $(DIST_DIR)/$(APP_NAME)-$(VERSION)-linux-arm64.tar.gz -C $(BUILD_DIR) $(APP_NAME)-linux-arm64
# macOS x86_64
@tar -czf $(DIST_DIR)/$(APP_NAME)-$(VERSION)-darwin-amd64.tar.gz -C $(BUILD_DIR) $(APP_NAME)-darwin-amd64
# macOS ARM64
@tar -czf $(DIST_DIR)/$(APP_NAME)-$(VERSION)-darwin-arm64.tar.gz -C $(BUILD_DIR) $(APP_NAME)-darwin-arm64
# Windows x86_64
@cd $(BUILD_DIR) && zip ../$(DIST_DIR)/$(APP_NAME)-$(VERSION)-windows-amd64.zip $(APP_NAME)-windows-amd64.exe
# Windows ARM64
@cd $(BUILD_DIR) && zip ../$(DIST_DIR)/$(APP_NAME)-$(VERSION)-windows-arm64.zip $(APP_NAME)-windows-arm64.exe
@echo "Distribution packages created in $(DIST_DIR)/"
# Run the application
.PHONY: run
run: build
@echo "Running $(APP_NAME)..."
@$(BUILD_DIR)/$(APP_NAME)
# Run with example configuration
.PHONY: run-example
run-example: build
@echo "Running $(APP_NAME) with example configuration..."
@$(BUILD_DIR)/$(APP_NAME) -port=6789 -target-host=httpbin.org -target-port=443 -https=true -delay-min=1000 -delay-max=5000
# Development build (with debug info)
.PHONY: dev
dev:
@echo "Building $(APP_NAME) for development..."
@mkdir -p $(BUILD_DIR)
@go build -gcflags="all=-N -l" -o $(BUILD_DIR)/$(APP_NAME)-dev main.go
# Check Go version compatibility
.PHONY: check-version
check-version:
@echo "Go version: $(GO_VERSION)"
@echo "Required: go1.19 or later"
# Show build information
.PHONY: info
info:
@echo "Application: $(APP_NAME)"
@echo "Version: $(VERSION)"
@echo "Build Time: $(BUILD_TIME)"
@echo "Go Version: $(GO_VERSION)"
# Install the binary to GOPATH/bin
.PHONY: install
install:
@echo "Installing $(APP_NAME) to GOPATH/bin..."
@go install $(LDFLAGS) .
# Show help
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Clean and build for current platform"
@echo " build - Build for current platform"
@echo " build-linux - Build for Linux (x86_64)"
@echo " build-linux-arm64- Build for Linux (ARM64)"
@echo " build-ubuntu - Build for Ubuntu (alias for Linux x86_64)"
@echo " build-macos - Build for macOS (x86_64)"
@echo " build-macos-arm64- Build for macOS (ARM64)"
@echo " build-windows - Build for Windows (x86_64)"
@echo " build-windows-arm64 - Build for Windows (ARM64)"
@echo " build-all - Build for all platforms"
@echo " clean - Clean build artifacts"
@echo " deps - Install dependencies"
@echo " dev - Development build with debug info"
@echo " dist - Create distribution packages"
@echo " fmt - Format code"
@echo " help - Show this help message"
@echo " info - Show build information"
@echo " install - Install binary to GOPATH/bin"
@echo " lint - Run linter"
@echo " run - Build and run the application"
@echo " run-example - Run with example configuration"
@echo " test - Run tests"
@echo " test-race - Run tests with race detection"
@echo " vet - Vet code"
@echo " check-version - Check Go version compatibility"