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.8 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. all: check get_vendor_deps build test install metalinter
  8. check: check_tools
  9. ########################################
  10. ### Tools & dependencies
  11. check_tools:
  12. @# https://stackoverflow.com/a/25668869
  13. @echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\
  14. $(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
  15. get_tools:
  16. @echo "--> Installing tools"
  17. go get -u -v $(GOTOOLS)
  18. @gometalinter.v2 --install
  19. update_tools:
  20. @echo "--> Updating tools"
  21. @go get -u $(GOTOOLS)
  22. get_vendor_deps:
  23. @rm -rf vendor/
  24. @echo "--> Running dep ensure"
  25. @dep ensure
  26. ########################################
  27. ### Build
  28. build:
  29. @go build
  30. install:
  31. @go install
  32. test:
  33. @go test -race
  34. build-all: check_tools
  35. rm -rf ./dist
  36. gox -verbose \
  37. -ldflags "-s -w" \
  38. -arch="amd64 386 arm arm64" \
  39. -os="linux darwin windows freebsd" \
  40. -osarch="!darwin/arm !darwin/arm64" \
  41. -output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" .
  42. dist: build-all
  43. cd dist && \
  44. $(DIST_DIRS) cp ../LICENSE {} \; && \
  45. $(DIST_DIRS) cp ../README.rst {} \; && \
  46. $(DIST_DIRS) tar -zcf tm-bench-${VERSION}-{}.tar.gz {} \; && \
  47. shasum -a256 ./*.tar.gz > "./tm-bench_${VERSION}_SHA256SUMS" && \
  48. cd ..
  49. ########################################
  50. ### Docker
  51. build-docker:
  52. rm -f ./tm-bench
  53. docker run -it --rm -v "$(PWD):/go/src/app" -w "/go/src/app" -e "CGO_ENABLED=0" golang:alpine go build -ldflags "-s -w" -o tm-bench
  54. docker build -t "tendermint/bench" .
  55. clean:
  56. rm -f ./tm-bench
  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