erlc.mk 3.1 KB

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