-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
125 lines (92 loc) · 3.63 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
# 默认执行 all 目标
.DEFAULT_GOAL := all
# ==============================================================================
# 定义 Makefile all 伪目标,执行 `make` 时,会默认会执行 all 伪目标
.PHONY: all
all: gen.add-copyright go.format go.build
# ==============================================================================
# Includes
# 确保 `include common.mk` 位于第一行,common.mk 中定义了一些变量,后面的子 makefile 有依赖
include scripts/make-rules/common.mk
include scripts/make-rules/tools.mk
include scripts/make-rules/golang.mk
include scripts/make-rules/generate.mk
include scripts/make-rules/image.mk
# ==============================================================================
# Usage
define USAGE_OPTIONS
Options:
BINS The binaries to build. Default is all of cmd.
This option is available when using: make build
Example: make build BINS="kingnet test"
IMAGES Backend images to make. Default is all of cmd.
This option is available when using: make image/push
Example: make image IMAGES="kingnet"
VERSION The version information compiled into binaries.
The default is obtained from gsemver or git.
V Set to 1 enable verbose build. Default is 0.
endef
export USAGE_OPTIONS
## --------------------------------------
## Generate / Manifests
## --------------------------------------
##@ generate:
.PHONY: add-copyright
add-copyright: ## 添加版权头信息.
@$(MAKE) gen.add-copyright
.PHONY: deps
deps: ## 安装依赖,例如:生成需要的代码、安装需要的工具等.
@$(MAKE) gen.deps
## --------------------------------------
## Binaries
## --------------------------------------
##@ build:
.PHONY: build
build: go.tidy ## 编译源码,依赖 tidy 目标自动添加/移除依赖包.
@$(MAKE) go.build
.PHONY: image
image: ## 构建 Docker 镜像.
@$(MAKE) image.build
.PHONY: push
push: ## 构建 Docker 镜像,并 push 到镜像仓库.
@$(MAKE) image.push
## --------------------------------------
## Cleanup
## --------------------------------------
##@ clean:
.PHONY: clean
clean: ## 清理构建产物、临时文件等.
@echo "===========> Cleaning all build output"
@-rm -vrf $(OUTPUT_DIR)
## --------------------------------------
## Lint / Verification
## --------------------------------------
##@ lint and verify:
#.PHONY: lint
#lint: ## 执行静态代码检查.
# @$(MAKE) go.lint
## --------------------------------------
## Testing
## --------------------------------------
##@ test:
#.PHONY: test
#test: ## 执行单元测试.
# @$(MAKE) go.test
#
#.PHONY: cover
#cover: ## 执行单元测试,并校验覆盖率阈值.
# @$(MAKE) go.cover
## --------------------------------------
## Hack / Tools
## --------------------------------------
##@ hack/tools:
.PHONY: format
format: ## 格式化 Go 源码.
@$(MAKE) go.format
.PHONY: tidy
tidy: ## 自动添加/移除依赖包.
@$(MAKE) go.tidy
.PHONY: help
help: Makefile ## 打印 Makefile help 信息.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<TARGETS> <OPTIONS>\033[0m\n\n\033[35mTargets:\033[0m\n"} /^[0-9A-Za-z._-]+:.*?##/ { printf " \033[36m%-45s\033[0m %s\n", $$1, $$2 } /^\$$\([0-9A-Za-z_-]+\):.*?##/ { gsub("_","-", $$1); printf " \033[36m%-45s\033[0m %s\n", tolower(substr($$1, 3, length($$1)-7)), $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' Makefile #$(MAKEFILE_LIST)
@echo -e "$$USAGE_OPTIONS"