protobuffs.mk 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. {include_as_lib, true},
  38. {module_name_suffix, "_pb"},
  39. {o_hrl, "./include"},
  40. {o_erl, "./src"}])
  41. end || F <- string:tokens("$1", " ")],
  42. halt().
  43. endef
  44. endif
  45. ifneq ($(PROTO_FILES),)
  46. $(PROJECT).d:: $(PROTO_FILES)
  47. $(verbose) mkdir -p ebin/ include/
  48. $(if $(strip $?),$(proto_verbose) $(call erlang,$(call compile_proto.erl,$?)))
  49. endif
  50. endif
  51. endif