protobuffs.mk 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (c) 2015-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. # Verbosity.
  4. proto_verbose_0 = @echo " PROTO " $(filter %.proto,$(?F));
  5. proto_verbose = $(proto_verbose_$(V))
  6. # Core targets.
  7. ifneq ($(wildcard src/),)
  8. PROTO_FILES := $(filter %.proto,$(ALL_SRC_FILES))
  9. ERL_FILES += $(addprefix src/,$(patsubst %.proto,%_pb.erl,$(notdir $(PROTO_FILES))))
  10. ifeq ($(words $(PROTO_FILES)),0)
  11. $(ERLANG_MK_TMP)/last-makefile-change-protobuffs:
  12. $(verbose) :
  13. else
  14. # Rebuild proto files when the Makefile changes.
  15. # We exclude $(PROJECT).d to avoid a circular dependency.
  16. $(ERLANG_MK_TMP)/last-makefile-change-protobuffs: $(filter-out $(PROJECT).d,$(MAKEFILE_LIST))
  17. $(verbose) mkdir -p $(ERLANG_MK_TMP)
  18. $(verbose) if test -f $@; then \
  19. touch $(PROTO_FILES); \
  20. fi
  21. $(verbose) touch $@
  22. $(PROJECT).d:: $(ERLANG_MK_TMP)/last-makefile-change-protobuffs
  23. endif
  24. define compile_proto.erl
  25. [begin
  26. protobuffs_compile:generate_source(F,
  27. [{output_include_dir, "./include"},
  28. {output_src_dir, "./src"}])
  29. end || F <- string:tokens("$1", " ")],
  30. halt().
  31. endef
  32. $(PROJECT).d:: $(PROTO_FILES)
  33. $(verbose) mkdir -p ebin/ include/
  34. $(if $(strip $?),$(proto_verbose) $(call erlang,$(call compile_proto.erl,$?)))
  35. endif