|
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 # Sets up environment for building Chromium on Android. It can either be |
|
8 # compiled with the Android tree or using the Android SDK/NDK. To build with |
|
9 # NDK/SDK: ". build/android/envsetup.sh --sdk". Environment variable |
|
10 # ANDROID_SDK_BUILD=1 will then be defined and used in the rest of the setup to |
|
11 # specifiy build type. |
|
12 |
|
13 # When building WebView as part of Android we can't use the SDK. Other builds |
|
14 # default to using the SDK. |
|
15 # NOTE(yfriedman): This looks unnecessary but downstream the default value |
|
16 # should be 0 until all builds switch to SDK/NDK. |
|
17 if [[ "${CHROME_ANDROID_BUILD_WEBVIEW}" -eq 1 ]]; then |
|
18 export ANDROID_SDK_BUILD=0 |
|
19 else |
|
20 export ANDROID_SDK_BUILD=1 |
|
21 fi |
|
22 # Loop over args in case we add more arguments in the future. |
|
23 while [ "$1" != "" ]; do |
|
24 case $1 in |
|
25 -s | --sdk ) export ANDROID_SDK_BUILD=1 ; shift ;; |
|
26 * ) shift ; break ;; |
|
27 esac |
|
28 done |
|
29 |
|
30 if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then |
|
31 echo "Using SDK build" |
|
32 fi |
|
33 |
|
34 host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/') |
|
35 |
|
36 case "${host_os}" in |
|
37 "linux") |
|
38 toolchain_dir="linux-x86_64" |
|
39 ;; |
|
40 "mac") |
|
41 toolchain_dir="darwin-x86" |
|
42 ;; |
|
43 *) |
|
44 echo "Host platform ${host_os} is not supported" >& 2 |
|
45 return 1 |
|
46 esac |
|
47 |
|
48 CURRENT_DIR="$(readlink -f "$(dirname $BASH_SOURCE)/../../")" |
|
49 if [[ -z "${CHROME_SRC}" ]]; then |
|
50 # If $CHROME_SRC was not set, assume current directory is CHROME_SRC. |
|
51 export CHROME_SRC="${CURRENT_DIR}" |
|
52 fi |
|
53 |
|
54 if [[ "${CURRENT_DIR/"${CHROME_SRC}"/}" == "${CURRENT_DIR}" ]]; then |
|
55 # If current directory is not in $CHROME_SRC, it might be set for other |
|
56 # source tree. If $CHROME_SRC was set correctly and we are in the correct |
|
57 # directory, "${CURRENT_DIR/"${CHROME_SRC}"/}" will be "". |
|
58 # Otherwise, it will equal to "${CURRENT_DIR}" |
|
59 echo "Warning: Current directory is out of CHROME_SRC, it may not be \ |
|
60 the one you want." |
|
61 echo "${CHROME_SRC}" |
|
62 fi |
|
63 |
|
64 # Android sdk platform version to use |
|
65 export ANDROID_SDK_VERSION=16 |
|
66 |
|
67 # Source functions script. The file is in the same directory as this script. |
|
68 . "$(dirname $BASH_SOURCE)"/envsetup_functions.sh |
|
69 |
|
70 if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then |
|
71 sdk_build_init |
|
72 # Sets up environment for building Chromium for Android with source. Expects |
|
73 # android environment setup and lunch. |
|
74 elif [[ -z "$ANDROID_BUILD_TOP" || \ |
|
75 -z "$ANDROID_TOOLCHAIN" || \ |
|
76 -z "$ANDROID_PRODUCT_OUT" ]]; then |
|
77 echo "Android build environment variables must be set." |
|
78 echo "Please cd to the root of your Android tree and do: " |
|
79 echo " . build/envsetup.sh" |
|
80 echo " lunch" |
|
81 echo "Then try this again." |
|
82 echo "Or did you mean NDK/SDK build. Run envsetup.sh with --sdk argument." |
|
83 return 1 |
|
84 elif [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then |
|
85 webview_build_init |
|
86 else |
|
87 non_sdk_build_init |
|
88 fi |
|
89 |
|
90 # Workaround for valgrind build |
|
91 if [[ -n "$CHROME_ANDROID_VALGRIND_BUILD" ]]; then |
|
92 # arm_thumb=0 is a workaround for https://bugs.kde.org/show_bug.cgi?id=270709 |
|
93 DEFINES+=" arm_thumb=0 release_extra_cflags='-fno-inline\ |
|
94 -fno-omit-frame-pointer -fno-builtin' release_valgrind_build=1\ |
|
95 release_optimize=1" |
|
96 fi |
|
97 |
|
98 # Source a bunch of helper functions |
|
99 . ${CHROME_SRC}/build/android/adb_device_functions.sh |
|
100 |
|
101 ANDROID_GOMA_WRAPPER="" |
|
102 if [[ -d $GOMA_DIR ]]; then |
|
103 ANDROID_GOMA_WRAPPER="$GOMA_DIR/gomacc" |
|
104 fi |
|
105 export ANDROID_GOMA_WRAPPER |
|
106 |
|
107 # Declare Android are cross compile. |
|
108 export GYP_CROSSCOMPILE=1 |
|
109 |
|
110 export CXX_target="${ANDROID_GOMA_WRAPPER} \ |
|
111 $(echo -n ${ANDROID_TOOLCHAIN}/*-g++)" |
|
112 |
|
113 # Performs a gyp_chromium run to convert gyp->Makefile for android code. |
|
114 android_gyp() { |
|
115 echo "GYP_GENERATORS set to '$GYP_GENERATORS'" |
|
116 # http://crbug.com/143889. |
|
117 # In case we are doing a Clang build, we have to unset CC_target and |
|
118 # CXX_target. Otherwise GYP ends up generating a gcc build (although we set |
|
119 # 'clang' to 1). This behavior was introduced by |
|
120 # 54d2f6fe6d8a7b9d9786bd1f8540df6b4f46b83f in GYP. |
|
121 ( |
|
122 # Fork to avoid side effects on the user's environment variables. |
|
123 if echo "$GYP_DEFINES" | grep -qE '(clang|asan)'; then |
|
124 if echo "$CXX_target" | grep -q g++; then |
|
125 unset CXX_target |
|
126 fi |
|
127 fi |
|
128 "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" --check "$@" |
|
129 ) |
|
130 } |
|
131 |
|
132 # FLOCK needs to be null on system that has no flock |
|
133 which flock > /dev/null || export FLOCK= |