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.

187 lines
6.4 KiB

9 years ago
7 years ago
7 years ago
7 years ago
  1. GOTOOLS := \
  2. github.com/mitchellh/gox \
  3. github.com/Masterminds/glide \
  4. github.com/tcnksm/ghr \
  5. gopkg.in/alecthomas/gometalinter.v2
  6. GO_MIN_VERSION := 1.9.2
  7. PACKAGES := $(shell go list ./... | grep -v '/vendor/')
  8. BUILD_TAGS ?= tendermint
  9. TMHOME ?= $(HOME)/.tendermint
  10. GOPATH ?= $(shell go env GOPATH)
  11. GOROOT ?= $(shell go env GOROOT)
  12. GOGCCFLAGS ?= $(shell go env GOGCCFLAGS)
  13. #LDFLAGS_EXTRA ?= -w -s
  14. XC_ARCH ?= 386 amd64 arm
  15. XC_OS ?= solaris darwin freebsd linux windows
  16. XC_OSARCH ?= !darwin/arm !solaris/amd64 !freebsd/amd64
  17. BUILD_OUTPUT ?= ./build/{{.OS}}_{{.Arch}}/tendermint
  18. GOX_FLAGS = -os="$(XC_OS)" -arch="$(XC_ARCH)" -osarch="$(XC_OSARCH)" -output="$(BUILD_OUTPUT)"
  19. ifeq ($(BUILD_FLAGS_RACE),YES)
  20. RACEFLAG=-race
  21. else
  22. RACEFLAG=
  23. endif
  24. BUILD_FLAGS = -asmflags "-trimpath $(GOPATH)" -gcflags "-trimpath $(GOPATH)" -tags "$(BUILD_TAGS)" -ldflags "-X github.com/tendermint/tendermint/version.GitCommit=$(shell git rev-parse --short=8 HEAD) $(LDFLAGS_EXTRA)" $(RACEFLAG)
  25. GO_VERSION:=$(shell go version | grep -o '[[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+')
  26. #Check that that minor version of GO meets the minimum required
  27. GO_MINOR_VERSION := $(shell grep -o \.[[:digit:]][[:digit:]]*\. <<< $(GO_VERSION) | grep -o [[:digit:]]* )
  28. GO_MIN_MINOR_VERSION := $(shell grep -o \.[[:digit:]][[:digit:]]*\. <<< $(GO_MIN_VERSION) | grep -o [[:digit:]]* )
  29. GO_MINOR_VERSION_CHECK := $(shell test $(GO_MINOR_VERSION) -ge $(GO_MIN_MINOR_VERSION) && echo YES)
  30. all: check build test install metalinter
  31. check: check_tools get_vendor_deps
  32. ########################################
  33. ### Build
  34. build_xc: check_tools
  35. $(shell which gox) $(BUILD_FLAGS) $(GOX_FLAGS) ./cmd/tendermint/
  36. build:
  37. ifeq ($(OS),Windows_NT)
  38. make build_xc XC_ARCH=amd64 XC_OS=windows BUILD_OUTPUT=$(GOPATH)/bin/tendermint
  39. else
  40. make build_xc XC_ARCH=amd64 XC_OS="$(shell uname -s)" BUILD_OUTPUT=$(GOPATH)/bin/tendermint
  41. endif
  42. build_race:
  43. #TODO: Wait for this to be merged: https://github.com/mitchellh/gox/pull/105 Then switch over to make build and remove the go build line.
  44. # make build BUILD_FLAGS_RACE=YES
  45. $(shell which go) build $(BUILD_FLAGS) -race -o "$(BUILD_OUTPUT)" ./cmd/tendermint/
  46. # dist builds binaries for all platforms and packages them for distribution
  47. dist:
  48. @BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/dist.sh'"
  49. install:
  50. make build
  51. ########################################
  52. ### Tools & dependencies
  53. check_tools:
  54. ifeq ($(GO_VERSION),)
  55. $(error go not found)
  56. endif
  57. #Check minimum required go version
  58. ifneq ($(GO_VERSION),$(GO_MIN_VERSION))
  59. $(warning WARNING: build will not be deterministic. go version should be $(GO_MIN_VERSION))
  60. ifneq ($(GO_MINOR_VERSION_CHECK),YES)
  61. $(error ERROR: The minor version of Go ($(GO_VERSION)) is lower than the minimum required ($(GO_MIN_VERSION)))
  62. endif
  63. endif
  64. #-fdebug-prefix-map switches the temporary, randomized workdir name in the binary to a static text
  65. ifneq ($(findstring -fdebug-prefix-map,$(GOGCCFLAGS)),-fdebug-prefix-map)
  66. $(warning WARNING: build will not be deterministic. The compiler does not support the '-fdebug-prefix-map' flag.)
  67. endif
  68. #GOROOT string is copied into the binary. For deterministic builds, we agree to keep it at /usr/local/go. (Default for golang:1.9.2 docker image, linux and osx.)
  69. ifneq ($(GOROOT),/usr/local/go)
  70. $(warning WARNING: build will not be deterministic. GOROOT should be set to /usr/local/go)
  71. endif
  72. #GOPATH string is copied into the binary. Although the -trimpath flag tries to eliminate it, it doesn't do it everywhere in Go 1.9.2. For deterministic builds we agree to keep it at /go. (Default for golang:1.9.2 docker image.)
  73. ifneq ($(GOPATH),/go)
  74. $(warning WARNING: build will not be deterministic. GOPATH should be set to /go)
  75. endif
  76. #External dependencies defined in GOTOOLS are built with get_tools. If they are already available on the system (for exmaple using a package manager), then get_tools might not be necessary.
  77. ifneq ($(findstring $(GOPATH)/bin,$(PATH)),$(GOPATH)/bin)
  78. $(warning WARNING: PATH does not contain GOPATH/bin. Some external dependencies might be unavailable.)
  79. endif
  80. # https://stackoverflow.com/a/25668869
  81. @echo "Found tools: $(foreach tool,$(notdir $(GOTOOLS)),$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH. Add GOPATH/bin to PATH and run 'make get_tools'")))"
  82. get_tools:
  83. @echo "--> Installing tools"
  84. go get -u -v $(GOTOOLS)
  85. @gometalinter.v2 --install
  86. update_tools:
  87. @echo "--> Updating tools"
  88. @go get -u $(GOTOOLS)
  89. get_vendor_deps:
  90. @rm -rf vendor/
  91. @echo "--> Running glide install"
  92. @glide install
  93. draw_deps:
  94. @# requires brew install graphviz or apt-get install graphviz
  95. go get github.com/RobotsAndPencils/goviz
  96. @goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
  97. ########################################
  98. ### Testing
  99. test:
  100. @echo "--> Running go test"
  101. @go test $(PACKAGES)
  102. test_race:
  103. @echo "--> Running go test --race"
  104. @go test -v -race $(PACKAGES)
  105. test_integrations:
  106. @bash ./test/test.sh
  107. test_release:
  108. @go test -tags release $(PACKAGES)
  109. test100:
  110. @for i in {1..100}; do make test; done
  111. vagrant_test:
  112. vagrant up
  113. vagrant ssh -c 'make install'
  114. vagrant ssh -c 'make test_race'
  115. vagrant ssh -c 'make test_integrations'
  116. ########################################
  117. ### Formatting, linting, and vetting
  118. fmt:
  119. @go fmt ./...
  120. metalinter:
  121. @echo "--> Running linter"
  122. gometalinter.v2 --vendor --deadline=600s --disable-all \
  123. --enable=deadcode \
  124. --enable=gosimple \
  125. --enable=misspell \
  126. --enable=safesql \
  127. ./...
  128. #--enable=gas \
  129. #--enable=maligned \
  130. #--enable=dupl \
  131. #--enable=errcheck \
  132. #--enable=goconst \
  133. #--enable=gocyclo \
  134. #--enable=goimports \
  135. #--enable=golint \ <== comments on anything exported
  136. #--enable=gotype \
  137. #--enable=ineffassign \
  138. #--enable=interfacer \
  139. #--enable=megacheck \
  140. #--enable=staticcheck \
  141. #--enable=structcheck \
  142. #--enable=unconvert \
  143. #--enable=unparam \
  144. #--enable=unused \
  145. #--enable=varcheck \
  146. #--enable=vet \
  147. #--enable=vetshadow \
  148. metalinter_all:
  149. @echo "--> Running linter (all)"
  150. gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
  151. # To avoid unintended conflicts with file names, always add to .PHONY
  152. # unless there is a reason not to.
  153. # https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
  154. .PHONY: check build build_race dist install check_tools get_tools update_tools get_vendor_deps draw_deps test test_race test_integrations test_release test100 vagrant_test fmt metalinter metalinter_all