Android platform development-android build system-Compilation System Analysis

Source: Internet
Author: User

This article from: http://blog.sina.com.cn/s/blog_569a151b0100nmym.html

 

I. Preview makefile
Ii. Android compilation system hierarchy
3. Common configuration files of the android Compiling System
Iv. Android compilation process
V. Use of Android Compiling System

I. Preview makefile rules:
Target
...: Prerequisites...
Command


...

...
Target is a target file, which can be an object.
File, which can also be an execution file. It can also be a label ).
Prerequisites is the file or object required to generate the target.
.
Command is the command to be executed by make. (Any shell command)

This is the dependency of a file, that is, the target
One or more target files depend on files in prerequisites,
Its generation rules are defined in command.
To put it bluntly, if more than one file in the prerequisites is newer than the target file, the command defined by the command will be executed. This is
Makefile rules. That is, the core of makefile
Content. As described above, the above is the core content of makefile. The Android compilation system complies with the GNU make standard,
Of course, this is also the core content of the android compilation system.

2. Android build system
System) is concentrated in build/Core under the android source code. In android2.2
56 *. mk files. There are also some shell scripts. The android compilation system does not only perform binary operations on the target (host) system.
Compiling files, compiling, linking, and packaging Java applications, as well as generating various dependencies and ensuring that modifications to a module
The re-compilation link of the dependent files, including the generation of the target file system and the generation of configuration files. Therefore, the android compilation system
Multi-Architecture (linux-x86, windows, arm, etc.), multi-language (assembly, C, C ++, Java, etc.), multi-objective, multi-compilation mode.

The compilation layer contains the abstraction layer described in the following table. Each layer is associated with one or more layers. For example, one arch has multiple
Board, each
The Board has multiple devices. You can define an element in a layer to exclude replication and simplify maintenance. Layer
Example description product myproduct,
Myproduct_eu, J2,
The SDK Product Layer defines the complete syntax for porting products.
Myproduct_eu_fr: defines which modules to compile and how to configure them. You may provide several different versions based on regions or features, such as cameras. Device mydevice,
Mydevice_eu: The device layer represents the physical layer of the device. For example, a device in North America can
Mydevice_eu_lite can contain QWERTY keyboards, while devices sold in France may
Contains the AZERTY keyboard. The peripheral device is generally connected to the device layer.
Sardine, trout,
The goldfish circuit board layer represents the original diagram of the product. There may be peripheral devices
Connect to this layer. Arch arm
(Arm5te) (arm6), x86,
The 68 K system layer describes the processors running on the Ultimate Edition. 3. Common configuration files of the android compilation system are in Android. The main makefile files are stored in the build/CORE/directory, and are grouped into multiple files suffixed with MK, it is also called build system. Android
Build system consists of the configuration part and the target build part. Build
The main process file of system is the build/CORE/Main. mk file.
Several important *. mk files are as follows:

Buildspec. mk:
Located in the root directory, you can select the product, platform, and additional module/package to be generated here.
Build/buildspec. mk. Default is a sample.

Androidproducts. mk:
This is the interface file provided to the vendor by the android build system. You can use this file to define


Packages to be compiled and installed (that is, applications ). The default option is generic.

Boardconfig. mk:
Is to set the product motherboard, such as Driver selection settings, select CPU architecture and so on.
Android. mk: Yes
Module and package configuration files. Each module/package directory has
Android. mk. The so-called module refers to the native code of the system, compared with the code written in Java
Androidapplication is called a package.
Build/envsetup. mk: Build Environment
Environment initialization, defining some practical Shell functions for compilation and use.
Build/CORE/makefile: Contains build/Core
/Main. mk. This file mainly controls the generation of system. IMG, ramdisk. IMG, userdata. IMG, and recorvery
Image, SDK, etc.
Main. mk:
For example, find all android. mk files in the top directory.
Config. mk: defines the toolchain required to compile the target program.
And compile parameters.
Base_rules.mk: regularization of some makefile Variables

Binary. mk: controls how a target file is generated
Parts
Clear_vars.mk: clears the temporary variables used in the compilation system.

Definations. mk: defined in many compilation systems
Macro, equivalent to the function library
Copy_headers.mk: copy the header file to the specified directory.

Combo/linux-arm.mk: Control
How to generate a Linux-arm binary file, including arm-related compilers and compilation Parameters

Set

Build/envsetup. sh: provides several useful commands to execute
. Build/envsetup. Sh (. There is a space behind it ).

Note: The steps for compiling modules are as follows: tapas, M, mm, and mmm.
.

1. Tapas -- sets the Build Environment Variables interactively.

Input: tapas

The
Step 1: select the target device:
For example
Select 1
Step 2: select the code format:

Me
Select 1
Step 3: select the product platform:

