android_setup.sh revision d165de44c89f0dcc88f0a196698744e08662e33f
1function exportVar { 2 NAME=$1 3 VALUE=$2 4 echo export $NAME=\"$VALUE\" 5 export $NAME="$VALUE" 6} 7 8SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 9 10# A valid Android SDK installation is required to build the sample app. 11if [ -z "$ANDROID_SDK_ROOT" ]; then 12 ANDROID_TOOL=$(which android 2>/dev/null) 13 if [ -z "$ANDROID_TOOL" ]; then 14 echo "ERROR: Please define ANDROID_SDK_ROOT in your environment to point" 15 echo " to a valid Android SDK installation." 16 return 1 17 fi 18 ANDROID_SDK_ROOT=$(cd $(dirname "$ANDROID_TOOL")/.. && pwd) 19 exportVar ANDROID_SDK_ROOT "$ANDROID_SDK_ROOT" 20fi 21 22# ant is required to be installed on your system and in your PATH 23ant -version &> /dev/null 24if [[ "$?" != "0" ]]; then 25 echo "ERROR: Unable to find ant. Please install it before proceeding." 26 exit 1 27fi 28 29# check to see that gclient sync ran successfully 30THIRD_PARTY_EXTERNAL_DIR=${SCRIPT_DIR}/../third_party/externals 31if [ ! -d "$ANDROID_TOOLCHAIN" ]; then 32 echo "" 33 echo "ERROR: Unable to find the required third_party dependencies needed to build." 34 echo " To fix this add the following line to your .gclient file and run 'gclient sync'" 35 echo " target_os = ['android']" 36 echo "" 37 exit 1; 38fi 39 40# determine the toolchain that we will be using 41API_LEVEL=14 42 43if [[ -z "$NDK_REV" ]]; 44then 45 NDK_REV="8d" 46fi 47 48if [[ -z "$ANDROID_ARCH" ]]; 49then 50 ANDROID_ARCH="arm" 51fi 52 53TOOLCHAIN_DIR=${SCRIPT_DIR}/../toolchains 54if [ $(uname) == "Linux" ]; then 55 echo "Using Linux toolchain." 56 TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL 57elif [ $(uname) == "Darwin" ]; then 58 echo "Using Mac toolchain." 59 TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-mac_v$API_LEVEL 60else 61 echo "Could not automatically determine toolchain! Defaulting to Linux." 62 TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL 63fi 64exportVar ANDROID_TOOLCHAIN ${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE}/bin 65 66# if the toolchain doesn't exist on your machine then we need to fetch it 67if [ ! -d "$ANDROID_TOOLCHAIN" ]; then 68 # gsutil must be installed on your system and in your PATH 69 gsutil version &> /dev/null 70 if [[ "$?" != "0" ]]; then 71 echo "ERROR: Unable to find gsutil. Please install it before proceeding." 72 exit 1 73 fi 74 # create the toolchain directory if needed 75 if [ ! -d "$TOOLCHAIN_DIR" ]; then 76 mkdir $TOOLCHAIN_DIR 77 fi 78 # enter the toolchain directory then download, unpack, and remove the tarball 79 pushd $TOOLCHAIN_DIR 80 TARBALL=ndk-r$NDK_REV-v$API_LEVEL.tgz 81 gsutil cp gs://chromium-skia-gm/android-toolchains/$TARBALL $TARBALL 82 echo "Untarring $TOOLCHAIN_TYPE from $TARBALL." 83 tar -xzf $TARBALL $TOOLCHAIN_TYPE 84 echo "Removing $TARBALL" 85 rm $TARBALL 86 popd 87fi 88 89if [ ! -d "$ANDROID_TOOLCHAIN" ]; then 90 echo "ERROR: unable to download/setup the required toolchain (${TOOLCHAIN_TYPE})" 91 return 1; 92fi 93 94echo "The build is targeting NDK API level $API_LEVEL for use on Android 4.0 (NDK Revision $NDK_REV) and above" 95 96LS="/bin/ls" # Use directly to avoid any 'ls' alias that might be defined. 97GCC=$($LS $ANDROID_TOOLCHAIN/*-gcc | head -n1) 98if [ -z "$GCC" ]; then 99 echo "ERROR: Could not find Android cross-compiler in: $ANDROID_TOOLCHAIN" 100 return 1 101fi 102 103# Remove the '-gcc' at the end to get the full toolchain prefix 104ANDROID_TOOLCHAIN_PREFIX=${GCC%%-gcc} 105 106exportVar AR "$ANDROID_TOOLCHAIN_PREFIX-ar" 107if [[ -z "$ANDROID_MAKE_CCACHE" ]]; then 108 exportVar CC "$ANDROID_TOOLCHAIN_PREFIX-gcc" 109 exportVar CXX "$ANDROID_TOOLCHAIN_PREFIX-g++" 110 exportVar LINK "$ANDROID_TOOLCHAIN_PREFIX-gcc" 111else 112 exportVar CC "$ANDROID_MAKE_CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" 113 exportVar CXX "$ANDROID_MAKE_CCACHE $ANDROID_TOOLCHAIN_PREFIX-g++" 114 exportVar LINK "$ANDROID_MAKE_CCACHE $ANDROID_TOOLCHAIN_PREFIX-gcc" 115fi 116exportVar RANLIB "$ANDROID_TOOLCHAIN_PREFIX-ranlib" 117exportVar OBJCOPY "$ANDROID_TOOLCHAIN_PREFIX-objcopy" 118exportVar STRIP "$ANDROID_TOOLCHAIN_PREFIX-strip" 119 120# Helper function to configure the GYP defines to the appropriate values 121# based on the target device. 122setup_device() { 123 DEFINES="OS=android" 124 DEFINES="${DEFINES} host_os=$(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')" 125 DEFINES="${DEFINES} skia_os=android" 126 DEFINES="${DEFINES} android_base=${SCRIPT_DIR}/.." 127 DEFINES="${DEFINES} android_toolchain=${TOOLCHAIN_TYPE}" 128 129 # Setup the build variation depending on the target device 130 TARGET_DEVICE="$1" 131 132 if [ -z "$TARGET_DEVICE" ]; then 133 echo "INFO: no target device type was specified so using the default 'arm_v7'" 134 TARGET_DEVICE="arm_v7" 135 fi 136 137 case $TARGET_DEVICE in 138 nexus_s) 139 DEFINES="${DEFINES} skia_arch_type=arm arm_neon=1 armv7=1 arm_thumb=0" 140 DEFINES="${DEFINES} skia_texture_cache_mb_limit=24" 141 ;; 142 nexus_4 | nexus_7 | nexus_10) 143 DEFINES="${DEFINES} skia_arch_type=arm arm_neon=1 armv7=1 arm_thumb=0" 144 ;; 145 xoom) 146 DEFINES="${DEFINES} skia_arch_type=arm arm_neon=0 armv7=1 arm_thumb=0" 147 ;; 148 galaxy_nexus) 149 DEFINES="${DEFINES} skia_arch_type=arm arm_neon=1 armv7=1 arm_thumb=0" 150 DEFINES="${DEFINES} skia_texture_cache_mb_limit=32" 151 ;; 152 razr_i) 153 DEFINES="${DEFINES} skia_arch_type=x86 skia_arch_width=32" 154 DEFINES="${DEFINES} skia_texture_cache_mb_limit=32" 155 ;; 156 arm_v7) 157 DEFINES="${DEFINES} skia_arch_type=arm arm_neon_optional=1 armv7=1 arm_thumb=0" 158 ;; 159 arm_v7_thumb) 160 DEFINES="${DEFINES} skia_arch_type=arm arm_neon_optional=1 armv7=1 arm_thumb=1" 161 ;; 162 arm) 163 DEFINES="${DEFINES} skia_arch_type=arm arm_neon=0 armv7=0 arm_thumb=0" 164 ;; 165 arm_thumb) 166 DEFINES="${DEFINES} skia_arch_type=arm arm_neon=0 armv7=0 arm_thumb=1" 167 ;; 168 x86) 169 DEFINES="${DEFINES} skia_arch_type=x86 skia_arch_width=32" 170 DEFINES="${DEFINES} skia_texture_cache_mb_limit=32" 171 ;; 172 *) 173 echo -n "ERROR: unknown device specified ($TARGET_DEVICE), valid values: " 174 echo "nexus_[s,4,7,10] xoom galaxy_nexus arm arm_thumb arm_v7 arm_v7_thumb x86" 175 return 1; 176 ;; 177 esac 178 179 echo "The build is targeting the device: $TARGET_DEVICE" 180 181 exportVar GYP_DEFINES "$DEFINES" 182 exportVar SKIA_OUT "out/config/android-${TARGET_DEVICE}" 183} 184 185# Run the setup device command initially as a convenience for the user 186#setup_device 187#echo "** The device has been setup for you by default. If you would like to **" 188#echo "** use a different device then run the setup_device function with the **" 189#echo "** appropriate input. **" 190 191# Use the "android" flavor of the Makefile generator for both Linux and OS X. 192exportVar GYP_GENERATORS "make-android" 193 194# Helper function so that when we run "make" to build for clank it exports 195# the toolchain variables to make. 196#make_android() { 197# CC="$CROSS_CC" CXX="$CROSS_CXX" LINK="$CROSS_LINK" \ 198# AR="$CROSS_AR" RANLIB="$CROSS_RANLIB" \ 199# command make $* 200#} 201