Makefile 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. cover:
  19. #A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
  20. go test -coverprofile cover.out $(PACKAGES_EXPANDED)
  21. go tool cover -html=cover.out
  22. # Throw an error if gofmt finds problems.
  23. # "read" will return a failure return code if there is no output. This is inverted wth the "!"
  24. gofmt:
  25. ! gofmt -d $(PACKAGES) 2>&1 | read
  26. gofmt-fix:
  27. gofmt -w $(PACKAGES)
  28. license-check:
  29. dist/license-check.sh
  30. ## Display this help text
  31. help: # Some kind of magic from https://gist.github.com/rcmachado/af3db315e31383502660
  32. $(info Available targets)
  33. @awk '/^[a-zA-Z\-\_0-9]+:/ { \
  34. nb = sub( /^## /, "", helpMsg ); \
  35. if(nb == 0) { \
  36. helpMsg = $$0; \
  37. nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
  38. } \
  39. if (nb) \
  40. printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
  41. } \
  42. { helpMsg = $$0 }' \
  43. $(MAKEFILE_LIST)