免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2150 | 回复: 0
打印 上一主题 下一主题

Android Building System [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-20 17:21 |只看该作者 |倒序浏览

mydroid/development/pdk/build_system.html gives a brief overview of Android Build System. The attached article should be seen as the complement to the build_system.html, which will help readers/users have in-depth understanding on Android Building System.
[[[[[Forwarded from Steve GUO's blog http://letsgoustc.spaces.live.com/blog/cns!89AD27DFB5E249BA!465.entry?_c=BlogPart]]]]]
Device/docs/design/build-system.html
is a good start point to understand Android build system. In this
topic, I will describe the behind details using mm to compile an
executable and shared library.
[color="#000000"]

[color="#000000"]Tips: “make ***  showcommands”can let build system show the original compile commands.
[color="#000000"]1. Basic
[color="#000000"]In envsetup.sh, mm macro is defined.
[color="#000000"]function mm()
[color="#000000"]{
[color="#000000"]    # If we're sitting in the root of the build tree, just do a
[color="#000000"]    # normal make.
[color="#000000"]    if [ -f config/envsetup.make -a -f Makefile ]; then
[color="#000000"]        make $@
[color="#000000"]    else
[color="#000000"]        # Find the closest Android.mk file.
[color="#000000"]        T=$(gettop)
[color="#000000"]        M=$(findmakefile)
[color="#000000"]        if [ ! "$T" ]; then
[color="#000000"]            echo "Couldn't locate the top of the tree.  Try setting TOP."
[color="#000000"]        elif [ ! "$M" ]; then
[color="#000000"]            echo "Couldn't locate a makefile from the current directory."
[color="#000000"]        else
[color="#000000"]            ONE_SHOT_MAKEFILE=$M make -C $T files $@
[color="#000000"]        fi
[color="#000000"]    fi
[color="#000000"]}
[color="#000000"]
[color="#000000"]In top layer Makefile
[color="#000000"]ifneq ($(ONE_SHOT_MAKEFILE[color="#000000"]),)
[color="#000000"]# We've probably been invoked by the "mm" shell function
[color="#000000"]# with a subdirectory's makefile.
[color="#000000"]include $(ONE_SHOT_MAKEFILE)
[color="#000000"]# Change CUSTOM_MODULES to include only modules that were
[color="#000000"]# defined by this makefile; this will install all of those
[color="#000000"]# modules as a side-effect.  Do this after including ONE_SHOT_MAKEFILE
[color="#000000"]# so that the modules will be installed in the same place they
[color="#000000"]# would have been with a normal make.
[color="#000000"]CUSTOM_MODULES := $(sort $(call get-tagged-modules,$(ALL_MODULE_TAGS),))
[color="#000000"]FULL_BUILD :=
[color="#000000"]INTERNAL_DEFAULT_DOCS_TARGETS :=
[color="#000000"]# Stub out the notice targets, which probably aren't defined
[color="#000000"]# when using ONE_SHOT_MAKEFILE.
[color="#000000"]NOTICE-HOST-%: ;
[color="#000000"]NOTICE-TARGET-%: ;
So
if we type mm in a directory, it will finally include our own
Android.mk. Android will put every Android.mk into one huge Makefile.
[color="#000000"]In top layer Makefile, it includes base_rules.make, while in base_rules.make it defines a target for LOCAL_MODULE which must be specified in our own Android.mk.
[color="#000000"]# Provide a short-hand for building this module.
[color="#000000"]# We name both BUILT and INSTALLED in case
[color="#000000"]# LOCAL_UNINSTALLABLE_MODULE is set.
[color="#000000"].PHONY: $(LOCAL_MODULE)
[color="#000000"]$(LOCAL_MODULE): $(LOCAL_BUILT_MODULE) $(LOCAL_INSTALLED_MODULE)
[color="#000000"]
[color="#000000"]definitions.make contains the most important macros for building source file. Here lists the two macros for building C++ and C source files.
[color="#000000"]###########################################################
[color="#000000"]## Commands for running gcc to compile a C++ file
[color="#000000"]###########################################################
[color="#000000"]
[color="#000000"]define transform-cpp-to-o
[color="#000000"]@mkdir -p $(dir $@)
[color="#000000"]@echo "target $(PRIVATE_ARM_MODE) C++: $(PRIVATE_MODULE)  
[color="#000000"]$(hide) $(PRIVATE_CXX) \
[color="#000000"]       $(foreach incdir, \
[color="#000000"]           $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
[color="#000000"]              $(TARGET_PROJECT_INCLUDES) \
[color="#000000"]              $(TARGET_C_INCLUDES) \
[color="#000000"]            ) \
[color="#000000"]           $(PRIVATE_C_INCLUDES) \
[color="#000000"]         , \
[color="#000000"]           -I $(incdir) \
[color="#000000"]        ) \
[color="#000000"]       -c \
[color="#000000"]       $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
[color="#000000"]           $(TARGET_GLOBAL_CFLAGS) \
[color="#000000"]           $(TARGET_GLOBAL_CPPFLAGS) \
[color="#000000"]           $(PRIVATE_ARM_CFLAGS) \
[color="#000000"]        ) \
[color="#000000"]       $(PRIVATE_CFLAGS) \
[color="#000000"]       $(PRIVATE_CPPFLAGS) \
[color="#000000"]       $(PRIVATE_DEBUG_CFLAGS) \
[color="#000000"]       -fno-rtti \
[color="#000000"]       -MD -o $@ $
[color="#000000"]$(hide) $(transform-d-to-p)
[color="#000000"]endef
[color="#000000"]
[color="#000000"]###########################################################
[color="#000000"]## Commands for running gcc to compile a C file
[color="#000000"]###########################################################
[color="#000000"]
[color="#000000"]# $(1): extra flags
[color="#000000"]define transform-c-or-s-to-o-no-deps
[color="#000000"]@mkdir -p $(dir $@)
[color="#000000"]$(hide) $(PRIVATE_CC) \
[color="#000000"]       $(foreach incdir, \
[color="#000000"]           $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
[color="#000000"]              $(TARGET_PROJECT_INCLUDES) \
[color="#000000"]              $(TARGET_C_INCLUDES) \
[color="#000000"]            ) \
[color="#000000"]           $(PRIVATE_C_INCLUDES) \
[color="#000000"]         , \
[color="#000000"]           -I $(incdir) \
[color="#000000"]        ) \
[color="#000000"]       -c \
[color="#000000"]       $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),, \
[color="#000000"]           $(TARGET_GLOBAL_CFLAGS) \
[color="#000000"]           $(PRIVATE_ARM_CFLAGS) \
[color="#000000"]        ) \
[color="#000000"]       $(PRIVATE_CFLAGS) \
[color="#000000"]       $(1) \
[color="#000000"]       $(PRIVATE_DEBUG_CFLAGS) \
[color="#000000"]       -MD -o $@ $
[color="#000000"]endef
[color="#000000"]
[color="#000000"]
[color="#000000"]2. Executable
[color="#000000"]In our own Android.mk we should add two lines.
[color="#000000"]LOCAL_MODULE := ***
[color="#000000"]include $(BUILD_EXECUTABLE)
[color="#000000"]
[color="#000000"]BUILD_EXECUTALE is defined in config.make.
[color="#000000"]BUILD_EXECUTABLE:= $(BUILD_SYSTEM)/executable.make
[color="#000000"]
[color="#000000"]In executable.make
[color="#000000"]include $(BUILD_SYSTEM)/dynamic_binary.make
[color="#000000"]
[color="#000000"]ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
[color="#000000"]$(linked_module): $(TARGET_CRTBEGIN_STATIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
[color="#000000"]       $(transform-o-to-static-executable)
[color="#000000"]else  
[color="#000000"]$(linked_module): $(TARGET_CRTBEGIN_DYNAMIC_O) $(all_objects) $(all_libraries) $(TARGET_CRTEND_O)
[color="#000000"]       $(transform-o-to-executable)
[color="#000000"]Endif
[color="#000000"]So here defined a new target $(linked_module).
[color="#000000"]
[color="#000000"]transform-o-to-exeuctable macro is defined in defintions.make.
[color="#000000"]define transform-o-to-executable
[color="#000000"]@mkdir -p $(dir $@)
[color="#000000"]@echo "target Executable: $(PRIVATE_MODULE) ($@)"
[color="#000000"]$(hide) $(transform-o-to-executable-inner)
[color="#000000"]endef
[color="#000000"]
[color="#000000"]combo/linux-arm.make contains macros to transform o to executable for ARM.
[color="#000000"]define transform-o-to-executable-inner
[color="#000000"]$(TARGET_CXX) -nostdlib -Bdynamic -Wl,-T,$(BUILD_SYSTEM)/armelf.x \
[color="#000000"]       -Wl,-dynamic-linker,/system/bin/linker \
[color="#000000"]    -Wl,--gc-sections \
[color="#000000"]       -Wl,-z,nocopyreloc \
[color="#000000"]       -o $@ \
[color="#000000"]       $(TARGET_GLOBAL_LD_DIRS) \
[color="#000000"]       -Wl,-rpath-link=$(TARGET_OUT_INTERMEDIATE_LIBRARIES) \
[color="#000000"]       $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
[color="#000000"]       $(TARGET_CRTBEGIN_DYNAMIC_O) \
[color="#000000"]       $(PRIVATE_ALL_OBJECTS) \
[color="#000000"]       $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
[color="#000000"]       $(PRIVATE_LDFLAGS) \
[color="#000000"]       $(TARGET_LIBGCC) \
[color="#000000"]       $(TARGET_CRTEND_O)
[color="#000000"]endef
[color="#000000"]
[color="#000000"]binary.make contains some PRIVATE_* definitions used by the above macros.
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_YACCFLAGS := $(LOCAL_YACCFLAGS)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_ASFLAGS := $(LOCAL_ASFLAGS)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS := $(LOCAL_CPPFLAGS)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(LOCAL_C_INCLUDES)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(LOCAL_LDFLAGS)
[color="#000000"]$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(LOCAL_LDLIBS)
[color="#000000"]
[color="#000000"]combo/linux-arm.make contains default CFLAGS/CPPFLAGS/C_INCLUDES definitions.
[color="#000000"]$(combo_target)GLOBAL_CFLAGS += \
[color="#000000"]                     -march=armv5te -mtune=xscale \
[color="#000000"]                     -msoft-float -fpic \
[color="#000000"]                     -mthumb-interwork \
[color="#000000"]                     -ffunction-sections \
[color="#000000"]                     -funwind-tables \
[color="#000000"]                     -fstack-protector \
[color="#000000"]                     -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ \
[color="#000000"]                     -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ \
[color="#000000"]                     -include include/arch/linux-arm/AndroidConfig.h
[color="#000000"]
[color="#000000"]$(combo_target)GLOBAL_CPPFLAGS += -fvisibility-inlines-hidden
[color="#000000"]
[color="#000000"]$(combo_target)RELEASE_CFLAGS := \
[color="#000000"]                     -DSK_RELEASE -DNDEBUG \
[color="#000000"]                     -O2 -g \
[color="#000000"]                     -Wstrict-aliasing=2 \
[color="#000000"]                     -finline-functions \
[color="#000000"]                     -fno-inline-functions-called-once \
[color="#000000"]                     -fgcse-after-reload \
[color="#000000"]                     -frerun-cse-after-loop \
[color="#000000"]                     -frename-registers
[color="#000000"]
[color="#000000"]# unless CUSTOM_KERNEL_HEADERS is defined, we're going to use
[color="#000000"]# symlinks located in out/ to point to the appropriate kernel
[color="#000000"]# headers. see 'config/kernel_headers.make' for more details
[color="#000000"]#
[color="#000000"]KERNEL_HEADERS_COMMON := system/bionic/kernel/common
[color="#000000"]KERNEL_HEADERS_ARCH   := system/bionic/kernel/arch-$(TARGET_ARCH)
[color="#000000"]ifneq ($(CUSTOM_KERNEL_HEADERS),)
[color="#000000"]    KERNEL_HEADERS_COMMON := $(CUSTOM_KERNEL_HEADERS)
[color="#000000"]    KERNEL_HEADERS_ARCH   := $(CUSTOM_KERNEL_HEADERS)
[color="#000000"]endif
[color="#000000"]KERNEL_HEADERS := $(KERNEL_HEADERS_COMMON) $(KERNEL_HEADERS_ARCH)
[color="#000000"]
[color="#000000"]$(combo_target)C_INCLUDES := \
[color="#000000"]       system/bionic/arch-arm/include \
[color="#000000"]       system/bionic/include \
[color="#000000"]       system/libstdc++/include \
[color="#000000"]       $(KERNEL_HEADERS) \
[color="#000000"]       system/libm/include \
[color="#000000"]       system/libm/include/arch/arm \
[color="#000000"]       system/libthread_db/include
[color="#000000"]
[color="#000000"]3. Shared Library
[color="#000000"]In our own Android.mk we should add two lines.
[color="#000000"]LOCAL_MODULE := ***
[color="#000000"]include $(BUILD_SHARED_LIBRARY)
[color="#000000"]
[color="#000000"]BUILD_SHARED_LIBRARY is defined in config.make.
[color="#000000"]BUILD_SHARED_LIBRARY:= $(BUILD_SYSTEM)/shared_library.make
[color="#000000"]
[color="#000000"]In shared_library.make
[color="#000000"]include $(BUILD_SYSTEM)/dynamic_binary.make
[color="#000000"]
[color="#000000"]$(linked_module): $(all_objects) $(all_libraries) $(LOCAL_ADDITIONAL_DEPENDENCIES)
[color="#000000"]       $(transform-o-to-shared-lib)
[color="#000000"]So here defined a new target $(linked_module).
[color="#000000"]
[color="#000000"]transform-o-to-shared-lib macro is defined in defintions.make.
[color="#000000"]define transform-o-to-shared-lib
[color="#000000"]@mkdir -p $(dir $@)
[color="#000000"]@echo "target SharedLib: $(PRIVATE_MODULE) ($@)"
[color="#000000"]$(hide) $(transform-o-to-shared-lib-inner)
[color="#000000"]endef
[color="#000000"]
[color="#000000"]combo/linux-arm.make contains macro to transform o to shared lib for ARM.
[color="#000000"]define transform-o-to-shared-lib-inner
[color="#000000"]$(TARGET_CXX) \
[color="#000000"]       -nostdlib -Wl,-soname,$(notdir $@) -Wl,-T,$(BUILD_SYSTEM)/armelf.xsc \
[color="#000000"]       -Wl,--gc-sections \
[color="#000000"]       -Wl,-shared,-Bsymbolic \
[color="#000000"]       $(TARGET_GLOBAL_LD_DIRS) \
[color="#000000"]       $(PRIVATE_ALL_OBJECTS) \
[color="#000000"]       -Wl,--whole-archive \
[color="#000000"]       $(call normalize-host-libraries,$(PRIVATE_ALL_WHOLE_STATIC_LIBRARIES)) \
[color="#000000"]       -Wl,--no-whole-archive \
[color="#000000"]       $(call normalize-target-libraries,$(PRIVATE_ALL_STATIC_LIBRARIES)) \
[color="#000000"]       $(call normalize-target-libraries,$(PRIVATE_ALL_SHARED_LIBRARIES)) \
[color="#000000"]       -o $@ \
[color="#000000"]       $(PRIVATE_LDFLAGS) \
[color="#000000"]       $(TARGET_LIBGCC)
[color="#000000"]endef
[color="#000000"]
[color="#000000"]=====EOF===============



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/87831/showart_1805660.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP