Android compilation process (III)

Source: Internet
Author: User

 

Android compilation process (I): http://www.cnblogs.com/mr-raptor/archive/2012/06/07/2540359.html

Android compilation process (2): http://www.cnblogs.com/mr-raptor/archive/2012/06/08/2541571.html

Android compilation process (3): http://www.cnblogs.com/mr-raptor/archive/2012/06/12/2547030.html

The previous two sections explain how to customize Android compilation items and create Product configuration files. In addition to compiling and defining Product-related environment variables, you also need to define Board-related environment variables.

1. build/core/config. mk

 
109 # ---------------------------------------------------------------  110 # Define most of the global variables.  These are the ones that  111 # are specific to the user's build configuration.  112 include $(BUILD_SYSTEM)/envsetup.mk  113   114 # Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)  115 # or under vendor/*/$(TARGET_DEVICE).  Search in both places, but  116 # make sure only one exists.  117 # Real boards should always be associated with an OEM vendor.  118 board_config_mk := \  119     $(strip $(wildcard \  120         $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \  121         vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \  122     ))  123 ifeq ($(board_config_mk),)  124   $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE))  125 endif  126 ifneq ($(words $(board_config_mk)),1)  127   $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))  128 endif  129 include $(board_config_mk)  130 TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))  131 board_config_mk :=  
The above code has been seen in the previous section, but it only analyzes the envsetup of Line 1. mk. According to the content in the previous section, envsetup. mk sets many OUT variables and sets TARGET_DEVICE = fs100 In the build/core/product_config.mk file.

 

We continue the analysis from row 3.

From 114 ~ The explanations in line 3 are as follows:

The configuration files related to the Board will exist in the $ (SRC_TARGET_DIR)/board/$ (TARGET_DEVICE)/or vendor/*/$ (TARGET_DEVICE)/directory, one Vendor can have only one corresponding Board configuration file.

Row 3 defines the variable board_config_mk:

$ (Wildcard xxx) is used to locate the matching item of xxx and put it in the space list. The TARGET_DEVICE variable = fs100 is defined before, so $ (SRC_TARGET_DIR)/board/fs100/BoardConfig. mk does not exist. The domain name must exist in the domain name "vendor"/*/fs100/BoardConfig. mk file to define the development board configuration information.

Line 3: include vendor/*/fs100/BoardConfig. mk through include,

Row 3: TARGET_DEVICE_DIR is the path of board_config_mk, that is, vendor/*/fs100.

Summary:

A vendor must have a corresponding Board configuration file, that is, vendor/*/fs100/BoardConfig. mk.

Defines the TARGET_DEVICE_DIR variable, which is the path of board_config_mk, that is, vendor/*/fs100

