relx.mk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. # Copyright (c) 2013-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. ifeq ($(filter relx,$(BUILD_DEPS) $(DEPS) $(REL_DEPS)),relx)
  4. .PHONY: relx-rel relx-relup distclean-relx-rel run
  5. # Configuration.
  6. RELX_CONFIG ?= $(CURDIR)/relx.config
  7. RELX_OUTPUT_DIR ?= _rel
  8. RELX_REL_EXT ?=
  9. RELX_TAR ?= 1
  10. ifdef SFX
  11. RELX_TAR = 1
  12. endif
  13. # Core targets.
  14. ifeq ($(IS_DEP),)
  15. ifneq ($(wildcard $(RELX_CONFIG)),)
  16. rel:: relx-rel
  17. relup:: relx-relup
  18. endif
  19. endif
  20. distclean:: distclean-relx-rel
  21. # Plugin-specific targets.
  22. define relx_release.erl
  23. {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
  24. {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
  25. Vsn = case Vsn0 of
  26. {cmd, Cmd} -> os:cmd(Cmd);
  27. semver -> "";
  28. {semver, _} -> "";
  29. VsnStr -> Vsn0
  30. end,
  31. {ok, _} = relx:build_release(#{name => Name, vsn => Vsn}, Config),
  32. halt(0).
  33. endef
  34. define relx_tar.erl
  35. {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
  36. {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
  37. Vsn = case Vsn0 of
  38. {cmd, Cmd} -> os:cmd(Cmd);
  39. semver -> "";
  40. {semver, _} -> "";
  41. VsnStr -> Vsn0
  42. end,
  43. {ok, _} = relx:build_tar(#{name => Name, vsn => Vsn}, Config),
  44. halt(0).
  45. endef
  46. define relx_relup.erl
  47. {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
  48. {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
  49. Vsn = case Vsn0 of
  50. {cmd, Cmd} -> os:cmd(Cmd);
  51. semver -> "";
  52. {semver, _} -> "";
  53. VsnStr -> Vsn0
  54. end,
  55. {ok, _} = relx:build_relup(Name, Vsn, undefined, Config ++ [{output_dir, "$(RELX_OUTPUT_DIR)"}]),
  56. halt(0).
  57. endef
  58. relx-rel: rel-deps app
  59. $(call erlang,$(call relx_release.erl),-pa ebin/)
  60. $(verbose) $(MAKE) relx-post-rel
  61. ifeq ($(RELX_TAR),1)
  62. $(call erlang,$(call relx_tar.erl),-pa ebin/)
  63. endif
  64. relx-relup: rel-deps app
  65. $(call erlang,$(call relx_release.erl),-pa ebin/)
  66. $(MAKE) relx-post-rel
  67. $(call erlang,$(call relx_relup.erl),-pa ebin/)
  68. ifeq ($(RELX_TAR),1)
  69. $(call erlang,$(call relx_tar.erl),-pa ebin/)
  70. endif
  71. distclean-relx-rel:
  72. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  73. # Default hooks.
  74. relx-post-rel::
  75. $(verbose) :
  76. # Run target.
  77. ifeq ($(wildcard $(RELX_CONFIG)),)
  78. run::
  79. else
  80. define get_relx_release.erl
  81. {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
  82. {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
  83. Vsn = case Vsn0 of
  84. {cmd, Cmd} -> os:cmd(Cmd);
  85. semver -> "";
  86. {semver, _} -> "";
  87. VsnStr -> Vsn0
  88. end,
  89. Extended = case lists:keyfind(extended_start_script, 1, Config) of
  90. {_, true} -> "1";
  91. _ -> ""
  92. end,
  93. io:format("~s ~s ~s", [Name, Vsn, Extended]),
  94. halt(0).
  95. endef
  96. RELX_REL := $(shell $(call erlang,$(get_relx_release.erl)))
  97. RELX_REL_NAME := $(word 1,$(RELX_REL))
  98. RELX_REL_VSN := $(word 2,$(RELX_REL))
  99. RELX_REL_CMD := $(if $(word 3,$(RELX_REL)),console)
  100. ifeq ($(PLATFORM),msys2)
  101. RELX_REL_EXT := .cmd
  102. endif
  103. run:: all
  104. $(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME)$(RELX_REL_EXT) $(RELX_REL_CMD)
  105. ifdef RELOAD
  106. rel::
  107. $(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME)$(RELX_REL_EXT) ping
  108. $(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME)$(RELX_REL_EXT) \
  109. eval "io:format(\"~p~n\", [c:lm()])"
  110. endif
  111. help::
  112. $(verbose) printf "%s\n" "" \
  113. "Relx targets:" \
  114. " run Compile the project, build the release and run it"
  115. endif
  116. endif