• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (C) 2013 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17# Rebuild all on-device toolchain for le32 target
18#
19
20PROGDIR=$(dirname $0)
21. $PROGDIR/prebuilt-common.sh
22
23NDK_DIR=$ANDROID_NDK_ROOT
24register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory"
25
26BUILD_DIR=/tmp/ndk-$USER/build
27register_var_option "--build-dir=<path>" BUILD_DIR "Specify temporary build dir."
28
29OUT_DIR=/tmp/ndk-$USER/out
30register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly."
31
32ABI=armeabi-v7a
33register_var_option "--abi=<target>" ABI "List which emulator target you use"
34
35NO_SYNC=
36do_no_sync_option () { NO_SYNC=yes; }
37register_option "--no-sync" do_no_sync_option "Do not push sysroot to device /data/local/tmp/"
38
39TESTING=
40do_testing_option () { TESTING=yes; }
41register_option "--testing" do_testing_option "Copy each c++ libraries for (even for GPL stuff)"
42
43SHARED=
44do_shared_option () { SHARED=yes; }
45register_option "--shared" do_shared_option "Build libLLVM*.so shared by on-device llvm toolchain, and link lib*stl_shared.so"
46
47register_jobs_option
48
49PROGRAM_PARAMETERS="<toolchain-src-dir>"
50PROGRAM_DESCRIPTION=\
51"This script can be used to copy all components that on-device compilation needs.
52Also, it will compile on-device LLVM-related toolchain."
53
54extract_parameters "$@"
55
56# Check toolchain source path
57SRC_DIR="$PARAMETERS"
58check_toolchain_src_dir "$SRC_DIR"
59BUILDTOOLS=$ANDROID_NDK_ROOT/build/tools
60run rm -rf $BUILD_DIR
61run mkdir -p $BUILD_DIR $OUT_DIR
62
63FLAGS=
64if [ "$VERBOSE" = "yes" ]; then
65  FLAGS=$FLAGS" --verbose"
66fi
67if [ "$VERBOSE2" = "yes" ]; then
68  FLAGS=$FLAGS" --verbose"
69fi
70FLAGS="$FLAGS -j$NUM_JOBS"
71if [ "$SHARED" = "yes" ]; then
72  FLAGS="$FLAGS --shared"
73fi
74
75TMP_OUT_DIR=/tmp/ndk-$USER/on_device_out
76FLAGS="$FLAGS --out-dir=$TMP_OUT_DIR"
77ARCH="$(convert_abi_to_arch $ABI)"
78GCC_TOOLCHAIN_VERSION=`cat $NDK_DIR/toolchains/llvm-$DEFAULT_LLVM_VERSION/setup.mk | grep '^TOOLCHAIN_VERSION' | awk '{print $3'}`
79
80SYSROOT=$NDK_DIR/$(get_default_platform_sysroot_for_arch $ARCH)
81OUT_SYSROOT=$OUT_DIR
82
83run mkdir -p $OUT_SYSROOT/usr/bin
84run mkdir -p $OUT_SYSROOT/usr/lib
85
86dump "Copy platform CRT files..."
87run cp -r $SYSROOT/usr/lib/crtbegin_dynamic.o $OUT_SYSROOT/usr/lib
88run cp -r $SYSROOT/usr/lib/crtbegin_so.o $OUT_SYSROOT/usr/lib
89run cp -r $SYSROOT/usr/lib/crtend_android.o $OUT_SYSROOT/usr/lib
90run cp -r $SYSROOT/usr/lib/crtend_so.o $OUT_SYSROOT/usr/lib
91
92dump "Copy $ABI gabi++ library"
93run cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_shared.so $OUT_SYSROOT/usr/lib
94
95dump "Copy $ABI libportable library"
96run cp -f $NDK_DIR/$LIBPORTABLE_SUBDIR/libs/$ABI/libportable.a $OUT_SYSROOT/usr/lib
97run cp -f $NDK_DIR/$LIBPORTABLE_SUBDIR/libs/$ABI/libportable.wrap $OUT_SYSROOT/usr/lib
98
99dump "Copy $ABI compiler-rt library"
100run cp -f $NDK_DIR/$COMPILER_RT_SUBDIR/libs/$ABI/libcompiler_rt_static.a $OUT_SYSROOT/usr/lib
101
102dump "Copy $ABI gccunwind library"
103run cp -f $NDK_DIR/$GCCUNWIND_SUBDIR/libs/$ABI/libgccunwind.a $OUT_SYSROOT/usr/lib
104
105if [ "$TESTING" = "yes" ]; then
106  dump "Copy stuff for testing"
107  run cp -f $NDK_DIR/$GNUSTL_SUBDIR/$GCC_TOOLCHAIN_VERSION/libs/$ABI/libsupc++.a $OUT_SYSROOT/usr/lib
108  run cp -f $NDK_DIR/$GNUSTL_SUBDIR/$GCC_TOOLCHAIN_VERSION/libs/$ABI/libgnustl_static.a $OUT_SYSROOT/usr/lib
109  run cp -f $NDK_DIR/$GNUSTL_SUBDIR/$GCC_TOOLCHAIN_VERSION/libs/$ABI/libgnustl_shared.so $OUT_SYSROOT/usr/lib
110
111  run cp -f $NDK_DIR/$STLPORT_SUBDIR/libs/$ABI/libstlport_static.a $OUT_SYSROOT/usr/lib
112  run cp -f $NDK_DIR/$STLPORT_SUBDIR/libs/$ABI/libstlport_shared.so $OUT_SYSROOT/usr/lib
113
114  run cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_static.a $OUT_SYSROOT/usr/lib
115  run cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_shared.so $OUT_SYSROOT/usr/lib
116fi
117
118dump "Strip $ABI binaries"
119STRIP=$NDK_DIR/$(get_default_toolchain_binprefix_for_arch $ARCH)strip
120run find $OUT_SYSROOT/usr/lib \( -name "*\.so" \) -exec $STRIP --strip-all {} \;
121
122dump "Build $ABI LLVM toolchain from $SRC_DIR ..."
123run $BUILDTOOLS/build-device-llvm.sh $FLAGS --abis=$ABI --gcc-version=$GCC_TOOLCHAIN_VERSION $SRC_DIR $NDK_DIR
124fail_panic "Could not build le32 LLVM toolchain!"
125run mv -f $TMP_OUT_DIR/$ABI/SOURCES $OUT_SYSROOT/usr
126if [ "$SHARED" = "yes" ]; then
127  run mv -f $TMP_OUT_DIR/$ABI/lib*.so $OUT_SYSROOT/usr/lib
128fi
129run mv -f $TMP_OUT_DIR/$ABI/* $OUT_SYSROOT/usr/bin
130run rmdir $TMP_OUT_DIR/$ABI
131run rmdir $TMP_OUT_DIR
132
133if [ "$NO_SYNC" != "yes" ]; then
134  dump "Push on-device $ABI toolchain sysroot to /data/local/tmp/"
135  run adb shell rm -rf /data/local/tmp/*
136  run adb push $OUT_SYSROOT /data/local/tmp/
137  fail_panic "Could not push sysroot!"
138fi
139
140dump "Done."
141exit 0
142