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 31# Turn off the build cache and make sure we build all of LLVM from scratch. 32export ANDROID_USE_BUILDCACHE=false 33export FORCE_BUILD_LLVM_COMPONENTS=true 34 35# Skip building LLVM and compiler-rt tests while updating prebuilts 36export SKIP_LLVM_TESTS=true 37 38# RENDERSCRIPT_V8_JAR is the generated JAVA static lib for RenderScript Support Lib. 39RENDERSCRIPT_V8_JAR=out/target/common/obj/JAVA_LIBRARIES/android-support-v8-renderscript_intermediates/classes.jar 40 41# ANDROID_HOST_OUT is where the new prebuilts will be constructed/copied from. 42ANDROID_HOST_OUT=$MY_ANDROID_DIR/out/host/$SHORT_OSNAME-x86/ 43 44# HOST_LIB_DIR allows us to pick up the built librsrt_*.bc libraries. 45HOST_LIB_DIR=$ANDROID_HOST_OUT/lib 46 47# HOST_LIB64_DIR 48HOST_LIB64_DIR=$ANDROID_HOST_OUT/lib64 49 50# PREBUILTS_DIR is where we want to copy our new files to. 51PREBUILTS_DIR=$MY_ANDROID_DIR/prebuilts/sdk/ 52 53print_usage() { 54 echo "USAGE: $0 [-h|--help] [-j <num>] [-n|--no-build] [--no-start] [-x]" 55 echo "OPTIONS:" 56 echo " -j <num> : Specify parallelism for builds." 57 echo " -h, --help : Display this help message." 58 echo " -n, --no-build : Skip the build step and just copy files." 59 echo " --no-start : Do not \"repo start\" a new branch for the copied files." 60 echo " -x : Display commands before they are executed." 61} 62 63build_rs_libs() { 64 echo Building for target $1 65 lunch $1 66 # Build the RS runtime libraries. 67 cd $MY_ANDROID_DIR/frameworks/rs/driver/runtime && mma -j$NUM_CORES && cd - || exit 1 68 # Build libRSSupport.so 69 cd $MY_ANDROID_DIR/frameworks/rs/support && mma -j$NUM_CORES && cd - || exit 2 70 # Build android-support-v8-renderscript.jar 71 # We need to explicitly do so, since JACK won't generate a jar by default. 72 cd $MY_ANDROID_DIR && make $RENDERSCRIPT_V8_JAR -j$NUM_CORES && cd - || exit 3 73 # Build libcompiler-rt.a 74 cd $MY_ANDROID_DIR/external/compiler-rt && mma -j$NUM_CORES && cd - || exit 4 75 # Build the blas libraries. 76 cd $MY_ANDROID_DIR/external/cblas && mma -j$NUM_CORES && cd - || exit 5 77} 78 79build_rstest_compatlib() { 80 echo Building for target $1 81 lunch $1 82 # Build a sample support application to ensure that all the pieces are up to date. 83 cd $MY_ANDROID_DIR/frameworks/rs/tests/java_api/RSTest_CompatLib/ && mma -j$NUM_CORES FORCE_BUILD_RS_COMPAT=true && cd - || exit 6 84} 85 86build_rs_host_tools() { 87 echo "Building RS host tools (llvm-rs-cc and bcc_compat)" 88 lunch aosp_arm64-userdebug 89 90 cd $MY_ANDROID_DIR/frameworks/compile/slang && mma -j$NUM_CORES && cd - || exit 7 91 cd $MY_ANDROID_DIR/frameworks/compile/libbcc && mma -j$NUM_CORES && cd - || exit 8 92} 93 94# Build everything by default 95build_rs=1 96 97# repo start by default 98repo_start=1 99 100while [ $# -gt 0 ]; do 101 case "$1" in 102 -h|--help) 103 print_usage 104 exit 0 105 ;; 106 -j) 107 if [[ $# -gt 1 && "$2" =~ ^[0-9]+$ ]]; then 108 NUM_CORES="$2" 109 shift 110 else 111 echo Expected numeric argument after "$1" 112 print_usage 113 exit 99 114 fi 115 ;; 116 -n|--no-build) 117 build_rs=0 118 ;; 119 --no-start) 120 repo_start=0 121 ;; 122 -x) 123 # set lets us enable bash -x mode. 124 set -x 125 ;; 126 *) 127 echo Unknown argument: "$1" 128 print_usage 129 exit 99 130 break 131 ;; 132 esac 133 shift 134done 135 136if [ $build_rs -eq 1 ]; then 137 138 echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 139 echo !!! BUILDING RS PREBUILTS !!! 140 echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!! 141 142 echo "Using $NUM_CORES cores" 143 144 source build/envsetup.sh 145 146 build_rs_host_tools 147 148 for t in ${TARGETS[@]}; do 149 build_rs_libs aosp_${t}-userdebug 150 done 151 152 echo DONE BUILDING RS PREBUILTS 153 154else 155 156 echo SKIPPING BUILD OF RS PREBUILTS 157 158fi 159 160cd $PREBUILTS_DIR || exit 3 161 162# Verify that project is "clean" 163if [ `git status --short --untracked-files=no | wc -l` -ne 0 ]; then 164 echo $PREBUILTS_DIR contains modified files -- aborting. 165 git status --untracked-files=no 166 exit 1 167fi 168 169if [ $repo_start -eq 1 ]; then 170 DATE=`date +%Y%m%d` 171 repo start pb_$DATE . 172 if [ $? -ne 0 ]; then 173 echo repo start failed -- aborting. 174 exit 1 175 fi 176fi 177 178# Don't copy device prebuilts on Darwin. We don't need/use them. 179if [ $DARWIN -eq 0 ]; then 180 for i in $(seq 0 $((${#TARGETS[@]} - 1))); do 181 t=${TARGETS[$i]} 182 sys_name=${SYS_NAMES[$i]} 183 case "$sys_name" in 184 *64) 185 sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib64 186 ;; 187 *) 188 sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib 189 ;; 190 esac 191 obj_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/lib 192 obj_static_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/STATIC_LIBRARIES 193 194 for a in `find renderscript/lib/$t -name \*.so`; do 195 file=`basename $a` 196 cp `find $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 4 197 done 198 199 for a in `find renderscript/lib/$t -name \*.bc`; do 200 file=`basename $a` 201 cp `find $HOST_LIB_DIR $HOST_LIB64_DIR $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 5 202 done 203 204 for a in `find renderscript/lib/$t -name \*.a`; do 205 file=`basename $a` 206 cp `find $obj_static_lib_dir -name $file | head -1` $a || exit 4 207 done 208 209 done 210 211 # javalib.jar 212 cp $MY_ANDROID_DIR/$RENDERSCRIPT_V8_JAR renderscript/lib/javalib.jar 213 214fi 215 216# Copy header files for compilers 217cp $MY_ANDROID_DIR/external/clang/lib/Headers/*.h renderscript/clang-include 218cp $MY_ANDROID_DIR/frameworks/rs/script_api/include/* renderscript/include 219 220 221# Host-specific tools (bin/ and lib/) 222TOOLS_BIN=" 223bcc_compat 224llvm-rs-cc 225" 226 227TOOLS_LIB=" 228libbcc.$SONAME 229libbcinfo.$SONAME 230libclang.$SONAME 231libc++.$SONAME 232libLLVM.$SONAME 233" 234 235TOOLS_LIB32="libc++.$SONAME" 236 237for a in $TOOLS_BIN; do 238 cp $ANDROID_HOST_OUT/bin/$a tools/$SHORT_OSNAME/bin 239 strip tools/$SHORT_OSNAME/bin/$a 240done 241 242for a in $TOOLS_LIB; do 243 cp $HOST_LIB64_DIR/$a tools/$SHORT_OSNAME/lib64 244 strip tools/$SHORT_OSNAME/lib64/$a 245done 246 247for a in $TOOLS_LIB32; do 248 cp $HOST_LIB_DIR/$a tools/$SHORT_OSNAME/lib 249 strip tools/$SHORT_OSNAME/lib/$a 250done 251 252if [ $build_rs -eq 1 ]; then 253 254 echo BUILDING RSTest_CompatLib with the new prebuilts 255 256 echo "Using $NUM_CORES cores" 257 258 source $MY_ANDROID_DIR/build/envsetup.sh 259 260 for t in ${TARGETS[@]}; do 261 build_rstest_compatlib aosp_${t}-userdebug 262 done 263 264 echo DONE BUILDING RSTest_CompatLib 265 266else 267 268 echo SKIPPING BUILD OF RSTest_CompatLib 269 270fi 271 272if [ $DARWIN -eq 0 ]; then 273 echo "DON'T FORGET TO UPDATE THE DARWIN COMPILER PREBUILTS!!!" 274fi 275