build/envsetup.sh中hmm、get_abs_build_var、get_build_var解析
function hmm() {
# 打印帮助信息
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5|arm64|x86_64|mips64] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their dependencies.
To limit the modules being built use the syntax: mmm dir/:target1,target2.
- mma: Builds all of the modules in the current directory, and their dependencies.
- mmma: Builds all of the modules in the supplied directories, and their dependencies.
- cgrep: Greps on all local C/C++ files.
- ggrep: Greps on all local Gradle files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- sgrep: Greps on all local source files.
- godir: Go to the directory containing a file.
Look at the source to view more functions. The complete list is:
EOF
# gettop是脚本内函数,功能:返回当前android代码树的顶层路径。前提是当前路径位于android代码树中
T=$(gettop)
# A变量 局部变量化
local A
A=""
# 查看envsetup.sh内容,且行首开始空格、制表符任意次,替换function为匹配的子串(函数名),按字符排升序、去掉重复
for i in `cat $T/build/envsetup.sh | sed -n "/^[ \t]*function /s/function \([a-z_]*\).*/\/p" | sort | uniq`; do
# 替换出来的函数名 追加在A后 并打印
A="$A $i"
done
echo $A
}
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#得到build变量(脚本内)的绝对路径
function get_abs_build_var()
{
# 得到源码树顶层目录
T=$(gettop)
# 源码树顶层目录有效性容错
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&
return
fi
# 进入顶层目录,设置build变量,
# 通过make指定build/core/config.mk文件
# --no-print-directory:不要再屏幕上打印"Entering directory..
# CALLED_FROM_SETUP=true:打印出dumpvar-abs-$1所表示的变量的值必须先设置CALLED_FROM_SETUP
# BUILD_SYSTEM:设置所有的编译脚本路径
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
command make --no-print-directory -f build/core/config.mk dumpvar-abs-$)
}
function get_build_var()
{
T=$(gettop)
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&
return
fi
# 注释同上 唯一不同是目标dumpvar-$1不同
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
command make --no-print-directory -f build/core/config.mk dumpvar-$)
}
题外话:
BUILD_SYSTEM设置的Makefile目录——build/core目录下所有Makefile一览

