46e3a4eaeccdfbfddf1a76d2c35e756460287aa6
[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.  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.
11
12 # Make sure we're being sourced (possibly by another script). Check for bash
13 # since zsh sets $0 when sourcing.
14 if [[ -n "$BASH_VERSION" && "${BASH_SOURCE:-$0}" == "$0" ]]; then
15   echo "ERROR: envsetup must be sourced."
16   exit 1
17 fi
18
19 # Source functions script.  The file is in the same directory as this script.
20 SCRIPT_DIR="$(dirname "${BASH_SOURCE:-$0}")"
21 . "${SCRIPT_DIR}"/envsetup_functions.sh
22
23 export ANDROID_SDK_BUILD=1  # Default to SDK build.
24
25 process_options "$@"
26
27 # When building WebView as part of Android we can't use the SDK. Other builds
28 # default to using the SDK.
29 if [[ "${CHROME_ANDROID_BUILD_WEBVIEW}" -eq 1 ]]; then
30   export ANDROID_SDK_BUILD=0
31 fi
32
33 if [[ "${ANDROID_SDK_BUILD}" -ne 1 ]]; then
34   echo "Initializing for non-SDK build."
35 fi
36
37 # Get host architecture, and abort if it is 32-bit.
38 host_arch=$(uname -m)
39 case "${host_arch}" in
40   x86_64)  # pass
41     ;;
42   i?86)
43     echo "ERROR: Android build requires a 64-bit host build machine."
44     return 1
45     ;;
46   *)
47     echo "ERROR: Unsupported host architecture (${host_arch})."
48     echo "Try running this script on a Linux/x86_64 machine instead."
49     return 1
50 esac
51
52 CURRENT_DIR="$(readlink -f "${SCRIPT_DIR}/../../")"
53 if [[ -z "${CHROME_SRC}" ]]; then
54   # If $CHROME_SRC was not set, assume current directory is CHROME_SRC.
55   export CHROME_SRC="${CURRENT_DIR}"
56 fi
57
58 if [[ "${CURRENT_DIR/"${CHROME_SRC}"/}" == "${CURRENT_DIR}" ]]; then
59   # If current directory is not in $CHROME_SRC, it might be set for other
60   # source tree. If $CHROME_SRC was set correctly and we are in the correct
61   # directory, "${CURRENT_DIR/"${CHROME_SRC}"/}" will be "".
62   # Otherwise, it will equal to "${CURRENT_DIR}"
63   echo "Warning: Current directory is out of CHROME_SRC, it may not be \
64 the one you want."
65   echo "${CHROME_SRC}"
66 fi
67
68 if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then
69   if [[ -z "${TARGET_ARCH}" ]]; then
70     return 1
71   fi
72   sdk_build_init
73 # Sets up environment for building Chromium for Android with source. Expects
74 # android environment setup and lunch.
75 elif [[ -z "$ANDROID_BUILD_TOP" || \
76         -z "$ANDROID_TOOLCHAIN" || \
77         -z "$ANDROID_PRODUCT_OUT" ]]; then
78   echo "Android build environment variables must be set."
79   echo "Please cd to the root of your Android tree and do: "
80   echo "  . build/envsetup.sh"
81   echo "  lunch"
82   echo "Then try this again."
83   echo "Or did you mean NDK/SDK build. Run envsetup.sh without any arguments."
84   return 1
85 elif [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then
86   webview_build_init
87 fi
88
89 # Source a bunch of helper functions
90 . ${CHROME_SRC}/build/android/adb_device_functions.sh
91
92 # Declare Android are cross compile.
93 export GYP_CROSSCOMPILE=1
94
95 # Performs a gyp_chromium run to convert gyp->Makefile for android code.
96 android_gyp() {
97   # This is just a simple wrapper of gyp_chromium, please don't add anything
98   # in this function.
99   (
100     "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" --check "$@"
101   )
102 }