Android编译系统参考手册

build/core/binary.mk

定义了将asm,c,cpp,yacc,lex源代码编译为目标文件的基本规则
模块想生成某类型目标时不会直接包含该makefile,但如果生成二进制程序,会间接包含该makefile
dynamic_binary.mk,executable.mk,host_executable.mk,host_shared_library.mk
host_static_library.mk,prebuilt.mk,raw_executable.mk,shared_library.mk,static_library.mk
等makefile都会包含binary.mk
所有的目标文件将添加到$(all_objects)变量里

LOCAL_SDK_VERSION

build/core/java.mk里定义该变量
LOCAL_SDK_VERSION := $(PDK_BUILD_SDK_VERSION)
如果定义了LOCAL_SDK_VERSION,那么不能定义LOCAL_NDK_VERSION,否则会提示LOCAL_NDK_VERSION is now retired
如果定义了LOCAL_SDK_VERSION,那么不能定义LOCAL_IS_HOST_MODULE,否则提示LOCAL_SDK_VERSION cannot be used in host module
因为编译app时,常需要编译jni代码
示例:LOCAL_SDK_VERSION: 9

HISTORICAL_NDK_VERSIONS_ROOT

ndk的路径,在config.mk里定义:
  HISTORICAL_NDK_VERSIONS_ROOT := $(TOPDIR)prebuilts/ndk
  即prebuilts/ndk

my_ndk_source_root

my_ndk_source_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/sources
示例:HISTORICAL_NDK_VERSIONS_ROOT: prebuilts/ndk
示例: my_ndk_source_root : prebuilts/ndk/current/sources

my_ndk_version_root

my_ndk_version_root := $(HISTORICAL_NDK_VERSIONS_ROOT)/current/platforms/android-$(LOCAL_SDK_VERSION)/arch-$(TARGET_ARCH)
示例:
  my_ndk_source_root : prebuilts/ndk/current/current

LOCAL_NDK_STL_VARIANT

示例:
    LOCAL_NDK_STL_VARIANT := system

my_ndk_stl_include_path

示例:prebuilts/ndk/current/sources/cxx-stl/system/include

my_ndk_stl_shared_lib_fullpath

示例:
   prebuilts/ndk/cxx-stl/stlport/libs/armeabi-v7a/libstlport_static.a

my_ndk_stl_shared_lib

示例:
     my_ndk_stl_shared_lib := -lstlport_shared

my_ndk_stl_static_lib

示例:prebuilts/ndk/current/sources/cxx-stl/stlport/libs/armeabi-v7a/libstlport_static.a

LOCAL_SYSTEM_SHARED_LIBRARIES

ifdef LOCAL_IS_HOST_MODULE
  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
LOCAL_SYSTEM_SHARED_LIBRARIES :=
  endif
else
  ifeq ($(LOCAL_SYSTEM_SHARED_LIBRARIES),none)
LOCAL_SYSTEM_SHARED_LIBRARIES := $(TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES)
  endif
endif
示例:
  TARGET_DEFAULT_SYSTEM_SHARED_LIBRARIES:libc libstdc++ libm
 LOCAL_SYSTEM_SHARED_LIBRARIES:libc libstdc++ libm

Function:  insert-liblog

使得包含了libcutils或者libutils的模块,也包含liblog,并使得liblog排在前面

LOCAL_SHARED_LIBRARIES

表示模块要链接的动态链接库
ifneq (,$(filter libcutils libutils,$(LOCAL_SHARED_LIBRARIES)))
 LOCAL_SHARED_LIBRARIES := $(call insert-liblog,$(LOCAL_SHARED_LIBRARIES))
endif
 示例:frameworks/av/media/mtp模块
Android.mk LOCAL_SHARED_LIBRARIES := libutils libcutils libusbhost libbinder
最终:LOCAL_SHARED_LIBRARIES: libutils liblog libcutils libusbhost libbinder

LOCAL_STATIC_LIBRARIES

表示模块要链接的静态库
 ifneq (,$(filter libcutils libutils,$(LOCAL_STATIC_LIBRARIES)))
LOCAL_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_STATIC_LIBRARIES))
endif
示例:external/busybox/Android.mk
LOCAL_STATIC_LIBRARIES := libcutils libc libm
最终:
 LOCAL_STATIC_LIBRARIES := libcutils libc libm liblog 

LOCAL_WHOLE_STATIC_LIBRARIES

链接时会将LOCAL_WHOLE_STATIC_LIBRARIES类型的静态链接库的所有目标代码放入最终目标文件里,而不去掉
These are the static libraries that you want to include in your module without allowing the linker to remove dead code from them. This is mostly useful if you want to add a static library to a shared library and have the static library's content exposed from the shared library.
ifneq (,$(filter libcutils libutils,$(LOCAL_WHOLE_STATIC_LIBRARIES)))
  LOCAL_WHOLE_STATIC_LIBRARIES := $(call insert-liblog,$(LOCAL_WHOLE_STATIC_LIBRARIES))
