erlc.mk 2.9 KB

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