erlydtl.mk 1.4 KB

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