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