Android config Android.mk parameter

0x00 LOCAL_PATH

According to Android build system requirements, Android.mk document must begin with a definition of LOCAL_PATH variables.

LOCAL_PATH := $(call my-dir)

Construction LOCAL_PATH Android system uses to locate the source file. Since the amount of change is set to hard-coded value is inappropriate, the Android build system provides a macro function is called my-dir. By setting the variable my-dir return value of the macro function, which can be placed in the current directory.

0x01 CLEAR_VARS

Construction CLEAR_VARS Android system variable is set to the position clear-vars.mk fragments. Makefile fragment may comprise in addition LOCAL_PATH clear LOCAL_name variable, e.g. LOCAL_SRC_FILE LOCAL_MODULE and the like.

Include $(CLEAR_VARS)

This is because the analytical system may construct a plurality Android build and schema definitions in a single execution, LOCAL_ <name> is a global variable. Clear them to avoid conflict, each a native component is called a module.

0x02 LOCAL_MODULE

These are used to change the module sets a unique name. The following code names of the modules to hello-jni:

LOCAL_MODULE := hello-jni

Because the module name is also used to build process the generated file name, to the file system constructed so add the appropriate prefix and suffix. In this example, hello-jni module will generate a shared file system will be constructed and named it libhello-jni.so.

0x03 LOCAL_SRC_FILES

The variables used to build and assemble a list of source files this module.

LOCAL_SRC_FILES := hello-jni.c

Here, hello-jni only one source file generating module, and LOCAL_SRC_FILES space separated variable may comprise a plurality of source file names.

0x04 BUILD_SHARED_LIBRARY

In order to establish the main application modules available for use, it must become the shared library modules. Android NDK build system variable is set to the BUILD_SHARED_LIBRARY saved build_shared_libray.mk file location. Makefile fragment contains the necessary changes to the process to build and assemble into source files shared libraries.

include $(BUILD_SHARED_LIBRARY)

0x05 BUILD_STATIC_LIBRARY

Create a static library, Android applications do not directly use a static library, the third-party code is generally introduced as a static library dynamic library use.

include $(BUILD_STATIC_LIBRARY)

0x06 introduction of shared and static libraries

LOCAL_SHARED_LIBRARY := avilib_share
LOCAL_STATIC_LIBRARY := avilib_static

0x07 multi-project sharing module

When multiple projects share a module, the first source import %NDK_HOME%/source, configure the corresponding Android.mk file. In the project need to add:

LOCAL_SHARED_LIBRARIES := avilib
$(call import-module, transcode/avilib) 

Prebuilt library with 0x08

The file has been compiled as a shared module, so the project:

LOCAL_PATH := $(call my-dir)
#第三方模块
include $(CLEAR_VARS)
LOCAL_MODULE := avilib
LOCAL_SRC_FILES := libavilib.so

include $(RREBUILT_SHARED_LIBRARY)

0x09 build an executable file

include $(BUILD_EXECUTABLE)

0x10 other build system variables

#目标 CPU 体系结构名称
TARGET_ARCH := arm

#目标 Android 平台名称
TARGET_PLARFORM := andoid-3

#目标 CPU 体系结构和 ABI 名称
TARGET_ARCH_ABI := armeabi-v7a

#目标平台和 ABI 串联
TARGET_ABI := android-3-armeabi-v7a

#重定向输出文件名(默认为 LOCAL_MODULE)
LOCAL_MODULE_FILENAME := avilib

#指定 C++ 源码文件扩展名
LOCAL_CPP_EXTENSION := .cpp .cxx

#指定模块所依赖的具体 C++ 特性
LOCAL_CPP_FEATURES := rtti

#可选目录列表,NDK安装目录的相对路径,用来搜索头文件
LOCAL_C_INCLUDES := sources/shared-module

#添加编译器标志(添加宏定义)
LOCAL_CFLAGS := -DNDEBUG -DPROT=1234

#添加编译器标志(添加宏定义)仅C++
LOCAL_CPP_CFLAGS := -DNDEBUG -DPROT=1234

#LOCAL_STATIC_LIBRARY变体,所有静态库内容(当几个静态库有循环依赖的时候很有用)
LOCAL_WHOLE_STATIC_LIBRARY := avilib bvilib

#链接标志的可选列表
LOCAL_LDLIBS := -llog

#禁止生产文件中进行缺失符号检查
LOCAL_ALLOW_UNDEFINED_SYMBOLS :

#指定要生成的 ARM 二进制类型
LOCAL_ARM_MODE := arm

#开启 NEON 指令
LOCAL_ARM_NEON := true

#禁用 NX bit 安全特性(Never Execute)
LOCAL_DISABLE_NO_EXECUTE := true

#记录一组编译器标志
LOCAL_EXPORT_CFLAGS := -DENABLE_AUDIO

#与上面类型,仅用于 C++
LOCAL_EXPORT_CPPFLAGS := -DENABLE_AUDIO

#与 LOCAL_EXPORT_CFLAGS 类型用于链接器标志
LOCAL_EXPORT_LDFLAGS := -DENABLE_AUDIO

#允许记录路径集
LOCAL_EXPORT_C_INCLUDES :=

#用于有大量资源或者独立的静态库/动态库的模块,分解命令长度
LOCAL_SHORT_COMMANDS := true

#定义了用于过滤来至 LOCAL_SRC_FILES变量的装配文件的应用程序
LOCAL_FILTER_ASM :=

0x11 other building systems function macros

#返回当前目录下的所有子目录下的 Android.mk 构建文件列表
include $(call all-subdir-makefiles)

#放回当前 Android.mk 构建文件的路径
this-makefile

#返回包含当前构建文件的父 Android.mk 构建文件路径
parent-makefile

#和 parent-makefile 一样但用于祖父目录
grand-parent-makefile

0x12 define a new variable

LOCAL_ and the beginning of the NDK_ name is reserved for constructing, variables can be used at the beginning of MY_

MY_SRC_FILES := avilib.c platform_posix.c

LOCAL_SRC_FILES := $(addprefix avilib/, $(MY_SRC_FILES))

0x13 operating conditions

It contains a different set of source code files in each architecture

ifeq ($(TARGET_ARCH), arm)
    LOCAL_SRC_FILES += armonly.c
else
    LOCAL_SRC_FILES += generic.c
endif

0x14 Application.mk

 
#覆盖 Android.mk 构建的模块列表
APP_MODULES := avilib 

#设置二进制文件的优化级别,默认 release
APP_OPTIM := relase / debug

#编译器标志
APP_CLAGS

#编译器标志,作用于 C++ 源文件
APP_CPPLAGS

#从非 jni 子目录下查找 Android.mk 构建文件
APP_BUILD_SCRIPT

#构建系统的二进制文件,默认 armeabi ABI
APP_ABI := all / armeabi mips

#使用不同 STL 实现库,默认 system 库
APP_STL := stlport_shared

#与 LOCAL_CPP_EXTENSIONS 变量相似,表明所有模块都依赖与具体的 C++ 特性,如 RTTI,exceptions
APP_GUNSTL_FORCE_CPP_FEATURES

#与 LOCAL_SHORT_COMMANDS 变量类似
APP_SHORT_COMMANDS

Guess you like

Origin www.cnblogs.com/YZFHKMS-X/p/12635667.html