endif
示例:
dalvik/vm/Android.mk
LOCAL_WHOLE_STATIC_LIBRARIES += libexpat libcutils libdex liblog libz
最终
 LOCAL_WHOLE_STATIC_LIBRARIES += libexpat libcutils libdex liblog libz liblog

installed_shared_library_module_names

安装的动态链接库名字,用于定义依赖的动态链接库
ifdef LOCAL_SDK_VERSION
  # Get the list of INSTALLED libraries as module names.
  # We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for
  # they may cusomize their install path with LOCAL_MODULE_PATH
  installed_shared_library_module_names := \
$(LOCAL_SHARED_LIBRARIES)
else
  installed_shared_library_module_names := \
$(LOCAL_SYSTEM_SHARED_LIBRARIES) $(LOCAL_SHARED_LIBRARIES)

LOCAL_SYSTEM_SHARED_LIBRARIES

Used while building the base libraries: libc, libm, libdl.
Usually it should be set to "none," as it is in $(CLEAR_VARS). 
When building 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 and libraries,
so you don't need to specify them manually.
    示例:
 libc libstdc++ libm

LOCAL_REQUIRED_MODULES

本模块依赖的模块
 Set LOCAL_REQUIRED_MODULES to any number of whitespace-separated module names, like "libblah" or "Email". 
 If this module is installed, all of the modules that it requires will be installed as well. 
 This can be used to, e.g., ensure that necessary shared libraries 
 or providers are installed when a given app is installed
示例:  
LOCAL_REQUIRED_MODULES += $(installed_shared_library_module_names)

LOCAL_CLANG

表示编译C代码

LOCAL_CFLAGS

表示编译C代码时用的参数

LOCAL_LDFLAGS

表示链接时用的参数

CLANG

C编译器
CLANG := $(HOST_OUT_EXECUTABLES)/clang$(HOST_EXECUTABLE_SUFFIX)

CLANG_CXX

C++编译器 
CLANG_CXX := $(HOST_OUT_EXECUTABLES)/clang++$(HOST_EXECUTABLE_SUFFIX)

LOCAL_ENABLE_APROF

编译动态链接库时用到

LOCAL_ASFLAGS

Explicitly declare assembly-only __ASSEMBLY__ macro for
assembly source
  LOCAL_ASFLAGS += -D__ASSEMBLY__

LOCAL_INTERMEDIATE_TARGETS

编译动态链接库时用, 
LOCAL_INTERMEDIATE_TARGETS := $(linked_module)

LOCAL_GENERATED_SOURCES

编译时生成的源代码文件,像aidl将专为java代码

proto_generated_cc_sources

定义了将.proto编译为.cc的目标

proto_generated_objects

定义了将 proto代码编译后的c代码编译为目标文件的目标

yacc_cpps

利用yacc将.y文件编译为.cpp文件

yacc_objects

将.y文件编译的.cpp文件编译为目标文件

lex_cpps

利用lex将.l文件编译为.cpp文件

lex_objects

利用lex将lex编译出来的.cpp编译为目标文件   

cpp_objects

将cpp编译为目标文件

gen_cpp_objects

将生成的Cpp编译为目标文件

gen_s_objects

将汇编代码.s,.S编译为目标文件

c_objects

将c代码编译为目标文件

gen_c_objects

将生成的C文件编译为目标文件

objc_sources

将objectc代码(以.m结尾)编译为目标文件   

asm_objects_S

将汇编代码编译[.S]为目标文件

asm_objects_s

将汇编代码编译[.s]为目标文件   

import_includes

需要include的头文件
内容示例:-I system/core/fs_mgr/include

all_objects

要编译的目标集合   
some rules depend on asm_objects being first.  If your code depends on
   being first, it's reasonable to require it to be assembly.  
   all_objects := \
$(asm_objects) \
$(cpp_objects) \
$(gen_cpp_objects) \
$(gen_asm_objects) \
$(c_objects) \
$(gen_c_objects) \
$(objc_objects) \
$(yacc_objects) \
$(lex_objects) \
$(proto_generated_objects) \
$(addprefix $(TOPDIR)$(LOCAL_PATH)/,$(LOCAL_PREBUILT_OBJ_FILES)) 

LOCAL_COPY_HEADERS

需要拷贝至安装目录的头文件集合,你需要同时定义LOCAL_COPY_HEADERS_TO 

LOCAL_COPY_HEADERS_TO

需要拷贝头头文件至哪个安装目录

LOCAL_CC

你可以通过LOCAL_CC定义一个不同的C编译器

LOCAL_CXX

你可以通过LOCAL_CXX定义一个不同的C++编译器

LOCAL_ASSET_FILES

编译Android Package(app)程序时,通常用LOCAL_ASSET_FILES,表示assets目录的所有文件
通常使用方式:
LOCAL_ASSET_FILES += $(call find-subdir-assets)   

