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
This commit is contained in:
Wink Saville 2014-06-25 19:48:51 -07:00 committed by Amit Mahajan
parent 042d4dc4a1
commit 597cfdb9db
3 changed files with 17 additions and 13 deletions

View file

@ -472,13 +472,15 @@ ALL_GENERATED_SOURCES += $(my_generated_sources)
proto_sources := $(filter %.proto,$(LOCAL_SRC_FILES)) 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 ## Compile the .proto files to .cc and then to .o
########################################################### ###########################################################
proto_generated_objects :=
proto_generated_headers :=
ifneq ($(proto_sources),) ifneq ($(proto_sources),)
proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
proto_generated_cc_sources_dir := $(generated_sources_dir)/proto 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. # Auto-export the generated proto source dir.
LOCAL_EXPORT_C_INCLUDE_DIRS += $(proto_generated_cc_sources_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. # Ensure the transform-proto-to-cc rule is only defined once in multilib build.
ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
@ -527,10 +528,8 @@ endif # $(proto_sources) non-empty
else 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),) ifneq ($(proto_sources),)
nanopb_c_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources)) nanopb_c_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
nanopb_c_generated_sources_dir := $(intermediates)/proto 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. # Auto-export the generated proto source dir.
LOCAL_EXPORT_C_INCLUDE_DIRS += $(nanopb_c_generated_sources_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_INCLUDES := $(TOP)
$(nanopb_c_generated_sources): PRIVATE_NANOPB_C_OUTPUT_DIR := $(nanopb_c_generated_sources_dir) $(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_MODE := $(normal_objects_mode)
$(nanopb_c_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) $(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) $(nanopb_c_generated_objects): $(nanopb_c_generated_sources_dir)/%.o: $(nanopb_c_generated_sources_dir)/%.c $(nanopb_c_generated_headers)
$(transform-$(PRIVATE_HOST)cpp-to-o) $(transform-$(PRIVATE_HOST)c-to-o)
-include $(nanopb_c_generated_objects:%.o=%.P) -include $(nanopb_c_generated_objects:%.o=%.P)
LOCAL_C_INCLUDES += external/nanopb-c $(dir $(nanopb_c_generated_headers)) 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 LOCAL_STATIC_LIBRARIES += libnanopb-c-2.8.0
endif endif
endif
endif endif
@ -742,7 +744,7 @@ $(c_normal_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
c_objects := $(c_arm_objects) $(c_normal_objects) c_objects := $(c_arm_objects) $(c_normal_objects)
ifneq ($(strip $(c_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) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) \
| $(my_compiler_dependencies) | $(my_compiler_dependencies)
$(transform-$(PRIVATE_HOST)c-to-o) $(transform-$(PRIVATE_HOST)c-to-o)
@ -761,7 +763,7 @@ ifneq ($(strip $(gen_c_objects)),)
# TODO: support compiling certain generated files as arm. # TODO: support compiling certain generated files as arm.
$(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode) $(gen_c_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
$(gen_c_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags) $(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) \ $(LOCAL_ADDITIONAL_DEPENDENCIES) \
| $(my_compiler_dependencies) | $(my_compiler_dependencies)
$(transform-$(PRIVATE_HOST)c-to-o) $(transform-$(PRIVATE_HOST)c-to-o)

View file

@ -125,7 +125,7 @@ LOCAL_RENDERSCRIPT_TARGET_API:=
LOCAL_DEX_PREOPT:= # '',true,false,nostripping LOCAL_DEX_PREOPT:= # '',true,false,nostripping
LOCAL_DEX_PREOPT_IMAGE_LOCATION:= LOCAL_DEX_PREOPT_IMAGE_LOCATION:=
LOCAL_DEX_PREOPT_FLAGS:= 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_PROTOC_FLAGS:=
LOCAL_PROTO_JAVA_OUTPUT_PARAMS:= LOCAL_PROTO_JAVA_OUTPUT_PARAMS:=
LOCAL_NO_CRT:= LOCAL_NO_CRT:=

View file

@ -956,6 +956,7 @@ endef
## Commands for running protoc to compile .proto into .pb.cc and .pb.h ## Commands for running protoc to compile .proto into .pb.cc and .pb.h
###################################################################### ######################################################################
define transform-proto-to-cc define transform-proto-to-cc
$(warning transform-proto-to-cc)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo "Protoc: $@ <= $<" @echo "Protoc: $@ <= $<"
$(hide) $(PROTOC) \ $(hide) $(PROTOC) \
@ -968,6 +969,7 @@ endef
## Commands for running protoc to compile .proto into nano protobuf .pb.c and .pb.h ## Commands for running protoc to compile .proto into nano protobuf .pb.c and .pb.h
###################################################################### ######################################################################
define transform-nanopb_c-to-c define transform-nanopb_c-to-c
$(warning transform-nanopb_c-to-c)
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo "Protoc: $@ <= $<" @echo "Protoc: $@ <= $<"
$(hide) $(PROTOC) \ $(hide) $(PROTOC) \