-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
254 lines (204 loc) · 7.2 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# ==============================================================================
# define the default goal
#
.DEFAULT_GOAL := help
## all: Run tidy, gen, add-copyright, format, lint, cover, build ✨
.PHONY: all
all: tidy gen add-copyright format lint cover
# ==============================================================================
# Build set
#ROOT_PACKAGE=github.com/OpenIMSDK/Open-IM-Server
## TODO: This is version control for the future
#VERSION_PACKAGE=github.com/OpenIMSDK/Open-IM-Server/pkg/version
# ==============================================================================
# Includes
#include scripts/make-rules/common.mk # make sure include common.mk at the first include line
#include scripts/make-rules/golang.mk
#include scripts/make-rules/image.mk
#include scripts/make-rules/copyright.mk
#include scripts/make-rules/gen.mk
#include scripts/make-rules/dependencies.mk
#include scripts/make-rules/tools.mk
#include scripts/make-rules/release.mk
#include scripts/make-rules/swagger.mk
# ==============================================================================
# Usage
#define USAGE_OPTIONS
#
#Options:
#
# DEBUG Whether or not to generate debug symbols. Default is 0.
#
# BINS Binaries to build. Default is all binaries under cmd.
# This option is available when using: make {build}(.multiarch)
# Example: make build BINS="openim-api openim-cmdutils".
#
# PLATFORMS Platform to build for. Default is linux_arm64 and linux_amd64.
# This option is available when using: make {build}.multiarch
# Example: make multiarch PLATFORMS="linux_s390x linux_mips64
# linux_mips64le darwin_amd64 windows_amd64 linux_amd64 linux_arm64".
#
# V Set to 1 enable verbose build. Default is 0.
#endef
#export USAGE_OPTIONS
OS:= $(or $(os),linux)
ARCH:=$(or $(arch),amd64)
NOW=`date "+%Y-%m-%d %H:%M:%S"`
GO ?= go
# ==============================================================================
# Targets
## multiarch: Build binaries for multiple platforms. See option PLATFORMS. ✨
.PHONY: multiarch
multiarch:
@$(MAKE) go.build.multiarch
## tidy: tidy go.mod ✨
.PHONY: tidy
tidy:
@$(GO) mod tidy
## vendor: vendor go.mod ✨
.PHONY: vendor
vendor:
@$(GO) mod vendor
## style: code style -> fmt,vet,lint ✨
.PHONY: style
style: fmt vet lint
## fmt: Run go fmt against code. ✨
.PHONY: fmt
fmt:
@$(GO) fmt ./...
## vet: Run go vet against code. ✨
.PHONY: vet
vet:
@$(GO) vet ./...
## lint: Check syntax and styling of go sources. ✨
.PHONY: lint
lint:
@$(MAKE) go.lint
## format: Gofmt (reformat) package sources (exclude vendor dir if existed). ✨
.PHONY: format
format:
@$(MAKE) go.format
## test: Run unit test. ✨
.PHONY: test
test:
@$(MAKE) go.test
## cover: Run unit test and get test coverage. ✨
.PHONY: cover
cover:
@$(MAKE) go.test.cover
## updates: Check for updates to go.mod dependencies. ✨
.PHONY: updates
@$(MAKE) go.updates
## imports: task to automatically handle import packages in Go files using goimports tool. ✨
.PHONY: imports
imports:
@$(MAKE) go.imports
## clean: Remove all files that are created by building. ✨
#.PHONY: clean
#clean:
# @$(MAKE) go.clean
## image: Build docker images for host arch. ✨
.PHONY: image
image:
@$(MAKE) image.build
## image.multiarch: Build docker images for multiple platforms. See option PLATFORMS. ✨
.PHONY: image.multiarch
image.multiarch:
@$(MAKE) image.build.multiarch
## push: Build docker images for host arch and push images to registry. ✨
#.PHONY: push
#push:
# @$(MAKE) image.push
## push.multiarch: Build docker images for multiple platforms and push images to registry. ✨
.PHONY: push.multiarch
push.multiarch:
@$(MAKE) image.push.multiarch
## tools: Install dependent tools. ✨
.PHONY: tools
tools:
@$(MAKE) tools.install
## gen: Generate all necessary files. ✨
.PHONY: gen
gen:
@$(MAKE) gen.run
## swagger: Generate swagger document. ✨
.PHONY: swagger
swagger:
@$(MAKE) swagger.run
## serve-swagger: Serve swagger spec and docs. ✨
.PHONY: swagger.serve
serve-swagger:
@$(MAKE) swagger.serve
## verify-copyright: Verify the license headers for all files. ✨
#.PHONY: verify-copyright
#verify-copyright:
# @$(MAKE) copyright.verify
## add-copyright: Add copyright ensure source code files have license headers. ✨
#.PHONY: add-copyright
#add-copyright:
# @$(MAKE) copyright.add
## release: release the project ✨
#.PHONY: release
#release: release.verify release.ensure-tag
# @scripts/release.sh
## help: Show this help info. ✨
#.PHONY: help
#help: Makefile
# $(call makehelp)
## help-all: Show all help details info. ✨
#.PHONY: help-all
#help-all: go.help copyright.help tools.help image.help dependencies.help gen.help release.help swagger.help help
# $(call makeallhelp)
.PHONY:api
api:
@echo "${NOW} Starting to build api..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-api cmd/openim-api/main.go
.PHONY:gateway
gateway:
@echo "${NOW} Starting to build gateway..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-msg-gateway cmd/openim-msggateway/main.go
.PHONY:transfer
transfer:
@echo "${NOW} Starting to build transfer..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-msgtransfer cmd/openim-msgtransfer/main.go
.PHONY:push
push:
@echo "${NOW} Starting to build push..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-push cmd/openim-push/main.go
.PHONY:group
group:
@echo "${NOW} Starting to build rpc_group..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-group cmd/openim-rpc/openim-rpc-group/main.go
.PHONY:msg
msg:
@echo "${NOW} Starting to build rpc_msg..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-msg cmd/openim-rpc/openim-rpc-msg/main.go
.PHONY:user
user:
@echo "${NOW} Starting to build rpc_user..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-user cmd/openim-rpc/openim-rpc-user/main.go
.PHONY:conversation
conversation:
@echo "${NOW} Starting to build rpc_conversation..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-conversation cmd/openim-rpc/openim-rpc-conversation/main.go
.PHONY:friend
friend:
@echo "${NOW} Starting to build rpc_conversation..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-friend cmd/openim-rpc/openim-rpc-friend/main.go
.PHONY:third
third:
@echo "${NOW} Starting to build rpc_conversation..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-third cmd/openim-rpc/openim-rpc-third/main.go
.PHONY:auth
auth:
@echo "${NOW} Starting to build rpc_conversation..."
CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH};go build -ldflags="-w -s" -o ./bin/openim-rpc-auth cmd/openim-rpc/openim-rpc-auth/main.go
.PHONY:build
build: api gateway transfer push group msg user conversation friend third auth
@echo "${NOW} Build done, files in ./bin as follow:"
@ls -l bin | grep openim-
.PHONY:clean
clean:
@echo "${NOW} Starting to clean ..."
rm -rf bin/openim-* && rm -rf logs
@echo "${NOW} Clean done!"