-
Notifications
You must be signed in to change notification settings - Fork 124
/
Makefile
125 lines (100 loc) · 4.38 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
.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 freebsd-amd64 freebsd-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)
build-freebsd-amd64:
CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -o $(BUILD_DIR)/freebsd-amd64/$(BINARY_NAME)
build-freebsd-arm64:
CGO_ENABLED=0 GOOS=freebsd GOARCH=arm64 go build -o $(BUILD_DIR)/freebsd-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)/freebsd-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); \
upx --best --lzma $(BUILD_DIR)/freebsd-arm64/$(BINARY_NAME)
endif
compress:
@$(MAKE) --no-print-directory $(addprefix compress-,$(PLATFORMS))
compress-darwin-amd64:
cp -r static $(BUILD_DIR)/darwin-amd64/
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64.tar.gz -C $(BUILD_DIR)/darwin-amd64/ $(BINARY_NAME) static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/darwin-amd64
@echo "Removed build directory for darwin-amd64"
endif
compress-darwin-arm64:
cp -r static $(BUILD_DIR)/darwin-arm64/
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64.tar.gz -C $(BUILD_DIR)/darwin-arm64/ $(BINARY_NAME) static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/darwin-arm64
@echo "Removed build directory for darwin-arm64"
endif
compress-windows-amd64:
cp -r static $(BUILD_DIR)/windows-amd64/
zip -j $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.zip $(BUILD_DIR)/windows-amd64/$(BINARY_NAME).exe
zip -r $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.zip $(BUILD_DIR)/windows-amd64/static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/windows-amd64
@echo "Removed build directory for windows-amd64"
endif
compress-windows-arm64:
cp -r static $(BUILD_DIR)/windows-arm64/
zip -j $(BUILD_DIR)/$(BINARY_NAME)-windows-arm64.zip $(BUILD_DIR)/windows-arm64/$(BINARY_NAME).exe
zip -r $(BUILD_DIR)/$(BINARY_NAME)-windows-arm64.zip $(BUILD_DIR)/windows-arm64/static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/windows-arm64
@echo "Removed build directory for windows-arm64"
endif
compress-linux-amd64:
cp -r static $(BUILD_DIR)/linux-amd64/
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64.tar.gz -C $(BUILD_DIR)/linux-amd64/ $(BINARY_NAME) static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/linux-amd64
@echo "Removed build directory for linux-amd64"
endif
compress-linux-arm64:
cp -r static $(BUILD_DIR)/linux-arm64/
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64.tar.gz -C $(BUILD_DIR)/linux-arm64/ $(BINARY_NAME) static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/linux-arm64
@echo "Removed build directory for linux-arm64"
endif
compress-freebsd-amd64:
cp -r static $(BUILD_DIR)/freebsd-amd64/
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-freebsd-amd64.tar.gz -C $(BUILD_DIR)/freebsd-amd64/ $(BINARY_NAME) static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/freebsd-amd64
@echo "Removed build directory for freebsd-amd64"
endif
compress-freebsd-arm64:
cp -r static $(BUILD_DIR)/freebsd-arm64/
tar -czvf $(BUILD_DIR)/$(BINARY_NAME)-freebsd-arm64.tar.gz -C $(BUILD_DIR)/freebsd-arm64/ $(BINARY_NAME) static
ifeq ($(clean_up),1)
rm -rf $(BUILD_DIR)/freebsd-arm64
@echo "Removed build directory for freebsd-arm64"
endif
clean:
rm -rf $(BUILD_DIR)/*