am c3dcb6c0: Merge "Consolidate the nanopb-c and regular protobuf build rules."

* commit 'c3dcb6c06bd2fbe816a918e9c3b099669bbeb5b5':
  Consolidate the nanopb-c and regular protobuf build rules.
This commit is contained in:
Ying Wang 2015-08-18 21:41:03 +00:00 committed by Android Git Automerger
commit f526c169ef
2 changed files with 44 additions and 24 deletions

View file

@ -53,6 +53,7 @@ my_c_includes := $(LOCAL_C_INCLUDES)
my_generated_sources := $(LOCAL_GENERATED_SOURCES)
my_native_coverage := $(LOCAL_NATIVE_COVERAGE)
my_additional_dependencies := $(LOCAL_MODULE_MAKEFILE) $(LOCAL_ADDITIONAL_DEPENDENCIES)
my_export_c_include_dirs := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
ifdef LOCAL_IS_HOST_MODULE
my_allow_undefined_symbols := true
@ -413,7 +414,7 @@ endif
## Define arm-vs-thumb-mode flags.
###########################################################
LOCAL_ARM_MODE := $(strip $(LOCAL_ARM_MODE))
ifeq ($(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
ifeq ($($(my_prefix)$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH),arm)
arm_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),arm)
normal_objects_mode := $(if $(LOCAL_ARM_MODE),$(LOCAL_ARM_MODE),thumb)
@ -541,34 +542,44 @@ my_generated_sources := $(patsubst $(generated_sources_dir)/%,$(intermediates)/%
ALL_GENERATED_SOURCES += $(my_generated_sources)
###########################################################
## Compile the .proto files to .cc and then to .o
## Compile the .proto files to .cc (or .c) and then to .o
###########################################################
proto_sources := $(filter %.proto,$(my_src_files))
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
proto_generated_cc_sources := $(addprefix $(proto_generated_cc_sources_dir)/, \
$(patsubst %.proto,%.pb.cc,$(proto_sources_fullpath)))
proto_generated_headers := $(patsubst %.pb.cc,%.pb.h, $(proto_generated_cc_sources))
proto_generated_sources_dir := $(generated_sources_dir)/proto
proto_generated_obj_dir := $(intermediates)/proto
ifneq (,$(filter nanopb-c nanopb-c-enable_malloc, $(LOCAL_PROTOC_OPTIMIZE_TYPE)))
my_proto_source_suffix := .c
my_proto_c_includes := external/nanopb-c
my_protoc_flags := --nanopb_out=$(proto_generated_sources_dir) \
--plugin=external/nanopb-c/generator/protoc-gen-nanopb
else
my_proto_source_suffix := .cc
my_proto_c_includes := external/protobuf/src
my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
my_protoc_flags := --cpp_out=$(proto_generated_sources_dir)
endif
my_proto_c_includes += $(proto_generated_sources_dir)
proto_sources_fullpath := $(addprefix $(LOCAL_PATH)/, $(proto_sources))
proto_generated_sources := $(addprefix $(proto_generated_sources_dir)/, \
$(patsubst %.proto,%.pb$(my_proto_source_suffix),$(proto_sources_fullpath)))
proto_generated_headers := $(patsubst %.pb$(my_proto_source_suffix),%.pb.h, $(proto_generated_sources))
proto_generated_objects := $(addprefix $(proto_generated_obj_dir)/, \
$(patsubst %.proto,%.pb.o,$(proto_sources_fullpath)))
# Auto-export the generated proto source dir.
LOCAL_EXPORT_C_INCLUDE_DIRS += $(proto_generated_cc_sources_dir)
# Ensure the transform-proto-to-cc rule is only defined once in multilib build.
ifndef $(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined
$(proto_generated_cc_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
$(proto_generated_cc_sources): PRIVATE_PROTO_CC_OUTPUT_DIR := $(proto_generated_cc_sources_dir)
$(proto_generated_cc_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS)
$(proto_generated_cc_sources): $(proto_generated_cc_sources_dir)/%.pb.cc: %.proto $(PROTOC)
$(proto_generated_sources): PRIVATE_PROTO_INCLUDES := $(TOP)
$(proto_generated_sources): PRIVATE_PROTOC_FLAGS := $(LOCAL_PROTOC_FLAGS) $(my_protoc_flags)
$(proto_generated_sources): $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix): %.proto $(PROTOC)
$(transform-proto-to-cc)
# This is just a dummy rule to make sure gmake doesn't skip updating the dependents.
$(proto_generated_headers): $(proto_generated_cc_sources_dir)/%.pb.h: $(proto_generated_cc_sources_dir)/%.pb.cc
$(proto_generated_headers): $(proto_generated_sources_dir)/%.pb.h: $(proto_generated_sources_dir)/%.pb$(my_proto_source_suffix)
@echo "Updated header file $@."
$(my_prefix)_$(LOCAL_MODULE_CLASS)_$(LOCAL_MODULE)_proto_defined := true
@ -576,13 +587,23 @@ endif # transform-proto-to-cc rule included only once
$(proto_generated_objects): PRIVATE_ARM_MODE := $(normal_objects_mode)
$(proto_generated_objects): PRIVATE_ARM_CFLAGS := $(normal_objects_cflags)
$(proto_generated_objects): $(proto_generated_obj_dir)/%.o: $(proto_generated_cc_sources_dir)/%.cc $(proto_generated_headers)
$(proto_generated_objects): $(proto_generated_obj_dir)/%.o: $(proto_generated_sources_dir)/%$(my_proto_source_suffix) $(proto_generated_headers)
ifeq ($(my_proto_source_suffix),.c)
$(transform-$(PRIVATE_HOST)c-to-o)
else
$(transform-$(PRIVATE_HOST)cpp-to-o)
endif
-include $(proto_generated_objects:%.o=%.P)
my_c_includes += external/protobuf/src $(proto_generated_cc_sources_dir)
my_cflags += -DGOOGLE_PROTOBUF_NO_RTTI
ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
my_c_includes += $(my_proto_c_includes)
# Auto-export the generated proto source dir.
my_export_c_include_dirs += $(my_proto_c_includes)
ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c-enable_malloc)
my_static_libraries += libnanopb-c-2.8.0-enable_malloc
else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),nanopb-c)
my_static_libraries += libnanopb-c-2.8.0
else ifeq ($(LOCAL_PROTOC_OPTIMIZE_TYPE),full)
ifdef LOCAL_SDK_VERSION
my_static_libraries += libprotobuf-cpp-full
else
@ -597,7 +618,6 @@ else
endif
endif # $(proto_sources) non-empty
###########################################################
## Compile the .dbus.xml files to c++ headers
###########################################################
@ -1186,12 +1206,12 @@ $(LOCAL_INSTALLED_MODULE): | $(installed_static_library_notice_file_targets)
# Export includes
###########################################################
export_includes := $(intermediates)/export_includes
$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(LOCAL_EXPORT_C_INCLUDE_DIRS)
$(export_includes): PRIVATE_EXPORT_C_INCLUDE_DIRS := $(my_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)
@echo Export includes file: $< -- $@
$(hide) mkdir -p $(dir $@) && rm -f $@
ifdef LOCAL_EXPORT_C_INCLUDE_DIRS
ifdef my_export_c_include_dirs
$(hide) for d in $(PRIVATE_EXPORT_C_INCLUDE_DIRS); do \
echo "-I $$d" >> $@; \
done

View file

@ -919,7 +919,7 @@ $(hide) touch $@
endef
######################################################################
## Commands for running protoc to compile .proto into .pb.cc and .pb.h
## Commands for running protoc to compile .proto into .pb.cc (or.pb.c) and .pb.h
######################################################################
define transform-proto-to-cc
@echo "Protoc: $@ <= $<"
@ -927,7 +927,7 @@ define transform-proto-to-cc
$(hide) $(PROTOC) \
$(addprefix --proto_path=, $(PRIVATE_PROTO_INCLUDES)) \
$(PRIVATE_PROTOC_FLAGS) \
--cpp_out=$(PRIVATE_PROTO_CC_OUTPUT_DIR) $<
$<
endef