erlc.mk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  21. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  22. > ebin/$(PROJECT).app
  23. define compile_erl
  24. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  25. -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
  26. endef
  27. define compile_xyrl
  28. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  29. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  30. @rm ebin/*.erl
  31. endef
  32. ifneq ($(wildcard src/),)
  33. ebin/$(PROJECT).app::
  34. @mkdir -p ebin/
  35. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  36. $(shell find src -type f -name \*.core)
  37. $(if $(strip $?),$(call compile_erl,$?))
  38. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  39. $(shell find src -type f -name \*.yrl)
  40. $(if $(strip $?),$(call compile_xyrl,$?))
  41. endif
  42. clean:: clean-app
  43. # Extra targets.
  44. clean-app:
  45. $(gen_verbose) rm -rf ebin/