m mm等和envsetup.sh

envsetup.sh简介:

Android 完成编译的时候先执行 source build/envsetup.sh。在这个shell 脚本中定义了 help, croot, m, mm, mmm 等 function,这些function可以作为命令行工具使用

source命令:source 命令会把对应脚本中的内容读取到当前的bash 解释器中,在当前的执行环境中执行;其中定义的 function 以及通过 export 声明的变量等在 source 执行结束之后依然存在于当前的bash 环境中。比如我们常用的 source .bashrc 或者 source .profile等目的是为了引用刚刚改动过的环境变量。

envsetup.sh中提供一下工具:

lunch:lunch<product_name> - <build_variant>
tapas:tapas[<App1> <App2> ...] [arm | x86 | mips] [eng | userdebug | user]
croot:将目录更改为树的顶部。
m:从树顶make。
mm:构建(build)当前目录中的所有模块。
mmm:构建(build)所提供目录中的所有模块。
cgrep:Greps所有本地C/C ++文件。
jgrep:Greps所有本地Java文件。
resgrep:Greps on all local res/*.xml文件。
godir:到包含文件的目录。

1.m
当在任何一个目录下打 m 的时候, 它会执行下面的function.

function m()
{
    T=$(gettop)
    if [ "$T" ]; then
        make -C $T $@
    else
        echo "Couldn't locate the top of the tree.  Try setting TOP."
    fi
}

$@ 返回调用这个脚本时传入的参数,比如执行$ m showcommands -d 经过 function m 的翻译后就执行
make -C /home/yajun/Android/an403 showcommands -d   $T可以使用 $ gettop 来查看,若当前目录不在源码树中,$T就为空,打印上面的错误信息。

2.mm
build当前目录中的所有模块

function mm()
{
    # If we're sitting in the root of the build tree, just do a
    # normal make.
    if [ -f build/core/envsetup.mk -a -f Makefile ]; then
        make $@
    else
        # Find the closest Android.mk file.
        T=$(gettop)
        local M=$(findmakefile)
        # Remove the path to top as the makefilepath needs to be relative
        local M=`echo $M|sed 's:'$T'/::'`
        if [ ! "$T" ]; then
            echo "Couldn't locate the top of the tree.  Try setting TOP."
        elif [ ! "$M" ]; then
            echo "Couldn't locate a makefile from the current directory."
        else
            ONE_SHOT_MAKEFILE=$M make -C $T all_modules $@
        fi
    fi
}

从它的注释可以看出,当你在某个目录下执行 mm 的时候,它首先现判断当前目录是不是 TOP 目录,如果是,就直接开始make 了,如果不是,就调用findmakefile 寻找 Android.mk , 搜索的路径是 当前目录-> 父目录 -> 父目录 -> ... -> 到根目录.

function findmakefile()
{
    TOPFILE=build/core/envsetup.mk
    # We redirect cd to /dev/null in case it's aliased to
    # a command that prints something as a side-effect
    # (like pushd)
    local HERE=$PWD
    T=
    while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
        T=`PWD= /bin/pwd`
        if [ -f "$T/Android.mk" ]; then
            echo $T/Android.mk
            cd $HERE > /dev/null
            return
        fi
        cd .. > /dev/null
    done
    cd $HERE > /dev/null
}

当在某个目录下找到Android.mk后,就把它echo 出来。然后 cd $HERE 返回调用 findmakefile 的目录。

3.gettop
返回源码的顶层目录,如果这个目录存在。

function gettop
{
    local TOPFILE=build/core/envsetup.mk
    if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
        echo $TOP
    else
        if [ -f $TOPFILE ] ; then
            # The following circumlocution (repeated below as well) ensures
            # that we record the true directory name and not one that is
            # faked up with symlink names.
            PWD= /bin/pwd
        else
            # We redirect cd to /dev/null in case it's aliased to
            # a command that prints something as a side-effect
            # (like pushd)
            local HERE=$PWD
            T=
            while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
                cd .. > /dev/null
                T=`PWD= /bin/pwd`
            done
            cd $HERE > /dev/null
            if [ -f "$T/$TOPFILE" ]; then
                echo $T
            fi
        fi
    fi
}

如果这个目录存在,比如在我的机器上是:
$ gettop
/home/mypc/Android/an403

LOCAL_MODULE:= 这是对变量LOCAL_MODULE赋值为空!!

可以在.mk文件中打印变量linked_module的值进行查看:$(warning "linked_modle=$(linked_module)")  它会将“”中的内容打印出来。

参考:https://blog.csdn.net/yajun0601/article/details/7309010  对m mm分析的教详细

猜你喜欢

转载自www.cnblogs.com/hellokitty2/p/10275040.html
M
^M