-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
138 lines (107 loc) · 4.5 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
.PHONY: test check clean build dist all
TOP_DIR := $(shell pwd)
# ifeq ($(FILE), $(wildcard $(FILE)))
# @ echo target file not found
# endif
DIST_VERSION := v1.0.0
# linux windows darwin list as: go tool dist list
DIST_OS := linux
# amd64 386
DIST_ARCH := amd64
DIST_OS_DOCKER ?= linux
DIST_ARCH_DOCKER ?= amd64
ROOT_NAME ?= zlog
# ignore used not matching mode
ROOT_TEST_INVERT_MATCH ?= "vendor"
# set ignore of test case like grep -v -E "vendor|fataloom" to ignore vendor and fataloom package
ROOT_TEST_LIST ?= $$(go list ./... | grep -v -E $(ROOT_TEST_INVERT_MATCH))
# test max time
ROOT_TEST_MAX_TIME := 1m
ROOT_BUILD_PATH ?= ./build
ROOT_DIST ?= ./dist
ROOT_REPO ?= ./dist
ROOT_LOG_PATH ?= ./log
ROOT_TEST_BUILD_PATH ?= $(ROOT_BUILD_PATH)/test/$(DIST_VERSION)
ROOT_TEST_DIST_PATH ?= $(ROOT_DIST)/test/$(DIST_VERSION)
ROOT_TEST_OS_DIST_PATH ?= $(ROOT_DIST)/$(DIST_OS)/test/$(DIST_VERSION)
ROOT_REPO_DIST_PATH ?= $(ROOT_REPO)/$(DIST_VERSION)
ROOT_REPO_OS_DIST_PATH ?= $(ROOT_REPO)/$(DIST_OS)/release/$(DIST_VERSION)
# change this for ip-v4 get
ROOT_LOCAL_IP_V4_LINUX = $$(ifconfig enp8s0 | grep inet | grep -v inet6 | cut -d ':' -f2 | cut -d ' ' -f1)
ROOT_LOCAL_IP_V4_DARWIN = $$(ifconfig en0 | grep inet | grep -v inet6 | cut -d ' ' -f2)
# can use as https://goproxy.io/ https://gocenter.io https://mirrors.aliyun.com/goproxy/
ENV_GO_PROXY ?= https://goproxy.cn/
# include MakeDockerRun.mk for docker run
include MakeGoMod.mk
include MakeDockerRun.mk
include MakeGoTravis.mk
checkEnvGOPATH:
ifndef GOPATH
@echo Environment variable GOPATH is not set
exit 1
endif
cleanBuild:
@if [ -d ${ROOT_BUILD_PATH} ]; then rm -rf ${ROOT_BUILD_PATH} && echo "~> cleaned ${ROOT_BUILD_PATH}"; else echo "~> has cleaned ${ROOT_BUILD_PATH}"; fi
cleanDist:
@if [ -d ${ROOT_DIST} ]; then rm -rf ${ROOT_DIST} && echo "~> cleaned ${ROOT_DIST}"; else echo "~> has cleaned ${ROOT_DIST}"; fi
cleanLog:
@if [ -d ${ROOT_LOG_PATH} ]; then rm -rf ${ROOT_LOG_PATH} && echo "~> cleaned ${ROOT_LOG_PATH}"; else echo "~> has cleaned ${ROOT_LOG_PATH}"; fi
clean: cleanBuild cleanLog
@echo "~> clean finish"
checkTestBuildPath:
@if [ ! -d ${ROOT_TEST_BUILD_PATH} ]; then mkdir -p ${ROOT_TEST_BUILD_PATH} && echo "~> mkdir ${ROOT_TEST_BUILD_PATH}"; fi
checkTestDistPath:
@if [ ! -d ${ROOT_TEST_DIST_PATH} ]; then mkdir -p ${ROOT_TEST_DIST_PATH} && echo "~> mkdir ${ROOT_TEST_DIST_PATH}"; fi
checkTestOSDistPath:
@if [ ! -d ${ROOT_TEST_OS_DIST_PATH} ]; then mkdir -p ${ROOT_TEST_OS_DIST_PATH} && echo "~> mkdir ${ROOT_TEST_OS_DIST_PATH}"; fi
checkReleaseDistPath:
@if [ ! -d ${ROOT_REPO_DIST_PATH} ]; then mkdir -p ${ROOT_REPO_DIST_PATH} && echo "~> mkdir ${ROOT_REPO_DIST_PATH}"; fi
checkReleaseOSDistPath:
@if [ ! -d ${ROOT_REPO_OS_DIST_PATH} ]; then mkdir -p ${ROOT_REPO_OS_DIST_PATH} && echo "~> mkdir ${ROOT_REPO_OS_DIST_PATH}"; fi
init:
@echo "~> start init this project"
@echo "-> check version"
go version
@echo "-> check env golang"
go env
@echo "~> you can use [ make help ] see more task"
-GOPROXY="$(ENV_GO_PROXY)" GO111MODULE=on go mod vendor
buildMain:
@echo "-> start build local OS"
@go build -o build/main main.go
buildARCH:
@echo "-> start build OS:$(DIST_OS) ARCH:$(DIST_ARCH)"
@GOOS=$(DIST_OS) GOARCH=$(DIST_ARCH) go build -o build/main main.go
dev: buildMain
-ENV_WEB_AUTO_HOST=true ./build/main
run: dev
@echo "=> run start"
test:
@echo "=> run test start"
#=> go test -test.v $(ROOT_TEST_LIST)
@go test -test.v $(ROOT_TEST_LIST)
testBenchmem:
@echo "=> run test benchmem start"
@go test -test.benchmem
localIPLinux:
@echo "=> now run as docker with linux"
@echo "local ip address is: $(ROOT_LOCAL_IP_V4_LINUX)"
localIPDarwin:
@echo "=> now run as docker with darwin"
@echo "local ip address is: $(ROOT_LOCAL_IP_V4_DARWIN)"
cloc:
# https://stackoverflow.com/questions/26152014/cloc-ignore-exclude-list-file-clocignore
cloc --exclude-list-file=.clocignore .
helpProjectRoot:
@echo "Help: Project root Makefile"
@echo "-- now build name: $(ROOT_NAME) version: $(DIST_VERSION)"
@echo "-- distTestOS or distReleaseOS will out abi as: $(DIST_OS) $(DIST_ARCH) --"
@echo ""
@echo "~> make init - check base env of this project"
@echo "~> make clean - remove binary file and log files"
@echo "~> make test - run test case ignore --invert-match $(ROOT_TEST_INVERT_MATCH)"
@echo "~> make testBenchmem - run go test benchmem case all"
@echo "~> make dev - run as develop"
help: helpGoMod helpDockerRun helpGoTravis helpProjectRoot
@echo ""
@echo "-- more info see Makefile include: MakeGoMod.mk MakeDockerRun.mk --"