Android compilation detailed lunch command "go"

Source: Internet
Author: User

This article is reproduced from:

Android compilation detailed lunch command(2012-10-08 10:27:55) reproduced
Tags: it Category: Android kernel anatomy
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.

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

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.

+-------------------------------------------------------------------------------------------------+

This article uses Android version 2.1, using the Development Board for the Huaqing Vision development of the FS_S5PC100 A8 Development Board.

+-------------------------------------------------------------------------------------------------+

Follow the steps given by Google to compile the following:

1> source build/envsetup.sh: Load command

2> Lunch: Choose Platform compilation options

3> Make: Perform compilation

We follow the compilation steps to analyze the details of the compilation process and eventually add our own platform compilation options.

1. SOURCE build/envsetup.sh

This command is used to load all the commands in the envsetup.sh into the environment variable, so let's analyze it.

The main commands in envsetup.sh are as follows:



function Help () # Display assistance information
function Get_abs_build_var () # Get absolute variables
function Get_build_var () # Get absolute variables
function check_product () # Check Product
function check_variant () # Check variables
function setpaths () # Set file path
function Printconfig () # Print configuration
function set_stuff_for_environment () # Setting environment variables
function Set_sequence_number () # Set Ordinal
function Settitle () # Set Caption
function Choosetype () # Setting type
function chooseproduct () # Set Product
function Choosevariant () # Set variant
function tapas () # Functions with Choosecombo
function Choosecombo () # Set compilation parameters
function Add_lunch_combo () # Add Lunch Project
function Print_lunch_menu () # Print lunch list
function lunch () # config Lunch
function m () # Make from top
function Findmakefile () # Find Makefile
function mm () # Make from current directory
function mmm () # Make the supplied directories
function Croot () # Back to the root directory
function Cproj ()
function pid ()
function Systemstack ()
function Gdbclient ()
function Jgrep () # Find Java files
function Cgrep () # Find C/cpp file
function Resgrep ()
function Tracedmdump ()
function Runhat ()
function Getbugreports ()
function Startviewserver ()
function Stopviewserver ()
function isviewserverstarted ()
function SmokeTest ()
function Runtest ()
function Godir () # jumps to the specified directory 405

# Add_lunch_combo function is called multiple times, which is to add Android compilation options
# Clear this variable. It'll be built up again when the vendorsetup.sh
406 # files is included at the end of this file.
# Empty the Lunch_menu_choices variable for compilation options
407 unset lunch_menu_choices
408 function Add_lunch_combo ()
409 {
410 Local new_combo=$1 # gets parameters when Add_lunch_combo is called
411 Local C
# Loop through the value in lunch_menu_choices, in fact, when the function is first called, the value is empty
412 for C in ${lunch_menu_choices[@]}; Do
413 if ["$new _combo" = "$c"]; Then # if the value in the argument already exists in the lunch_menu_choices variable, return
414 return
415 fi
416 Done
# If the value of the parameter does not exist, it is added to the lunch_menu_choices variable
417 lunch_menu_choices= (${lunch_menu_choices[@]} $new _combo)
418}


# This is the system that automatically adds a default compiler entry Generic-eng
420 # Add the default one here
421 Add_lunch_combo Generic-eng # Call the above Add_lunch_combo function to pass Generic-eng as a parameter past
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

# The following code is important, it wants to find the vendorsetup.sh file from the vendor directory, and if it does, load it
1037 # Execute The contents of any vendorsetup.sh files we can find.
1038 for F in '/bin/ls vendorbuild/vendorsetup.sh 2>/dev/null '
1039 Do
1040 echo "including $f"
1041. $f # Execute the found script, which is actually the manufacturer's own definition of the compilation options
1042 Done
1043 Unset F

The main functions of envsetup.sh are as follows:

1. Load the function commands used at compile time, such as: help,lunch,m,mm,mmm, etc.
2. Added two compilation options: Generic-eng and Simulator, both of which are system default options
3. 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
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.

According to the above content, can be measured, if you want to define their own product compilation, the simple way is directly in the envsetup.sh Finally, 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