LOCAL_NO_DEFAULT_COMPILER_FLAGS

通常为C或者C++源代码文件的编译提供了默认的头文件目录和flag,可以通过LOCAL_NO_DEFAULT_COMPILER_FLAGS设置不使用这些东东

LOCAL_JAVACFLAGS

额外的编译java用的flags
示例: 
LOCAL_JAVACFLAGS += -Xlint:deprecation

LOCAL_JAVA_LIBRARIES

当链接java app程序和库时, LOCAL_JAVA_LIBRARIES指定了哪些java类将被包含,
目前只有 LOCAL_JAVA_LIBRARIES := core framework
注意目前编译app设置LOCAL_JAVA_LIBRARIES是不必要的,也不被允许的,在include  $(BUILD_PACKAGE)时
合适的库都会被包含进来

LOCAL_LDFLAGS

额外的链接flag 
记住 flag的顺序很重要,需要在所有平台都测试,否则容易出错

LOCAL_LDLIBS

额外的动态链接库
LOCAL_LDLIBS allows you to specify additional libraries that are not part of the build for 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 these libraries.
It's most useful in simulator builds where you want to use a library preinstalled on the host.
The linker (ld) is a particularly fussy beast, 
so it's sometimes necessary to pass other flags here if you're doing something sneaky.
Some examples:
LOCAL_LDLIBS += -lcurses -lpthread
LOCAL_LDLIBS += -Wl,-z,origin 

LOCAL_NO_MANIFEST

如果你的packege没有manifest,可以设置LOCAL_NO_MANIFEST:=true
一般资源包会这么做

LOCAL_PACKAGE_NAME

App名字 
示例: Dialer, Contacts, etc. 
This will probably change or go away when we switch to an ant-based build system for the apps.

LOCAL_POST_PROCESS_COMMAND

你可以为主机上的可执行程序添加一条命令,这条命令在这个模块被链接后执行
 You might have to go through some contortions to get 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

预编译好的可执行程序,一般通过include $(BUILD_PREBUILT)设置
会将预编译好的程序拷贝直接拷贝至安装目录 

LOCAL_PREBUILT_LIBS

预编译好的库,当使用including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT)
会将LOCAL_PREBUILT_LIBS所指的库拷贝到安装目录

LOCAL_UNSTRIPPED_PATH

没有strip的程序存放路径,通常放在symbols目录
Instructs the build system to put the unstripped version of the module somewhere 
other than what's normal for its type. 
Usually, you override this because you overrode LOCAL_MODULE_PATH for an executable or a shared library.
If you overrode LOCAL_MODULE_PATH, but not LOCAL_UNSTRIPPED_PATH, an error will occur.

LOCAL_MODULE_PATH

表示模块生成后的程序安装路径,设置该变量后,必须设置LOCAL_UNSTRIPPED_PATH,如果是预编译的类型,则不用设置   
   Instructs the build system to put the module somewhere other than what's normal for its type. 
   If you override this, make sure you also set LOCAL_UNSTRIPPED_PATH 
   if it's an executable or a shared library so the unstripped binary has somewhere to go.
An error will occur if you forget to.

LOCAL_YACCFLAGS

额外的yacc编译器flag
Any flags to pass to invocations of yacc for your module. 
A known limitation here is that the flags will be the same for all invocations of YACC for your module. 
This can be fixed. If you ever need it to be, just ask.
LOCAL_YACCFLAGS := -p kjsyy

LOCAL_ADDITIONAL_DEPENDENCIES

额外的依赖
If your module needs to depend on anything else that isn't actually built in to it,
you can add those make targets to LOCAL_ADDITIONAL_DEPENDENCIES. 
Usually this is a workaround for some other dependency that isn't created automatically.

LOCAL_BUILT_MODULE

表示编译链接后的目标文件(文件路径+文件名),存放在临时目录
When a module is built, the module is created in an intermediate directory then copied to its final location.
 LOCAL_BUILT_MODULE is the full path to the intermediate file. 
 See LOCAL_INSTALLED_MODULE for 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 the other includes that we're building for the host.
Kenneth did this as part of openbinder, and I would like to clean it up so the rules,
 includes and definitions aren't duplicated for host and target.

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 file that the make rules should actually be constructing.

LOCAL_REPLACE_VARS

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

LOCAL_SCRIPTS

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

LOCAL_STRIP_MODULE

表示该模块生成的目标是否需要被strip
   Calculated in base_rules.make to determine if this module should actually be stripped or not,
   based on whether LOCAL_STRIPPABLE_MODULE is set, and whether the combo is configured to ever strip modules. 
   With Iliyan's stripping tool, this might change.

LOCAL_STRIPPABLE_MODULE

表示模块生成的文件是否能被Strip,只有可执行程序和动态链接库可以被strip
Set by the include makefiles if that type of module is strippable. 
Executables and shared libraries are.

all_libraries

all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.

export_includes

导出的头文件,参看 import_includes

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值