【转】Application.mk 文件语法规范

原文网址:http://blog.sina.com.cn/s/blog_4c451e0e0100s6q4.html

Application.mk file syntax specification

Application.mk 文件语法规范

Introduction:

介绍:

-------------

This document describes the syntax of Application.mk build files

written to describe the native modules required by your Android

application. To understand what follows, it is assumed that you have

read the docs/OVERVIEW.html file that explains their role and

usage.

本文档描述了 Application.mk 生成文件的语法,以及根据你的 Android 应用程序要求描述本机模块。

为了理解下面内容,假设你有读过 docs/OVERVIEW.html 文件,明白了它们的作用和用法。

Readers of this document should have read docs/OVERVIEW.html and

docs/ANDROID-MK.html

本文档的读者将有读过 docs/OVERVIEW.html 和 docs/ANDROID-MK.html

Overview:

概述:

---------

The purpose of Application.mk is to describe which native

‘modules‘ (i.e. static/shared libraries) are needed by your

application.

Application.mk 文件的目地是来描述被你的应用程序所需要的本机模块(也就是:静态库或共享库)。

An Application.mk file is usually placed under $PROJECT/jni/Application.mk,

where $PROJECT points to your application‘s project directory.

一个 Application.mk 文件通常是放置在 $PROJECT/jni/Application.mk 这个路径下面,

$PROJECT 意味着你应用程序的工程目录。

Another alternative is to place it under a sub-directory of the top-level

$NDK/apps directory, e.g.:

另一个可放置的地方是在 $NDK/apps 目录的子目录下,例如:

$NDK/apps/<myapp>/Application.mk

Where <myapp> is a short name used to describe your ‘application‘

to the NDK build system (this name doesn‘t go into your generated

shared libraries or your final packages).

<myapp>是一个短名称用来为 NDK 生成系统描述你的应用程序

(这个名字不会进入你的共享库或你的最终包)。

The Application.mk is really a tiny GNU Makefile fragment that must

define a few variables:

Application.mk 实际上是一个极小的 GNU Makefile 片断,必然要定义几个变量:

APP_PROJECT_PATH

This variable should give the *absolute* path to your

Application‘s project root directory. This is used to copy/install

stripped versions of the generated JNI shared libraries to a

specific location known to the APK-generating tools.

这个变量将提供你应用程序工程根目录的绝对路径。

这是用来拷贝或安装已脱离版本的 JNI 共享库到一个 APK 产生工具已知的具体位置。

Note that it is optional for $PROJECT/jni/Application.mk, but

*mandatory* for $NDK/apps/<myapp>/Application.mk

注意,对于 $PROJECT/jni/Application.mk 它是可选项的,

   但是对于 $NDK/apps/<myapp>/Application.mk 就是强制的了。

APP_MODULES

This variable is optional. If not defined, the NDK will build by

default _all_ the modules declared by your Android.mk, and any

sub-makefile it may include.

这个变量是可选的。

如果没有定义的话,NDK 将通过默认 _all_ 生成由你的 Android.mk 文件声明的所有模块,

并且可以包含任意子 Makefile 文件。

If APP_MODULES is defined, it must be a space-separated list of module

names as they appear in the LOCAL_MODULE definitions of Android.mk

files. Note that the NDK will compute module dependencies automatically.

如果 APP_MODULES 是定义过的,

它一定是一个空格分隔的模块名列表,就像它们出现在 Android.mk 文件的 LOCAL_MODULE 定义中一样。

NOTE: This variable‘s behaviour changed in NDK r4. Before that:

注意:这个变量的行为方式已在 NDK r4 中改变。之前是:

- the variable was mandatory in your Application.mk

- 该变量在你的 Application.mk 文件中是强制的。

- all required modules had to be listed explicitly.

- 全部需要的模块已明确地列出。

APP_OPTIM

This optional variable can be defined to either ‘release‘ or

‘debug‘. This is used to alter the optimization level when

building your application‘s modules.

这个可选的变量可以定义 发行版 或 调试版 。

这是用来在生成你应用程序的模块时改变优化级别。

A ‘release‘ mode is the default, and will generate highly

optimized binaries. The ‘debug‘ mode will generate un-optimized

binaries which are much easier to debug.

发行版 模式是默认的,并且将产生高度地优化二进制代码。

调试版 模式将产生未优化的二进制代码,让调试更容易些。

Note that if your application is debuggable (i.e. if your manifest

sets the android:debuggable attribute to "true" in its <application>

tag), the default will be ‘debug‘ instead of ‘release‘. This can

be overridden by setting APP_OPTIM to ‘release‘.

注意如果你的应用程序是可调试的

(也就是:如果你的 manifest 在它的 <application> 标签中 设置 android:debuggable 属性为 true ),

调度版 模式将替代 发行版 模式成为默认方式。

这可以通过设置 APP_OPTIM 为 release 来不理会。

Note that it is possible to debug both ‘release‘ and ‘debug‘

binaries, but the ‘release‘ builds tend to provide less information

during debugging sessions: some variables are optimized out and

can‘t be inspected, code re-ordering can make stepping through

