erlc.mk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. ERLC_EXCLUDE ?=
  10. ERLC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .erl,$(ERLC_EXCLUDE)))
  11. # Verbosity.
  12. appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
  13. appsrc_verbose = $(appsrc_verbose_$(V))
  14. erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
  15. $(filter %.erl %.core,$(?F)));
  16. erlc_verbose = $(erlc_verbose_$(V))
  17. xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
  18. xyrl_verbose = $(xyrl_verbose_$(V))
  19. # Core targets.
  20. app:: erlc-include ebin/$(PROJECT).app
  21. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  22. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  23. @if [ -z "$$(grep -E '^[^%]*{modules,' src/$(PROJECT).app.src)" ]; then \
  24. echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \
  25. exit 1; \
  26. fi
  27. $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
  28. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  29. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  30. | sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
  31. > ebin/$(PROJECT).app
  32. define compile_erl
  33. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  34. -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),\
  35. $(COMPILE_FIRST_PATHS) $(1))
  36. endef
  37. define compile_xyrl
  38. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  39. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  40. @rm ebin/*.erl
  41. endef
  42. ifneq ($(wildcard src/),)
  43. ebin/$(PROJECT).app::
  44. @mkdir -p ebin/
  45. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  46. $(shell find src -type f -name \*.core)
  47. $(if $(strip $?),$(call compile_erl,$?))
  48. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  49. $(shell find src -type f -name \*.yrl)
  50. $(if $(strip $?),$(call compile_xyrl,$?))
  51. endif
  52. clean:: clean-app
  53. # Extra targets.
  54. erlc-include:
  55. -@if [ -d ebin/ ]; then \
  56. find include/ src/ -type f -name \*.hrl -newer ebin -exec touch $(shell find src/ -type f -name "*.erl") \; 2>/dev/null || printf ''; \
  57. fi
  58. clean-app:
  59. $(gen_verbose) rm -rf ebin/