以下是加载命令和选择平台编译选项,也就是设置编译环境变量。
一、/build/envsetup.sh之初始化...... add_lunch_combo full-eng add_lunch_combo full_x86-eng add_lunch_combo vbox_x86-eng #模拟器 ...... # Execute the contents of any vendorsetup.sh files we can find. for f in `/bin/ls vendor/*/vendorsetup.sh vendor/*/*/vendorsetup.sh device/*/*/vendorsetup.sh 2> /dev/null` do echo "including $f" . $f done unset f #遍历/vendor/*/vendorsetup.sh、/vendor/*/*/vendorsetup.sh和/device/*/*/vendorsetup.sh文件; #eg:/device/tank/tanka3/vendorsetup.sh add_lunch_combo full_tanka3-userdebug
二、/build/envsetup.sh之add_lunch_combo命令
function add_lunch_combo(){ local new_combo=$1 local c for c in ${LUNCH_MENU_CHOICES[@]} ; do if [ "$new_combo" = "$c" ] ; then return fi done LUNCH_MENU_CHOICES=(${LUNCH_MENU_CHOICES[@]} $new_combo) }三、/build/envsetup.sh之lunch命令
function lunch(){ ...... check_product $product #从上处剥离$product == full_tanka3 ...... } function check_product(){ ...... CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ TARGET_PRODUCT=$1 \ TARGET_BUILD_VARIANT= \ TARGET_BUILD_TYPE= \ TARGET_BUILD_APPS= \ get_build_var TARGET_DEVICE > /dev/null ...... } function get_build_var(){ ...... CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core \ make --no-print-directory -C "$T" -f build/core/config.mk dumpvar-$1 }
四、/build/core/config.mk
...... include $(BUILD_SYSTEM)/envsetup.mk ...... board_config_mk := \ $(strip $(wildcard \ $(SRC_TARGET_DIR)/board/$(TARGET_DEVICE)/BoardConfig.mk \ device/*/$(TARGET_DEVICE)/BoardConfig.mk \ vendor/*/$(TARGET_DEVICE)/BoardConfig.mk \ )) #查找/device/tank/tanka3/BoardConfig.mk #模拟器查找/build/target/board/emulator/BoardConfig.mk ......
五、/build/core/envsetup.mk
...... include $(BUILD_SYSTEM)/product_config.mk ...... ifeq ($(TARGET_ARCH),) TARGET_ARCH := arm endif ......
六、/build/core/product_config.mk
...... include $(BUILD_SYSTEM)/product.mk ......
七、/build/core/product.mk
...... define _find-android-products-files $(shell test -d device && find device -maxdepth 6 -name AndroidProducts.mk) \ $(shell test -d vendor && find vendor -maxdepth 6 -name AndroidProducts.mk) \ $(SRC_TARGET_DIR)/product/AndroidProducts.mk endef ...... #查找/device/tank/tanka3/AndroidProducts.mk #模拟器查找/build/target/product/AndroidProducts.mk
以上执行完后,后设置如下环境变量:
PLATFORM_VERSION_CODENAME=REL PLATFORM_VERSION=4.0.3 TARGET_PRODUCT=full_tanka3 TARGET_BUILD_VARIANT=userdebug TARGET_BUILD_TYPE=release TARGET_BUILD_APPS= TARGET_ARCH=arm TARGET_ARCH_VARIANT=armv7-a-neon HOST_ARCH=x86 HOST_OS=linux HOST_BUILD_TYPE=release BUILD_ID=IML74K====================================================================================================================================
以下是真正开始编译:
一、/Makefile
include build/core/main.mk
二、/build/core/main.mk
...... include $(BUILD_SYSTEM)/config.mk ......
三、/build/core/config.mk
后边与上面《四-七》一一对应。定制自己厂商目录:
一、mkdir /device/tank
二、mkdir /device/tank/tanka3
三、cd /device/tank/tanka3
touch vendorsetup.sh touch BoardConfig.mk touch AndroidProducts.mk //包含full_tanka3.mk touch full_tanka3.mk //包含device.mk touch device.mk
====================================================================================================================================
补充:
在BoardConfig.mk文件中可以设置对象CPU架构、类型以及交叉编译工具链路径,如:
TARGET_ARCH=mips #架构,若不设置、由/build/core/envsetup.mk默认设置arm TARGET_ARCH_VARIANT := mips32r2-fp #核类型,若不设置、由/build/core/combo/TARGET_linux-arm.mk默认设置armv5te TARGET_ARCH_VERSION=mips32 TARGET_TOOLS_PREFIX := #交叉编译工具链,若不设置、由build/core/combo/TARGET_linux-arm.mk默认设置 #TARGET_TOOLS_PREFIX := prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.4.3/bin/arm-
其他主要文件或目录:
build/core/combo/TARGET_linux-arm.mk
//决定arm架构的具体类型(如果TARGET_ARCH_VARIANT未定义)以及交叉编译工具链路径
...... ifeq ($(strip $(TARGET_ARCH_VARIANT)),) TARGET_ARCH_VARIANT := armv5te endif ...... ifeq ($(strip $(TARGET_TOOLS_PREFIX)),) TARGET_TOOLS_PREFIX := prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.4.3/bin/arm-eabi- endif ......
build/core/combo/arch/arm/
bionic/libc/arch-arm/
bionic/libm/Android.mk
bionic/linker/Android.mk
arm架构交叉编译工具链路径:
prebuilt/ndk/android-ndk-r4/platforms/android-8/arch-arm/