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)變量裡
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
ndk的路徑,在config.mk裡定義:
HISTORICAL_NDK_VERSIONS_ROOT := $(TOPDIR)prebuilts/ndk
即prebuilts/ndk
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 := $(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 := system
示例:prebuilts/ndk/current/sources/cxx-stl/system/include
示例:
prebuilts/ndk/cxx-stl/stlport/libs/armeabi-v7a/libstlport_static.a
示例:
my_ndk_stl_shared_lib := -lstlport_shared
示例:prebuilts/ndk/current/sources/cxx-stl/stlport/libs/armeabi-v7a/libstlport_static.a
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
使得包含了libcutils或者libutils的模塊,也包含liblog,並使得liblog排在前面
表示模塊要鏈接的動態鏈接庫
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
表示模塊要鏈接的靜態庫
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類型的靜態鏈接庫的所有目標代碼放入最終目標文件裡,而不去掉
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
安裝的動態鏈接庫名字,用於定義依賴的動態鏈接庫
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)
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
本模塊依賴的模塊
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 , eg, ensure that necessary shared libraries
or providers are installed when a given app is installed
示例:
LOCAL_REQUIRED_MODULES += $(installed_shared_library_module_names)
C編譯器
CLANG := $(HOST_OUT_EXECUTABLES)/clang$(HOST_EXECUTABLE_SUFFIX)
C++編譯器
CLANG_CXX := $(HOST_OUT_EXECUTABLES)/clang++$(HOST_EXECUTABLE_SUFFIX)
Explicitly declare assembly-only __ASSEMBLY__ macro for
assembly source
LOCAL_ASFLAGS += -D__ASSEMBLY__
編譯動態鏈接庫時用,
LOCAL_INTERMEDIATE_TARGETS := $(linked_module)
編譯時生成的源代碼文件,像aidl將專為java代碼
定義了將 proto代碼編譯後的c代碼編譯為目標文件的目標
利用lex將lex編譯出來的.cpp編譯為目標文件
需要include的頭文件
內容示例:-I system/core/fs_mgr/include
要編譯的目標集合
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_TO
你可以通過LOCAL_CXX定義一個不同的C++編譯器
編譯Android Package(app)程序時,通常用LOCAL_ASSET_FILES,表示assets目錄的所有文件
通常使用方式:
LOCAL_ASSET_FILES += $(call find-subdir-assets)
通常為C或者C++源代碼文件的編譯提供了默認的頭文件目錄和flag,可以通過LOCAL_NO_DEFAULT_COMPILER_FLAGS設置不使用這些東東
額外的編譯java用的flags
示例:
LOCAL_JAVACFLAGS += -Xlint:deprecation
當鏈接java app程序和庫時, LOCAL_JAVA_LIBRARIES指定了哪些java類將被包含,
目前只有LOCAL_JAVA_LIBRARIES := core framework
注意目前編譯app設置LOCAL_JAVA_LIBRARIES是不必要的,也不被允許的,在include $(BUILD_PACKAGE)時
合適的庫都會被包含進來
額外的鏈接flag
記住flag的順序很重要,需要在所有平台都測試,否則容易出錯
額外的動態鏈接庫
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
如果你的packege沒有manifest,可以設置LOCAL_NO_MANIFEST:=true
一般資源包會這麼做
App名字
示例: Dialer, Contacts, etc.
This will probably change or go away when we switch to an ant-based build system for the apps.
你可以為主機上的可執行程序添加一條命令,這條命令在這個模塊被鏈接後執行
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
預編譯好的可執行程序,一般通過include $(BUILD_PREBUILT)設置
會將預編譯好的程序拷貝直接拷貝至安裝目錄
預編譯好的庫,當使用including $(BUILD_PREBUILT) or $(BUILD_HOST_PREBUILT)
會將LOCAL_PREBUILT_LIBS所指的庫拷貝到安裝目錄
沒有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_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.
額外的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
額外的依賴
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.
表示編譯鏈接後的目標文件(文件路徑+文件名),存放在臨時目錄
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.
表示是在模塊生成的文件是在主機上的程序
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.
表示模塊的安裝路徑+文件名 ,存放在安裝目錄
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.
Used in some stuff remaining from the openbinder for building scripts with particular values set,
Used in some stuff remaining from the openbinder build system that we might find handy some day.
表示該模塊生成的目標是否需要被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.
表示模塊生成的文件是否能被Strip,只有可執行程序和動態鏈接庫可以被strip
Set by the include makefiles if that type of module is strippable.
Executables and shared libraries are.
all_libraries is used for the dependencies on LOCAL_BUILT_MODULE.
導出的頭文件,參看 import_includes
c语言代码片段
回覆刪除比较两个字符串的最后一个实例