1. cd AP 进入AP目录,如果已经进入到了A目录,可以忽略
2. source build/envsetup.sh 初始编译环境,envsetup.sh里面是一些编译命令,类似于linxu自带的ls cd等指令
cwm@cwm-OptiPlex-7060:~/work/project/gm/android_p/AP$ source build/envsetup.sh
including device/generic/car/vendorsetup.sh
including device/generic/mini-emulator-arm64/vendorsetup.sh
including device/generic/mini-emulator-armv7-a-neon/vendorsetup.sh
including device/generic/mini-emulator-x86_64/vendorsetup.sh
including device/generic/mini-emulator-x86/vendorsetup.sh
including device/generic/uml/vendorsetup.sh
including device/google/muskie/vendorsetup.sh
including device/google/taimen/vendorsetup.sh
including device/qcom/common/vendorsetup.sh
including device/qcom/qssi/vendorsetup.sh
including vendor/dolby/device/sailfish_dax1_sw/vendorsetup.sh
including vendor/dolby/device/walleye_dax1_sw/vendorsetup.sh
including vendor/qcom/opensource/core-utils/vendorsetup.sh
including vendor/qcom/proprietary/common/vendorsetup.sh
including sdk/bash_completion/adb.bash
3. lunch 这个lunc命令执行了第二步以后,在当前环境存在的,选择的是第40个选项 40. msm8937_64-userdebug
cwm@cwm-OptiPlex-7060:~/work/project/gm/android_p/AP$ lunch
You're building on Linux
Lunch menu... pick a combo:
1. aosp_arm-eng
2. aosp_arm64-eng
3. aosp_mips-eng
4. aosp_mips64-eng
5. aosp_x86-eng
6. aosp_x86_64-eng
7. aosp_car_arm-userdebug
8. aosp_car_arm64-userdebug
9. aosp_car_x86-userdebug
10. aosp_car_x86_64-userdebug
11. mini_emulator_arm64-userdebug
12. m_e_arm-userdebug
13. mini_emulator_x86_64-userdebug
14. mini_emulator_x86-userdebug
15. uml-userdebug
16. aosp_walleye-userdebug
17. aosp_walleye_test-userdebug
18. aosp_taimen-userdebug
19. msm8974-userdebug
20. msm8610-userdebug
21. msm8226-userdebug
22. apq8084-userdebug
23. mpq8092-userdebug
24. msm_bronze-userdebug
25. msm8916_32-userdebug
26. msm8916_32_512-userdebug
27. msm8916_32_k64-userdebug
28. msm8916_64-userdebug
29. msm8994-userdebug
30. msm8996-userdebug
31. msm8909-userdebug
32. msm8909go-userdebug
33. msm8909_512-userdebug
34. msm8909_512go-userdebug
35. msm8992-userdebug
36. msm8952_64-userdebug
37. msm8952_32-userdebug
38. msm8937_32-userdebug
39. msm8937_32go-userdebug
40. msm8937_64-userdebug
41. msm8953_32-userdebug
42. msm8953_64-userdebug
43. msm8998-userdebug
44. msm8998_32-userdebug
45. sdm660_64-userdebug
46. sdm660_32-userdebug
47. sdm845-userdebug
48. apq8098_latv-userdebug
49. sdm710-userdebug
50. msmnile-userdebug
51. msmnile_au-userdebug
52. qcs605-userdebug
53. talos-userdebug
54. talos_au-userdebug
55. qssi-userdebug
56. sailfish_dax1_sw-userdebug
57. walleye_dax1_sw-userdebug
Which would you like? [aosp_arm-eng] 40
4. make -j6 开始编译根据需要选择自己的核数
第2步的envsetup.sh脚本分析之lunch命令
function lunch()
{
local answer
if [ "$1" ] ; then
answer=$1 #如果lunch时带参数,那么就执行这条语句
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)
if [ -n "$version" ]; then
export TARGET_PLATFORM_VERSION=$(get_build_var TARGET_PLATFORM_VERSION)
else
unset TARGET_PLATFORM_VERSION
fi
export TARGET_BUILD_TYPE=release
echo
set_stuff_for_environment
printconfig
destroy_build_var_cache
}
print_lunch_menu函数分析
function print_lunch_menu()
{
local uname=$(uname)
echo
echo "You're building on" $uname
echo
echo "Lunch menu... pick a combo:"
local i=1
local choice
for choice in ${LUNCH_MENU_CHOICES[@]} #LUNCH_MENU_CHOICES保存的是所有平台信息,平台信息收集是通过add_lunch_combo函数
do
echo " $i. $choice"
i=$(($i+1))
done
echo
}
add_lunch_combo函数分析
unset LUNCH_MENU_CHOICES
function add_lunch_combo() #调用此函数,同时跟一个代表平台信息的参数,此函数会在不同目录下的vendorsetup.sh脚本被调用
{
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)
}
遍历的目录包含device vendor product
# 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/null | sort` \
`test -d vendor && find -L vendor -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort` \
`test -d product && find -L product -maxdepth 4 -name 'vendorsetup.sh' 2> /dev/null | sort`
do
echo "including $f"
. $f
done
unset f
查看device/qcom/common目录下的vendorsetup.sh,加载了以下平台信息
#
# Copyright (c) 2012, The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
add_lunch_combo msm8974-userdebug
add_lunch_combo msm8610-userdebug
add_lunch_combo msm8226-userdebug
add_lunch_combo apq8084-userdebug
add_lunch_combo mpq8092-userdebug
add_lunch_combo msm_bronze-userdebug
add_lunch_combo msm8916_32-userdebug
add_lunch_combo msm8916_32_512-userdebug
add_lunch_combo msm8916_32_k64-userdebug
add_lunch_combo msm8916_64-userdebug
add_lunch_combo msm8994-userdebug
add_lunch_combo msm8996-userdebug
add_lunch_combo msm8909-userdebug
add_lunch_combo msm8909go-userdebug
add_lunch_combo msm8909_512-userdebug
add_lunch_combo msm8909_512go-userdebug
add_lunch_combo msm8992-userdebug
add_lunch_combo msm8952_64-userdebug
add_lunch_combo msm8952_32-userdebug
add_lunch_combo msm8937_32-userdebug
add_lunch_combo msm8937_32go-userdebug
add_lunch_combo msm8937_64-userdebug
add_lunch_combo msm8953_32-userdebug
add_lunch_combo msm8953_64-userdebug
add_lunch_combo msm8998-userdebug
add_lunch_combo msm8998_32-userdebug
add_lunch_combo sdm660_64-userdebug
add_lunch_combo sdm660_32-userdebug
add_lunch_combo sdm845-userdebug
add_lunch_combo apq8098_latv-userdebug
add_lunch_combo sdm710-userdebug
add_lunch_combo msmnile-userdebug
add_lunch_combo msmnile_au-userdebug
add_lunch_combo qcs605-userdebug
add_lunch_combo talos-userdebug
add_lunch_combo talos_au-userdebug