Chinaunix首页 | 论坛 | 博客
  • 博客访问: 412855
  • 博文数量: 125
  • 博客积分: 2066
  • 博客等级: 大尉
  • 技术积分: 1032
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-16 14:06
文章分类

全部博文(125)

文章存档

2011年(125)

分类: LINUX

2011-08-03 10:56:35

# Use bash, not whatever shell somebody has installed as /bin/sh
# This is repeated in config.mk, since envsetup.sh runs that file
# directly.
#(1)根据ANDROID_BUILD_SHELL来选择编译系统用到的Shell,如果我们不想使用bash,而想使用sh,可以在
# 它前面写上ANDROID_BUILD_SHELL := /bin/sh,或者在build/envsetup.sh中添加相关定义。
SHELL := /bin/bash
# this turns off the suffix rules built into make
.SUFFIXES:
# If a rule fails, delete $@.
.DELETE_ON_ERROR:
# Figure out where we are.
#TOP := $(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
#TOP := $(patsubst %/,%,$(TOP))
# TOPDIR is the normal variable you should use, because
# if we are executing relative to the current directory
# it can be "", whereas TOP must be "." which causes
# pattern matching probles when make strips off the
# trailing "./" from paths in various places.
#ifeq ($(TOP),.)
#TOPDIR :=
#else
#TOPDIR := $(TOP)/
#endif

