android makefile 语法总结

来源:互联网 发布:网络算命婚姻 编辑:程序博客网 时间:2024/06/03 04:35

以下android.mk 文件为例来说明一下android makefile 文件

 

LOCAL_PATH := $(call my-dir)  

 

include $(CLEAR_VARS)

 

LOCAL_C_INCLUDES := \

         $(LOCAL_PATH)/../lib/include \

         $(LOCAL_PATH)/include

 

LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog

 

LOCAL_MODULE    := libjni_eng_mode

LOCAL_MODULE_TAGS := optional

 

LOCAL_SRC_FILES := \

        com_yulong_engineering_interfaces_EngineeringManager.c \

        eng_mode_functions.c \

        eng_utils.c

 

LOCAL_SHARED_LIBRARIES := lib_eng_mode

#LOCAL_32_BIT_ONLY := true

 

include $(BUILD_SHARED_LIBRARY)

 

Android.mk基本组成

1.   LOCAL_PATH 定义了当前模块的相对路径,必须出现在所有的编译模块之前

2.   每个编译模块由include $(CLEAR_VARS) 开始,由include $(BUILD_XXX) 结束

3.   include $(CLEAR_VARS) 是一个编译模块的开始,它会清空除LOCAL_PATH之外的所有LOCA_XXX变量

4.  include $(BUILD_XXX) 是编译目标。

5.   LOCAL_SRC_FILES 定义了本模块编译使用的源文件,采用的是基于LOCAL_PATH的相对路径

6.   LOCAL_MODULE 定义了本模块的模块名

 

可选项:

·        LOCAL_STATIC_LIBRARIES 表示编译本模块时需要链接的静态库

·        LOCAL_C_INCLUDES 表示了本模块需要引用的include文件

 

以下对一些项目进行分析

 

一 编译目标(include $(BUILD_XXX)  一般在最后)

编译目标如下表

编译目标

说明

BUILD_HOST_STATIC_LIBRARY

主机上的静态库

BUILD_HOST_SHARED_LIBRARY

主机上的动态库

BUILD_HOST_EXECUTABLE

主机上的可执行文件

BUILD_STATIC_LIBRARY

目标设备上的静态库

BUILD_SHARED_LIBRARY

目标设备上的动态库

BUILD_EXECUTABLE

目标设备上的可执行文件

BUILD_JAVA_LIBRARY

JAVA库

BUILD_STATIC_JAVA_LIBRARY

静态JAVA库

BUILD_HOST_JAVA_LIBRARY

主机上的JAVA库

BUILD_PACKAGE

APK程序

 

二 LOCAL_PATH

为什么需要首先定义LOCAL_PATH呢?

请看一下NDK 文件的描述

This is a list of source files that will be built for your module. Only list the files that will be passed to a compiler, since the build system automatically computes dependencies for you.
Note that  source files names are all relative to LOCAL_PATH and you can use path components .

因此在定义LOCAL_SRC_FILES 时已经间接的使用到了LOCAL_PATH变量,即定义LOCAL_SRC_FILES是用的基于当前路径的相对路径。

 

所以LOCAL_PATH的定义必须要放在任何include $(CLEAR_VARS)语句之前,如果不这么做的话,编译就直接报错,停止不干了。

 

通常LOCAL_PATH := $(call my-dir),也就是当前目录(一般android.mk文件都会放到对应编译模块下。)

 

三  include $(CLEAR_VARS)

   编译模块的开始,它会清空之前的所有代码(除LOCAL_PATH之外)

四 LOCAL_SRC_FILES

从变量名可以很容易看出,定义了模块的源文件列表。

LOCAL_MODULE 

定义编译模块的模块名。

LOCAL_MODULE_TAGS

user: 指该模块只在user版本下才编译
eng: 指该模块只在eng版本下才编译
tests: 指该模块只在tests版本下才编译
optional:指该模块在所有版本下都编译

七 LOCAL_SHARED_LIBRARIES

LOCAL_SHARED_LIBRARIES:当前模块在运行时依赖的动态库的名称。

LOCAL_STATIC_LIBRARIES:当前模块在运行时依赖的静态库的名称

 

八  LOCAL_32_BIT_ONLY

仅构建32位静态库、动态库、可执行文件

这中参数的设置可以采用以下三种:

1. LOCAL_32_BIT_ONLY := true

2. TARGET_PREFER_32_BIT := true

3.    LOCAL_MULTILIB

   第三种的值可以是以下几种:

·         "both": build both 32-bit and 64-bit.

·         "32": build only 32-bit.

·         "64": build only 64-bit.

·         "first": build for only the first arch (32-bit in 32-bit devices and 64-bit in 64-bit devices).

·         "": the default; the build system decides what arch to build based on the module class and other LOCAL_ variables, such as LOCAL_MODULE_TARGET_ARCH, LOCAL_32_BIT_ONLY, etc.

0 0
原创粉丝点击