erlydtl.mk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Copyright (c) 2013-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. # Configuration.
  4. DTL_FULL_PATH ?=
  5. DTL_PATH ?= templates/
  6. DTL_SUFFIX ?= _dtl
  7. DTL_OPTS ?=
  8. # Verbosity.
  9. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  10. dtl_verbose = $(dtl_verbose_$(V))
  11. # Core targets.
  12. DTL_PATH := $(abspath $(DTL_PATH))
  13. DTL_FILES := $(sort $(call core_find,$(DTL_PATH),*.dtl))
  14. ifneq ($(DTL_FILES),)
  15. DTL_NAMES = $(addsuffix $(DTL_SUFFIX),$(DTL_FILES:$(DTL_PATH)/%.dtl=%))
  16. DTL_MODULES = $(if $(DTL_FULL_PATH),$(subst /,_,$(DTL_NAMES)),$(notdir $(DTL_NAMES)))
  17. BEAM_FILES += $(addsuffix .beam,$(addprefix ebin/,$(DTL_MODULES)))
  18. ifneq ($(words $(DTL_FILES)),0)
  19. # Rebuild templates when the Makefile changes.
  20. $(ERLANG_MK_TMP)/last-makefile-change-erlydtl: $(MAKEFILE_LIST)
  21. @mkdir -p $(ERLANG_MK_TMP)
  22. @if test -f $@; then \
  23. touch $(DTL_FILES); \
  24. fi
  25. @touch $@
  26. ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change-erlydtl
  27. endif
  28. define erlydtl_compile.erl
  29. [begin
  30. Module0 = case "$(strip $(DTL_FULL_PATH))" of
  31. "" ->
  32. filename:basename(F, ".dtl");
  33. _ ->
  34. "$(DTL_PATH)/" ++ F2 = filename:rootname(F, ".dtl"),
  35. re:replace(F2, "/", "_", [{return, list}, global])
  36. end,
  37. Module = list_to_atom(string:to_lower(Module0) ++ "$(DTL_SUFFIX)"),
  38. case erlydtl:compile(F, Module, [$(DTL_OPTS)] ++ [{out_dir, "ebin/"}, return_errors]) of
  39. ok -> ok;
  40. {ok, _} -> ok
  41. end
  42. end || F <- string:tokens("$(1)", " ")],
  43. halt().
  44. endef
  45. ebin/$(PROJECT).app:: $(DTL_FILES) | ebin/
  46. $(if $(strip $?),\
  47. $(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$(call core_native_path,$?)),\
  48. -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/))
  49. endif