summaryrefslogtreecommitdiff
path: root/update_rs_prebuilts.sh
blob: 397d9190675d949ff5de42e9e6c0552ff94ad862 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash

# We are currently in frameworks/rs, so compute our top-level directory.
MY_ANDROID_DIR=$PWD/../../
cd $MY_ANDROID_DIR

if [ $OSTYPE == 'darwin14' ];
then

  DARWIN=1
  SHORT_OSNAME=darwin
  SONAME=dylib
  # Only build arm on darwin.
  TARGETS=(arm)
  SYS_NAMES=(generic)
  NUM_CORES=`sysctl -n hw.ncpu`

else

  DARWIN=0
  SHORT_OSNAME=linux
  SONAME=so
  # Target architectures and their system library names.
  TARGETS=(arm mips x86 arm64)
  SYS_NAMES=(generic generic_mips generic_x86 generic_arm64)
  NUM_CORES=`cat /proc/cpuinfo | grep processor | tail -n 1 | cut -f 2 -d :`
  NUM_CORES=$(($NUM_CORES+1))

fi

echo "Using $NUM_CORES cores"

# Turn off the build cache and make sure we build all of LLVM from scratch.
export ANDROID_USE_BUILDCACHE=false
export FORCE_BUILD_LLVM_COMPONENTS=true

# Ensure that we have constructed the latest "bcc" for the host. Without
# this variable, we don't build the .so files, hence we never construct the
# actual required compiler pieces.
export FORCE_BUILD_RS_COMPAT=true

# Disable JACK when buiding RS prebuilts. Without this variable, we won't be
# able to get classes.jar.
export UPDATE_RS_PREBUILTS_DISABLE_JACK=true

# ANDROID_HOST_OUT is where the new prebuilts will be constructed/copied from.
ANDROID_HOST_OUT=$MY_ANDROID_DIR/out/host/$SHORT_OSNAME-x86/

# HOST_LIB_DIR allows us to pick up the built librsrt_*.bc libraries.
HOST_LIB_DIR=$ANDROID_HOST_OUT/lib

# HOST_LIB64_DIR
HOST_LIB64_DIR=$ANDROID_HOST_OUT/lib64

# PREBUILTS_DIR is where we want to copy our new files to.
PREBUILTS_DIR=$MY_ANDROID_DIR/prebuilts/sdk/

print_usage() {
  echo "USAGE: $0 [-h|--help] [-n|--no-build] [-x]"
  echo "OPTIONS:"
  echo "    -h, --help     : Display this help message."
  echo "    -n, --no-build : Skip the build step and just copy files."
  echo "    -x             : Display commands before they are executed."
}

build_rs_libs() {
  echo Building for target $1
  lunch $1
  # Build the RS runtime libraries.
  cd $MY_ANDROID_DIR/frameworks/rs/driver/runtime && mma -j$NUM_CORES && cd - || exit 1
  # Build a sample support application to ensure that all the pieces are up to date.
  cd $MY_ANDROID_DIR/frameworks/rs/java/tests/RSTest_CompatLib/ && mma -j$NUM_CORES && cd - || exit 2
  # Build libcompiler-rt.a
  cd $MY_ANDROID_DIR/external/compiler-rt && mma -j$NUM_CORES && cd - || exit 3
  # Build the blas libraries.
  cd $MY_ANDROID_DIR/external/cblas && mma -j$NUM_CORES && cd - || exit 4
}

# Build everything by default
build_rs=1

while [ $# -gt 0 ]; do
  case "$1" in
    -h|--help)
      print_usage
      exit 0
      ;;
    -n|--no-build)
      build_rs=0
      ;;
    -x)
      # set lets us enable bash -x mode.
      set -x
      ;;
    *)
      echo Unknown argument: "$1"
      print_usage
      exit 99
      break
      ;;
  esac
  shift
done

if [ $build_rs -eq 1 ]; then

  echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  echo !!! BUILDING RS PREBUILTS !!!
  echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  source build/envsetup.sh

  for t in ${TARGETS[@]}; do
    build_rs_libs aosp_${t}-userdebug
  done

  echo DONE BUILDING RS PREBUILTS

else

  echo SKIPPING BUILD OF RS PREBUILTS

fi

DATE=`date +%Y%m%d`

cd $PREBUILTS_DIR || exit 3
repo start pb_$DATE .

# Don't copy device prebuilts on Darwin. We don't need/use them.
if [ $DARWIN -eq 0 ]; then
  for i in $(seq 0 $((${#TARGETS[@]} - 1))); do
    t=${TARGETS[$i]}
    sys_name=${SYS_NAMES[$i]}
    case "$sys_name" in 
      *64)
        sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib64
        ;;
      *)
        sys_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/system/lib
        ;;
    esac
    obj_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/lib
    obj_static_lib_dir=$MY_ANDROID_DIR/out/target/product/$sys_name/obj/STATIC_LIBRARIES

    for a in `find renderscript/lib/$t -name \*.so`; do
      file=`basename $a`
      cp `find $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 4
    done

    for a in `find renderscript/lib/$t -name \*.bc`; do
      file=`basename $a`
      cp `find $HOST_LIB_DIR $HOST_LIB64_DIR $sys_lib_dir $obj_lib_dir -name $file | head -1` $a || exit 5
    done

    for a in `find renderscript/lib/$t -name \*.a`; do
      file=`basename $a`
      cp `find $obj_static_lib_dir -name $file | head -1` $a || exit 4
    done

  done

  # javalib.jar
  cp $MY_ANDROID_DIR/out/target/common/obj/JAVA_LIBRARIES/android-support-v8-renderscript_intermediates/classes.jar renderscript/lib/javalib.jar

fi

# Copy header files for compilers
cp $MY_ANDROID_DIR/external/clang/lib/Headers/*.h renderscript/clang-include
cp $MY_ANDROID_DIR/frameworks/rs/scriptc/* renderscript/include


# Host-specific tools (bin/ and lib/)
TOOLS_BIN="
bcc_compat
llvm-rs-cc
"

TOOLS_LIB="
libbcc.$SONAME
libbcinfo.$SONAME
libclang.$SONAME
libc++.$SONAME
libLLVM.$SONAME
"

TOOLS_LIB32="libc++.$SONAME"

for a in $TOOLS_BIN; do
  cp $ANDROID_HOST_OUT/bin/$a tools/$SHORT_OSNAME/bin
  strip tools/$SHORT_OSNAME/bin/$a
done

for a in $TOOLS_LIB; do
  cp $HOST_LIB64_DIR/$a tools/$SHORT_OSNAME/lib64
  strip tools/$SHORT_OSNAME/lib64/$a
done

for a in $TOOLS_LIB32; do
  cp $HOST_LIB_DIR/$a tools/$SHORT_OSNAME/lib
  strip tools/$SHORT_OSNAME/lib/$a
done

if [ $DARWIN -eq 0 ]; then
  echo "DON'T FORGET TO UPDATE THE DARWIN COMPILER PREBUILTS!!!"
fi