michael@0: #!/bin/bash michael@0: michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: # Defines functions for envsetup.sh which sets up environment for building michael@0: # Chromium on Android. The build can be either use the Android NDK/SDK or michael@0: # android source tree. Each has a unique init function which calls functions michael@0: # prefixed with "common_" that is common for both environment setups. michael@0: michael@0: ################################################################################ michael@0: # Check to make sure the toolchain exists for the NDK version. michael@0: ################################################################################ michael@0: common_check_toolchain() { michael@0: if [[ ! -d "${ANDROID_TOOLCHAIN}" ]]; then michael@0: echo "Can not find Android toolchain in ${ANDROID_TOOLCHAIN}." >& 2 michael@0: echo "The NDK version might be wrong." >& 2 michael@0: return 1 michael@0: fi michael@0: } michael@0: michael@0: ################################################################################ michael@0: # Exports environment variables common to both sdk and non-sdk build (e.g. PATH) michael@0: # based on CHROME_SRC and ANDROID_TOOLCHAIN, along with DEFINES for GYP_DEFINES. michael@0: ################################################################################ michael@0: common_vars_defines() { michael@0: michael@0: # Set toolchain path according to product architecture. michael@0: toolchain_arch="arm-linux-androideabi" michael@0: if [[ "${TARGET_PRODUCT}" =~ .*x86.* ]]; then michael@0: toolchain_arch="x86" michael@0: fi michael@0: michael@0: toolchain_version="4.6" michael@0: toolchain_target=$(basename \ michael@0: ${ANDROID_NDK_ROOT}/toolchains/${toolchain_arch}-${toolchain_version}) michael@0: toolchain_path="${ANDROID_NDK_ROOT}/toolchains/${toolchain_target}"\ michael@0: "/prebuilt/${toolchain_dir}/bin/" michael@0: michael@0: # Set only if not already set. michael@0: # Don't override ANDROID_TOOLCHAIN if set by Android configuration env. michael@0: export ANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN:-${toolchain_path}} michael@0: michael@0: common_check_toolchain michael@0: michael@0: # Add Android SDK/NDK tools to system path. michael@0: export PATH=$PATH:${ANDROID_NDK_ROOT} michael@0: export PATH=$PATH:${ANDROID_SDK_ROOT}/tools michael@0: export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools michael@0: michael@0: # This must be set before ANDROID_TOOLCHAIN, so that clang could find the michael@0: # gold linker. michael@0: # TODO(michaelbai): Remove this path once the gold linker become the default michael@0: # linker. michael@0: export PATH=$PATH:${CHROME_SRC}/build/android/${toolchain_arch}-gold michael@0: michael@0: # Must have tools like arm-linux-androideabi-gcc on the path for ninja michael@0: export PATH=$PATH:${ANDROID_TOOLCHAIN} michael@0: michael@0: # Add Chromium Android development scripts to system path. michael@0: # Must be after CHROME_SRC is set. michael@0: export PATH=$PATH:${CHROME_SRC}/build/android michael@0: michael@0: # TODO(beverloo): Remove these once all consumers updated to --strip-binary. michael@0: export OBJCOPY=$(echo ${ANDROID_TOOLCHAIN}/*-objcopy) michael@0: export STRIP=$(echo ${ANDROID_TOOLCHAIN}/*-strip) michael@0: michael@0: # The set of GYP_DEFINES to pass to gyp. Use 'readlink -e' on directories michael@0: # to canonicalize them (remove double '/', remove trailing '/', etc). michael@0: DEFINES="OS=android" michael@0: DEFINES+=" host_os=${host_os}" michael@0: michael@0: if [[ -n "$CHROME_ANDROID_OFFICIAL_BUILD" ]]; then michael@0: DEFINES+=" branding=Chrome" michael@0: DEFINES+=" buildtype=Official" michael@0: michael@0: # These defines are used by various chrome build scripts to tag the binary's michael@0: # version string as 'official' in linux builds (e.g. in michael@0: # chrome/trunk/src/chrome/tools/build/version.py). michael@0: export OFFICIAL_BUILD=1 michael@0: export CHROMIUM_BUILD="_google_chrome" michael@0: export CHROME_BUILD_TYPE="_official" michael@0: michael@0: # Used by chrome_version_info_posix.cc to display the channel name. michael@0: # Valid values: "unstable", "stable", "dev", "beta". michael@0: export CHROME_VERSION_EXTRA="beta" michael@0: fi michael@0: michael@0: # The order file specifies the order of symbols in the .text section of the michael@0: # shared library, libchromeview.so. The file is an order list of section michael@0: # names and the library is linked with option michael@0: # --section-ordering-file=. The order file is updated by profiling michael@0: # startup after compiling with the order_profiling=1 GYP_DEFINES flag. michael@0: ORDER_DEFINES="order_text_section=${CHROME_SRC}/orderfiles/orderfile.out" michael@0: michael@0: # The following defines will affect ARM code generation of both C/C++ compiler michael@0: # and V8 mksnapshot. michael@0: case "${TARGET_PRODUCT}" in michael@0: "passion"|"soju"|"sojua"|"sojus"|"yakju"|"mysid"|"nakasi") michael@0: DEFINES+=" arm_neon=1 armv7=1 arm_thumb=1" michael@0: DEFINES+=" ${ORDER_DEFINES}" michael@0: TARGET_ARCH="arm" michael@0: ;; michael@0: "trygon"|"tervigon") michael@0: DEFINES+=" arm_neon=0 armv7=1 arm_thumb=1 arm_fpu=vfpv3-d16" michael@0: DEFINES+=" ${ORDER_DEFINES}" michael@0: TARGET_ARCH="arm" michael@0: ;; michael@0: "full") michael@0: DEFINES+=" arm_neon=0 armv7=0 arm_thumb=1 arm_fpu=vfp" michael@0: TARGET_ARCH="arm" michael@0: ;; michael@0: *x86*) michael@0: # TODO(tedbo): The ia32 build fails on ffmpeg, so we disable it here. michael@0: DEFINES+=" use_libffmpeg=0" michael@0: michael@0: host_arch=$(uname -m | sed -e \ michael@0: 's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/') michael@0: DEFINES+=" host_arch=${host_arch}" michael@0: TARGET_ARCH="x86" michael@0: ;; michael@0: *) michael@0: echo "TARGET_PRODUCT: ${TARGET_PRODUCT} is not supported." >& 2 michael@0: return 1 michael@0: esac michael@0: michael@0: case "${TARGET_ARCH}" in michael@0: "arm") michael@0: DEFINES+=" target_arch=arm" michael@0: ;; michael@0: "x86") michael@0: DEFINES+=" target_arch=ia32" michael@0: ;; michael@0: *) michael@0: echo "TARGET_ARCH: ${TARGET_ARCH} is not supported." >& 2 michael@0: return 1 michael@0: esac michael@0: michael@0: DEFINES+=" android_gdbserver=${ANDROID_NDK_ROOT}/prebuilt/\ michael@0: android-${TARGET_ARCH}/gdbserver/gdbserver" michael@0: } michael@0: michael@0: michael@0: ################################################################################ michael@0: # Exports common GYP variables based on variable DEFINES and CHROME_SRC. michael@0: ################################################################################ michael@0: common_gyp_vars() { michael@0: export GYP_DEFINES="${DEFINES}" michael@0: michael@0: # Set GYP_GENERATORS to make-android if it's currently unset or null. michael@0: export GYP_GENERATORS="${GYP_GENERATORS:-make-android}" michael@0: michael@0: # Use our All target as the default michael@0: export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" michael@0: michael@0: # We want to use our version of "all" targets. michael@0: export CHROMIUM_GYP_FILE="${CHROME_SRC}/build/all_android.gyp" michael@0: } michael@0: michael@0: michael@0: ################################################################################ michael@0: # Initializes environment variables for NDK/SDK build. Only Android NDK Revision michael@0: # 7 on Linux or Mac is offically supported. To run this script, the system michael@0: # environment ANDROID_NDK_ROOT must be set to Android NDK's root path. The michael@0: # ANDROID_SDK_ROOT only needs to be set to override the default SDK which is in michael@0: # the tree under $ROOT/src/third_party/android_tools/sdk. michael@0: # TODO(navabi): Add NDK to $ROOT/src/third_party/android_tools/ndk. michael@0: # To build Chromium for Android with NDK/SDK follow the steps below: michael@0: # > export ANDROID_NDK_ROOT= michael@0: # > export ANDROID_SDK_ROOT= # to override the default sdk michael@0: # > . build/android/envsetup.sh --sdk michael@0: # > make michael@0: ################################################################################ michael@0: sdk_build_init() { michael@0: # If ANDROID_NDK_ROOT is set when envsetup is run, use the ndk pointed to by michael@0: # the environment variable. Otherwise, use the default ndk from the tree. michael@0: if [[ -z "${ANDROID_NDK_ROOT}" || ! -d "${ANDROID_NDK_ROOT}" ]]; then michael@0: export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/" michael@0: fi michael@0: michael@0: # If ANDROID_SDK_ROOT is set when envsetup is run, and if it has the michael@0: # right SDK-compatible directory layout, use the sdk pointed to by the michael@0: # environment variable. Otherwise, use the default sdk from the tree. michael@0: local sdk_suffix=platforms/android-${ANDROID_SDK_VERSION} michael@0: if [[ -z "${ANDROID_SDK_ROOT}" || \ michael@0: ! -d "${ANDROID_SDK_ROOT}/${sdk_suffix}" ]]; then michael@0: export ANDROID_SDK_ROOT="${CHROME_SRC}/third_party/android_tools/sdk/" michael@0: fi michael@0: michael@0: # Makes sure ANDROID_BUILD_TOP is unset if build has option --sdk michael@0: unset ANDROID_BUILD_TOP michael@0: michael@0: # Set default target. michael@0: export TARGET_PRODUCT="${TARGET_PRODUCT:-trygon}" michael@0: michael@0: # Unset toolchain so that it can be set based on TARGET_PRODUCT. michael@0: # This makes it easy to switch between architectures. michael@0: unset ANDROID_TOOLCHAIN michael@0: michael@0: common_vars_defines michael@0: michael@0: DEFINES+=" sdk_build=1" michael@0: # If we are building NDK/SDK, and in the upstream (open source) tree, michael@0: # define a special variable for bringup purposes. michael@0: case "${ANDROID_BUILD_TOP-undefined}" in michael@0: "undefined") michael@0: DEFINES+=" android_upstream_bringup=1" michael@0: ;; michael@0: esac michael@0: michael@0: # Sets android specific directories to NOT_SDK_COMPLIANT. This will allow michael@0: # android_gyp to generate make files, but will cause errors when (and only michael@0: # when) building targets that depend on these directories. michael@0: DEFINES+=" android_src='NOT_SDK_COMPLIANT'" michael@0: DEFINES+=" android_product_out=${CHROME_SRC}/out/android" michael@0: DEFINES+=" android_lib='NOT_SDK_COMPLIANT'" michael@0: DEFINES+=" android_static_lib='NOT_SDK_COMPLIANT'" michael@0: DEFINES+=" android_sdk=${ANDROID_SDK_ROOT}/${sdk_suffix}" michael@0: DEFINES+=" android_sdk_root=${ANDROID_SDK_ROOT}" michael@0: DEFINES+=" android_sdk_tools=${ANDROID_SDK_ROOT}/platform-tools" michael@0: DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" michael@0: DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" michael@0: michael@0: common_gyp_vars michael@0: michael@0: if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then michael@0: # Can not build WebView with NDK/SDK because it needs the Android build michael@0: # system and build inside an Android source tree. michael@0: echo "Can not build WebView with NDK/SDK. Requires android source tree." \ michael@0: >& 2 michael@0: echo "Try . build/android/envsetup.sh instead." >& 2 michael@0: return 1 michael@0: fi michael@0: michael@0: } michael@0: michael@0: ################################################################################ michael@0: # Initializes environment variables for build with android source. This expects michael@0: # android environment to be set up along with lunch. To build: michael@0: # > . build/envsetup.sh michael@0: # > lunch michael@0: # > . build/android/envsetup.sh michael@0: # > make michael@0: ############################################################################# michael@0: non_sdk_build_init() { michael@0: # We export "TOP" here so that "mmm" can be run to build Java code without michael@0: # having to cd to $ANDROID_BUILD_TOP. michael@0: export TOP="$ANDROID_BUILD_TOP" michael@0: michael@0: # Set "ANDROID_NDK_ROOT" as checked-in version, if it was not set. michael@0: if [[ "${ANDROID_NDK_ROOT}" || ! -d "$ANDROID_NDK_ROOT" ]] ; then michael@0: export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/" michael@0: fi michael@0: if [[ ! -d "${ANDROID_NDK_ROOT}" ]] ; then michael@0: echo "Can not find Android NDK root ${ANDROID_NDK_ROOT}." >& 2 michael@0: return 1 michael@0: fi michael@0: michael@0: # We export "ANDROID_SDK_ROOT" for building Java source with the SDK. michael@0: export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\ michael@0: ${ANDROID_SDK_VERSION} michael@0: # Needed by android antfiles when creating apks. michael@0: export ANDROID_SDK_HOME=${ANDROID_SDK_ROOT} michael@0: michael@0: # Unset ANDROID_TOOLCHAIN, so it could be set to checked-in 64-bit toolchain. michael@0: # in common_vars_defines michael@0: unset ANDROID_TOOLCHAIN michael@0: michael@0: common_vars_defines michael@0: michael@0: DEFINES+=" sdk_build=0" michael@0: DEFINES+=" android_product_out=${ANDROID_PRODUCT_OUT}" michael@0: michael@0: if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then michael@0: webview_build_init michael@0: return michael@0: fi michael@0: michael@0: # The non-SDK build currently requires the SDK path to build the framework michael@0: # Java aidl files. TODO(steveblock): Investigate avoiding this requirement. michael@0: DEFINES+=" android_sdk=${ANDROID_SDK_ROOT}" michael@0: DEFINES+=" android_sdk_root=${ANDROID_SDK_ROOT}" michael@0: DEFINES+=" android_sdk_tools=${ANDROID_SDK_ROOT}/../tools/linux" michael@0: DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" michael@0: DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" michael@0: michael@0: common_gyp_vars michael@0: } michael@0: michael@0: ################################################################################ michael@0: # To build WebView, we use the Android build system and build inside an Android michael@0: # source tree. This method is called from non_sdk_build_init() and adds to the michael@0: # settings specified there. michael@0: ############################################################################# michael@0: webview_build_init() { michael@0: # For the WebView build we always use the NDK and SDK in the Android tree, michael@0: # and we don't touch ANDROID_TOOLCHAIN which is already set by Android. michael@0: export ANDROID_NDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/ndk/8 michael@0: export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\ michael@0: ${ANDROID_SDK_VERSION} michael@0: michael@0: common_vars_defines michael@0: michael@0: # We need to supply SDK paths relative to the top of the Android tree to make michael@0: # sure the generated Android makefiles are portable, as they will be checked michael@0: # into the Android tree. michael@0: ANDROID_SDK=$(python -c \ michael@0: "import os.path; print os.path.relpath('${ANDROID_SDK_ROOT}', \ michael@0: '${ANDROID_BUILD_TOP}')") michael@0: ANDROID_SDK_TOOLS=$(python -c \ michael@0: "import os.path; \ michael@0: print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/linux', \ michael@0: '${ANDROID_BUILD_TOP}')") michael@0: DEFINES+=" android_build_type=1" michael@0: DEFINES+=" sdk_build=0" michael@0: DEFINES+=" android_src=\$(GYP_ABS_ANDROID_TOP_DIR)" michael@0: DEFINES+=" android_product_out=NOT_USED_ON_WEBVIEW" michael@0: DEFINES+=" android_upstream_bringup=1" michael@0: DEFINES+=" android_sdk=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK}" michael@0: DEFINES+=" android_sdk_root=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK}" michael@0: DEFINES+=" android_sdk_tools=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK_TOOLS}" michael@0: DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" michael@0: DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" michael@0: export GYP_DEFINES="${DEFINES}" michael@0: michael@0: export GYP_GENERATORS="android" michael@0: michael@0: export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" michael@0: export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} limit_to_target_all=1" michael@0: export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} auto_regeneration=0" michael@0: michael@0: export CHROMIUM_GYP_FILE="${CHROME_SRC}/android_webview/all_webview.gyp" michael@0: }