一般来说编译一个sdk或者一个比较大的工程项目,第一步都是执行 envsetup.sh这个脚本,比如编译android,qt源码以及其他一些嵌入式的sdk。

而且执行的时候需要特别注意使用

source build/envsetup.sh

或者

. ./build/envsetup.sh

特别注意两个点之间是有空格的,这个作用相当于source。

==========================================补课开始=====================================================================

一般执行shell脚本时直接用./来执行,此时是系统启动一个子shell进程来执行命令,执行完后返回最后一条指令的结果(可以用echo $?来获取执行结果值(0-255)),其结果并不会对当前的BASH产生影响。

source命令的用法:

source FileName

他的作用是在当前bash环境下读取并执行FileName中的指令,这个命令执行完之后会把FileName执行过程中的一些输出设置到当前的BASH中,也就设置环境变量。

需要注意的是用source执行新产生的这些变量的作用范围(作用域)只是在当前终端有用,如果你关闭当前终端了,或者在其他终端是无法使用这些新增的变量的。

==========================================补课结束=====================================================================

当我们用source命令执行完encsetup.sh的时候,里面设置的一些变量(方法)就会输出到当前的BASH环境中,在后续的过程中我们就可以在当前终端使用这些变量,比如用android的envsetup.sh来说,执行完后会增加一些shell cmd及环境变量可以使用

输入hmm可以看到以下帮助信息

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] [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.
- 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.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is:
addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient gdbwrapper get_abs_build_var getbugreports get_build_var getlastscreenshot getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop godir hmm isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m mangrep mm mma mmm mmma pez pid printconfig print_lunch_menu qpid resgrep runhat runtest sepgrep set_java_home setpaths set_sequence_number set_stuff_for_environment settitle smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump
liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ source build/envsetup.sh
find Makefile
including device/generic/mips/vendorsetup.sh
including device/generic/armv7-a-neon/vendorsetup.sh
including device/generic/x86/vendorsetup.sh
including device/softwinner/common/vendorsetup.sh
including device/softwinner/dolphin-fvd-p1/vendorsetup.sh
liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ hmm
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] [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.
- 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.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is:
addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient gdbwrapper get_abs_build_var getbugreports get_build_var getlastscreenshot getprebuilt getscreenshotpath getsdcardpath gettargetarch gettop godir hmm isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m mangrep mm mma mmm mmma pez pid printconfig print_lunch_menu qpid resgrep runhat runtest sepgrep set_java_home setpaths set_sequence_number set_stuff_for_environment settitle smoketest stacks startviewserver stopviewserver systemstack tapas tracedmdump
liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$

这些命令都是在android/build/envsetup.sh中定义输出的,可以打开看下

export ROOT_DIR=${PWD}
MAKEFILE=$ROOT_DIR/Makefile
if [ -f $MAKEFILE ]; then
echo "find Makefile"
else
echo "copy Makefile"
cp $ROOT_DIR/build/core/root.mk $ROOT_DIR/Makefile
fi
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] [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.
- 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.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file. Look at the source to view more functions. The complete list is:
EOF
T=$(gettop)
local A
A=""
for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
A="$A $i"
done
echo $A
} # Get the value of a build variable as an absolute path.
function get_abs_build_var()
{
T=$(gettop)
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP." >&2
return
fi
(\cd $T; CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \
make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-abs-$1)
}

这些方法还有一些变量都会输出到当前的BASH环境中,输入env指令就可以打印出当前BASH下的所有环境变量

liuxueneng@airfly-dev:~/workCode/allwinner_h2_2018-0907/android$ env
XDG_SESSION_ID=13509
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=192.168.11.102 1097 22
OLDPWD=/home/liuxueneng
SSH_TTY=/dev/pts/26
USER=liuxueneng
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
ROOT_DIR=/home/liuxueneng/workCode/allwinner_h2_2018-0907/android
MAIL=/var/mail/liuxueneng
PATH=/home/liuxueneng/bin:/home/liuxueneng/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=/home/liuxueneng/workCode/allwinner_h2_2018-0907/android
LANG=en_HK.UTF-8
SHLVL=1
HOME=/home/liuxueneng
LANGUAGE=en_HK:en
LOGNAME=liuxueneng
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
SSH_CONNECTION=192.168.11.102 1097 192.168.11.111 22
LESSOPEN=| /usr/bin/lesspipe %s
XDG_RUNTIME_DIR=/run/user/1006
LESSCLOSE=/usr/bin/lesspipe %s %s
_=/usr/bin/env

