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. define erlydtl_compile.erl
  12. [begin
  13. Module0 = case "$(strip $(DTL_FULL_PATH))" of
  14. "" ->
  15. filename:basename(F, ".dtl");
  16. _ ->
  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. ifdef DTL_FULL_PATH
  31. BEAM_FILES += $(addprefix ebin/,$(patsubst %.dtl,%_dtl.beam,$(subst /,_,$(DTL_FILES:$(DTL_PATH)%=%))))
  32. else
  33. BEAM_FILES += $(addprefix ebin/,$(patsubst %.dtl,%_dtl.beam,$(notdir $(DTL_FILES))))
  34. endif
  35. # Rebuild templates when the Makefile changes.
  36. $(DTL_FILES): $(MAKEFILE_LIST)
  37. @touch $@
  38. ebin/$(PROJECT).app:: $(DTL_FILES)
  39. $(gen_verbose) mkdir -p ebin/
  40. $(if $(strip $?),\
  41. $(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$?,-pa ebin/ $(DEPS_DIR)/erlydtl/ebin/)))
  42. endif