-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (110 loc) · 3.12 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
# init project path
WORKROOT := $(shell pwd)
OUTDIR := $(WORKROOT)/output
OS := $(shell go env GOOS)
# init environment variables
export PATH := $(shell go env GOPATH)/bin:$(PATH)
export GO111MODULE := on
# init command params
GO := go
GOBUILD := $(GO) build
GOTEST := $(GO) test
GOVET := $(GO) vet
GOGET := $(GO) get
GOGEN := $(GO) generate
GOCLEAN := $(GO) clean
GOINSTALL := $(GO) install
GOFLAGS := -race
STATICCHECK := staticcheck
LICENSEEYE := license-eye
PIP := pip3
PIPINSTALL := $(PIP) install
# init arch
ARCH := $(shell getconf LONG_BIT)
ifeq ($(ARCH),64)
GOTEST += $(GOFLAGS)
endif
# init miniproxy version
M_VERSION ?= $(shell cat VERSION)
# init git commit id
GIT_COMMIT ?= $(shell git rev-parse HEAD)
# init miniproxy packages
M_PKGS := $(shell go list ./...)
# go install package
# $(1) package name
# $(2) package address
define INSTALL_PKG
@echo installing $(1)
$(GOINSTALL) $(2)
@echo $(1) installed
endef
define PIP_INSTALL_PKG
@echo installing $(1)
$(PIPINSTALL) $(1)
@echo $(1) installed
endef
# make, make all
all: prepare compile package
# make, make strip
strip: prepare compile-strip package
# make prepare, download dependencies
prepare: prepare-dep prepare-gen
prepare-dep:
$(call INSTALL_PKG, goyacc, golang.org/x/tools/cmd/goyacc)
# make compile, go build
compile: test build
build:
ifeq ($(OS),darwin)
$(GOBUILD) -ldflags "-X main.version=$(M_VERSION) -X main.commit=$(GIT_COMMIT)"
else
$(GOBUILD) -ldflags "-X main.version=$(M_VERSION) -X main.commit=$(GIT_COMMIT) -extldflags=-static"
endif
# make compile-strip, go build without symbols and DWARFs
compile-strip: test build-strip
build-strip:
ifeq ($(OS),darwin)
$(GOBUILD) -ldflags "-X main.version=$(M_VERSION) -X main.commit=$(GIT_COMMIT) -s -w"
else
$(GOBUILD) -ldflags "-X main.version=$(M_VERSION) -X main.commit=$(GIT_COMMIT) -extldflags=-static -s -w"
endif
# make test, test your code
test: test-case vet-case
test-case:
$(GOTEST) -cover ./...
vet-case:
${GOVET} ./...
# make coverage for codecov
coverage:
echo -n > coverage.txt
for pkg in $(M_PKGS) ; do $(GOTEST) -coverprofile=profile.out -covermode=atomic $${pkg} && cat profile.out >> coverage.txt; done
# make package
package:
mkdir -p $(OUTDIR)/bin
mv miniproxy $(OUTDIR)/bin
cp -r conf $(OUTDIR)
# make deps
deps:
$(call PIP_INSTALL_PKG, pre-commit)
$(call INSTALL_PKG, goyacc, golang.org/x/tools/cmd/goyacc)
$(call INSTALL_PKG, staticcheck, honnef.co/go/tools/cmd/staticcheck)
$(call INSTALL_PKG, license-eye, github.com/apache/skywalking-eyes/cmd/license-eye@latest)
# make precommit, enable autoupdate and install with hooks
precommit:
pre-commit autoupdate
pre-commit install --install-hooks
# make check
check:
$(STATICCHECK) ./...
# make license-check, check code file's license declaration
license-check:
$(LICENSEEYE) header check
# make license-fix, fix code file's license declaration
license-fix:
$(LICENSEEYE) header fix
# make clean
clean:
$(GOCLEAN)
rm -rf $(OUTDIR)
rm -rf $(GOPATH)/pkg/linux_amd64
# avoid filename conflict and speed up build
.PHONY: all prepare compile test package clean build