Makefile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. # Ensure GOBIN is not set during build so that promu is installed to the correct path
  14. unexport GOBIN
  15. GO ?= go
  16. GOFMT ?= $(GO)fmt
  17. FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
  18. STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck
  19. pkgs = $(shell $(GO) list ./... | grep -v /vendor/)
  20. PREFIX ?= $(shell pwd)
  21. BIN_DIR ?= $(shell pwd)
  22. ifdef DEBUG
  23. bindata_flags = -debug
  24. endif
  25. STATICCHECK_IGNORE =
  26. all: format staticcheck build test
  27. style:
  28. @echo ">> checking code style"
  29. @! $(GOFMT) -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
  30. check_license:
  31. @echo ">> checking license header"
  32. @./scripts/check_license.sh
  33. test: fixtures/.unpacked sysfs/fixtures/.unpacked
  34. @echo ">> running all tests"
  35. @$(GO) test -race $(shell $(GO) list ./... | grep -v /vendor/ | grep -v examples)
  36. format:
  37. @echo ">> formatting code"
  38. @$(GO) fmt $(pkgs)
  39. vet:
  40. @echo ">> vetting code"
  41. @$(GO) vet $(pkgs)
  42. staticcheck: $(STATICCHECK)
  43. @echo ">> running staticcheck"
  44. @$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs)
  45. %/.unpacked: %.ttar
  46. ./ttar -C $(dir $*) -x -f $*.ttar
  47. touch $@
  48. update_fixtures: fixtures.ttar sysfs/fixtures.ttar
  49. %fixtures.ttar: %/fixtures
  50. rm -v $(dir $*)fixtures/.unpacked
  51. ./ttar -C $(dir $*) -c -f $*fixtures.ttar fixtures/
  52. $(FIRST_GOPATH)/bin/staticcheck:
  53. @GOOS= GOARCH= $(GO) get -u honnef.co/go/tools/cmd/staticcheck
  54. .PHONY: all style check_license format test vet staticcheck
  55. # Declaring the binaries at their default locations as PHONY targets is a hack
  56. # to ensure the latest version is downloaded on every make execution.
  57. # If this is not desired, copy/symlink these binaries to a different path and
  58. # set the respective environment variables.
  59. .PHONY: $(GOPATH)/bin/staticcheck