Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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/4.4-2:23.3.4.9-3-alpine3.14
  7. export EMQX_DEFAULT_RUNNER = alpine:3.14
  8. export OTP_VSN ?= $(shell $(CURDIR)/scripts/get-otp-vsn.sh)
  9. export PKG_VSN ?= $(shell $(CURDIR)/pkg-vsn.sh)
  10. export EMQX_DASHBOARD_VERSION ?= v0.10.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. endif
  16. PROFILE ?= emqx
  17. REL_PROFILES := emqx emqx-edge emqx-enterprise
  18. PKG_PROFILES := emqx-pkg emqx-edge-pkg emqx-enterprise-pkg
  19. PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
  20. CT_NODE_NAME ?= 'test@127.0.0.1'
  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) conf-segs
  42. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name $(CT_NODE_NAME) -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: conf-segs
  48. $(REBAR) ct --name $(CT_NODE_NAME) -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: ct-suite
  59. ct-suite: $(REBAR)
  60. ifneq ($(TESTCASE),)
  61. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  62. else ifneq ($(GROUP),)
  63. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  64. else
  65. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE)
  66. endif
  67. .PHONY: cover
  68. cover: $(REBAR)
  69. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  70. .PHONY: coveralls
  71. coveralls: $(REBAR)
  72. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  73. .PHONY: $(REL_PROFILES)
  74. $(REL_PROFILES:%=%): $(REBAR) get-dashboard conf-segs
  75. @$(REBAR) as $(@) do compile,release
  76. ## Not calling rebar3 clean because
  77. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  78. ## 2. it's slow
  79. ## NOTE: this does not force rebar3 to fetch new version dependencies
  80. ## make clean-all to delete all fetched dependencies for a fresh start-over
  81. .PHONY: clean $(PROFILES:%=clean-%)
  82. clean: $(PROFILES:%=clean-%)
  83. $(PROFILES:%=clean-%):
  84. @if [ -d _build/$(@:clean-%=%) ]; then \
  85. rm rebar.lock \
  86. rm -rf _build/$(@:clean-%=%)/rel; \
  87. 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; \
  88. find _build/$(@:clean-%=%) -type l -delete; \
  89. fi
  90. .PHONY: clean-all
  91. clean-all:
  92. @rm -f rebar.lock
  93. @rm -rf _build
  94. .PHONY: deps-all
  95. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  96. @make clean # ensure clean at the end
  97. ## deps-<profile> is used in CI scripts to download deps and the
  98. ## share downloads between CI steps and/or copied into containers
  99. ## which may not have the right credentials
  100. .PHONY: $(PROFILES:%=deps-%)
  101. $(PROFILES:%=deps-%): $(REBAR) get-dashboard
  102. @$(REBAR) as $(@:deps-%=%) get-deps
  103. @rm -f rebar.lock
  104. .PHONY: xref
  105. xref: $(REBAR)
  106. @$(REBAR) as check xref
  107. .PHONY: dialyzer
  108. dialyzer: $(REBAR)
  109. @$(REBAR) as check dialyzer
  110. COMMON_DEPS := $(REBAR) get-dashboard conf-segs
  111. ## rel target is to create release package without relup
  112. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  113. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  114. @$(BUILD) $(subst -rel,,$(@)) rel
  115. ## relup target is to create relup instructions
  116. .PHONY: $(REL_PROFILES:%=%-relup)
  117. define gen-relup-target
  118. $1-relup: $(COMMON_DEPS)
  119. @$(BUILD) $1 relup
  120. endef
  121. ALL_ZIPS = $(REL_PROFILES)
  122. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-relup-target,$(zt))))
  123. ## zip target is to create a release package .zip with relup
  124. .PHONY: $(REL_PROFILES:%=%-zip)
  125. define gen-zip-target
  126. $1-zip: $1-relup
  127. @$(BUILD) $1 zip
  128. endef
  129. ALL_ZIPS = $(REL_PROFILES)
  130. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-zip-target,$(zt))))
  131. ## A pkg target depend on a regular release
  132. .PHONY: $(PKG_PROFILES)
  133. define gen-pkg-target
  134. $1: $1-rel
  135. @$(BUILD) $1 pkg
  136. endef
  137. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  138. .PHONY: run
  139. run: $(PROFILE) quickrun
  140. .PHONY: quickrun
  141. quickrun:
  142. ./_build/$(PROFILE)/rel/emqx/bin/emqx console
  143. ## docker target is to create docker instructions
  144. .PHONY: $(REL_PROFILES:%=%-docker)
  145. define gen-docker-target
  146. $1-docker: $(COMMON_DEPS)
  147. @$(BUILD) $1 docker
  148. endef
  149. ALL_ZIPS = $(REL_PROFILES)
  150. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-docker-target,$(zt))))
  151. ## emqx-docker-testing
  152. ## emqx-enterprise-docker-testing
  153. ## is to directly copy a unzipped zip-package to a
  154. ## base image such as ubuntu20.04. Mostly for testing
  155. .PHONY: $(REL_PROFILES:%=%-docker-testing)
  156. define gen-docker-target-testing
  157. $1-docker-testing: $(COMMON_DEPS)
  158. @$(BUILD) $1 docker-testing
  159. endef
  160. ALL_ZIPS = $(REL_PROFILES)
  161. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-docker-target-testing,$(zt))))
  162. conf-segs:
  163. @scripts/merge-config.escript