?
#mkdir vendor/farsight/
#touch vendor/farsight/vendorsetup.sh
#echo "Add_lunch_combo Fs100-eng" > vendor/farsight/vendorsetup.sh



Thus, when we execute the source build/envsetup.sh command, we can see the following message on the shell:


?
including vendor/farsight/vendorsetup.sh


2. Follow the steps on the Android website to start executing lunch Full-eng



Of course if you follow the above command, it compiles the general ENG version of the system, not our personality system, we can execute the lunch command, it will print a selection menu, listing the available compilation options

If you have added vendorsetup.sh in the first step, your options will appear as follows:

You ' re building on Linux

Generic-eng Simulator Fs100-eng
Lunch Menu ... pick a combo:
1. Generic-eng
2. Simulator
3. Fs100-eng



The 3rd item is the compiled item we added ourselves.



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.

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:

ENG: Engineering Machine,

User: End user machine

Userdebug: Commissioning test machine

Tests: Test machine

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.



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.



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,



All right, let's analyze what the lunch command did.



function Lunch ()
{
Local answer

If ["$"]; Then
# Lunch with parameters directly behind
Answer=$1
Else
# with no parameters behind lunch, all target product and Variant menus at print place provide user selection
Print_lunch_menu
Echo-n "which would you like? [Generic-eng] "
Read answer
Fi

Local selection=

If [-Z "$answer"]
Then
# If the user does not have a selection in the menu, enter directly, then the system default Generic-eng
Selection=generic-eng
elif ["$answer" = "simulator"]
Then
# if it's an emulator
Selection=simulator
Elif (echo-n $answer | grep-q-E "^[0-9][0-9]*$")
Then
# If answer is a number that selects a menu, gets the string corresponding to that number
If [$answer-le ${#LUNCH_MENU_CHOICES [@]}]
Then
selection=${lunch_menu_choices[$ (($answer-$_arrayoffset)]}
Fi
# If the answer string matches the *-* pattern (the beginning of * cannot be-)
Elif (echo-n $answer | grep-q-E "^[^\-][^\-]*-[^\-][^\-]*$")
Then
selection= $answer
Fi

If [-Z "$selection"]
Then
Echo
echo "Invalid Lunch Combo: $answer"
Return 1
Fi

# Special Case the simulator
If ["$selection" = "simulator"]
Then
# Simulator Mode
Export Target_product=sim
Export Target_build_variant=eng
Export Target_simulator=true
Export Target_build_type=debug
Else

# separate the product from the product-variant pattern
Local product=$ (echo-n $selection | sed-e "s/-.*$//")

# Check it, call the relationship check_product ()->get_build_var ()->build/core/config.mk more verbose, don't expand
Check_product $product
If [$?-ne 0]
Then
Echo
echo "* * Don ' t has a product spec for: ' $product '"
echo "* * do" has the right repo manifest? "
product=
Fi

# separate the variant from the product-variant pattern
Local variant=$ (echo-n $selection | sed-e "s/^[^\-]*-//")

# Check to see if it's within the scope of (User Userdebug Eng)
Check_variant $variant
If [$?-ne 0]
Then
Echo
echo "* * Invalid variant: ' $variant '"
echo "* * must be one of ${variant_choices[@]}"
Variant=
Fi

If [-z] $product "-o-z" $variant "]
Then
Echo
Return 1
Fi
# Export environment variables, it is important here, because the subsequent compilation system is dependent on a few variables defined here
Export target_product= $product
Export target_build_variant= $variant
Export Target_simulator=false
Export Target_build_type=release
Fi #!simulator

Echo

# Set to environment variables, more, no longer listed, the simplest method set >env.txt can be obtained
Set_stuff_for_environment
# Print Some major variables, call Relationship printconfig ()->get_build_var ()->build/core/config.mk->build/core/envsetup.mk more verbose, not expanded
Printconfig
}



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)



target_product=fs100
Target_build_variant=eng
Target_simulator=false
Target_build_type=release


After executing the two steps above, the execution: Make command, the next chapter to analyze.

Android compilation detailed lunch command "go"

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.