A simple pure-Go Linux init system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.mk 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. OS := $(shell uname)
  2. DIST := dist
  3. BUILD_FLAGS := -o $(EXECUTABLE) -v
  4. NOW=$(shell date -u '+%Y%m%d%I%M%S')
  5. TAGS =
  6. GOVET=go vet
  7. GOLINT=golint -set_exit_status
  8. GO ?= go
  9. GOFMT ?= gofmt -s
  10. ifneq ($(DRONE_TAG),)
  11. VERSION ?= $(subst v,,$(DRONE_TAG))
  12. else
  13. ifneq ($(DRONE_BRANCH),)
  14. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  15. else
  16. VERSION ?= master
  17. endif
  18. endif
  19. ### Targets
  20. .PHONY: build clean
  21. all: build
  22. check: test
  23. vet:
  24. $(GOVET) $(PACKAGES)
  25. lint:
  26. @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  27. $(GO) get -u github.com/golang/lint/golint; \
  28. fi
  29. for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
  30. build:
  31. $(GO) build $(BUILD_FLAGS) -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
  32. build-race:
  33. $(GO) build $(BUILD_FLAGS) -race -ldflags '$(LDFLAGS)' -tags '$(TAGS)'
  34. clean:
  35. $(GO) clean -i ./...
  36. find . -name ".DS_Store" -delete
  37. test: fmt-check
  38. $(GO) test -cover -v$(PACKAGES)
  39. .PHONY: misspell-check
  40. misspell-check:
  41. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  42. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  43. fi
  44. misspell -error -i unknwon $(GOFILES)
  45. .PHONY: misspell
  46. misspell:
  47. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  48. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  49. fi
  50. misspell -w -i unknwon $(GOFILES)
  51. required-gofmt-version:
  52. @go version | grep -q '\(1.7\|1.8\|1.9\)' || { echo "We require go version 1.7, 1.8 or 1.9 to format code" >&2 && exit 1; }
  53. .PHONY: fmt
  54. fmt: required-gofmt-version
  55. $(GOFMT) -w $(GOFILES)
  56. .PHONY: fmt-check
  57. fmt-check: required-gofmt-version
  58. # get all go files and run go fmt on them
  59. @diff=$$($(GOFMT) -d $(GOFILES)); \
  60. if [ -n "$$diff" ]; then \
  61. echo "Please run 'make fmt' and commit the result:"; \
  62. echo "$${diff}"; \
  63. exit 1; \
  64. fi;