Android.mk理解
来源:互联网 发布:双语字幕制作软件 编辑:程序博客网 时间:2024/06/10 19:29
转自:http://blog.csdn.net/jshazk1989/article/details/6823888
怎么说到了编译Android Source的方法呢
切入主题 先写一个简单的Android.mk
- LOCAL_PATH := $(call my-dir) #指定当前目录
- include $(CLEAR_VARS) #引入编译变量
- LOCAL_MODULE_TAGS := optional #编译选项便是在何种情况下编译
- LOCAL_SRC_FILES := hello.c #源文件(可以指定多个)
- LOCAL_MODULE := hello #编译出来的模块名
- LOCAL_MODULE_CLASS := EXECUTABLES #指定编译之后放置的位置(此处指示放在system/bin下)
- include $(BUILD_EXECUTABLE) #引入编译成可执行文件的规则
以上的Android.mk 会编译出一个hello的可执行文件,并放入system/bin
LOCAL_PATH : 指定目录,以上是一般用法指示当前目录(my-dir函数是Android编译时. build/envsetup.sh命令生成的 能够获取当前目录的路径)
CLEAR_VARS: android有自己的一套代码编译规则跟编译选项等变量的定义,此变量会引入,实际是android/build/core下的clear_vas.mk,
clear_vas.mk
- ##########################################################
- ## Clear out values of all variables used by rule templates.
- ###########################################################
- LOCAL_MODULE:=
- LOCAL_MODULE_PATH:=
- LOCAL_MODULE_STEM:=
- LOCAL_DONT_CHECK_MODULE:=
- LOCAL_CHECKED_MODULE:=
- .
- .
- .
- LOCAL_CERTIFICATE:=
- LOCAL_SDK_VERSION:=
- LOCAL_NDK_VERSION:=
- LOCAL_NO_EMMA_INSTRUMENT:=
- LOCAL_NO_EMMA_COMPILE:=
- LOCAL_PROGUARD_ENABLED:= # '',optonly,full,custom
- LOCAL_PROGUARD_FLAGS:=
- LOCAL_PROGUARD_FLAG_FILES:=
- LOCAL_EMMA_COVERAGE_FILTER:=
- LOCAL_MANIFEST_FILE:=
- LOCAL_BUILD_HOST_DEX:=
- LOCAL_DEX_PREOPT:=
- LOCAL_DEX_PREOPT:=
- # Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
- # iterate over thousands of entries every time.
- # Leave the current makefile to make sure we don't break anything
- # that expects to be able to find the name of the current makefile.
- MAKEFILE_LIST := $(lastword $(MAKEFILE_LIST))
LOCAL_MODULE 指示当前编译出来的模块名
LOCAL_MODULE_TAGS 标识在什么情况下去编译起模块
有几个选项
user模块只在user下编译eng模块在eng模式下编译teststest状态下编译optional此模块在所有版本下都编译即 TARGET_BUILD_VARIANT=eng 编译TAGS为eng和optional的模块LOCAL_SRC_FILES 表示编译出此模块需要的源程序 可以有多个
LOCAL_C_INCLUDE 如果不去调用标准库头文件,跟当前目录的头文件,则需要在此指定头文件的位置,在此指定头文件的目录。
LOCAL_STATIC_LIBRARIES: 指定需要连接的静态库像一些比较通用的标准库就无需指定了
LOCAL_SHARED_LIBRARIES: 指定需要连接的动态库
最后include $(BUILD_XXX) 表示编译出来的模块类型,有三种
BUILD_EXECUTABLE编译成可执行的模块build/core/host_executable.mkBUILD_STATIC_LIBRARY编译成静态库build/core/host_static_library.mkBUILD_SHARED_LIBRARY编译成动态库build/core/host_shared_library.mkLOCAL_MODULE_CLASS 标识了所编译模块最后放置的位置,如果不指定,不会放到系统中,之后放在最后的obj目录下的对应目录中。LOCAL_MODULE_CLASS := ETC #表示放于system/etc目录
LOCAL_MODULE_CLASS := EXECUTABLES #放于/system/bin
LOCAL_MODULE_CLASS := SHARED_LIBRARIES #放在/system/lib下
build/core下有很多编译的全局的mk,如编译C/C++规则definitions.mk ......
再说一下编译内核模块的Makefile
- ifneq ($(KERNELRELEASE),) #查看是都已定义kernel版本
- obj-m := gps_onoff.o #如果已定义则编译出得模块名是gps_onoff.o
- #(在linux2.6编译模块后会生成module_name.ko module_name.o
- #使用insmod module_name.ko来装载模块moudule_name.o已经弃用
- #即moudule_name.ko 是最终产物)
- else #第一次运行时候会走此分支
- PWD := $(shell pwd) #指定源文件目录
- KDIR ?= /home/zk/POP_TD/marvell-pxa920-kernel #指定到已经编译的内核的目录
- #如果编译PC机上的模块则指定到当前运行的内核
- #(uname -r 查看当前的内核版本)
- #(此时内核版本也被定义KERNELRELEASE非空)
- #内核编译命令 此处可以指定硬件体系与交叉编译工具
- all:
- $(MAKE) -C $(KDIR) M=$(PWD) modules ARCH=arm CROSS_COMPILE=arm-eabi-
- #重新编译内核前需要先make clean 清空编译生成的文件 否则编译会出错
- clean:
- rm -rf .* *.ko *.o *.cmd *.tmp_version *.mod.c *.order Module.*endif
编译模块的Mkefile会被读取两次,Makefile从命令行调用时候KERNELRELEASE尚未设置,
在运行到KDIR时即会指向一个内核构造树,
在运行$(MAKE)时 会第二次运行make命令,此时设置obj-m 构造真正的内核模块
转自:http://blog.csdn.net/a345017062/article/details/6096795
这里提供了一些代码,帮助你实现一些普通的编译任务。一、编译一个简单的APK LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Name of the APK to build LOCAL_PACKAGE_NAME := LocalPackage # Tell it to build an APK include $(BUILD_PACKAGE)二、编译一个依赖某个.jar文件的APK LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # List of static libraries to include in the package LOCAL_STATIC_JAVA_LIBRARIES := static-library # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Name of the APK to build LOCAL_PACKAGE_NAME := LocalPackage # Tell it to build an APK include $(BUILD_PACKAGE)三、编译一个用platform key签过名的APK LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Name of the APK to build LOCAL_PACKAGE_NAME := LocalPackage LOCAL_CERTIFICATE := platform # Tell it to build an APK include $(BUILD_PACKAGE)四、编译一个用vendor key签名的APK LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Name of the APK to build LOCAL_PACKAGE_NAME := LocalPackage LOCAL_CERTIFICATE := vendor/example/certs/app # Tell it to build an APK include $(BUILD_PACKAGE)五、添加一个prebuilt APK LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Module name should match apk name to be installed. LOCAL_MODULE := LocalModuleName LOCAL_SRC_FILES := $(LOCAL_MODULE).apk LOCAL_MODULE_CLASS := APPS LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX) include $(BUILD_PREBUILT)六、添加一个静态java库 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # Build all java files in the java subdirectory LOCAL_SRC_FILES := $(call all-subdir-java-files) # Any libraries that this library depends on LOCAL_JAVA_LIBRARIES := android.test.runner # The name of the jar file to create LOCAL_MODULE := sample # Build a static jar file. include $(BUILD_STATIC_JAVA_LIBRARY)七、Android.mk中的变量下面列出了一些你在Android.mk文件中常见的变量,先看一下名字前缀:1、LOCAL_:这类变量每个模块都要设置自己,用include $(CLEAR_VARS)可以清除这类变量,这类变量也是使用最多的。2、PRIVATE_:这类变量是make-target-specific的变量。只有在编译某个模块时才会用到这类变量。在你从子模块返回时,这类变量不会改变。这个可以对我一下标准的make教程。3、HOST_和TARGET_:这里包含了一些针对特定的host或target的目录和定义。不要在make文件中设置这类变量。4、BUILD_和CLEAR_VARS:这类变量通常是一些预定义过的模板make文件的名字。比如CLEAR_VARS和BUILD_HOST_PACKAGE,通常执行某个具体功能。5、编译系统不可以递归调用,因为所有的变量都是全局的。
Parameter
Description
LOCAL_AAPT_FLAGS
LOCAL_ACP_UNAVAILABLE
LOCAL_ADDITIONAL_JAVA_DIR
LOCAL_AIDL_INCLUDES
LOCAL_ALLOW_UNDEFINED_SYMBOLS
LOCAL_ARM_MODE
LOCAL_ASFLAGS
LOCAL_ASSET_DIR
LOCAL_ASSET_FILES
In Android.mkfiles that include$(BUILD_PACKAGE)
set this to the set offiles you want built into your app. Usually:
LOCAL_ASSET_FILES+= $(call find-subdir-assets)
调用
include$(BUILD_PACKAGE)
时
,会把这个属性中列出的文件编译到
app
中。
LOCAL_BUILT_MODULE_STEM
LOCAL_C_INCLUDES
Additionaldirectories to instruct the C/C++ compilers to look for headerfiles in. These paths are rooted at the top of the tree.UseLOCAL_PATH
ifyou have subdirectories of your own that you want in the includepaths.
如果想C/C++编译器在更多的目录中搜索头文件的话,把这些附加的目录包含在这个属性中。如果这些目录中还有子目录的话,使用LOCAL_PATH
For example:
LOCAL_C_INCLUDES+= extlibs/zlib-1.2.3
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
You should notadd subdirectories of include to LOCAL_C_INCLUDES
,instead you should reference those files in the #include
statementwith their subdirectories.
不要把子目录添加到这个属性中去,应该使用#include
去包含子目录。
For example:
#include<utils/KeyedVector.h>
not #include<KeyedVector.h>
LOCAL_CC
If you want touse a different C compiler for this module, set LOCAL_CC to thepath to the compiler. If LOCAL_CC is blank, the appropriatedefault compiler is used.
如果你想为当前模块使用一个不同的C编译器,就在这个属性中设置好路径
LOCAL_CERTIFICATE
LOCAL_CFLAGS
If you haveadditional flags to pass into the C or C++ compiler, add themhere.
如果有一些标识需要传递给编译器的话,放在这个属性中。
For example:
LOCAL_CFLAGS+= -DLIBUTILS_NATIVE=1
LOCAL_CLASSPATH
LOCAL_COMPRESS_MODULE_SYMBOLS
LOCAL_COPY_HEADERS
The set of filesto copy to the install include tree. You must alsosupply LOCAL_COPY_HEADERS_TO
.
This is goingaway because copying headers messes up the error messages, and maylead to people editing those headers instead of the correct ones.It also makes it easier to do bad layering in the system, which wewant to avoid. We also aren't doing a C/C++ SDK, so there is noultimate requirement to copy any headers.
由于这个属性常常引起一些问题,以后会被删除。
LOCAL_COPY_HEADERS_TO
The directorywithin "include" to copy the headers listedin LOCAL_COPY_HEADERS
to.
This is goingaway because copying headers messes up the error messages, and maylead to people editing those headers instead of the correct ones.It also makes it easier to do bad layering in the system, which wewant to avoid. We also aren't doing a C/C++ SDK, so there is noultimate requirement to copy any headers.
LOCAL_CPP_EXTENSION
If your C++ filesend in something other than ".cpp
",you can specify the custom extension here.
如果你的C++文件扩展名不是“.cpp
”的话,把自定义的扩展名写在这里。
For example:
LOCAL_CPP_EXTENSION:= .cc
Note that all C++files for a given module must have the same extension; it is notcurrently possible to mix different extensions.
注意,一个模块中,所有的C++文件必须有相同的扩展名。
LOCAL_CPPFLAGS
If you haveadditional flags to pass into only the C++compiler, add them here.
你如果只想传递一些标志给C++编译器,写在这里。
For example:
LOCAL_CPPFLAGS+= -ffriend-injection
LOCAL_CPPFLAGS
isguaranteed to be after LOCAL_CFLAGS
onthe compile line, so you can use it to override flags listedinLOCAL_CFLAGS
LOCAL_CXX
If you want touse a different C++ compiler for this module, set LOCAL_CXX to thepath to the compiler. If LOCAL_CXX is blank, the appropriatedefault compiler is used.
如果想为当前模块使用一个不同的C++编译器,把编译器的路径写在这里
LOCAL_DX_FLAGS
LOCAL_EXPORT_PACKAGE_RESOURCES
LOCAL_FORCE_STATIC_EXECUTABLE
If yourexecutable should be linked statically,set LOCAL_FORCE_STATIC_EXECUTABLE:=true
.There is a very short list of libraries that we have in staticform (currently only libc). This is really only used forexecutables in /sbin on the root filesystem.
如果你的可执行文件需要静态链接的话,就把这个变量设置为true。只有很少的库需要静态链接,目前只是libc库。事实上,这种形式只用于/sbin目录下的可执行文件。
LOCAL_GENERATED_SOURCES
Files that youadd to LOCAL_GENERATED_SOURCES
willbe automatically generated and then linked in when your module isbuilt. See the CustomTools template makefile for an example.
添加到这个属性中的文件会在编译模块时自动生成并链接,可以看一下例子子。
LOCAL_INSTRUMENTATION_FOR
LOCAL_INSTRUMENTATION_FOR_PACKAGE_NAME
LOCAL_INTERMEDIATE_SOURCES
LOCAL_INTERMEDIATE_TARGETS
LOCAL_IS_HOST_MODULE
LOCAL_JAR_MANIFEST
LOCAL_JARJAR_RULES
LOCAL_JAVA_LIBRARIES
When linking Javaapps and libraries, LOCAL_JAVA_LIBRARIES
specifieswhich sets ofJava classes to include. Currently there are two ofthese: core
and framework
.In most cases, it will look like this:
LOCAL_JAVA_LIBRARIES:= core framework
Note thatsetting LOCAL_JAVA_LIBRARIES
isnot necessary (and is not allowed) when building an APK with"include$(BUILD_PACKAGE)
". The appropriatelibraries will be included automatically.
链接Java程序和Java库时,这个属性会标识出哪个Java库会被包含。当前只有两个,core
和framework
。大部分情况下,会是这样的形式:LOCAL_JAVA_LIBRARIES:= core framework
。注意,当使用"include$(BUILD_PACKAGE)
"来编译APK时,这个属性不能设置。因为相应库会自动链接。
LOCAL_JAVA_RESOURCE_DIRS
LOCAL_JAVA_RESOURCE_FILES
LOCAL_JNI_SHARED_LIBRARIES
LOCAL_LDFLAGS
You can passadditional flags to the linker by setting LOCAL_LDFLAGS
.Keep in mind that the order of parameters is very important to ld,so test whatever you do on all platforms.
通过这个属性,你可以向链接器传递一些会加的标识。一定要注意,参数的顺序对ld来说非常重要,多多测试。
LOCAL_LDLIBS
LOCAL_LDLIBS
allowsyou to specify additional libraries that are not part of the buildfor your executable or library. Specify the libraries you want in-lxxx format; they're passed directly to the link line. However,keep in mind that there will be no dependency generated for theselibraries. It's most useful in simulator builds where you want touse a library preinstalled on the host. The linker (ld) is aparticularly fussy beast, so it's sometimes necessary to passother flags here if you're doing something sneaky.
不管是编译可执行文件还是编译库,这个属性允许你添加一些附加库。需要注意的是,编译系统不会生成这些库的依赖关系。通常,这个属性会在编译模拟器时使用,你可能会使用一个已经安装在host上的库。
Some examples:
LOCAL_LDLIBS+= -lcurses -lpthread
LOCAL_LDLIBS += -Wl,-z,origin
LOCAL_MODULE
LOCAL_MODULE
isthe name of what's supposed to be generated from your Android.mk.For exmample,
for libkjs,theLOCAL_MODULE
is"libkjs" (the build system adds the appropriate suffix-- .so .dylib .dll). For app modules,useLOCAL_PACKAGE_NAME
insteadof LOCAL_MODULE
.
这个属性存放你要生成的模块名字。如果是app模块,使用LOCAL_PACKAGE_NAME
属性。
LOCAL_MODULE_PATH
Instructs thebuild system to put the module somewhere other than what's normalfor its type. If you override this, make sure you alsoset LOCAL_UNSTRIPPED_PATH
ifit's an executable or a shared library so the unstripped binaryhas somewhere to Go. An error will occur if you forget to.
用新路径替换掉编译系统生成模块的默认存放路径。如果编译目标是一个可执行文件或者一个共享库,还必须设置LOCAL_UNSTRIPPED_PATH
属性来保存unstripped二进制文件,如果没有设置的话,编译系统会报错。
See Puttingmodules elsewhere for more.
LOCAL_MODULE_STEM
LOCAL_MODULE_TAGS
Set LOCAL_MODULE_TAGS
toany number of whitespace-separated tags.
This variablecontrols what build flavors the package gets included in.
该属性的多个值之间以空格分隔。
For example:
user
:include this in user/userdebug buildseng
:include this in eng buildstests
:the target is a testing target and makes it available for testsoptional
:don't include this
LOCAL_NO_DEFAULT_COMPILER_FLAGS
LOCAL_NO_EMMA_COMPILE
LOCAL_NO_EMMA_INSTRUMENT
LOCAL_NO_STANDARD_LIBRARIES
LOCAL_OVERRIDES_PACKAGES
LOCAL_PACKAGE_NAME
LOCAL_PACKAGE_NAME
isthe name of an app. For example, Dialer, Contacts, etc.
属性值是要生成的app的名字。
LOCAL_POST_PROCESS_COMMAND
For hostexecutables, you can specify a command to run on the module afterit's been linked. You might have to go through some contortions toget variables right because of early or late variable evaluation:
module:=$(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)
LOCAL_POST_PROCESS_COMMAND:= /Developer/Tools/Rez -d __DARWIN__ -t APPL/
-d__WXMAC__ -o $(module) Carbon.r
LOCAL_PREBUILT_EXECUTABLES
When including$(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these toexecutables that you want copied. They're located automaticallyinto the right bin directory.
使用$(BUILD_PREBUILT)或$(BUILD_HOST_PREBUILT)时,这个属性设置为你想复制的可执行文件列表,它们会被自动定位。
LOCAL_PREBUILT_JAVA_LIBRARIES
LOCAL_PREBUILT_LIBS
When including$(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), set these tolibraries that you want copied. They're located automatically intothe right lib directory.
使用$(BUILD_PREBUILT)或$(BUILD_HOST_PREBUILT)时,这个属性设置为你想复制的库文件列表,它们会被自动定位。
LOCAL_PREBUILT_OBJ_FILES
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES
LOCAL_PRELINK_MODULE
LOCAL_REQUIRED_MODULES
Set LOCAL_REQUIRED_MODULES
toany number of whitespace-separated module names, like "libblah"or "Email". If this module is installed, all of themodules that it requires will be installed as well. This can beused to, e.g., ensure that necessary shared libraries or providersare installed when a given app is installed.
属性值是有空格分隔的一系列模块名字,如“libblah”或“Email”。如果当前编译的模块被安装,这个列表中所有的模块也会被安装。假如你需要安装一个app时,这种机制可以保证app依赖的共享库或者provider被安装。
LOCAL_RESOURCE_DIR
LOCAL_SDK_VERSION
LOCAL_SHARED_LIBRARIES
These are thelibraries you directly link against.
编译时需要链接的库的列表。
You don't need topass transitively included libraries. Specify the name without thesuffix:
LOCAL_SHARED_LIBRARIES:= /
libutils /
libui/
libaudio /
libexpat/
libsgl
LOCAL_SRC_FILES
The build systemlooks at LOCAL_SRC_FILES
toknow what source files to compile -- .cpp .c .y .l .java. For lexand yacc files, it knows how to correctly do the intermediate .hand .c/.cpp files automatically. If the files are in asubdirectory of the one containing the Android.mk, prefix themwith the directory name:
需要编译的文件列表,如果某些文件在一个子目录中,而且这个子目录中也包含一个Android.mk,就像下面这样使用。
LOCAL_SRC_FILES:= /
file1.cpp /
dir/file2.cpp
LOCAL_STATIC_JAVA_LIBRARIES
LOCAL_STATIC_LIBRARIES
These are thestatic libraries that you want to include in your module. Mostly,we use shared libraries, but there are a couple of places, likeexecutables in sbin and host executables where we use staticlibraries instead.
编译模块时需要链接的静态库列表。大部分情况下,我们使用共享库,但链接sbin中的可执行文件和host上的可执行文件时,会使用静态库。
LOCAL_STATIC_LIBRARIES:= /
libutils /
libtinyxml
LOCAL_UNINSTALLABLE_MODULE
LOCAL_UNSTRIPPED_PATH
Instructs thebuild system to put the unstripped version of the module somewhereother than what's normal for its type. Usually, you override thisbecause you overrode LOCAL_MODULE_PATH
foran executable or a shared library. If youoverrodeLOCAL_MODULE_PATH
,but not LOCAL_UNSTRIPPED_PATH
,an error will occur.
告诉编译系统把模块的unstripped版本放在某个地方。通常,你给LOCAL_MODULE_PATH
赋值时才会给这个属性赋值。如果你给LOCAL_MODULE_PATH
赋值,但不给这个属性赋值,系统会报错。
See Puttingmodules elsewhere for more.
LOCAL_WHOLE_STATIC_LIBRARIES
These are thestatic libraries that you want to include in your module withoutallowing the linker to remove dead code from them. This is mostlyuseful if you want to add a static library to a shared library andhave the static library's content exposed from the shared library.
想把静态库包含在模块中,又不想链接器移除无用的代码时,使用这个属性。通常用于你想把一个静态库添加到共享库中,或者让静态库从共享库中暴露出来时。
LOCAL_WHOLE_STATIC_LIBRARIES:= /
libsqlite3_android
LOCAL_YACCFLAGS
Any flags to passto invocations of yacc for your module. A known limitation here isthat the flags will be the same for all invocations of YACC foryour module. This can be fixed. If you ever need it to be, justask.
调用yacc时传递的标记。注意,当前模块中所有的yacc调用都会传递这个标记。
LOCAL_YACCFLAGS:= -p kjsyy
OVERRIDE_BUILT_MODULE_PATH
- Android.mk理解
- Android.mk文件的理解
- 深入,全面正确的理解Android.mk
- CocosDeshion's android.mk 文件的理解
- CocosDeshion's android.mk 文件的理解
- android.mk 的理解和使用
- Application.mk & Android.mk
- PRODUCT_COPY_FILES的深入理解,为何不能在Android.mk使用
- android.mk
- Android.mk
- Android.mk
- Android.mk
- Android mk
- Android.mk
- android.mk
- android.mk
- android.mk
- ANDROID-MK
- 深入理解闭包
- http-关于application/x-www-form-urlencoded等字符编码的解释说明
- NLP大神推荐的机器学习入门书单(附大量百度网盘电子书)
- 单元测试辅助工具Hamcrest详解
- linux学习笔记--pmap命令
- Android.mk理解
- springMVC源码分析--RequestMappingHandlerAdapter(五)
- Android之SharedPreferences用法
- socket通信之心跳
- 最大流算法
- 快速生成react项目
- JS(四)RegExp正则表达式
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- PCL在VS2013下快速安装或者cmake详细安装(可以运行kinectFusion使用kinect1拍摄深度图彩色图三维模型)两种安装方式