core.mk 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. # Copyright (c) 2013-2015, 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 install-docs tests check 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:: deps
  30. @$(MAKE) --no-print-directory app
  31. @$(MAKE) --no-print-directory rel
  32. # Noop to avoid a Make warning when there's nothing to do.
  33. rel::
  34. @echo -n
  35. check:: clean app tests
  36. clean:: clean-crashdump
  37. clean-crashdump:
  38. ifneq ($(wildcard erl_crash.dump),)
  39. $(gen_verbose) rm -f erl_crash.dump
  40. endif
  41. distclean:: clean
  42. help::
  43. @printf "%s\n" \
  44. "erlang.mk (version $(ERLANG_MK_VERSION)) is distributed under the terms of the ISC License." \
  45. "Copyright (c) 2013-2014 Loïc Hoguin <essen@ninenines.eu>" \
  46. "" \
  47. "Usage: [V=1] make [-jNUM] [target]" \
  48. "" \
  49. "Core targets:" \
  50. " all Run deps, app and rel targets in that order" \
  51. " deps Fetch dependencies (if needed) and compile them" \
  52. " app Compile the project" \
  53. " rel Build a release for this project, if applicable" \
  54. " docs Build the documentation for this project" \
  55. " install-docs Install the man pages for this project" \
  56. " tests Run the tests for this project" \
  57. " check Compile and run all tests and analysis for this project" \
  58. " clean Delete temporary and output files from most targets" \
  59. " distclean Delete all temporary and output files" \
  60. " help Display this help and exit" \
  61. "" \
  62. "The target clean only removes files that are commonly removed." \
  63. "Dependencies and releases are left untouched." \
  64. "" \
  65. "Setting V=1 when calling make enables verbose mode." \
  66. "Parallel execution is supported through the -j Make flag."
  67. # Core functions.
  68. define newline
  69. endef
  70. define erlang
  71. $(ERL) -eval "$(subst $(newline),,$(subst ",\",$(1)))"
  72. endef
  73. ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
  74. define core_http_get
  75. wget --no-check-certificate -O $(1) $(2)|| rm $(1)
  76. endef
  77. else
  78. define core_http_get.erl
  79. ssl:start(),
  80. inets:start(),
  81. case httpc:request(get, {"$(2)", []}, [{autoredirect, true}], []) of
  82. {ok, {{_, 200, _}, _, Body}} ->
  83. case file:write_file("$(1)", Body) of
  84. ok -> ok;
  85. {error, R1} -> halt(R1)
  86. end;
  87. {error, R2} ->
  88. halt(R2)
  89. end,
  90. halt(0).
  91. endef
  92. define core_http_get
  93. $(call erlang,$(call core_http_get.erl,$(1),$(2)))
  94. endef
  95. endif
  96. # Automated update.
  97. ERLANG_MK_BUILD_CONFIG ?= build.config
  98. ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
  99. erlang-mk:
  100. git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
  101. if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR); fi
  102. cd $(ERLANG_MK_BUILD_DIR) && make
  103. cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
  104. rm -rf $(ERLANG_MK_BUILD_DIR)