blob: 11b1009dab06e5de1558bdf81feeb6b8ffc2aaf1 [file] [log] [blame]
Stephen Hinesbe965652013-12-20 16:46:25 -08001#!/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
Miao Wangf149b322016-02-27 12:01:59 -08007if [[ $OSTYPE == darwin* ]];
Stephen Hinesa3957aa2014-01-09 02:08:10 -08008then
9
10 DARWIN=1
11 SHORT_OSNAME=darwin
12 SONAME=dylib
13 # Only build arm on darwin.
14 TARGETS=(arm)
15 SYS_NAMES=(generic)
Stephen Hines971d42a2014-02-20 01:42:40 -080016 NUM_CORES=`sysctl -n hw.ncpu`
Stephen Hinesa3957aa2014-01-09 02:08:10 -080017
18else
19
20 DARWIN=0
21 SHORT_OSNAME=linux
22 SONAME=so
23 # Target architectures and their system library names.
Stephen Hines648a1c12015-07-24 16:45:36 -070024 TARGETS=(arm mips x86 arm64)
25 SYS_NAMES=(generic generic_mips generic_x86 generic_arm64)
Stephen Hines971d42a2014-02-20 01:42:40 -080026 NUM_CORES=`cat /proc/cpuinfo | grep processor | tail -n 1 | cut -f 2 -d :`
27 NUM_CORES=$(($NUM_CORES+1))
Stephen Hinesa3957aa2014-01-09 02:08:10 -080028
29fi
30
Stephen Hines971d42a2014-02-20 01:42:40 -080031echo "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
Pirama Arumuga Nainar651a38e2016-03-14 13:44:31 -070037# Skip building LLVM and compiler-rt tests while updating prebuilts
38export SKIP_LLVM_TESTS=true
39
Stephen Hines971d42a2014-02-20 01:42:40 -080040# 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
Miao Wangd0c45802016-02-26 11:39:22 -080045# 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
Miao Wang4581f032015-07-25 17:34:21 -070047
Stephen Hinesbe965652013-12-20 16:46:25 -080048# ANDROID_HOST_OUT is where the new prebuilts will be constructed/copied from.
Stephen Hinesa3957aa2014-01-09 02:08:10 -080049ANDROID_HOST_OUT=$MY_ANDROID_DIR/out/host/$SHORT_OSNAME-x86/
Stephen Hinesbe965652013-12-20 16:46:25 -080050
51# HOST_LIB_DIR allows us to pick up the built librsrt_*.bc libraries.
52HOST_LIB_DIR=$ANDROID_HOST_OUT/lib
53
Tim Murrayf7dfd222014-09-30 12:37:22 -070054# HOST_LIB64_DIR
55HOST_LIB64_DIR=$ANDROID_HOST_OUT/lib64
56
Stephen Hinesbe965652013-12-20 16:46:25 -080057# PREBUILTS_DIR is where we want to copy our new files to.
58PREBUILTS_DIR=$MY_ANDROID_DIR/prebuilts/sdk/
59
Stephen Hinesbe965652013-12-20 16:46:25 -080060print_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.
Stephen Hines971d42a2014-02-20 01:42:40 -080072 cd $MY_ANDROID_DIR/frameworks/rs/driver/runtime && mma -j$NUM_CORES && cd - || exit 1
Stephen Hinesbe965652013-12-20 16:46:25 -080073 # Build a sample support application to ensure that all the pieces are up to date.
Stephen Hines971d42a2014-02-20 01:42:40 -080074 cd $MY_ANDROID_DIR/frameworks/rs/java/tests/RSTest_CompatLib/ && mma -j$NUM_CORES && cd - || exit 2
Miao Wangd0c45802016-02-26 11:39:22 -080075 # 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
Stephen Hines648a1c12015-07-24 16:45:36 -070078 # Build libcompiler-rt.a
Miao Wangd0c45802016-02-26 11:39:22 -080079 cd $MY_ANDROID_DIR/external/compiler-rt && mma -j$NUM_CORES && cd - || exit 4
Stephen Hines648a1c12015-07-24 16:45:36 -070080 # Build the blas libraries.
Miao Wangd0c45802016-02-26 11:39:22 -080081 cd $MY_ANDROID_DIR/external/cblas && mma -j$NUM_CORES && cd - || exit 5
Stephen Hinesbe965652013-12-20 16:46:25 -080082}
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
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800135# 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]}
Stephen Hines648a1c12015-07-24 16:45:36 -0700139 sys_name=${SYS_NAMES[$i]}
Miao Wangd0c45802016-02-26 11:39:22 -0800140 case "$sys_name" in
Stephen Hines648a1c12015-07-24 16:45:36 -0700141 *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
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800151 for a in `find renderscript/lib/$t -name \*.so`; do
152 file=`basename $a`
Stephen Hines1baebcd2014-05-06 10:08:53 -0700153 cp `find $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 4
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800154 done
155
156 for a in `find renderscript/lib/$t -name \*.bc`; do
157 file=`basename $a`
Tim Murrayf7dfd222014-09-30 12:37:22 -0700158 cp `find $HOST_LIB_DIR $HOST_LIB64_DIR $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 5
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800159 done
Stephen Hines648a1c12015-07-24 16:45:36 -0700160
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
Stephen Hinesbe965652013-12-20 16:46:25 -0800166 done
167
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800168 # javalib.jar
Miao Wangd0c45802016-02-26 11:39:22 -0800169 cp $MY_ANDROID_DIR/$RENDERSCRIPT_V8_JAR renderscript/lib/javalib.jar
Stephen Hinesbe965652013-12-20 16:46:25 -0800170
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800171fi
Stephen Hinesbe965652013-12-20 16:46:25 -0800172
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
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800178# Host-specific tools (bin/ and lib/)
Stephen Hinesbe965652013-12-20 16:46:25 -0800179TOOLS_BIN="
180bcc_compat
181llvm-rs-cc
182"
183
184TOOLS_LIB="
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800185libbcc.$SONAME
186libbcinfo.$SONAME
187libclang.$SONAME
Stephen Hines1baebcd2014-05-06 10:08:53 -0700188libc++.$SONAME
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800189libLLVM.$SONAME
Stephen Hinesbe965652013-12-20 16:46:25 -0800190"
191
Pirama Arumuga Nainarf5627842015-05-11 14:36:37 -0700192TOOLS_LIB32="libc++.$SONAME"
193
Stephen Hinesbe965652013-12-20 16:46:25 -0800194for a in $TOOLS_BIN; do
Pirama Arumuga Nainarf5627842015-05-11 14:36:37 -0700195 cp $ANDROID_HOST_OUT/bin/$a tools/$SHORT_OSNAME/bin
196 strip tools/$SHORT_OSNAME/bin/$a
Stephen Hinesbe965652013-12-20 16:46:25 -0800197done
198
199for a in $TOOLS_LIB; do
Pirama Arumuga Nainarf5627842015-05-11 14:36:37 -0700200 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
Stephen Hinesbe965652013-12-20 16:46:25 -0800207done
208
Stephen Hinesa3957aa2014-01-09 02:08:10 -0800209if [ $DARWIN -eq 0 ]; then
210 echo "DON'T FORGET TO UPDATE THE DARWIN COMPILER PREBUILTS!!!"
211fi