From 042d4dc4a10bd9701e83ef2d28408243ddb7c5ef Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Tue, 6 May 2014 15:45:57 -0700 Subject: [PATCH 1/2] nanopb-c Change-Id: I584d0a1e228338ea4ec3e5e2875d1ed329bc37f2 --- core/binary.mk | 53 +++++++++++++++++++++++++++++++++++++++++++-- core/clear_vars.mk | 2 +- core/definitions.mk | 11 ++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index 1e313ffe4..487faca38 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -466,10 +466,17 @@ my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/% ALL_GENERATED_SOURCES += $(my_generated_sources) +########################################################### +# PROTOC transforms +########################################################### + +proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) + +ifneq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c) + ########################################################### ## Compile the .proto files to .cc and then to .o ########################################################### -proto_sources := $(filter %.proto,$(my_src_files)) proto_generated_objects := proto_generated_headers := ifneq ($(proto_sources),) @@ -484,6 +491,7 @@ proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \ # Auto-export the generated proto source dir. LOCAL_EXPORT_C_INCLUDE_DIRS += $(proto_generated_cc_sources_dir) +$(warning wink protobuf LECID=$(LOCAL_EXPORT_C_INCLUDE_DIRS)) # Ensure the transform-proto-to-cc rule is only defined once in multilib build. ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined @@ -516,6 +524,46 @@ endif endif # $(proto_sources) non-empty +else + +########################################################### +## Compile the .proto files to nanopb-c and then to .o +########################################################### +nanopb_c_generated_objects := +nanopb_c_generated_headers := +ifneq ($(proto_sources),) +nanopb_c_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) +nanopb_c_generated_sources_dir := $(intermediates)/proto +nanopb_c_generated_sources := $(addprefix $(nanopb_c_generated_sources_dir)/, \ + $(patsubst %.proto,%.pb.c,$(nanopb_c_sources_fullpath))) +nanopb_c_generated_objects := $(patsubst %.c,%.o, $(nanopb_c_generated_sources)) + +# Auto-export the generated proto source dir. +LOCAL_EXPORT_C_INCLUDE_DIRS += $(nanopb_c_generated_sources_dir) +$(warning wink nanopb LECID=$(LOCAL_EXPORT_C_INCLUDE_DIRS)) + +$(nanopb_c_generated_sources): PRIVATE_NANOPB_C_INCLUDES := $(TOP) +$(nanopb_c_generated_sources): PRIVATE_NANOPB_C_OUTPUT_DIR := $(nanopb_c_generated_sources_dir) +$(nanopb_c_generated_sources): PRIVATE_NANOPB_C_FLAGS := $(LOCAL_PROTOC_FLAGS) + +$(nanopb_c_generated_sources): $(nanopb_c_generated_sources_dir)/%.pb.c: %.proto $(PROTOC) + $(transform-nanopb_c-to-c) + +nanopb_c_generated_headers := $(patsubst %.pb.c,%.pb.h, $(nanopb_c_generated_sources)) +$(nanopb_c_generated_headers): $(nanopb_c_generated_sources_dir)/%.pb.h: $(nanopb_c_generated_sources_dir)/%.pb.c + +$(nanopb_c_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) +$(nanopb_c_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) +$(nanopb_c_generated_objects): $(nanopb_c_generated_sources_dir)/%.pb.o: $(nanopb_c_generated_sources_dir)/%.pb.c $(nanopb_c_generated_headers) + $(transform-$(PRIVATE_HOST)cpp-to-o) +-include $(nanopb_c_generated_objects:%.o=%.P) + +LOCAL_C_INCLUDES += external/nanopb-c $(dir $(nanopb_c_generated_headers)) +LOCAL_STATIC_LIBRARIES += libnanopb-c-2.8.0 +endif + +endif + ########################################################### ## YACC: Compile .y and .yy files to .cpp and the to .o. ########################################################### @@ -813,6 +861,7 @@ normal_objects := \ $(objc_objects) \ $(yacc_objects) \ $(lex_objects) \ + $(nanopb_c_generated_objects) \ $(proto_generated_objects) \ $(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) @@ -981,7 +1030,7 @@ $(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets) export_includes := $(intermediates)/export_includes $(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS) # Make sure .pb.h are already generated before any dependent source files get compiled. -$(export_includes) : $(LOCAL_MODULE_MAKEFILE) $(proto_generated_headers) +$(export_includes) : $(LOCAL_MODULE_MAKEFILE) $(proto_generated_headers) $(nanopb_c_generated_headers) @echo Export includes file: $< -- $@ $(hide) mkdir -p $(dir $@) && rm -f $@ ifdef LOCAL_EXPORT_C_INCLUDE_DIRS diff --git a/core/clear_vars.mk b/core/clear_vars.mk index bf81ebf12..81c54ebc1 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -125,7 +125,7 @@ LOCAL_RENDERSCRIPT_TARGET_API:= LOCAL_DEX_PREOPT:= # '',true,false,nostripping LOCAL_DEX_PREOPT_IMAGE_LOCATION:= LOCAL_DEX_PREOPT_FLAGS:= -LOCAL_PROTOC_OPTIMIZE_TYPE:= # lite(default),micro,nano,full +LOCAL_PROTOC_OPTIMIZE_TYPE:= # lite(default),micro,nano,full,nanopb-c LOCAL_PROTOC_FLAGS:= LOCAL_PROTO_JAVA_OUTPUT_PARAMS:= LOCAL_NO_CRT:= diff --git a/core/definitions.mk b/core/definitions.mk index 57fc434c2..b95ce4c65 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -964,6 +964,17 @@ $(hide) $(PROTOC) \ --cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $< endef +###################################################################### +## Commands for running protoc to compile .proto into nano protobuf .pb.c and .pb.h +###################################################################### +define transform-nanopb_c-to-c +@mkdir -p $(dir $@) +@echo "Protoc: $@ <= $<" +$(hide) $(PROTOC) \ + $(addprefix --proto_path=, $(PRIVATE_NANOPB_C_INCLUDES)) \ + $(PRIVATE_NANOPB_C_FLAGS) \ + --nanopb_out=$(PRIVATE_NANOPB_C_OUTPUT_DIR) --plugin=external/nanopb-c/generator/protoc-gen-nanopb $< +endef ########################################################### ## Commands for running gcc to compile a C++ file From 597cfdb9db079994620333665db992de7c0a99a0 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Wed, 25 Jun 2014 19:48:51 -0700 Subject: [PATCH 2/2] Add support for PB_ENABLE_MALLOC in nanopb-c There will be two version of the the nanopb-c library, libnanopb-c-2.8.0 which doesn't support automatic malloc and libnanopb-c-2.8.0-enable_malloc which does. There will be two version of the the nanopb-c library, libnanopb-c-2.8.0 which doesn't support automatic malloc and libnanopb-c-2.8.0-enable_malloc which does. Set LOCAL_PROTO_OPTIMIZE_TYPE=nanopb-c which doesn't support malloc and set it to nanopb-c-enable_malloc which does. For client code details see nanopb-api: http://koti.kapsi.fi/jpa/nanopb/docs/reference.html Change-Id: If238412463aabb5e1d556dfc9c464bcaf9e3333a --- core/binary.mk | 26 ++++++++++++++------------ core/clear_vars.mk | 2 +- core/definitions.mk | 2 ++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index 487faca38..f8ae8b5c8 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -472,13 +472,15 @@ ALL_GENERATED_SOURCES += $(my_generated_sources) proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) -ifneq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c) +proto_generated_objects := +proto_generated_headers := +nanopb_c_generated_objects := +nanopb_c_generated_headers := +ifeq (,$(filter nanopb-c nanopb-c-enable_malloc, $(LOCAL_PROTOC_OPTIMIZE_TYPE))) ########################################################### ## Compile the .proto files to .cc and then to .o ########################################################### -proto_generated_objects := -proto_generated_headers := ifneq ($(proto_sources),) proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) proto_generated_cc_sources_dir := $(generated_sources_dir)/proto @@ -491,7 +493,6 @@ proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \ # Auto-export the generated proto source dir. LOCAL_EXPORT_C_INCLUDE_DIRS += $(proto_generated_cc_sources_dir) -$(warning wink protobuf LECID=$(LOCAL_EXPORT_C_INCLUDE_DIRS)) # Ensure the transform-proto-to-cc rule is only defined once in multilib build. ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined @@ -527,10 +528,8 @@ endif # $(proto_sources) non-empty else ########################################################### -## Compile the .proto files to nanopb-c and then to .o +## Compile the .proto files to .c from nanopb-c and then to .o ########################################################### -nanopb_c_generated_objects := -nanopb_c_generated_headers := ifneq ($(proto_sources),) nanopb_c_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) nanopb_c_generated_sources_dir := $(intermediates)/proto @@ -540,7 +539,6 @@ nanopb_c_generated_objects := $(patsubst %.c,%.o, $(nanopb_c_generated_sources)) # Auto-export the generated proto source dir. LOCAL_EXPORT_C_INCLUDE_DIRS += $(nanopb_c_generated_sources_dir) -$(warning wink nanopb LECID=$(LOCAL_EXPORT_C_INCLUDE_DIRS)) $(nanopb_c_generated_sources): PRIVATE_NANOPB_C_INCLUDES := $(TOP) $(nanopb_c_generated_sources): PRIVATE_NANOPB_C_OUTPUT_DIR := $(nanopb_c_generated_sources_dir) @@ -554,13 +552,17 @@ $(nanopb_c_generated_headers): $(nanopb_c_generated_sources_dir)/%.pb.h: $(nanop $(nanopb_c_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) $(nanopb_c_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) -$(nanopb_c_generated_objects): $(nanopb_c_generated_sources_dir)/%.pb.o: $(nanopb_c_generated_sources_dir)/%.pb.c $(nanopb_c_generated_headers) - $(transform-$(PRIVATE_HOST)cpp-to-o) +$(nanopb_c_generated_objects): $(nanopb_c_generated_sources_dir)/%.o: $(nanopb_c_generated_sources_dir)/%.c $(nanopb_c_generated_headers) + $(transform-$(PRIVATE_HOST)c-to-o) -include $(nanopb_c_generated_objects:%.o=%.P) LOCAL_C_INCLUDES += external/nanopb-c $(dir $(nanopb_c_generated_headers)) +ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc) +LOCAL_STATIC_LIBRARIES += libnanopb-c-2.8.0-enable_malloc +else LOCAL_STATIC_LIBRARIES += libnanopb-c-2.8.0 endif +endif endif @@ -742,7 +744,7 @@ $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) c_objects := $(c_arm_objects) $(c_normal_objects) ifneq ($(strip $(c_objects)),) -$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) \ +$(c_objects): $(intermediates)/%.o: $(TOPDIR)$(LOCAL_PATH)/%.c $(yacc_cpps) $(proto_generated_headers) $(nanopb_c_generated_headers) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) \ | $(my_compiler_dependencies) $(transform-$(PRIVATE_HOST)c-to-o) @@ -761,7 +763,7 @@ ifneq ($(strip $(gen_c_objects)),) # TODO: support compiling certain generated files as arm. $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) $(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) -$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) \ +$(gen_c_objects): $(intermediates)/%.o: $(intermediates)/%.c $(yacc_cpps) $(proto_generated_headers) $(nanopb_c_generated_headers) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) \ | $(my_compiler_dependencies) $(transform-$(PRIVATE_HOST)c-to-o) diff --git a/core/clear_vars.mk b/core/clear_vars.mk index 81c54ebc1..605908d82 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -125,7 +125,7 @@ LOCAL_RENDERSCRIPT_TARGET_API:= LOCAL_DEX_PREOPT:= # '',true,false,nostripping LOCAL_DEX_PREOPT_IMAGE_LOCATION:= LOCAL_DEX_PREOPT_FLAGS:= -LOCAL_PROTOC_OPTIMIZE_TYPE:= # lite(default),micro,nano,full,nanopb-c +LOCAL_PROTOC_OPTIMIZE_TYPE:= # lite(default),micro,nano,full,nanopb-c,nanopb-c-enable_malloc LOCAL_PROTOC_FLAGS:= LOCAL_PROTO_JAVA_OUTPUT_PARAMS:= LOCAL_NO_CRT:= diff --git a/core/definitions.mk b/core/definitions.mk index b95ce4c65..50366b56c 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -956,6 +956,7 @@ endef ## Commands for running protoc to compile .proto into .pb.cc and .pb.h ###################################################################### define transform-proto-to-cc +$(warning transform-proto-to-cc) @mkdir -p $(dir $@) @echo "Protoc: $@ <= $<" $(hide) $(PROTOC) \ @@ -968,6 +969,7 @@ endef ## Commands for running protoc to compile .proto into nano protobuf .pb.c and .pb.h ###################################################################### define transform-nanopb_c-to-c +$(warning transform-nanopb_c-to-c) @mkdir -p $(dir $@) @echo "Protoc: $@ <= $<" $(hide) $(PROTOC) \