涉及的内容:svn服务器的使用
android的编译系统,原理,工具链,辅助工具,参数等,环境变量,怎样单独添加编译一个单独的模块等。
android的编译结果:文件系统分析文件系统的使用,启动流程设置模块流程分析
============================
====================================================1.Android编译系统分析编译脚本及系统变量
build/envsetup.sh脚本分析
在编译源代码之前通常需要在android源代码顶层目录执行../build/envsetup.sh目的是为了使用
脚本envsetup.sh里面定义了一些函数:functionhelp()
functionget_abs_build_var()functionget_build_var()functioncheck_product()functioncheck_variant()functionsetpaths()functionprintconfig()
functionset_stuff_for_environment()functionset_sequence_number()functionsettitle()functionchoosetype()functionchooseproduct()functionchoosevariant()functiontapas()
functionchoosecombo()functionprint_lunch_menu()functionlunch()functiongettopfunctionm()
functionfindmakefile()functionmm()functionmmm()functioncroot()functionpid()
functiongdbclient()functionjgrep()functioncgrep()functionresgrep()functiongetprebuiltfunctiontracedmdump()functionrunhat()
functiongetbugreports()functionstartviewserver()functionstopviewserver()
functionisviewserverstarted()functionsmoketest()functionruntest()functionruntest_py()functiongodir()
choosecombo命令分析:functionchoosecombo(){
choosesim$1echoecho
choosetype$2
echoecho
chooseproduct$3echoecho
choosevariant$4echo
set_stuff_for_environmentprintconfig
}
会依次进行如下选择:
Buildforthesimulatororthedevice?
1.Device2.Simulator
Whichwouldyoulike?[1]Buildtypechoicesare:
1.release2.debug
Whichwouldyoulike?[1]
Productchoicesare:
1.emulator2.generic3.sim4.littleton
Youcanalsotypethenameofaproductifyouknowit.Whichwouldyoulike?[littleton]Variantchoicesare:
1.user
2.userdebug3.eng
Whichwouldyoulike?[eng]user默认选择以后会出现:
TARGET_PRODUCT=littletonTARGET_BUILD_VARIANT=user
TARGET_SIMULATOR=falseTARGET_BUILD_TYPE=releaseTARGET_ARCH=armHOST_ARCH=x86HOST_OS=linux
HOST_BUILD_TYPE=releaseBUILD_ID=
==========
functionchooseproduct()函数分析:
choices=(`/bin/lsbuild/target/board/*/BoardConfig.mkvendor/*/*/BoardConfig.mk2>/dev/null`)读取build/target/board/*目录下的板配置文件:BoardConfig.mk读取vendor/*/*/目录下的板配置文件:BoardConfig.mkchoices的值为:
build/target/board/emulator/BoardConfig.mkbuild/target/board/generic/BoardConfig.mkbuild/target/board/sim/BoardConfig.mkvendor/marvell/littleton/BoardConfig.mk经过:
forchoicein${choices[@]}do
#Theproductnameisthenameofthedirectorycontaining#themakefilewefound,above.
prodlist=(${prodlist[@]}`dirname${choice}|xargsbasename`)done
的处理,prodlist的值为:emulatorgenericsimlittleton所以选择菜单为:Productchoicesare:
1.emulator2.generic3.sim4.littleton
如果选择4,那么TARGET_PRODUCT被赋值为:littleton。
board_config_mk:=\\$(strip$(wildcard\\
$(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk\\vendor/*/$(TARGET_DEVICE)/BoardConfig.mk\\))
怎样添加一个模块
LOCAL_PATH:=$(callmy-dir)#编译静态库
include$(CLEAR_VARS)LOCAL_MODULE=libhellos
LOCAL_CFLAGS=$(L_CFLAGS)LOCAL_SRC_FILES=hellos.c
LOCAL_C_INCLUDES=$(INCLUDES)LOCAL_SHARED_LIBRARIES:=libcutils
LOCAL_COPY_HEADERS_TO:=libhellosLOCAL_COPY_HEADERS:=hellos.hinclude$(BUILD_STATIC_LIBRARY)#编译动态库
include$(CLEAR_VARS)LOCAL_MODULE=libhellod
LOCAL_CFLAGS=$(L_CFLAGS)LOCAL_SRC_FILES=hellod.c
LOCAL_C_INCLUDES=$(INCLUDES)LOCAL_SHARED_LIBRARIES:=libcutilsLOCAL_COPY_HEADERS_TO:=libhellodLOCAL_COPY_HEADERS:=hellod.hinclude$(BUILD_SHARED_LIBRARY)BUILD_TEST=true
ifeq($(BUILD_TEST),true)#使用静态库
include$(CLEAR_VARS)LOCAL_MODULE:=hellos
LOCAL_STATIC_LIBRARIES:=libhellosLOCAL_SHARED_LIBRARIES:=LOCAL_LDLIBS+=-ldl
LOCAL_CFLAGS:=$(L_CFLAGS)LOCAL_SRC_FILES:=mains.c
LOCAL_C_INCLUDES:=$(INCLUDES)include$(BUILD_EXECUTABLE)
#使用动态库
include$(CLEAR_VARS)LOCAL_MODULE:=hellod
LOCAL_MODULE_TAGS:=debug
LOCAL_SHARED_LIBRARIES:=libclibcutilslibhellodLOCAL_LDLIBS+=-ldl
LOCAL_CFLAGS:=$(L_CFLAGS)LOCAL_SRC_FILES:=maind.c
LOCAL_C_INCLUDES:=$(INCLUDES)include$(BUILD_EXECUTABLE)
endif#ifeq($(WPA_BUILD_SUPPLICANT),true)########################
#local_target_dir:=$(TARGET_OUT)/etc/wifi#include$(CLEAR_VARS)
#LOCAL_MODULE:=wpa_supplicant.conf#LOCAL_MODULE_TAGS:=user#LOCAL_MODULE_CLASS:=ETC
#LOCAL_MODULE_PATH:=$(local_target_dir)#LOCAL_SRC_FILES:=$(LOCAL_MODULE)#include$(BUILD_PREBUILT)########################系统变量解析
LOCAL_MODULE-编译的目标对象
LOCAL_SRC_FILES-编译的源文件
LOCAL_C_INCLUDES-需要包含的头文件目录
LOCAL_SHARED_LIBRARIES-链接时需要的外部库LOCAL_PRELINK_MODULE-是否需要prelink处理BUILD_SHARED_LIBRARY-指明要编译成动态库
LOCAL_PATH-编译时的目录
$(call目录,目录….)目录引入操作符
如该目录下有个文件夹名称src,则可以这样写$(callsrc),那么就会得到src目录的完整路径
include$(CLEAR_VARS)-清除之前的一些系统变量CLEAR_VARS:=$(BUILD_SYSTEM)/clear_vars.mk
在build/core/config.mk定义CLEAR_VARS:=$(BUILD_SYSTEM)/clear_vars.mk
通过include包含自定义的.mk文件(即是自定义编译规则)或是引用系统其他的.mk文件(系统定义的编译规则)。
LOCAL_SRC_FILES-编译的源文件
可以是.c,.cpp,.java,.S(汇编文件)或是.aidl等格式
不同的文件用空格隔开。如果编译目录子目录,采用相对路径,如子目录/文件名。也可以通过$(call目录),指明编译某目录
下所有.c/.cpp/.java/.S/.aidl文件.追加文件LOCAL_SRC_FILES+=文件
LOCAL_C_INCLUDES-需要包含的头文件目录
可以是系统定义路径,也可以是相对路径.如该编译目录下有个include目录,写法是include/*.h
LOCAL_SHARED_LIBRARIES-链接时需要的外部共享库LOCAL_STATIC_LIBRARIES-链接时需要的外部外部静态LOCAL_JAVA_LIBRARIES加入jar包LOCAL_MODULE-编译的目标对象
module是指系统的nativecode,通常针对c,c++代码./system/core/sh/Android.mk:32:LOCAL_MODULE:=sh
./system/core/libcutils/Android.mk:71:LOCAL_MODULE:=libcutils./system/core/cpio/Android.mk:9:LOCAL_MODULE:=mkbootfs
./system/core/mkbootimg/Android.mk:8:LOCAL_MODULE:=mkbootimg./system/core/toolbox/Android.mk:61:LOCAL_MODULE:=toolbox./system/core/logcat/Android.mk:10:LOCAL_MODULE:=logcat./system/core/adb/Android.mk:65:LOCAL_MODULE:=adb./system/core/adb/Android.mk:125:LOCAL_MODULE:=adbd./system/core/init/Android.mk:20:LOCAL_MODULE:=init./system/core/vold/Android.mk:24:LOCAL_MODULE:=vold
./system/core/mountd/Android.mk:13:LOCAL_MODULE:=mountd
LOCAL_PACKAGE_NAME
Java应用程序的名字用该变量定义
./packages/apps/Music/Android.mk:9:LOCAL_PACKAGE_NAME:=Music
./packages/apps/Browser/Android.mk:14:LOCAL_PACKAGE_NAME:=Browser