relx.mk 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. ifneq ($(wildcard $(RELX_CONFIG)),)
  18. rel:: distclean-relx-rel relx-rel
  19. endif
  20. distclean:: distclean-relx-rel distclean-relx
  21. # Plugin-specific targets.
  22. define relx_fetch
  23. $(call core_http_get,$(RELX),$(RELX_URL))
  24. chmod +x $(RELX)
  25. endef
  26. $(RELX):
  27. @$(call relx_fetch)
  28. relx-rel: $(RELX)
  29. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  30. distclean-relx-rel:
  31. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  32. distclean-relx:
  33. $(gen_verbose) rm -rf $(RELX)
  34. # Run target.
  35. ifeq ($(wildcard $(RELX_CONFIG)),)
  36. run:
  37. else
  38. define get_relx_release.erl
  39. {ok, Config} = file:consult("$(RELX_CONFIG)"),
  40. {release, {Name, _}, _} = lists:keyfind(release, 1, Config),
  41. io:format("~s", [Name]),
  42. halt(0).
  43. endef
  44. RELX_RELEASE = `$(call erlang,$(get_relx_release.erl))`
  45. run: all
  46. @$(RELX_OUTPUT_DIR)/$(RELX_RELEASE)/bin/$(RELX_RELEASE) console
  47. help::
  48. @printf "%s\n" "" \
  49. "Relx targets:" \
  50. " run Compile the project, build the release and run it"
  51. endif