-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
93 lines (69 loc) · 2.35 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
PROJECT_NAME := gb-cms
BINARY_NAME := $(PROJECT_NAME)
# 默认目标平台和架构
GOOS ?= linux
GOARCH ?= amd64
ifeq ($(GOOS),windows)
BINARY_EXT = .exe
COMPRESS_CMD = zip -j
COMPRESS_EXT = .zip
else
BINARY_EXT =
COMPRESS_CMD = tar -czf
COMPRESS_EXT = .tar.gz
endif
BIN_DIR := bin
RESOURCES := config.json broadcast.html g711.js
BINARY := $(BINARY_NAME)-$(GOOS)-$(GOARCH)$(BINARY_EXT)
COMPRESSED_BINARY := $(BIN_DIR)/$(BINARY_NAME)-$(GOOS)-$(GOARCH)$(COMPRESS_EXT)
GO_BUILD := go build -v
all: build
create-bin-dir:
@echo "Creating bin directory..."
@mkdir -p $(BIN_DIR)
build: create-bin-dir
@echo "Building $(BINARY)..."
@CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO_BUILD) -o $(BIN_DIR)/$(BINARY)
compress:
@echo "Compressing $(BINARY)..."
ifeq ($(GOOS),windows)
@$(COMPRESS_CMD) $(COMPRESSED_BINARY) $(BIN_DIR)/$(BINARY) $(RESOURCES)
else
@$(COMPRESS_CMD) $(COMPRESSED_BINARY) -C $(BIN_DIR)/ $(BINARY) -C ../ $(RESOURCES)
endif
clean:
@echo "Cleaning up..."
@rm -rf $(BIN_DIR)/$(BINARY_NAME)-*
@rm -rf $(BIN_DIR)/$(BINARY_NAME)-*.tar.gz $(BIN_DIR)/$(BINARY_NAME)-*.zip
build-windows:
$(MAKE) build GOOS=windows GOARCH=amd64
build-windows-arm64:
$(MAKE) build GOOS=windows GOARCH=arm64
build-linux:
$(MAKE) build GOOS=linux GOARCH=amd64
build-linux-arm64:
$(MAKE) build GOOS=linux GOARCH=arm64
build-darwin:
$(MAKE) build GOOS=darwin GOARCH=amd64
build-darwin-arm64:
$(MAKE) build GOOS=darwin GOARCH=arm64
build-all: build-windows build-windows-arm64 build-linux build-linux-arm64 build-darwin build-darwin-arm64
$(MAKE) compress-windows
$(MAKE) compress-windows-arm64
$(MAKE) compress-linux
$(MAKE) compress-linux-arm64
$(MAKE) compress-darwin
$(MAKE) compress-darwin-arm64
compress-windows:
@$(MAKE) compress GOOS=windows GOARCH=amd64
compress-windows-arm64:
@$(MAKE) compress GOOS=windows GOARCH=arm64
compress-linux:
@$(MAKE) compress GOOS=linux GOARCH=amd64
compress-linux-arm64:
@$(MAKE) compress GOOS=linux GOARCH=arm64
compress-darwin:
@$(MAKE) compress GOOS=darwin GOARCH=amd64
compress-darwin-arm64:
@$(MAKE) compress GOOS=darwin GOARCH=arm64
.PHONY: all build clean build-windows build-windows-arm64 build-linux build-linux-arm64 build-darwin build-darwin-arm64 build-all compress compress-windows compress-windows-arm64 compress-linux compress-linux-arm64 compress-darwin compress-darwin-arm64 create-bin-dir