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