nanopb.mk 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # This is an include file for Makefiles. It provides rules for building
  2. # .pb.c and .pb.h files out of .proto, as well the path to nanopb core.
  3. # Path to the nanopb root directory
  4. NANOPB_DIR := $(patsubst %/,%,$(dir $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))))
  5. # Files for the nanopb core
  6. NANOPB_CORE = $(NANOPB_DIR)/pb_encode.c $(NANOPB_DIR)/pb_decode.c $(NANOPB_DIR)/pb_common.c
  7. # Check if we are running on Windows
  8. ifdef windir
  9. WINDOWS = 1
  10. endif
  11. ifdef WINDIR
  12. WINDOWS = 1
  13. endif
  14. # Check whether to use binary version of nanopb_generator or the
  15. # system-supplied python interpreter.
  16. ifneq "$(wildcard $(NANOPB_DIR)/generator-bin)" ""
  17. # Binary package
  18. PROTOC = $(NANOPB_DIR)/generator-bin/protoc
  19. PROTOC_OPTS =
  20. else
  21. # Source only or git checkout
  22. PROTOC_OPTS =
  23. ifdef WINDOWS
  24. PROTOC = python $(NANOPB_DIR)/generator/protoc
  25. else
  26. PROTOC = $(NANOPB_DIR)/generator/protoc
  27. endif
  28. endif
  29. # Rule for building .pb.c and .pb.h
  30. %.pb.c %.pb.h: %.proto $(wildcard %.options)
  31. $(PROTOC) $(PROTOC_OPTS) --nanopb_out=. $<