@@ -45,32 +45,31 @@ GOOS ?= $(shell uname | tr A-Z a-z)
45
45
GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
46
46
47
47
GO_VERSION ?= 1.5.3
48
+ GOPATH ?= $(CURDIR)/.build/gopath
49
+ ROOTPKG ?= github.com/prometheus/$(TARGET)
50
+ SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
48
51
49
52
# Check for the correct version of go in the path. If we find it, use it.
50
53
# Otherwise, prepare to build go locally.
51
54
ifeq ($(shell command -v "go" >/dev/null && go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/'), $(GO_VERSION))
52
55
GOCC ?= $(shell command -v "go")
53
56
GOFMT ?= $(shell command -v "gofmt")
54
- GO ?= $(GOCC)
57
+ GO ?= GOPATH=$(GOPATH) $(GOCC)
55
58
else
56
59
GOURL ?= https://golang.org/dl
57
60
GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH).tar.gz
58
61
GOROOT ?= $(CURDIR)/.build/go$(GO_VERSION)
59
62
GOCC ?= $(GOROOT)/bin/go
60
63
GOFMT ?= $(GOROOT)/bin/gofmt
61
- GO ?= GOROOT=$(GOROOT) $(GOCC)
64
+ GO ?= GOPATH=$(GOPATH) GOROOT=$(GOROOT) $(GOCC)
62
65
endif
63
66
64
67
# Use vendored dependencies if available. Otherwise try to download them.
65
68
ifneq (,$(wildcard vendor))
66
69
DEPENDENCIES := $(shell find vendor/ -type f -iname '*.go')
67
70
GO := GO15VENDOREXPERIMENT=1 $(GO)
68
71
else
69
- GOPATH := $(CURDIR)/.build/gopath
70
- ROOTPKG ?= github.com/prometheus/$(TARGET)
71
- SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
72
72
DEPENDENCIES := dependencies-stamp
73
- GO := GOPATH=$(GOPATH) $(GO)
74
73
endif
75
74
76
75
# Never honor GOBIN, should it be set at all.
@@ -82,8 +81,8 @@ ARCHIVE ?= $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
82
81
83
82
default: $(BINARY)
84
83
85
- $(BINARY): $(GOCC) $(SRC) $(DEPENDENCIES) Makefile Makefile.COMMON
86
- $(GO) build $(GOFLAGS) -o $@
84
+ $(BINARY): $(GOCC) $(SRC) $(DEPENDENCIES) Makefile Makefile.COMMON | $(SELFLINK)
85
+ cd $(SELFLINK) && $(GO) build $(GOFLAGS) -o $@
87
86
88
87
.PHONY: archive
89
88
archive: $(ARCHIVE)
97
96
git push --tags
98
97
99
98
.PHONY: test
100
- test: $(GOCC) $(DEPENDENCIES)
101
- $(GO) test $$($(GO) list ./... | grep -v /vendor/)
99
+ test: $(GOCC) $(DEPENDENCIES) | $(SELFLINK)
100
+ cd $(SELFLINK) && $(GO) test $$($(GO) list ./... | grep -v /vendor/)
102
101
103
102
.PHONY: format
104
103
format: $(GOCC)
0 commit comments