Android编译系统分析(1)

来源:互联网 发布:node http 模块 编辑:程序博客网 时间:2024/06/01 10:08

1. 根目录下Makefile

 内容如下:
### DO NOT EDIT THIS FILE ###
include build/core/main.mk###
DO NOT EDIT THIS FILE ###
该文件仅包含 build/core/main.mk

2.  build/core/main.mk

首先选择使用的shell
ifdef ANDROID_BUILD_SHELL
SHELL := $(ANDROID_BUILD_SHELL)
else
SHELL := /bin/bash
endif
关闭makefile隐藏的后缀规则
.SUFFIXES:
编译过程中如出错,删除所有中间文件
.DELETE_ON_ERROR: 
检查make工具版本,其中info,warining,error前加$表示为make内置函数,打印出相关信息,如为error则打印信息后退出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 http://source.android.com/download)
$(warning ********************************************************************************)
$(error stopping)endif

接着设置环境变量
TOP := .
TOPDIR :=
BUILD_SYSTEM := $(TOPDIR)build/core

继续定义两个伪目标,所有默认在根目录make的话实际上编译的都是droid,即编译第一个伪目标
 .PHONY: droid
DEFAULT_GOAL := droid
$(DEFAULT_GOAL):

.PHONY:
FORCEFORCE:

随后又包含两个文件,这两个文件随后分析
include $(BUILD_SYSTEM)/config.mk
include $(BUILD_SYSTEM)/cleanbuild.mk

VERSION_CHECK_SEQUENCE_NUMBER := 2
-include $(OUT_DIR)/versions_checked.mk
ifneq ($(VERSION_CHECK_SEQUENCE_NUMBER),$(VERSIONS_CHECKED))
-include表示如没有该文件也没有关系,会忽略该错误继续make过程 ,然后做一个版本比较,若版本有改文件,且版本检查通过,则跳过以下的版本检查

$(info Checking build tools versions...)
ifeq ($(BUILD_OS),linux)
build_arch := $(shell uname -m)
ifneq (64,$(findstring 64,$(build_arch)))
$(warning ************************************************************)
$(warning You are attempting to build on a 32-bit system.)
$(warning Only 64-bit build environments are supported beyond froyo/2.2.)
$(warning ************************************************************)
$(error stop)
endif
endif
该部分要求系统是64位的,32位的系统走到之就编译失败了,解决办法将64改为i686即可或者注释掉这部分亦可

ifneq ($(HOST_OS),windows)
ifneq ($(HOST_OS)-$(HOST_ARCH),darwin-ppc)
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 on a case-insensitive filesystem.)
$(warning Please move your source tree to a case-sensitive filesystem.)
$(warning ************************************************************)
$(error Case-insensitive filesystems not supported)
endif
endif
endif
检查主机端的操作系统,是否为大小写敏感

ifneq ($(words $(shell pwd)),1)
$(warning ************************************************************)
$(warning You are building in a directory whose absolute path contains)
$(warning a space character:)
$(warning $(space))
$(warning "$(shell pwd)")
$(warning $(space))
$(warning Please move your source tree to a path that does not contain)
$(warning any spaces.)
$(warning ************************************************************)
$(error Directory names containing spaces not supported)
endif
检查源码目录(绝对路径)是否含有空格 

java_version := $(shell java -version 2>&1 | head -n 1 | grep '[ "]1\.6[\. "$$]')
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.6.)
$(info $(space))
$(info Please follow the machine setup instructions at)
$(info $(space)$(space)$(space)$(space)http://source.android.com/download)
$(info ************************************************************)
$(error stop)
endif

javac_version := $(shell javac -version 2>&1 | head -n 1 | grep '[ "]1\.6[\. "$$]')
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.6.)
$(info $(space))
$(info Please follow the machine setup instructions at)
$(info $(space)$(space)$(space)$(space)http://source.android.com/download)
$(info ************************************************************)
$(error stop)
endif
检查java和javac编译器版本是否为1.6 

版本检查结束,将版本信息保存,这样下次编译就不必再做版本检查了