From fcbf669779a866a0afed8c2f1f77c2281f8f7ed8 Mon Sep 17 00:00:00 2001 From: kingecg Date: Thu, 3 Jul 2025 11:32:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(build):=20=E9=87=8D=E6=9E=84=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E7=B3=BB=E7=BB=9F=E4=BB=A5=E4=BD=BF=E7=94=A8=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改Makefile以将所有构建产物输出到target目录下的平台特定子目录中 --- Makefile | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index bc1164b..3bbafbd 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,25 @@ # 构建目标 BINARY := gofirewall +TARGET_DIR := target + +# 创建目标目录 +$(TARGET_DIR): + @mkdir -p $(TARGET_DIR)/linux/amd64 + @mkdir -p $(TARGET_DIR)/linux/arm64 + @mkdir -p $(TARGET_DIR)/windows/amd64 + @mkdir -p $(TARGET_DIR)/darwin/amd64 + @mkdir -p $(TARGET_DIR)/darwin/arm64 # 默认构建 -build: +build: $(TARGET_DIR) @echo "Building for current platform..." - go build -o $(BINARY) + go build -o $(TARGET_DIR)/$(BINARY) # 清理构建产物 clean: @echo "Cleaning build artifacts..." - @rm -f $(BINARY) $(BINARY)-* + @rm -rf $(TARGET_DIR) # 运行测试 test: @@ -19,10 +28,10 @@ test: go test ./... # 多平台构建 -build-all: clean test +build-all: clean test $(TARGET_DIR) @echo "Building for all platforms..." - GOOS=linux GOARCH=amd64 go build -o $(BINARY)-linux-amd64 - GOOS=linux GOARCH=arm64 go build -o $(BINARY)-linux-arm64 - GOOS=windows GOARCH=amd64 go build -o $(BINARY)-windows-amd64.exe - GOOS=darwin GOARCH=amd64 go build -o $(BINARY)-darwin-amd64 - GOOS=darwin GOARCH=arm64 go build -o $(BINARY)-darwin-arm64 \ No newline at end of file + GOOS=linux GOARCH=amd64 go build -o $(TARGET_DIR)/linux/amd64/$(BINARY) + GOOS=linux GOARCH=arm64 go build -o $(TARGET_DIR)/linux/arm64/$(BINARY) + GOOS=windows GOARCH=amd64 go build -o $(TARGET_DIR)/windows/amd64/$(BINARY).exe + GOOS=darwin GOARCH=amd64 go build -o $(TARGET_DIR)/darwin/amd64/$(BINARY) + GOOS=darwin GOARCH=arm64 go build -o $(TARGET_DIR)/darwin/arm64/$(BINARY) \ No newline at end of file