erlydtl.mk 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 ?= 0
  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. define erlydtl_compile.erl
  12. [begin
  13. Module0 = case $(DTL_FULL_PATH) of
  14. 0 ->
  15. filename:basename(F, ".dtl");
  16. 1 ->
  17. "$(DTL_PATH)" ++ F2 = filename:rootname(F, ".dtl"),
  18. re:replace(F2, "/", "_", [{return, list}, global])
  19. end,
  20. Module = list_to_atom(string:to_lower(Module0) ++ "$(DTL_SUFFIX)"),
  21. case erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) of
  22. ok -> ok;
  23. {ok, _} -> ok
  24. end
  25. end || F <- string:tokens("$(1)", " ")],
  26. halt().
  27. endef
  28. ifneq ($(wildcard src/),)
  29. DTL_FILES = $(sort $(call core_find,$(DTL_PATH),*.dtl))
  30. DTL_ERL_FILES = $(addprefix src/,$(patsubst %.dtl,%_dtl.erl,$(notdir $(DTL_FILES))))
  31. ERL_FILES += $(DTL_ERL_FILES)
  32. ebin/$(PROJECT).app:: $(DTL_FILES)
  33. $(if $(strip $?),\
  34. $(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$?,-pa ebin/ $(DEPS_DIR)/erlydtl/ebin/)))
  35. endif