-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
52 lines (43 loc) · 1.11 KB
/
Copy pathMakefile
File metadata and controls
52 lines (43 loc) · 1.11 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
# 定义变量
BIN_DIR := ./bin
APP_NAME := safelineApi
SRC_DIR := ./cmd/safelineApi
VERSION := 1.0.0
BUILD_TIME := $(shell date +"%Y-%m-%dT%H:%M:%S")
# 默认任务
.DEFAULT_GOAL := build
# 构建任务
build:
@echo "Building $(APP_NAME) version $(VERSION)..."
mkdir -p $(BIN_DIR)
go build -ldflags "-X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)" -o $(BIN_DIR)/$(APP_NAME) $(SRC_DIR)
# 运行任务
run:
@echo "Running $(APP_NAME)..."
$(BIN_DIR)/$(APP_NAME)
# 清理任务
clean:
@echo "Cleaning up..."
rm -rf $(BIN_DIR)
# 测试任务
test:
@echo "Running tests..."
go test ./...
# 格式化代码
fmt:
@echo "Formatting code..."
go fmt ./...
# 检查代码风格
vet:
@echo "Vetting code..."
go vet ./...
# 安装依赖
tidy:
@echo "Tidying dependencies..."
go mod tidy
# 多平台编译
build-all:
@echo "Building for all platforms..."
GOOS=linux GOARCH=amd64 go build -o $(BIN_DIR)/$(APP_NAME)-linux-amd64 $(SRC_DIR)
GOOS=windows GOARCH=amd64 go build -o $(BIN_DIR)/$(APP_NAME)-windows-amd64.exe $(SRC_DIR)
GOOS=darwin GOARCH=amd64 go build -o $(BIN_DIR)/$(APP_NAME)-darwin-amd64 $(SRC_DIR)