1#!/bin/bash 2 3# We are currently in frameworks/rs, so compute our top-level directory. 4MY_ANDROID_DIR=$PWD/../../ 5cd $MY_ANDROID_DIR 6 7if [ $OSTYPE == 'darwin14' ]; 8then 9 10 DARWIN=1 11 SHORT_OSNAME=darwin 12 SONAME=dylib 13 # Only build arm on darwin. 14 TARGETS=(arm) 15 SYS_NAMES=(generic) 16 NUM_CORES=`sysctl -n hw.ncpu` 17 18else 19 20 DARWIN=0 21 SHORT_OSNAME=linux 22 SONAME=so 23 # Target architectures and their system library names. 24 TARGETS=(arm mips x86 arm64) 25 SYS_NAMES=(generic generic_mips generic_x86 generic_arm64) 26 NUM_CORES=`cat /proc/cpuinfo | grep processor | tail -n 1 | cut -f 2 -d :` 27 NUM_CORES=$(($NUM_CORES+1)) 28 29fi 30 31echo "Using $NUM_CORES cores" 32 33# Turn off the build cache and make sure we build all of LLVM from scratch. 34export ANDROID_USE_BUILDCACHE=false 35export FORCE_BUILD_LLVM_COMPONENTS=true 36 37# Ensure that we have constructed the latest "bcc" for the host. Without 38# this variable, we don't build the .so files, hence we never construct the 39# actual required compiler pieces. 40export FORCE_BUILD_RS_COMPAT=true 41 42# Disable JACK when buiding RS prebuilts. Without this variable, we won't be 43# able to get classes.jar. 44export UPDATE_RS_PREBUILTS_DISABLE_JACK=true 45 46# ANDROID_HOST_OUT is where the new prebuilts will be constructed/copied from. 47ANDROID_HOST_OUT=$MY_ANDROID_DIR/out/host/$SHORT_OSNAME-x86/ 48 49# HOST_LIB_DIR allows us to pick up the built librsrt_*.bc libraries. 50HOST_LIB_DIR=$ANDROID_HOST_OUT/lib 51 52# HOST_LIB64_DIR 53HOST_LIB64_DIR=$ANDROID_HOST_OUT/lib64 54 55# PREBUILTS_DIR is where we want to copy our new files to. 56PREBUILTS_DIR=$MY_ANDROID_DIR/prebuilts/sdk/ 57 58print_usage() { 59 echo "USAGE: $0 [-h|--help] [-n|--no-build] [-x]" 60 echo "OPTIONS:" 61 echo " -h, --help : Display this help message." 62 echo " -n, --no-build : Skip the build step and just copy files." 63 echo " -x : Display commands before they are executed." 64} 65 66build_rs_libs() { 67 echo Building for target $1 68 lunch $1 69 # Build the RS runtime libraries. 70 cd $MY_ANDROID_DIR/frameworks/rs/driver/runtime && mma -j$NUM_CORES && cd - || exit 1 71 # Build a sample support application to ensure that all the pieces are up to date. 72 cd $MY_ANDROID_DIR/frameworks/rs/java/tests/RSTest_CompatLib/ && mma -j$NUM_CORES && cd - || exit 2 73 # Build libcompiler-rt.a 74 cd $MY_ANDROID_DIR/external/compiler-rt && mma -j$NUM_CORES && cd - || exit 3 75 # Build the blas libraries. 76 cd $MY_ANDROID_DIR/external/cblas && mma -j$NUM_CORES && cd - || exit 4 77} 78 79# Build everything by default 80build_rs=1 81 82while [ $# -gt 0 ]; do 83 case "$1" in 84 -h|--help) 85 print_usage 86 exit 0 87 ;; 88 -n|--no-build) 89 build_rs=0 90 ;; 91 -x) 92 # set lets us enable bash -x mode. 93 set -x 94 ;; 95 *) 96 echo Unknown argument: "$1" 97 print_usage 98 exit 99 99 break 100 ;; 101 esac 102 shift 103done 104 105if [ $build_rs -eq 1 ]; then 106 107 echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 108 echo !!! BUILDING RS PREBUILTS !!! 109 echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 110 111 source build/envsetup.sh 112 113 for t in ${TARGETS[@]}; do 114 build_rs_libs aosp_${t}-userdebug 115 done 116 117 echo DONE BUILDING RS PREBUILTS 118 119else 120 121 echo SKIPPING BUILD OF RS PREBUILTS 122 123fi 124 125DATE=`date +%Y%m%d` 126 127cd $PREBUILTS_DIR || exit 3 128repo start pb_$DATE . 129 130# Don't copy device prebuilts on Darwin. We don't need/use them. 131if [ $DARWIN -eq 0 ]; then 132 for i in $(seq 0 $((${#TARGETS[@]} - 1))); do 133 t=${TARGETS[$i]} 134 sys_name=${SYS_NAMES[$i]} 135 case "$sys_name" in 136 *64) 137 sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib64 138 ;; 139 *) 140 sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib 141 ;; 142 esac 143 obj_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/lib 144 obj_static_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/STATIC_LIBRARIES 145 146 for a in `find renderscript/lib/$t -name \*.so`; do 147 file=`basename $a` 148 cp `find $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 4 149 done 150 151 for a in `find renderscript/lib/$t -name \*.bc`; do 152 file=`basename $a` 153 cp `find $HOST_LIB_DIR $HOST_LIB64_DIR $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 5 154 done 155 156 for a in `find renderscript/lib/$t -name \*.a`; do 157 file=`basename $a` 158 cp `find $obj_static_lib_dir -name $file | head -1` $a || exit 4 159 done 160 161 done 162 163 # javalib.jar 164 cp $MY_ANDROID_DIR/out/target/common/obj/JAVA_LIBRARIES/android-support-v8-renderscript_intermediates/classes.jar renderscript/lib/javalib.jar 165 166fi 167 168# Copy header files for compilers 169cp $MY_ANDROID_DIR/external/clang/lib/Headers/*.h renderscript/clang-include 170cp $MY_ANDROID_DIR/frameworks/rs/scriptc/* renderscript/include 171 172 173# Host-specific tools (bin/ and lib/) 174TOOLS_BIN=" 175bcc_compat 176llvm-rs-cc 177" 178 179TOOLS_LIB=" 180libbcc.$SONAME 181libbcinfo.$SONAME 182libclang.$SONAME 183libc++.$SONAME 184libLLVM.$SONAME 185" 186 187TOOLS_LIB32="libc++.$SONAME" 188 189for a in $TOOLS_BIN; do 190 cp $ANDROID_HOST_OUT/bin/$a tools/$SHORT_OSNAME/bin 191 strip tools/$SHORT_OSNAME/bin/$a 192done 193 194for a in $TOOLS_LIB; do 195 cp $HOST_LIB64_DIR/$a tools/$SHORT_OSNAME/lib64 196 strip tools/$SHORT_OSNAME/lib64/$a 197done 198 199for a in $TOOLS_LIB32; do 200 cp $HOST_LIB_DIR/$a tools/$SHORT_OSNAME/lib 201 strip tools/$SHORT_OSNAME/lib/$a 202done 203 204if [ $DARWIN -eq 0 ]; then 205 echo "DON'T FORGET TO UPDATE THE DARWIN COMPILER PREBUILTS!!!" 206fi 207