Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / build / android / envsetup_functions.sh
1 #!/bin/bash
2
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.
6
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.
11
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
20
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
24
25   # The set of GYP_DEFINES to pass to gyp.
26   DEFINES="OS=android"
27
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"
35   fi
36
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"
41   fi
42
43   # The following defines will affect ARM code generation of both C/C++ compiler
44   # and V8 mksnapshot.
45   case "${TARGET_ARCH}" in
46     "arm")
47       DEFINES+=" target_arch=arm"
48       ;;
49     "x86")
50       DEFINES+=" target_arch=ia32"
51       ;;
52     "mips")
53       DEFINES+=" target_arch=mipsel"
54       ;;
55     *)
56       echo "TARGET_ARCH: ${TARGET_ARCH} is not supported." >& 2
57       print_usage
58       return 1
59   esac
60 }
61
62
63 ################################################################################
64 # Prints out help message on usage.
65 ################################################################################
66 print_usage() {
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
71 }
72
73 ################################################################################
74 # Process command line options.
75 ################################################################################
76 process_options() {
77   host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
78   while [[ -n $1 ]]; do
79     case "$1" in
80       --target-arch=*)
81         target_arch="$(echo "$1" | sed 's/^[^=]*=//')"
82         ;;
83       --host-os=*)
84         host_os="$(echo "$1" | sed 's/^[^=]*=//')"
85         ;;
86       --help)
87         print_usage
88         return 1
89         ;;
90       *)
91         # Ignore other command line options
92         echo "Unknown option: $1"
93         ;;
94     esac
95     shift
96   done
97
98   # Sets TARGET_ARCH. Defaults to arm if not specified.
99   TARGET_ARCH=${target_arch:-arm}
100 }
101
102 ################################################################################
103 # Initializes environment variables for NDK/SDK build.
104 ################################################################################
105 sdk_build_init() {
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/"
111   fi
112   if [[ -z "${ANDROID_SDK_ROOT}" || ! -d "${ANDROID_SDK_ROOT}" ]]; then
113     export ANDROID_SDK_ROOT="${CHROME_SRC}/third_party/android_tools/sdk/"
114   fi
115
116   common_vars_defines
117
118   export GYP_DEFINES="${DEFINES}"
119
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." \
124         >& 2
125     echo "Try . build/android/envsetup.sh instead." >& 2
126     return 1
127   fi
128 }
129
130 ################################################################################
131 # To build WebView, we use the Android build system and build inside an Android
132 # source tree.
133 #############################################################################
134 webview_build_init() {
135   # Use the latest API in the AOSP prebuilts directory (change with AOSP roll).
136   android_sdk_version=18
137
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}
141
142   common_vars_defines
143
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}')")
150   case "${host_os}" in
151     "linux")
152       ANDROID_SDK_TOOLS=$(python -c \
153           "import os.path; \
154           print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/linux', \
155           '${ANDROID_BUILD_TOP}')")
156       ;;
157     "mac")
158       ANDROID_SDK_TOOLS=$(python -c \
159           "import os.path; \
160           print os.path.relpath('${ANDROID_SDK_ROOT}/../tools/darwin', \
161           '${ANDROID_BUILD_TOP}')")
162       ;;
163   esac
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"
175   fi
176   export GYP_DEFINES="${DEFINES}"
177 }