Makefile 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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.17.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)/fail-on-old-otp-version.escript
  32. @$(SCRIPTS)/ensure-rebar3.sh $(REBAR_VERSION)
  33. $(REBAR): ensure-rebar3
  34. .PHONY: get-dashboard
  35. get-dashboard:
  36. @$(SCRIPTS)/get-dashboard.sh
  37. .PHONY: eunit
  38. eunit: $(REBAR)
  39. @ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
  40. .PHONY: proper
  41. proper: $(REBAR)
  42. @ENABLE_COVER_COMPILE=1 $(REBAR) proper -d test/props -c
  43. .PHONY: ct
  44. ct: $(REBAR) conf-segs
  45. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name $(CT_NODE_NAME) -c -v
  46. APPS=$(shell $(CURDIR)/scripts/find-apps.sh)
  47. ## app/name-ct targets are intended for local tests hence cover is not enabled
  48. .PHONY: $(APPS:%=%-ct)
  49. define gen-app-ct-target
  50. $1-ct: conf-segs
  51. $(REBAR) ct --name $(CT_NODE_NAME) -v --suite $(shell $(CURDIR)/scripts/find-suites.sh $1)
  52. endef
  53. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  54. ## apps/name-prop targets
  55. .PHONY: $(APPS:%=%-prop)
  56. define gen-app-prop-target
  57. $1-prop:
  58. $(REBAR) proper -d test/props -v -m $(shell $(CURDIR)/scripts/find-props.sh $1)
  59. endef
  60. $(foreach app,$(APPS),$(eval $(call gen-app-prop-target,$(app))))
  61. .PHONY: ct-suite
  62. ct-suite: $(REBAR)
  63. ifneq ($(TESTCASE),)
  64. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --case $(TESTCASE)
  65. else ifneq ($(GROUP),)
  66. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE) --group $(GROUP)
  67. else
  68. $(REBAR) ct -v --readable=false --name $(CT_NODE_NAME) --suite $(SUITE)
  69. endif
  70. .PHONY: cover
  71. cover: $(REBAR)
  72. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  73. .PHONY: coveralls
  74. coveralls: $(REBAR)
  75. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  76. .PHONY: $(REL_PROFILES)
  77. $(REL_PROFILES:%=%): $(REBAR) get-dashboard conf-segs
  78. @$(REBAR) as $(@) do release
  79. ## Not calling rebar3 clean because
  80. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  81. ## 2. it's slow
  82. ## NOTE: this does not force rebar3 to fetch new version dependencies
  83. ## make clean-all to delete all fetched dependencies for a fresh start-over
  84. .PHONY: clean $(PROFILES:%=clean-%)
  85. clean: $(PROFILES:%=clean-%)
  86. $(PROFILES:%=clean-%):
  87. @if [ -d _build/$(@:clean-%=%) ]; then \
  88. rm rebar.lock \
  89. rm -rf _build/$(@:clean-%=%)/rel; \
  90. $(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; \
  91. $(FIND) _build/$(@:clean-%=%) -type l -delete; \
  92. fi
  93. .PHONY: clean-all
  94. clean-all:
  95. @rm -f rebar.lock
  96. @rm -rf _build
  97. .PHONY: deps-all
  98. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  99. @make clean # ensure clean at the end
  100. ## deps-<profile> is used in CI scripts to download deps and the
  101. ## share downloads between CI steps and/or copied into containers
  102. ## which may not have the right credentials
  103. .PHONY: $(PROFILES:%=deps-%)
  104. $(PROFILES:%=deps-%): $(REBAR) get-dashboard
  105. @$(REBAR) as $(@:deps-%=%) get-deps
  106. @rm -f rebar.lock
  107. .PHONY: xref
  108. xref: $(REBAR)
  109. @$(REBAR) as check xref
  110. .PHONY: dialyzer
  111. dialyzer: $(REBAR)
  112. @$(REBAR) as check dialyzer
  113. COMMON_DEPS := $(REBAR) get-dashboard conf-segs
  114. ## rel target is to create release package without relup
  115. .PHONY: $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel)
  116. $(REL_PROFILES:%=%-rel) $(PKG_PROFILES:%=%-rel): $(COMMON_DEPS)
  117. @$(BUILD) $(subst -rel,,$(@)) rel
  118. ## relup target is to create relup instructions
  119. .PHONY: $(REL_PROFILES:%=%-relup)
  120. define gen-relup-target
  121. $1-relup: $(COMMON_DEPS)
  122. @$(BUILD) $1 relup
  123. endef
  124. ALL_ZIPS = $(REL_PROFILES)
  125. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-relup-target,$(zt))))
  126. ## zip target is to create a release package .zip with relup
  127. .PHONY: $(REL_PROFILES:%=%-zip)
  128. define gen-zip-target
  129. $1-zip: $1-relup
  130. @$(BUILD) $1 zip
  131. endef
  132. ALL_ZIPS = $(REL_PROFILES)
  133. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-zip-target,$(zt))))
  134. ## A pkg target depend on a regular release
  135. .PHONY: $(PKG_PROFILES)
  136. define gen-pkg-target
  137. $1: $1-rel
  138. @$(BUILD) $1 pkg
  139. endef
  140. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  141. .PHONY: run
  142. run: $(PROFILE) quickrun
  143. .PHONY: quickrun
  144. quickrun:
  145. ./_build/$(PROFILE)/rel/emqx/bin/emqx console
  146. ## docker target is to create docker instructions
  147. .PHONY: $(REL_PROFILES:%=%-docker)
  148. define gen-docker-target
  149. $1-docker: $(COMMON_DEPS)
  150. @$(BUILD) $1 docker
  151. endef
  152. ALL_ZIPS = $(REL_PROFILES)
  153. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-docker-target,$(zt))))
  154. ## emqx-docker-testing
  155. ## emqx-enterprise-docker-testing
  156. ## is to directly copy a unzipped zip-package to a
  157. ## base image such as ubuntu20.04. Mostly for testing
  158. .PHONY: $(REL_PROFILES:%=%-docker-testing)
  159. define gen-docker-target-testing
  160. $1-docker-testing: $(COMMON_DEPS)
  161. @$(BUILD) $1 docker-testing
  162. endef
  163. ALL_ZIPS = $(REL_PROFILES)
  164. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-docker-target-testing,$(zt))))
  165. conf-segs:
  166. @scripts/merge-config.escript