Note: The default value in Google source code is
Generic.

2. Use the make command of independent modules for M, mm, and mmm.

M
Compile from the root directory;
Mm
Compile all modules in the current directory;
Mmm
Compile all modules in the specified directory;

4. The main process of Android compilation is from build/CORE/Main. mk.
Arranged.
1. initialize related variables

2. Check the compilation environment
Environment and target environment
3. Determine the target product

4. Read
Product settings
5. Read
Target Platform Architecture settings specified by product
6. Select
Toolchain
7. Specify compilation Parameters
(*-. Mk)
8,
Clear output directory
9. Set/check the version number

10. Read all
Boardconfig. mk File
11,
Read settings of all modules
12. Generate required
Rule
13. Generate
Image

1. Initialization and Detection

By
Build/CORE/config. mk. Build/CORE/envsetup. mk check developer
Settings
(Buildspec. mk) and check the execution environment to determine the output directory and environment. Build/CORE/config. mk is also based on
Parameters are used to determine the relevant parameters during interpretation, such as the compiler path, flags, Lex, and YACC path parameters. About
Product settings are processed by build/CORE/product_config.mk.
Macro loading provided by build/CORE/product. mk. According to the content of androidproduct. mk,
Product_config.mk
It determines: product_tags, ota_public_keys, and product_policy.

2. Read the product settings

Android
The product settings are from build/target/product/androidproduct. mk and vendor.
Sub-category
Directory androidproduct. mk. Building system uses the find command to find all possible
Androidproduct. mk. Define the product_makefiles variable in androidproduct. mk to list all actual definitions.
Makefile of the product. These makefiles define independent products. Product-related parameters are saved
A variable in the form of products. And save the makefile path to products.
Variable. Therefore, you can obtain all
The product path/name, and get the content through the variable in the form of products.

3. Read module set by module
It refers to the software module of native code, and Java application is called package.
Build/CORE/definitions. mk define module/package related macro, read and check
Module/package definition files; scattered Android. mk across the source tree
File.
Build/CORE/Main. mk
Use the find command to find all android. mk files in these subdirectories and save the path
In the subdir_makefiles variable. Finally, include these files. These Android. mk will include
Defined as a variable
Build_shared_library, build_package, and so on. These makefiles
Will change
The content defined by Android. mk is saved as all_modules. Android. mk>.
. For example, Android. mk
The value of local_module_suffix is changed to all_modules.
Android. mk>. local_module_suffix. Android. mk path,
It will also be stored in the all_modules variable. Search
The path of Android. mk is basically the entire source tree. But it will depend on the specific goal.
Find a specific directory. For example, the SDK only needs Android. mk in a specific directory. 4. Board level settings are related to the motherboard of the target platform, such as the device used and driver
Or do you need to compile bootloader,
Kernel and so on are all set in boardconfig. mk. Similarly, each motherboard can have different settings, with
Boardconfig. mk to find the following file:
Build/target/board/$ (target_device)/boardconfig. mk

Device $ (target_device)/boardconfig. mk

Target_device
Is defined by the product, so the same boardconfig. mk can be used by multiple products.
One
Target_device, usually only one boardconfig. mk. Boardconfig. mk will be directly include
To the name space of the building system. Therefore, some module
Enable/disable, which can correspond to different motherboard in boardconfig. mk. 5. Rules
In the module definition file Android. mk, you can define the module tag, local_module_tags,
To classify these
Module. Each product can specify the required tag (product_tags) so that the building
System only indicates
The module of the tag. In build/CORE/Main. mk, all modules marked with specific tags are
All_default_installed_modules, and include build/CORE/makefile
Processing.
Build/CORE/makefile
Generate rule for these modules and make the goal depend on
To compile these modules. V. Use of Android Compiling System

The first method produces more stable results. Method 1: create a local version of buildspec. mk. The easiest way is to enter your Device directory and execute the following commands: CP
Buildspec. mk. Default buildspec. mk; chmod u = RW buildspec. mk default buildspec. mk file. All options are commented out. To create a personalized configuration environment, you can edit
Buildspec. mk.
Generally, the following options can be pulled:

Build_env_sequence_number
: = 9
Target_board_platform
: = Imx53
Target_product
: = Mine_mx53 once a configuration file is created and copied to the root directory, You can compile the device code by executing make.
It will take a long time. On a dual-core machine, consider using '-j1' (or even 'j4') to accelerate compilation. Make
-J2 Method 2: make a general version,

Run

Source
// Device/envsetup. Sh. This file contains necessary variables and function definitions, which are described below:

CD
$ Top
. Envsetup. Sh

Partner_setup
Generic // select generic as
Product
Make
-J4 product-generic-user

// You can also replace the user with Eng,
Generate a modal version.
Make
-J4 product-generic-Eng

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.