Makefile 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. $(shell $(CURDIR)/scripts/git-hooks-init.sh)
  2. REBAR_VERSION = 3.16.1-emqx-1
  3. REBAR = $(CURDIR)/rebar3
  4. BUILD = $(CURDIR)/build
  5. SCRIPTS = $(CURDIR)/scripts
  6. export PKG_VSN ?= $(shell $(CURDIR)/pkg-vsn.sh)
  7. export EMQX_DESC ?= EMQ X
  8. export EMQX_DASHBOARD_VERSION ?= v5.0.0-beta.18
  9. ifeq ($(OS),Windows_NT)
  10. export REBAR_COLOR=none
  11. endif
  12. PROFILE ?= emqx
  13. REL_PROFILES := emqx emqx-edge
  14. PKG_PROFILES := emqx-pkg emqx-edge-pkg
  15. PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
  16. CT_NODE_NAME ?= 'test@127.0.0.1'
  17. export REBAR_GIT_CLONE_OPTIONS += --depth=1
  18. .PHONY: default
  19. default: $(REBAR) $(PROFILE)
  20. .PHONY: all
  21. all: $(REBAR) $(PROFILES)
  22. .PHONY: ensure-rebar3
  23. ensure-rebar3:
  24. @$(SCRIPTS)/fail-on-old-otp-version.escript
  25. @$(SCRIPTS)/ensure-rebar3.sh $(REBAR_VERSION)
  26. $(REBAR): ensure-rebar3
  27. .PHONY: get-dashboard
  28. get-dashboard:
  29. @$(SCRIPTS)/get-dashboard.sh
  30. .PHONY: eunit
  31. eunit: $(REBAR)
  32. @ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
  33. .PHONY: proper
  34. proper: $(REBAR)
  35. @ENABLE_COVER_COMPILE=1 $(REBAR) proper -d test/props -c
  36. .PHONY: ct
  37. ct: $(REBAR) conf-segs
  38. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name $(CT_NODE_NAME) -c -v
  39. APPS=$(shell $(CURDIR)/scripts/find-apps.sh)
  40. ## app/name-ct targets are intended for local tests hence cover is not enabled
  41. .PHONY: $(APPS:%=%-ct)
  42. define gen-app-ct-target
  43. $1-ct:
  44. $(REBAR) ct --name $(CT_NODE_NAME) -v --suite $(shell $(CURDIR)/scripts/find-suites.sh $1)
  45. endef
  46. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  47. ## apps/name-prop targets
  48. .PHONY: $(APPS:%=%-prop)
  49. define gen-app-prop-target
  50. $1-prop:
  51. $(REBAR) proper -d test/props -v -m $(shell $(CURDIR)/scripts/find-props.sh $1)
  52. endef
  53. $(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
  54. .PHONY: ct-suite
  55. ct-suite: $(REBAR)
  56. ifneq ($(TESTCASE),)
  57. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  58. else ifneq ($(GROUP),)
  59. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  60. else
  61. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE)
  62. endif
  63. .PHONY: cover
  64. cover: $(REBAR)
  65. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  66. .PHONY: coveralls
  67. coveralls: $(REBAR)
  68. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  69. .PHONY: $(REL_PROFILES)
  70. $(REL_PROFILES:%=%): $(REBAR) get-dashboard conf-segs
  71. @$(REBAR) as $(@) do compile,release
  72. ## Not calling rebar3 clean because
  73. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  74. ## 2. it's slow
  75. ## NOTE: this does not force rebar3 to fetch new version dependencies
  76. ## make clean-all to delete all fetched dependencies for a fresh start-over
  77. .PHONY: clean $(PROFILES:%=clean-%)
  78. clean: $(PROFILES:%=clean-%)
  79. $(PROFILES:%=clean-%):
  80. @if [ -d _build/$(@:clean-%=%) ]; then \
  81. rm -rf _build/$(@:clean-%=%)/rel; \
  82. find _build/$(@:clean-%=%) -name '*.beam' -o -name '*.so' -o -name '*.app' -o -name '*.appup' -o -name '*.o' -o -name '*.d' -type f | xargs rm -f; \
  83. fi
  84. .PHONY: clean-all
  85. clean-all:
  86. @rm -f rebar.lock
  87. @rm -rf _build
  88. .PHONY: deps-all
  89. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  90. ## deps-<profile> is used in CI scripts to download deps and the
  91. ## share downloads between CI steps and/or copied into containers
  92. ## which may not have the right credentials
  93. .PHONY: $(PROFILES:%=deps-%)
  94. $(PROFILES:%=deps-%): $(REBAR) get-dashboard
  95. @$(REBAR) as $(@:deps-%=%) get-deps
  96. .PHONY: xref
  97. xref: $(REBAR)
  98. @$(REBAR) as check xref
  99. .PHONY: dialyzer
  100. dialyzer: $(REBAR)
  101. @$(REBAR) as check dialyzer
  102. COMMON_DEPS := $(REBAR) get-dashboard conf-segs
  103. ## rel target is to create release package without relup
  104. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  105. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  106. @$(BUILD) $(subst -rel,,$(@)) rel
  107. ## relup target is to create relup instructions
  108. .PHONY: $(REL_PROFILES:%=%-relup)
  109. define gen-relup-target
  110. $1-relup: $(COMMON_DEPS)
  111. @$(BUILD) $1 relup
  112. endef
  113. ALL_ZIPS = $(REL_PROFILES)
  114. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-relup-target,$(zt))))
  115. ## zip target is to create a release package .zip with relup
  116. .PHONY: $(REL_PROFILES:%=%-zip)
  117. define gen-zip-target
  118. $1-zip: $1-relup
  119. @$(BUILD) $1 zip
  120. endef
  121. ALL_ZIPS = $(REL_PROFILES)
  122. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-zip-target,$(zt))))
  123. ## A pkg target depend on a regular release
  124. .PHONY: $(PKG_PROFILES)
  125. define gen-pkg-target
  126. $1: $1-rel
  127. @$(BUILD) $1 pkg
  128. endef
  129. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  130. .PHONY: run
  131. run: $(PROFILE) quickrun
  132. .PHONY: quickrun
  133. quickrun:
  134. ./_build/$(PROFILE)/rel/emqx/bin/emqx console
  135. ## docker target is to create docker instructions
  136. .PHONY: $(REL_PROFILES:%=%-docker)
  137. define gen-docker-target
  138. $1-docker: $(COMMON_DEPS)
  139. @$(BUILD) $1 docker
  140. endef
  141. ALL_ZIPS = $(REL_PROFILES)
  142. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-docker-target,$(zt))))
  143. conf-segs:
  144. @scripts/merge-config.escript