erlydtl.mk 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2013-2015, 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. # Verbosity.
  8. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  9. dtl_verbose = $(dtl_verbose_$(V))
  10. # Core targets.
  11. DTL_FILES = $(sort $(call core_find,$(DTL_PATH),*.dtl))
  12. ifneq ($(DTL_FILES),)
  13. ifdef DTL_FULL_PATH
  14. BEAM_FILES += $(addprefix ebin/,$(patsubst %.dtl,%_dtl.beam,$(subst /,_,$(DTL_FILES:$(DTL_PATH)%=%))))
  15. else
  16. BEAM_FILES += $(addprefix ebin/,$(patsubst %.dtl,%_dtl.beam,$(notdir $(DTL_FILES))))
  17. endif
  18. # Rebuild templates when the Makefile changes.
  19. $(DTL_FILES): $(MAKEFILE_LIST)
  20. @touch $@
  21. define erlydtl_compile.erl
  22. [begin
  23. Module0 = case "$(strip $(DTL_FULL_PATH))" of
  24. "" ->
  25. filename:basename(F, ".dtl");
  26. _ ->
  27. "$(DTL_PATH)" ++ F2 = filename:rootname(F, ".dtl"),
  28. re:replace(F2, "/", "_", [{return, list}, global])
  29. end,
  30. Module = list_to_atom(string:to_lower(Module0) ++ "$(DTL_SUFFIX)"),
  31. case erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) of
  32. ok -> ok;
  33. {ok, _} -> ok
  34. end
  35. end || F <- string:tokens("$(1)", " ")],
  36. halt().
  37. endef
  38. ebin/$(PROJECT).app:: $(DTL_FILES) | ebin/
  39. $(if $(strip $?),\
  40. $(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$?),-pa ebin/ $(DEPS_DIR)/erlydtl/ebin/))
  41. endif