Skip to content

Commit 265e721

Browse files
committed
feat(build): 添加 Linux/Debian 版本编译目标并更新帮助信息
- 在 Makefile 中新增 build-linux 目标以支持静态链接的 Linux/Debian 版本编译 - 更新 build 目标以设置 CGO_ENABLED=0,确保无 CGO 依赖 - 修改帮助信息以反映新的编译选项
1 parent a750f69 commit 265e721

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ run: tidy format dev
3737

3838
.PHONY: build
3939
build: tidy # 编译源码,依赖 tidy 目标自动添加/移除依赖包.
40-
@go build -v -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(ROOT_DIR)/$(PROJECT_NAME).go
40+
@CGO_ENABLED=0 go build -v -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME) $(ROOT_DIR)/$(PROJECT_NAME).go
41+
42+
.PHONY: build-linux
43+
build-linux: tidy # 编译 Linux/Debian 版本(静态链接,无 CGO 依赖).
44+
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -a -installsuffix cgo -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(PROJECT_NAME)-linux-amd64 $(ROOT_DIR)/$(PROJECT_NAME).go
4145

4246
.PHONY: format
4347
format: # 格式化 Go 源码.
@@ -139,7 +143,8 @@ swagger-clean: # 清理 Swagger 文档
139143
help: # 显示帮助信息
140144
@echo "Available targets:"
141145
@echo " all - 构建项目 (默认)"
142-
@echo " build - 编译源码"
146+
@echo " build - 编译源码(当前平台)"
147+
@echo " build-linux - 编译 Linux/Debian 版本(静态链接)"
143148
@echo " run - 开发运行"
144149
@echo " dev - 开发运行"
145150
@echo " test - 运行测试"

0 commit comments

Comments
 (0)