erlc.mk 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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:: erlc-include 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,' 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. $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
  25. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  26. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  27. | sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
  28. > ebin/$(PROJECT).app
  29. define compile_erl
  30. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  31. -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
  32. endef
  33. define compile_xyrl
  34. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  35. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  36. @rm ebin/*.erl
  37. endef
  38. ifneq ($(wildcard src/),)
  39. ebin/$(PROJECT).app::
  40. @mkdir -p ebin/
  41. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  42. $(shell find src -type f -name \*.core)
  43. $(if $(strip $?),$(call compile_erl,$?))
  44. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  45. $(shell find src -type f -name \*.yrl)
  46. $(if $(strip $?),$(call compile_xyrl,$?))
  47. endif
  48. clean:: clean-app
  49. # Extra targets.
  50. erlc-include:
  51. -@if [ -d ebin/ ]; then \
  52. find include/ src/ -type f -name \*.hrl -newer ebin -exec touch $(shell find src/ -type f -name "*.erl") \; 2>/dev/null || printf ''; \
  53. fi
  54. clean-app:
  55. $(gen_verbose) rm -rf ebin/