Android编译环境 相关

转载 2012年03月28日 18:07:32

1、  # make clean-helloworld
“make clean-$(LOCAL_MODULE)”是Android编译环境提供的make clean的方式。
Android编译环境提供了”showcommands”选项来显示编译命令行,我们可以通过打开这个选项来查看一些编译时的细节。

2、使用showcommands选项重新编译helloworld:
# make helloworld showcommands

build/core/product_config.mk:229: WARNING: adding test OTA key
target thumb C: helloworld <= development/hello/hello.c
prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -I system/core/include -I hardware/libhardware/include -I hardware/ril/include -I dalvik/libnativehelper/include -I frameworks/base/include -I external/skia/include -I out/target/product/generic/obj/include -I bionic/libc/arch-arm/include -I bionic/libc/include -I bionic/libstdc++/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -I bionic/libm/include -I bionic/libm/include/arch/arm -I bionic/libthread_db/include -I development/hello -I out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates -c -fno-exceptions -Wno-multichar -march=armv5te -mtune=xscale -msoft-float -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -include system/core/include/arch/linux-arm/AndroidConfig.h -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -DSK_RELEASE -DNDEBUG -O2 -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -MD -o out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/hello.o development/hello/hello.c
target Executable: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld)
prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-g++ -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib -lc -lstdc++ -lm out/target/product/generic/obj/lib/crtbegin_dynamic.o out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/hello.o -Wl,--no-undefined prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a out/target/product/generic/obj/lib/crtend_android.o
target Non-prelinked: helloworld (out/target/product/generic/symbols/system/bin/helloworld)
out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld out/target/product/generic/symbols/system/bin/helloworld
target Strip: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/helloworld)
out/host/linux-x86/bin/soslim --strip --shady --quiet out/target/product/generic/symbols/system/bin/helloworld --outfile out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/helloworld
Install: out/target/product/generic/system/bin/helloworld
out/host/linux-x86/bin/acp -fpt out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/helloworld out/target/product/generic/system/bin/helloworld 

从上面的命令行可以看到,Android编译环境所用的交叉编译工具链是prebuilt/linux-x86/toolchain /arm-eabi-4.2.1/bin/arm-eabi-gcc,-I和-L参数指定了所用的C库头文件和动态库文件路径分别是bionic /libc/include 和out/target/product/generic/obj/lib,其他还包括很多编译选项以及-D所定义的预编译宏。

我们可以利用上面的编译命令,稍加简化来手工编译helloworld程序。先手工删除上次编译得到的helloworld程序:
# rm out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/hello.o
# rm out/target/product/generic/system/bin/helloworld
再用gcc编译,生成目标文件:
# prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -I bionic/libc/arch-arm/include -I bionic/libc/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -c -fno-exceptions -Wno-multichar -march=armv5te -mtune=xscale -msoft-float -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -include system/core/include/arch/linux-arm/AndroidConfig.h -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -DSK_RELEASE -DNDEBUG -O2 -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -MD -o out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/hello.o development/hello/hello.c
与Android.mk编译参数比较,上面主要减少了不必要的-I参数。

接下来生成可执行文件:
# prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,nocopyreloc -o out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld -Lout/target/product/generic/obj/lib -Wl,-rpath-link=out/target/product/generic/obj/lib -lc -lm out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/hello.o out/target/product/generic/obj/lib/crtbegin_dynamic.o -Wl,--no-undefined ./prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/interwork/libgcc.a out/target/product/generic/obj/lib/crtend_android.o
这里值得留意的是参数“-Wl,-dynamic-linker,/system/bin/linker”,它指定了Android专用的动态链接器/system/bin/linker,而不是通常所用的ld.so。


3、生成的可执行程序可用file和readelf命令来查看一下:
# file out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld
out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

