Android build system

Android uses a script to explore all directories and subdirectories until it finds an Android.mk file. The Android.mk file specify how the local module is built.

A "module" in Android is a component of the AOSP that needs to be built.

The build system is configured by a set of variables which are set via envsetup.sh and lunch or are defined statically in buildspec.mk file. To get more insight into the build system, have a look at the build/core/build-system.html .

There is only one official file named 'Makefile', at the top of the source tree for the whole repository.

include build/make/core/main.mk

You set some environment variables, then type 'make' to build stuff.

envsetup.sh defines new shell commands, such as lunch, and sets up environment variables required for the rest of the build.

The build system doesn't generate object files within the same location as the source files. The build system creates an out/ directory where it stores everything it generates.

Android’s build system pulls everything into a single makefile; it isn’t recursive. Hence, each .mk file you see eventually becomes part of a single huge makefile that contains the rules for building all the pieces in the system.

The entry point to making sense of the build system is the main.mk file found in the build/make/core/ directory, which is invoked through the top-level makefile.

The build can be configured either by the use of the envsetup.sh and lunch commands or by providing a buildspec.mk file at the top-level directory. In either case, some of the following variables need to be set.
  • TARGET_PRODUCT
  • 'generic' or some specific board or platform name
  • TARGET_BUILD_VARIANT
  • 'user', 'userdebug', or 'eng'
  • TARGET_BUILD_TYPE
  • 'release' or 'debug'
  • TARGET_TOOLS_PREFIX
  • OUT_DIR
  • BUILD_ENV_SEQUENCE_NUMBER

envsetup.sh defines a series of shell functions that are useful to any sort of AOSP work:
  • printconfig
  • Prints the current configuration as set by the lunch and choosecombo commands.
  • m
  • Runs make from the top of the tree. This is useful because you can run make from within subdirectories. If you have the TOP environment variable set, it uses that. If you don't, it looks up the tree from the current directory, trying to find the top of the tree.
  • croot
  • cd to the top of the tree.
  • sgrep
  • grep for the regex you provide in all .c, .cpp, .h, .java, and .xml files below the current directory. - lunch: - tapas: - croot: - m: - mm: - mmm: - cgrep: - jgrep: - resgrep: Greps on all local res/*.xml files. - godir: Go to the directory containing a file.
To build a specific module:
1. make android_module_name
    The android_module_name can be found in the file Android.mk with the following form:
        LOCAL_MODULE := android_module_name
    For ex., system/core/init/Android.mk:
        LOCAL_MODULE := init
    To build the module init:
        make init
2. mmm patch_of_module
    For ex., to build the module under the path system/core/init:
        mmm system/core/init

3. cd patch_of_module; mm

    For ex., to build the module under the path system/core/init:
        cd system/core/init; mm

The building of a specific module doesn't generate a new Android file system image.
You need to append the snod target to the make command. For ex.,
    make input snod

留言

熱門文章