Android compilation system Details (i)

Source: Internet
Author: User
<span id="Label3"></p><p><p>++++++++++++++++++++++++++++++++++++++++++</p></p><p><p>This article is the original site, Welcome to reprint! Reprint Please specify the Source:</p></p><p><p>http://blog.csdn.net/mr_raptor/article/details/7539978</p></p><p><p>++++++++++++++++++++++++++++++++++++++++++</p></p><p><p>Android compilation system detailed (a): http://blog.csdn.net/mr_raptor/article/details/7539978</p></p><p><p>Android compilation system detailed (ii): http://blog.csdn.net/mr_raptor/article/details/7540066</p></p><p><p>Android compilation system detailed (c): http://blog.csdn.net/mr_raptor/article/details/7540730</p></p><p><p></p></p><p><p>The advantage of Android is that its open source, mobile phone and tablet manufacturers can customize their own mobile phone products according to their own hardware, such as xiaomi, lephone,m9, etc., so, When we are on the Android source customization, it is necessary to understand the next, the Android compilation Process.</p></p><p><p>If you have never compiled Android code, then the most official compilation process is to check the Android website: http://source.android.com/source/building.html</p></p><p><p>But Here's just a way to tell you how to compile a generic system that doesn't tell you the details, and we follow the build process to understand it.</p></p><p><p>+-------------------------------------------------------------------------------------------------------------- ------+</p></p><p><p><strong>This article uses Android version 2.1, using the Development Board for the Huaqing Vision development of the fs_s5pc100 A8 development Board.</strong></p></p><p><p><strong>+-------------------------------------------------------------------------------------------------------------- ------+</strong></p></p><p><p></p></p><p><p>Follow the steps given by Google to compile the following:</p></p><p><p>1> Source build/envsetup.sh: Load command</p></p><p><p>2> Lunch: Choose Platform Compilation options</p></p><p><p>3> make: Perform compilation</p></p><p><p>We follow the compilation steps to analyze the details of the compilation process and finally add the compilation options for our own platform Product.</p></p><p><p><br><strong>1. Source build/envsetup.sh</strong></p></p><p><p>This command is used to load all the commands in the envsetup.sh into the environment variable, so let's analyze it.</p></p><p><p>The main commands in envsetup.sh are as Follows:</p></p><pre><span style="color: #000000;"><span style="color: #000000;">function Help () # Display helper information function Get_abs_build_var () # get absolute variable function Get_build_var () # get absolute variable function check_product () # check productfunction check_variant () # check variable function setpath S () # Set file path function printconfig () # Print config function set_stuff_for_environment () # SET environment variable F               Unction set_sequence_number () # Set ordinal function Settitle () # Set caption function Choosetype () # set Typefunction chooseproduct () # set productfunction choosevariant () # set Variantfunction tapas () # function with choosecombofunction Choosecombo () # Set compilation parameters function Add_lunch_combo () #                   Add Lunch Item function Print_lunch_menu () # print lunch list function Lunch () # config lunchfunction m () #</span> make</span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> from</span><span style="color: #000000;"><span style="color: #000000;">topfunction findmakefile () # Find makefilefunction mm () #</span> make</span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> from</span><span style="color: #000000;">current <span style="color: #000000;">directoryfunction mmm () # make the supplied directoriesfunction Croot () # back To the root directory function cproj () function pid () function systemstack () function gdbclient () function Jgrep () # find Java file fun ction Cgrep () # Find C</span></span>/<span style="color: #000000;"><span style="color: #000000;">CPP file function resgrep () function tracedmdump () function runhat () function getbugreports () function startviewserver (                 ) function Stopviewserver () function isviewserverstarted () function smoketest () function runtest () function Godir () # skip to the specified directory</span></span><span style="color: #800080;"><span style="color: #800080;">405</span></span><span style="color: #000000;"><span style="color: #000000;"># Add_lunch_combo function is called multiple times, that is it to add Android compilation option # Clear</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">Variable. It</span> 'll be built up again when the vendorsetup.sh</span><span style="color: #800080;"><span style="color: #800080;">406</span></span># files is included at the end of<span style="color: #0000ff;"><span style="color: #0000ff;"></span> this</span><span style="color: #000000;"><span style="color: #000000;">file. # Empty lunch_menu_choices variable to save compilation options</span></span><span style="color: #800080;"><span style="color: #800080;">407</span></span><span style="color: #000000;"><span style="color: #000000;">unset lunch_menu_choices</span></span><span style="color: #800080;"><span style="color: #800080;">408</span></span><span style="color: #000000;"><span style="color: #000000;">function Add_lunch_combo ()</span></span><span style="color: #800080;"><span style="color: #800080;">409</span></span><span style="color: #000000;"><span style="color: #000000;"> { </span></span><span style="color: #800080;"><span style="color: #800080;">410</span></span>Local new_combo=$<span style="color: #800080;"><span style="color: #800080;">1</span></span><span style="color: #000000;"><span style="color: #000000;"># Get parameters when Add_lunch_combo is called</span></span><span style="color: #800080;"><span style="color: #800080;">411</span></span><span style="color: #000000;"><span style="color: #000000;">Local C # iterates through the values in lunch_menu_choices, in fact, when the function is first called, the value is empty</span></span><span style="color: #800080;"><span style="color: #800080;">412</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>C<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span>${lunch_menu_choices[@]};<span style="color: #0000ff;"><span style="color: #0000ff;"></span> do</span> <span style="color: #800080;"><span style="color: #800080;">413</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>[<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">$new _combo</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>=<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">$c</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;"> ] ; Then # if the value in the argument already exists in the Lunch_menu_choices variable, return</span></span><span style="color: #800080;"><span style="color: #800080;">414</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span> <span style="color: #800080;"><span style="color: #800080;">415</span></span><span style="color: #000000;"><span style="color: #000000;">fi</span></span><span style="color: #800080;"><span style="color: #800080;">416</span></span><span style="color: #000000;">done <span style="color: #000000;"># If the value of the parameter does not exist, it is added to the lunch_menu_choices variable</span></span><span style="color: #800080;"><span style="color: #800080;">417</span></span>lunch_menu_choices=<span style="color: #000000;"><span style="color: #000000;">(${lunch_menu_choices[@]} $new _combo)</span></span><span style="color: #800080;"><span style="color: #800080;">418</span></span><span style="color: #000000;"><span style="color: #000000;">}# This is the system automatically adds a default compiler entry generic</span></span>-<span style="color: #000000;"><span style="color: #000000;">Eng</span></span><span style="color: #800080;"><span style="color: #800080;">420</span></span># Add the<span style="color: #0000ff;"><span style="color: #0000ff;">default</span></span><span style="color: #000000;"><span style="color: #000000;"></span> one Here</span><span style="color: #800080;"><span style="color: #800080;">421</span></span>Add_lunch_combo Generic-eng # calls the above Add_lunch_combo function, which will generic-<span style="color: #000000;"><span style="color: #000000;">Eng passes past as a parameter</span></span><span style="color: #800080;"><span style="color: #800080;">422</span></span> <span style="color: #800080;"><span style="color: #800080;">423</span></span>#<span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>We<span style="color: #800000;"><span style="color: #800000;">'</span></span><span style="color: #800000;"><span style="color: #800000;">re on linux, add the Simulator. There is a special</span> case</span> <span style="color: #800080;"><span style="color: #800080;">424</span></span>#<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span><span style="color: #000000;"><span style="color: #000000;">Lunch to deal</span> with the simulator</span><span style="color: #800080;"><span style="color: #800080;">425</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>[<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">$ (uname)</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span>=<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">Linux</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #000000;"><span style="color: #000000;"> ] ; </span>then</span><span style="color: #800080;"><span style="color: #800080;">426</span></span><span style="color: #000000;"><span style="color: #000000;">Add_lunch_combo Simulator</span></span><span style="color: #800080;"><span style="color: #800080;">427</span></span><span style="color: #000000;"><span style="color: #000000;">fi# The following code is important, it wants to find the vendorsetup.sh file from the vendor directory, and if it does, load it</span></span><span style="color: #800080;"><span style="color: #800080;">1037</span></span><span style="color: #000000;"><span style="color: #000000;"># Execute The contents of any vendorsetup.sh files we can find.</span></span><span style="color: #800080;"><span style="color: #800080;">1038</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> for</span>F<span style="color: #0000ff;"><span style="color: #0000ff;">inch</span></span>'/bin/ls Vendor<span style="color: #008000;"><span style="color: #008000;">/*</span></span><span style="color: #008000;"><span style="color: #008000;">/vendorsetup.sh vendor/</span></span><span style="color: #008000;"><span style="color: #008000;">*/</span></span>build/vendorsetup.sh<span style="color: #800080;"><span style="color: #800080;">2</span></span>>/dev/<span style="color: #0000ff;"><span style="color: #0000ff;">NULL</span></span><span style="color: #000000;"><span style="color: #000000;">`</span></span><span style="color: #800080;"><span style="color: #800080;">1039</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"></span> do</span><span style="color: #800080;"><span style="color: #800080;">1040</span></span>Echo<span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800000;"><span style="color: #800000;">including $f</span></span><span style="color: #800000;"><span style="color: #800000;">"</span></span><span style="color: #800080;"><span style="color: #800080;">1041</span></span><span style="color: #000000;"><span style="color: #000000;">. $f # Execute the found script, which is actually the Manufacturer's own definition of the compilation options</span></span><span style="color: #800080;"><span style="color: #800080;">1042</span></span><span style="color: #000000;"><span style="color: #000000;"></span> done</span><span style="color: #800080;"><span style="color: #800080;">1043</span></span>Unset F<span style="background-color: #ffffff; font-family: verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.5;"><span style="background-color: #ffffff; font-family: verdana, Arial, Helvetica, sans-serif; font-size: 14px; line-height: 1.5;"> </span></span></pre><p><p>The main functions of envsetup.sh are as Follows:</p></p> <ol> <ol> <li>The function commands used at compile time are loaded, such as: help,lunch,m,mm,mmm, etc.</li> <li>Added two compilation options: Generic-eng and simulator, both of which are system default options</li> <li>Find the Vendor/<-vendor directory >/and vendor/< Vendor directory >/build/directory vendorsetup.sh, if present, load execute it, Add the manufacturer to define the Product's own compilation options</li> </ol> </ol>In fact, the above 3rd is to the compiler system to add the Manufacturer's own definition of the product compiler options, the code is: Add_lunch_combo xxx-xxx.<p><p></p></p><p><p>According to the above content, can be measured, if you want to define their own platform product compilation, The simple way is directly in the envsetup.sh last add Add_lunch_combo myproduct-eng, of course, do not conform to the above code last intention, We're still honest. Create your company name in the vendor directory, then create a new vendorsetup.sh in the company directory and add your own product compilation</p></p><p><p></p></p><strong><strong>[plain]</strong></strong>View Plaincopy <ol start="1"> <ol start="1"> <li class="alt">#mkdir vendor/farsight/</li> <li>#touch vendor/farsight/vendorsetup.sh</li> <li class="alt">#echo "add_lunch_combo fs100-eng" > vendor/farsight/vendorsetup.sh</li> </ol> </ol><p><p>thus, when we execute the source build/envsetup.sh command, we can see the following message on the Shell:</p></p><p><p></p></p><p><p></p></p><strong><strong>[plain]</strong></strong>View Plaincopy <ol start="1"> <ol start="1"> <li class="alt">including vendor/farsight/vendorsetup.sh</li> </ol> </ol><p><p><br><strong>2. Follow the steps on the Android website to start executing lunch Full-eng</strong></p></p><p><p></p></p><p><p>Of course if you follow the above command, it compiles the general Eng version of the system, not our custom system, we can execute the lunch command, it will print out a selection menu, listing the available compilation options</p></p><p><p>If you have added vendorsetup.sh in the first step, your options will appear as Follows:</p></p><p><p></p></p><strong><strong>[plain]</strong></strong>View Plaincopy <ol start="1"> <ol start="1"> <li class="alt">You ' re building on Linux</li> <li></li> <li class="alt">Generic-eng Simulator Fs100-eng</li> <li>Lunch menu ... pick a combo:</li> <li class="alt">1. Generic-eng</li> <li>2. simulator</li> <li class="alt">3. Fs100-eng</li> </ol> </ol><p><p>The 3rd item is the compiled item we added Ourselves.</p></p><p><p></p></p><p><p>The lunch command is a command defined in envsetup.sh that allows the user to select a compilation item to define the global variables used in the product and compilation Process.</p></p><p><p>We have not explained what the previous Fs100-eng mean, now to illustrate, fs100 is the name of the product I define, Eng is the product of the compilation type, in addition to eng, there are user, userdebug, respectively, said:</p></p><p><p>Eng: Engineering machine,</p></p><p><p>User: End user Machine</p></p><p><p>Userdebug: Commissioning Test machine</p></p><p><p>Tests: test Machine</p></p><p><p>thus, in addition to Eng and user, the other two generally can not be handed over to the end user, remember when the M8 out, first released a part of Eng engineering machine, and then out of the user machine, you can use the engineering Machine.</p></p><p><p>So what are these four types for? In fact, in the main.mk, in the Android source code, each target (can also be seen as a Project) directory has a android.mk makefile, each target android.mk has a type declaration: local_module_tags , this tags is used to specify, the current target compiled in which category Belongs.</p></p><p><p>PS:Android.mk and Linux in the makefile is not the same, it is the Android compiler system of its own definition of a makefile to facilitate the compilation Of: c,c++ dynamic, static library or executable program, or Java library or Android program,</p></p><p><p>All right, Let's analyze what the lunch command did.</p></p><p><p>function Lunch ()<br>{<br>Local answer</p></p><p><p># Lunch the case with parameters directly behind it, the compiled item is the specified Parameter: $</p></p><p><p>If ["$"]; Then<br><br>Answer=$1<br>Else<br># Lunch with no parameters, then call the Print_lunch_menu function, print all the target product and Variant menu to provide user selection<br>Print_lunch_menu<br>Echo-n "which Would you like? [generic-eng] "<br>Read Answer # reads user-selected results, Note that here can be a number, or the option content of a string<br>Fi</p></p><p><p>Local selection=</p></p><p><p># If the user does not enter anything in the menu (direct carriage return), then the system default Generic-eng compilation entry</p></p><p><p>If [-z "$answer"]<br>Then<br>Selection=generic-eng<br>Elif ["$answer" = "simulator"]<br>Then<br># If the user is entering an emulator: simulator<br>Selection=simulator</p></p><p><p># If answer is a number in the menu, get the number<br>Elif (echo-n $answer | grep-q-e "^[0-9][0-9]*$")<br>Then<br>If [$answer-le ${#LUNCH_MENU_CHOICES [@]}] # If the user enters a menu number that is not valid (more than the number of elements in the all options Array)</p></p><p><p># ${#LUNCH_MENU_CHOICES [@]} refers to the number of elements lunch_menu_choices this array, lunch_menu_choices[@] directs all elements in the array to return as a list<br>Then<br>selection=${lunch_menu_choices[$ (($answer-$_arrayoffset)]} #这儿通过 $answer-$_arrayoffset to refer to the array of numbers entered by the user Lunch_menu _choices in the compiler, where _arrayoffset this variable indicates whether the array subscript starts at 0, where the value is: 1<br>Fi<br># If the answer string matches the *-* pattern (the beginning end cannot be-)<br>Elif (echo-n $answer | grep-q-e "^[^\-][^\-]*-[^\-][^\-]*$")<br>Then<br>selection= $answer<br>Fi</p></p><p><p>#如果selection为空, Error Exiting</p></p><p><p>     if [-z ' $selection] <br>     then <br>          echo <br>         echo "Invalid lunch combo: $answer" <br>          return 1 <br>     fi </p></p><p><p>     # Special case the simulator <br>     if ["$selection" = "SIMULATOR"]&NBSP;&NBSP;&NB sp;    #如果用户选项为使用模拟器 <br>     then <br>          # Exports 4 Environment variables, These 4 environment variables compile the specified compilation system into an emulator <br>         export Target_product=sim                       #产品变量 <br>         export target_build_variant=eng           #版本型号变量 <br>         export target_ simulator=true                   #编译在模拟器中 <br>         export target_build_type=debug             #类型变量 <br>     Else </p></p><p><p># separate the product from the Product-variant pattern, and the SED command is to replace the string followed by The--that is, preserving only--the Previous content<br>Local product=$ (echo-n $selection | sed-e "s/-.*$//")</p></p><p><p># check it, call the relationship check_product ()->get_build_var ()->build/core/config.mk more verbose, don't expand<br>Check_product $product<br>If [$?-ne 0]<br>Then<br>Echo<br>Echo "* * Don ' t has a product spec for: ' $product '"<br>Echo "* * do" has the right repo manifest? "<br>product=<br>Fi</p></p><p><p># separate the variant from the Product-variant pattern, and the SED command replaces the previous content with an empty string<br>Local variant=$ (echo-n $selection | sed-e "s/^[^\-]*-//")</p></p><p><p># Check to see if it's within the scope of (user Userdebug Eng)<br>Check_variant $variant<br>If [$?-ne 0]<br>Then<br>Echo<br>Echo "* * Invalid variant: ' $variant '"<br>Echo "* * must be one of ${variant_choices[@]}"<br>Variant=<br>Fi</p></p><p><p>If [-z ' $product "-o-z" $variant "] #再次检查两个变量是否为空<br>Then<br>Echo<br>Return 1<br>Fi<br># Export 4 environment variables (as compared to the emulator above), it is important here, because the subsequent compilation system relies on a few variables defined here<br>Export target_product= $product<br>Export target_build_variant= $variant<br>Export Target_simulator=false<br>Export Target_build_type=release<br>Fi #!simulator</p></p><p><p>Echo</p></p><p><p># Set to Environment variables, more, no longer listed, The simplest method set >env.txt can be obtained<br>Set_stuff_for_environment<br># print Some major variables, call relationship Printconfig ()->get_build_var ()->build/core/config.mk->build/core/envsetup.mk more verbose, not expanded<br>Printconfig<br>}</p></p><p><p></p></p><p><p></p></p><p><p>From the above analysis, the lunch command can take parameters and no parameters, and finally export some important environment variables, thus affecting the compilation results of the compiled System. The exported variables are as follows (in the case of actual OPERATIONS)</p></p><p><p></p></p><p><p></p></p><strong><strong>[plain]</strong></strong>View Plaincopy <ol start="1"> <ol start="1"> <li class="alt">target_product=fs100</li> <li>Target_build_variant=eng</li> <li class="alt">Target_simulator=false</li> <li>Target_build_type=release</li> </ol> </ol><p><p></p></p><p><p>Execute the above two steps: make command, of course, if you follow the above two steps done, there will be a problem after the implementation, we have to do some other operations, the next chapter to Analyze.</p></p><p><p><br><br></p></p><p><p></p></p><p><p><br></p></p><p><p>Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p><p><p>Android compilation system Details (i)</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.