Matthias Andreas Benkard | 832a54e | 2019-01-29 09:27:38 +0100 | [diff] [blame^] | 1 | # 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 |
| 15 | unexport GOBIN |
| 16 | |
| 17 | GO ?= go |
| 18 | GOFMT ?= $(GO)fmt |
| 19 | FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH))) |
| 20 | STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck |
| 21 | pkgs = $(shell $(GO) list ./... | grep -v /vendor/) |
| 22 | |
| 23 | PREFIX ?= $(shell pwd) |
| 24 | BIN_DIR ?= $(shell pwd) |
| 25 | |
| 26 | ifdef DEBUG |
| 27 | bindata_flags = -debug |
| 28 | endif |
| 29 | |
| 30 | STATICCHECK_IGNORE = |
| 31 | |
| 32 | all: format staticcheck build test |
| 33 | |
| 34 | style: |
| 35 | @echo ">> checking code style" |
| 36 | @! $(GOFMT) -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^' |
| 37 | |
| 38 | check_license: |
| 39 | @echo ">> checking license header" |
| 40 | @./scripts/check_license.sh |
| 41 | |
| 42 | test: fixtures/.unpacked sysfs/fixtures/.unpacked |
| 43 | @echo ">> running all tests" |
| 44 | @$(GO) test -race $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples) |
| 45 | |
| 46 | format: |
| 47 | @echo ">> formatting code" |
| 48 | @$(GO) fmt $(pkgs) |
| 49 | |
| 50 | vet: |
| 51 | @echo ">> vetting code" |
| 52 | @$(GO) vet $(pkgs) |
| 53 | |
| 54 | staticcheck: $(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 | |
| 62 | update_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 |