前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android系统编译流程详解(二)

Android系统编译流程详解(二)

作者头像
李小白是一只喵
发布2020-04-24 09:23:39
1.7K0
发布2020-04-24 09:23:39
举报
文章被收录于专栏:算法微时光

编译源码步骤

google给出的编译步骤如下:

  1. source build/envsetup.sh:加载命令
  2. lunch:选择平台编译选项
  3. make:执行编译 那么每一步都做了什么呢?

build/envsetup.sh

打开build/envsetup.sh文件: (Android P版本下)

可以看到有许多的函数.

函数名

含义

hmm()

显示帮助信息

lunch

配置lunch

tapas

tapas

croot

回到根目录

m

make from top

mm

Builds all of the modules in the current directory,

mma

Builds all of the modules in the current directory

mmma

Builds all of the modules in the supplied directories,

cgrep

查找c/c++文件

ggrep

查找所有的文件

jgrep

查找java文件

resgrep

查找xml文件

mangrep

查找Manifest.xml文件

mgrep

查找所有的mk文件

sepgrep

查找sepolicy文件

sgrep

查找源码文件

godir

跳转指定目录

get_abs_build_var

获取绝对变量

get_build_var

获取绝对变量

check_product

检查product

check_variant

检查变量

setpaths

设置文件路径

printconfig

打印配置

set_stuff_for_environment

设置环境变量

set_sequence_number

设置序号

settitle

设置标题

choosetype

设置type

chooseproduct

设置product

choosevariant

设置variant

tapas

功能同choosecombo

choosecombo

设置编译参数

有兴趣的可以看一下源码.O(∩_∩)O

执行:
代码语言:javascript
复制
source build/envsetup.sh 

在脚本最后,执行以下代码,来加载各个区域的vendorsetup.sh文件.

代码语言:javascript
复制
 if [ "x$SHELL" != "x/bin/bash" ]; then
     case `ps -o command -p $$` in
         *bash*)
             ;;
         *)
             echo "WARNING: Only bash is supported, use of other shell would lead to err     oneous results"
             ;;
     esac
 fi
 
 # Execute the contents of any vendorsetup.sh files we can find.
 for f in `test -d device && find -L device -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/n     ull | sort` \
          `test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/n     ull | sort` \
          `test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev     /null | sort`
 do
     echo "including $f"
     . $f
 done

查看下device/google/marlin/vendorsetup.sh文件,可以看到:

文件中调用了add_lunch_combo命令.

add_lunch_combo命令的定义在文件build/envsetup.sh中:

代码语言:javascript
复制
  function add_lunch_combo()
  {
      local new_combo=$1
      local c
      for c in ${LUNCH_MENU_CHOICES[@]} ; do
          if [ "$new_combo" = "$c" ] ; then
              return
          fi
      done
      LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
  }

可以看出,编译时,就是通过add_lunch_combo将编译选项传递给lunch的.

lunch

先来看下lunch的实现:

代码语言:javascript
复制
function lunch()
{
    local answer

    if [ "$1" ] ; then
        answer=$1
    else
        print_lunch_menu
        echo -n "Which would you like? [aosp_arm-eng] "
        read answer
    fi

    local selection=

    if [ -z "$answer" ]
    then
        selection=aosp_arm-eng
    elif (echo -n $answer | grep -q -e "^[0-9][0-9]*$")
    then
        if [ $answer -le ${#LUNCH_MENU_CHOICES[@]} ]
        then
            selection=${LUNCH_MENU_CHOICES[$(($answer-1))]}
        fi
    else
        selection=$answer
    fi

    export TARGET_BUILD_APPS=

    local product variant_and_version variant version

    product=${selection%%-*} # Trim everything after first dash
    variant_and_version=${selection#*-} # Trim everything up to first dash
    if [ "$variant_and_version" != "$selection" ]; then
        variant=${variant_and_version%%-*}
        if [ "$variant" != "$variant_and_version" ]; then
            version=${variant_and_version#*-}
        fi
    fi

    if [ -z "$product" ]
    then
        echo
        echo "Invalid lunch combo: $selection"
        return 1
    fi

    TARGET_PRODUCT=$product \
    TARGET_BUILD_VARIANT=$variant \
    TARGET_PLATFORM_VERSION=$version \
    build_build_var_cache
    if [ $? -ne 0 ]
    then
        return 1
    fi

    export TARGET_PRODUCT=$(get_build_var TARGET_PRODUCT)
    export TARGET_BUILD_VARIANT=$(get_build_var TARGET_BUILD_VARIANT)
    export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
    export TARGET_BUILD_TYPE=release

    echo

    set_stuff_for_environment
    printconfig
    destroy_build_var_cache
}

lunch命令是envsetup.sh里定义的一个命令,用来让用户选择编译项,来定义Product和编译过程中用到的全局量

liunch大致实现了导出一些重要的环境变量,从而影响编译系统的编译结果。

接下来就是make了.

参考

Android编译过程详解(一)

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 编译源码步骤
  • build/envsetup.sh
  • lunch
  • 参考
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档