Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 EMQX_DEFAULT_BUILDER = ghcr.io/emqx/emqx-builder/5.0-5:1.13.2-24.1.5-4-alpine3.14
  7. export EMQX_DEFAULT_RUNNER = alpine:3.14
  8. export OTP_VSN ?= $(shell $(CURDIR)/scripts/get-otp-vsn.sh)
  9. export ELIXIR_VSN ?= $(shell $(CURDIR)/scripts/get-elixir-vsn.sh)
  10. export EMQX_DASHBOARD_VERSION ?= v0.19.0
  11. export DOCKERFILE := deploy/docker/Dockerfile
  12. export DOCKERFILE_TESTING := deploy/docker/Dockerfile.testing
  13. ifeq ($(OS),Windows_NT)
  14. export REBAR_COLOR=none
  15. FIND=/usr/bin/find
  16. else
  17. FIND=find
  18. endif
  19. PROFILE ?= emqx
  20. REL_PROFILES := emqx emqx-edge emqx-enterprise
  21. PKG_PROFILES := emqx-pkg emqx-edge-pkg emqx-enterprise-pkg
  22. PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
  23. CT_NODE_NAME ?= 'test@127.0.0.1'
  24. export REBAR_GIT_CLONE_OPTIONS += --depth=1
  25. .PHONY: default
  26. default: $(REBAR) $(PROFILE)
  27. .PHONY: all
  28. all: $(REBAR) $(PROFILES)
  29. .PHONY: ensure-rebar3
  30. ensure-rebar3:
  31. @$(SCRIPTS)/ensure-rebar3.sh $(REBAR_VERSION)
  32. .PHONY: ensure-hex
  33. ensure-hex:
  34. @mix local.hex --if-missing --force
  35. .PHONY: ensure-mix-rebar3
  36. ensure-mix-rebar3: $(REBAR)
  37. @mix local.rebar rebar3 $(CURDIR)/rebar3 --if-missing --force
  38. .PHONY: ensure-mix-rebar
  39. ensure-mix-rebar: $(REBAR)
  40. @mix local.rebar --if-missing --force
  41. .PHONY: mix-deps-get
  42. mix-deps-get: $(ELIXIR_COMMON_DEPS)
  43. @mix deps.get
  44. $(REBAR): ensure-rebar3
  45. .PHONY: get-dashboard
  46. get-dashboard:
  47. @$(SCRIPTS)/get-dashboard.sh
  48. .PHONY: eunit
  49. eunit: $(REBAR)
  50. @ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
  51. .PHONY: proper
  52. proper: $(REBAR)
  53. @ENABLE_COVER_COMPILE=1 $(REBAR) proper -d test/props -c
  54. .PHONY: ct
  55. ct: $(REBAR) conf-segs
  56. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name $(CT_NODE_NAME) -c -v
  57. .PHONY: static_checks
  58. static_checks:
  59. @$(REBAR) as check do xref, dialyzer, ct --suite apps/emqx/test/emqx_static_checks --readable false
  60. APPS=$(shell $(CURDIR)/scripts/find-apps.sh)
  61. ## app/name-ct targets are intended for local tests hence cover is not enabled
  62. .PHONY: $(APPS:%=%-ct)
  63. define gen-app-ct-target
  64. $1-ct: conf-segs
  65. $(REBAR) ct --name $(CT_NODE_NAME) -v --suite $(shell $(CURDIR)/scripts/find-suites.sh $1)
  66. endef
  67. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  68. ## apps/name-prop targets
  69. .PHONY: $(APPS:%=%-prop)
  70. define gen-app-prop-target
  71. $1-prop:
  72. $(REBAR) proper -d test/props -v -m $(shell $(CURDIR)/scripts/find-props.sh $1)
  73. endef
  74. $(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
  75. .PHONY: ct-suite
  76. ct-suite: $(REBAR)
  77. ifneq ($(TESTCASE),)
  78. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  79. else ifneq ($(GROUP),)
  80. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  81. else
  82. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE)
  83. endif
  84. .PHONY: cover
  85. cover: $(REBAR)
  86. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  87. .PHONY: coveralls
  88. coveralls: $(REBAR)
  89. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  90. COMMON_DEPS := $(REBAR) get-dashboard conf-segs
  91. ELIXIR_COMMON_DEPS := ensure-hex ensure-mix-rebar3 ensure-mix-rebar
  92. .PHONY: $(REL_PROFILES)
  93. $(REL_PROFILES:%=%): $(COMMON_DEPS)
  94. @$(REBAR) as $(@) do release
  95. ## Not calling rebar3 clean because
  96. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  97. ## 2. it's slow
  98. ## NOTE: this does not force rebar3 to fetch new version dependencies
  99. ## make clean-all to delete all fetched dependencies for a fresh start-over
  100. .PHONY: clean $(PROFILES:%=clean-%)
  101. clean: $(PROFILES:%=clean-%)
  102. $(PROFILES:%=clean-%):
  103. @if [ -d _build/$(@:clean-%=%) ]; then \
  104. rm rebar.lock \
  105. rm -rf _build/$(@:clean-%=%)/rel; \
  106. $(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; \
  107. $(FIND) _build/$(@:clean-%=%) -type l -delete; \
  108. fi
  109. .PHONY: clean-all
  110. clean-all:
  111. @rm -f rebar.lock
  112. @rm -rf _build
  113. .PHONY: deps-all
  114. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  115. @make clean # ensure clean at the end
  116. ## deps-<profile> is used in CI scripts to download deps and the
  117. ## share downloads between CI steps and/or copied into containers
  118. ## which may not have the right credentials
  119. .PHONY: $(PROFILES:%=deps-%)
  120. $(PROFILES:%=deps-%): $(COMMON_DEPS)
  121. @$(REBAR) as $(@:deps-%=%) get-deps
  122. @rm -f rebar.lock
  123. .PHONY: xref
  124. xref: $(REBAR)
  125. @$(REBAR) as check xref
  126. .PHONY: dialyzer
  127. dialyzer: $(REBAR)
  128. @$(REBAR) as check dialyzer
  129. ## rel target is to create release package without relup
  130. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  131. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  132. @$(BUILD) $(subst -rel,,$(@)) rel
  133. ## relup target is to create relup instructions
  134. .PHONY: $(REL_PROFILES:%=%-relup)
  135. define gen-relup-target
  136. $1-relup: $(COMMON_DEPS)
  137. @$(BUILD) $1 relup
  138. endef
  139. ALL_TGZS = $(REL_PROFILES)
  140. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-relup-target,$(zt))))
  141. ## tgz target is to create a release package .tar.gz with relup
  142. .PHONY: $(REL_PROFILES:%=%-tgz)
  143. define gen-tgz-target
  144. $1-tgz: $1-relup
  145. @$(BUILD) $1 tgz
  146. endef
  147. ALL_TGZS = $(REL_PROFILES)
  148. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-tgz-target,$(zt))))
  149. ## A pkg target depend on a regular release
  150. .PHONY: $(PKG_PROFILES)
  151. define gen-pkg-target
  152. $1: $1-rel
  153. @$(BUILD) $1 pkg
  154. endef
  155. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  156. .PHONY: run
  157. run: $(PROFILE) quickrun
  158. .PHONY: quickrun
  159. quickrun:
  160. ./_build/$(PROFILE)/rel/emqx/bin/emqx console
  161. ## docker target is to create docker instructions
  162. .PHONY: $(REL_PROFILES:%=%-docker) $(REL_PROFILES:%=%-elixir-docker)
  163. define gen-docker-target
  164. $1-docker: $(COMMON_DEPS)
  165. @$(BUILD) $1 docker
  166. endef
  167. ALL_DOCKERS = $(REL_PROFILES) $(REL_PROFILES:%=%-elixir)
  168. $(foreach zt,$(ALL_DOCKERS),$(eval $(call gen-docker-target,$(zt))))
  169. ## emqx-docker-testing
  170. ## emqx-enterprise-docker-testing
  171. ## is to directly copy a extracted tgz-package to a
  172. ## base image such as ubuntu20.04. Mostly for testing
  173. .PHONY: $(REL_PROFILES:%=%-docker-testing)
  174. define gen-docker-target-testing
  175. $1-docker-testing: $(COMMON_DEPS)
  176. @$(BUILD) $1 docker-testing
  177. endef
  178. ALL_TGZS = $(REL_PROFILES)
  179. $(foreach zt,$(ALL_TGZS),$(eval $(call gen-docker-target-testing,$(zt))))
  180. .PHONY:
  181. conf-segs:
  182. @scripts/merge-config.escript
  183. ## elixir target is to create release packages using Elixir's Mix
  184. .PHONY: $(REL_PROFILES:%=%-elixir) $(PKG_PROFILES:%=%-elixir)
  185. $(REL_PROFILES:%=%-elixir) $(PKG_PROFILES:%=%-elixir): $(COMMON_DEPS) $(ELIXIR_COMMON_DEPS) mix-deps-get
  186. @$(BUILD) $(subst -elixir,,$(@)) elixir
  187. .PHONY: $(REL_PROFILES:%=%-elixirpkg)
  188. define gen-elixirpkg-target
  189. # the Elixir places the tar in a different path than Rebar3
  190. $1-elixirpkg: $1-pkg-elixir
  191. @env TAR_PKG_DIR=_build/$1-pkg \
  192. IS_ELIXIR=yes \
  193. $(BUILD) $1-pkg pkg
  194. endef
  195. $(foreach pt,$(REL_PROFILES),$(eval $(call gen-elixirpkg-target,$(pt))))
  196. .PHONY: $(REL_PROFILES:%=%-elixir-tgz)
  197. define gen-elixir-tgz-target
  198. $1-elixir-tgz: $(COMMON_DEPS) $(ELIXIR_COMMON_DEPS) mix-deps-get
  199. @env IS_ELIXIR=yes $(BUILD) $1 tgz
  200. endef
  201. ALL_ELIXIR_TGZS = $(REL_PROFILES)
  202. $(foreach tt,$(ALL_ELIXIR_TGZS),$(eval $(call gen-elixir-tgz-target,$(tt))))