Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. $(shell $(CURDIR)/scripts/git-hooks-init.sh)
  2. REBAR_VERSION = 3.14.3-emqx-8
  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_CE_DASHBOARD_VERSION ?= v4.3.1
  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. export REBAR_GIT_CLONE_OPTIONS += --depth=1
  17. .PHONY: default
  18. default: $(REBAR) $(PROFILE)
  19. .PHONY: all
  20. all: $(REBAR) $(PROFILES)
  21. .PHONY: ensure-rebar3
  22. ensure-rebar3:
  23. @$(SCRIPTS)/fail-on-old-otp-version.escript
  24. @$(SCRIPTS)/ensure-rebar3.sh $(REBAR_VERSION)
  25. $(REBAR): ensure-rebar3
  26. .PHONY: get-dashboard
  27. get-dashboard:
  28. @$(SCRIPTS)/get-dashboard.sh
  29. .PHONY: eunit
  30. eunit: $(REBAR)
  31. @ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
  32. .PHONY: proper
  33. proper: $(REBAR)
  34. @ENABLE_COVER_COMPILE=1 $(REBAR) proper -d test/props -c
  35. .PHONY: ct
  36. ct: $(REBAR)
  37. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name 'test@127.0.0.1' -c -v
  38. APPS=$(shell $(CURDIR)/scripts/find-apps.sh)
  39. ## app/name-ct targets are intended for local tests hence cover is not enabled
  40. .PHONY: $(APPS:%=%-ct)
  41. define gen-app-ct-target
  42. $1-ct:
  43. $(REBAR) ct --name 'test@127.0.0.1' -v --suite $(shell $(CURDIR)/scripts/find-suites.sh $1)
  44. endef
  45. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  46. ## apps/name-prop targets
  47. .PHONY: $(APPS:%=%-prop)
  48. define gen-app-prop-target
  49. $1-prop:
  50. $(REBAR) proper -d test/props -v -m $(shell $(CURDIR)/scripts/find-props.sh $1)
  51. endef
  52. $(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
  53. .PHONY: cover
  54. cover: $(REBAR)
  55. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  56. .PHONY: coveralls
  57. coveralls: $(REBAR)
  58. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  59. .PHONY: $(REL_PROFILES)
  60. $(REL_PROFILES:%=%): $(REBAR) get-dashboard
  61. @$(REBAR) as $(@) do compile,release
  62. ## Not calling rebar3 clean because
  63. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  64. ## 2. it's slow
  65. ## NOTE: this does not force rebar3 to fetch new version dependencies
  66. ## make clean-all to delete all fetched dependencies for a fresh start-over
  67. .PHONY: clean $(PROFILES:%=clean-%)
  68. clean: $(PROFILES:%=clean-%)
  69. $(PROFILES:%=clean-%):
  70. @if [ -d _build/$(@:clean-%=%) ]; then \
  71. rm -rf _build/$(@:clean-%=%)/rel; \
  72. 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; \
  73. fi
  74. .PHONY: clean-all
  75. clean-all:
  76. @rm -rf _build
  77. .PHONY: deps-all
  78. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  79. ## deps-<profile> is used in CI scripts to download deps and the
  80. ## share downloads between CI steps and/or copied into containers
  81. ## which may not have the right credentials
  82. .PHONY: $(PROFILES:%=deps-%)
  83. $(PROFILES:%=deps-%): $(REBAR) get-dashboard
  84. @$(REBAR) as $(@:deps-%=%) get-deps
  85. .PHONY: xref
  86. xref: $(REBAR)
  87. @$(REBAR) as check xref
  88. .PHONY: dialyzer
  89. dialyzer: $(REBAR)
  90. @$(REBAR) as check dialyzer
  91. COMMON_DEPS := $(REBAR) get-dashboard $(CONF_SEGS)
  92. ## rel target is to create release package without relup
  93. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  94. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  95. @$(BUILD) $(subst -rel,,$(@)) rel
  96. ## relup target is to create relup instructions
  97. .PHONY: $(REL_PROFILES:%=%-relup)
  98. define gen-relup-target
  99. $1-relup: $(COMMON_DEPS)
  100. @$(BUILD) $1 relup
  101. endef
  102. ALL_ZIPS = $(REL_PROFILES)
  103. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-relup-target,$(zt))))
  104. ## zip target is to create a release package .zip with relup
  105. .PHONY: $(REL_PROFILES:%=%-zip)
  106. define gen-zip-target
  107. $1-zip: $1-relup
  108. @$(BUILD) $1 zip
  109. endef
  110. ALL_ZIPS = $(REL_PROFILES)
  111. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-zip-target,$(zt))))
  112. ## A pkg target depend on a regular release
  113. .PHONY: $(PKG_PROFILES)
  114. define gen-pkg-target
  115. $1: $1-rel
  116. @$(BUILD) $1 pkg
  117. endef
  118. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  119. .PHONY: run
  120. run: $(PROFILE) quickrun
  121. .PHONY: quickrun
  122. quickrun:
  123. ./_build/$(PROFILE)/rel/emqx/bin/emqx console
  124. include docker.mk