protobuffs.mk 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 ($(PROTO_FILES),)
  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)) | $(ERLANG_MK_TMP)
  17. $(verbose) if test -f $@; then \
  18. touch $(PROTO_FILES); \
  19. fi
  20. $(verbose) touch $@
  21. $(PROJECT).d:: $(ERLANG_MK_TMP)/last-makefile-change-protobuffs
  22. endif
  23. ifeq ($(filter gpb,$(BUILD_DEPS) $(DEPS)),)
  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. else
  33. define compile_proto.erl
  34. [begin
  35. gpb_compile:file(F, [
  36. {include_as_lib, true},
  37. {module_name_suffix, "_pb"},
  38. {o_hrl, "./include"},
  39. {o_erl, "./src"}])
  40. end || F <- string:tokens("$1", " ")],
  41. halt().
  42. endef
  43. endif
  44. ifneq ($(PROTO_FILES),)
  45. $(PROJECT).d:: $(PROTO_FILES)
  46. $(verbose) mkdir -p ebin/ include/
  47. $(if $(strip $?),$(proto_verbose) $(call erlang,$(call compile_proto.erl,$?)))
  48. endif
  49. endif