Makefile 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. .PHONY: all test cover gofmt gofmt-fix license-check
  2. # Grab the absolute directory that contains this file.
  3. ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
  4. # These variables can be overridden by setting an environment variable.
  5. TEST_PACKAGES?=pkg/ip subnet remote
  6. TEST_PACKAGES_EXPANDED=$(TEST_PACKAGES:%=github.com/coreos/flannel/%)
  7. PACKAGES?=$(TEST_PACKAGES) network
  8. PACKAGES_EXPANDED=$(PACKAGES:%=github.com/coreos/flannel/%)
  9. default: help
  10. all: test ## Run all the tests
  11. binary: artifacts/flanneld ## Create the flanneld binary
  12. artifacts/flanneld: $(shell find . -type f -name '*.go')
  13. mkdir -p artifacts
  14. go build -o artifacts/flanneld \
  15. -ldflags "-extldflags -static -X github.com/coreos/flannel/version.Version=$(shell git describe --dirty)"
  16. test:
  17. go test -cover $(TEST_PACKAGES_EXPANDED)
  18. cd dist; ./mk-docker-opts_tests.sh
  19. cover:
  20. #A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
  21. go test -coverprofile cover.out $(PACKAGES_EXPANDED)
  22. go tool cover -html=cover.out
  23. # Throw an error if gofmt finds problems.
  24. # "read" will return a failure return code if there is no output. This is inverted wth the "!"
  25. gofmt:
  26. ! gofmt -d $(PACKAGES) 2>&1 | read
  27. gofmt-fix:
  28. gofmt -w $(PACKAGES)
  29. license-check:
  30. dist/license-check.sh
  31. ## Display this help text
  32. help: # Some kind of magic from https://gist.github.com/rcmachado/af3db315e31383502660
  33. $(info Available targets)
  34. @awk '/^[a-zA-Z\-\_0-9]+:/ { \
  35. nb = sub( /^## /, "", helpMsg ); \
  36. if(nb == 0) { \
  37. helpMsg = $$0; \
  38. nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
  39. } \
  40. if (nb) \
  41. printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
  42. } \
  43. { helpMsg = $$0 }' \
  44. $(MAKEFILE_LIST)