relx.mk 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. .PHONY: relx-rel relx-relup distclean-relx-rel run
  4. # Configuration.
  5. RELX ?= $(ERLANG_MK_TMP)/relx
  6. RELX_CONFIG ?= $(CURDIR)/relx.config
  7. RELX_URL ?= https://github.com/erlware/relx/releases/download/v3.23.0/relx
  8. RELX_OPTS ?=
  9. RELX_OUTPUT_DIR ?= _rel
  10. RELX_REL_EXT ?=
  11. RELX_TAR ?= 1
  12. ifdef SFX
  13. RELX_TAR = 1
  14. endif
  15. ifeq ($(firstword $(RELX_OPTS)),-o)
  16. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  17. else
  18. RELX_OPTS += -o $(RELX_OUTPUT_DIR)
  19. endif
  20. # Core targets.
  21. ifeq ($(IS_DEP),)
  22. ifneq ($(wildcard $(RELX_CONFIG)),)
  23. rel:: relx-rel
  24. relup:: relx-relup
  25. endif
  26. endif
  27. distclean:: distclean-relx-rel
  28. # Plugin-specific targets.
  29. $(RELX):
  30. $(verbose) mkdir -p $(ERLANG_MK_TMP)
  31. $(gen_verbose) $(call core_http_get,$(RELX),$(RELX_URL))
  32. $(verbose) chmod +x $(RELX)
  33. relx-rel: $(RELX) rel-deps app
  34. $(verbose) $(RELX) -c $(RELX_CONFIG) $(RELX_OPTS) release $(if $(filter 1,$(RELX_TAR)),tar)
  35. relx-relup: $(RELX) rel-deps app
  36. $(verbose) $(RELX) -c $(RELX_CONFIG) $(RELX_OPTS) release relup $(if $(filter 1,$(RELX_TAR)),tar)
  37. distclean-relx-rel:
  38. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  39. # Run target.
  40. ifeq ($(wildcard $(RELX_CONFIG)),)
  41. run::
  42. else
  43. define get_relx_release.erl
  44. {ok, Config} = file:consult("$(call core_native_path,$(RELX_CONFIG))"),
  45. {release, {Name, Vsn0}, _} = lists:keyfind(release, 1, Config),
  46. Vsn = case Vsn0 of
  47. {cmd, Cmd} -> os:cmd(Cmd);
  48. semver -> "";
  49. {semver, _} -> "";
  50. VsnStr -> Vsn0
  51. end,
  52. io:format("~s ~s", [Name, Vsn]),
  53. halt(0).
  54. endef
  55. RELX_REL := $(shell $(call erlang,$(get_relx_release.erl)))
  56. RELX_REL_NAME := $(word 1,$(RELX_REL))
  57. RELX_REL_VSN := $(word 2,$(RELX_REL))
  58. ifeq ($(PLATFORM),msys2)
  59. RELX_REL_EXT := .cmd
  60. endif
  61. run:: all
  62. $(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME)$(RELX_REL_EXT) console
  63. help::
  64. $(verbose) printf "%s\n" "" \
  65. "Relx targets:" \
  66. " run Compile the project, build the release and run it"
  67. endif