-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
146 lines (117 loc) · 4.02 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
# Small make tasks for go
.PHONY: test
# More tools:
# https://github.com/kisielk/godepgraph
USER=geolffreym
PACKAGE=p2p-noise
VERSION=0.1.0
INPUT=./examples/pingpong
BINARY=main
BINARY_WIN=${BINARY}-win
BINARY_OSX=${BINARY}-darwin
BINARY_LINUX=${BINARY}-linux
ARCH_64=amd64
ARCH_32=386
LINUX_64=${BINARY_LINUX}-${ARCH_64}
LINUX_32=${BINARY_LINUX}-${ARCH_32}
WIN_64=${BINARY_WIN}-${ARCH_64}
WIN_32=${BINARY_WIN}-${ARCH_32}
OSX_64=${BINARY_LINUX}-${ARCH_64}
# -count 1 idiomatic no cached testing
# -race test race condition for routines
# @ = dont echo the output
.PHONY: test ## run tests
test:
@go test -v ./... -count 1 -race -covermode=atomic
@echo "[OK] test finished"
# Could be compared using
# make benchmark > a.old
# make benchmark > b.new
# benchcmp a.old b.new
.PHONY: benchmark ## run benchmark tests
benchmark:
@perflock -governor=80% go test -run=^Benchmarck$ -benchtime 1s -bench=. -count=1
@echo "[OK] benchmark finished"
# View standard output profiling:
# go tool pprof -top cpu.prof
# For memory profiling type use:
# inuse_space Display in-use memory size
# inuse_objects Display in-use object counts
# alloc_space Display allocated memory size
# alloc_objects Display allocated object counts
# eg. go tool pprof --alloc_space -top prof.mem
# For fancy visualization:
# Could use Graphviz (https://graphviz.org/download/)
# eg. go tool pprof -web bin/main-linux-amd64 cpu.prof
.PHONY: profiling ## run profiling tests
profiling:
@perflock -governor=80% go test -run=^Benchmarck$ -benchmem -benchtime 1s -bench=. -cpu 1,2,4,8 -count=1 -memprofile mem.prof -cpuprofile cpu.prof
@echo "[OK] profiling finished"
.PHONY: coverage ## run tests coverage
coverage:
@go test -v ./... -race -covermode=atomic -coverprofile coverage ./...
@echo "[OK] coverage finished"
.PHONY: coverage-export ## run tests coverage export
coverage-export: coverage
@go tool cover -html=coverage
@echo "[OK] code test coverage finished"
# Allow to preview documentation.
# Please verify your GOPATH before run this command
.PHONY: preview-doc ## run local documentation server
preview-doc:
@godoc -http=localhost:6060 -links=true
.PHONY: build ## compiles the command into and executable
build:
@go build -v ./...
.PHONY: format ## automatically formats Go source cod
format:
@go fmt ./...
@goimports -w .
@echo "[OK] code format finished"
.PHONY: check ## examines Go source code and reports suspicious constructs
check:
@go vet -v ./...
@echo "[OK] code check finished"
.PHONY: clean ## removes generated files and clean go cache
clean:
@go clean --cache ./...
@rm -f mem.prof
@rm -f prof.mem
@rm -rf bin
@echo "[OK] cleaned"
.PHONY: compile-win ## compiles window exec
compile-win:
@GOOS=windows GOARCH=amd64 go build -o bin/${WIN_64} ${INPUT}
@GOOS=windows GOARCH=386 go build -o bin/${WIN_32} ${INPUT}
#Go1.15 deprecates 32-bit macOS builds
# go build -x to show compilation details
#GOOS=darwin GOARCH=386 go build -o bin/main-mac-386 main.go
.PHONY: compile-mac ## compiles mac exec
compile-mac:
@GOOS=darwin GOARCH=amd64 go build -o bin/${OSX_64} ${INPUT}
.PHONY: compile-linux ## compiles linux exec
compile-linux:
@GOOS=linux GOARCH=amd64 go build -o bin/${LINUX_64} ${INPUT}
@GOOS=linux GOARCH=386 go build -o bin/${LINUX_32} ${INPUT}
.PHONY: compile ## compiles all os exec
compile: compile-linux compile-win compile-mac
@echo "[OK] Compiling for every OS and Platform"
.PHONY: run ## compiles and runs the named main Go package
run:
@go run ${INPUT} $(filter-out $@,$(MAKECMDGOALS))
.PHONY: update-pkg-cache ## updated the package cache version
update-pkg-cache:
GOPROXY=https://proxy.golang.org GO111MODULE=on \
go get github.com/${USER}/${PACKAGE}@v${VERSION}
# https://go.dev/ref/mod#go-mod-vendor
.PHONY: vendorize ## lock dependencies
vendorize:
@go mod vendor
@echo "[OK]"
all: build test check-test-coverage code-check compile
.PHONY: help ## display this message
help:
@grep -E \
'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
sort | \
awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-19s\033[0m %s\n", $$2, $$3}'