-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
82 lines (70 loc) · 2.33 KB
/
Makefile
File metadata and controls
82 lines (70 loc) · 2.33 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
# 设置 Go 编译环境变量
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
# 设置版本信息
VERSION := $(shell git describe --tags --always --dirty)
BUILDTIME := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
LDFLAGS := -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILDTIME)"
# 设置输出目录
BUILD_DIR := build
BINARY_NAME := dumpall-go
# 默认目标
.PHONY: all
all: clean build-all
# 清理构建目录
.PHONY: clean
clean:
@echo "Cleaning build directory..."
@rm -rf $(BUILD_DIR)
@mkdir -p $(BUILD_DIR)
# 构建所有平台
.PHONY: build-all
build-all: build-windows build-linux build-darwin
# 构建 Windows 版本
.PHONY: build-windows
build-windows:
@echo "Building for Windows..."
@GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe
@GOOS=windows GOARCH=386 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-windows-386.exe
# 构建 Linux 版本
.PHONY: build-linux
build-linux:
@echo "Building for Linux..."
@GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64
@GOOS=linux GOARCH=386 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-386
@GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64
# 构建 macOS 版本
.PHONY: build-darwin
build-darwin:
@echo "Building for macOS..."
@GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64
@GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64
# 构建当前平台
.PHONY: build
build:
@echo "Building for current platform..."
@go build $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME)
# 运行测试
.PHONY: test
test:
@echo "Running tests..."
@go test -v ./...
# 安装依赖
.PHONY: deps
deps:
@echo "Installing dependencies..."
@go mod tidy
@go mod download
# 帮助信息
.PHONY: help
help:
@echo "Available targets:"
@echo " all - Build for all platforms"
@echo " build - Build for current platform"
@echo " build-windows- Build for Windows (amd64, 386)"
@echo " build-linux - Build for Linux (amd64, 386, arm64)"
@echo " build-darwin - Build for macOS (amd64, arm64)"
@echo " clean - Clean build directory"
@echo " test - Run tests"
@echo " deps - Install dependencies"
@echo " help - Show this help message"