erlydtl.mk 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2013-2016, 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_PATH := $(abspath $(DTL_PATH))
  13. DTL_FILES = $(call core_find,$(DTL_PATH),*.dtl)
  14. ifneq ($(DTL_FILES),)
  15. DTL_NAMES = $(addsuffix $(DTL_SUFFIX),$(DTL_FILES:$(DTL_PATH)/%.dtl=%))
  16. DTL_MODULES = $(if $(DTL_FULL_PATH),$(subst /,_,$(DTL_NAMES)),$(notdir $(DTL_NAMES)))
  17. BEAM_FILES += $(addsuffix .beam,$(addprefix ebin/,$(DTL_MODULES)))
  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, [$(DTL_OPTS)] ++ [{out_dir, "ebin/"}, return_errors]) 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