Makefile 4.6 KB

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