# readelf -d out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld |grep NEEDED
0x00000001 (NEEDED) Shared library: [libc.so]
0x00000001 (NEEDED) Shared library: [libm.so]
这是ARM格式的动态链接可执行文件,运行时需要libc.so和libm.so。“not stripped”表示它还没被STRIP。嵌入式系统中为节省空间通常将编译完成的可执行文件或动态库进行STRIP,即去掉其中多余的符号表信息。在 前面“make helloworld showcommands”命令的最后我们也可以看到,Android编译环境中使用了out/host/linux-x86/bin/soslim工具 进行STRIP。
有关Android Toolchain的其他一些内容可参考:Android Toolchain与Bionic Libc

4、由linux-arm.mk 开始分析 先看看注释部分(eclair)


1 # Configuration for Linux on ARM.
  2 # Included by combo/select.make
  3
  4 # You can set TARGET_ARCH_VARIANT to use an arch version other
  5 # than ARMv5TE. Each value should correspond to a file named
  6 # $(BUILD_COMBOS)/arch/<name>.mk which must contain
  7 # makefile variable definitions similar to the preprocessor
  8 # defines in system/core/include/arch/<combo>/AndroidConfig.h. Their
  9 # purpose is to allow module Android.mk files to selectively compile
 10 # different versions of code based upon the funtionality and
 11 # instructions available in a given architecture version.
 12 #
 13 # The blocks also define specific arch_variant_cflags, which
 14 # include defines, and compiler settings for the given architecture
 15 # version.
 16 #
 17 ifeq ($(strip $(TARGET_ARCH_VARIANT)),)
 18 TARGET_ARCH_VARIANT := armv5te
 19 endif
你可以通过设定TARGET_ARCH_VARIANT=yournane而不采用android默认使用的ARMv5TE指令集。你的yourname的值应该当和$(BUILD_COMBOS)/arch/<name>.mk中的name名称相同。

system/core/include/arch/linux-arm/AndroidConfig.h中定义了arm编译时的一些定义供C/C++程序引用,这些定义的目的是允许Android.mk 可以根据指定的硬件架构的功能和指令的不同可以有选择性进行编译。

20
 21 # TARGET_ARCH_VARIANT used to be called TARGET_ARCH_VERSION
 22 # to avoid any weirdness, issue an error message if the latter
 23 # is defined.
 24 #
 25 ifneq ($(strip $(TARGET_ARCH_VERSION)),)
 26 $(info Definition for TARGET_ARCH_VERSION encountered !)
 27 $(info This variable has been renamed TARGET_ARCH_VARIANT, please update your build files !!)
 28 $(error Aborting the build.)
 29 endif
 30
 31 TARGET_ARCH_SPECIFIC_MAKEFILE := $(BUILD_COMBOS)/arch/$(TARGET_ARCH)/$(TARGET_ARCH_VARIANT).mk
 32 ifeq ($(strip $(wildcard $(TARGET_ARCH_SPECIFIC_MAKEFILE))),)
 33 $(error Unknown ARM architecture version: $(TARGET_ARCH_VARIANT))
 34 endif
 35
 36 include $(TARGET_ARCH_SPECIFIC_MAKEFILE)

TARGET_ARCH_VARIANT 会被 TARGET_ARCH_VERSION调用, TARGET_ARCH_VERSION不能被直接声明,否则会报错。
根据 TARGET_ARCH_VARIANT的设置加载对应的build/core/combo/arch/arm/armv???.mk文件。

38 # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
 39 ifeq ($(strip $($(combo_target)TOOLS_PREFIX)),)
 40 $(combo_target)TOOLS_PREFIX := \
 41     prebuilt/$(HOST_PREBUILT_TAG)/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
 42 endif
 43
 44 $(combo_target)CC := $($(combo_target)TOOLS_PREFIX)gcc$(HOST_EXECUTABLE_SUFFIX)
 45 $(combo_target)CXX := $($(combo_target)TOOLS_PREFIX)g++$(HOST_EXECUTABLE_SUFFIX)
 46 $(combo_target)AR := $($(combo_target)TOOLS_PREFIX)ar$(HOST_EXECUTABLE_SUFFIX)
 47 $(combo_target)OBJCOPY := $($(combo_target)TOOLS_PREFIX)objcopy$(HOST_EXECUTABLE_SUFFIX)
 48 $(combo_target)LD := $($(combo_target)TOOLS_PREFIX)ld$(HOST_EXECUTABLE_SUFFIX)
 49
 50 $(combo_target)NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined
 51
 52 TARGET_arm_CFLAGS :=    -O2 \
 53                         -fomit-frame-pointer \
 54                         -fstrict-aliasing    \
 55                         -funswitch-loops     \
 56                         -finline-limit=300

