Makefile comprehension (4) [compile makefile in the Android. mk analysis module]

Source: Internet
Author: User

Finally, C ++ code porting was introduced to bootloader. The only achievement was familiarity with makefile. Some factory companies could not afford to be hurt. Every time they had to do something to meet the needs of factory-side testing, in order to be able to meet the requirements of the factory for testing in Boot, after discussion with the chip company, only C ++ can be obtained to boot, it is really a second decision that boot will eventually achieve 2 m larger than some kernel. However, if the boss had to do this, he had a strong scalp and now he was quite happy. After being forced, the potential of the person was quite great.

The functions used in makefile are still being studied, and the usage of the main functions will be written later.

Because we are engaged in Android driver development, we need to access Android. mk every day.
1. Run. Build/envsetup. Sh to generate some operations, such as chooseproduct mmm.
2. Run the chooseproduct project to select the project to be compiled
3. Run make to compile the entire android source.

How can I compile Android source?

First write a simple Android. mk

Local_path: = $ (call my-DIR) # specify the current directory include $ (clear_vars) # introduce the compilation variable local_module_tags: = optional # When the compilation option is used to compile local_src_files: = hello. C # source file (multiple files can be specified) local_module: = hello # The compiled Module name local_module_class: = executables # specifies the location to be placed after compilation (This indicates to be placed under system/bin) include $ (build_executable) # introduce the rules for compiling into executable files

The above Android. mk will compile a hello executable file and put it in system/bin.

Local_path: Specifies the directory. The preceding statements indicate the current directory. (The my-Dir function is the path generated by the. Build/envsetup. Sh command during Android compilation to obtain the current directory)

Clear_vars: Android has its own set of code compilation rules, compilation options, and other variable definitions. This variable will be introduced. It is actually clear_vas.mk under Android/build/core,

Clear_vas.mk

############################################################ Clear out values of all variables used by rule templates.###########################################################LOCAL_MODULE:=                                                                          LOCAL_MODULE_PATH:=LOCAL_MODULE_STEM:=LOCAL_DONT_CHECK_MODULE:=LOCAL_CHECKED_MODULE:= ...LOCAL_CERTIFICATE:=LOCAL_SDK_VERSION:=LOCAL_NDK_VERSION:=LOCAL_NO_EMMA_INSTRUMENT:=LOCAL_NO_EMMA_COMPILE:=LOCAL_PROGUARD_ENABLED:= # '',optonly,full,customLOCAL_PROGUARD_FLAGS:=LOCAL_PROGUARD_FLAG_FILES:=LOCAL_EMMA_COVERAGE_FILTER:=LOCAL_MANIFEST_FILE:=LOCAL_BUILD_HOST_DEX:=LOCAL_DEX_PREOPT:=LOCAL_DEX_PREOPT:=# Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to# iterate over thousands of entries every time.# Leave the current makefile to make sure we don't break anything# that expects to be able to find the name of the current makefile.MAKEFILE_LIST := $(lastword $(MAKEFILE_LIST))

Variable definitions frequently used when compiling C/C ++ code

Local_module indicates the name of the currently compiled module.

Local_module_tags indicates when to compile the module

There are several options

User The module is compiled only under the user.
Eng Module compilation in Eng Mode
Tests Compile in test state
Optional This module is compiled in All Versions

That is, the target_build_variant = ENG compiles the tags into The ENG and optional modules.

Local_src_files indicates that multiple source programs are required for compiling this module.

Local_c_include if you do not call the standard library header file and the current directory header file, you must specify the header file location and the directory of the header file here.

Local_static_libraries: Specifies the static library to be connected. For example, some common standard libraries do not need to be specified.

Local_shared_libraries: Specifies the dynamic library to be connected.

Finally, include $ (build_xxx) indicates the compiled module type. There are three types:

Build_executable Compiled into executable modules Build/CORE/host_executable.mk
Build_static_library Compile to static library Build/CORE/host_static_library.mk
Build_shared_library Compile to dynamic library Build/CORE/host_shared_library.mk

Local_module_class identifies the last position of the compiled module. If this parameter is not specified, it is not placed in the system, and then placed in the corresponding directory under the final OBJ directory.

Local_module_class: = etc # indicates that it is stored in the system/etc directory.

Local_module_class: = executables # stored in/system/bin

Local_module_class: = shared_libraries # Put it under/system/lib

There are many global MK compiled in build/core, such as compiling the C/C ++ rule definitions. mk ......

Let's talk about compiling the makefile of the kernel module.

Ifneq ($ (kernelrelease),) # check that all kernel versions have been defined. obj-M: = modules # If defined, the compiled Module name is gps_onoff.o # product) else # This branch PWD :=$ (shell PWD) # specifies the source file directory kdir? =/Home/ZK/pop_td/marvell-pxa920-kernel # specify to the directory of the compiled kernel # If the module on the PC is compiled, specify to the currently running kernel # (uname-r view the current kernel version) # (in this case, the kernel version is also defined as kernelrelease not empty) # The kernel compilation command specifies the hardware system and cross-compilation tool all: $ (make)-C $ (kdir) M = $ (PWD) Modules arch = arm cross_compile = arm-Eabi-# Make clean to clear the compiled files before re-compiling the kernel. Otherwise, an error occurs during compilation: Clean: Rm-RF. **. ko *. O *. CMD *. tmp_version *. mod. C *. order module. * endif

The mkefile of the compilation module is read twice. When makefile is called from the command line, kernelrelease is not set yet,

When running to kdir, it will point to a kernel construction tree,

When you run $ (make), The make command is run for the second time. In this case, obj-M is set to construct the real kernel module.

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.