6286a1e1f921a7a4eff30fd21f9c23e5480f9026
[platform/framework/web/crosswalk.git] / src / build / android / envsetup.sh
1 #!/bin/bash
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.
5
6 # Sets up environment for building Chromium on Android.
7
8 # Make sure we're being sourced (possibly by another script). Check for bash
9 # since zsh sets $0 when sourcing.
10 if [[ -n "$BASH_VERSION" && "${BASH_SOURCE:-$0}" == "$0" ]]; then
11   echo "ERROR: envsetup must be sourced."
12   exit 1
13 fi
14
15 # Source functions script.  The file is in the same directory as this script.
16 SCRIPT_DIR="$(dirname "${BASH_SOURCE:-$0}")"
17
18 # Get host architecture, and abort if it is 32-bit.
19 host_arch=$(uname -m)
20 case "${host_arch}" in
21   x86_64)  # pass
22     ;;
23   i?86)
24     echo "ERROR: Android build requires a 64-bit host build machine."
25     return 1
26     ;;
27   *)
28     echo "ERROR: Unsupported host architecture (${host_arch})."
29     echo "Try running this script on a Linux/x86_64 machine instead."
30     return 1
31 esac
32
33 CURRENT_DIR="$(readlink -f "${SCRIPT_DIR}/../../")"
34 if [[ -z "${CHROME_SRC}" ]]; then
35   # If $CHROME_SRC was not set, assume current directory is CHROME_SRC.
36   export CHROME_SRC="${CURRENT_DIR}"
37 fi
38
39 if [[ "${CURRENT_DIR/"${CHROME_SRC}"/}" == "${CURRENT_DIR}" ]]; then
40   # If current directory is not in $CHROME_SRC, it might be set for other
41   # source tree. If $CHROME_SRC was set correctly and we are in the correct
42   # directory, "${CURRENT_DIR/"${CHROME_SRC}"/}" will be "".
43   # Otherwise, it will equal to "${CURRENT_DIR}"
44   echo "Warning: Current directory is out of CHROME_SRC, it may not be \
45 the one you want."
46   echo "${CHROME_SRC}"
47 fi
48
49 # Allow the caller to override a few environment variables. If any of them is
50 # unset, we default to a sane value that's known to work. This allows for
51 # experimentation with a custom SDK.
52 if [[ -z "${ANDROID_NDK_ROOT}" || ! -d "${ANDROID_NDK_ROOT}" ]]; then
53   export ANDROID_NDK_ROOT="${CHROME_SRC}/third_party/android_tools/ndk/"
54 fi
55 if [[ -z "${ANDROID_SDK_ROOT}" || ! -d "${ANDROID_SDK_ROOT}" ]]; then
56   export ANDROID_SDK_ROOT="${CHROME_SRC}/third_party/android_tools/sdk/"
57 fi
58
59 # Add Android SDK tools to system path.
60 export PATH=$PATH:${ANDROID_SDK_ROOT}/tools
61 export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools
62
63 # Add Chromium Android development scripts to system path.
64 # Must be after CHROME_SRC is set.
65 export PATH=$PATH:${CHROME_SRC}/build/android
66
67 # The set of GYP_DEFINES to pass to gyp.
68 DEFINES="OS=android"
69
70 if [[ -n "$CHROME_ANDROID_OFFICIAL_BUILD" ]]; then
71   # These defines are used by various chrome build scripts to tag the binary's
72   # version string as 'official' in linux builds (e.g. in
73   # chrome/trunk/src/chrome/tools/build/version.py).
74   export OFFICIAL_BUILD=1
75   export CHROMIUM_BUILD="_google_chrome"
76   export CHROME_BUILD_TYPE="_official"
77 fi
78
79 # TODO(thakis), Jan 18 2014: Remove this after two weeks or so, after telling
80 # everyone to set use_goma in GYP_DEFINES instead of a GOMA_DIR env var.
81 if [[ -d $GOMA_DIR ]]; then
82   DEFINES+=" use_goma=1 gomadir=$GOMA_DIR"
83 fi
84
85 export GYP_DEFINES="${DEFINES}"
86
87 # Source a bunch of helper functions
88 . ${CHROME_SRC}/build/android/adb_device_functions.sh
89
90 # Performs a gyp_chromium run to convert gyp->Makefile for android code.
91 android_gyp() {
92   # This is just a simple wrapper of gyp_chromium, please don't add anything
93   # in this function.
94   "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" --check "$@"
95 }