1. 程式人生 > >Android系統移植與除錯之------->Amlogic方案編譯步驟

Android系統移植與除錯之------->Amlogic方案編譯步驟

這個命令是用來將envsetup.sh裡的所有用到的命令載入到環境變數裡去,我們來分析下它。

envsetup.sh裡的主要命令如下:

function help() 顯示幫助資訊
function get_abs_build_var()獲取絕對變數
function get_build_var()獲取絕對變數
function check_product()檢查product
function check_variant()檢查變數
function setpaths()設定檔案路徑
function printconfig()列印配置
function set_stuff_for_environment()

設定環境變數
function set_sequence_number()設定序號
function settitle()設定標題
function choosetype()設定type
function chooseproduct()設定product
function choosevariant()設定variant
function tapas()功能同choosecombo
function choosecombo()設定編譯引數
function add_lunch_combo()新增lunch專案
function print_lunch_menu()
列印lunch列表
function lunch()配置lunch
function m()# make from top
function findmakefile()查詢makefile
function mm()# make from current directory
function mmm()# make the supplied directories
function croot()回到根目錄
function cproj()
function pid()
function systemstack()
function gdbclient()
function jgrep()
查詢java檔案
function cgrep()查詢c/cpp檔案
function resgrep()
function tracedmdump()
function runhat()
function getbugreports()
function startviewserver()
function stopviewserver()
function isviewserverstarted()
function smoketest()
function runtest()
function godir () 跳到指定目錄 405

 # add_lunch_combo函式被多次呼叫,就是它來新增Android編譯選項
 # Clear this variable.  It will be built up again when the vendorsetup.sh
 406 # files are included at the end of this file.
 # 清空LUNCH_MENU_CHOICES變數,用來存在編譯選項
 407 unset LUNCH_MENU_CHOICES
 408 function add_lunch_combo()   
 409 {
 410     local new_combo=$1         # 獲得add_lunch_combo被呼叫時的引數
 411     local c
     # 依次遍歷LUNCH_MENU_CHOICES裡的值,其實該函式第一次呼叫時,該值為空
 412     for c in ${LUNCH_MENU_CHOICES[@]} ; do 
 413         if [ "$new_combo" = "$c" ] ; then    # 如果引數裡的值已經存在於LUNCH_MENU_CHOICES變數裡,則返回
 414             return
 415         fi
 416     done
     # 如果引數的值不存在,則新增到LUNCH_MENU_CHOICES變數裡
 417     LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo)
 418 }


這是系統自動增加了一個預設的編譯項 generic-eng
 420 # add the default one here
 421 add_lunch_combo generic-eng    呼叫上面的add_lunch_combo函式,將generic-eng作為引數傳遞過去
 422 
 423 # if we're on linux, add the simulator.  There is a special case
 424 # in lunch to deal with the simulator
 425 if [ "$(uname)" = "Linux" ] ; then
 426     add_lunch_combo simulator
 427 fi

下面的程式碼很重要,它要從vendor目錄下查詢vendorsetup.sh檔案,如果查到了,就載入它
1037 # Execute the contents of any vendorsetup.sh files we can find.
1038 for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/build/vendorsetup.sh 2> /dev/null`
1039 do
1040     echo "including $f"
1041    . $f       執行找到的指令碼,其實裡面就是廠商自己定義的編譯選項
1042 done
1043 unset f

envsetup.sh其主要作用如下:

  1. 載入了編譯時使用到的函式命令,如:helplunchmmmmmm
  2. 添加了兩個編譯選項:generic-engsimulator,這兩個選項是系統預設選項
  3. 查詢vendor/<-廠商目錄>/vendor/<廠商目錄>/build/目錄下的vendorsetup.sh,如果存在的話,載入執行它,新增廠商自己定義產品的編譯選項
 其實,上述第3條是向編譯系統添加了廠商自己定義產品的編譯選項,裡面的程式碼就是:add_lunch_combo xxx-xxx

根據上面的內容,可以推測出,如果要想定義自己的產品編譯項,簡單的辦法是直接在envsetup.sh最後,新增上add_lunch_combo myProduct-eng,當然這麼做,不太符合上面程式碼最後的本意,我們還是老實的在vendor目錄下建立自己公司名字,然後在公司目錄下建立一個新的vendorsetup.sh,在裡面新增上自己的產品編譯項

#mkdir vendor/farsight/

#touch vendor/farsight/vendorsetup.sh

#echo "add_lunch_combo fs100-eng" > vendor/farsight/vendorsetup.sh

這樣,當我們在執行source build/envsetup.sh命令的時候,可以在shell上看到下面的資訊:

including vendor/farsight/vendorsetup.sh