设为首页 加入收藏

TOP

Android编译之解析main.mk
2014-11-24 08:45:04 来源: 作者: 【 】 浏览:0
Tags:Android 编译 解析 main.mk

首先是根目录的makefile文件


### DO NOT EDIT THIS FILE ###
include build/core/main.mk
### DO NOT EDIT THIS FILE ###


好简单额,意思很直观明了。就是包含了 build/core/main.mk文件。那么我们接下来将解析大头,就是main.mk文件。由于main.mk很大,我们一步一步的来解析它,当然我们只解析关键的步骤,因为android的脚本文件里含有丰富的注释(这是一个好习惯)。所以我只是解析下关键部分。


# This is the default target. It must be the first declared target.
.PHONY: droid
DEFAULT_GOAL := droid
$(DEFAULT_GOAL):


这里设定了一个默认的target名称droid。当用户直接调用make命令的时候,生成的target就为droid。但是这里并没有定义编译条件。


# Set up various standard variables based on configuration
# and host information.
include $(BUILD_SYSTEM)/config.mk


# This allows us to force a clean build - included after the config.make
# environment setup is done, but before we generate any dependencies. This
# file does the rm -rf inline so the deps which are all done below will
# be generated correctly
include $(BUILD_SYSTEM)/cleanbuild.mk


VERSION_CHECK_SEQUENCE_NUMBER := 2
-include $(OUT_DIR)/versions_checked.mk
ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))


这里是包含了其它的mk文件。


后面有一大段是检测系统环境的,比如检测系统是否为windows(android只能在linux和苹果机上编译),java的版本。


ifneq ($(filter eng user userdebug,$(MAKECMDGOALS)),)
$(info ***************************************************************)
$(info ***************************************************************)
$(info Don't pass '$(filter eng user userdebug tests,$(MAKECMDGOALS))' on \
the make command line.)
# XXX The single quote on this line fixes gvim's syntax highlighting.
# Without which, the rest of this file is impossible to read.
$(info Set TARGET_BUILD_VARIANT in buildspec.mk, or use lunch or)
$(info choosecombo.)
$(info ***************************************************************)
$(info ***************************************************************)
$(error stopping)
endif


检查product的类型,product只能为user,eng,userdebug,tests四种。


# Can't use first-makefiles-under here because
# --mindepth=2 makes the prunes not work.
subdir_makefiles := \
$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)


调用build/tools/findleaves.py脚本来遍历所有目录下的Android.mk文件,不包括out,repo和git目录。


include $(subdir_makefiles)


将所查找到的Android.mk包含进来。


接下来大部分就是定义了一下其它的target。


# All the droid stuff, in directories
.PHONY: files
files: prebuilt \
$(modules_to_install) \
$(modules_to_check) \
$(INSTALLED_ANDROID_INFO_TXT_TARGET)


比如files就是编译过程中生成的一些临时文件等等。至此。main.mk的大致流程算上讲完了。后续将继续分析如何增加一个product


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java后台JOSN转换为Stirng 下一篇Android编译之make脚本

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·有没有哪些高效的c++ (2025-12-27 08:20:57)
·Socket 编程时 Accep (2025-12-27 08:20:54)
·计算机网络知识点总 (2025-12-27 08:20:52)
·一篇说人话的文章, (2025-12-27 07:50:09)
·Python Web框架哪家 (2025-12-27 07:50:06)