relx.mk 1.9 KB

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