Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. .PHONY: plugins tests
  2. PROJECT = emqx
  3. PROJECT_DESCRIPTION = EMQ X Broker
  4. DEPS = jsx gproc gen_rpc ekka esockd cowboy clique
  5. dep_jsx = hex-emqx 2.9.0
  6. dep_gproc = hex-emqx 0.8.0
  7. dep_gen_rpc = git-emqx https://github.com/emqx/gen_rpc 2.3.0
  8. dep_esockd = git-emqx https://github.com/emqx/esockd v5.4.2
  9. dep_ekka = git-emqx https://github.com/emqx/ekka v0.5.1
  10. dep_cowboy = hex-emqx 2.4.0
  11. dep_clique = git-emqx https://github.com/emqx/clique develop
  12. NO_AUTOPATCH = cuttlefish
  13. ERLC_OPTS += +debug_info -DAPPLICATION=emqx
  14. BUILD_DEPS = cuttlefish
  15. dep_cuttlefish = git-emqx https://github.com/emqx/cuttlefish v2.1.1
  16. #TEST_DEPS = emqx_ct_helplers
  17. #dep_emqx_ct_helplers = git git@github.com:emqx/emqx-ct-helpers
  18. TEST_ERLC_OPTS += +debug_info -DAPPLICATION=emqx
  19. EUNIT_OPTS = verbose
  20. # CT_SUITES = emqx_frame
  21. ## emqx_trie emqx_router emqx_frame emqx_mqtt_compat
  22. CT_SUITES = emqx emqx_client emqx_zone emqx_banned emqx_session \
  23. emqx_access emqx_broker emqx_cm emqx_frame emqx_guid emqx_inflight emqx_json \
  24. emqx_keepalive emqx_lib emqx_metrics emqx_mod emqx_mod_sup emqx_mqtt_caps \
  25. emqx_mqtt_props emqx_mqueue emqx_net emqx_pqueue emqx_router emqx_sm \
  26. emqx_tables emqx_time emqx_topic emqx_trie emqx_vm emqx_mountpoint \
  27. emqx_listeners emqx_protocol emqx_pool emqx_shared_sub emqx_bridge \
  28. emqx_hooks emqx_batch
  29. CT_NODE_NAME = emqxct@127.0.0.1
  30. CT_OPTS = -cover test/ct.cover.spec -erl_args -name $(CT_NODE_NAME)
  31. COVER = true
  32. PLT_APPS = sasl asn1 ssl syntax_tools runtime_tools crypto xmerl os_mon inets public_key ssl compiler mnesia
  33. DIALYZER_DIRS := ebin/
  34. DIALYZER_OPTS := --verbose --statistics -Werror_handling -Wrace_conditions #-Wunmatched_returns
  35. GIT_VSN := $(shell git --version | grep -oE "[0-9]{1,2}\.[0-9]{1,2}")
  36. GIT_VSN_17_COMP := $(shell echo -e "$(GIT_VSN)\n1.7" | sort -V | tail -1)
  37. ifeq ($(GIT_VSN_17_COMP),1.7)
  38. define dep_fetch_git-emqx
  39. git clone -q -n -- $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1)); \
  40. cd $(DEPS_DIR)/$(call dep_name,$(1)) && git checkout -q $(call dep_commit,$(1))
  41. endef
  42. else
  43. define dep_fetch_git-emqx
  44. git clone -q -c advice.detachedHead=false --depth 1 -b $(call dep_commit,$(1)) -- $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1))
  45. endef
  46. endif
  47. core_http_get-emqx = curl -Lf$(if $(filter-out 0,$(V)),,s)o $(call core_native_path,$1) $2
  48. define dep_fetch_hex-emqx
  49. mkdir -p $(ERLANG_MK_TMP)/hex $(DEPS_DIR)/$1; \
  50. $(call core_http_get-emqx,$(ERLANG_MK_TMP)/hex/$1.tar,\
  51. https://repo.hex.pm/tarballs/$1-$(strip $(word 2,$(dep_$1))).tar); \
  52. tar -xOf $(ERLANG_MK_TMP)/hex/$1.tar contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
  53. endef
  54. include erlang.mk
  55. clean:: gen-clean
  56. .PHONY: gen-clean
  57. gen-clean:
  58. @rm -rf bbmustache
  59. @rm -f etc/gen.emqx.conf
  60. bbmustache:
  61. $(verbose) git clone https://github.com/soranoba/bbmustache.git && cd bbmustache && ./rebar3 compile && cd ..
  62. # This hack is to generate a conf file for testing
  63. # relx overlay is used for release
  64. etc/gen.emqx.conf: bbmustache etc/emqx.conf
  65. $(verbose) erl -noshell -pa bbmustache/_build/default/lib/bbmustache/ebin -eval \
  66. "{ok, Temp} = file:read_file('etc/emqx.conf'), \
  67. {ok, Vars0} = file:consult('vars'), \
  68. Vars = [{atom_to_list(N), list_to_binary(V)} || {N, V} <- Vars0], \
  69. Targ = bbmustache:render(Temp, Vars), \
  70. ok = file:write_file('etc/gen.emqx.conf', Targ), \
  71. halt(0)."
  72. CUTTLEFISH_SCRIPT = _build/default/lib/cuttlefish/cuttlefish
  73. app.config: $(CUTTLEFISH_SCRIPT) etc/gen.emqx.conf
  74. $(verbose) $(CUTTLEFISH_SCRIPT) -l info -e etc/ -c etc/gen.emqx.conf -i priv/emqx.schema -d data/
  75. ct: app.config
  76. rebar-cover:
  77. @rebar3 cover
  78. coveralls:
  79. @rebar3 coveralls send
  80. $(CUTTLEFISH_SCRIPT): rebar-deps
  81. @if [ ! -f cuttlefish ]; then make -C _build/default/lib/cuttlefish; fi
  82. rebar-xref:
  83. @rebar3 xref
  84. rebar-deps:
  85. @rebar3 get-deps
  86. rebar-eunit: $(CUTTLEFISH_SCRIPT)
  87. @rebar3 eunit
  88. rebar-compile:
  89. @rebar3 compile
  90. rebar-ct: app.config
  91. @rebar3 as test compile
  92. @ln -s -f '../../../../etc' _build/test/lib/emqx/
  93. @ln -s -f '../../../../data' _build/test/lib/emqx/
  94. @rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',')
  95. rebar-clean:
  96. @rebar3 clean
  97. distclean::
  98. @rm -rf _build cover deps logs log data
  99. @rm -f rebar.lock compile_commands.json cuttlefish
  100. ## Below are for version consistency check during erlang.mk and rebar3 dual mode support
  101. none=
  102. space = $(none) $(none)
  103. comma = ,
  104. quote = \"
  105. curly_l = "{"
  106. curly_r = "}"
  107. dep-versions = [$(foreach dep,$(DEPS) $(BUILD_DEPS),$(curly_l)$(dep),$(quote)$(word $(words $(dep_$(dep))),$(dep_$(dep)))$(quote)$(curly_r)$(comma))[]]
  108. .PHONY: dep-vsn-check
  109. dep-vsn-check:
  110. $(verbose) erl -noshell -eval \
  111. "MkVsns = lists:sort(lists:flatten($(dep-versions))), \
  112. {ok, Conf} = file:consult('rebar.config'), \
  113. {_, Deps1} = lists:keyfind(deps, 1, Conf), \
  114. {_, Deps2} = lists:keyfind(github_emqx_deps, 1, Conf), \
  115. F = fun({N, V}) when is_list(V) -> {N, V}; ({N, {git, _, {branch, V}}}) -> {N, V} end, \
  116. RebarVsns = lists:sort(lists:map(F, Deps1 ++ Deps2)), \
  117. case {RebarVsns -- MkVsns, MkVsns -- RebarVsns} of \
  118. {[], []} -> halt(0); \
  119. {Rebar, Mk} -> erlang:error({deps_version_discrepancy, [{rebar, Rebar}, {mk, Mk}]}) \
  120. end."