-
Notifications
You must be signed in to change notification settings - Fork 62
/
Makefile
305 lines (279 loc) · 7.21 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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# =====================================================================
# This file was autogenerated. Do not edit it manually!
# save all your custom variables and targets in Makefile.expansion!
# =====================================================================
#
# Old-skool build tools.
#
# Commonly used targets (see each target for more information):
# all: Build code.
# test: Run tests.
# clean: Clean up.
#
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /bin/bash
# Default target
.DEFAULT_GOAL := all
# We don't need make's built-in rules.
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
# Constants used throughout.
.EXPORT_ALL_VARIABLES:
# This controls the verbosity of the build. Higher numbers mean more output.
VERBOSE ?= 1
# enable go module
GO111MODULE := on
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
MYBUILD="hack/make-rules/build.sh"
define command_exists
@$(shell command -v $(1) >/dev/null 2>&1)
endef
# user defined Makefile to expands targets
-include Makefile.expansion
.PHONY: make-rules
make-rules:
ifeq (, $(shell command -v make-rules))
@cd $(shell mktemp -d) && go get -v github.com/zoumo/make-rules/cmd/[email protected]
MYMAKE=$(GOBIN)/make-rules
else
MYMAKE=$(shell command -v make-rules)
endif
define ALL_HELP_INFO
# Build code.
# make all == make build
#
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under bin/.
# If not specified, "everything" will be built.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
# make
# make all or make build
# make build WHAT=cmd/server GOFLAGS=-v
# make all GOGCFLAGS="-N -l"
# Note: Use the -N -l options to disable compiler optimizations an inlining.
# Using these build options allows you to subsequently use source
# debugging tools like delve.
endef
.PHONY: all build
ifeq ($(HELP),y)
all build:
@echo "$$ALL_HELP_INFO"
else
all build: make-rules
@$(MYBUILD) $(WHAT)
endif
define GO_BUILD_HELP_INFO
# Build code.
#
# Args:
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
# make $(1)
# make $(1) GOFLAGS=-v
# make $(1) GOGCFLAGS="-N -l"
# Note: Use the -N -l options to disable compiler optimizations an inlining.
# Using these build options allows you to subsequently use source
# debugging tools like delve.
endef
.PHONY: $(GO_BUILD_TARGETS)
ifeq ($(HELP),y)
$(GO_BUILD_TARGETS):
$(call GO_BUILD_HELP_INFO, $@)
else
$(GO_BUILD_TARGETS): make-rules
@$(MYBUILD) $@
endif
define UNITTEST_HELP_INFO
# Run uniitest
#
# Args:
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
# make
# make unittest
# make unittest GOFLAGS="-v -x"
# make unittest GOGCFLAGS="-N -l"
# Note: Use the -N -l options to disable compiler optimizations an inlining.
# Using these build options allows you to subsequently use source
# debugging tools like delve.
endef
.PHONY: unittest
ifeq ($(HELP),y)
unittest:
@echo "$$UNITTEST_HELP_INFO"
else
unittest: make-rules
@$(MYMAKE) go unittest
endif
define BUILD_LOCAL_HELP_INFO
# Build code on local.
#
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under bin/.
# If not specified, "everything" will be built.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
# make
# make build-local
# make build-local WHAT=cmd/server GOFLAGS=-v
# make build-local GOGCFLAGS="-N -l"
# Note: Use the -N -l options to disable compiler optimizations an inlining.
# Using these build options allows you to subsequently use source
# debugging tools like delve.
endef
.PHONY: build-local
ifeq ($(HELP),y)
build-local:
@echo "$$BUILD_LOCAL_HELP_INFO"
else
build-local: make-rules
@$(MYBUILD) $(WHAT)
endif
define BUILD_IN_CONTAINER_HELP_INFO
# Build code in container.
#
# Args:
# WHAT: Directory names to build. If any of these directories has a 'main'
# package, the build will produce executable files under bin/.
# If not specified, "everything" will be built.
# GOFLAGS: Extra flags to pass to 'go' when building.
# GOLDFLAGS: Extra linking flags passed to 'go' when building.
# GOGCFLAGS: Additional go compile flags passed to 'go' when building.
#
# Example:
# make
# make build-in-container
# make build-in-container WHAT=cmd/server GOFLAGS=-v
# make build-in-container GOGCFLAGS="-N -l"
# Note: Use the -N -l options to disable compiler optimizations an inlining.
# Using these build options allows you to subsequently use source
# debugging tools like delve.
endef
.PHONY: build-in-container
ifeq ($(HELP),y)
build-in-container:
@echo "$$BUILD_LINUX_HELP_INFO"
else
build-in-container: make-rules
@$(MYBUILD) $(WHAT)
endif
define CONTAINER_HELP_INFO
# Build container image.
#
# Args:
# WHAT: Directories containing Dockerfile.
#
# Example:
# make container
# make container WHAT=build/server
endef
.PHONY: container
ifeq ($(HELP),y)
container:
@echo "$$CONTAINER_HELP_INFO"
else
container: make-rules
@$(MYMAKE) container build --version="$(VERSION)" --v="$(VERBOSE)" $(WHAT)
endif
define DOCKER_BUILD_HELP_INFO
# Build container image.
#
# Example:
# make $(1)
endef
.PHONY: $(DOCKER_BUILD_TARGETS)
ifeq ($(HELP),y)
$(DOCKER_BUILD_TARGETS):
$(call DOCKER_BUILD_HELP_INFO, $@)
else
$(DOCKER_BUILD_TARGETS): make-rules
@$(MYMAKE) container build --version="$(VERSION)" --v="$(VERBOSE)" $@
endif
define PUSH_HELP_INFO
# Push container image.
# You should run make container before push
#
# Args:
# WHAT: Directory names containing Dockerfile.
#
# Example:
# make push
# make push WHAT=build/server
endef
.PHONY: push
ifeq ($(HELP),y)
push:
@echo "$$PUSH_HELP_INFO"
else
push: make-rules
@$(MYMAKE) container push --version="$(VERSION)" --v="$(VERBOSE)" $(WHAT)
endif
define CLEAN_HELP_INFO
# Remove all output binaries.
#
# Example:
# make clean
#
endef
.PHONY: clean
ifeq ($(HELP),y)
clean:
@echo "$$CLEAN_HELP_INFO"
else
clean:
@rm -rf bin/
@rm -rf output/
endif
define FORMAT_HELP_INFO
# Format go file
#
# Example:
# make format
#
endef
.PHONY: format
ifeq ($(HELP),y)
format:
@echo "$$FORMAT_HELP_INFO"
else
format:
@$(MYMAKE) go format
endif
define UPDATE_GOMOD_HELP_INFO
# Update go.mod
#
# Example:
# make update-gomod
#
endef
.PHONY: update-gomod
ifeq ($(HELP),y)
update-gomod:
@echo "$$UPDATE_GOMOD_HELP_INFO"
else
update-gomod:
@$(MYMAKE) go mod update
endif
.PHONY: debug-makefile
debug-makefile:
env