Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/bin/bash |
michael@0 | 2 | |
michael@0 | 3 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 4 | # Use of this source code is governed by a BSD-style license that can be |
michael@0 | 5 | # found in the LICENSE file. |
michael@0 | 6 | |
michael@0 | 7 | # Defines functions for envsetup.sh which sets up environment for building |
michael@0 | 8 | # Chromium on Android. The build can be either use the Android NDK/SDK or |
michael@0 | 9 | # android source tree. Each has a unique init function which calls functions |
michael@0 | 10 | # prefixed with "common_" that is common for both environment setups. |
michael@0 | 11 | |
michael@0 | 12 | ################################################################################ |
michael@0 | 13 | # Check to make sure the toolchain exists for the NDK version. |
michael@0 | 14 | ################################################################################ |
michael@0 | 15 | common_check_toolchain() { |
michael@0 | 16 | if [[ ! -d "${ANDROID_TOOLCHAIN}" ]]; then |
michael@0 | 17 | echo "Can not find Android toolchain in ${ANDROID_TOOLCHAIN}." >& 2 |
michael@0 | 18 | echo "The NDK version might be wrong." >& 2 |
michael@0 | 19 | return 1 |
michael@0 | 20 | fi |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | ################################################################################ |
michael@0 | 24 | # Exports environment variables common to both sdk and non-sdk build (e.g. PATH) |
michael@0 | 25 | # based on CHROME_SRC and ANDROID_TOOLCHAIN, along with DEFINES for GYP_DEFINES. |
michael@0 | 26 | ################################################################################ |
michael@0 | 27 | common_vars_defines() { |
michael@0 | 28 | |
michael@0 | 29 | # Set toolchain path according to product architecture. |
michael@0 | 30 | toolchain_arch="arm-linux-androideabi" |
michael@0 | 31 | if [[ "${TARGET_PRODUCT}" =~ .*x86.* ]]; then |
michael@0 | 32 | toolchain_arch="x86" |
michael@0 | 33 | fi |
michael@0 | 34 | |
michael@0 | 35 | toolchain_version="4.6" |
michael@0 | 36 | toolchain_target=$(basename \ |
michael@0 | 37 | ${ANDROID_NDK_ROOT}/toolchains/${toolchain_arch}-${toolchain_version}) |
michael@0 | 38 | toolchain_path="${ANDROID_NDK_ROOT}/toolchains/${toolchain_target}"\ |
michael@0 | 39 | "/prebuilt/${toolchain_dir}/bin/" |
michael@0 | 40 | |
michael@0 | 41 | # Set only if not already set. |
michael@0 | 42 | # Don't override ANDROID_TOOLCHAIN if set by Android configuration env. |
michael@0 | 43 | export ANDROID_TOOLCHAIN=${ANDROID_TOOLCHAIN:-${toolchain_path}} |
michael@0 | 44 | |
michael@0 | 45 | common_check_toolchain |
michael@0 | 46 | |
michael@0 | 47 | # Add Android SDK/NDK tools to system path. |
michael@0 | 48 | export PATH=$PATH:${ANDROID_NDK_ROOT} |
michael@0 | 49 | export PATH=$PATH:${ANDROID_SDK_ROOT}/tools |
michael@0 | 50 | export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools |
michael@0 | 51 | |
michael@0 | 52 | # This must be set before ANDROID_TOOLCHAIN, so that clang could find the |
michael@0 | 53 | # gold linker. |
michael@0 | 54 | # TODO(michaelbai): Remove this path once the gold linker become the default |
michael@0 | 55 | # linker. |
michael@0 | 56 | export PATH=$PATH:${CHROME_SRC}/build/android/${toolchain_arch}-gold |
michael@0 | 57 | |
michael@0 | 58 | # Must have tools like arm-linux-androideabi-gcc on the path for ninja |
michael@0 | 59 | export PATH=$PATH:${ANDROID_TOOLCHAIN} |
michael@0 | 60 | |
michael@0 | 61 | # Add Chromium Android development scripts to system path. |
michael@0 | 62 | # Must be after CHROME_SRC is set. |
michael@0 | 63 | export PATH=$PATH:${CHROME_SRC}/build/android |
michael@0 | 64 | |
michael@0 | 65 | # TODO(beverloo): Remove these once all consumers updated to --strip-binary. |
michael@0 | 66 | export OBJCOPY=$(echo ${ANDROID_TOOLCHAIN}/*-objcopy) |
michael@0 | 67 | export STRIP=$(echo ${ANDROID_TOOLCHAIN}/*-strip) |
michael@0 | 68 | |
michael@0 | 69 | # The set of GYP_DEFINES to pass to gyp. Use 'readlink -e' on directories |
michael@0 | 70 | # to canonicalize them (remove double '/', remove trailing '/', etc). |
michael@0 | 71 | DEFINES="OS=android" |
michael@0 | 72 | DEFINES+=" host_os=${host_os}" |
michael@0 | 73 | |
michael@0 | 74 | if [[ -n "$CHROME_ANDROID_OFFICIAL_BUILD" ]]; then |
michael@0 | 75 | DEFINES+=" branding=Chrome" |
michael@0 | 76 | DEFINES+=" buildtype=Official" |
michael@0 | 77 | |
michael@0 | 78 | # These defines are used by various chrome build scripts to tag the binary's |
michael@0 | 79 | # version string as 'official' in linux builds (e.g. in |
michael@0 | 80 | # chrome/trunk/src/chrome/tools/build/version.py). |
michael@0 | 81 | export OFFICIAL_BUILD=1 |
michael@0 | 82 | export CHROMIUM_BUILD="_google_chrome" |
michael@0 | 83 | export CHROME_BUILD_TYPE="_official" |
michael@0 | 84 | |
michael@0 | 85 | # Used by chrome_version_info_posix.cc to display the channel name. |
michael@0 | 86 | # Valid values: "unstable", "stable", "dev", "beta". |
michael@0 | 87 | export CHROME_VERSION_EXTRA="beta" |
michael@0 | 88 | fi |
michael@0 | 89 | |
michael@0 | 90 | # The order file specifies the order of symbols in the .text section of the |
michael@0 | 91 | # shared library, libchromeview.so. The file is an order list of section |
michael@0 | 92 | # names and the library is linked with option |
michael@0 | 93 | # --section-ordering-file=<orderfile>. The order file is updated by profiling |
michael@0 | 94 | # startup after compiling with the order_profiling=1 GYP_DEFINES flag. |
michael@0 | 95 | ORDER_DEFINES="order_text_section=${CHROME_SRC}/orderfiles/orderfile.out" |
michael@0 | 96 | |
michael@0 | 97 | # The following defines will affect ARM code generation of both C/C++ compiler |
michael@0 | 98 | # and V8 mksnapshot. |
michael@0 | 99 | case "${TARGET_PRODUCT}" in |
michael@0 | 100 | "passion"|"soju"|"sojua"|"sojus"|"yakju"|"mysid"|"nakasi") |
michael@0 | 101 | DEFINES+=" arm_neon=1 armv7=1 arm_thumb=1" |
michael@0 | 102 | DEFINES+=" ${ORDER_DEFINES}" |
michael@0 | 103 | TARGET_ARCH="arm" |
michael@0 | 104 | ;; |
michael@0 | 105 | "trygon"|"tervigon") |
michael@0 | 106 | DEFINES+=" arm_neon=0 armv7=1 arm_thumb=1 arm_fpu=vfpv3-d16" |
michael@0 | 107 | DEFINES+=" ${ORDER_DEFINES}" |
michael@0 | 108 | TARGET_ARCH="arm" |
michael@0 | 109 | ;; |
michael@0 | 110 | "full") |
michael@0 | 111 | DEFINES+=" arm_neon=0 armv7=0 arm_thumb=1 arm_fpu=vfp" |
michael@0 | 112 | TARGET_ARCH="arm" |
michael@0 | 113 | ;; |
michael@0 | 114 | *x86*) |
michael@0 | 115 | # TODO(tedbo): The ia32 build fails on ffmpeg, so we disable it here. |
michael@0 | 116 | DEFINES+=" use_libffmpeg=0" |
michael@0 | 117 | |
michael@0 | 118 | host_arch=$(uname -m | sed -e \ |
michael@0 | 119 | 's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/') |
michael@0 | 120 | DEFINES+=" host_arch=${host_arch}" |
michael@0 | 121 | TARGET_ARCH="x86" |
michael@0 | 122 | ;; |
michael@0 | 123 | *) |
michael@0 | 124 | echo "TARGET_PRODUCT: ${TARGET_PRODUCT} is not supported." >& 2 |
michael@0 | 125 | return 1 |
michael@0 | 126 | esac |
michael@0 | 127 | |
michael@0 | 128 | case "${TARGET_ARCH}" in |
michael@0 | 129 | "arm") |
michael@0 | 130 | DEFINES+=" target_arch=arm" |
michael@0 | 131 | ;; |
michael@0 | 132 | "x86") |
michael@0 | 133 | DEFINES+=" target_arch=ia32" |
michael@0 | 134 | ;; |
michael@0 | 135 | *) |
michael@0 | 136 | echo "TARGET_ARCH: ${TARGET_ARCH} is not supported." >& 2 |
michael@0 | 137 | return 1 |
michael@0 | 138 | esac |
michael@0 | 139 | |
michael@0 | 140 | DEFINES+=" android_gdbserver=${ANDROID_NDK_ROOT}/prebuilt/\ |
michael@0 | 141 | android-${TARGET_ARCH}/gdbserver/gdbserver" |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | |
michael@0 | 145 | ################################################################################ |
michael@0 | 146 | # Exports common GYP variables based on variable DEFINES and CHROME_SRC. |
michael@0 | 147 | ################################################################################ |
michael@0 | 148 | common_gyp_vars() { |
michael@0 | 149 | export GYP_DEFINES="${DEFINES}" |
michael@0 | 150 | |
michael@0 | 151 | # Set GYP_GENERATORS to make-android if it's currently unset or null. |
michael@0 | 152 | export GYP_GENERATORS="${GYP_GENERATORS:-make-android}" |
michael@0 | 153 | |
michael@0 | 154 | # Use our All target as the default |
michael@0 | 155 | export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" |
michael@0 | 156 | |
michael@0 | 157 | # We want to use our version of "all" targets. |
michael@0 | 158 | export CHROMIUM_GYP_FILE="${CHROME_SRC}/build/all_android.gyp" |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | |
michael@0 | 162 | ################################################################################ |
michael@0 | 163 | # Initializes environment variables for NDK/SDK build. Only Android NDK Revision |
michael@0 | 164 | # 7 on Linux or Mac is offically supported. To run this script, the system |
michael@0 | 165 | # environment ANDROID_NDK_ROOT must be set to Android NDK's root path. The |
michael@0 | 166 | # ANDROID_SDK_ROOT only needs to be set to override the default SDK which is in |
michael@0 | 167 | # the tree under $ROOT/src/third_party/android_tools/sdk. |
michael@0 | 168 | # TODO(navabi): Add NDK to $ROOT/src/third_party/android_tools/ndk. |
michael@0 | 169 | # To build Chromium for Android with NDK/SDK follow the steps below: |
michael@0 | 170 | # > export ANDROID_NDK_ROOT=<android ndk root> |
michael@0 | 171 | # > export ANDROID_SDK_ROOT=<android sdk root> # to override the default sdk |
michael@0 | 172 | # > . build/android/envsetup.sh --sdk |
michael@0 | 173 | # > make |
michael@0 | 174 | ################################################################################ |
michael@0 | 175 | sdk_build_init() { |
michael@0 | 176 | # If ANDROID_NDK_ROOT is set when envsetup is run, use the ndk pointed to by |
michael@0 | 177 | # the environment variable. Otherwise, use the default ndk from the tree. |
michael@0 | 178 | if [[ -z "${ANDROID_NDK_ROOT}" || ! -d "${ANDROID_NDK_ROOT}" ]]; then |
michael@0 | 179 | export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/" |
michael@0 | 180 | fi |
michael@0 | 181 | |
michael@0 | 182 | # If ANDROID_SDK_ROOT is set when envsetup is run, and if it has the |
michael@0 | 183 | # right SDK-compatible directory layout, use the sdk pointed to by the |
michael@0 | 184 | # environment variable. Otherwise, use the default sdk from the tree. |
michael@0 | 185 | local sdk_suffix=platforms/android-${ANDROID_SDK_VERSION} |
michael@0 | 186 | if [[ -z "${ANDROID_SDK_ROOT}" || \ |
michael@0 | 187 | ! -d "${ANDROID_SDK_ROOT}/${sdk_suffix}" ]]; then |
michael@0 | 188 | export ANDROID_SDK_ROOT="${CHROME_SRC}/third_party/android_tools/sdk/" |
michael@0 | 189 | fi |
michael@0 | 190 | |
michael@0 | 191 | # Makes sure ANDROID_BUILD_TOP is unset if build has option --sdk |
michael@0 | 192 | unset ANDROID_BUILD_TOP |
michael@0 | 193 | |
michael@0 | 194 | # Set default target. |
michael@0 | 195 | export TARGET_PRODUCT="${TARGET_PRODUCT:-trygon}" |
michael@0 | 196 | |
michael@0 | 197 | # Unset toolchain so that it can be set based on TARGET_PRODUCT. |
michael@0 | 198 | # This makes it easy to switch between architectures. |
michael@0 | 199 | unset ANDROID_TOOLCHAIN |
michael@0 | 200 | |
michael@0 | 201 | common_vars_defines |
michael@0 | 202 | |
michael@0 | 203 | DEFINES+=" sdk_build=1" |
michael@0 | 204 | # If we are building NDK/SDK, and in the upstream (open source) tree, |
michael@0 | 205 | # define a special variable for bringup purposes. |
michael@0 | 206 | case "${ANDROID_BUILD_TOP-undefined}" in |
michael@0 | 207 | "undefined") |
michael@0 | 208 | DEFINES+=" android_upstream_bringup=1" |
michael@0 | 209 | ;; |
michael@0 | 210 | esac |
michael@0 | 211 | |
michael@0 | 212 | # Sets android specific directories to NOT_SDK_COMPLIANT. This will allow |
michael@0 | 213 | # android_gyp to generate make files, but will cause errors when (and only |
michael@0 | 214 | # when) building targets that depend on these directories. |
michael@0 | 215 | DEFINES+=" android_src='NOT_SDK_COMPLIANT'" |
michael@0 | 216 | DEFINES+=" android_product_out=${CHROME_SRC}/out/android" |
michael@0 | 217 | DEFINES+=" android_lib='NOT_SDK_COMPLIANT'" |
michael@0 | 218 | DEFINES+=" android_static_lib='NOT_SDK_COMPLIANT'" |
michael@0 | 219 | DEFINES+=" android_sdk=${ANDROID_SDK_ROOT}/${sdk_suffix}" |
michael@0 | 220 | DEFINES+=" android_sdk_root=${ANDROID_SDK_ROOT}" |
michael@0 | 221 | DEFINES+=" android_sdk_tools=${ANDROID_SDK_ROOT}/platform-tools" |
michael@0 | 222 | DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" |
michael@0 | 223 | DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" |
michael@0 | 224 | |
michael@0 | 225 | common_gyp_vars |
michael@0 | 226 | |
michael@0 | 227 | if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then |
michael@0 | 228 | # Can not build WebView with NDK/SDK because it needs the Android build |
michael@0 | 229 | # system and build inside an Android source tree. |
michael@0 | 230 | echo "Can not build WebView with NDK/SDK. Requires android source tree." \ |
michael@0 | 231 | >& 2 |
michael@0 | 232 | echo "Try . build/android/envsetup.sh instead." >& 2 |
michael@0 | 233 | return 1 |
michael@0 | 234 | fi |
michael@0 | 235 | |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | ################################################################################ |
michael@0 | 239 | # Initializes environment variables for build with android source. This expects |
michael@0 | 240 | # android environment to be set up along with lunch. To build: |
michael@0 | 241 | # > . build/envsetup.sh |
michael@0 | 242 | # > lunch <lunch-type> |
michael@0 | 243 | # > . build/android/envsetup.sh |
michael@0 | 244 | # > make |
michael@0 | 245 | ############################################################################# |
michael@0 | 246 | non_sdk_build_init() { |
michael@0 | 247 | # We export "TOP" here so that "mmm" can be run to build Java code without |
michael@0 | 248 | # having to cd to $ANDROID_BUILD_TOP. |
michael@0 | 249 | export TOP="$ANDROID_BUILD_TOP" |
michael@0 | 250 | |
michael@0 | 251 | # Set "ANDROID_NDK_ROOT" as checked-in version, if it was not set. |
michael@0 | 252 | if [[ "${ANDROID_NDK_ROOT}" || ! -d "$ANDROID_NDK_ROOT" ]] ; then |
michael@0 | 253 | export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/" |
michael@0 | 254 | fi |
michael@0 | 255 | if [[ ! -d "${ANDROID_NDK_ROOT}" ]] ; then |
michael@0 | 256 | echo "Can not find Android NDK root ${ANDROID_NDK_ROOT}." >& 2 |
michael@0 | 257 | return 1 |
michael@0 | 258 | fi |
michael@0 | 259 | |
michael@0 | 260 | # We export "ANDROID_SDK_ROOT" for building Java source with the SDK. |
michael@0 | 261 | export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\ |
michael@0 | 262 | ${ANDROID_SDK_VERSION} |
michael@0 | 263 | # Needed by android antfiles when creating apks. |
michael@0 | 264 | export ANDROID_SDK_HOME=${ANDROID_SDK_ROOT} |
michael@0 | 265 | |
michael@0 | 266 | # Unset ANDROID_TOOLCHAIN, so it could be set to checked-in 64-bit toolchain. |
michael@0 | 267 | # in common_vars_defines |
michael@0 | 268 | unset ANDROID_TOOLCHAIN |
michael@0 | 269 | |
michael@0 | 270 | common_vars_defines |
michael@0 | 271 | |
michael@0 | 272 | DEFINES+=" sdk_build=0" |
michael@0 | 273 | DEFINES+=" android_product_out=${ANDROID_PRODUCT_OUT}" |
michael@0 | 274 | |
michael@0 | 275 | if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then |
michael@0 | 276 | webview_build_init |
michael@0 | 277 | return |
michael@0 | 278 | fi |
michael@0 | 279 | |
michael@0 | 280 | # The non-SDK build currently requires the SDK path to build the framework |
michael@0 | 281 | # Java aidl files. TODO(steveblock): Investigate avoiding this requirement. |
michael@0 | 282 | DEFINES+=" android_sdk=${ANDROID_SDK_ROOT}" |
michael@0 | 283 | DEFINES+=" android_sdk_root=${ANDROID_SDK_ROOT}" |
michael@0 | 284 | DEFINES+=" android_sdk_tools=${ANDROID_SDK_ROOT}/../tools/linux" |
michael@0 | 285 | DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" |
michael@0 | 286 | DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" |
michael@0 | 287 | |
michael@0 | 288 | common_gyp_vars |
michael@0 | 289 | } |
michael@0 | 290 | |
michael@0 | 291 | ################################################################################ |
michael@0 | 292 | # To build WebView, we use the Android build system and build inside an Android |
michael@0 | 293 | # source tree. This method is called from non_sdk_build_init() and adds to the |
michael@0 | 294 | # settings specified there. |
michael@0 | 295 | ############################################################################# |
michael@0 | 296 | webview_build_init() { |
michael@0 | 297 | # For the WebView build we always use the NDK and SDK in the Android tree, |
michael@0 | 298 | # and we don't touch ANDROID_TOOLCHAIN which is already set by Android. |
michael@0 | 299 | export ANDROID_NDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/ndk/8 |
michael@0 | 300 | export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\ |
michael@0 | 301 | ${ANDROID_SDK_VERSION} |
michael@0 | 302 | |
michael@0 | 303 | common_vars_defines |
michael@0 | 304 | |
michael@0 | 305 | # We need to supply SDK paths relative to the top of the Android tree to make |
michael@0 | 306 | # sure the generated Android makefiles are portable, as they will be checked |
michael@0 | 307 | # into the Android tree. |
michael@0 | 308 | ANDROID_SDK=$(python -c \ |
michael@0 | 309 | "import os.path; print os.path.relpath('${ANDROID_SDK_ROOT}', \ |
michael@0 | 310 | '${ANDROID_BUILD_TOP}')") |
michael@0 | 311 | ANDROID_SDK_TOOLS=$(python -c \ |
michael@0 | 312 | "import os.path; \ |
michael@0 | 313 | print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/linux', \ |
michael@0 | 314 | '${ANDROID_BUILD_TOP}')") |
michael@0 | 315 | DEFINES+=" android_build_type=1" |
michael@0 | 316 | DEFINES+=" sdk_build=0" |
michael@0 | 317 | DEFINES+=" android_src=\$(GYP_ABS_ANDROID_TOP_DIR)" |
michael@0 | 318 | DEFINES+=" android_product_out=NOT_USED_ON_WEBVIEW" |
michael@0 | 319 | DEFINES+=" android_upstream_bringup=1" |
michael@0 | 320 | DEFINES+=" android_sdk=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK}" |
michael@0 | 321 | DEFINES+=" android_sdk_root=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK}" |
michael@0 | 322 | DEFINES+=" android_sdk_tools=\$(GYP_ABS_ANDROID_TOP_DIR)/${ANDROID_SDK_TOOLS}" |
michael@0 | 323 | DEFINES+=" android_sdk_version=${ANDROID_SDK_VERSION}" |
michael@0 | 324 | DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}" |
michael@0 | 325 | export GYP_DEFINES="${DEFINES}" |
michael@0 | 326 | |
michael@0 | 327 | export GYP_GENERATORS="android" |
michael@0 | 328 | |
michael@0 | 329 | export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" |
michael@0 | 330 | export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} limit_to_target_all=1" |
michael@0 | 331 | export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} auto_regeneration=0" |
michael@0 | 332 | |
michael@0 | 333 | export CHROMIUM_GYP_FILE="${CHROME_SRC}/android_webview/all_webview.gyp" |
michael@0 | 334 | } |