diff --git a/GNUmakefile b/GNUmakefile index 9e3b646a59..55faa4a6ef 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -7,6 +7,17 @@ GOTOOLS = \ TEST ?= ./... GOTAGS ?= consul GOFILES ?= $(shell go list $(TEST) | grep -v /vendor/) +GOOS=$(shell go env GOOS) +GOARCH=$(shell go env GOARCH) + +# Get the git commit +GIT_COMMIT=$(shell git rev-parse --short HEAD) +GIT_DIRTY=$(shell test -n "`git status --porcelain`" && echo "+CHANGES" || true) +GIT_DESCRIBE=$(shell git describe --tags --always) +GIT_IMPORT=github.com/hashicorp/consul/version +GOLDFLAGS=-X $(GIT_IMPORT).GitCommit=$(GIT_COMMIT)$(GIT_DIRTY) -X $(GIT_IMPORT).GitDescribe=$(GIT_DESCRIBE) + +export GOLDFLAGS # all builds binaries for all targets all: bin @@ -16,8 +27,11 @@ bin: tools @GOTAGS='$(GOTAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" # dev creates binaries for testing locally - these are put into ./bin and $GOPATH -dev: format - @CONSUL_DEV=1 GOTAGS='$(GOTAGS)' sh -c "'$(CURDIR)/scripts/build.sh'" +dev: + mkdir -p pkg/$(GOOS)_$(GOARCH) + go install -ldflags '$(GOLDFLAGS)' -tags '$(GOTAGS)' + cp $(GOPATH)/bin/consul bin + cp $(GOPATH)/bin/consul pkg/$(GOOS)_$(GOARCH) # dist builds binaries for all platforms and packages them for distribution dist: diff --git a/scripts/build.sh b/scripts/build.sh index 2011bd5985..566dbc6cc8 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -13,12 +13,6 @@ DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" # Change into that directory cd "$DIR" -# Get the git commit -GIT_COMMIT="$(git rev-parse --short HEAD)" -GIT_DIRTY="$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)" -GIT_DESCRIBE="$(git describe --tags --always)" -GIT_IMPORT="github.com/hashicorp/consul/version" - # Determine the arch/os combos we're building for XC_ARCH=${XC_ARCH:-"386 amd64 arm"} XC_OS=${XC_OS:-"solaris darwin freebsd linux windows"} @@ -41,7 +35,7 @@ echo "==> Building..." -os="${XC_OS}" \ -arch="${XC_ARCH}" \ -osarch="!darwin/arm" \ - -ldflags "-X ${GIT_IMPORT}.GitCommit='${GIT_COMMIT}${GIT_DIRTY}' -X ${GIT_IMPORT}.GitDescribe='${GIT_DESCRIBE}'" \ + -ldflags "${GOLDFLAGS}" \ -output "pkg/{{.OS}}_{{.Arch}}/consul" \ -tags="${GOTAGS}" \ .