config.mk详见一篇,此处一笔带过,只为得到CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core command make --no-print-directory -f build/core/config.mk dumpvar-$1”最终执行结果与过程。
..... include $(BUILD_SYSTEM)/dumpvar.mk
继续引入dumpvar.mk
# MAKECMDGOALS 变量是传进来的目标dumpvar-abs-$1或 dumpvar-$1的abs-$1或$
dumpvar_goals := \
$(strip $(patsubst dumpvar-%,%,$(filter dumpvar-%,$(MAKECMDGOALS))))
ifdef dumpvar_goals ifneq ($(words $(dumpvar_goals)),)
$(error Only one "dumpvar-" goal allowed. Saw "$(MAKECMDGOALS)")
endif # If the goal is of the form "dumpvar-abs-VARNAME", then
# treat VARNAME as a path and return the absolute path to it.
absolute_dumpvar := $(strip $(filter abs-%,$(dumpvar_goals)))
# 是否有abs
ifdef absolute_dumpvar
dumpvar_goals := $(patsubst abs-%,%,$(dumpvar_goals))
ifneq ($(filter /%,$($(dumpvar_goals))),)
DUMPVAR_VALUE := $($(dumpvar_goals))
else
DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals))
endif
# get_abs_build_var()中dumpvar-abs-$1对应的
dumpvar_target := dumpvar-abs-$(dumpvar_goals)
else
DUMPVAR_VALUE := $($(dumpvar_goals))
# get_build_var()中dumpvar-$1对应的
dumpvar_target := dumpvar-$(dumpvar_goals)
endif .PHONY: $(dumpvar_target)
# 执行目标与执行语句
$(dumpvar_target):
@echo $(DUMPVAR_VALUE)
即打印
其中如有abs则ifdef absolute_dumpvar->DUMPVAR_VALUE := $(PWD)/$($(dumpvar_goals)),打印信息增加pwd绝对路径
如没有 则else->DUMPVAR_VALUE := $($(dumpvar_goals)),打印信息没有绝对路径
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
envsetup.sh使用方法:
book@book-virtual-machine:/work/android-5.0.$ source build/envsetup.sh
including device/asus/deb/vendorsetup.sh
including device/asus/fugu/vendorsetup.sh
including device/asus/tilapia/vendorsetup.sh
including device/asus/flo/vendorsetup.sh
including device/asus/grouper/vendorsetup.sh
including device/samsung/manta/vendorsetup.sh
including device/friendly-arm/tiny4412/vendorsetup.sh
including device/lge/mako/vendorsetup.sh
including device/lge/hammerhead/vendorsetup.sh
including device/moto/shamu/vendorsetup.sh
including device/generic/mini-emulator-mips/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including sdk/bash_completion/adb.bash
book@book-virtual-machine:/work/android-5.0.$ get_abs_build_var TARGET_PRODUCT
/work/android-5.0./full
build/envsetup.sh中hmm、get_abs_build_var、get_build_var解析的更多相关文章
- 【Android】在build/envsetup.sh中添加自己的命令(函数)
由于测试的需要,经常需要手动刷入boot.img和system.img,把它写到envsetup.sh就可以每次使用一行命令来代替了: function flashtestimage(){ if [[ ...
- build/envsetup.sh内lunch解析
........ # 测试device是否存在且是一个目录 并且 只查找device目录4层以上的子目录,名字为vendorsetup.sh 并且 将命令执行的错误报告直接送往回收站 不显示在屏幕上 ...
- build/envsetup.sh 生成的命令详解表
参考: https://wiki.cyanogenmod.org/w/Envsetup_help 它是一个.sh文件,用source后就生成android编译相关函数,具体如下. 速查 Invokin ...
- 【转】Android编译系统详解(一)——build/envsetup.sh
出处 http://www.cloudchou.com/android/post-134.html 本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 准备好编译环境后,编译Rom的 ...
- 【转】Android source build/envsetup.sh学习笔记
原文网址:http://blog.csdn.net/mliubing2532/article/details/7567164 如果你只需要修改某一个模块的内容,但是却每次都要执行make, 最后等待很 ...
- [转载]Android 编译环境 build/envsetup.sh分析
2013-12-23 11:28:40 转载自: http://blog.csdn.net/evilcode/article/details/7005757 请到转载地址阅读原文, 转载以备查询.
- Android编译执行envsetup.sh,产生工具命令m、mm、mmm、mmma、tapas 、croot、cgrep、jgrep、 resgrep、godir
一般来说编译一个sdk或者一个比较大的工程项目,第一步都是执行 envsetup.sh这个脚本,比如编译android,qt源码以及其他一些嵌入式的sdk. 而且执行的时候需要特别注意使用 sourc ...
- Building System之 get_abs_build_var() && get_build_var()
点击打开链接 1.get_abs_build_var() 和 get_build_var()的实现都在build/envsetup.sh中. 2.在buld目录下grep这两个函数可知:这两个函数只在 ...
- m mm等和envsetup.sh
envsetup.sh简介: Android 完成编译的时候先执行 source build/envsetup.sh.在这个shell 脚本中定义了 help, croot, m, mm, mmm 等 ...
随机推荐
- 如何使用mysql的grant命令(详解)
grant命令的基本格式 grant 权限 on 数据库对象 to 用户 实例一:在任意ip地址登陆的common_user用户可以对testdb数据库里的数据进行查询操作.插入操作.更新操作.删除操 ...
- [QuickX]xcode运行Quick-cocos2d-x项目时自动更新lua资源文件
1.项目设置 build settings ->build options ->Scan all source files and Includes = YES 2.加入script (1 ...
- 【Android开发经验】ViewHolder到底用什么修饰?static?final?static final?
其实一上来我就贴一张图就ok了,因为这几种完全一样,不管用什么修饰,ViewHolder都会初始化当前界面可见item的数量+1次,和convertView的实例化次数是一样的,因此,我么不管使用什么 ...
- 【HDOJ】3234 Exclusive-OR
并查集.对于对元素赋值操作,更改为I p n v.令val[n]=0(任何数与0异或仍为原值).考虑fa[x] = fx, fa[y] = fy.如果使得fa[fx] = fy, 那么val[fx] ...
- suse系统FTP问题
1.修改FTP端口问题 在 这个配置文件中vi /etc/vsftpd.conf 添加 Listen_port=34 vi /etc/services ftp 21/tcp # F ...
- ASOP源码下载
vmware11下对虚拟机ubuntu14.10系统所在分区sda1进行磁盘扩容完后,重启在引导界面出现“a start job is running for dev-disk-by…”错误,产生此错 ...
- Eclipse&Spring开发开发环境配置
下载Eclipse,打开http://www.eclipse.org/downloads/,选择J2EE开发版: 根据操作系统选择32位还是64位. 开发工具:SpringSource Tool Su ...
- Tomcat7.0配置
Tomcat7.0下载地址:http://tomcat.apache.org/download-70.cgi 选择符合自己操作系统的版本即可(本机win8-64位系统),选择如下: http://11 ...
- Linux I2C设备驱动编写(三)-实例分析AM3359
TI-AM3359 I2C适配器实例分析 I2C Spec简述 特性: 兼容飞利浦I2C 2.1版本规格 支持标准模式(100K bits/s)和快速模式(400K bits/s) 多路接收.发送模式 ...
- Kbuild文件
3 Kbuild文件 大部分内核中的Makefile都是使用Kbuild组织结构的Kbuild Makefile.这章将介绍Kbuild Makefile的语法. 对于Kbuild文件名来讲,Kbui ...