ABS (Android Build System) generates source code files during compilation

Source: Internet
Author: User

ABS (Android Build System) generates source code files during compilation

Some. c or. H files need to be generated by an interface definition file during compilation. You may also have the following requirements:
* The same interface definition file is used to generate multiple source files.
* The generated source file may be used by other projects.

For example, you need to generate the source file xxx_A.h, xxx_ B .h, and xxx_C.c from the interface definition file xxx. xml through the executable file generator. Command:
Generator A <xxx. xml> xxx_A.h
Generator B <xxx. xml> xxx_ B .h
Generator C <xxx. xml> xxx_C.c

One method is to use the transform-generated-source function defined in ABS:

GENERATOR := $(HOST_OUT_EXECUTABLES)/generator$(HOST_EXECUTABLE_SUFFIX)                                      IDL_DIR := ./                                                                                                 IDL_SRC := $(IDL_DIR)/xxx.xml                                                                                    IDL_TGT_CODE := $(IDL_DIR)/xxx_C.c                                                                        IDL_TGT_A := $(IDL_DIR)/xxx_A.h                                                        IDL_TGT_B := $(IDL_DIR)/xxx_B.h                                                                                                                                                                                 GEN := $(LOCAL_PATH)/$(IDL_TGT_A)                                                                          $(GEN): PRIVATE_PATH := $(LOCAL_PATH)                                                                                    $(GEN): PRIVATE_CUSTOM_TOOL = $(GENERATOR) A < $< > $@                                                 $(GEN): $(LOCAL_PATH)/$(IDL_SRC)                                                                                           $(transform-generated-source)                                                                                                                                                                                                                 LOCAL_GENERATED_SOURCES += $(GEN)                                                                                                                                                                                                                 GEN := $(LOCAL_PATH)/$(IDL_TGT_B)                                                                          $(GEN): PRIVATE_PATH := $(LOCAL_PATH)                                                                                    $(GEN): PRIVATE_CUSTOM_TOOL = $(GENERATOR) B < $< > $@                                                 $(GEN): $(LOCAL_PATH)/$(IDL_SRC)                                                                                           $(transform-generated-source)                                                                                                                                                                                                                 LOCAL_GENERATED_SOURCES += $(GEN)                                                                                                                                                                                                                 GEN := $(LOCAL_PATH)/$(IDL_TGT_CODE)                                                                                   $(GEN): PRIVATE_PATH := $(LOCAL_PATH)                                                                                    $(GEN): PRIVATE_CUSTOM_TOOL = $(GENERATOR) C < $< > $@                                                          $(GEN): $(LOCAL_PATH)/$(IDL_SRC) $(LOCAL_PATH)/$(IDL_TGT_A) $(LOCAL_PATH)/$(IDL_TGT_B)         $(transform-generated-source)                                                                                                                                                                                                                 LOCAL_GENERATED_SOURCES += $(GEN)      ...LOCAL_SRC_FILES := \                    $(IDL_TGT_CODE) \                 ...

 

If there are multiple interface definition files, such as a. xml and B. xml, the following method may be more convenient.
 

GENERATOR := $(HOST_OUT_EXECUTABLES)/generator$(HOST_EXECUTABLE_SUFFIX) IDL_DIR := ./     IDL_TGT_CODE := $(IDL_DIR)/xxx_C.c                                                                                                                                                          define transform-generated-A                                        @echo "target Generated $@ <= $<"                                                         $(GENERATOR) A < $< > $@                                                endef                                                                                                                                                                               define transform-generated-B                                        @echo "target Generated $@ <= $<"                                                         $(GENERATOR) B < $< > $@                                                endef                                                                                                                                                                               define transform-generated-C                                               @echo "target Generated $@ <= $<"                                                         $(GENERATOR) C < $< > $@                                                         endef                                                                                                                                                                               $(LOCAL_PATH)/$(IDL_DIR)/%_A.h : $(LOCAL_PATH)/$(IDL_DIR)/%.xml             $(transform-generated-A)                                                                                                                                  $(LOCAL_PATH)/$(IDL_DIR)/%_B.h : $(LOCAL_PATH)/$(IDL_DIR)/%.xml             $(transform-generated-B)                                                                                                                                  $(LOCAL_PATH)/$(IDL_DIR)/%-C.c : $(LOCAL_PATH)/$(IDL_DIR)/%.xml                    $(transform-generated-C)                                               ...LOCAL_SRC_FILES := \                    $(IDL_TGT_CODE) \                 ...LOCAL_ADDITIONAL_DEPENDENCIES += $(LOCAL_PATH)/xxx_A.h  $(LOCAL_PATH)/xxx_B.h   

 

In addition, if you want to compile several specific binary files in the image with symbol, you can add the following in Android. mk:

LOCAL_STRIP_MODULE: = false

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.