Makefile 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. CMD = agent aggregator graph hbs judge nodata transfer gateway api alarm falcon2p8s
  2. TARGET = open-falcon
  3. PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
  4. GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
  5. GOFMT ?= gofmt "-s"
  6. VERSION := $(shell cat VERSION)
  7. all: $(CMD) $(TARGET)
  8. .PHONY: misspell-check
  9. misspell-check:
  10. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  11. go get -u github.com/client9/misspell/cmd/misspell; \
  12. fi
  13. misspell -error $(GOFILES)
  14. .PHONY: misspell
  15. misspell:
  16. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  17. go get -u github.com/client9/misspell/cmd/misspell; \
  18. fi
  19. misspell -w $(GOFILES)
  20. vet:
  21. go vet $(PACKAGES)
  22. fmt:
  23. $(GOFMT) -w $(GOFILES)
  24. .PHONY: fmt-check
  25. fmt-check:
  26. # get all go files and run go fmt on them
  27. @diff=$$($(GOFMT) -d $(GOFILES)); \
  28. if [ -n "$$diff" ]; then \
  29. echo "Please run 'make fmt' and commit the result:"; \
  30. echo "$${diff}"; \
  31. exit 1; \
  32. fi;
  33. $(CMD):
  34. if [ $@ = "gateway" ]; then \
  35. GO111MODULE=on go build -ldflags "-X main.BinaryName=gateway -X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=$(VERSION)" \
  36. -o bin/gateway/falcon-gateway ./modules/transfer ; \
  37. else \
  38. GO111MODULE=on go build -ldflags "-X main.BinaryName=$@ -X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=$(VERSION)" \
  39. -o bin/$@/falcon-$@ ./modules/$@ ; \
  40. fi
  41. .PHONY: $(TARGET)
  42. $(TARGET): $(GOFILES)
  43. GO111MODULE=on go build -ldflags "-X main.BinaryName=Open-Falcon -X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=$(VERSION)" -o open-falcon
  44. checkbin: bin/ config/ open-falcon
  45. pack: checkbin
  46. @if [ -e out ] ; then rm -rf out; fi
  47. @mkdir out
  48. @$(foreach var,$(CMD),mkdir -p ./out/$(var)/bin;)
  49. @$(foreach var,$(CMD),mkdir -p ./out/$(var)/config;)
  50. @$(foreach var,$(CMD),mkdir -p ./out/$(var)/logs;)
  51. @$(foreach var,$(CMD),cp ./config/$(var).json ./out/$(var)/config/cfg.json;)
  52. @$(foreach var,$(CMD),cp ./bin/$(var)/falcon-$(var) ./out/$(var)/bin;)
  53. @cp -r ./modules/agent/public ./out/agent/
  54. @(cd ./out && ln -s ./agent/public ./public)
  55. @(cd ./out && mkdir -p ./agent/plugin && ln -s ./agent/plugin ./plugin)
  56. @cp -r ./modules/api/data ./out/api/
  57. @mkdir out/graph/data
  58. @bash ./config/confgen.sh
  59. @cp $(TARGET) ./out/$(TARGET)
  60. tar -C out -zcf open-falcon-v$(VERSION).tar.gz .
  61. @rm -rf out
  62. pack4docker: checkbin
  63. @if [ -e out ] ; then rm -rf out; fi
  64. @mkdir out
  65. @$(foreach var,$(CMD),mkdir -p ./out/$(var)/bin;)
  66. @$(foreach var,$(CMD),mkdir -p ./out/$(var)/config;)
  67. @$(foreach var,$(CMD),mkdir -p ./out/$(var)/logs;)
  68. @$(foreach var,$(CMD),cp ./config/$(var).json ./out/$(var)/config/cfg.json;)
  69. @$(foreach var,$(CMD),cp ./bin/$(var)/falcon-$(var) ./out/$(var)/bin;)
  70. @if expr "$(CMD)" : "agent" > /dev/null; then \
  71. (cp -r ./modules/agent/public ./out/agent/); \
  72. (cd ./out && ln -s ./agent/public ./public); \
  73. (cd ./out && mkdir -p ./agent/plugin && ln -s ./agent/plugin ./plugin); \
  74. fi
  75. @if expr "$(CMD)" : "api" > /dev/null; then \
  76. cp -r ./modules/api/data ./out/api/; \
  77. fi
  78. @if expr "$(CMD)" : "graph" > /dev/null; then \
  79. mkdir out/graph/data; \
  80. fi
  81. @cp ./docker/ctrl.sh ./out/ && chmod +x ./out/ctrl.sh
  82. @cp $(TARGET) ./out/$(TARGET)
  83. tar -C out -zcf open-falcon-v$(VERSION).tar.gz .
  84. @rm -rf out
  85. .PHONY: test
  86. test:
  87. @go test ./modules/api/test
  88. clean:
  89. @rm -rf ./bin
  90. @rm -rf ./out
  91. @rm -rf ./$(TARGET)
  92. @rm -rf open-falcon-v$(VERSION).tar.gz
  93. .PHONY: clean all agent aggregator graph hbs judge nodata transfer gateway api alarm