Android Compilation System Analysis

Source: Internet
Author: User

Android Compilation System Analysis

Since the android open source, it has aroused a boom in the embedded industry. Many embedded developers expressed strong interest in Android and downloaded the android source code for compilation and transplantation. The huge Android source code (repo down, about 2 GB) gives people the illusion that android is quite complex. From the android compiling system perspective, this article shows you that android is actually pure.

The android compilation system is concentrated in the build/core of the android source code. In android2.2, there are 56 *. mk files. There are also some shell scripts. Why is Google making its compilation system so complicated? The build-system.html file under build/corecontains the following descriptions:

1. Multiple Targets
2. Non-recursive make
3. Rapid compile-test cycles
4. both environment and Config File Based settings
5. object file directory/make clean

Based on the above objectives, Google Android Developers have made the android build system as it is now. On android.git.kernel.org, we can see that the android build system is constantly updated as a project. Therefore, the maintenance of its compilation system is also a very complex project. To achieve Android porting on the ARM platform (x86, MIPS, or even a new architecture), you must have a deep understanding of the android compilation system.


Android Architecture

The makefile rules have been badly supplemented over the past few days. The following is an excerpt from the http://www.360doc.com/content/10/0409/13/502243_22235679.shtml

For a while, it is strongly recommended that you read makefile. It seems that there is a PDF file called "Write makefile with me" to deepen your understanding of the compilation process. With the make tool in Linux, You can despise the Visual Studio IDE in windows.

Makefile rules:

Target...: prerequisites...

Command

...

...

Target is a target file, which can be an object file or an execution file. It can also be a label. For the label feature, it will be described in the subsequent "pseudo-target" chapter.

Prerequisites is the file or target 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 to say, one or more target files depend on the files in prerequisites, and their generation rules are defined in command. To put it bluntly, if more than one prerequisites file is newer than the target file, the command defined by command will be executed. This is the makefile rule. That is, the core content in makefile.

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.

Android compilation system architecture:

 

By analyzing the android compilation system, you will find that the android compilation system does not only compile, link, and package the binary files of the target (host) system, Java applications, etc, it also includes generating various dependencies, ensuring that modifications to a module cause re-compilation links of dependent files, and even generating the target file system and configuration files, therefore, Android compilation system supports multi-Architecture (linux-x86, windows, arm, etc.), multi-language (assembly, C, C ++, Java, etc.), multi-objective, multi-compilation mode. These goals and structures determine their architecture.

Android compilation systems are concentrated in build/CORE. Several important *. mk files are as follows:

Main. mk (Master makefile)

Base_rules.mk (normalization of some makefile variables)

Config. mk (configuration of compilation parameters and compilation commands)

Definations. mk (defines many macros used in the compilation system, which is equivalent to the function library)

Makefile (this makefile refers to the makefile under build/core. This file mainly controls the generation of system. IMG, ramdisk. IMG, userdata. IMG, and recorvery image, SDK, etc)

Binary. mk (controls how to generate the target file)

Clear_vars.mk (clear the temporary variables used in the compilation system)

Combo/linux-arm.mk (controls how to generate Linux-arm binaries, including arm-related compilers, compiler parameters, and other settings)

Copy_headers.mk (copy the header file to the specified directory)

Android. mk distributed in various directories (control the source code of the local module generation, the header file path required by the name, the dependent library, and other special options)

Build/envsetup. mk (initialize the compiling environment and define some practical Shell functions for compilation and usage)

The preceding documents can be divided into social labor:

As the President, Main. mk is the boss and undertakes a lot of work.

Makefile is the vice president, assisting the boss main. mk

Base_rules.mk is a traffic police service that makes irregular things a rule.

Config. mk is the governor and specifies how the masses should act.

Definations. mk is the library Administrator

Binary. mk should belong to the village chief and define how everyone should act.

Clear_vars.mk should belong to the cleaning company's workers.

Combo/linux-arm.mk should belong to a social citizen and he decides how to do it

Note: The analysis of main. mk will be posted tomorrow. please correct me.

 

Main. mk Analysis

Main. mk mainly includes the following parts:

1. Shell settings

2. compile environment Configuration

3. Check the compiling environment

4. include necessary macros

5. Set the variables during compilation according to the Make Parameter

6. Include Android. mk to be compiled

7. Set the compilation system target: prerequisites to control the entire compilation process.

The following are some explanations:

With the analysis of the android compilation system architecture in the previous section, if you need to modify the android compilation system, you can not blindly find the problem and modify the code. Analyze main. mk today to see what valuable information it can provide for Android compilation and how to customize our android compilation system.

Main. the first sentence of MK is to package the shell used by the System Based on android_build_shell. If we don't want to use Bash, but want to use SH, we can write android_build_shell before it: =/bin/sh, or in build/envsetup. sh.

After the shell is defined, check make_version and define the default compilation target droid!

If we do not add any parameters after typing make, the default target is droid. Note that although the include $ (build_system)/config. mk statement is written after the default target droid dependency, the statement and the subsequent statement must be executed, which is determined by the makefile syntax.

Include config. mk cleanbuild. mk to configure the compilation system. Check the compiling environment, including case sensitivity, path check, Java version check, and javac version check. Android will not check the compiling environment again at the next compilation if it meets the criteria.

After checking the version, it will include definations. MK, as mentioned earlier, definations. MK defines a lot of macros used in the compilation system. These macros need to be called frequently during compilation. Therefore, they are included in a very early stage of compilation.

Then, compile and configure the compilation type (ENG user userdebug showcommands) passed in make. These configurations will affect the modules included in the final compilation target. For the differences between compilation targets such as Eng user userdebug SDK win_sdk tests, you can check the main. mk code to find out what is the difference.

Skip some unimportant content here and jump directly

Ifeq ($ (sdk_only), true), around 368 rows. This judgment statement is used to set the subdirs variable until the end of the statement block, the subdirs variable determines which subfolders are finally compiled.

The subsequent setting of the subdir_makefiles variable determines which Android. mk is compiled. Then include $ (subdir_makefiles) adds dependencies for all these Android. mk files. This includes the droid dependency, which we will find later.

Then, all modules to be compiled will be identified based on these makefiles, and necessary classifications (such as eng_modules/debug_modules/tests_modules, modules_to_check/modules_to_install) will be performed to differentiate them.

A series of hidden targets are defined: prebuilt, all_copied_headers, files, checkbuild, ramdisk, systemtallball, userdataimage, userdatatarball, bootimg, and droidcore. The most important thing is that droid depends on droidcore, while droidcore depends on

Droidcore: files/

Systemimage/

$ (Installed_bootimage_target )/

$ (Installed_recoveryimage_target )/

$ (Installed_userdataimage_target )/

$ (Installed_files_file)

These dependencies control the compilation of the entire android system.

The next blog post will describe the entire generation process of system. IMG.


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.