#(2)MAKE_VERSION的检查。对这个项目的编译,需要make的版本大于或等于3.81
# check for broken versions of make
ifeq (0,$(shell expr $$(echo $(MAKE_VERSION) | sed "s/[^0-9\.].*//") \>= 3.81))
$(warning ********************************************************************************)
$(warning * You are using version $(MAKE_VERSION) of make.)
$(warning * You must upgrade to version 3.81 or greater.)
$(warning * see file://$(shell pwd)/docs/development-environment/machine-setup.html)
$(warning ********************************************************************************)
$(error stopping)
endif
TOP := .
TOPDIR :=
BUILD_SYSTEM := $(TOPDIR)build/core
#(3)设定第一个目标:DEFAULT_GOAL := droid,在用户输入make之后,如果不加任何参数,那么默认的目标就是
# droid。虽然后面的include $(BUILD_SYSTEM)/config.mk写在默认目标droid依赖之后,但该目标之后的语句
# 都是要执行的,这由Makefile的语法决定的。
# This is the default target. It must be the first declared target.
DEFAULT_GOAL := droid
$(DEFAULT_GOAL):
# Set up various standard variables based _disibledevent=> -include $(OUT_DIR)/versions_checked.mk
ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
$(info Checking build tools versions...)

#(6)编译环境若不是windows的话,会检查Case-insensitive filesystems。(这里好像无关紧要)
ifneq ($(HOST_OS),windows)
ifneq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
# check for a case sensitive file system
ifneq (a,$(shell mkdir -p $(OUT_DIR) ; \
echo a > $(OUT_DIR)/casecheck.txt; \
echo B > $(OUT_DIR)/CaseCheck.txt; \
cat $(OUT_DIR)/casecheck.txt))
$(warning ************************************************************)
$(warning You are building _disibledevent=>&1 | head -n 1 | grep '[ "]1\.5[\. "$$]')
ifeq ($(strip $(java_version)),)
$(info ************************************************************)
$(info You are attempting to build with the incorrect version)
$(info of java.)
$(info $(space))
$(info Your version is: $(shell java -version 2>&1 | head -n 1).)
$(info The correct version is: 1.5.)
$(info $(space))
$(info Please follow the machine setup instructions at)
$(info $(space)$(space)$(space)$(space))
$(info ************************************************************)
$(error stop)
endif
# Check for the correct version of javac
#(8)对编译的java 版本的检查,在windows编译是使用1.6的,在别的平台上要使用1.5,如下。
javac_version := $(shell javac -version 2>&1 | head -n 1 | grep '[ "]1\.5[\. "$$]')
ifeq ($(strip $(javac_version)),)
$(info ************************************************************)
$(info You are attempting to build with the incorrect version)
$(info of javac.)
$(info $(space))
$(info Your version is: $(shell javac -version 2>&1 | head -n 1).)
$(info The correct version is: 1.5.)
$(info $(space))
$(info Please follow the machine setup instructions at)
$(info $(space)$(space)$(space)$(space))
$(info ************************************************************)
$(error stop)
endif
endif # windows
$(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \
> $(OUT_DIR)/versions_checked.mk)
endif
# These are the modifier targets that don't do anything themselves, but
# change the behavior of the build.
# (must be defined before including definitions.make)
INTERNAL_MODIFIER_TARGETS := showcommands checkbuild
# Bring in standard build system definitions.
#(9)包含definition.mk: definations.mk中定义了很多编译系统中用到的宏,这些宏在编译时需要经常调用,
# 因此在编译的很靠前的阶段,就将之包含了进来。
include $(BUILD_SYSTEM)/definitions.mk
ifneq ($(filter eng user userdebug tests,$(MAKECMDGOALS)),)
$(info ***************************************************************)
$(info ***************************************************************)
$(info Don't pass '$(filter eng user userdebug tests,$(MAKECMDGOALS))' _disibledevent=> ifneq ($(filter sdk,$(MAKECMDGOALS)),)
is_sdk_build := true
endif
ifneq ($(filter sdk_addon,$(MAKECMDGOALS)),)
is_sdk_build := true
endif
## user/userdebug ##
# (12)查看buildspec.mk文件中定义的TARGET_BUILD_VARIANT是否已经定义有userdebuguser,将结果保存到user_variant
# user_variant这个参数在后面会用很多,关系到后面ADDITIONAL_DEFAULT_PROPERTIEStags_to_installenable_target_debugging
# 这些重要参数的设置。ADDITIONAL_BUILD_PROPERTIES用于指定被编译项的文件特性。
user_variant := $(filter userdebug user,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
ifneq (,$(user_variant))
# Target is secure in user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1
tags_to_install := user
ifeq ($(user_variant),userdebug)
# Pick up some extra useful tools
tags_to_install += debug
else
# Disable debugging in plain user builds.
enable_target_debugging :=
endif
# TODO: Always set WITH_DEXPREOPT (for user builds) _disibledevent=> endif
# Disallow mock locations by default for user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=0
else # !user_variant
# Turn _disibledevent=> # Set device insecure for non-user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=0
# Allow mock locations by default for non user builds
ADDITIONAL_DEFAULT_PROPERTIES += ro.allow.mock.location=1
endif # !user_variant
#(13)根据enable_target_debugging的设置(在前面设定),设置 DDITIONAL_DEFAULT_PROPERTIES的值。
ifeq (true,$(strip $(enable_target_debugging)))
# Target is more debuggable and adbd is _disibledevent=> # Include the debugging/testing OTA keys in this build.
INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
# Target is less debuggable and adbd is off by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0 persist.service.adb.enable=0
endif # !enable_target_debugging
## eng ##
#(14)若是buildspec.mk文件中定义的TARGET_BUILD_VARIANTeng,再对tags_to_installADDITIONAL_BUILD_PROPERTIES
# 进行设置。
ifeq ($(TARGET_BUILD_VARIANT),eng)
tags_to_install := user debug eng
# Don't require the setup wizard _disibledevent=> $(call collapse-pairs, $(ADDITIONAL_BUILD_PROPERTIES))) \
ro.setupwizard.mode=OPTIONAL
endif
## tests ##
#(15)若是buildspec.mk文件中定义的TARGET_BUILD_VARIANTtest,再对tags_to_install进行配置
ifeq ($(TARGET_BUILD_VARIANT),tests)
tags_to_install := user debug eng tests
endif
## sdk ##
#(16)若是对sdk的编译,会对MAKECMDGOALS的值进行检查,在编译sdk的时候,是不允许再另多其他中间目标的。
# 若是是sdk的边缘,还会tags_to_installADDITIONAL_BUILD_PROPERTIES添加一些值。
ifdef is_sdk_build
ifneq ($(words $(filter-out $(INTERNAL_MODIFIER_TARGETS),$(MAKECMDGOALS))),1)
$(error The 'sdk' target may not be specified with any other targets)
endif
# TODO: this should be eng I think. Since the sdk is built from the eng
# variant.
tags_to_install := user debug eng
ADDITIONAL_BUILD_PROPERTIES += xmpp.auto-presence=true
ADDITIONAL_BUILD_PROPERTIES += ro.config.nocheckin=yes
else # !sdk
endif
## precise GC ##
#(17)查看PRODUCT_TAGS是否有定义dalvik.gc.type-precisePRODUCT_TAGS这个变量在product_config.mk定义。
# 若是有定义的话还要在ADDITIONAL_BUILD_PROPERTIES添加dalvik.vm.dexopt-flags这个配置信息。
ifneq ($(filter dalvik.gc.type-precise,$(PRODUCT_TAGS)),)
# Enabling type-precise GC results in larger optimized DEX files. The
# additional storage requirements for ".odex" files can cause /system
# to overflow _disibledevent=> endif
#########################################################################################################
#(18)若是PRODUCT_COPY_FILES没有记录apns-conf.xml,要确保添加上去。
# 注意:这几个文件的作用如下:
# apns-conf_sdk.xml如:$ANDROID_SRC_HOME/development/data/etc/apns-conf_sdk.xml
# --主要用于生成system/etc/apns-conf.xml文件,生成过程本质上就是原文拷贝
# apns.xml 如:$ANDROID_SRC_HOME/frameworks/base/core/res/res/xml/apns.xml
# --该文件实际上在apn的设置方面没有实际意义,然而在android apn设置的逻辑方面却很重要,尤其是里面的version的值。
# apns-conf.xml 如: $ANDROID_SRC_HOME/out/target/product/generic/system/etc/apns-conf.xml
# --该文件里记录的内容最终打包到system.img中:
##########################################################################################################
#
# Install an apns-conf.xml file if _disibledevent=> development/data/etc/apns-conf_sdk.xml:system/etc/apns-conf.xml
ifeq ($(filter eng tests,$(TARGET_BUILD_VARIANT)),)
$(warning implicitly installing apns-conf_sdk.xml)
endif
endif
#(19)若是在test eng的创建,且不是sdk那么要替换上面添加的apns-conf_sdk.xml
# If we're _disibledevent=> ifneq ($(strip $(apns_to_use)),)
PRODUCT_COPY_FILES := \
$(filter-out %:system/etc/apns-conf.xml,$(PRODUCT_COPY_FILES)) \
$(strip $(apns_to_use)):system/etc/apns-conf.xml
endif
endif
endif
#(20)再次配置ADDITIONAL_BUILD_PROPERTIES
ADDITIONAL_BUILD_PROPERTIES += net.bt.name=Android
ADDITIONAL_BUILD_PROPERTIES += ro.config.sync=yes
# enable vm tracing in files for now to help track
# the cause of ANRs in the content process
ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.stack-trace-file=/data/anr/traces.txt
# ------------------------------------------------------------
# Define a function that, given a list of module tags, returns
# non-empty if that module should be installed in /system.
# For most goals, anything not tagged with the "tests" tag should
# be installed in /system.
define should-install-to-system
$(if $(filter tests,$(1)),,true)
endef
ifdef is_sdk_build
# For the sdk goal, anything with the "samples" tag should be
# installed in /data even if that module also has "eng"/"debug"/"user".
define should-install-to-system
$(if $(filter samples tests,$(1)),,true)
endef
endif
# If they _disibledevent=> endif
ifeq ($(MAKECMDGOALS),clobber)
dont_bother := true
endif
ifeq ($(MAKECMDGOALS),dataclean)
dont_bother := true
endif
ifeq ($(MAKECMDGOALS),installclean)
dont_bother := true
endif
# Bring in all modules that need to be built.
ifneq ($(dont_bother),true)
ifeq ($(HOST_OS),windows)
SDK_ONLY := true
endif
ifeq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
SDK_ONLY := true
endif
ifeq ($(SDK_ONLY),true)
# ----- SDK for Windows ------
# These configure the build targets that are available for the SDK under Cygwin.
# The first section defines all the C/C++ tools that can be compiled under Cygwin,
# the second section defines all the Java _disibledevent=> prebuilt \
build/libs/host \
build/tools/zipalign \
dalvik/dexdump \
dalvik/libdex \
dalvik/tools/dmtracedump \
dalvik/tools/hprof-conv \
development/tools/line_endings \
development/tools/etc1tool \
sdk/emulator/mksdcard \
sdk/sdklauncher \
development/host \
external/expat \
external/libpng \
external/qemu \
external/sqlite/dist \
external/zlib \
frameworks/base/libs/utils \
frameworks/base/tools/aapt \
frameworks/base/tools/aidl \
frameworks/base/opengl/libs \
system/core/adb \
system/core/fastboot \
system/core/libcutils \
system/core/liblog \
system/core/libzipfile
# The following can _disibledevent=> build/tools/signapk \
dalvik/dx \
dalvik/libcore \
sdk/archquery \
sdk/androidprefs \
sdk/apkbuilder \
sdk/jarutils \
sdk/layoutlib_api \
sdk/layoutlib_utils \
sdk/ninepatch \
sdk/sdkstats \
sdk/sdkmanager \
sdk/layoutopt \
development/apps \
development/tools/mkstubs \
frameworks/base/tools/layoutlib \
external/googleclient \
packages
else
$(warning sdk-only: javac not available.)
endif
#(25)若当前HOST不是linux,那么还要要添加build/tools/acp这个目录。
# Exclude tools/acp when cross-compiling windows under linux
ifeq ($(findstring Linux,$(UNAME)),)
subdirs += build/tools/acp
endif
#(26)若SDK_ONLY不为真,且BUILD_TINY_ANDROID为真,那么添加一些文件,编译一个最小的系统.
else # !SDK_ONLY
ifeq ($(BUILD_TINY_ANDROID), true)
# TINY_ANDROID is a super-minimal build configuration, handy for board
# bringup and very low level debugging
subdirs := \
bionic \
system/core \
build/libs \
build/target \
build/tools/acp \
build/tools/apriori \
build/tools/kcm \
build/tools/soslim \
external/elfcopy \
external/elfutils \
external/yaffs2 \
external/zlib
else # !BUILD_TINY_ANDROID

#(27)若上面的两个条件(SDK_ONLY为真,BUILD_TINY_ANDROID为真)都不成了,那么就要包含$(TOP)下面
# 的所有android.mk文件了。这才是最典型的编译.
#
# Typical build; include any Android.mk files we can find.
#
subdirs := $(TOP)
FULL_BUILD := true
endif # !BUILD_TINY_ANDROID
endif # !SDK_ONLY
ifneq ($(ONE_SHOT_MAKEFILE),)
# We've probably been invoked by the "mm" shell function
# with a subdirectory's makefile.
include $(ONE_SHOT_MAKEFILE)
# Change CUSTOM_MODULES to include _disibledevent=> FULL_BUILD :=
# Stub out the notice targets, which probably aren't defined
# when using _disibledevent=> #(29)在这里调用findleaves.py查找在subdirs的包含的子目录下所有的 Android.mk文件。
subdir_makefiles := \
$(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk)
include $(subdir_makefiles)
endif # _disibledevent=> unknown_custom_modules := $(filter-out $(ALL_MODULES),$(CUSTOM_MODULES))
CUSTOM_MODULES := \
$(call module-installed-files,$(known_custom_modules)) \
$(unknown_custom_modules)
# -------------------------------------------------------------------
# Define dependencies for modules that require other modules.
# This can _disibledevent=> $(if $(r), \
$(eval r := $(call module-installed-files,$(r))) \
$(eval $(call add-required-deps,$(ALL_MODULES.$(m).INSTALLED),$(r))) \
) \
)
m :=
r :=
add-required-deps :=
# -------------------------------------------------------------------
# Figure out our module sets.
# Of the modules defined by the component makefiles,
# determine what we actually want to build.
# If a module has the "restricted" tag _disibledevent=> $(CUSTOM_MODULES))
# TODO: Remove the 3 places in the tree that use
# ALL_DEFAULT_INSTALLED_MODULES and get rid of it from this list.
ifdef FULL_BUILD
# The base list of modules to build for this product is specified
# by the appropriate product definition file, which was included
# by product_config.make.
#
#(33)设定user_PACKAGES获取这个product的所有的modules 的list,这份list定义的module选择定义在
# product_config.mk这个文件以及这个文件包含的子*.mk文件中。
user_PACKAGES := $(call module-installed-files, \
$(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_PACKAGES))
ifeq (0,1)
$(info user packages for $(TARGET_DEVICE) ($(INTERNAL_PRODUCT)):)
$(foreach p,$(user_PACKAGES),$(info : $(p)))
$(error done)
endif
else
# We're not doing a full build, and are probably _disibledevent=> endif
#(34)模块设定:引擎类模块eng_MODULES,应用类模块user_MODULES,测试模块test_MODULES,调试模块debug_MOUDLE
# Use tags to get the non-APPS user modules. Use the product
# definition files to get the APPS user modules.
user_MODULES := $(sort $(call get-tagged-modules,user,_class@APPS restricted))
user_MODULES := $(user_MODULES) $(user_PACKAGES)
eng_MODULES := $(sort $(call get-tagged-modules,eng,restricted))
debug_MODULES := $(sort $(call get-tagged-modules,debug,restricted))
tests_MODULES := $(sort $(call get-tagged-modules,tests,restricted))
ifeq ($(strip $(tags_to_install)),)
$(error ASSERTION FAILED: tags_to_install should not be empty)
endif

#(35)tags_to_install获取要安装的模块
# 获取关系如下:tags_to_install <- user_variant <- TARGET_BUILD_VARIANT,TARGET_BUILD_VARIANT在buildspec.mk设定
modules_to_install := $(sort $(Default_MODULES) \
$(foreach tag,$(tags_to_install),$($(tag)_MODULES)))
# Some packages may override others using LOCAL_OVERRIDES_PACKAGES.
# Filter out (do not install) any overridden packages.
overridden_packages := $(call get-package-overrides,$(modules_to_install))
ifdef overridden_packages
# old_modules_to_install := $(modules_to_install)
modules_to_install := \
$(filter-out $(foreach p,$(overridden_packages),$(p) %/$(p).apk), \
$(modules_to_install))
endif
#$(error filtered out
# $(filter-out $(modules_to_install),$(old_modules_to_install)))
# Don't include any GNU targets in the SDK. It's ok (and necessary)
# to build the host tools, but nothing that's going to be installed
# _disibledevent=> $(filter \
$(TARGET_OUT_INTERMEDIATES)/% \
$(TARGET_OUT)/% \
$(TARGET_OUT_DATA)/%, \
$(sort $(call get-tagged-modules,gnu)))
$(info Removing from sdk:)$(foreach d,$(target_gnu_MODULES),$(info : $(d)))
modules_to_install := \
$(filter-out $(target_gnu_MODULES),$(modules_to_install))
endif
# build/core/Makefile contains extra stuff that we don't want to pollute this
# top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES
# contains everything that's built during the current make, but it also further
# extends ALL_DEFAULT_INSTALLED_MODULES.
#(37)对ALL_DEFAULT_INSTALLED_MODULES 的处理
ALL_DEFAULT_INSTALLED_MODULES := $(modules_to_install)
include $(BUILD_SYSTEM)/Makefile
modules_to_install := $(sort $(ALL_DEFAULT_INSTALLED_MODULES))
ALL_DEFAULT_INSTALLED_MODULES :=
endif # dont_bother
# These are additional goals that we build, in order to make sure that there
# is as little code as possible in the tree that doesn't build.
#(38)确保我们定义我们构建的模块是没有冗余的。
modules_to_check := $(foreach m,$(ALL_MODULES),$(ALL_MODULES.$(m).CHECKED))
# If you would like to build all goals, and not skip any intermediate
# steps, you can pass the "all" modifier goal _disibledevent=> endif
# for easier debugging
modules_to_check := $(sort $(modules_to_check))
#$(error modules_to_check $(modules_to_check))
# -------------------------------------------------------------------
# This is used to to get the ordering right, you can also use these,
# but they're considered undocumented, so don't complain if their
# behavior changes.
.PHONY: prebuilt
prebuilt: $(ALL_PREBUILT)
# An internal target that depends _disibledevent=> endif
#40)一下是整改项目的build动作,如果要把整个编译过程分成:配置和编译两部分的话,
# 上面的所有的都是配置过程,下面的为编译过程。
# 这里确定好要生成的子目标。
# Build files and then package it into the rom formats
.PHONY: droidcore
droidcore: files \
systemimage \
$(INSTALLED_BOOTIMAGE_TARGET) \
$(INSTALLED_RECOVERYIMAGE_TARGET) \
$(INSTALLED_USERDATAIMAGE_TARGET) \
$(INSTALLED_FILES_FILE)
# The actual files built by the droidcore target changes depending
# _disibledevent=> sdk: $(ALL_SDK_TARGETS)
$(call dist-for-goals,sdk,$(ALL_SDK_TARGETS))
.PHONY: findbugs
findbugs: $(INTERNAL_FINDBUGS_HTML_TARGET) $(INTERNAL_FINDBUGS_XML_TARGET)
.PHONY: clean
dirs_to_clean := \
$(PRODUCT_OUT) \
$(TARGET_COMMON_OUT_ROOT) \
$(HOST_OUT) \
$(HOST_COMMON_OUT_ROOT)
clean:
@for dir in $(dirs_to_clean) ; do \
echo "Cleaning $$dir..."; \
rm -rf $$dir; \
done
@echo "Clean."; \
.PHONY: clobber
clobber:
@rm -rf $(OUT_DIR)
@echo "Entire build directory removed."
# The rules for dataclean and installclean are defined in cleanbuild.mk.
#xxx scrape this from ALL_MODULE_NAME_TAGS
.PHONY: modules
modules:
@echo "Available sub-modules:"
@echo "$(call module-names-for-tag-list,$(ALL_MODULE_TAGS))" | \
sed -e 's/ */\n/g' | sort -u | $(COLUMN)
.PHONY: showcommands
showcommands:
@echo >/dev/null
Tags: 
阅读(2129) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~