[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 | |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 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 |
[email protected] | 9f7b764 | 2012-10-23 00:29:14 | [diff] [blame] | 9 | # NDK/SDK: ". build/android/envsetup.sh". Environment variable |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 10 | # ANDROID_SDK_BUILD=1 will then be defined and used in the rest of the setup to |
| 11 | # specifiy build type. |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 12 | |
[email protected] | ed5f019 | 2012-11-08 18:11:02 | [diff] [blame] | 13 | # Source functions script. The file is in the same directory as this script. |
| 14 | . "$(dirname $BASH_SOURCE)"/envsetup_functions.sh |
| 15 | |
| 16 | export ANDROID_SDK_BUILD=1 # Default to SDK build. |
| 17 | |
| 18 | process_options "$@" |
| 19 | |
[email protected] | 0d7291e | 2012-10-04 19:16:08 | [diff] [blame] | 20 | # When building WebView as part of Android we can't use the SDK. Other builds |
| 21 | # default to using the SDK. |
[email protected] | 0d7291e | 2012-10-04 19:16:08 | [diff] [blame] | 22 | if [[ "${CHROME_ANDROID_BUILD_WEBVIEW}" -eq 1 ]]; then |
| 23 | export ANDROID_SDK_BUILD=0 |
[email protected] | 0d7291e | 2012-10-04 19:16:08 | [diff] [blame] | 24 | fi |
[email protected] | 4e2e2e2a | 2011-10-25 16:12:24 | [diff] [blame] | 25 | |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 26 | if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then |
| 27 | echo "Using SDK build" |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 28 | fi |
| 29 | |
[email protected] | 8f77362 | 2012-11-15 20:34:29 | [diff] [blame] | 30 | # Get host architecture, and abort if it is 32-bit, unless --try-32 |
| 31 | # is also used. |
| 32 | host_arch=$(uname -m) |
| 33 | case "${host_arch}" in |
| 34 | x86_64) # pass |
| 35 | ;; |
| 36 | i?86) |
| 37 | if [[ -z "${try_32bit_host_build}" ]]; then |
| 38 | echo "ERROR: Android build requires a 64-bit host build machine." |
| 39 | echo "If you really want to try it on this machine, use the \ |
| 40 | --try-32bit-host flag." |
| 41 | echo "Be warned that this may fail horribly at link time, due \ |
| 42 | very large binaries." |
| 43 | return 1 |
| 44 | else |
| 45 | echo "WARNING: 32-bit host build enabled. Here be dragons!" |
| 46 | host_arch=x86 |
| 47 | fi |
| 48 | ;; |
| 49 | *) |
| 50 | echo "ERROR: Unsupported host architecture (${host_arch})." |
| 51 | echo "Try running this script on a Linux/x86_64 machine instead." |
| 52 | return 1 |
| 53 | esac |
| 54 | |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 55 | host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/') |
| 56 | |
| 57 | case "${host_os}" in |
| 58 | "linux") |
[email protected] | 8f77362 | 2012-11-15 20:34:29 | [diff] [blame] | 59 | toolchain_dir="linux-${host_arch}" |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 60 | ;; |
| 61 | "mac") |
[email protected] | 8f77362 | 2012-11-15 20:34:29 | [diff] [blame] | 62 | toolchain_dir="darwin-${host_arch}" |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 63 | ;; |
| 64 | *) |
| 65 | echo "Host platform ${host_os} is not supported" >& 2 |
| 66 | return 1 |
| 67 | esac |
| 68 | |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 69 | CURRENT_DIR="$(readlink -f "$(dirname $BASH_SOURCE)/../../")" |
[email protected] | e3da7822 | 2012-09-11 18:03:52 | [diff] [blame] | 70 | if [[ -z "${CHROME_SRC}" ]]; then |
[email protected] | 4f0dd34 | 2012-02-14 00:41:55 | [diff] [blame] | 71 | # If $CHROME_SRC was not set, assume current directory is CHROME_SRC. |
[email protected] | 1c898c96 | 2012-07-11 10:23:52 | [diff] [blame] | 72 | export CHROME_SRC="${CURRENT_DIR}" |
[email protected] | f724725 | 2012-05-30 07:44:21 | [diff] [blame] | 73 | fi |
| 74 | |
[email protected] | e3da7822 | 2012-09-11 18:03:52 | [diff] [blame] | 75 | if [[ "${CURRENT_DIR/"${CHROME_SRC}"/}" == "${CURRENT_DIR}" ]]; then |
[email protected] | f724725 | 2012-05-30 07:44:21 | [diff] [blame] | 76 | # If current directory is not in $CHROME_SRC, it might be set for other |
| 77 | # source tree. If $CHROME_SRC was set correctly and we are in the correct |
[email protected] | 1c898c96 | 2012-07-11 10:23:52 | [diff] [blame] | 78 | # directory, "${CURRENT_DIR/"${CHROME_SRC}"/}" will be "". |
| 79 | # Otherwise, it will equal to "${CURRENT_DIR}" |
[email protected] | f724725 | 2012-05-30 07:44:21 | [diff] [blame] | 80 | echo "Warning: Current directory is out of CHROME_SRC, it may not be \ |
| 81 | the one you want." |
| 82 | echo "${CHROME_SRC}" |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 83 | fi |
| 84 | |
[email protected] | 456b296 | 2012-08-08 04:47:02 | [diff] [blame] | 85 | # Android sdk platform version to use |
| 86 | export ANDROID_SDK_VERSION=16 |
| 87 | |
[email protected] | e3da7822 | 2012-09-11 18:03:52 | [diff] [blame] | 88 | if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then |
[email protected] | cbb6459 | 2012-10-31 17:25:20 | [diff] [blame] | 89 | if [[ -z "${TARGET_ARCH}" ]]; then |
| 90 | return 1 |
| 91 | fi |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 92 | sdk_build_init |
| 93 | # Sets up environment for building Chromium for Android with source. Expects |
| 94 | # android environment setup and lunch. |
[email protected] | e3da7822 | 2012-09-11 18:03:52 | [diff] [blame] | 95 | elif [[ -z "$ANDROID_BUILD_TOP" || \ |
| 96 | -z "$ANDROID_TOOLCHAIN" || \ |
| 97 | -z "$ANDROID_PRODUCT_OUT" ]]; then |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 98 | echo "Android build environment variables must be set." |
| 99 | echo "Please cd to the root of your Android tree and do: " |
| 100 | echo " . build/envsetup.sh" |
| 101 | echo " lunch" |
| 102 | echo "Then try this again." |
[email protected] | 9f7b764 | 2012-10-23 00:29:14 | [diff] [blame] | 103 | echo "Or did you mean NDK/SDK build. Run envsetup.sh without any arguments." |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 104 | return 1 |
[email protected] | 0d7291e | 2012-10-04 19:16:08 | [diff] [blame] | 105 | elif [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then |
| 106 | webview_build_init |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 107 | fi |
| 108 | |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 109 | # Workaround for valgrind build |
[email protected] | e3da7822 | 2012-09-11 18:03:52 | [diff] [blame] | 110 | if [[ -n "$CHROME_ANDROID_VALGRIND_BUILD" ]]; then |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 111 | # arm_thumb=0 is a workaround for https://bugs.kde.org/show_bug.cgi?id=270709 |
| 112 | DEFINES+=" arm_thumb=0 release_extra_cflags='-fno-inline\ |
| 113 | -fno-omit-frame-pointer -fno-builtin' release_valgrind_build=1\ |
| 114 | release_optimize=1" |
| 115 | fi |
| 116 | |
| 117 | # Source a bunch of helper functions |
| 118 | . ${CHROME_SRC}/build/android/adb_device_functions.sh |
[email protected] | 73919ea | 2012-04-26 00:48:41 | [diff] [blame] | 119 | |
[email protected] | c564ba1 | 2012-06-04 23:39:58 | [diff] [blame] | 120 | ANDROID_GOMA_WRAPPER="" |
| 121 | if [[ -d $GOMA_DIR ]]; then |
| 122 | ANDROID_GOMA_WRAPPER="$GOMA_DIR/gomacc" |
| 123 | fi |
| 124 | export ANDROID_GOMA_WRAPPER |
| 125 | |
[email protected] | e1b37ddd | 2012-09-24 19:24:36 | [diff] [blame] | 126 | # Declare Android are cross compile. |
| 127 | export GYP_CROSSCOMPILE=1 |
| 128 | |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 129 | # Performs a gyp_chromium run to convert gyp->Makefile for android code. |
| 130 | android_gyp() { |
[email protected] | d0245a1 | 2012-10-18 22:08:06 | [diff] [blame] | 131 | # This is just a simple wrapper of gyp_chromium, please don't add anything |
| 132 | # in this function. |
[email protected] | 829a898 | 2012-06-14 08:03:50 | [diff] [blame] | 133 | echo "GYP_GENERATORS set to '$GYP_GENERATORS'" |
[email protected] | 8d9927c4 | 2012-09-24 18:31:58 | [diff] [blame] | 134 | ( |
[email protected] | 8d9927c4 | 2012-09-24 18:31:58 | [diff] [blame] | 135 | "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" --check "$@" |
| 136 | ) |
[email protected] | ec5dcded | 2011-09-26 21:40:38 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | 0115f04 | 2012-07-27 20:36:53 | [diff] [blame] | 139 | # FLOCK needs to be null on system that has no flock |
| 140 | which flock > /dev/null || export FLOCK= |