当前位置:操作系统 > 安卓/Android >>

Android编译过程详解(三)

前面两节讲解了自定义Android编译项和创建Product产品配置文件,除了编译和定义产品相关环境变量外,还需要定义Board相关环境变量。

1. build/core/config.mk


[plain] <pre name="code" class="plain">109 # ---------------------------------------------------------------   
110 # Define most of the global variables.  These are the ones that   
111 # are specific to the user's build configuration.   
112 include $(BUILD_SYSTEM)/envsetup.mk   
113    
114 # Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)   
115 # or under vendor/*/$(TARGET_DEVICE).  Search in both places, but   
116 # make sure only one exists.   
117 # Real boards should always be associated with an OEM vendor.   
118 board_config_mk := \   
119     $(strip $(wildcard \   
120         $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \   
121         vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \   
122     ))   
123 ifeq ($(board_config_mk),)   
124   $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE))   
125 endif   
126 ifneq ($(words $(board_config_mk)),1)   
127   $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk))   
128 endif   
129 include $(board_config_mk)   
130 TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk)))   
131 board_config_mk :=   
<pre name="code" class="plain">109 # --------------------------------------------------------------- 
110 # Define most of the global variables.  These are the ones that 
111 # are specific to the user's build configuration. 
112 include $(BUILD_SYSTEM)/envsetup.mk 
113  
114 # Boards may be defined under $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE) 
115 # or under vendor/*/$(TARGET_DEVICE).  Search in both places, but 
116 # make sure only one exists. 
117 # Real boards should always be associated with an OEM vendor. 
118 board_config_mk := \ 
119     $(strip $(wildcard \ 
120         $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \ 
121         vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \ 
122     )) 
123 ifeq ($(board_config_mk),) 
124   $(error No config file found for TARGET_DEVICE $(TARGET_DEVICE)) 
125 endif 
126 ifneq ($(words $(board_config_mk)),1) 
127   $(error Multiple board config files for TARGET_DEVICE $(TARGET_DEVICE): $(board_config_mk)) 
128 endif 
129 include $(board_config_mk) 
130 TARGET_DEVICE_DIR := $(patsubst %/,%,$(dir $(board_config_mk))) 
131 board_config_mk :=  

上述代码在上一节已经见到过,只是分析了112行的envsetup.mk,根据上一节内容可知,envsetup.mk设置了很多OUT变量,最终在build/core/product_config.mk文件里,设置了TARGET_DEVICE = fs100。

我们从114行继续分析。

从114~117行解释大意可知:

    Board相关配置文件会存在于$(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/或vendor/*/$(TARGET_DEVICE)/目录中,一个Vendor厂商只能有一个对应的Board配置文件。

118行定义board_config_mk变量:

    $(wildcard xxx)函数就是找到与xxx的匹配项放到空格列表里,前面定义TARGET_DEVICE变量 = fs100,所以$(SRC_TARGET_DIR)/board/fs100/BoardConfig.mk不存在,必须要存在vendor/*/fs100/BoardConfig.mk文件来定义开发板配置信息。

129行,通过include将vendor/*/fs100/BoardConfig.mk包含进来,

130行,TARGET_DEVICE_DIR为board_config_mk的路径,即:vendor/*/fs100

总结:

   一个vendor厂商必须要有一个对应的Board配置文件,即:vendor/*/fs100/BoardConfig.mk

    定义了TARGET_DEVICE_DIR变量,为board_config_mk的路径,即:vendor/*/fs100

指定board 相关特性,一定要包含:
TARGET_CPU_ABI := armeabi/...
其他属性参见其他board样例.(build/target/board/XXX

 

2.  build/core/main.mk


[plain] 141 # Bring in standard build system definitions. 
142 include $(BUILD_SYSTEM)/definitions.mk 
... 
347 ifeq ($(SDK_ONLY),true) 
348  
349 # ----- SDK for Windows ------ 
350 # These configure the build targets that are available for the SDK under Cygwin. 
351 # The first section defines all the C/C++ tools that can be compiled under Cygwin, 
352 # the second section defines all the Java ones (assuming javac is available.) 
353  
354 subdirs := \ 
355     prebuilt \ 
356     build/libs/host \ 
357     build/tools/zipalign \ 
... 
382 # The following can only be built if "javac" is available. 
383 # This check is used when building parts of the SDK under Cygwin. 
384 ifneq (,$(shell which javac 2>/dev/null)) 
385 $(warning sdk-only: javac available.) 
386 subdirs += \ 
387     build/tools/signapk \ 
388     dalvik/dx \ 
389     dalvik/libcore \ 
... 
414 else    # !SDK_ONLY 
415 ifeq ($(BUILD_TINY_ANDROID), true) 
416  
417 # TINY_ANDROID is a super-minimal build configuration, handy for board  
418 # bringup and very low level debugging 
419  
420 subdirs := \ 
421     bionic \ 
422     system/core \ 
423     build/libs \ 
424     build/target \ 
... 
433 else    # !BUILD_TINY_ANDROID 
434  
435 # 
436 # Typical build; include any Android.mk files we can find. 
437 # 
438 subdirs := $(TOP) 
439  
440 FULL_BUILD := true 
441  
442 endif   # !BUILD_TINY_ANDROID 
443  
444 endif   # !SDK_ONLY 
... 
464 # 
465 # Include all of the makefiles in the system 
466 # 
467  
468 # Can't use first-makefiles-under here because 
469 # --mindepth=2 makes the prunes not work. 
470 subdir_makefiles := \ 
471     $(shell build/tools/findleaves.py --prune=out --prune=.repo --prune=.git $(subdirs) Android.mk) 
472  
473 include $(subdir_makefiles) 
141 # Bring in standard build system definitions.
142 include $(BUILD_SYSTEM)/definitions.mk
...
347 ifeq ($(SDK_ONLY),true)
348
349 # ----- SDK for Windows ------
350 # These configure the build targets that are available for the SDK under Cygwin.
351 # The first section defines all the C/C++ tools that can be compiled under Cygwin,
352 # the second section defines all the Java ones (assu

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,