Common syntax in Android. mk
The Android. mk compilation file is used to describe your C and C ++ source code files to Android NDK. Today I checked some common syntaxes.
I. Overview: An Android. mk file is used to describe your source code to the compilation system.
Specifically, this file is a small part of GNU Makefile and will be parsed by the compilation system once or more build systems.
You can define one or more modules in each Android. mk file,
You can also use the same source code file in several modules.
Syntax 1 must define the content first:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := XXXLOCAL_FILES := XXX.cpp...include $(BUILD_XXX)
The specific meaning is as follows:
LOCAL_PATH: = $ (call my-dir)
Each Android. mk file must start with LOCAL_PATH. It is used to search for source files in the Development tree.
My-dir is a macro function provided by a compilation system. It returns the current path, that is, the file directory containing Android. mk.
Include $ (CLEAR_VARS)
The CLEAR_VARS variable is provided by compilation and points to a GNU Makefile, which is used to clear the LOCAL_xxx variable (not LOCAL_PATH ).
Because all the compilation control files are parsed and executed by the same GNU Make, and their variables are global, mutual influence can be avoided after cleaning.
LOCAL_MODULE: = XXX
LOCAL_MODULE is the module name and must be defined before include $ (BUILD_XXXXX). It is unique and does not contain spaces.
LOCAL_SRC_FILES: = XXX. cpp
The source file list must contain the C/C ++ source code to be packaged as a module.
You do not need to list header files. The compilation system will automatically find the dependency header files.
The default C ++ source code extension is. cpp. You can also modify it through LOCAL_CPP_EXTENSION.
Include $ (XXX)
Collects all LOCAL_XXX information since the last call of include $ (CLEAR_VARS. And decide the reason for compilation.
This section only describes two commonly used methods:
BUILD_STATIC_LIBRARY: compile as a static library and generate a file named lib $ (LOCAL_MODULE). so.
BUILD_SHARED_LIBRARY: compile as a dynamic library and generate a file named lib $ (LOCAL_MODULE)..
2 common optional content: LOCAL_MODULE_FILENAME: = XXX
Generally, after LOCAL_MODULE: = XXX, it is used to overwrite LOCAL_MODULE and redefine the final target file name.
LOCAL_CPP_EXTENSION: =. cXX
Indicates the C ++ extension. For example, LOCAL_CPP_EXTENSION: =. cxx. cpp. cc.
LOCAL_C_INCLUDES: = XXX
Specify the include path. These directories will be attached during compilation.
For example:
LOCAL_C_INCLUDES: = $ (LOCAL_PATH)/.../../Classes \
$ (LOCAL_PATH)/.../../Classes/SdkController \
$ (LOCAL_PATH)/.../../Classes/SdkController/android \
$ (LOCAL_PATH)/.../../Classes/ingress controller \
$ (LOCAL_PATH)/.../cocos2dx/platform/android/jni
LOCAL_CFLAGS: = XXX, LOCAL_CPPFLAGS: = XXX
Used to add compilation options when compiling C/C ++.
For example:
LOCAL_CFLAGS: = \
-Wno-multichar \
-DAndroid \
-DLIBDIR = "c "\
-DBUILDING_LIBICONV \
-DIN_LIBRARY
LOCAL_WHOLE_STATIC_LIBRARIES: = XXX
The full link of the static library. The compiler will complete the link of the static library without deleting and optimizing it.
Unlike LOCAL_STATIC_LIBRARIES, it is similar to using -- whole-archive.
For example:
LOCAL_WHOLE_STATIC_LIBRARIES: = cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES + = cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES + = cocos_lua_static
Import-module:
Allows you to search for and import other modules to Android. mk. It searches for the specified Module name from NDK_MODULE_PATH.
$ (Call import-module, )
For example:
$ (Call import-module, cocos2dx)
$ (Call import-module, CocosDenshion/android)
$ (Call import-module, scripting/lua/proj. android)
Appendix: Refer to blog
Http://www.cnblogs.com/wainiwann/p/3837936.html
Http://www.cnblogs.com/leaven/archive/2011/01/25/1944688.html