-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
91 lines (75 loc) · 2.88 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
default: help
HOST_GOLANG_VERSION := $(shell go version | cut -d ' ' -f3 | cut -c 3-)
MODULE := redis-trib
ifneq (,$(wildcard .git/.*))
COMMIT = $(shell git rev-parse HEAD 2> /dev/null || true)
VERSION = $(shell git describe --tags --abbrev=0 2> /dev/null)
else
COMMIT = "unknown"
VERSION = "unknown"
endif
#Replaces ":" (*nix), ";" (windows) with newline for easy parsing
GOPATHS=$(shell echo ${GOPATH} | tr ":" "\n" | tr ";" "\n")
# See Golang issue re: '-trimpath': https://github.com/golang/go/issues/13809
GO_GCFLAGS=$(shell \
set -- ${GOPATHS}; \
echo "-gcflags=-trimpath=$${1}"; \
)
GO_ASMFLAGS=$(shell \
set -- ${GOPATHS}; \
echo "-asmflags=-trimpath=$${1}"; \
)
#export GOPATH := $(shell cd ./ && pwd)/vendor:$(GOPATH)
## Make bin for $MODULE.
bin:
@echo "GOVERSION: ${HOST_GOLANG_VERSION}"
@echo "GOPATH:" $$GOPATH
go build ${GO_GCFLAGS} ${GO_ASMFLAGS} -i -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o ${MODULE} .
## Build debug trace for $MODULE.
debug:
@echo "GOVERSION: ${HOST_GOLANG_VERSION}"
@echo "GOPATH:" $$GOPATH
go build -n -v -i -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o ${MODULE} .
## Make static link bin for $MODULE.
static-bin:
@echo "GOVERSION:" ${HOST_GOLANG_VERSION}
@echo "GOPATH:" $$GOPATH
go build ${GO_GCFLAGS} ${GO_ASMFLAGS} -i -ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o ${MODULE} .
## Get dep tool for managing dependencies for Go projects.
dep:
go get -u github.com/golang/dep/cmd/dep
## Get dep tool and init project.
depinit: dep
dep init
dep ensure
## Get vet go tools.
vet:
go get golang.org/x/tools/cmd/vet
## Validate this go project.
validate:
script/validate-gofmt
#go vet ./...
## Run test case for this go project.
test:
go test $(go list ./... | grep -v '/vendor/')
## Clean everything (including stray volumes).
clean:
# find . -name '*.created' -exec rm -f {} +
-rm -rf var
-rm -f ${MODULE}
help: # Some kind of magic from https://gist.github.com/rcmachado/af3db315e31383502660
$(info Available targets)
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
nb = sub( /^## /, "", helpMsg ); \
if(nb == 0) { \
helpMsg = $$0; \
nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
} \
if (nb) { \
h = sub( /[^ ]*MODULE/, "'${MODULE}'", helpMsg ); \
printf " \033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
} \
} \
{ helpMsg = $$0 }' \
width=$$(grep -o '^[a-zA-Z_0-9]\+:' $(MAKEFILE_LIST) | wc -L 2> /dev/null) \
$(MAKEFILE_LIST)