Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. $(shell $(CURDIR)/scripts/git-hooks-init.sh)
  2. REBAR_VERSION = 3.14.3-emqx-5
  3. REBAR = $(CURDIR)/rebar3
  4. BUILD = $(CURDIR)/build
  5. SCRIPTS = $(CURDIR)/scripts
  6. export PKG_VSN ?= $(shell $(CURDIR)/pkg-vsn.sh)
  7. export EMQX_DESC ?= EMQ X
  8. export EMQX_CE_DASHBOARD_VERSION ?= v4.3.0-beta.1
  9. ifeq ($(OS),Windows_NT)
  10. export REBAR_COLOR=none
  11. endif
  12. PROFILE ?= emqx
  13. REL_PROFILES := emqx emqx-edge
  14. PKG_PROFILES := emqx-pkg emqx-edge-pkg
  15. PROFILES := $(REL_PROFILES) $(PKG_PROFILES) default
  16. export REBAR_GIT_CLONE_OPTIONS += --depth=1
  17. .PHONY: default
  18. default: $(REBAR) $(PROFILE)
  19. .PHONY: all
  20. all: $(REBAR) $(PROFILES)
  21. .PHONY: ensure-rebar3
  22. ensure-rebar3:
  23. @$(SCRIPTS)/fail-on-old-otp-version.escript
  24. @$(SCRIPTS)/ensure-rebar3.sh $(REBAR_VERSION)
  25. $(REBAR): ensure-rebar3
  26. .PHONY: get-dashboard
  27. get-dashboard:
  28. @$(SCRIPTS)/get-dashboard.sh
  29. .PHONY: eunit
  30. eunit: $(REBAR)
  31. @ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c
  32. .PHONY: proper
  33. proper: $(REBAR)
  34. @ENABLE_COVER_COMPILE=1 $(REBAR) as test proper -d test/props -c
  35. .PHONY: ct
  36. ct: $(REBAR)
  37. @ENABLE_COVER_COMPILE=1 $(REBAR) ct --name 'test@127.0.0.1' -c -v
  38. APPS=$(shell $(CURDIR)/scripts/find-apps.sh)
  39. ## app/name-ct targets are intended for local tests hence cover is not enabled
  40. .PHONY: $(APPS:%=%-ct)
  41. define gen-app-ct-target
  42. $1-ct:
  43. $(REBAR) ct --name 'test@127.0.0.1' -v --suite $(shell $(CURDIR)/scripts/find-suites.sh $1)
  44. endef
  45. $(foreach app,$(APPS),$(eval $(call gen-app-ct-target,$(app))))
  46. .PHONY: cover
  47. cover: $(REBAR)
  48. @ENABLE_COVER_COMPILE=1 $(REBAR) cover
  49. .PHONY: coveralls
  50. coveralls: $(REBAR)
  51. @ENABLE_COVER_COMPILE=1 $(REBAR) as test coveralls send
  52. .PHONY: $(REL_PROFILES)
  53. $(REL_PROFILES:%=%): $(REBAR) get-dashboard
  54. @$(REBAR) as $(@) do compile,release
  55. ## Not calling rebar3 clean because
  56. ## 1. rebar3 clean relies on rebar3, meaning it reads config, fetches dependencies etc.
  57. ## 2. it's slow
  58. ## NOTE: this does not force rebar3 to fetch new version dependencies
  59. ## make clean-all to delete all fetched dependencies for a fresh start-over
  60. .PHONY: clean $(PROFILES:%=clean-%)
  61. clean: $(PROFILES:%=clean-%)
  62. $(PROFILES:%=clean-%):
  63. @if [ -d _build/$(@:clean-%=%) ]; then \
  64. rm -rf _build/$(@:clean-%=%)/rel; \
  65. 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; \
  66. fi
  67. .PHONY: clean-all
  68. clean-all:
  69. @rm -rf _build
  70. .PHONY: deps-all
  71. deps-all: $(REBAR) $(PROFILES:%=deps-%)
  72. ## deps-<profile> is used in CI scripts to download deps and the
  73. ## share downloads between CI steps and/or copied into containers
  74. ## which may not have the right credentials
  75. .PHONY: $(PROFILES:%=deps-%)
  76. $(PROFILES:%=deps-%): $(REBAR) get-dashboard
  77. @$(REBAR) as $(@:deps-%=%) get-deps
  78. .PHONY: xref
  79. xref: $(REBAR)
  80. @$(REBAR) as check xref
  81. .PHONY: dialyzer
  82. dialyzer: $(REBAR)
  83. @$(REBAR) as check dialyzer
  84. .PHONY: $(REL_PROFILES:%=relup-%)
  85. $(REL_PROFILES:%=relup-%): $(REBAR)
  86. ifneq ($(OS),Windows_NT)
  87. @$(BUILD) $(@:relup-%=%) relup
  88. endif
  89. .PHONY: $(REL_PROFILES:%=%-tar) $(PKG_PROFILES:%=%-tar)
  90. $(REL_PROFILES:%=%-tar) $(PKG_PROFILES:%=%-tar): $(REBAR) get-dashboard $(CONF_SEGS)
  91. @$(BUILD) $(subst -tar,,$(@)) tar
  92. ## zip targets depend on the corresponding relup and tar artifacts
  93. .PHONY: $(REL_PROFILES:%=%-zip)
  94. define gen-zip-target
  95. $1-zip: relup-$1 $1-tar
  96. @$(BUILD) $1 zip
  97. endef
  98. ALL_ZIPS = $(REL_PROFILES) $(PKG_PROFILES)
  99. $(foreach zt,$(ALL_ZIPS),$(eval $(call gen-zip-target,$(zt))))
  100. ## A pkg target depend on a regular release profile zip to include relup,
  101. ## and also a -pkg suffixed profile tar (without relup) for making deb/rpm package
  102. .PHONY: $(PKG_PROFILES)
  103. define gen-pkg-target
  104. $1: $(subst -pkg,,$1)-zip $1-tar
  105. @$(BUILD) $1 pkg
  106. endef
  107. $(foreach pt,$(PKG_PROFILES),$(eval $(call gen-pkg-target,$(pt))))
  108. include docker.mk