protobuffs.mk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. ifneq ($(filter gpb protobuffs,$(BUILD_DEPS) $(DEPS)),)
  9. PROTO_FILES := $(filter %.proto,$(ALL_SRC_FILES))
  10. ERL_FILES += $(addprefix src/,$(patsubst %.proto,%_pb.erl,$(notdir $(PROTO_FILES))))
  11. ifeq ($(PROTO_FILES),)
  12. $(ERLANG_MK_TMP)/last-makefile-change-protobuffs:
  13. $(verbose) :
  14. else
  15. # Rebuild proto files when the Makefile changes.
  16. # We exclude $(PROJECT).d to avoid a circular dependency.
  17. $(ERLANG_MK_TMP)/last-makefile-change-protobuffs: $(filter-out $(PROJECT).d,$(MAKEFILE_LIST)) | $(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. ifeq ($(filter gpb,$(BUILD_DEPS) $(DEPS)),)
  25. define compile_proto.erl
  26. [begin
  27. protobuffs_compile:generate_source(F, [
  28. {output_include_dir, "./include"},
  29. {output_src_dir, "./src"}])
  30. end || F <- string:tokens("$1", " ")],
  31. halt().
  32. endef
  33. else
  34. define compile_proto.erl
  35. [begin
  36. gpb_compile:file(F, [
  37. $(foreach i,$(sort $(dir $(PROTO_FILES))),{i$(comma) "$i"}$(comma))
  38. {include_as_lib, true},
  39. {module_name_suffix, "_pb"},
  40. {o_hrl, "./include"},
  41. {o_erl, "./src"},
  42. {use_packages, true}
  43. ])
  44. end || F <- string:tokens("$1", " ")],
  45. halt().
  46. endef
  47. endif
  48. ifneq ($(PROTO_FILES),)
  49. $(PROJECT).d:: $(PROTO_FILES)
  50. $(verbose) mkdir -p ebin/ include/
  51. $(if $(strip $?),$(proto_verbose) $(call erlang,$(call compile_proto.erl,$?)))
  52. endif
  53. endif
  54. endif