core.mk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  2. #
  3. # Permission to use, copy, modify, and/or distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. .PHONY: all deps app rel docs tests clean distclean help erlang-mk
  15. ERLANG_MK_VERSION = 1
  16. # Core configuration.
  17. PROJECT ?= $(notdir $(CURDIR))
  18. PROJECT := $(strip $(PROJECT))
  19. # Verbosity.
  20. V ?= 0
  21. gen_verbose_0 = @echo " GEN " $@;
  22. gen_verbose = $(gen_verbose_$(V))
  23. # "erl" command.
  24. ERL = erl +A0 -noinput -boot start_clean
  25. # Core targets.
  26. ifneq ($(words $(MAKECMDGOALS)),1)
  27. .NOTPARALLEL:
  28. endif
  29. all::
  30. @$(MAKE) --no-print-directory deps
  31. @$(MAKE) --no-print-directory app
  32. # @todo Plugin stuff creeping inside Core, not good.
  33. ifneq ($(wildcard $(RELX_CONFIG)),)
  34. @$(MAKE) --no-print-directory rel
  35. endif
  36. clean::
  37. $(gen_verbose) rm -f erl_crash.dump
  38. distclean:: clean
  39. help::
  40. @printf "%s\n" \
  41. "erlang.mk (version $(ERLANG_MK_VERSION)) is distributed under the terms of the ISC License." \
  42. "Copyright (c) 2013-2014 Loïc Hoguin <essen@ninenines.eu>" \
  43. "" \
  44. "Usage: [V=1] make [-jNUM] [target]" \
  45. "" \
  46. "Core targets:" \
  47. " all Run deps, app and rel targets in that order" \
  48. " deps Fetch dependencies (if needed) and compile them" \
  49. " app Compile the project" \
  50. " rel Build a release for this project, if applicable" \
  51. " docs Build the documentation for this project" \
  52. " tests Run the tests for this project" \
  53. " clean Delete temporary and output files from most targets" \
  54. " distclean Delete all temporary and output files" \
  55. " help Display this help and exit" \
  56. "" \
  57. "The target clean only removes files that are commonly removed." \
  58. "Dependencies and releases are left untouched." \
  59. "" \
  60. "Setting V=1 when calling make enables verbose mode." \
  61. "Parallel execution is supported through the -j Make flag."
  62. # Core functions.
  63. ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
  64. define core_http_get
  65. wget --no-check-certificate -O $(1) $(2)|| rm $(1)
  66. endef
  67. else
  68. define core_http_get
  69. $(ERL) -eval 'ssl:start(), inets:start(), case httpc:request(get, {"$(2)", []}, [{autoredirect, true}], []) of {ok, {{_, 200, _}, _, Body}} -> case file:write_file("$(1)", Body) of ok -> ok; {error, R1} -> halt(R1) end; {error, R2} -> halt(R2) end, halt(0).'
  70. endef
  71. endif
  72. # Automated update.
  73. ERLANG_MK_BUILD_CONFIG ?= build.config
  74. ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
  75. erlang-mk:
  76. git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
  77. if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR); fi
  78. cd $(ERLANG_MK_BUILD_DIR) && make
  79. cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
  80. rm -rf $(ERLANG_MK_BUILD_DIR)