如果你想采用自己的交叉编译器,可以通过设定TARGET_TOOLS_PREFIX来达到效果。否则android会采用自己的prebuild 的交叉编译器。


58 # Modules can choose to compile some source as thumb. As
59 # non-thumb enabled targets are supported, this is treated
60 # as a 'hint'. If thumb is not enabled, these files are just
61 # compiled as ARM.
62 ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
63 TARGET_thumb_CFLAGS := -mthumb \
64 -Os \
65 -fomit-frame-pointer \
66 -fno-strict-aliasing \
67 -finline-limit=64
68 else
69 TARGET_thumb_CFLAGS := $(TARGET_arm_CFLAGS)
70 endif

可以设定是有采用thumb来进行源码编译。

72 # Set FORCE_ARM_DEBUGGING to "true" in your buildspec.mk
 73 # or in your environment to force a full arm build, even for
 74 # files that are normally built as thumb; this can make
 75 # gdb debugging easier.  Don't forget to do a clean build.
 76 #
 77 # NOTE: if you try to build a -O0 build with thumb, several
 78 # of the libraries (libpv, libwebcore, libkjs) need to be built
 79 # with -mlong-calls.  When built at -O0, those libraries are
 80 # too big for a thumb "BL <label>" to go from one end to the other.
 81 ifeq ($(FORCE_ARM_DEBUGGING),true)
 82   TARGET_arm_CFLAGS += -fno-omit-frame-pointer -fno-strict-aliasing
 83   TARGET_thumb_CFLAGS += -marm -fno-omit-frame-pointer
 84 endif
 85
 86 android_config_h := $(call select-android-config-h,linux-arm)
 87 arch_include_dir := $(dir $(android_config_h))
 88
 89 $(combo_target)GLOBAL_CFLAGS += \
 90             -msoft-float -fpic \
 91             -ffunction-sections \
 92             -funwind-tables \
 93             -fstack-protector \
 94             -fno-short-enums \
 95             $(arch_variant_cflags) \
 96             -include $(android_config_h) \
 97             -I $(arch_include_dir)
 98
 99 $(combo_target)GLOBAL_LDFLAGS += \
100             $(arch_variant_ldflags)

在CFLAGS 上加载 system/core/include/linux-arm/AndroidConfig.h 文件 和 头文件的路径
在LDFLAGS 上记载库路径。



102 # We only need thumb interworking in cases where thumb support
103 # is available in the architecture, and just to be sure, (and
104 # since sometimes thumb-interwork appears to be default), we
105 # specifically disable when thumb support is unavailable.
106 ifeq ($(ARCH_ARM_HAVE_THUMB_SUPPORT),true)
107 $(combo_target)GLOBAL_CFLAGS += -mthumb-interwork
108 else
109 $(combo_target)GLOBAL_CFLAGS += -mno-thumb-interwork
110 endif
111
112 $(combo_target)GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
113
114 $(combo_target)RELEASE_CFLAGS := \
115 -DSK_RELEASE -DNDEBUG \
116 -g \
117 -Wstrict-aliasing=2 \
118 -finline-functions \
119 -fno-inline-functions-called-once \
120 -fgcse-after-reload \
121 -frerun-cse-after-loop \
122 -frename-registers
123
124 libc_root := bionic/libc
125 libm_root := bionic/libm
126 libstdc++_root := bionic/libstdc++
127 libthread_db_root := bionic/libthread_db

如果支持thumb,则强制使用 thumb的交互方式。



