2018-01-03 14:58:23 -05:00
GOTOOLS := \
2017-12-23 02:23:05 -08:00
github.com/mitchellh/gox \
github.com/Masterminds/glide \
github.com/tcnksm/ghr \
gopkg.in/alecthomas/gometalinter.v2
2018-01-03 14:58:23 -05:00
GO_MIN_VERSION := 1.9.2
PACKAGES := $( shell go list ./... | grep -v '/vendor/' )
BUILD_TAGS ?= tendermint
TMHOME ?= $( HOME) /.tendermint
GOPATH ?= $( shell go env GOPATH)
GOROOT ?= $( shell go env GOROOT)
GOGCCFLAGS ?= $( shell go env GOGCCFLAGS)
2018-01-03 17:24:11 -05:00
#LDFLAGS_EXTRA ?= -w -s
2018-01-03 14:58:23 -05:00
XC_ARCH ?= 386 amd64 arm
XC_OS ?= solaris darwin freebsd linux windows
XC_OSARCH ?= !darwin/arm !solaris/amd64 !freebsd/amd64
2018-01-05 14:22:13 -05:00
BUILD_OUTPUT ?= ./build/{ { .OS} } _{ { .Arch} } /tendermint
2018-01-03 14:58:23 -05:00
GOX_FLAGS = -os= " $( XC_OS) " -arch= " $( XC_ARCH) " -osarch= " $( XC_OSARCH) " -output= " $( BUILD_OUTPUT) "
i f e q ( $( BUILD_FLAGS_RACE ) , Y E S )
RACEFLAG = -race
e l s e
RACEFLAG =
e n d i f
2018-01-05 14:22:13 -05:00
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)
2018-01-03 14:58:23 -05:00
GO_VERSION := $( shell go version | grep -o '[[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+' )
2018-01-05 14:22:13 -05:00
#Check that that minor version of GO meets the minimum required
GO_MINOR_VERSION := $( shell grep -o \. [ [ :digit:] ] [ [ :digit:] ] *\. <<< $( GO_VERSION) | grep -o [ [ :digit:] ] * )
GO_MIN_MINOR_VERSION := $( shell grep -o \. [ [ :digit:] ] [ [ :digit:] ] *\. <<< $( GO_MIN_VERSION) | grep -o [ [ :digit:] ] * )
GO_MINOR_VERSION_CHECK := $( shell test $( GO_MINOR_VERSION) -ge $( GO_MIN_MINOR_VERSION) && echo YES)
2017-12-04 17:35:42 -06:00
2017-12-23 02:23:05 -08:00
all : check build test install metalinter
2015-07-13 11:49:09 -07:00
2017-12-23 02:23:05 -08:00
check : check_tools get_vendor_deps
########################################
### Build
2014-12-28 16:26:53 -08:00
2018-01-05 14:22:13 -05:00
build_xc : check_tools
2018-01-03 14:58:23 -05:00
$( shell which gox) $( BUILD_FLAGS) $( GOX_FLAGS) ./cmd/tendermint/
2017-01-04 00:32:39 +04:00
build :
2018-01-03 17:24:11 -05:00
i f e q ( $( OS ) , W i n d o w s _ N T )
2018-01-05 14:22:13 -05:00
make build_xc XC_ARCH = amd64 XC_OS = windows BUILD_OUTPUT = $( GOPATH) /bin/tendermint
2018-01-03 17:24:11 -05:00
e l s e
2018-01-05 14:22:13 -05:00
make build_xc XC_ARCH = amd64 XC_OS = " $( shell uname -s) " BUILD_OUTPUT = $( GOPATH) /bin/tendermint
2018-01-03 17:24:11 -05:00
e n d i f
2015-04-21 19:51:23 -07:00
2017-01-04 00:32:39 +04:00
build_race :
2018-01-03 17:24:11 -05:00
#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.
# make build BUILD_FLAGS_RACE=YES
2018-01-03 14:58:23 -05:00
$( shell which go) build $( BUILD_FLAGS) -race -o " $( BUILD_OUTPUT) " ./cmd/tendermint/
2014-12-28 17:10:03 -08:00
2017-01-23 13:45:14 +04:00
# dist builds binaries for all platforms and packages them for distribution
dist :
@BUILD_TAGS= '$(BUILD_TAGS)' sh -c " ' $( CURDIR) /scripts/dist.sh' "
2017-12-23 02:23:05 -08:00
install :
2018-01-03 14:58:23 -05:00
make build
2017-12-23 02:23:05 -08:00
########################################
### Tools & dependencies
check_tools :
2018-01-03 14:58:23 -05:00
i f e q ( $( GO_VERSION ) , )
$( error go not found)
e n d i f
2018-01-05 14:22:13 -05:00
#Check minimum required go version
2018-01-03 14:58:23 -05:00
i f n e q ( $( GO_VERSION ) , $( GO_MIN_VERSION ) )
$( warning WARNING: build will not be deterministic. go version should be $( GO_MIN_VERSION) )
2018-01-05 14:22:13 -05:00
i f n e q ( $( GO_MINOR_VERSION_CHECK ) , Y E S )
$( error ERROR: The minor version of Go ( $( GO_VERSION) ) is lower than the minimum required ( $( GO_MIN_VERSION) ) )
e n d i f
2018-01-03 14:58:23 -05:00
e n d i f
2018-01-05 14:22:13 -05:00
#-fdebug-prefix-map switches the temporary, randomized workdir name in the binary to a static text
2018-01-03 14:58:23 -05:00
i f n e q ( $( findstring -fdebug -prefix -map ,$ ( GOGCCFLAGS ) ) , - f d e b u g - p r e f i x - m a p )
$( warning WARNING: build will not be deterministic. The compiler does not support the '-fdebug-prefix-map' flag.)
e n d i f
2018-01-05 14:22:13 -05:00
#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.)
2018-01-03 14:58:23 -05:00
i f n e q ( $( GOROOT ) , / u s r / l o c a l / g o )
2018-01-05 14:22:13 -05:00
$( warning WARNING: build will not be deterministic. GOROOT should be set to /usr/local/go)
e n d i f
#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.)
i f n e q ( $( GOPATH ) , / g o )
$( warning WARNING: build will not be deterministic. GOPATH should be set to /go)
2018-01-03 14:58:23 -05:00
e n d i f
2018-01-05 14:22:13 -05:00
#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.
2018-01-03 14:58:23 -05:00
i f n e q ( $( findstring $ ( GOPATH ) /bin ,$ ( PATH ) ) , $( GOPATH ) / b i n )
$( warning WARNING: PATH does not contain GOPATH/bin. Some external dependencies might be unavailable.)
e n d i f
# https://stackoverflow.com/a/25668869
@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' " ) ) ) "
2017-12-23 02:23:05 -08:00
get_tools :
@echo "--> Installing tools"
go get -u -v $( GOTOOLS)
@gometalinter.v2 --install
update_tools :
@echo "--> Updating tools"
@go get -u $( GOTOOLS)
get_vendor_deps :
@rm -rf vendor/
@echo "--> Running glide install"
@glide install
draw_deps :
@# requires brew install graphviz or apt-get install graphviz
go get github.com/RobotsAndPencils/goviz
@goviz -i github.com/tendermint/tendermint/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
########################################
### Testing
2017-01-30 12:02:24 +04:00
test :
2017-01-22 18:03:20 +04:00
@echo "--> Running go test"
2017-02-22 20:01:32 +01:00
@go test $( PACKAGES)
2017-01-04 00:32:39 +04:00
2017-01-30 12:02:24 +04:00
test_race :
2017-01-22 18:03:20 +04:00
@echo "--> Running go test --race"
2017-02-22 20:01:32 +01:00
@go test -v -race $( PACKAGES)
2014-12-28 16:26:53 -08:00
2017-01-04 00:32:39 +04:00
test_integrations :
2017-01-22 18:03:20 +04:00
@bash ./test/test.sh
2016-07-23 12:48:30 -04:00
2017-12-04 17:37:32 -06:00
test_release :
2017-10-25 19:20:33 -07:00
@go test -tags release $( PACKAGES)
2017-01-30 12:02:24 +04:00
test100 :
2017-01-22 18:03:20 +04:00
@for i in { 1..100} ; do make test; done
2016-04-29 15:32:50 -07:00
2017-12-08 18:36:58 +01:00
vagrant_test :
vagrant up
vagrant ssh -c 'make install'
vagrant ssh -c 'make test_race'
vagrant ssh -c 'make test_integrations'
2017-02-08 19:28:25 +01:00
2017-12-23 02:23:05 -08:00
########################################
2017-05-30 13:27:31 -04:00
### Formatting, linting, and vetting
2017-12-23 02:23:05 -08:00
fmt :
@go fmt ./...
2017-02-08 19:28:25 +01:00
2017-12-23 02:23:05 -08:00
metalinter :
@echo "--> Running linter"
2017-12-11 23:05:22 -06:00
gometalinter.v2 --vendor --deadline= 600s --disable-all \
2017-09-21 14:13:13 -04:00
--enable= deadcode \
2017-12-10 17:44:22 +00:00
--enable= gosimple \
2017-09-21 14:13:13 -04:00
--enable= misspell \
--enable= safesql \
./...
2017-12-10 17:44:22 +00:00
#--enable=gas \
2017-10-26 19:24:18 -04:00
#--enable=maligned \
2017-09-21 14:13:13 -04:00
#--enable=dupl \
2017-10-14 14:38:47 -04:00
#--enable=errcheck \
2017-09-21 14:13:13 -04:00
#--enable=goconst \
#--enable=gocyclo \
2017-10-03 18:49:20 -04:00
#--enable=goimports \
2017-09-21 14:13:13 -04:00
#--enable=golint \ <== comments on anything exported
2017-10-03 19:11:55 -04:00
#--enable=gotype \
2017-10-28 11:07:59 -04:00
#--enable=ineffassign \
2017-09-21 14:13:13 -04:00
#--enable=interfacer \
#--enable=megacheck \
#--enable=staticcheck \
2017-11-09 13:59:35 -05:00
#--enable=structcheck \
2017-09-21 14:13:13 -04:00
#--enable=unconvert \
#--enable=unparam \
#--enable=unused \
2017-11-09 13:59:35 -05:00
#--enable=varcheck \
2017-09-21 14:13:13 -04:00
#--enable=vet \
#--enable=vetshadow \
2017-09-21 13:54:34 -04:00
2017-12-23 02:23:05 -08:00
metalinter_all :
@echo "--> Running linter (all)"
gometalinter.v2 --vendor --deadline= 600s --enable-all --disable= lll ./...
# To avoid unintended conflicts with file names, always add to .PHONY
# unless there is a reason not to.
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.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 test 100 vagrant_test fmt metalinter metalinter_all