其中我们可以看到至少以下两个变量是执行刚才的envsetup.sh输出来的

ROOT_DIR=/home/liuxueneng/workCode/allwinner_h2_2018-0907/android

联系以上的的croot指令就是改变当前工作目录的哦ROOT_DIR中。

另外还可以查看输出到当前BASH环境中的临时shell方法,输入set指令来查看(小心会有一大堆东西喷出来)

tracedmdump ()
{
T=$(gettop);
if [ ! "$T" ]; then
echo "Couldn't locate the top of the tree. Try setting TOP.";
return;
fi;
local prebuiltdir=$(getprebuilt);
local arch=$(gettargetarch);
local KERNEL=$T/prebuilts/qemu-kernel/$arch/vmlinux-qemu;
local TRACE=$1;
if [ ! "$TRACE" ]; then
echo "usage: tracedmdump tracename";
return;
fi;
if [ ! -r "$KERNEL" ]; then
echo "Error: cannot find kernel: '$KERNEL'";
return;
fi;
local BASETRACE=$(basename $TRACE);
if [ "$BASETRACE" = "$TRACE" ]; then
TRACE=$ANDROID_PRODUCT_OUT/traces/$TRACE;
fi;
echo "post-processing traces...";
rm -f $TRACE/qtrace.dexlist;
post_trace $TRACE;
if [ $? -ne 0 ]; then
echo "***";
echo "*** Error: malformed trace. Did you remember to exit the emulator?";
echo "***";
return;
fi;
echo "generating dexlist output...";
/bin/ls $ANDROID_PRODUCT_OUT/system/framework/*.jar $ANDROID_PRODUCT_OUT/system/app/*.apk $ANDROID_PRODUCT_OUT/data/app/*.apk 2> /dev/null | xargs dexlist > $TRACE/qtrace.dexlist;
echo "generating dmtrace data...";
q2dm -r $ANDROID_PRODUCT_OUT/symbols $TRACE $KERNEL $TRACE/dmtrace || return;
echo "generating html file...";
dmtracedump -h $TRACE/dmtrace >| $TRACE/dmtrace.html || return;
echo "done, see $TRACE/dmtrace.html for details";
echo "or run:";
echo " traceview $TRACE/dmtrace"
}
treegrep ()
{
find . -name .repo -prune -o -name .git -prune -o -regextype posix-egrep -iregex '.*\.(c|h|cpp|S|java|xml)' -type f -print0 | xargs -0 grep --color -n -i "$@"
}
verity_file_init ()
{
echo "verity_file_init";
cp -rf $DEVICE/verity ${OUT};
$DEVICE/verity/gen_file_verify_block.sh ${OUT}/system;
cp -f ${OUT}/verity/verity_block ${OUT}/verity_block.img
}
verity_key_init ()
{
$DEVICE/verity/gen_dm_verity_key.sh;
cp -f $DEVICE/verity/rsa_key/verity_key $OUT/root
}

以上treegrep tracedmdump等shell方法都是从envsetup.sh输出来的。

后续讲解下输出的m mm mmm mmma croot cgrep 等作用及用法。

Android编译执行envsetup.sh,产生工具命令m、mm、mmm、mmma、tapas 、croot、cgrep、jgrep、 resgrep、godir的更多相关文章

  1. Android 经常使用工作命令mmm,mm,m,croot,cgrep,jgrep,resgrep,godir

    官方定义: Invoke ". build/envsetup.sh" from your shell to add the following functions to your ...

  2. android平台的三个编译命令——make,mm,mmm

    在Android源码根目录下,执行以下三步即可编译android: 1.  build/envsetup.sh  #这个脚本用来设置android的编译环境; 2.  lunch  #选择编译目标 3 ...

  3. build/envsetup.sh 生成的命令详解表

    参考: https://wiki.cyanogenmod.org/w/Envsetup_help 它是一个.sh文件,用source后就生成android编译相关函数,具体如下. 速查 Invokin ...

  4. 【转】Android源代码编译命令m/mm/mmm/make分析--不错

    原文网址:http://blog.csdn.net/luoshengyang/article/details/19023609 在前文中,我们分析了Android编译环境的初始化过程.Android编 ...

  5. 【转】Android source build/envsetup.sh学习笔记

    原文网址:http://blog.csdn.net/mliubing2532/article/details/7567164 如果你只需要修改某一个模块的内容,但是却每次都要执行make, 最后等待很 ...

  6. Android编译详解之lunch命令 【转】

    本文转载自: Android编译详解之lunch命令 (2012-10-08 10:27:55) 转载▼ 标签: it 分类: android内核剖析     Android的优势就在于其开源,手机和 ...

  7. Android编译过程详解(二)

    通过上篇文章,我们分析了编译android时source build/envsetup.sh和lunch命令,在执行完上述两个命令后, 我们就可以进行编译android了. 1. make  执行ma ...

  8. Android 编译时:m、mm、mmm、mma、mmma的区别

    m:编译整个安卓系统 makes from the top of the tree mm:编译当前目录下的模块,当前目录下需要有Android.mk这个makefile文件,否则就往上找最近的Andr ...

  9. android编译遇到问题修改

    (注意要确定安装了jdk) 第一步: cd  lichee; ./build.sh  -p sun5i_elite -k 3.0  (apt-get install uboot-mkimage需要安装 ...

随机推荐

  1. 数据结构逆向分析-Map

    数据结构逆向分析-Map map是一个典型的二叉树结构,准确的来说是一个平衡二叉树或者红黑树,特点是数据存储是有序的存储. 参考侯杰老师的stl源码剖析,map里面采用的是RB-TREE也就是红黑树 ...

  2. 学习PHP中的国际化功能来查看货币及日期信息

    做为一门在世界范围内广泛使用的编程语言,国际化能力往往是衡量一个编程语言是否能够大范围流行的重要内容.特别是对于 PHP 这种以 Web 页面编程为主战场的语言来说,国际化能力更是重中之重.在 PHP ...

  3. 深入HTML5第一天

    页面的title一般是30-40个字符:分别为主页,详情页,列表页  keywords:100个字符  description: em是:emphasize: 强调,着重  i:italic斜体的 : ...

  4. python线程threading

    线程示例: import threading import time # 唱歌任务 def sing(): # 扩展: 获取当前线程 # print("sing当前执行的线程为:" ...

  5. django中csrf_token处理方式

    第一:先在HTML中加入{% csrf_token %} $.ajax({ url: '{% url "ceshi:list" %}', type: 'post', dataTyp ...

  6. css布局宽度自适应

    随着各种终端的不断涌现,网页中的元素适应不同的分辨率变得特别重要,根据经验,涉及到宽度自适应的一共有四种情况: 左端固定,右边自适应:右端固定,左边自适应:两端固定,中间自适应:中间固定,两端自适应. ...

  7. mysql where in 数组解决小tips

    由于sql语法要求,不可在in后面直接连数组,若数组形式下,则需要转换成逗号隔开的字符串 <?php$arr = array(1,2,3,4,5);$arr_string= join(',', ...

  8. Python3入门系列之-----函数

    什么是函数 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可以自己 ...

  9. 从产业链、架构和技术三个层面,看元宇宙与RPA的发展关系

    你可能还不知道,元宇宙也将带动RPA高速发展 一文读懂RPA如何赋能元宇宙,虚拟空间更需要RPA无处不在 三个层面,解读元宇宙如何利好RPA行业发展 从产业链.架构和技术三个层面,看元宇宙与RPA的发 ...

  10. Ubuntu系统的开机全流程介绍及grub美化

    目录 前言 Ubuntu开机经历的步骤 BIOS Boot Loader Kernel 配置 Grub 的个性化主题 /usr/share/grub/default/grub /etc/default ...