130 ## on some hosts, the target cross-compiler is not available so do not run this command
131 ifneq ($(wildcard $($(combo_target)CC)),)
132 # We compile with the global cflags to ensure that
133 # any flags which affect libgcc are correctly taken
134 # into account.
135 $(combo_target)LIBGCC := $(shell $($(combo_target)CC) $($(combo_target)GLOBAL_CFLAGS) -print-libgcc-file-name)
136 endif

忽略



138 # unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
139 # symlinks located in out/ to point to the appropriate kernel
140 # headers. see 'config/kernel_headers.make' for more details
141 #
142 ifneq ($(CUSTOM_KERNEL_HEADERS),)
143 KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
144 KERNEL_HEADERS_ARCH := $(CUSTOM_KERNEL_HEADERS)
145 else
146 KERNEL_HEADERS_COMMON := $(libc_root)/kernel/common
147 KERNEL_HEADERS_ARCH := $(libc_root)/kernel/arch-$(TARGET_ARCH)
148 endif
149 KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)

如果没有对CUSTOM_KERNEL_HEADERS 进行定义,那么默认的系统头文件位置在out为根目录的位置。

下面就是一些对编译选项的一些具体定义。


总结分析:
可以看出,对于具体的硬件平台移植这里边有一个重要的宏
TARGET_ARCH_VARIANT 和其关联的两个重要的文件 build/core/combo/arch/arm/armv???.mk 以及
system/core/include/arch/linux-arm/AndroidConfig.h, 这些确定你编译的细节。
TARGET_ARCH_VARIANT应该可以设定在你的 product.mk中。
虽然android建议不要修改这些文件,但我们可以修改这些文件来达到特殊目的。

webkit idl 资料

webcore 通过 idl 实现与 js引擎的绑定,idl为 w3c定义的一个 接口定义语言,为简化开发过程,webkit 通过perl解析 idl文件生成. h .cpp 源码 实现与外部js引擎...
  • scusyq
  • scusyq
  • 2012年06月03日 19:22
  • 1241

正确地保存编译内核产生的.config文件-使用make savedefconfig

正确地保存编译内核产生的.config文件-使用make savedefconfig,一直以来保存编译内核生成的.config文件都是cp .config arch/arm/configs/xxx_d...
  • kangear
  • kangear
  • 2014年09月25日 16:27
  • 17091

make ARCH=arm sama5_defconfig

1. make ARCH=arm sama5_defconfig %config: scripts_basic outputmakefile FORCE             $(Q...

Android 开发效率工具,开发自测相关,测试工具,开发及编译环境,其他

主要介绍和Android开发工具和测试工具相关的开源项目。 一、开发效率工具 Parceler 通过注解及工具类自动完成实体类 Parcelable及值传递 项目地址:https:...

android 编译环境 libgl1-mesa-glx:i386相关安装后ubuntu启动失败

http://www.zhihu.com/question/22151505 http://askubuntu.com/questions/335853/ubuntu-wont-boot-aft...

android 编译环境 libgl1-mesa-glx:i386相关安装后ubuntu启动失败

 http://www.zhihu.com/question/22151505 http://askubuntu.com/questions/335853/ubuntu-won...

Android 开源项目android-open-project开发工具及测试工具解析 开发效率工具,开发自测相关,测试工具,开发及编译环境,其他

主要介绍和Android开发工具和测试工具相关的开源项目。 一、开发效率工具 Parceler 通过注解及工具类自动完成实体类 Parcelable及值传递 项目地址:https://git...
  • pcaxb
  • pcaxb
  • 2015年07月06日 16:16
  • 802

Android编译环境安装指南

  • 2014年11月20日 17:23
  • 383KB
  • 下载

Android编译环境工具

  • 2015年11月18日 12:03
  • 324KB
  • 下载

搭建mips平台编译环境及生成相关

一、搭建mips平台编译环境及生成相关 准备工作 1、在home目录下建立一个mute目录,用于项目开发相关开发的一个目录 2、拷贝西格码公司提供的SMP8634平台相关开发源码包到刚才新建的目...
  • BoArmy
  • BoArmy
  • 2013年03月08日 21:35
  • 644
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Android编译环境 相关
举报原因:
原因补充:

(最多只允许输入30个字)