blob: 4d1098394667518f4ff332d4aceff64bef528eb1 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001# Copyright 2018 The Prometheus Authors
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14# Ensure GOBIN is not set during build so that promu is installed to the correct path
15unexport GOBIN
16
17GO ?= go
18GOFMT ?= $(GO)fmt
19FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
20STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
21pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
22
23PREFIX ?= $(shell pwd)
24BIN_DIR ?= $(shell pwd)
25
26ifdef DEBUG
27 bindata_flags = -debug
28endif
29
30STATICCHECK_IGNORE =
31
32all: format staticcheck build test
33
34style:
35 @echo ">> checking code style"
36 @! $(GOFMT) -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
37
38check_license:
39 @echo ">> checking license header"
40 @./scripts/check_license.sh
41
42test: fixtures/.unpacked sysfs/fixtures/.unpacked
43 @echo ">> running all tests"
44 @$(GO) test -race $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples)
45
46format:
47 @echo ">> formatting code"
48 @$(GO) fmt $(pkgs)
49
50vet:
51 @echo ">> vetting code"
52 @$(GO) vet $(pkgs)
53
54staticcheck: $(STATICCHECK)
55 @echo ">> running staticcheck"
56 @$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
57
58%/.unpacked: %.ttar
59 ./ttar -C $(dir $*) -x -f $*.ttar
60 touch $@
61
62update_fixtures: fixtures.ttar sysfs/fixtures.ttar
63
64%fixtures.ttar: %/fixtures
65 rm -v $(dir $*)fixtures/.unpacked
66 ./ttar -C $(dir $*) -c -f $*fixtures.ttar fixtures/
67
68$(FIRST_GOPATH)/bin/staticcheck:
69 @GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
70
71.PHONY: all style check_license format test vet staticcheck
72
73# Declaring the binaries at their default locations as PHONY targets is a hack
74# to ensure the latest version is downloaded on every make execution.
75# If this is not desired, copy/symlink these binaries to a different path and
76# set the respective environment variables.
77.PHONY: $(GOPATH)/bin/staticcheck