relx.mk 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (c) 2013-2015, 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 distclean-relx-rel distclean-relx run
  4. # Configuration.
  5. RELX_CONFIG ?= $(CURDIR)/relx.config
  6. RELX ?= $(CURDIR)/relx
  7. export RELX
  8. RELX_URL ?= https://github.com/erlware/relx/releases/download/v2.0.0/relx
  9. RELX_OPTS ?=
  10. RELX_OUTPUT_DIR ?= _rel
  11. ifeq ($(firstword $(RELX_OPTS)),-o)
  12. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  13. else
  14. RELX_OPTS += -o $(RELX_OUTPUT_DIR)
  15. endif
  16. # Core targets.
  17. ifeq ($(IS_DEP),)
  18. ifneq ($(wildcard $(RELX_CONFIG)),)
  19. rel:: distclean-relx-rel relx-rel
  20. endif
  21. endif
  22. distclean:: distclean-relx-rel distclean-relx
  23. # Plugin-specific targets.
  24. define relx_fetch
  25. $(call core_http_get,$(RELX),$(RELX_URL))
  26. chmod +x $(RELX)
  27. endef
  28. $(RELX):
  29. @$(call relx_fetch)
  30. relx-rel: $(RELX)
  31. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  32. distclean-relx-rel:
  33. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  34. distclean-relx:
  35. $(gen_verbose) rm -rf $(RELX)
  36. # Run target.
  37. ifeq ($(wildcard $(RELX_CONFIG)),)
  38. run:
  39. else
  40. define get_relx_release.erl
  41. {ok, Config} = file:consult("$(RELX_CONFIG)"),
  42. {release, {Name, _}, _} = lists:keyfind(release, 1, Config),
  43. io:format("~s", [Name]),
  44. halt(0).
  45. endef
  46. RELX_RELEASE = `$(call erlang,$(get_relx_release.erl))`
  47. run: all
  48. @$(RELX_OUTPUT_DIR)/$(RELX_RELEASE)/bin/$(RELX_RELEASE) console
  49. help::
  50. @printf "%s\n" "" \
  51. "Relx targets:" \
  52. " run Compile the project, build the release and run it"
  53. endif