2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # Sets up environment for building Chromium on Android. It can either be
7 # compiled with the Android tree or using the Android SDK/NDK. To build with
8 # NDK/SDK: ". build/android/envsetup.sh". Environment variable
9 # ANDROID_SDK_BUILD=1 will then be defined and used in the rest of the setup to
10 # specifiy build type.
12 # TODO(ilevy): Figure out the right check here. This breaks the webkit build as
13 # is since it's sourced from another script:
14 # http://build.webkit.org/builders/Chromium%20Android%20Release/builds/34681
15 #if [ "$_" == "$0" ]; then
16 # echo "ERROR: envsetup must be sourced."
20 # Source functions script. The file is in the same directory as this script.
21 SCRIPT_DIR
="$(dirname "${BASH_SOURCE:-$0}")"
22 .
"${SCRIPT_DIR}"/envsetup_functions.sh
24 export ANDROID_SDK_BUILD
=1 # Default to SDK build.
28 # When building WebView as part of Android we can't use the SDK. Other builds
29 # default to using the SDK.
30 if [[ "${CHROME_ANDROID_BUILD_WEBVIEW}" -eq 1 ]]; then
31 export ANDROID_SDK_BUILD
=0
34 if [[ "${ANDROID_SDK_BUILD}" -ne 1 ]]; then
35 echo "Initializing for non-SDK build."
38 # Get host architecture, and abort if it is 32-bit, unless --try-32
41 case "${host_arch}" in
45 if [[ -z "${try_32bit_host_build}" ]]; then
46 echo "ERROR: Android build requires a 64-bit host build machine."
47 echo "If you really want to try it on this machine, use the \
48 --try-32bit-host flag."
49 echo "Be warned that this may fail horribly at link time, due \
53 echo "WARNING: 32-bit host build enabled. Here be dragons!"
58 echo "ERROR: Unsupported host architecture (${host_arch})."
59 echo "Try running this script on a Linux/x86_64 machine instead."
65 toolchain_dir
="linux-${host_arch}"
68 toolchain_dir
="darwin-${host_arch}"
71 echo "Host platform ${host_os} is not supported" >& 2
75 CURRENT_DIR
="$(readlink -f "${SCRIPT_DIR}/..
/..
/")"
76 if [[ -z "${CHROME_SRC}" ]]; then
77 # If $CHROME_SRC was not set, assume current directory is CHROME_SRC.
78 export CHROME_SRC
="${CURRENT_DIR}"
81 if [[ "${CURRENT_DIR/"${CHROME_SRC}"/}" == "${CURRENT_DIR}" ]]; then
82 # If current directory is not in $CHROME_SRC, it might be set for other
83 # source tree. If $CHROME_SRC was set correctly and we are in the correct
84 # directory, "${CURRENT_DIR/"${CHROME_SRC}"/}" will be "".
85 # Otherwise, it will equal to "${CURRENT_DIR}"
86 echo "Warning: Current directory is out of CHROME_SRC, it may not be \
91 if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then
92 if [[ -z "${TARGET_ARCH}" ]]; then
96 # Sets up environment for building Chromium for Android with source. Expects
97 # android environment setup and lunch.
98 elif [[ -z "$ANDROID_BUILD_TOP" || \
99 -z "$ANDROID_TOOLCHAIN" || \
100 -z "$ANDROID_PRODUCT_OUT" ]]; then
101 echo "Android build environment variables must be set."
102 echo "Please cd to the root of your Android tree and do: "
103 echo " . build/envsetup.sh"
105 echo "Then try this again."
106 echo "Or did you mean NDK/SDK build. Run envsetup.sh without any arguments."
108 elif [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then
112 java
-version 2>&1 |
grep -qs "Java HotSpot"
113 if [ $?
-ne 0 ]; then
114 echo "Please check and make sure you are using the Oracle Java SDK, and it"
115 echo "appears before other Java SDKs in your path."
116 echo "Refer to the \"Install prerequisites\" section here:"
117 echo "https://code.google.com/p/chromium/wiki/AndroidBuildInstructions"
121 if [[ -n "$JAVA_HOME" && -x "$JAVA_HOME/bin/java" ]]; then
122 "$JAVA_HOME/bin/java" -version 2>&1 |
grep -qs "Java HotSpot"
123 if [ $?
-ne 0 ]; then
124 echo "If JAVA_HOME is defined then it must refer to the install location"
125 echo "of the Oracle Java SDK."
126 echo "Refer to the \"Install prerequisites\" section here:"
127 echo "https://code.google.com/p/chromium/wiki/AndroidBuildInstructions"
132 # Workaround for valgrind build
133 if [[ -n "$CHROME_ANDROID_VALGRIND_BUILD" ]]; then
134 # arm_thumb=0 is a workaround for https://bugs.kde.org/show_bug.cgi?id=270709
135 DEFINES
+=" arm_thumb=0 release_extra_cflags='-fno-inline\
136 -fno-omit-frame-pointer -fno-builtin' release_valgrind_build=1\
140 # Source a bunch of helper functions
141 .
${CHROME_SRC}/build
/android
/adb_device_functions.sh
143 ANDROID_GOMA_WRAPPER
=""
144 if [[ -d $GOMA_DIR ]]; then
145 ANDROID_GOMA_WRAPPER
="$GOMA_DIR/gomacc"
146 num_cores
="$(grep --count ^processor /proc/cpuinfo)"
147 # Goma is IO-ish you want more threads than you have cores.
148 let goma_threads
=num_cores
*2
149 if [ -z "${GOMA_COMPILER_PROXY_THREADS}" -a "${goma_threads}" -gt 16 ]; then
150 # The default is 16 threads, if the machine has many cores we crank it up a bit
151 GOMA_COMPILER_PROXY_THREADS
="${goma_threads}"
152 export GOMA_COMPILER_PROXY_THREADS
155 export ANDROID_GOMA_WRAPPER
157 # Declare Android are cross compile.
158 export GYP_CROSSCOMPILE
=1
160 # Performs a gyp_chromium run to convert gyp->Makefile for android code.
162 # This is just a simple wrapper of gyp_chromium, please don't add anything
164 echo "GYP_GENERATORS set to '$GYP_GENERATORS'"
166 "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" --check "$@"
170 # FLOCK needs to be null on system that has no flock
171 which flock
> /dev
/null ||
export FLOCK
=