Makefile 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # See LICENSE for licensing information.
  2. PROJECT = cowboy
  3. ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
  4. +warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
  5. # Dependencies.
  6. dep_ranch = https://github.com/extend/ranch.git 0.8.1
  7. DEPS_DIR ?= $(CURDIR)/deps
  8. export DEPS_DIR
  9. define get_dep =
  10. @mkdir -p $(DEPS_DIR)
  11. git clone -n -- $(word 1,$(dep_$(1))) $(DEPS_DIR)/$(1)
  12. cd $(DEPS_DIR)/$(1) ; git checkout -q $(word 2,$(dep_$(1)))
  13. endef
  14. # Makefile 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 autobahn build-plt dialyze
  24. # Application.
  25. all: deps app
  26. clean-all: clean clean-deps clean-docs
  27. $(gen_verbose) rm -rf .$(PROJECT).plt $(DEPS_DIR) logs
  28. MODULES = $(shell ls src/*.erl | sed 's/src\///;s/\.erl/,/' | sed '$$s/.$$//')
  29. app: ebin/$(PROJECT).app
  30. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  31. | sed 's/{modules, \[\]}/{modules, \[$(MODULES)\]}/' \
  32. > ebin/$(PROJECT).app
  33. COMPILE_FIRST = src/cowboy_middleware.erl src/cowboy_sub_protocol.erl
  34. ebin/$(PROJECT).app: src/*.erl
  35. @mkdir -p ebin/
  36. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ -pa ebin/ \
  37. $(COMPILE_FIRST) $?
  38. clean:
  39. $(gen_verbose) rm -rf ebin/ test/*.beam erl_crash.dump
  40. # Dependencies.
  41. $(DEPS_DIR)/ranch:
  42. $(call get_dep,ranch)
  43. deps: $(DEPS_DIR)/ranch
  44. @$(MAKE) -C $(DEPS_DIR)/ranch
  45. clean-deps:
  46. -@$(MAKE) -C $(DEPS_DIR)/ranch clean
  47. # Documentation.
  48. docs: clean-docs
  49. $(gen_verbose) erl -noshell \
  50. -eval 'edoc:application($(PROJECT), ".", []), init:stop().'
  51. clean-docs:
  52. $(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
  53. # Tests.
  54. build-tests:
  55. $(gen_verbose) erlc -v $(ERLC_OPTS) \
  56. -o test/ test/*.erl test/*/*.erl -pa ebin/
  57. CT_RUN = ct_run \
  58. -no_auto_compile \
  59. -noshell \
  60. -pa ebin $(DEPS_DIR)/*/ebin \
  61. -dir test \
  62. -logdir logs
  63. # -cover test/cover.spec
  64. tests: ERLC_OPTS += -DTEST=1 +'{parse_transform, eunit_autoexport}'
  65. tests: clean clean-deps deps app build-tests
  66. @mkdir -p logs/
  67. @$(CT_RUN) -suite eunit_SUITE http_SUITE ws_SUITE
  68. $(gen_verbose) rm -f test/*.beam
  69. autobahn: clean clean-deps deps app build-tests
  70. @mkdir -p logs/
  71. @$(CT_RUN) -suite autobahn_SUITE
  72. # Dialyzer.
  73. build-plt: deps app
  74. @dialyzer --build_plt --output_plt .$(PROJECT).plt \
  75. --apps erts kernel stdlib crypto public_key ssl $(DEPS_DIR)/ranch
  76. dialyze:
  77. @dialyzer --src src --plt .$(PROJECT).plt --no_native \
  78. -Werror_handling -Wrace_conditions -Wunmatched_returns # -Wunderspecs