the code difficult, stack traces may not be reliable, etc...

注意 发行版 模式 和 调试版 模式都可做调式,但是 发行版 模式在调试作业阶段提供较少的信息:

一些变量是被优化掉了不能被视察了,代码再排序让单步调试困难,堆栈跟踪不可信赖,等等。

APP_CFLAGS

A set of C compiler flags passed when compiling any C or C++ source code

of any of the modules. This can be used to change the build of a given

module depending on the application that needs it, instead of modifying

the Android.mk file itself.

一组 C 编译器的标志在编译任意模块的任何 C 或 C++ 源代码时被传递。

这可以是应用程序视情况而定来改变特定模块的生成。

IMPORTANT WARNING:

重要警告:

+++++++++++++++++++++++++++++++++++++++++++++++++++

+

+ All paths in these flags should be relative to the top-level NDK

+ directory. For example, if you have the following setup:

+ 在这些标志中的全部路径将是相对于顶级 NDK 目录。例如,如果你有如下结构:

+

+    sources/foo/Android.mk

+    sources/bar/Android.mk

+

+  To specify in foo/Android.mk that you want to add the path to the

+ ‘bar‘ sources during compilation, you should use:

+ 在 foo/Android.mk 文件中具体指定你想要在编译时期添加 bar 源文件路径,你将使用:

+

+   APP_CFLAGS += -Isources/bar

+

+ Or alternatively:

+ 或者:

+

+   APP_CFLAGS += -I$(LOCAL_PATH)/../bar

+

+ Using ‘-I../bar‘ will *NOT* work since it will be equivalent to

+ ‘-I$NDK_ROOT/../bar‘ instead.

+ 使用 -I../bar 将没有效,因为它将相当于 -I$NDK_ROOT/../bar 。

+

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

NOTE: In android-ndk-1.5_r1, this only applied to C sources, not C++ ones.

This has been corrected to match the full Android build system.

注意:在 android-ndk-1.5_r1 中,这仅适用于 C 源文件,而没有 C++ 编译标志一个。

   这已经改正彻底地匹配 Android 生成系统。

APP_CXXFLAGS

An alias for APP_CPPFLAGS, to be considered obsolete as it may disappear

in a future release of the NDK.

一个 APP_CPPFLAGS 的别名,在未来 NDK 的发行版中考虑到过时的原因,它可能会消失。

APP_CPPFLAGS

A set of C++ compiler flags passed when building C++ sources *only*.

一组 C++ 编译器的标志仅在生成 C++ 源文件时被传递。

NOTE: In android-ndk-1.5_r1, this applied to both C and C++ sources.

This has been corrected to match the full Android build system.

You can now use APP_CFLAGS for flags that shall apply to C and

C++ sources.

注意:在 android-ndk-1.5_r1 中,这适用于 C 和 C++ 两者的源文件。

   这已经改正彻底地匹配 Android 生成系统。

   你可以现在使用 APP_CFLAGS 变量,将适用于 C 和 C++ 源文件。

APP_BUILD_SCRIPT

By default, the NDK build system will look for a file named Android.mk

under $(APP_PROJECT_PATH)/jni, i.e. for the file:

默认情况下,NDK 生成系统将寻找一个名为 Android.mk 文件在 $(APP_PROJECT_PATH)/jni 目录下,

也就是,如此文件:

$(APP_PROJECT_PATH)/jni/Android.mk

If you want to override this behaviour, you can define APP_BUILD_SCRIPT

to point to an alternate build script. A non-absolute path will always

be interpreted as relative to the NDK‘s top-level directory.

如果你想要替代这个行为方式,你可以定义 APP_BUILD_SCRIPT 来指出一个供替换的生成脚本。

一个非绝对路径将一直是被解释为相对于 NDK 顶级目录。

APP_ABI

By default, the NDK build system will generate machine code for the

‘armeabi‘ ABI. This corresponds to an ARMv5TE based CPU with software

floating point operations. You can use APP_ABI to select a different

ABI.

默认情况下,NDK 生成系统将产生适用于 armeabi ABI 机器码。

这符合一个基于 ARMv5TE 的 CPU 对应软件浮点操作。

你可以使用 APP_ABI 来选择一个不同的 ABI 。

For example, to support hardware FPU instructions on ARMv7 based devices,

use:

例如,对于支持硬件 FPU 指令在基于 ARMv7 的设备上,使用:

APP_ABI := armeabi-v7a

Or to support both ARMv5TE and ARMv7 based devices, use:

或对于基于 ARMv5TE 和 ARMv7 两者都支持的设备,使用:

APP_ABI := armeabi armeabi-v7a

For the list of all supported ABIs and details about their usage and

limitations, please read docs/CPU-ARCH-ABIS.html

对于全部支持的 ABI 列表和详细说明关于它们的用法与限制,请阅读 read docs/CPU-ARCH-ABIS.html

APP_STL

By default, the NDK build system provides C++ headers for the minimal

C++ runtime library (/system/lib/libstdc++.so) provided by the Android

system.

默认情况下,NDK 生成系统为由 Android 系统提供的最低限度的 C++ 运行时库(/system/lib/libstdc++.so)提供头文件。

