michael@0: #!/bin/bash michael@0: michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: # Sets up environment for building Chromium on Android. It can either be michael@0: # compiled with the Android tree or using the Android SDK/NDK. To build with michael@0: # NDK/SDK: ". build/android/envsetup.sh --sdk". Environment variable michael@0: # ANDROID_SDK_BUILD=1 will then be defined and used in the rest of the setup to michael@0: # specifiy build type. michael@0: michael@0: # When building WebView as part of Android we can't use the SDK. Other builds michael@0: # default to using the SDK. michael@0: # NOTE(yfriedman): This looks unnecessary but downstream the default value michael@0: # should be 0 until all builds switch to SDK/NDK. michael@0: if [[ "${CHROME_ANDROID_BUILD_WEBVIEW}" -eq 1 ]]; then michael@0: export ANDROID_SDK_BUILD=0 michael@0: else michael@0: export ANDROID_SDK_BUILD=1 michael@0: fi michael@0: # Loop over args in case we add more arguments in the future. michael@0: while [ "$1" != "" ]; do michael@0: case $1 in michael@0: -s | --sdk ) export ANDROID_SDK_BUILD=1 ; shift ;; michael@0: * ) shift ; break ;; michael@0: esac michael@0: done michael@0: michael@0: if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then michael@0: echo "Using SDK build" michael@0: fi michael@0: michael@0: host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/') michael@0: michael@0: case "${host_os}" in michael@0: "linux") michael@0: toolchain_dir="linux-x86_64" michael@0: ;; michael@0: "mac") michael@0: toolchain_dir="darwin-x86" michael@0: ;; michael@0: *) michael@0: echo "Host platform ${host_os} is not supported" >& 2 michael@0: return 1 michael@0: esac michael@0: michael@0: CURRENT_DIR="$(readlink -f "$(dirname $BASH_SOURCE)/../../")" michael@0: if [[ -z "${CHROME_SRC}" ]]; then michael@0: # If $CHROME_SRC was not set, assume current directory is CHROME_SRC. michael@0: export CHROME_SRC="${CURRENT_DIR}" michael@0: fi michael@0: michael@0: if [[ "${CURRENT_DIR/"${CHROME_SRC}"/}" == "${CURRENT_DIR}" ]]; then michael@0: # If current directory is not in $CHROME_SRC, it might be set for other michael@0: # source tree. If $CHROME_SRC was set correctly and we are in the correct michael@0: # directory, "${CURRENT_DIR/"${CHROME_SRC}"/}" will be "". michael@0: # Otherwise, it will equal to "${CURRENT_DIR}" michael@0: echo "Warning: Current directory is out of CHROME_SRC, it may not be \ michael@0: the one you want." michael@0: echo "${CHROME_SRC}" michael@0: fi michael@0: michael@0: # Android sdk platform version to use michael@0: export ANDROID_SDK_VERSION=16 michael@0: michael@0: # Source functions script. The file is in the same directory as this script. michael@0: . "$(dirname $BASH_SOURCE)"/envsetup_functions.sh michael@0: michael@0: if [[ "${ANDROID_SDK_BUILD}" -eq 1 ]]; then michael@0: sdk_build_init michael@0: # Sets up environment for building Chromium for Android with source. Expects michael@0: # android environment setup and lunch. michael@0: elif [[ -z "$ANDROID_BUILD_TOP" || \ michael@0: -z "$ANDROID_TOOLCHAIN" || \ michael@0: -z "$ANDROID_PRODUCT_OUT" ]]; then michael@0: echo "Android build environment variables must be set." michael@0: echo "Please cd to the root of your Android tree and do: " michael@0: echo " . build/envsetup.sh" michael@0: echo " lunch" michael@0: echo "Then try this again." michael@0: echo "Or did you mean NDK/SDK build. Run envsetup.sh with --sdk argument." michael@0: return 1 michael@0: elif [[ -n "$CHROME_ANDROID_BUILD_WEBVIEW" ]]; then michael@0: webview_build_init michael@0: else michael@0: non_sdk_build_init michael@0: fi michael@0: michael@0: # Workaround for valgrind build michael@0: if [[ -n "$CHROME_ANDROID_VALGRIND_BUILD" ]]; then michael@0: # arm_thumb=0 is a workaround for https://bugs.kde.org/show_bug.cgi?id=270709 michael@0: DEFINES+=" arm_thumb=0 release_extra_cflags='-fno-inline\ michael@0: -fno-omit-frame-pointer -fno-builtin' release_valgrind_build=1\ michael@0: release_optimize=1" michael@0: fi michael@0: michael@0: # Source a bunch of helper functions michael@0: . ${CHROME_SRC}/build/android/adb_device_functions.sh michael@0: michael@0: ANDROID_GOMA_WRAPPER="" michael@0: if [[ -d $GOMA_DIR ]]; then michael@0: ANDROID_GOMA_WRAPPER="$GOMA_DIR/gomacc" michael@0: fi michael@0: export ANDROID_GOMA_WRAPPER michael@0: michael@0: # Declare Android are cross compile. michael@0: export GYP_CROSSCOMPILE=1 michael@0: michael@0: export CXX_target="${ANDROID_GOMA_WRAPPER} \ michael@0: $(echo -n ${ANDROID_TOOLCHAIN}/*-g++)" michael@0: michael@0: # Performs a gyp_chromium run to convert gyp->Makefile for android code. michael@0: android_gyp() { michael@0: echo "GYP_GENERATORS set to '$GYP_GENERATORS'" michael@0: # http://crbug.com/143889. michael@0: # In case we are doing a Clang build, we have to unset CC_target and michael@0: # CXX_target. Otherwise GYP ends up generating a gcc build (although we set michael@0: # 'clang' to 1). This behavior was introduced by michael@0: # 54d2f6fe6d8a7b9d9786bd1f8540df6b4f46b83f in GYP. michael@0: ( michael@0: # Fork to avoid side effects on the user's environment variables. michael@0: if echo "$GYP_DEFINES" | grep -qE '(clang|asan)'; then michael@0: if echo "$CXX_target" | grep -q g++; then michael@0: unset CXX_target michael@0: fi michael@0: fi michael@0: "${CHROME_SRC}/build/gyp_chromium" --depth="${CHROME_SRC}" --check "$@" michael@0: ) michael@0: } michael@0: michael@0: # FLOCK needs to be null on system that has no flock michael@0: which flock > /dev/null || export FLOCK=