Simple analysis of ANDROID.MK files

Source: Internet
Author: User

android.mk simple analysis of files

a android.mk file is used to describe the source code that needs to be compiled to the compilation system. Specifically: The file is a small part of the gnumakefile that is parsed one or more times by the compiled system. You can define one or more modules in each of the android.mk, or you can use the same source code file in several modules.


Each module belongs to one of the following types:

1 apk Program, General Android program, compile package build apk file

2 ) Java Library, Java class Library, compile package build jar file

3) c\c++ application, executable c\c++ application

4 c\c++ Static libraries, compile and build c\c++ static libraries, and package them as. A Files

5 c\c++ share libraries, compile and build shared libraries (dynamic link libraries), and package them as. So, and only shared libraries can be installed/copied into the Application (APK) package.


A simple example


A simple "Hello World", such as the following file:

Sources/helloworld/helloworld.c

Sources/helloworld/android.mk

the corresponding android.mk file will look like this:

Local_path: = $ (call My-dir)  include $ (clear_vars)  local_module  : = HelloWorld  Local_src_files: = HELLOWORLD.C  include $ (build_shared_library)  


Brief description:

1 , Local_path: = $ (call My-dir) , a android.mk File first of all, you must define Local_path variable. It is used to find source files in the development tree. In this example, the macro function ' My-dir ', provided by the compilation system, is used to return the current path (that is , the directory that contains the android.mk file).

2,include $ (clear_vars),Clear_varsprovided by the compilation system ((can be inAndroidunder the installation directory/build/core/config.mkThe file sees its definition asclear_vars:=$ (Build_system)/clear_vars.mk)), specify to letGNU MAKEFILEfor you to clear manylocal_xxxvariables, such aslocal_module,local_src_files, Local_static_libraries,wait...),exceptLocal_path. This is necessary because all the compilation control files are in the sameGNU Makein the execution environment, all variables are global.

3 , local_module: = HelloWorld , Local_module variables must be defined , to identify you in android.mk each module described in the file. The name must be unique and does not contain any spaces. Note that the compilation system will automatically generate the appropriate prefix and suffix, in other words, a shared library module named ' foo ' will generate ' libfoo.so ' files.


4 , local_src_files: = HELLOWORLD.C , Local_src_files The variable must contain the package that will be compiled into the module. C or C + + source code files. Note that you do not have to list header files and include files here, because the compilation system will automatically find the dependent files for you; Just list the source code files that are passed directly to the compiler.


Other commonly used ones are:


5 , Local_c_includes : An optional variable that represents the search path for the header file. The default header file search path is the local_path directory. Example:local_c_includes: = Sources/foo or local_c_includes: = $ (local_path)/... /foo


6 , Target_arch : Target CPU the name of the platform; Target_platform : android.mk At the time of parsing, the target Android the name of the platform; Arget_arch_abi : Only two currently supported value , Armeabi and the armeabi-v7a


7 , local_static_libraries: indicates which static libraries the module needs to use in order to link at compile time.


8 , local_shared_libraries: represents a shared library that the module depends on at run time ( Dynamic Library ), which is required at link time to embed its corresponding information when the file is generated.


9 , Local_ldlibs: The additional that will be used when compiling the module linker options.


Ten , Local_arm_mode: by default, Arm the target binary is Thumb form of Generation ( each ) , you can set this variable to Arm If you want your Module is to + the form of a bit instruction


One , Local_cflags: The optional compiler option, which compiles the C code files are used when


A , include $ (call All-subdir-makefiles) : Returns a location in the current ' My-dir ' all of the subdirectories in the path android.mk the list.


----------------------

In addition:

in the android.mk file, you can also specify the final target installation path, using the Local_module_path and the Local_unstripped_path to specify. Different file system paths are selected with the following macros:


Target_root_out : represents the root file system Out/target/product/generic/root .

Target_out : represents system File System Out/target/product/generic/system .

Target_out_data : represents Data File System Out/target/product/generic/data .

Out_dir : Code Engineering compile-time out Build Directory

product_out: Image Generation directory

Simple analysis of ANDROID.MK files

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.