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 # Exports environment variables common to both sdk and non-sdk build (e.g. PATH)
14 # based on CHROME_SRC, along with DEFINES for GYP_DEFINES.
15 ################################################################################
16 common_vars_defines() {
17 # Add Android SDK tools to system path.
18 export PATH=$PATH:${ANDROID_SDK_ROOT}/tools
19 export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools
21 # Add Chromium Android development scripts to system path.
22 # Must be after CHROME_SRC is set.
23 export PATH=$PATH:${CHROME_SRC}/build/android
25 # The set of GYP_DEFINES to pass to gyp.
28 if [[ -n "$CHROME_ANDROID_OFFICIAL_BUILD" ]]; then
29 # These defines are used by various chrome build scripts to tag the binary's
30 # version string as 'official' in linux builds (e.g. in
31 # chrome/trunk/src/chrome/tools/build/version.py).
32 export OFFICIAL_BUILD=1
33 export CHROMIUM_BUILD="_google_chrome"
34 export CHROME_BUILD_TYPE="_official"
37 # TODO(thakis), Jan 18 2014: Remove this after two weeks or so, after telling
38 # everyone to set use_goma in GYP_DEFINES instead of a GOMA_DIR env var.
39 if [[ -d $GOMA_DIR ]]; then
40 DEFINES+=" use_goma=1 gomadir=$GOMA_DIR"
43 # The following defines will affect ARM code generation of both C/C++ compiler
45 case "${TARGET_ARCH}" in
47 DEFINES+=" target_arch=arm"
50 DEFINES+=" target_arch=ia32"
53 DEFINES+=" target_arch=mipsel"
56 echo "TARGET_ARCH: ${TARGET_ARCH} is not supported." >& 2
63 ################################################################################
64 # Prints out help message on usage.
65 ################################################################################
67 echo "usage: ${0##*/} [--target-arch=value] [--help]" >& 2
68 echo "--target-arch=value target CPU architecture (arm=default, x86)" >& 2
69 echo "--host-os=value override host OS detection (linux, mac)" >&2
70 echo "--help this help" >& 2
73 ################################################################################
74 # Process command line options.
75 ################################################################################
77 host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
81 target_arch="$(echo "$1" | sed 's/^[^=]*=//')"
84 host_os="$(echo "$1" | sed 's/^[^=]*=//')"
91 # Ignore other command line options
92 echo "Unknown option: $1"
98 # Sets TARGET_ARCH. Defaults to arm if not specified.
99 TARGET_ARCH=${target_arch:-arm}
102 ################################################################################
103 # Initializes environment variables for NDK/SDK build.
104 ################################################################################
106 # Allow the caller to override a few environment variables. If any of them is
107 # unset, we default to a sane value that's known to work. This allows for
108 # experimentation with a custom SDK.
109 if [[ -z "${ANDROID_NDK_ROOT}" || ! -d "${ANDROID_NDK_ROOT}" ]]; then
110 export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/"
112 if [[ -z "${ANDROID_SDK_ROOT}" || ! -d "${ANDROID_SDK_ROOT}" ]]; then
113 export ANDROID_SDK_ROOT="${CHROME_SRC}/third_party/android_tools/sdk/"
118 export GYP_DEFINES="${DEFINES}"
120 if [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then
121 # Can not build WebView with NDK/SDK because it needs the Android build
122 # system and build inside an Android source tree.
123 echo "Can not build WebView with NDK/SDK. Requires android source tree." \
125 echo "Try . build/android/envsetup.sh instead." >& 2
130 ################################################################################
131 # To build WebView, we use the Android build system and build inside an Android
133 #############################################################################
134 webview_build_init() {
135 # Use the latest API in the AOSP prebuilts directory (change with AOSP roll).
136 android_sdk_version=18
138 # For the WebView build we always use the SDK in the Android tree.
139 export ANDROID_SDK_ROOT=${ANDROID_BUILD_TOP}/prebuilts/sdk/\
140 ${android_sdk_version}
144 # We need to supply SDK paths relative to the top of the Android tree to make
145 # sure the generated Android makefiles are portable, as they will be checked
146 # into the Android tree.
147 ANDROID_SDK=$(python -c \
148 "import os.path; print os.path.relpath('${ANDROID_SDK_ROOT}', \
149 '${ANDROID_BUILD_TOP}')")
152 ANDROID_SDK_TOOLS=$(python -c \
154 print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/linux', \
155 '${ANDROID_BUILD_TOP}')")
158 ANDROID_SDK_TOOLS=$(python -c \
160 print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/darwin', \
161 '${ANDROID_BUILD_TOP}')")
164 DEFINES+=" android_webview_build=1"
165 DEFINES+=" android_src=\$(PWD)"
166 DEFINES+=" android_ndk_root=ndk_root_unused_in_webview_build"
167 DEFINES+=" android_sdk=\$(PWD)/${ANDROID_SDK}"
168 DEFINES+=" android_sdk_root=\$(PWD)/${ANDROID_SDK}"
169 DEFINES+=" android_sdk_tools=\$(PWD)/${ANDROID_SDK_TOOLS}"
170 DEFINES+=" android_sdk_version=sdk_version_unused_in_webview_build"
171 DEFINES+=" android_toolchain=${ANDROID_TOOLCHAIN}"
172 if [[ -n "$CHROME_ANDROID_WEBVIEW_OFFICIAL_BUILD" ]]; then
173 DEFINES+=" logging_like_official_build=1"
174 DEFINES+=" tracing_like_official_build=1"
176 export GYP_DEFINES="${DEFINES}"