dialyzer.mk 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (c) 2013-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: plt distclean-plt dialyze
  4. # Configuration.
  5. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  6. export DIALYZER_PLT
  7. PLT_APPS ?=
  8. DIALYZER_DIRS ?= --src -r $(wildcard src) $(ALL_APPS_DIRS)
  9. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions -Wunmatched_returns # -Wunderspecs
  10. # Core targets.
  11. check:: dialyze
  12. distclean:: distclean-plt
  13. help::
  14. $(verbose) printf "%s\n" "" \
  15. "Dialyzer targets:" \
  16. " plt Build a PLT file for this project" \
  17. " dialyze Analyze the project using Dialyzer"
  18. # Plugin-specific targets.
  19. define filter_opts.erl
  20. Opts = init:get_plain_arguments(),
  21. {Filtered, _} = lists:foldl(fun
  22. (O, {Os, true}) -> {[O|Os], false};
  23. (O = "-D", {Os, _}) -> {[O|Os], true};
  24. (O = [\\$$-, \\$$D, _ | _], {Os, _}) -> {[O|Os], false};
  25. (O = "-I", {Os, _}) -> {[O|Os], true};
  26. (O = [\\$$-, \\$$I, _ | _], {Os, _}) -> {[O|Os], false};
  27. (O = "-pa", {Os, _}) -> {[O|Os], true};
  28. (_, Acc) -> Acc
  29. end, {[], false}, Opts),
  30. io:format("~s~n", [string:join(lists:reverse(Filtered), " ")]),
  31. halt().
  32. endef
  33. $(DIALYZER_PLT): deps app
  34. $(verbose) dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(OTP_DEPS) $(LOCAL_DEPS) $(DEPS)
  35. plt: $(DIALYZER_PLT)
  36. distclean-plt:
  37. $(gen_verbose) rm -f $(DIALYZER_PLT)
  38. ifneq ($(wildcard $(DIALYZER_PLT)),)
  39. dialyze:
  40. else
  41. dialyze: $(DIALYZER_PLT)
  42. endif
  43. $(verbose) dialyzer --no_native `$(ERL) -eval "$(subst $(newline),,$(subst ",\",$(call filter_opts.erl)))" -extra $(ERLC_OPTS)` $(DIALYZER_DIRS) $(DIALYZER_OPTS)