Android NDK Learning (ii): Compiling script syntax android.mk and APPLICATION.MK

Source: Internet
Author: User

First, ANDROID.MK

Android.mk is divided into several parts:

    • local_path:= $ (call My-dir), which returns the path to the current file in the system, which must be defined at the beginning of the Android.mk file.
    • include $ (clear_vars), which indicates that all global variables in the previous build process are clear, because in a makefile compilation script, a large number of global variables are used, and this line of script indicates that all global variables need to be cleared.
    • Local_src_files, to compile C or CPP files, note that there is no need to enumerate header files, the build system will automatically help developers rely on these files.
    • local_static_libraries, dependent static library file
    • local_ldlibs:=-l$ (sysroot)/usr/lib-llog-lopensles-lglesv2- Legl-lz, which specifies the dynamic and static libraries that the NDK relies on for the compilation process, the Sysroot variable represents the ndk_root below the directory $ndk_root/platforms/android-18/arch-arm, while in this directory the usr/ The lib/directory has a number of dynamic libraries for so and static libraries for. A. The
    • local_cflags compiles the compile flags for C or CPP that are sent to the compiler when it is actually compiled. For example, the common example is to add-dauto_test, and then in the code can use the condition to Judge #ifdef Auto_test to do something related to automated testing.
    • local_ldflags, an optional list of link flags that are brought to the linker when the destination file is linked to generate an output file. This directive is somewhat similar to Local_ldlibs, which, in general, is used to specify a third-party compiled static library, local_ldlibs often used to specify the system's libraries (such as Log,opengl ES, EGL, etc.).
    • Local_module, the name of the compiled target of the module, used to differentiate the modules, the name must be unique and does not contain spaces, if the compilation target is so library, then the names of the so library is the LIB project name. So.
    • include$ (build_shared_library), in fact, there are many similar include, is to build system-provided built-in variables, the meaning of this variable is to build a dynamic library, the other built-in variables include the following:

---build_static_library: building a static library

---prebuild_static_library: The existing static libraries are packaged to make them into a module.

---prebuild_share_library: The existing dynamic libraries are packaged to make them into a module.

---build_executable: Build the executable file.

Building systems provide good built-in variables where can you see big? They are all in the $ndk-root/build/core/directory, there will be all pre-defined makefile, the developer includes a variable, is actually the corresponding makefile included in the ANDROID.MK, including the previously mentioned clear _vars, which is also a makefile below the directory.

    • include$ (call All-makefiles-under, $ (Local_path)) is also the build system-supplied variable that returns the Android.mk list of all subdirectories under that directory.
Second, application.mk

The application.mk is divided into the following sections:

    • App_abi: =xxx, here the XXX refers to different platforms, you can choose to fill the x86, MIPS, Armeabi, Armeabi-v7a,all, etc., it is worth mentioning that if you choose all to build all the platform so, if you do not fill in this, The default is built as a library under the Armeabi platform.
    • App_stl: = gnustl_static, the NDK build system provides a C + + header file for the smallest C + + Runtime library (/system/lib/libstdc++.so) given by the Android system. The NDK then comes with another C + + implementation that developers can use or link to in their own applications, and define APP_STL to choose one of them, including Stlport_static, stlport_shared, gnustl_static.
    • app_cppflags: =-std=gnu++11-fexceptions, which specifies flag during compilation, can turn on features such as  exception rtti in this option, but it is best to turn off rtti for efficiency.
    • ndk_toolchain_version = 4.8, specifying the version number within the cross-tool compilation chain, which specifies the use of 4.8.
    • app_platform:= android-9, which specifies the platform on which to create the dynamic library.
    • App_optim: = release, the variable is optional, used to define ' release ' or ' Debug ', ' Release ' mode is the default, and will generate highly optimized binary code, ' debug ' Patterns generate binary code that is not optimized, but can detect a lot of bugs, often used in the debug phase, or the equivalent of adding parameter ndk-debug=1 after the ndk-build instruction.
Third, the case Analysis 1. In the above we understand the basic grammar rules in android.mk, then after the input ndk-build, the system will use which compiler and the packager and linker to compile our program? A: You will use the GCC, g++, AR, LD and other tools under the $ndk_root/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/directory. The same strip tool in this directory will be used to clear the source code in the so package, and the NM tool allows developers to view a list of symbols under the static library. 2. Where does the header file go when GCC is compiled? A: $NDK The _root/platforms/android-18/arch-arm/usr/include/directory will contain the header files that the compilation process relies on. 3. Where will the log or OpenGL ES and other libraries that are often used during the link process be stored? A: The library files that are dependent on the link process are stored under the/platforms/android-18/arch-arm/usr/lib directory.

Android NDK Learning (ii): Compiling script syntax android.mk and APPLICATION.MK

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.