1.PHONY: default install build test quicktest fmt vet lint 2 3# List of all release tags "supported" by our current Go version 4# E.g. ":go1.1:go1.2:go1.3:go1.4:go1.5:go1.6:go1.7:go1.8:go1.9:go1.10:go1.11:go1.12:" 5GO_RELEASE_TAGS := $(shell go list -f ':{{join (context.ReleaseTags) ":"}}:' runtime) 6 7# Only use the `-race` flag on newer versions of Go (version 1.3 and newer) 8ifeq (,$(findstring :go1.3:,$(GO_RELEASE_TAGS))) 9 RACE_FLAG := 10else 11 RACE_FLAG := -race -cpu 1,2,4 12endif 13 14# Run `go vet` on Go 1.12 and newer. For Go 1.5-1.11, use `go tool vet` 15ifneq (,$(findstring :go1.12:,$(GO_RELEASE_TAGS))) 16 GO_VET := go vet \ 17 -atomic \ 18 -bool \ 19 -copylocks \ 20 -nilfunc \ 21 -printf \ 22 -rangeloops \ 23 -unreachable \ 24 -unsafeptr \ 25 -unusedresult \ 26 . 27else ifneq (,$(findstring :go1.5:,$(GO_RELEASE_TAGS))) 28 GO_VET := go tool vet \ 29 -atomic \ 30 -bool \ 31 -copylocks \ 32 -nilfunc \ 33 -printf \ 34 -shadow \ 35 -rangeloops \ 36 -unreachable \ 37 -unsafeptr \ 38 -unusedresult \ 39 . 40else 41 GO_VET := @echo "go vet skipped -- not supported on this version of Go" 42endif 43 44default: fmt vet lint build quicktest 45 46install: 47 go get -t -v ./... 48 49build: 50 go build -v ./... 51 52test: 53 go test -v $(RACE_FLAG) -cover ./... 54 55quicktest: 56 go test ./... 57 58# Capture output and force failure when there is non-empty output 59fmt: 60 @echo gofmt -l . 61 @OUTPUT=`gofmt -l . 2>&1`; \ 62 if [ "$$OUTPUT" ]; then \ 63 echo "gofmt must be run on the following files:"; \ 64 echo "$$OUTPUT"; \ 65 exit 1; \ 66 fi 67 68vet: 69 $(GO_VET) 70 71# https://github.com/golang/lint 72# go get github.com/golang/lint/golint 73# Capture output and force failure when there is non-empty output 74# Only run on go1.5+ 75lint: 76 @echo golint ./... 77 @OUTPUT=`command -v golint >/dev/null 2>&1 && golint ./... 2>&1`; \ 78 if [ "$$OUTPUT" ]; then \ 79 echo "golint errors:"; \ 80 echo "$$OUTPUT"; \ 81 exit 1; \ 82 fi 83