1111# See the License for the specific language governing permissions and
1212# limitations under the License.
1313
14+ # Ensure GOBIN is not set during build so that promu is installed to the correct path
15+ unexport GOBIN
16+
1417GO ?= go
1518GOFMT ?= $(GO ) fmt
1619FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO ) env GOPATH) ) )
20+ GOHOSTOS ?= $(shell $(GO ) env GOHOSTOS)
21+ GOHOSTARCH ?= $(shell $(GO ) env GOHOSTARCH)
22+
23+ # Enforce Go modules support just in case the directory is inside GOPATH (and for Travis CI).
24+ GO111MODULE := on
25+ # Always use the local vendor/ directory to satisfy the dependencies.
26+ GOOPTS := $(GOOPTS ) -mod=vendor
27+
1728PROMU := $(FIRST_GOPATH ) /bin/promu
1829STATICCHECK := $(FIRST_GOPATH ) /bin/staticcheck
1930GOVERALLS := $(FIRST_GOPATH ) /bin/goveralls
20- pkgs = $(shell $(GO ) list ./... | grep -v /vendor/)
31+ pkgs = ./...
32+
33+ ifeq (arm, $(GOHOSTARCH ) )
34+ GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
35+ GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
36+ else
37+ GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
38+ endif
39+
40+ PROMU_VERSION ?= 0.5.0
41+ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION ) /promu-$(PROMU_VERSION ) .$(GO_BUILD_PLATFORM ) .tar.gz
2142
2243PREFIX ?= $(shell pwd)
2344BIN_DIR ?= $(shell pwd)
@@ -40,41 +61,48 @@ check_license:
4061 @echo " >> checking license header"
4162 @./scripts/check_license.sh
4263
43- # TODO(fabxc): example tests temporarily removed.
64+ deps :
65+ @echo " >> getting dependencies"
66+ ifdef GO111MODULE
67+ GO111MODULE=$(GO111MODULE) $(GO) mod download
68+ else
69+ $(GO) get $(GOOPTS) -t ./...
70+ endif
71+
4472test-short :
4573 @echo " >> running short tests"
46- @ $(GO ) test -short $(shell $(GO ) list ./... | grep -v /vendor/ | grep -v examples )
74+ $(GO ) test -short $(GOOPTS ) $(pkgs )
4775
4876test :
4977 @echo " >> running all tests"
50- @ $(GO ) test $(shell $(GO ) list ./... | grep -v /vendor/ | grep -v examples )
78+ $(GO ) test $(GOOPTS ) $(pkgs )
5179
5280cover :
5381 @echo " >> running all tests with coverage"
54- @ $(GO ) test -coverprofile=coverage.out $(shell $(GO ) list ./... | grep -v /vendor/ | grep -v examples )
82+ $(GO ) test -coverprofile=coverage.out $(GOOPTS ) $(pkgs )
5583
5684format :
5785 @echo " >> formatting code"
58- @ $(GO ) fmt $(pkgs )
86+ $(GO ) fmt $(pkgs )
5987
6088vet :
6189 @echo " >> vetting code"
62- @ $(GO ) vet $(pkgs )
90+ $(GO ) vet $( GOOPTS ) $(pkgs )
6391
6492staticcheck : $(STATICCHECK )
6593 @echo " >> running staticcheck"
66- @ $(STATICCHECK ) $(pkgs )
94+ $(STATICCHECK ) $(pkgs )
6795
6896goveralls : cover $(GOVERALLS )
6997ifndef COVERALLS_TOKEN
7098 $(error COVERALLS_TOKEN is undefined, follow https://docs.coveralls.io/go to create one and go to https://coveralls.io to retrieve existing ones)
7199endif
72100 @echo ">> running goveralls"
73- @ $(GOVERALLS) -coverprofile=coverage.out -service=travis-ci -repotoken "${COVERALLS_TOKEN}"
101+ $(GOVERALLS) -coverprofile=coverage.out -service=travis-ci -repotoken "${COVERALLS_TOKEN}"
74102
75103build : promu
76104 @echo " >> building binaries"
77- @ $(PROMU ) build --prefix $(PREFIX )
105+ $(PROMU ) build --prefix $(PREFIX )
78106
79107build-linux-amd64 : promu
80108 @echo " >> building linux amd64 binaries"
@@ -86,29 +114,30 @@ tarball: promu
86114
87115docker : build-linux-amd64
88116 @echo " >> building docker image"
89- @ docker build -t " $( DOCKER_IMAGE_NAME) :$( DOCKER_IMAGE_TAG) " .
117+ docker build -t " $( DOCKER_IMAGE_NAME) :$( DOCKER_IMAGE_TAG) " .
90118
91119push : test docker
92120 @echo " >> pushing docker image"
93121 docker push " $( DOCKER_IMAGE_NAME) :$( DOCKER_IMAGE_TAG) "
94122
95123assets :
96124 @echo " >> writing assets"
97- @ $(GO ) get -u github.com/jteeuwen/go-bindata/...
98- @ go-bindata $(bindata_flags ) -pkg ui -o web/ui/bindata.go -ignore ' (.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' web/ui/templates/... web/ui/static/...
99- @ $(GO ) fmt ./web/ui
125+ $(GO ) get -u github.com/jteeuwen/go-bindata/...
126+ go-bindata $(bindata_flags ) -pkg ui -o web/ui/bindata.go -ignore ' (.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' web/ui/templates/... web/ui/static/...
127+ $(GO ) fmt ./web/ui
100128
101129promu :
102130 @echo " >> fetching promu"
103- @GOOS=$(shell uname -s | tr A-Z a-z) \
104- GOARCH=$(subst x86_64,amd64,$(patsubst i% 86,386,$(shell uname -m) ) ) \
105- GO=" $( GO) " \
106- $(GO ) get -u github.com/prometheus/promu
131+ $(eval PROMU_TMP := $(shell mktemp -d) )
132+ curl -s -L $(PROMU_URL ) | tar -xvzf - -C $(PROMU_TMP )
133+ mkdir -p $(FIRST_GOPATH ) /bin
134+ cp $(PROMU_TMP ) /promu-$(PROMU_VERSION ) .$(GO_BUILD_PLATFORM ) /promu $(FIRST_GOPATH ) /bin/promu
135+ rm -r $(PROMU_TMP )
107136
108137$(FIRST_GOPATH ) /bin/staticcheck :
109- @ GOOS= GOARCH= $(GO ) get -u honnef.co/go/tools/cmd/staticcheck
138+ GOOS= GOARCH= $(GO ) get -u honnef.co/go/tools/cmd/staticcheck
110139
111140$(FIRST_GOPATH ) /bin/goveralls :
112- @ GOOS= GOARCH= $(GO ) get -u github.com/mattn/goveralls
141+ GOOS= GOARCH= $(GO ) get -u github.com/mattn/goveralls
113142
114- .PHONY : all style check_license format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH ) /bin/staticcheck goveralls $(FIRST_GOPATH ) /bin/goveralls
143+ .PHONY : all style check_license deps format build test vet assets tarball docker promu staticcheck $(FIRST_GOPATH ) /bin/staticcheck goveralls $(FIRST_GOPATH ) /bin/goveralls
0 commit comments