ANDROID.MK file parsing under Android

Source: Internet
Author: User

1 overview

We all know that under Linux the editor often writes a makefile file, which can be used to interpret the makefile file as a compiled configuration file, which holds the configuration information about how the compiler compiles the program, and determines what the result of the compilation is. While the Android.mk file under Android is also a type of function, as the name implies, can be guessed from the names, the Android.mk file is for Android makefile files. Specifically: The file is a small part of the GNU makefile, will be parsed one or more times by the compiled system. You can define one or more modules in each android.mk file, and you can use the same source code file in several modules. The compilation system handles many detail issues for you.

2 overall structure of the ANDROID.MK

For example, the contents of a android.mk are as follows:

Local_path:= $ (call My-dir) include $ (clear_vars) local_src_files:= android_media_mediaplayer.cpp Android_media_medi ARecorder.cpp android_media_mediascanner.cpp android_media_mediametadataretriever.cpp Android_media_resamplein PutStream.cpp android_media_mediaprofiles.cpp android_media_amrinputstream.cpp Android_media_utils.cpp and Roid_mtp_mtpdatabase.cpp android_mtp_mtpdevice.cpp android_mtp_mtpserver.cpp local_shared_libraries: = Libandr     Oid_runtime libnativehelper libutils libbinder libmedia libskia libui libcutils Libgui Libstagefright libcamera_client libsqlite libmtp libusbhost libexiflocal_c_includes + = external/j Head External/tremor/tremor frameworks/base/core/jni Frameworks/base/media/libmedia frameworks/base/media/ LIBSTAGEFRIGHT/CODECS/AMRNB/ENC/SRC Frameworks/base/media/libstagefright/codecs/amrnb/common frameworks/base/ media/libstagefright/codecs/aMrnb/common/include FRAMEWORKS/BASE/MEDIA/MTP $ (pv_includes) $ (jni_h_include) $ (call include-path-for, cor ECG graphics) local_cflags +=local_ldlibs: =-lpthreadlocal_module:= libmedia_jniinclude $ (build_shared_library) # Build libsoundpool.so# Build Libaudioeffect_jni.soinclude $ (call all-makefiles-under,$ (Local_path))

You must first define the Local_path variable. Then clear all the values of the LOCAL_XX variable, except the value of Local_path, and then define the source file, the header file, followed by the compile option parameter, followed by the compilation of the generated file name, and finally the resulting file type.

Variable definition within 3 ANDROID.MK 3.1 Local_path

A android.mk file must first define a good local_path variable. It is used to find source files in the development tree. For example:

Local_path:= $ (call My-dir)

Macro function ' My-dir ', provided by the compilation system, for returning the current path (that is, the directory containing the android.mk file)

3.2include $ (clear_vars)

Macro Clear_vars is provided by the compilation system, specifying that GNU makefile clears many local_xxx variables for you (such as Local_module, Local_src_files,local_static_libraries, and so on ...). ), except Local_path. This is necessary because all the compilation control files are in the same GNU make execution environment, and all the variables are global.

3.3 Local_src_files

Source files that need to be compiled this time

3.4 local_shared_libraries

This compilation requires a linked dynamic link library file, which is a. so file

3.5 local_static_libraries

Static link library.

3.6 Local_c_includes

This compilation needs to include a header file, a list of paths relative to the current directory, and it will be added to the include search path when compiling all the source files (c,c++ and compilations). For example:
Local_c_includes: = Sources/foo
or even:
Local_c_includes: = $ (Local_path)/. /foo

3.6 Local_ldlibs

Link Options for this compilation, equivalent to the parameters after Gcc-l

3.7 Local_cflags

The same is the compile option, which is equivalent to the parameters behind Gcc-o

3.8 Local_module

The generated module name, which must be defined to indicate the name of the file that will be generated after make

3.9Local_package_name

APK file name

4 include

Include can be more like Android in this form, such as: Include $ (clear_vars), include $ (build_shared_library). In fact, this include can be understood as "execution" meaning, then what to do? ? Of course, look at the macro behind.

Macro Clear_vars has been introduced in section 3.2, which indicates that some variables are cleared.

Macro Build_shared_library indicates that a shared library is generated, that is, the. so file is generated

Therefore, the include $ (build_shared_library) is specified to generate a lib$ (local_moudule). So file in the/system/lib/directory, the same type of macro as follows:

    • clear_vars                                               Clear local_xxx variable
    • Build_shared_library generate lib$ (local_moudule). So file in the/system/lib/directory
    • build_static_library Generate lib$ (local_moudule). a file
    • build_executable Generating executable files in/system/bin/directory
    • Build_package compiled into an apk file


Android.mk file parsing under Android

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.