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 20 PROGDIR=$(dirname $0) 21 . $PROGDIR/prebuilt-common.sh 22 23 NDK_DIR=$ANDROID_NDK_ROOT 24 register_var_option "--ndk-dir=<path>" NDK_DIR "NDK installation directory" 25 26 BUILD_DIR=/tmp/ndk-$USER/build 27 register_var_option "--build-dir=<path>" BUILD_DIR "Specify temporary build dir." 28 29 OUT_DIR=/tmp/ndk-$USER/out 30 register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly." 31 32 ABI=armeabi-v7a 33 register_var_option "--abi=<target>" ABI "List which emulator target you use" 34 35 NO_SYNC= 36 do_no_sync_option () { NO_SYNC=yes; } 37 register_option "--no-sync" do_no_sync_option "Do not push sysroot to device /data/local/tmp/" 38 39 TESTING= 40 do_testing_option () { TESTING=yes; } 41 register_option "--testing" do_testing_option "Copy each c++ libraries for (even for GPL stuff)" 42 43 register_jobs_option 44 45 PROGRAM_PARAMETERS="<toolchain-src-dir>" 46 PROGRAM_DESCRIPTION=\ 47 "This script can be used to copy all components that on-device compilation needs. 48 Also, it will compile on-device LLVM-related toolchain." 49 50 extract_parameters "$@" 51 52 # Check toolchain source path 53 SRC_DIR="$PARAMETERS" 54 check_toolchain_src_dir "$SRC_DIR" 55 BUILDTOOLS=$ANDROID_NDK_ROOT/build/tools 56 rm -rf $BUILD_DIR; mkdir -p $BUILD_DIR 57 mkdir -p $OUT_DIR 58 59 60 FLAGS= 61 if [ "$VERBOSE" = "yes" ]; then 62 FLAGS=$FLAGS" --verbose" 63 fi 64 if [ "$VERBOSE2" = "yes" ]; then 65 FLAGS=$FLAGS" --verbose" 66 fi 67 FLAGS="$FLAGS -j$NUM_JOBS" 68 TMP_OUT_DIR=/tmp/ndk-$USER/on_device_out 69 FLAGS="$FLAGS --out-dir=$TMP_OUT_DIR" 70 ARCH="$(convert_abi_to_arch $ABI)" 71 GCC_TOOLCHAIN_VERSION=`cat $NDK_DIR/toolchains/llvm-$DEFAULT_LLVM_VERSION/setup.mk | grep '^TOOLCHAIN_VERSION' | awk '{print $3'}` 72 73 SYSROOT=$NDK_DIR/$(get_default_platform_sysroot_for_arch $ARCH) 74 OUT_SYSROOT=$OUT_DIR 75 76 mkdir -p $OUT_SYSROOT/usr/bin 77 mkdir -p $OUT_SYSROOT/usr/lib 78 79 dump "Copy platform CRT files..." 80 cp -r $SYSROOT/usr/lib/crtbegin_dynamic.o $OUT_SYSROOT/usr/lib 81 cp -r $SYSROOT/usr/lib/crtbegin_so.o $OUT_SYSROOT/usr/lib 82 cp -r $SYSROOT/usr/lib/crtend_android.o $OUT_SYSROOT/usr/lib 83 cp -r $SYSROOT/usr/lib/crtend_so.o $OUT_SYSROOT/usr/lib 84 85 dump "Copy $ABI gabi++ library" 86 cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_shared.so $OUT_SYSROOT/usr/lib 87 88 dump "Copy $ABI libportable library" 89 cp -f $NDK_DIR/$LIBPORTABLE_SUBDIR/libs/$ABI/libportable.a $OUT_SYSROOT/usr/lib 90 cp -f $NDK_DIR/$LIBPORTABLE_SUBDIR/libs/$ABI/libportable.wrap $OUT_SYSROOT/usr/lib 91 92 dump "Copy $ABI libportable library" 93 cp -f $NDK_DIR/$COMPILER_RT_SUBDIR/libs/$ABI/libcompiler_rt_static.a $OUT_SYSROOT/usr/lib 94 95 if [ "$TESTING" = "yes" ]; then 96 dump "Copy stuff for testing" 97 cp -f $NDK_DIR/$GNUSTL_SUBDIR/$GCC_TOOLCHAIN_VERSION/libs/$ABI/libsupc++.a $OUT_SYSROOT/usr/lib 98 cp -f $NDK_DIR/$GNUSTL_SUBDIR/$GCC_TOOLCHAIN_VERSION/libs/$ABI/libgnustl_static.a $OUT_SYSROOT/usr/lib 99 cp -f $NDK_DIR/$GNUSTL_SUBDIR/$GCC_TOOLCHAIN_VERSION/libs/$ABI/libgnustl_shared.so $OUT_SYSROOT/usr/lib 100 101 cp -f $NDK_DIR/$STLPORT_SUBDIR/libs/$ABI/libstlport_static.a $OUT_SYSROOT/usr/lib 102 cp -f $NDK_DIR/$STLPORT_SUBDIR/libs/$ABI/libstlport_shared.so $OUT_SYSROOT/usr/lib 103 104 cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_static.a $OUT_SYSROOT/usr/lib 105 cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_shared.so $OUT_SYSROOT/usr/lib 106 fi 107 108 109 dump "Build $ARCH LLVM toolchain..." 110 run $BUILDTOOLS/build-device-llvm.sh $FLAGS --arch=$ARCH --gcc-version=$GCC_TOOLCHAIN_VERSION $SRC_DIR $NDK_DIR 111 fail_panic "Could not build le32 LLVM toolchain!" 112 mv -f $TMP_OUT_DIR/$ARCH/lib*.so $OUT_SYSROOT/usr/lib 113 mv -f $TMP_OUT_DIR/$ARCH/* $OUT_SYSROOT/usr/bin 114 115 116 if [ "$NO_SYNC" != "yes" ]; then 117 dump "Push on-device $ABI toolchain sysroot to /data/local/tmp/" 118 run adb shell rm -rf /data/local/tmp/* 119 run adb push $OUT_SYSROOT /data/local/tmp/ 120 fail_panic "Could not push sysroot!" 121 fi 122 123 dump "Done." 124 exit 0 125