You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.9 KiB

  1. DIST_DIRS := find * -type d -exec
  2. VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go)
  3. GOTOOLS = \
  4. github.com/mitchellh/gox \
  5. github.com/golang/dep/cmd/dep \
  6. gopkg.in/alecthomas/gometalinter.v2
  7. PACKAGES=$(shell go list ./... | grep -v '/vendor/')
  8. all: check get_vendor_deps build test install metalinter
  9. check: check_tools
  10. ########################################
  11. ### Tools & dependencies
  12. check_tools:
  13. @# https://stackoverflow.com/a/25668869
  14. @echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\
  15. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  16. get_tools:
  17. @echo "--> Installing tools"
  18. go get -u -v $(GOTOOLS)
  19. @gometalinter.v2 --install
  20. update_tools:
  21. @echo "--> Updating tools"
  22. @go get -u $(GOTOOLS)
  23. get_vendor_deps:
  24. @rm -rf vendor/
  25. @echo "--> Running dep ensure"
  26. @dep ensure
  27. ########################################
  28. ### Build
  29. build:
  30. @go build
  31. install:
  32. @go install
  33. test:
  34. @go test -race $(PACKAGES)
  35. build-all: check_tools
  36. rm -rf ./dist
  37. gox -verbose \
  38. -ldflags "-s -w" \
  39. -arch="amd64 386 arm arm64" \
  40. -os="linux darwin windows freebsd" \
  41. -osarch="!darwin/arm !darwin/arm64" \
  42. -output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" .
  43. dist: build-all
  44. cd dist && \
  45. $(DIST_DIRS) cp ../LICENSE {} \; && \
  46. $(DIST_DIRS) tar -zcf tm-monitor-${VERSION}-{}.tar.gz {} \; && \
  47. shasum -a256 ./*.tar.gz > "./tm-monitor_${VERSION}_SHA256SUMS" && \
  48. cd ..
  49. ########################################
  50. ### Docker
  51. build-docker:
  52. rm -f ./tm-monitor
  53. docker run -it --rm -v "$(PWD):/go/src/github.com/tendermint/tools/tm-monitor" -w "/go/src/github.com/tendermint/tools/tm-monitor" -e "CGO_ENABLED=0" golang:alpine go build -ldflags "-s -w" -o tm-monitor
  54. docker build -t "tendermint/monitor" .
  55. clean:
  56. rm -f ./tm-monitor
  57. rm -rf ./dist
  58. ########################################
  59. ### Formatting, linting, and vetting
  60. fmt:
  61. @go fmt ./...
  62. metalinter:
  63. @echo "==> Running linter"
  64. gometalinter.v2 --vendor --deadline=600s --disable-all \
  65. --enable=maligned \
  66. --enable=deadcode \
  67. --enable=goconst \
  68. --enable=goimports \
  69. --enable=gosimple \
  70. --enable=ineffassign \
  71. --enable=megacheck \
  72. --enable=misspell \
  73. --enable=staticcheck \
  74. --enable=safesql \
  75. --enable=structcheck \
  76. --enable=unconvert \
  77. --enable=unused \
  78. --enable=varcheck \
  79. --enable=vetshadow \
  80. ./...
  81. #--enable=gas \
  82. #--enable=dupl \
  83. #--enable=errcheck \
  84. #--enable=gocyclo \
  85. #--enable=golint \ <== comments on anything exported
  86. #--enable=gotype \
  87. #--enable=interfacer \
  88. #--enable=unparam \
  89. #--enable=vet \
  90. metalinter_all:
  91. gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
  92. # To avoid unintended conflicts with file names, always add to .PHONY
  93. # unless there is a reason not to.
  94. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  95. .PHONY: check check_tools get_tools update_tools get_vendor_deps build install test build-all dist fmt metalinter metalinter_all build-docker clean