-
Notifications
You must be signed in to change notification settings - Fork 66
/
Makefile
57 lines (48 loc) · 1.56 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
.PHONY: help print build test cover clean distclean package
BOLD = \033[1m
UNDERLINE = \033[4m
BLUE = \033[36m
RESET = \033[0m
VERSION := $(shell git describe --tags --always --dirty="-dev")
DATE := $(shell date -u '+%Y-%m-%d-%H%M UTC')
ARCHS ?= amd64 arm64
Q ?= @
## Show usage information for this Makefile
help:
@printf "$(BOLD)chl-byp-srv$(RESET)\n\n"
@printf "$(UNDERLINE)Available Tasks$(RESET)\n\n"
@awk -F \
':|##' '/^##/ {c=$$2; getline; printf "$(BLUE)%10s$(RESET) %s\n", $$1, c}' \
$(MAKEFILE_LIST)
@printf "\n"
## print command
print-command:
$Q@printf "GOARCH=$(ARCH) CGO_ENABLED=1 go build -ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"' -o bin/chl-byp-srv ./server"
## Build executable
build:
$Q# ARCH is set from `package`.
$Q# Alternatively, run `make ARCH=<amd64|arm64> build` to override here.
$QGOARCH=$(ARCH) CGO_ENABLED=1 go build \
-ldflags='-X "main.Version=$(VERSION)" -X "main.BuildTime=$(DATE)"' \
-o bin/chl-byp-srv \
./server
## Run tests
test: build
PATH="${PATH}:${PWD}/bin" && GOCACHE=off && go test -v -race ./...
## Generate cover report
cover:
$Qmkdir -p .cover
$Qrm -f .cover/*.out .cover/all.merged .cover/all.html
$Qfor pkg in $$(go list ./...); do \
go test -coverprofile=.cover/`echo $$pkg|tr "/" "_"`.out $$pkg; \
done
$Qecho 'mode: set' > .cover/all.merged
$Qgrep -h -v "mode: set" .cover/*.out >> .cover/all.merged
ifndef CI
$Qgo tool cover -html .cover/all.merged
else
$Qgo tool cover -html .cover/all.merged -o .cover/all.html
endif
## Clean build files
clean:
$Qrm -rf bin