[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 1 | #!/bin/bash |
2 | |||||
[email protected] | 9450628 | 2012-01-06 13:10:07 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 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. Only Android NDK, | ||||
8 | # Revision 6b on Linux or Mac is offically supported. | ||||
9 | # | ||||
10 | # To run this script, the system environment ANDROID_NDK_ROOT must be set | ||||
11 | # to Android NDK's root path. | ||||
12 | # | ||||
13 | # TODO(michaelbai): Develop a standard for NDK/SDK integration. | ||||
14 | # | ||||
15 | # If current path isn't the Chrome's src directory, CHROME_SRC must be set | ||||
16 | # to the Chrome's src directory. | ||||
17 | |||||
18 | if [ ! -d "${ANDROID_NDK_ROOT}" ]; then | ||||
19 | echo "ANDROID_NDK_ROOT must be set to the path of Android NDK, Revision 6b." \ | ||||
20 | >& 2 | ||||
[email protected] | 4e2e2e2a | 2011-10-25 16:12:24 | [diff] [blame] | 21 | echo "which could be installed by" >& 2 |
[email protected] | c4fabbc3 | 2012-03-07 02:22:18 | [diff] [blame] | 22 | echo "<chromium_tree>/src/build/install-build-deps-android-sdk.sh" >& 2 |
[email protected] | 4e2e2e2a | 2011-10-25 16:12:24 | [diff] [blame] | 23 | return 1 |
24 | fi | ||||
25 | |||||
26 | if [ ! -d "${ANDROID_SDK_ROOT}" ]; then | ||||
27 | echo "ANDROID_SDK_ROOT must be set to the path of Android SDK, Android 3.2." \ | ||||
28 | >& 2 | ||||
29 | echo "which could be installed by" >& 2 | ||||
[email protected] | c4fabbc3 | 2012-03-07 02:22:18 | [diff] [blame] | 30 | echo "<chromium_tree>/src/build/install-build-deps-android-sdk.sh" >& 2 |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 31 | return 1 |
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" | ||||
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 | |||||
[email protected] | febd357 | 2012-05-03 09:17:45 | [diff] [blame^] | 48 | # The following defines will affect ARM code generation of both C/C++ compiler |
49 | # and V8 mksnapshot. | ||||
50 | case "${TARGET_PRODUCT-full}" in | ||||
51 | "full") | ||||
52 | DEFINES=" target_arch=arm" | ||||
53 | DEFINES+=" arm_neon=0 armv7=1 arm_thumb=1 arm_fpu=vfpv3-d16" | ||||
54 | toolchain_arch="arm-linux-androideabi-4.4.3" | ||||
55 | ;; | ||||
56 | *x86*) | ||||
57 | DEFINES=" target_arch=ia32 use_libffmpeg=0" | ||||
58 | toolchain_arch="x86-4.4.3" | ||||
59 | ;; | ||||
60 | *) | ||||
61 | echo "TARGET_PRODUCT: ${TARGET_PRODUCT} is not supported." >& 2 | ||||
62 | return 1 | ||||
63 | esac | ||||
64 | |||||
65 | toolchain_path="${ANDROID_NDK_ROOT}/toolchains/${toolchain_arch}/prebuilt/" | ||||
66 | export ANDROID_TOOLCHAIN="${toolchain_path}/${toolchain_dir}/bin/" | ||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 67 | |
[email protected] | 6fa1e7ef | 2012-03-14 11:24:04 | [diff] [blame] | 68 | export ANDROID_SDK_VERSION="15" |
69 | |||||
[email protected] | d9f9695 | 2012-04-19 21:02:09 | [diff] [blame] | 70 | # Needed by android antfiles when creating apks. |
71 | export ANDROID_SDK_HOME=${ANDROID_SDK_ROOT} | ||||
72 | |||||
73 | # Add Android SDK/NDK tools to system path. | ||||
74 | export PATH=$PATH:${ANDROID_NDK_ROOT} | ||||
75 | export PATH=$PATH:${ANDROID_SDK_ROOT}/tools | ||||
76 | export PATH=$PATH:${ANDROID_SDK_ROOT}/platform-tools | ||||
[email protected] | 4e2e2e2a | 2011-10-25 16:12:24 | [diff] [blame] | 77 | |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 78 | if [ ! -d "${ANDROID_TOOLCHAIN}" ]; then |
79 | echo "Can not find Android toolchain in ${ANDROID_TOOLCHAIN}." >& 2 | ||||
80 | echo "The NDK version might be wrong." >& 2 | ||||
81 | return 1 | ||||
82 | fi | ||||
83 | |||||
84 | if [ -z "${CHROME_SRC}" ]; then | ||||
[email protected] | 4f0dd34 | 2012-02-14 00:41:55 | [diff] [blame] | 85 | # If $CHROME_SRC was not set, assume current directory is CHROME_SRC. |
86 | export CHROME_SRC=$(readlink -f .) | ||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 87 | fi |
88 | |||||
89 | if [ ! -d "${CHROME_SRC}" ]; then | ||||
90 | echo "CHROME_SRC must be set to the path of Chrome source code." >& 2 | ||||
91 | return 1 | ||||
92 | fi | ||||
93 | |||||
[email protected] | 73919ea | 2012-04-26 00:48:41 | [diff] [blame] | 94 | # Add Chromium Android development scripts to system path. |
95 | # Must be after CHROME_SRC is set. | ||||
96 | export PATH=$PATH:${CHROME_SRC}/build/android | ||||
97 | |||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 98 | # Performs a gyp_chromium run to convert gyp->Makefile for android code. |
99 | android_gyp() { | ||||
[email protected] | d10e2cc | 2012-03-20 10:45:27 | [diff] [blame] | 100 | GOMA_WRAPPER="" |
101 | if [[ -d $GOMA_DIR ]]; then | ||||
102 | GOMA_WRAPPER="$GOMA_DIR/gomacc" | ||||
103 | fi | ||||
104 | # Ninja requires "*_target" for target builds. | ||||
105 | GOMA_WRAPPER=${GOMA_WRAPPER} \ | ||||
106 | CC_target=$(basename ${ANDROID_TOOLCHAIN}/*-gcc) \ | ||||
107 | CXX_target=$(basename ${ANDROID_TOOLCHAIN}/*-g++) \ | ||||
108 | LINK_target=$(basename ${ANDROID_TOOLCHAIN}/*-gcc) \ | ||||
109 | AR_target=$(basename ${ANDROID_TOOLCHAIN}/*-ar) \ | ||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 110 | "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" |
111 | } | ||||
112 | |||||
[email protected] | d10e2cc | 2012-03-20 10:45:27 | [diff] [blame] | 113 | export OBJCOPY=$(echo ${ANDROID_TOOLCHAIN}/*-objcopy) |
114 | export STRIP=$(echo ${ANDROID_TOOLCHAIN}/*-strip) | ||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 115 | |
116 | # The set of GYP_DEFINES to pass to gyp. Use 'readlink -e' on directories | ||||
117 | # to canonicalize them (remove double '/', remove trailing '/', etc). | ||||
[email protected] | febd357 | 2012-05-03 09:17:45 | [diff] [blame^] | 118 | DEFINES+=" OS=android" |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 119 | DEFINES+=" android_build_type=0" # Currently, Only '0' is supportted. |
120 | DEFINES+=" host_os=${host_os}" | ||||
121 | DEFINES+=" linux_fpic=1" | ||||
122 | DEFINES+=" release_optimize=s" | ||||
123 | DEFINES+=" linux_use_tcmalloc=0" | ||||
124 | DEFINES+=" disable_nacl=1" | ||||
125 | DEFINES+=" remoting=0" | ||||
126 | DEFINES+=" p2p_apis=0" | ||||
127 | DEFINES+=" enable_touch_events=1" | ||||
[email protected] | 3b0836d4 | 2011-11-18 13:57:48 | [diff] [blame] | 128 | DEFINES+=" build_ffmpegsumo=0" |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 129 | # TODO(bulach): use "shared_libraries" once the transition from executable |
130 | # is over. | ||||
131 | DEFINES+=" gtest_target_type=executable" | ||||
132 | DEFINES+=" branding=Chromium" | ||||
133 | |||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 134 | export GYP_DEFINES="${DEFINES}" |
135 | |||||
136 | # Use the "android" flavor of the Makefile generator for both Linux and OS X. | ||||
137 | export GYP_GENERATORS="make-android" | ||||
138 | |||||
[email protected] | 4b397aa | 2011-11-28 23:07:53 | [diff] [blame] | 139 | # Use our All target as the default |
140 | export GYP_GENERATOR_FLAGS="${GYP_GENERATOR_FLAGS} default_target=All" | ||||
141 | |||||
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 142 | # We want to use our version of "all" targets. |
143 | export CHROMIUM_GYP_FILE="${CHROME_SRC}/build/all_android.gyp" |