Makefile 4.9 KB

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