1 # 2 # Nanoapp NanoPB Makefile 3 # 4 # Include this file in your nanoapp Makefile to produce pb.c and pb.h for .proto 5 # files specified in the NANOPB_SRCS variable. The produced pb.c files are 6 # automatically be added to the COMMON_SRCS variable for the nanoapp build. 7 8 include $(CHRE_PREFIX)/build/defs.mk 9 10 # Environment Checks ########################################################### 11 12 ifneq ($(NANOPB_SRCS),) 13 ifeq ($(NANOPB_PREFIX),) 14 $(error "NANOPB_SRCS is non-empty. You must supply a NANOPB_PREFIX environment \ 15 variable containing a path to the nanopb project. Example: \ 16 export NANOPB_PREFIX=$$HOME/path/to/nanopb/nanopb-c") 17 endif 18 endif 19 20 # Generated Source Files ####################################################### 21 22 NANOPB_GEN_PATH = $(OUT)/nanopb_gen 23 24 NANOPB_GEN_SRCS += $(patsubst %.proto, $(NANOPB_GEN_PATH)/%.pb.c, \ 25 $(NANOPB_SRCS)) 26 27 ifneq ($(NANOPB_GEN_SRCS),) 28 COMMON_CFLAGS += -I$(NANOPB_PREFIX) 29 COMMON_CFLAGS += -I$(NANOPB_GEN_PATH) 30 COMMON_CFLAGS += $(addprefix -I$(NANOPB_GEN_PATH)/, $(NANOPB_INCLUDES)) 31 32 COMMON_SRCS += $(NANOPB_PREFIX)/pb_common.c 33 COMMON_SRCS += $(NANOPB_PREFIX)/pb_decode.c 34 COMMON_SRCS += $(NANOPB_PREFIX)/pb_encode.c 35 endif 36 37 # NanoPB Compiler Flags ######################################################## 38 39 ifneq ($(NANOPB_GEN_SRCS),) 40 COMMON_CFLAGS += -DPB_NO_PACKED_STRUCTS=1 41 endif 42 43 # NanoPB Generator Setup ####################################################### 44 45 NANOPB_GENERATOR_SRCS = $(NANOPB_PREFIX)/generator/proto/nanopb_pb2.py 46 NANOPB_GENERATOR_SRCS += $(NANOPB_PREFIX)/generator/proto/plugin_pb2.py 47 48 $(NANOPB_GENERATOR_SRCS): 49 cd $(NANOPB_PREFIX)/generator/proto && make 50 51 # Generate NanoPB Sources ###################################################### 52 53 COMMON_SRCS += $(NANOPB_GEN_SRCS) 54 55 NANOPB_PROTOC = $(NANOPB_PREFIX)/generator/protoc-gen-nanopb 56 57 $(NANOPB_GEN_PATH)/%.pb.c $(NANOPB_GEN_PATH)/%.pb.h: %.proto \ 58 $(wildcard %.options) \ 59 $(NANOPB_GENERATOR_SRCS) 60 mkdir -p $(dir $@) 61 protoc --plugin=protoc-gen-nanopb=$(NANOPB_PROTOC) \ 62 --nanopb_out=$(NANOPB_GEN_PATH) $< 63