erlang.mk 3.8 KB

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