However, the NDK comes with alternative C++ implementations that you can

use or link to in your own applications. Define APP_STL to select one of

them. Examples are:

然而,NDK 提供任你选择的 C++ 实现,你可以使用或链入你的应用程序中。

定义 APP_STL 来选择它们中的一个。例如:

APP_STL := stlport_static    --> static STLport library

APP_STL := stlport_shared    --> shared STLport library

APP_STL := system            --> default C++ runtime library

For more information on the subject, please read docs/CPLUSPLUS-SUPPORT.html

就此话题的更多信息,请阅读 docs/CPLUSPLUS-SUPPORT.html

A trivial Application.mk file would be:

一个普通的 Application.mk 文件将是:

-------------- cut here -------------------------

APP_PROJECT_PATH := <path to project>

-------------- cut here -------------------------

时间: 2024-12-10 22:40:03

【转】Application.mk 文件语法规范的相关文章

Android.mk和Application.mk文件语法规范说明及举例

以下英文内容摘自:http://www.kandroid.org/ndk/docs/OVERVIEW.htmlThe Android NDK is a set of tools that allows Android application developers to embed native machine code compiled from C and/or C++ source files into their application packages. NDK development

Android.mk文件语法规范及使用模板

Android.mk文件语法规范 根据eoeandroid上的的连载,进行一些更新.修改和加亮. 今天翻译ANDROID-MK.TXT文件(英文原文件在/development/Ndk/Docs/android-mk.txt) Android.mk文件语法规范 Introduction: Android.mk编译文件是用来向Android NDK描述你的C,C++源代码文件的, 这篇文档描述了它的语法.在阅读下面的内容之前,假定你已经阅读了docs/OVERVIEW.TXT文件,了解了它们的脚色

【转】Android.mk文件语法规范(Android.mk File)

原文网址:http://blog.csdn.net/smfwuxiao/article/details/8530742 1.Android.mk文件概述 Android.mk文件用来告诉NDK编译系统,应该如何编译这些源码.更确切地说,该文件其实就是一个小型的Makefile.该文件会被NDK的编译工具解析多次,所以要注意不要过多使用环境变量,以免第一次解析时产生的变量影响后面的解析.Android.mk把源码组织成不同的模块,每个模块可以是一个静态库也可以是一个动态库.动态库才会被拷贝到安装包

Android NDK开发指南---Application.mk文件和android.mk文件

https://android.googlesource.com/platform/development/+/donut-release/ndk/docs/OVERVIEW.TXT https://android.googlesource.com/platform/ndk/+/4e159d95ebf23b5f72bb707b0cb1518ef96b3d03/docs/ANDROID-MK.TXT https://android.googlesource.com/platform/ndk/+/4

Android.mk 文件语法详解

转:http://blog.sina.com.cn/s/blog_602f8770010148ce.html ===================================================================================== 0. Android.mk简介: Android.mk文件用来告知NDK Build 系统关于Source的信息. Android.mk将是GNU Makefile的一部分,且将被Build System解析一次或多次

Android JNI的Android.mk文件语法详解

Android.mk简介: Android.mk文件用来告知NDK Build 系统关于Source的信息. Android.mk将是GNU Makefile的一部分,且将被Build System解析一次或多次. 所以,请尽量少的在Android.mk中声明变量,也不要假定任何东西不会在解析过程中定义. Android.mk文件语法允许我们将Source打包成一个"modules". modules可以是: 静态库 动态库. 只有动态库可以被 install/copy到应用程序包(A

NDK开发之Application.mk文件详解

做过NDK开发的同学应该都知道有个Application.mk文件,这是android NDK构建系统使用的一个可选构建文件.它的目的是描述应用程序需要哪些模块,也定义了所有模块的一些通用变量.主要有以下几个变量. APP_MODULES,默认情况下,ndk会构建在android.xk文件中声明的所有模块.但是这个变量可是覆盖上述行为. 假如我们的android.mk文件是这样的: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_

Android.mk文件、Application.mk文件编写规则

在Application.mk文件中有个预定义命令参数APP_ABI,是指明编译与调试的CPU架构. 目前Android系统支持以下七种不同的CPU架构:ARMv5,ARMv7(从2010年起),x86(从2011年),MIPS(从2012年),ARMv8,MIPS64和x86_64(从2014年),每一种都对应相应的ABI. CPU架构 ABI   ARMv5 armeabi 32位,从2010年 ARMv7 armeabi-v7a 32位,从2010年 x86 x86 32位,从2011年

Android.mk 文件语法指南

1 前言 本文档描述了c和c++编写的程序用Android NDK编译时,编译文件Android.mk的语法结构.为了便于理解下面的内容,假设你已经阅读了前面OVERVIEW部分,了解了它们的作用和用法. 2 概要 Android.mk是用来描述源文件是如何进行编译的.更具体的:-Android.mk实际上是一个轻量级的Makefile,它会被编译系统解析一次或多次.因此,你应该尽可能少的声明变量,同时不要假定在解析过程中没有定义任何东西.-Android.mk是用来允许你将源文件组织在一个'm