relx.mk 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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("$(RELX_CONFIG)"),
  43. {release, {Name, Vsn}, _} = lists:keyfind(release, 1, Config),
  44. io:format("~s ~s", [Name, Vsn]),
  45. halt(0).
  46. endef
  47. RELX_REL := $(shell $(call erlang,$(get_relx_release.erl)))
  48. RELX_REL_NAME := $(word 1,$(RELX_REL))
  49. RELX_REL_VSN := $(word 2,$(RELX_REL))
  50. run: all
  51. $(verbose) $(RELX_OUTPUT_DIR)/$(RELX_REL_NAME)/bin/$(RELX_REL_NAME) console
  52. help::
  53. $(verbose) printf "%s\n" "" \
  54. "Relx targets:" \
  55. " run Compile the project, build the release and run it"
  56. endif