forked from fruitbars/simple-one-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (72 loc) · 3 KB
/
Makefile
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
.PHONY: release build compress clean
BINARY_NAME=simple-one-api
BUILD_DIR=build
use_upx?=0 # 设置默认值为0,表示默认禁用 UPX 压缩
clean_up?=0 # 默认不删除构建目录
PLATFORMS = darwin-amd64 darwin-arm64 windows-amd64 windows-arm64 linux-amd64 linux-arm64
release: build upx compress
dev: build
build: $(PLATFORMS)
$(PLATFORMS):
@$(MAKE) --no-print-directory build-$@
build-darwin-amd64:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(BUILD_DIR)/darwin-amd64/$(BINARY_NAME)
build-darwin-arm64:
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o $(BUILD_DIR)/darwin-arm64/$(BINARY_NAME)
build-windows-amd64:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(BUILD_DIR)/windows-amd64/$(BINARY_NAME).exe
build-windows-arm64:
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -o $(BUILD_DIR)/windows-arm64/$(BINARY_NAME).exe
build-linux-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/linux-amd64/$(BINARY_NAME)
build-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o $(BUILD_DIR)/linux-arm64/$(BINARY_NAME)
upx:
ifeq ($(use_upx),1)
upx --best --lzma $(BUILD_DIR)/darwin-amd64/$(BINARY_NAME); \
upx --best --lzma $(BUILD_DIR)/windows-amd64/$(BINARY_NAME).exe; \
upx --best --lzma $(BUILD_DIR)/linux-amd64/$(BINARY_NAME);\
upx --best --lzma $(BUILD_DIR)/darwin-arm64/$(BINARY_NAME); \
upx --best --lzma $(BUILD_DIR)/windows-arm64/$(BINARY_NAME).exe; \
upx --best --lzma $(BUILD_DIR)/linux-arm64/$(BINARY_NAME)
endif
compress:
@$(MAKE) --no-print-directory $(addprefix compress-,$(PLATFORMS))
compress-darwin-amd64:
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64.tar.gz -C $(BUILD_DIR)/darwin-amd64/ $(BINARY_NAME)
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/darwin-amd64
@echo "Removed build directory for darwin-amd64"
endif
compress-darwin-arm64:
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64.tar.gz -C $(BUILD_DIR)/darwin-arm64/ $(BINARY_NAME)
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/darwin-arm64
@echo "Removed build directory for darwin-arm64"
endif
compress-windows-amd64:
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.tar.gz -C $(BUILD_DIR)/windows-amd64/ $(BINARY_NAME).exe
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/windows-amd64
@echo "Removed build directory for windows-amd64"
endif
compress-windows-arm64:
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-windows-arm64.tar.gz -C $(BUILD_DIR)/windows-arm64/ $(BINARY_NAME).exe
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/windows-arm64
@echo "Removed build directory for windows-arm64"
endif
compress-linux-amd64:
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64.tar.gz -C $(BUILD_DIR)/linux-amd64/ $(BINARY_NAME)
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/linux-amd64
@echo "Removed build directory for linux-amd64"
endif
compress-linux-arm64:
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64.tar.gz -C $(BUILD_DIR)/linux-arm64/ $(BINARY_NAME)
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/linux-arm64
@echo "Removed build directory for linux-arm64"
endif
clean:
rm -rf $(BUILD_DIR)/*