github.com/amimof/huego@v1.2.1/Makefile (about) 1 MODULE = $(shell env GO111MODULE=on $(GO) list -m) 2 DATE ?= $(shell date +%FT%T%z) 3 VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \ 4 cat $(CURDIR)/.version 2> /dev/null || echo v0) 5 COMMIT=$(shell git rev-parse HEAD) 6 BRANCH=$(shell git rev-parse --abbrev-ref HEAD) 7 GOVERSION=$(shell go version | awk -F\go '{print $$3}' | awk '{print $$1}') 8 PKGS = $(or $(PKG),$(shell env GO111MODULE=on $(GO) list ./...)) 9 TESTPKGS = $(shell env GO111MODULE=on $(GO) list -f \ 10 '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' \ 11 $(PKGS)) 12 BUILDPATH ?= $(BIN)/$(shell basename $(MODULE)) 13 SRC_FILES=find . -name "*.go" -type f -not -path "./vendor/*" -not -path "./.git/*" -not -path "./.cache/*" -print0 | xargs -0 14 TBIN = $(CURDIR)/test/bin 15 GO = go 16 TIMEOUT = 15 17 V = 0 18 Q = $(if $(filter 1,$V),,@) 19 M = $(shell printf "\033[34;1m➜\033[0m") 20 21 export GO111MODULE=on 22 export CGO_ENABLED=0 23 24 # Tools 25 26 $(TBIN): 27 @mkdir -p $@ 28 $(TBIN)/%: | $(TBIN) ; $(info $(M) building $(PACKAGE)) 29 $Q tmp=$$(mktemp -d); \ 30 env GO111MODULE=off GOPATH=$$tmp GOBIN=$(TBIN) $(GO) get $(PACKAGE) \ 31 || ret=$$?; \ 32 rm -rf $$tmp ; exit $$ret 33 34 GOLINT = $(TBIN)/golint 35 $(BIN)/golint: PACKAGE=golang.org/x/lint/golint 36 37 GOCYCLO = $(TBIN)/gocyclo 38 $(TBIN)/gocyclo: PACKAGE=github.com/fzipp/gocyclo/cmd/gocyclo 39 40 INEFFASSIGN = $(TBIN)/ineffassign 41 $(TBIN)/ineffassign: PACKAGE=github.com/gordonklaus/ineffassign 42 43 MISSPELL = $(TBIN)/misspell 44 $(TBIN)/misspell: PACKAGE=github.com/client9/misspell/cmd/misspell 45 46 GOLINT = $(TBIN)/golint 47 $(TBIN)/golint: PACKAGE=golang.org/x/lint/golint 48 49 GOCOV = $(TBIN)/gocov 50 $(TBIN)/gocov: PACKAGE=github.com/axw/gocov/... 51 52 # Tests 53 54 .PHONY: lint 55 lint: | $(GOLINT) ; $(info $(M) running golint) @ ## Runs the golint command 56 $Q $(GOLINT) -set_exit_status $(PKGS) 57 58 .PHONY: gocyclo 59 gocyclo: | $(GOCYCLO) ; $(info $(M) running gocyclo) @ ## Calculates cyclomatic complexities of functions in Go source code 60 $Q $(GOCYCLO) -over 25 . 61 62 .PHONY: ineffassign 63 ineffassign: | $(INEFFASSIGN) ; $(info $(M) running ineffassign) @ ## Detects ineffectual assignments in Go code 64 $Q $(INEFFASSIGN) . 65 66 .PHONY: misspell 67 misspell: | $(MISSPELL) ; $(info $(M) running misspell) @ ## Finds commonly misspelled English words 68 $Q $(MISSPELL) . 69 70 .PHONY: test 71 test: ; $(info $(M) running go test) @ ## Runs unit tests 72 $Q $(GO) test ${PKGS} 73 74 .PHONY: fmt 75 fmt: ; $(info $(M) running gofmt) @ ## Formats Go code 76 $Q $(GO) fmt $(PKGS) 77 78 .PHONY: vet 79 vet: ; $(info $(M) running go vet) @ ## Examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string 80 $Q $(GO) vet $(PKGS) 81 82 .PHONY: race 83 race: ; $(info $(M) running go race) @ ## Runs tests with data race detection 84 $Q CGO_ENABLED=1 $(GO) test -race -short $(PKGS) 85 86 .PHONY: benchmark 87 benchmark: ; $(info $(M) running go benchmark test) @ ## Benchmark tests to examine performance 88 $Q $(GO) test -run=__absolutelynothing__ -bench=. $(PKGS) 89 90 .PHONY: coverage 91 coverage: ; $(info $(M) running go coverage) @ ## Runs tests and generates code coverage report at ./test/coverage.out 92 $Q mkdir -p $(CURDIR)/test/ 93 $Q $(GO) test -coverprofile="$(CURDIR)/test/coverage.out" $(PKGS) 94 95 .PHONY: checkfmt 96 checkfmt: ; $(info $(M) running checkfmt) @ ## Checks if code is formatted with go fmt and errors out if not 97 @test "$(shell $(SRC_FILES) gofmt -l)" = "" \ 98 || { echo "Code not formatted, please run 'make fmt'"; exit 2; } 99 100 # Misc 101 102 .PHONY: help 103 help: 104 @grep -hE '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ 105 awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m∙ %s:\033[0m %s\n", $$1, $$2}' 106 107 .PHONY: version 108 version: ## Print version information 109 @echo App: $(VERSION) 110 @echo Go: $(GOVERSION) 111 @echo Commit: $(COMMIT) 112 @echo Branch: $(BRANCH) 113 114 .PHONY: clean 115 clean: ; $(info $(M) cleaning) @ ## Cleanup everything 116 @rm -rfv $(TBIN) 117 @rm -rfv $(CURDIR)/test