Makefile 5.0 KB

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