erlang.mk 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright (c) 2013, 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. # Verbosity and tweaks.
  15. V ?= 0
  16. appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
  17. appsrc_verbose = $(appsrc_verbose_$(V))
  18. erlc_verbose_0 = @echo " ERLC " $(?F);
  19. erlc_verbose = $(erlc_verbose_$(V))
  20. gen_verbose_0 = @echo " GEN " $@;
  21. gen_verbose = $(gen_verbose_$(V))
  22. .PHONY: all clean-all app clean deps clean-deps docs clean-docs \
  23. build-tests tests build-plt dialyze
  24. # Deps directory.
  25. DEPS_DIR ?= $(CURDIR)/deps
  26. export DEPS_DIR
  27. ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(DEPS))
  28. # Application.
  29. ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
  30. +warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
  31. COMPILE_FIRST ?=
  32. COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
  33. all: deps app
  34. clean-all: clean clean-deps clean-docs
  35. $(gen_verbose) rm -rf .$(PROJECT).plt $(DEPS_DIR) logs
  36. MODULES = $(shell ls src/*.erl | sed 's/src\///;s/\.erl/,/' | sed '$$s/.$$//')
  37. app: ebin/$(PROJECT).app
  38. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  39. | sed 's/{modules, \[\]}/{modules, \[$(MODULES)\]}/' \
  40. > ebin/$(PROJECT).app
  41. ebin/$(PROJECT).app: src/*.erl
  42. @mkdir -p ebin/
  43. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ -pa ebin/ \
  44. $(COMPILE_FIRST_PATHS) $?
  45. clean:
  46. $(gen_verbose) rm -rf ebin/ test/*.beam erl_crash.dump
  47. # Dependencies.
  48. define get_dep =
  49. @mkdir -p $(DEPS_DIR)
  50. git clone -n -- $(word 1,$(dep_$(1))) $(DEPS_DIR)/$(1)
  51. cd $(DEPS_DIR)/$(1) ; git checkout -q $(word 2,$(dep_$(1)))
  52. endef
  53. define dep_target =
  54. $(DEPS_DIR)/$(1):
  55. $(call get_dep,$(1))
  56. endef
  57. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  58. deps: $(ALL_DEPS_DIRS)
  59. @for dep in $(ALL_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  60. clean-deps:
  61. @for dep in $(ALL_DEPS_DIRS) ; do $(MAKE) -C $$dep clean; done
  62. # Documentation.
  63. docs: clean-docs
  64. $(gen_verbose) erl -noshell \
  65. -eval 'edoc:application($(PROJECT), ".", []), init:stop().'
  66. clean-docs:
  67. $(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
  68. # Tests.
  69. build-tests:
  70. $(gen_verbose) erlc -v $(ERLC_OPTS) -o test/ \
  71. $(wildcard test/*.erl test/*/*.erl) -pa ebin/
  72. CT_RUN = ct_run \
  73. -no_auto_compile \
  74. -noshell \
  75. -pa ebin $(DEPS_DIR)/*/ebin \
  76. -dir test \
  77. -logdir logs
  78. # -cover test/cover.spec
  79. CT_SUITES ?=
  80. CT_SUITES_FULL = $(addsuffix _SUITE,$(CT_SUITES))
  81. tests: ERLC_OPTS += -DTEST=1 +'{parse_transform, eunit_autoexport}'
  82. tests: clean clean-deps deps app build-tests
  83. @mkdir -p logs/
  84. @$(CT_RUN) -suite $(CT_SUITES_FULL)
  85. $(gen_verbose) rm -f test/*.beam
  86. # Dialyzer.
  87. PLT_APPS ?=
  88. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
  89. -Wunmatched_returns # -Wunderspecs
  90. build-plt: deps app
  91. @dialyzer --build_plt --output_plt .$(PROJECT).plt \
  92. --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIR)
  93. dialyze:
  94. @dialyzer --src src --plt .$(PROJECT).plt --no_native $(DIALYZER_OPTS)