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