erlydtl.mk 997 B

12345678910111213141516171819202122232425262728293031
  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. # Verbosity.
  6. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  7. dtl_verbose = $(dtl_verbose_$(V))
  8. # Core targets.
  9. define compile_erlydtl
  10. $(dtl_verbose) $(ERL) -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
  11. Compile = fun(F) -> \
  12. S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
  13. (0) -> filename:basename(F, ".dtl") \
  14. end, \
  15. Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
  16. {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
  17. end, \
  18. _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
  19. halt().'
  20. endef
  21. ifneq ($(wildcard src/),)
  22. ebin/$(PROJECT).app:: $(sort $(call core_find,templates/,*.dtl))
  23. $(if $(strip $?),$(call compile_erlydtl,$?))
  24. endif