erlc.mk 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (c) 2013-2014, 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: clean-app
  4. # Configuration.
  5. ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
  6. +warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
  7. COMPILE_FIRST ?=
  8. COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
  9. # Verbosity.
  10. appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
  11. appsrc_verbose = $(appsrc_verbose_$(V))
  12. erlc_verbose_0 = @echo " ERLC " $(filter %.erl %.core,$(?F));
  13. erlc_verbose = $(erlc_verbose_$(V))
  14. xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
  15. xyrl_verbose = $(xyrl_verbose_$(V))
  16. # Core targets.
  17. app:: ebin/$(PROJECT).app
  18. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  19. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  20. @if [ -z "$$(grep -E '^[^%]*{modules,[[:space:]]*\[\]}' src/$(PROJECT).app.src)" ]; then \
  21. echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \
  22. exit 1; \
  23. fi
  24. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  25. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  26. > ebin/$(PROJECT).app
  27. define compile_erl
  28. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  29. -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
  30. endef
  31. define compile_xyrl
  32. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  33. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  34. @rm ebin/*.erl
  35. endef
  36. ifneq ($(wildcard src/),)
  37. ebin/$(PROJECT).app::
  38. @mkdir -p ebin/
  39. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  40. $(shell find src -type f -name \*.core)
  41. $(if $(strip $?),$(call compile_erl,$?))
  42. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  43. $(shell find src -type f -name \*.yrl)
  44. $(if $(strip $?),$(call compile_xyrl,$?))
  45. endif
  46. clean:: clean-app
  47. # Extra targets.
  48. clean-app:
  49. $(gen_verbose) rm -rf ebin/