1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/android/envsetup_functions.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,334 @@ 1.4 +#!/bin/bash 1.5 + 1.6 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.7 +# Use of this source code is governed by a BSD-style license that can be 1.8 +# found in the LICENSE file. 1.9 + 1.10 +# Defines functions for envsetup.sh which sets up environment for building 1.11 +# Chromium on Android. The build can be either use the Android NDK/SDK or 1.12 +# android source tree. Each has a unique init function which calls functions 1.13 +# prefixed with "common_" that is common for both environment setups. 1.14 + 1.15 +################################################################################ 1.16 +# Check to make sure the toolchain exists for the NDK version. 1.17 +################################################################################ 1.18 +common_check_toolchain() { 1.19 + if [[ ! -d "${ANDROID_TOOLCHAIN}" ]]; then 1.20 + echo "Can not find Android toolchain in ${ANDROID_TOOLCHAIN}." >& 2 1.21 + echo "The NDK version might be wrong." >& 2 1.22 + return 1 1.23 + fi 1.24 +} 1.25 + 1.26 +################################################################################ 1.27 +# Exports environment variables common to both sdk and non-sdk build (e.g. PATH) 1.28 +# based on CHROME_SRC and ANDROID_TOOLCHAIN, along with DEFINES for GYP_DEFINES. 1.29 +################################################################################ 1.30 +common_vars_defines() { 1.31 + 1.32 + # Set toolchain path according to product architecture. 1.33 + toolchain_arch="arm-linux-androideabi" 1.34 + if [[ "${TARGET_PRODUCT}" =~ .*x86.* ]]; then 1.35 + toolchain_arch="x86" 1.36 + fi 1.37 + 1.38 + toolchain_version="4.6" 1.39 + toolchain_target=$(basename \ 1.40 + ${ANDROID_NDK_ROOT}/toolchains/${toolchain_arch}-${toolchain_version}) 1.41 + toolchain_path="${ANDROID_NDK_ROOT}/toolchains/${toolchain_target}"\ 1.42 +"/prebuilt/${toolchain_dir}/bin/" 1.43 + 1.44 + # Set only if not already set. 1.45 + # Don't override ANDROID_TOOLCHAIN if set by Android configuration env. 1.46 + export ANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN:-${toolchain_path}} 1.47 + 1.48 + common_check_toolchain 1.49 + 1.50 + # Add Android SDK/NDK tools to system path. 1.51 + export PATH=$PATH:${ANDROID_NDK_ROOT} 1.52 + export PATH=$PATH:${ANDROID_SDK_ROOT}/tools 1.53 + export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools 1.54 + 1.55 + # This must be set before ANDROID_TOOLCHAIN, so that clang could find the 1.56 + # gold linker. 1.57 + # TODO(michaelbai): Remove this path once the gold linker become the default 1.58 + # linker. 1.59 + export PATH=$PATH:${CHROME_SRC}/build/android/${toolchain_arch}-gold 1.60 + 1.61 + # Must have tools like arm-linux-androideabi-gcc on the path for ninja 1.62 + export PATH=$PATH:${ANDROID_TOOLCHAIN} 1.63 + 1.64 + # Add Chromium Android development scripts to system path. 1.65 + # Must be after CHROME_SRC is set. 1.66 + export PATH=$PATH:${CHROME_SRC}/build/android 1.67 + 1.68 + # TODO(beverloo): Remove these once all consumers updated to --strip-binary. 1.69 + export OBJCOPY=$(echo ${ANDROID_TOOLCHAIN}/*-objcopy) 1.70 + export STRIP=$(echo ${ANDROID_TOOLCHAIN}/*-strip) 1.71 + 1.72 + # The set of GYP_DEFINES to pass to gyp. Use 'readlink -e' on directories 1.73 + # to canonicalize them (remove double '/', remove trailing '/', etc). 1.74 + DEFINES="OS=android" 1.75 + DEFINES+=" host_os=${host_os}" 1.76 + 1.77 + if [[ -n "$CHROME_ANDROID_OFFICIAL_BUILD" ]]; then 1.78 + DEFINES+=" branding=Chrome" 1.79 + DEFINES+=" buildtype=Official" 1.80 + 1.81 + # These defines are used by various chrome build scripts to tag the binary's 1.82 + # version string as 'official' in linux builds (e.g. in 1.83 + # chrome/trunk/src/chrome/tools/build/version.py). 1.84 + export OFFICIAL_BUILD=1 1.85 + export CHROMIUM_BUILD="_google_chrome" 1.86 + export CHROME_BUILD_TYPE="_official" 1.87 + 1.88 + # Used by chrome_version_info_posix.cc to display the channel name. 1.89 + # Valid values: "unstable", "stable", "dev", "beta". 1.90 + export CHROME_VERSION_EXTRA="beta" 1.91 + fi 1.92 + 1.93 + # The order file specifies the order of symbols in the .text section of the 1.94 + # shared library, libchromeview.so. The file is an order list of section 1.95 + # names and the library is linked with option 1.96 + # --section-ordering-file=<orderfile>. The order file is updated by profiling 1.97 + # startup after compiling with the order_profiling=1 GYP_DEFINES flag. 1.98 + ORDER_DEFINES="order_text_section=${CHROME_SRC}/orderfiles/orderfile.out" 1.99 + 1.100 + # The following defines will affect ARM code generation of both C/C++ compiler 1.101 + # and V8 mksnapshot. 1.102 + case "${TARGET_PRODUCT}" in 1.103 + "passion"|"soju"|"sojua"|"sojus"|"yakju"|"mysid"|"nakasi") 1.104 + DEFINES+=" arm_neon=1 armv7=1 arm_thumb=1" 1.105 + DEFINES+=" ${ORDER_DEFINES}" 1.106 + TARGET_ARCH="arm" 1.107 + ;; 1.108 + "trygon"|"tervigon") 1.109 + DEFINES+=" arm_neon=0 armv7=1 arm_thumb=1 arm_fpu=vfpv3-d16" 1.110 + DEFINES+=" ${ORDER_DEFINES}" 1.111 + TARGET_ARCH="arm" 1.112 + ;; 1.113 + "full") 1.114 + DEFINES+=" arm_neon=0 armv7=0 arm_thumb=1 arm_fpu=vfp" 1.115 + TARGET_ARCH="arm" 1.116 + ;; 1.117 + *x86*) 1.118 + # TODO(tedbo): The ia32 build fails on ffmpeg, so we disable it here. 1.119 + DEFINES+=" use_libffmpeg=0" 1.120 + 1.121 + host_arch=$(uname -m | sed -e \ 1.122 + 's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/') 1.123 + DEFINES+=" host_arch=${host_arch}" 1.124 + TARGET_ARCH="x86" 1.125 + ;; 1.126 + *) 1.127 + echo "TARGET_PRODUCT: ${TARGET_PRODUCT} is not supported." >& 2 1.128 + return 1 1.129 + esac 1.130 + 1.131 + case "${TARGET_ARCH}" in 1.132 + "arm") 1.133 + DEFINES+=" target_arch=arm" 1.134 + ;; 1.135 + "x86") 1.136 + DEFINES+=" target_arch=ia32" 1.137 + ;; 1.138 + *) 1.139 + echo "TARGET_ARCH: ${TARGET_ARCH} is not supported." >& 2 1.140 + return 1 1.141 + esac 1.142 + 1.143 + DEFINES+=" android_gdbserver=${ANDROID_NDK_ROOT}/prebuilt/\ 1.144 +android-${TARGET_ARCH}/gdbserver/gdbserver" 1.145 +} 1.146 + 1.147 + 1.148 +################################################################################ 1.149 +# Exports common GYP variables based on variable DEFINES and CHROME_SRC. 1.150 +################################################################################ 1.151 +common_gyp_vars() { 1.152 + export GYP_DEFINES="${DEFINES}" 1.153 + 1.154 + # Set GYP_GENERATORS to make-android if it's currently unset or null. 1.155 + export GYP_GENERATORS="${GYP_GENERATORS:-make-android}" 1.156 + 1.157 + # Use our All target as the default 1.158 + export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" 1.159 + 1.160 + # We want to use our version of "all" targets. 1.161 + export CHROMIUM_GYP_FILE="${CHROME_SRC}/build/all_android.gyp" 1.162 +} 1.163 + 1.164 + 1.165 +################################################################################ 1.166 +# Initializes environment variables for NDK/SDK build. Only Android NDK Revision 1.167 +# 7 on Linux or Mac is offically supported. To run this script, the system 1.168 +# environment ANDROID_NDK_ROOT must be set to Android NDK's root path. The 1.169 +# ANDROID_SDK_ROOT only needs to be set to override the default SDK which is in 1.170 +# the tree under $ROOT/src/third_party/android_tools/sdk. 1.171 +# TODO(navabi): Add NDK to $ROOT/src/third_party/android_tools/ndk. 1.172 +# To build Chromium for Android with NDK/SDK follow the steps below: 1.173 +# > export ANDROID_NDK_ROOT=<android ndk root> 1.174 +# > export ANDROID_SDK_ROOT=<android sdk root> # to override the default sdk 1.175 +# > . build/android/envsetup.sh --sdk 1.176 +# > make 1.177 +################################################################################ 1.178 +sdk_build_init() { 1.179 + # If ANDROID_NDK_ROOT is set when envsetup is run, use the ndk pointed to by 1.180 + # the environment variable. Otherwise, use the default ndk from the tree. 1.181 + if [[ -z "${ANDROID_NDK_ROOT}" || ! -d "${ANDROID_NDK_ROOT}" ]]; then 1.182 + export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/" 1.183 + fi 1.184 + 1.185 + # If ANDROID_SDK_ROOT is set when envsetup is run, and if it has the 1.186 + # right SDK-compatible directory layout, use the sdk pointed to by the 1.187 + # environment variable. Otherwise, use the default sdk from the tree. 1.188 + local sdk_suffix=platforms/android-${ANDROID_SDK_VERSION} 1.189 + if [[ -z "${ANDROID_SDK_ROOT}" || \ 1.190 + ! -d "${ANDROID_SDK_ROOT}/${sdk_suffix}" ]]; then 1.191 + export ANDROID_SDK_ROOT="${CHROME_SRC}/third_party/android_tools/sdk/" 1.192 + fi 1.193 + 1.194 + # Makes sure ANDROID_BUILD_TOP is unset if build has option --sdk 1.195 + unset ANDROID_BUILD_TOP 1.196 + 1.197 + # Set default target. 1.198 + export TARGET_PRODUCT="${TARGET_PRODUCT:-trygon}" 1.199 + 1.200 + # Unset toolchain so that it can be set based on TARGET_PRODUCT. 1.201 + # This makes it easy to switch between architectures. 1.202 + unset ANDROID_TOOLCHAIN 1.203 + 1.204 + common_vars_defines 1.205 + 1.206 + DEFINES+=" sdk_build=1" 1.207 + # If we are building NDK/SDK, and in the upstream (open source) tree, 1.208 + # define a special variable for bringup purposes. 1.209 + case "${ANDROID_BUILD_TOP-undefined}" in 1.210 + "undefined") 1.211 + DEFINES+=" android_upstream_bringup=1" 1.212 + ;; 1.213 + esac 1.214 + 1.215 + # Sets android specific directories to NOT_SDK_COMPLIANT. This will allow 1.216 + # android_gyp to generate make files, but will cause errors when (and only 1.217 + # when) building targets that depend on these directories. 1.218 + DEFINES+=" android_src='NOT_SDK_COMPLIANT'" 1.219 + DEFINES+=" android_product_out=${CHROME_SRC}/out/android" 1.220 + DEFINES+=" android_lib='NOT_SDK_COMPLIANT'" 1.221 + DEFINES+=" android_static_lib='NOT_SDK_COMPLIANT'" 1.222 + DEFINES+=" android_sdk=${ANDROID_SDK_ROOT}/${sdk_suffix}" 1.223 + DEFINES+=" android_sdk_root=${ANDROID_SDK_ROOT}" 1.224 + DEFINES+=" android_sdk_tools=${ANDROID_SDK_ROOT}/platform-tools" 1.225 + DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" 1.226 + DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" 1.227 + 1.228 + common_gyp_vars 1.229 + 1.230 + if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then 1.231 + # Can not build WebView with NDK/SDK because it needs the Android build 1.232 + # system and build inside an Android source tree. 1.233 + echo "Can not build WebView with NDK/SDK. Requires android source tree." \ 1.234 + >& 2 1.235 + echo "Try . build/android/envsetup.sh instead." >& 2 1.236 + return 1 1.237 + fi 1.238 + 1.239 +} 1.240 + 1.241 +################################################################################ 1.242 +# Initializes environment variables for build with android source. This expects 1.243 +# android environment to be set up along with lunch. To build: 1.244 +# > . build/envsetup.sh 1.245 +# > lunch <lunch-type> 1.246 +# > . build/android/envsetup.sh 1.247 +# > make 1.248 +############################################################################# 1.249 +non_sdk_build_init() { 1.250 + # We export "TOP" here so that "mmm" can be run to build Java code without 1.251 + # having to cd to $ANDROID_BUILD_TOP. 1.252 + export TOP="$ANDROID_BUILD_TOP" 1.253 + 1.254 + # Set "ANDROID_NDK_ROOT" as checked-in version, if it was not set. 1.255 + if [[ "${ANDROID_NDK_ROOT}" || ! -d "$ANDROID_NDK_ROOT" ]] ; then 1.256 + export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/" 1.257 + fi 1.258 + if [[ ! -d "${ANDROID_NDK_ROOT}" ]] ; then 1.259 + echo "Can not find Android NDK root ${ANDROID_NDK_ROOT}." >& 2 1.260 + return 1 1.261 + fi 1.262 + 1.263 + # We export "ANDROID_SDK_ROOT" for building Java source with the SDK. 1.264 + export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\ 1.265 +${ANDROID_SDK_VERSION} 1.266 + # Needed by android antfiles when creating apks. 1.267 + export ANDROID_SDK_HOME=${ANDROID_SDK_ROOT} 1.268 + 1.269 + # Unset ANDROID_TOOLCHAIN, so it could be set to checked-in 64-bit toolchain. 1.270 + # in common_vars_defines 1.271 + unset ANDROID_TOOLCHAIN 1.272 + 1.273 + common_vars_defines 1.274 + 1.275 + DEFINES+=" sdk_build=0" 1.276 + DEFINES+=" android_product_out=${ANDROID_PRODUCT_OUT}" 1.277 + 1.278 + if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then 1.279 + webview_build_init 1.280 + return 1.281 + fi 1.282 + 1.283 + # The non-SDK build currently requires the SDK path to build the framework 1.284 + # Java aidl files. TODO(steveblock): Investigate avoiding this requirement. 1.285 + DEFINES+=" android_sdk=${ANDROID_SDK_ROOT}" 1.286 + DEFINES+=" android_sdk_root=${ANDROID_SDK_ROOT}" 1.287 + DEFINES+=" android_sdk_tools=${ANDROID_SDK_ROOT}/../tools/linux" 1.288 + DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" 1.289 + DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" 1.290 + 1.291 + common_gyp_vars 1.292 +} 1.293 + 1.294 +################################################################################ 1.295 +# To build WebView, we use the Android build system and build inside an Android 1.296 +# source tree. This method is called from non_sdk_build_init() and adds to the 1.297 +# settings specified there. 1.298 +############################################################################# 1.299 +webview_build_init() { 1.300 + # For the WebView build we always use the NDK and SDK in the Android tree, 1.301 + # and we don't touch ANDROID_TOOLCHAIN which is already set by Android. 1.302 + export ANDROID_NDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/ndk/8 1.303 + export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\ 1.304 +${ANDROID_SDK_VERSION} 1.305 + 1.306 + common_vars_defines 1.307 + 1.308 + # We need to supply SDK paths relative to the top of the Android tree to make 1.309 + # sure the generated Android makefiles are portable, as they will be checked 1.310 + # into the Android tree. 1.311 + ANDROID_SDK=$(python -c \ 1.312 + "import os.path; print os.path.relpath('${ANDROID_SDK_ROOT}', \ 1.313 + '${ANDROID_BUILD_TOP}')") 1.314 + ANDROID_SDK_TOOLS=$(python -c \ 1.315 + "import os.path; \ 1.316 + print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/linux', \ 1.317 + '${ANDROID_BUILD_TOP}')") 1.318 + DEFINES+=" android_build_type=1" 1.319 + DEFINES+=" sdk_build=0" 1.320 + DEFINES+=" android_src=\$(GYP_ABS_ANDROID_TOP_DIR)" 1.321 + DEFINES+=" android_product_out=NOT_USED_ON_WEBVIEW" 1.322 + DEFINES+=" android_upstream_bringup=1" 1.323 + DEFINES+=" android_sdk=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK}" 1.324 + DEFINES+=" android_sdk_root=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK}" 1.325 + DEFINES+=" android_sdk_tools=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK_TOOLS}" 1.326 + DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" 1.327 + DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" 1.328 + export GYP_DEFINES="${DEFINES}" 1.329 + 1.330 + export GYP_GENERATORS="android" 1.331 + 1.332 + export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" 1.333 + export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} limit_to_target_all=1" 1.334 + export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} auto_regeneration=0" 1.335 + 1.336 + export CHROMIUM_GYP_FILE="${CHROME_SRC}/android_webview/all_webview.gyp" 1.337 +}