Home | History | Annotate | Download | only in tools
      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 SHARED=
     44 do_shared_option () { SHARED=yes; }
     45 register_option "--shared" do_shared_option "Build libLLVM*.so shared by on-device llvm toolchain, and link lib*stl_shared.so"
     46 
     47 register_jobs_option
     48 
     49 PROGRAM_PARAMETERS="<toolchain-src-dir>"
     50 PROGRAM_DESCRIPTION=\
     51 "This script can be used to copy all components that on-device compilation needs.
     52 Also, it will compile on-device LLVM-related toolchain."
     53 
     54 extract_parameters "$@"
     55 
     56 # Check toolchain source path
     57 SRC_DIR="$PARAMETERS"
     58 check_toolchain_src_dir "$SRC_DIR"
     59 BUILDTOOLS=$ANDROID_NDK_ROOT/build/tools
     60 run rm -rf $BUILD_DIR
     61 run mkdir -p $BUILD_DIR $OUT_DIR
     62 
     63 FLAGS=
     64 if [ "$VERBOSE" = "yes" ]; then
     65   FLAGS=$FLAGS" --verbose"
     66 fi
     67 if [ "$VERBOSE2" = "yes" ]; then
     68   FLAGS=$FLAGS" --verbose"
     69 fi
     70 FLAGS="$FLAGS -j$NUM_JOBS"
     71 if [ "$SHARED" = "yes" ]; then
     72   FLAGS="$FLAGS --shared"
     73 fi
     74 
     75 TMP_OUT_DIR=/tmp/ndk-$USER/on_device_out
     76 FLAGS="$FLAGS --out-dir=$TMP_OUT_DIR"
     77 ARCH="$(convert_abi_to_arch $ABI)"
     78 GCC_TOOLCHAIN_VERSION=`cat $NDK_DIR/toolchains/llvm-$DEFAULT_LLVM_VERSION/setup.mk | grep '^TOOLCHAIN_VERSION' | awk '{print $3'}`
     79 
     80 SYSROOT=$NDK_DIR/$(get_default_platform_sysroot_for_arch $ARCH)
     81 OUT_SYSROOT=$OUT_DIR
     82 
     83 run mkdir -p $OUT_SYSROOT/usr/bin
     84 run mkdir -p $OUT_SYSROOT/usr/lib
     85 
     86 dump "Copy platform CRT files..."
     87 run cp -r $SYSROOT/usr/lib/crtbegin_dynamic.o $OUT_SYSROOT/usr/lib
     88 run cp -r $SYSROOT/usr/lib/crtbegin_so.o $OUT_SYSROOT/usr/lib
     89 run cp -r $SYSROOT/usr/lib/crtend_android.o $OUT_SYSROOT/usr/lib
     90 run cp -r $SYSROOT/usr/lib/crtend_so.o $OUT_SYSROOT/usr/lib
     91 
     92 dump "Copy $ABI gabi++ library"
     93 run cp -f $NDK_DIR/$GABIXX_SUBDIR/libs/$ABI/libgabi++_shared.so $OUT_SYSROOT/usr/lib
     94 
     95 dump "Copy $ABI libportable library"
     96 run cp -f $NDK_DIR/$LIBPORTABLE_SUBDIR/libs/$ABI/libportable.a $OUT_SYSROOT/usr/lib
     97 run cp -f $NDK_DIR/$LIBPORTABLE_SUBDIR/libs/$ABI/libportable.wrap $OUT_SYSROOT/usr/lib
     98 
     99 dump "Copy $ABI compiler-rt library"
    100 run cp -f $NDK_DIR/$COMPILER_RT_SUBDIR/libs/$ABI/libcompiler_rt_static.a $OUT_SYSROOT/usr/lib
    101 
    102 dump "Copy $ABI gccunwind library"
    103 run cp -f $NDK_DIR/$GCCUNWIND_SUBDIR/libs/$ABI/libgccunwind.a $OUT_SYSROOT/usr/lib
    104 
    105 if [ "$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
    116 fi
    117 
    118 dump "Strip $ABI binaries"
    119 STRIP=$NDK_DIR/$(get_default_toolchain_binprefix_for_arch $ARCH)strip
    120 run find $OUT_SYSROOT/usr/lib \( -name "*\.so" \) -exec $STRIP --strip-all {} \;
    121 
    122 dump "Build $ABI LLVM toolchain from $SRC_DIR ..."
    123 run $BUILDTOOLS/build-device-llvm.sh $FLAGS --abis=$ABI --gcc-version=$GCC_TOOLCHAIN_VERSION $SRC_DIR $NDK_DIR
    124 fail_panic "Could not build le32 LLVM toolchain!"
    125 run mv -f $TMP_OUT_DIR/$ABI/SOURCES $OUT_SYSROOT/usr
    126 if [ "$SHARED" = "yes" ]; then
    127   run mv -f $TMP_OUT_DIR/$ABI/lib*.so $OUT_SYSROOT/usr/lib
    128 fi
    129 run mv -f $TMP_OUT_DIR/$ABI/* $OUT_SYSROOT/usr/bin
    130 run rmdir $TMP_OUT_DIR/$ABI
    131 run rmdir $TMP_OUT_DIR
    132 
    133 if [ "$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!"
    138 fi
    139 
    140 dump "Done."
    141 exit 0
    142