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