Skip to content

Commit a05966a

Browse files
committed
Update Makefile.COMMON
Go expects to build a project from a location like `.../src/github.com/prometheus/node_exporter`.
1 parent b30806e commit a05966a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Makefile.COMMON

+9-10
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,31 @@ GOOS ?= $(shell uname | tr A-Z a-z)
4545
GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m)))
4646

4747
GO_VERSION ?= 1.5.3
48+
GOPATH ?= $(CURDIR)/.build/gopath
49+
ROOTPKG ?= github.com/prometheus/$(TARGET)
50+
SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
4851

4952
# Check for the correct version of go in the path. If we find it, use it.
5053
# Otherwise, prepare to build go locally.
5154
ifeq ($(shell command -v "go" >/dev/null && go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/'), $(GO_VERSION))
5255
GOCC ?= $(shell command -v "go")
5356
GOFMT ?= $(shell command -v "gofmt")
54-
GO ?= $(GOCC)
57+
GO ?= GOPATH=$(GOPATH) $(GOCC)
5558
else
5659
GOURL ?= https://golang.org/dl
5760
GOPKG ?= go$(GO_VERSION).$(GOOS)-$(GOARCH).tar.gz
5861
GOROOT ?= $(CURDIR)/.build/go$(GO_VERSION)
5962
GOCC ?= $(GOROOT)/bin/go
6063
GOFMT ?= $(GOROOT)/bin/gofmt
61-
GO ?= GOROOT=$(GOROOT) $(GOCC)
64+
GO ?= GOPATH=$(GOPATH) GOROOT=$(GOROOT) $(GOCC)
6265
endif
6366

6467
# Use vendored dependencies if available. Otherwise try to download them.
6568
ifneq (,$(wildcard vendor))
6669
DEPENDENCIES := $(shell find vendor/ -type f -iname '*.go')
6770
GO := GO15VENDOREXPERIMENT=1 $(GO)
6871
else
69-
GOPATH := $(CURDIR)/.build/gopath
70-
ROOTPKG ?= github.com/prometheus/$(TARGET)
71-
SELFLINK ?= $(GOPATH)/src/$(ROOTPKG)
7272
DEPENDENCIES := dependencies-stamp
73-
GO := GOPATH=$(GOPATH) $(GO)
7473
endif
7574

7675
# Never honor GOBIN, should it be set at all.
@@ -82,8 +81,8 @@ ARCHIVE ?= $(TARGET)-$(VERSION).$(SUFFIX).tar.gz
8281

8382
default: $(BINARY)
8483

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 $@
8786

8887
.PHONY: archive
8988
archive: $(ARCHIVE)
@@ -97,8 +96,8 @@ tag:
9796
git push --tags
9897

9998
.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/)
102101

103102
.PHONY: format
104103
format: $(GOCC)

0 commit comments

Comments
 (0)