打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android.mk文件中的变量
BUILD_SHARED_LIBRARY指明要编译成动态库。编译的目标,用include操作符
UILD_STATIC_LIBRARY来指明要编译成静态库。
LOCAL_C_INCLUDES -需要包含的头文件目录
可以是系统定义路径,也可以是相对路径.如该编译目录下有个include目录,写法是include/*.h
LOCAL_SHARED_LIBRARIES -链接时需要的外部共享库
LOCAL_STATIC_LIBRARIES 链接时需要的外部外部静态
LOCAL_JAVA_LIBRARIES加入jar包
LOCAL_MODULE - 编译的目标对象
LOCAL_SRC_FILES -编译的源文件
LOCAL_SHARED_LIBRARIES -链接时需要的外部库
LOCAL_PRELINK_MODULE -是否需要prelink处理
BUILD_SHARED_LIBRARY -指明要编译成动态库
LOCAL_PATH - 编译时的目录
$(call 目录,目录….) 目录引入操作符
如该目录下有个文件夹名称 src,则可以这样写 $(call src),那么就会得到 src目录的完整路径
include $(CLEAR_VARS) -清除之前的一些系统变量

Android.mk variables

These are thevariables that you'll commonly see in Android.mk files, listedalphabetically.

But first, a note onvariable naming:

LOCAL_ASSET_FILES

In Android.mk files that include$(BUILD_PACKAGE) set this to the set offiles you want built into your app. Usually:

LOCAL_ASSET_FILES += $(call find-subdir-assets)

This will probably change when we switch to ant for the apps' buildsystem.

LOCAL_CC

If you want to use a different C compiler for this module, setLOCAL_CC to the path to the compiler. If LOCAL_CC is blank, theappropriate default compiler is used.

LOCAL_CXX

If you want to use a different C++ compiler for this module, setLOCAL_CXX to the path to the compiler. If LOCAL_CXX is blank, theappropriate default compiler is used.

LOCAL_CFLAGS

If you have additional flags to pass into the C or C++ compiler,add them here. For example:

LOCAL_CPPFLAGS

If you have additional flags to passinto only the C++compiler, add them here. For example:

LOCAL_CPPFLAGS += -ffriend-injection

LOCAL_CPPFLAGS is guaranteed to beafter LOCAL_CFLAGS onthe compile line, so you can use it to override flags listedin LOCAL_CFLAGS .

LOCAL_CPP_EXTENSION

If your C++ files end in something other than".cpp ", you can specify the customextension here. For example:

LOCAL_CPP_EXTENSION := .cc

Note that all C++ files for a given module must have the sameextension; it is not currently possible to mix differentextensions.

LOCAL_NO_DEFAULT_COMPILER_FLAGS

Normally, the compile line for C and C++ files includes globalinclude paths and global cflags.IfLOCAL_NO_DEFAULT_COMPILER_FLAGS isnon-empty, none of the default includes or flags will be used whencompiling C and C++ files in thismodule. LOCAL_C_INCLUDES ,LOCAL_CFLAGS ,andLOCAL_CPPFLAGS will still be usedin this case, as willany DEBUG_CFLAGS thatare defined for the module.

LOCAL_COPY_HEADERS

This will be going away.

The set of files to copy to the install include tree. You must alsosupply LOCAL_COPY_HEADERS_TO .

This is going away because copying headers messes up the errormessages, and may lead to people editing those headers instead ofthe correct ones. It also makes it easier to do bad layering in thesystem, which we want to avoid. We also aren't doing a C/C++ SDK,so there is no ultimate requirement to copy any headers.

LOCAL_COPY_HEADERS_TO

This will be going away.

The directory within "include" to copy the headers listedin LOCAL_COPY_HEADERS to.

This is going away because copying headers messes up the errormessages, and may lead to people editing those headers instead ofthe correct ones. It also makes it easier to do bad layering in thesystem, which we want to avoid. We also aren't doing a C/C++ SDK,so there is no ultimate requirement to copy any headers.

LOCAL_C_INCLUDES

Additional directories to instruct the C/C++ compilers to look forheader files in. These paths are rooted at the top of the tree.Use LOCAL_PATH ifyou have subdirectories of your own that you want in the includepaths. For example:

LOCAL_C_INCLUDES += extlibs/zlib-1.2.3
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src

You should not add subdirectories of includeto LOCAL_C_INCLUDES ,instead you should reference those files inthe #include statementwith their subdirectories. For example:

#include 
not #include

There are some components that are doing this wrong, and should becleaned up.

LOCAL_MODULE_TAGS

Set LOCAL_MODULE_TAGS toany number of whitespace-separated tags. If the tag list is emptyor contains droid ,the module will get installed as part ofa make droid .Otherwise, it will only get installed byrunning make  orwith the makeall pseudotarget.

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 the modules that itrequires will be installed as well. This can be used to, e.g.,ensure that necessary shared libraries or providers are installedwhen a given app is installed.

LOCAL_FORCE_STATIC_EXECUTABLE

If your executable should be linked statically,set LOCAL_FORCE_STATIC_EXECUTABLE:=true .There is a very short list of libraries that we have in static form(currently only libc). This is really only used for executables in/sbin on the root filesystem.

LOCAL_GENERATED_SOURCES

Files that you addto LOCAL_GENERATED_SOURCES willbe automatically generated and then linked in when your module isbuilt. See the CustomTools template makefile for an example.

LOCAL_JAVA_LIBRARIES

When linking Java apps andlibraries, LOCAL_JAVA_LIBRARIES specifieswhich sets of java 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) ". Theappropriate libraries will be included automatically.

LOCAL_LDFLAGS

You can pass additional flags to the linker bysetting LOCAL_LDFLAGS .Keep in mind that the order of parameters is very important to ld,so test whatever you do on all platforms.

LOCAL_LDLIBS

LOCAL_LDLIBS allows you to specifyadditional libraries that are not part of the build for yourexecutable or library. Specify the libraries you want in -lxxxformat; they're passed directly to the link line. However, keep inmind 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 pass otherflags here if you're doing something sneaky. Some examples:

LOCAL_LDLIBS += -lcurses -lpthread
LOCAL_LDLIBS += -Wl,-z,origin

LOCAL_NO_MANIFEST

If your package doesn't have a manifest (AndroidManifest.xml), thensetLOCAL_NO_MANIFEST:=true . Thecommon resources package does this.

LOCAL_PACKAGE_NAME

LOCAL_PACKAGE_NAME is the name of anapp. For example, Dialer, Contacts, etc. This will probably changeor go away when we switch to an ant-based build system for theapps.

LOCAL_PATH

The directory your Android.mk file is in. You can set it by puttingthe following as the first line in your Android.mk:

LOCAL_PATH := $(my-dir)

The my-dir macrouses the MAKEFILE_LIST variable,so you must call it before you include any other makefiles. Also,consider that any subdirectories you inlcude might resetLOCAL_PATH, so do your own stuff before you include them. This alsomeans that if you try to writeseveralinclude lines thatreference LOCAL_PATH ,it won't work, because those included makefiles might resetLOCAL_PATH.

LOCAL_POST_PROCESS_COMMAND

For host executables, you can specify a command to run on themodule after it's been linked. You might have to go through somecontortions to get variables right because of early or latevariable 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), setthese to executables that you want copied. They're locatedautomatically into the right bin directory.

LOCAL_PREBUILT_LIBS

When including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT), setthese to libraries that you want copied. They're locatedautomatically into the right lib directory.

LOCAL_SHARED_LIBRARIES

These are the libraries you directly link against. You don't needto pass transitively included libraries. Specify the name withoutthe suffix:

LOCAL_SHARED_LIBRARIES := \
libutils \
libui \
libaudio \
libexpat \
libsgl

LOCAL_SRC_FILES

The build system looksat 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 a subdirectoryof the one containing the Android.mk, prefix them with thedirectory name:

LOCAL_SRC_FILES := \
file1.cpp \
dir/file2.cpp

LOCAL_STATIC_LIBRARIES

These are the static libraries that you want to include in yourmodule. Mostly, we use shared libraries, but there are a couple ofplaces, like executables in sbin and host executables where we usestatic libraries instead.

LOCAL_STATIC_LIBRARIES := \
libutils \
libtinyxml

LOCAL_MODULE

LOCAL_MODULE is the name of what'ssupposed to be generated from your Android.mk. For exmample, forlibkjs,the LOCAL_MODULE is"libkjs" (the build system adds the appropriate suffix -- .so.dylib .dll). For app modules,use LOCAL_PACKAGE_NAME insteadof LOCAL_MODULE. We're planning onswitching to ant for the apps, so this might become moot.

LOCAL_MODULE_PATH

Instructs the build system to put the module somewhere other thanwhat's normal for its type. If you override this, make sure youalsoset LOCAL_UNSTRIPPED_PATH ifit's an executable or a shared library so the unstripped binary hassomewhere to go. An error will occur if you forget to.

See Puttingmodules elsewhere for more.

LOCAL_UNSTRIPPED_PATH

Instructs the build system to put the unstripped version of themodule somewhere other than what's normal for its type. Usually,you override this because youoverrode LOCAL_MODULE_PATHfor anexecutable or a shared library. If youoverrode LOCAL_MODULE_PATH ,but notLOCAL_UNSTRIPPED_PATH , anerror will occur.

See Puttingmodules elsewhere for more.

LOCAL_WHOLE_STATIC_LIBRARIES

These are the static libraries that you want to include in yourmodule without allowing the linker to remove dead code from them.This is mostly useful if you want to add a static library to ashared library and have the static library's content exposed fromthe shared library.

LOCAL_WHOLE_STATIC_LIBRARIES := \
libsqlite3_android

LOCAL_YACCFLAGS

Any flags to pass to invocations of yacc for your module. A knownlimitation here is that the flags will be the same for allinvocations of YACC for your module. This can be fixed. If you everneed it to be, just ask.

LOCAL_YACCFLAGS := -p kjsyy

Implementation Details

You should never have to touch anything in the config directoryunless you're adding a new platform, new tools, or adding newfeatures to the build system. In general, please consult with thebuild system owner(s) (android-build-team )before you go mucking around in here. That said, here are somenotes on what's going on under the hood.

Environment Setup / buildspec.mkVersioning

In order to make easier for people when the build system changes,when it is necessary to make changes to buildspec.mk or to rerunthe environment setup scripts, they contain a version number in thevariable BUILD_ENV_SEQUENCE_NUMBER. If this variable does not matchwhat the build system expects, it fails printing an error messageexplaining what happened. If you make a change that requires anupdate, you need to update two places so this message will beprinted.

  • Inconfig/envsetup.make, increment theCORRECT_BUILD_ENV_SEQUENCE_NUMBER definition.
  • Inbuildspec.mk.default, update the BUILD_ENV_SEQUENCE_DUMBERdefinition to match the one in config/envsetup.make

The scripts automatically get the value from the build system, sothey will trigger the warning as well.

Additional makefilevariables

You probably shouldn't use these variables. Pleaseconsult android-build-team beforeusing them. These are mostly there for workarounds for otherissues, or things that aren't completely done right.

LOCAL_ADDITIONAL_DEPENDENCIES

If your module needs to depend on anything else that isn't actuallybuilt in to it, you can add those make targetsto LOCAL_ADDITIONAL_DEPENDENCIES .Usually this is a workaround for some other dependency that isn'tcreated automatically.

LOCAL_BUILT_MODULE

When a module is built, the module is created in an intermediatedirectory then copied to its final location. LOCAL_BUILT_MODULE isthe full path to the intermediate file. See LOCAL_INSTALLED_MODULEfor the path to the final installed location of the module.

LOCAL_HOST

Set by the host_xxx.make includes to tell base_rules.make and theother includes that we're building for the host. Kenneth did thisas part of openbinder, and I would like to clean it up so therules, includes and definitions aren't duplicated for host andtarget.

LOCAL_INSTALLED_MODULE

The fully qualified path name of the final location of the module.See LOCAL_BUILT_MODULE for the location of the intermediate filethat the make rules should actually be constructing.

LOCAL_REPLACE_VARS

Used in some stuff remaining from the openbinder for buildingscripts with particular values set,

LOCAL_SCRIPTS

Used in some stuff remaining from the openbinder build system thatwe might find handy some day.

LOCAL_MODULE_CLASS

Which kind of module this is. This variable is used to constructother variable names used to locate the modules. Seebase_rules.make and envsetup.make.

LOCAL_MODULE_NAME

Set to the leaf name of the LOCAL_BUILT_MODULE. I'm not sure, butit looks like it's just used in the WHO_AM_I variable to identifyin the pretty printing what's being built.

LOCAL_MODULE_SUFFIX

The suffix that will be appendedto LOCAL_MODULE toform LOCAL_MODULE_NAME .For example, .so, .a, .dylib.

LOCAL_STRIP_MODULE

Calculated in base_rules.make to determine if this module shouldactually be stripped or not, based onwhether LOCAL_STRIPPABLE_MODULE isset, and whether the combo is configured to ever strip modules.With Iliyan's stripping tool, this might change.

LOCAL_STRIPPABLE_MODULE

Set by the include makefiles if that type of module is strippable.Executables and shared libraries are.

LOCAL_SYSTEM_SHARED_LIBRARIES

Used while building the base libraries: libc, libm, libdl. Usuallyit should be set to "none," as it is in $(CLEAR_VARS). Whenbuilding these libraries, it's set to the ones they link against.For example, libc, libstdc++ and libdl don't link against anything,and libm links against libc. Normally, when the value is none,these libraries are automatically linked in to executables andlibraries, so you don't need to specify them manually.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android Build System - Google Android - Linux is Power
Android.mk中引用第3方动态库
Android Build Cookbook
android 集成第三方静态库的编译方法
Android.mk解析
Android.mk官方说明 中文翻译
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服