Specify the relevant features of the board, which must include:
TARGET_CPU_ABI: = armeabi /...
For other attributes, see other board examples (build/target/board/XXX

 

2. build/core/main. mk

 

141 # Bring in standard build system definitions.142 include $(BUILD_SYSTEM)/definitions.mk...347 ifeq ($(SDK_ONLY),true)348 349 # ----- SDK for Windows ------350 # These configure the build targets that are available for the SDK under Cygwin.351 # The first section defines all the C/C++ tools that can be compiled under Cygwin,352 # the second section defines all the Java ones (assuming javac is available.)353 354 subdirs := \355     prebuilt \356     build/libs/host \357     build/tools/zipalign \...382 # The following can only be built if "javac" is available.383 # This check is used when building parts of the SDK under Cygwin.384 ifneq (,$(shell which javac 2>/dev/null))385 $(warning sdk-only: javac available.)386 subdirs += \387     build/tools/signapk \388     dalvik/dx \389     dalvik/libcore \...414 else    # !SDK_ONLY415 ifeq ($(BUILD_TINY_ANDROID), true)416 417 # TINY_ANDROID is a super-minimal build configuration, handy for board 418 # bringup and very low level debugging419 420 subdirs := \421     bionic \422     system/core \423     build/libs \424     build/target \...433 else    # !BUILD_TINY_ANDROID434 435 #436 # Typical build; include any Android.mk files we can find.437 #438 subdirs := $(TOP)439 440 FULL_BUILD := true441 442 endif   # !BUILD_TINY_ANDROID443 444 endif   # !SDK_ONLY...464 #465 # Include all of the makefiles in the system466 #467 468 # Can't use first-makefiles-under here because469 # --mindepth=2 makes the prunes not work.470 subdir_makefiles := \471     $(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)472 473 include $(subdir_makefiles)

 

In the previous section, we only talked about the main. mk 49th line containing config. mk. We will continue to analyze it.

Row 142 contains: build/core/definitions. mk. This file defines many global variables and functions.

See the following common functions:

My-dir: returns the current path.

All-java-files-under: obtain all java files in the specified directory and subdirectory.

All-subdir-c-files: obtains all c files in the current directory and subdirectory.

354 ~ Line 3 defines the subdirs variable, which contains different directories in the Android source code based on different user compilation conditions.

Row 3 defines the subdir_makefile variable. Its value is the Android. mk file in the directory defined by subdirs.

Line 3 contains all Android. mk files in the compiled directory.

3. build/target/board/Android. mk

 26 ifeq (,$(wildcard $(TARGET_DEVICE_DIR)/AndroidBoard.mk)) 27   ifeq (,$(wildcard $(TARGET_DEVICE_DIR)/Android.mk)) 28     $(error Missing "$(TARGET_DEVICE_DIR)/AndroidBoard.mk") 29   else 30     # TODO: Remove this check after people have had a chance to switch, 31     # after April 2009. 32     $(error Please rename "$(TARGET_DEVICE_DIR)/Android.mk" to "$(TARGET_DEVICE_DIR)/AndroidBoard.mk") 33   endif 34 endif 35 include $(TARGET_DEVICE_DIR)/AndroidBoard.mk
Because Android. mk File include, build/target/board/Android. mk is naturally included. According to the previous analysis, TARGET_DEVICE_DIR = vendor/*/fs100, of which 26 ~ Line 35 is used to determine whether AndrodiBoard. mk exists in the corresponding product directory. If not, an error is prompted to exit. If so, include it in the compilation script.

 

Therefore, we must create AndrodiBoard under the product directory. mk file to describe the configuration items of the Development board. For details, refer to build/target/board/generic/AndroidBoard. mk content, and also create BoardConfig according to the previous analysis. mk file.

 

$cp build/target/board/generic/AndroidBoard.mk build/target/board/generic/BoardConfig.mk  vendor/farsight/fs100/

 

At this point, the basic steps for custom Android compilation options have been analyzed by division, and the details need to be analyzed for different development boards.

 

Summary:

Build/core/main. mk contains config. mk, which mainly defines the dependency between compiling all codes.

Build/core/config. mk defines a large number of compilation script commands, environment variables used during compilation, introduced the envsetup. mk file, and loaded the configuration files related to the board.
Build/core/envsetup. mk defines a large number of OUT output directories used during compilation and loads the product_config.mk file.
Build/core/product_config.mk defines the parsing script for Product-related configuration files under the Vendor directory, and reads AndrodProducts. mk to generate the TARGET_DEVICE variable.
Build/target/product config
Build/target/board config
Build/core/combo build flags config

Here we will explain the board and product here. Borad is mainly designed for hardware chip configurations, such as whether to provide certain hardware functions, such as GPU, or whether the chip supports floating point operations. Product is a pointer to the current chip configuration. It defines the personalized configuration of the product to be produced. It mainly refers to the APK configuration and the product to which the APK will be included, which APK is not provided in the current product.
Config. mk is a general concept that defines the HOST tools required for module compilation and how to compile various modules. For example, BUILT_PREBUILT defines how to compile the pre-compilation module. Envsetup. mk mainly reads some variables written by envsetup. sh to the environment variables to configure the output directory during the compilation process. combo mainly defines the compiler and compilation options that combine Host and Target.

1. Create your own company directory under the vendor directory, create a new vendorsetup. sh under the company directory, and add your own product compilation items to it.

$mkdir vendor/farsight/  $touch vendor/farsight/vendorsetup.sh  $echo "add_lunch_combo fs100-eng" > vendor/farsight/vendorsetup.sh  

 

2. Create the products directory under the company directory like the Android sample code
 $mkdir -p vendor/farsight/products
3. Create two mk files under the products directory, similar to the Android sample code.
$touch vendor/farsight/products/AndroidProduct.mk vendor/farsight/products/fs100.mk
Add the following content to AndroidProduct. mk:
PRODUCT_MAKEFILES := $(LOCAL_DIR)/fs100.mk  
Add the most basic information to the Product Configuration File
 PRODUCT_PACKAGES := \       IM \       VoiceDialer      $(call inherit-product, build/target/product/generic.mk)      # Overrides   PRODUCT_MANUFACTURER := farsight   PRODUCT_NAME := fs100   PRODUCT_DEVICE := fs100  
4. Use build/target/board/generic/AndroidBoard. mk and BoardConfig. mk to create the corresponding file.
$cp build/target/board/generic/AndroidBoard.mk build/target/board/generic/BoardConfig.mk  vendor/farsight/fs100/

 


Related Article

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.