Home | History | Annotate | Download | only in tools
      1 #!/bin/sh
      2 #
      3 # Copyright (C) 2010 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 #  This shell script is used to copy the prebuilt GNU libstdc++ binaries
     18 #  from a fresh toolchain directory generated with a command like
     19 #  "build-gcc.sh --keep-libstdcxx".
     20 #
     21 
     22 . `dirname $0`/prebuilt-common.sh
     23 
     24 PROGRAM_PARAMETERS="<toolchain-dir> <ndk-dir>"
     25 PROGRAM_DESCRIPTION="\
     26 This program is used to extract fresh GNU libstdc++ binaries from a
     27 toolchain directory that was generated with a command like:
     28 
     29   build-gcc.sh --keep-libstdcxx <toolchain-dir> <ndk-dir> <toolchain>
     30 
     31 It will copy the files (headers and libraries) under <ndk-dir>/$GNUSTL_SUBDIR
     32 unless you use the --out-dir option.
     33 "
     34 
     35 NDK_DIR="$ANDROID_NDK_ROOT"
     36 register_var_option "--ndk-dir=<path>" NDK_DIR "Source NDK installation."
     37 
     38 OUT_DIR=
     39 register_var_option "--out-dir=<path>" OUT_DIR "Alternate installation location."
     40 
     41 CLEAN_NDK=no
     42 register_var_option "--clean-ndk" CLEAN_NDK "Remove binaries from NDK installation."
     43 
     44 TOOLCHAIN=arm-linux-androideabi-4.4.3
     45 register_var_option "--toolchain=<name>" TOOLCHAIN "Specify toolchain name."
     46 
     47 REVERSE=no
     48 register_var_option "--reverse" REVERSE "Reverse copy direction."
     49 
     50 extract_parameters "$@"
     51 
     52 # Set HOST_TAG to linux-x86 on 64-bit Linux systems
     53 force_32bit_binaries
     54 
     55 set_parameters ()
     56 {
     57     TOOLCHAIN_DIR="$1"
     58     NDK_DIR="$2"
     59 
     60     # Check source directory
     61     #
     62     if [ -z "$TOOLCHAIN_DIR" ] ; then
     63         echo "ERROR: Missing toolchain directory parameter. See --help for details."
     64         exit 1
     65     fi
     66 
     67     TOOLCHAIN_DIR2="$TOOLCHAIN_DIR/toolchains/$TOOLCHAIN/prebuilt/$HOST_TAG"
     68     if [ -d "$TOOLCHAIN_DIR2" ] ; then
     69         TOOLCHAIN_DIR="$TOOLCHAIN_DIR2"
     70         log "Auto-detecting toolchain installation: $TOOLCHAIN_DIR"
     71     fi
     72 
     73     if [ ! -d "$TOOLCHAIN_DIR/bin" -o ! -d "$TOOLCHAIN_DIR/lib" ] ; then
     74         echo "ERROR: Directory does not point to toolchain: $TOOLCHAIN_DIR"
     75         exit 1
     76     fi
     77 
     78     log "Using toolchain directory: $TOOLCHAIN_DIR"
     79 
     80     # Check NDK installation directory
     81     #
     82     if [ -z "$NDK_DIR" ] ; then
     83         echo "ERROR: Missing NDK directory parameter. See --help for details."
     84         exit 1
     85     fi
     86 
     87     if [ ! -d "$NDK_DIR" ] ; then
     88         echo "ERROR: Not a valid directory: $NDK_DIR"
     89         exit 1
     90     fi
     91 
     92     log "Using NDK directory: $NDK_DIR"
     93 }
     94 
     95 set_parameters $PARAMETERS
     96 
     97 parse_toolchain_name
     98 
     99 # Determine output directory
    100 if [ -n "$OUT_DIR" ] ; then
    101     if [ "$REVERSE" = "no" ] ; then
    102         mkdir -p "$OUT_DIR"
    103         fail_panic "Could not create directory: $OUT_DIR"
    104         log "Using specific output directory: $OUT_DIR"
    105     fi
    106 else
    107     OUT_DIR="$NDK_DIR/$GNUSTL_SUBDIR"
    108     log "Using default output directory: $OUT_DIR"
    109     mkdir -p "$OUT_DIR"
    110 fi
    111 
    112 if [ ! -d "$OUT_DIR" ] ; then
    113     panic "Directory does not exist: $OUT_DIR"
    114 fi
    115 
    116 ABI_STL="$TOOLCHAIN_DIR/$ABI_CONFIGURE_TARGET"
    117 ABI_STL_INCLUDE="$ABI_STL/include/c++/$GCC_VERSION"
    118 
    119 OUT_INCLUDE="$OUT_DIR/include"
    120 OUT_INCLUDE_ABI="$OUT_INCLUDE/$ABI_CONFIGURE_TARGET"
    121 OUT_LIBS="$OUT_DIR/libs"
    122 OUT_ABI="$OUT_DIR/$ABI_CONFIGURE_TARGET"
    123 
    124 if [ "$REVERSE" = "no" ] ; then
    125     # Check the directories
    126     if [ ! -d "$ABI_STL" ] ; then
    127         panic "ERROR: Missing arch-specific directory: $ABI_STL"
    128     fi
    129     if [ ! -d "$ABI_STL_INCLUDE" ] ; then
    130         panic "ERROR: Missing toolchain-specific include directory: $ABI_STL_INCLUDE"
    131     fi
    132 
    133     # First, copy the headers
    134     copy_directory "$ABI_STL_INCLUDE" "$OUT_INCLUDE"
    135 
    136     # Copy platform-specific headers from $ABI_STL_INCLUDE/$ABI_CONFIGURE_TARGET
    137     # to relevant locations under $NDK_STL/libs/<arch>/include
    138     case "$ARCH" in
    139         arm)
    140             # We use the thumb version by default.
    141             copy_directory "$OUT_INCLUDE_ABI/thumb/bits" "$OUT_LIBS/armeabi/include/bits"
    142             copy_file_list "$ABI_STL/lib/thumb" "$OUT_LIBS/armeabi" "libstdc++.*"
    143 
    144             copy_directory "$OUT_INCLUDE_ABI/armv7-a/bits" "$OUT_LIBS/armeabi-v7a/include/bits"
    145             copy_file_list "$ABI_STL/lib/armv7-a" "$OUT_LIBS/armeabi-v7a" "libstdc++.*"
    146             ;;
    147         x86)
    148             copy_directory "$OUT_INCLUDE_ABI/bits" "$OUT_LIBS/x86/include/bits"
    149             copy_file_list "$ABI_STL/lib" "$OUT_LIBS/x86" "libstdc++.*"
    150             ;;
    151         *)
    152             dump "ERROR: Unsupported NDK architecture!"
    153     esac
    154 
    155     # Remove ABI-specific include headers
    156     run rm -rf "$OUT_INCLUDE_ABI"
    157     # We don't need the versioned libraries anymore (e.g. libstdc++.so.6
    158     # and libstdc++.so.6.0.13)
    159     run rm -f "$OUT_LIBS/"*/libstdc++.so.*
    160 else # REVERSE = yes
    161     copy_directory "$OUT_DIR/include" "$ABI_STL_INCLUDE"
    162     ABI_STL_INCLUDE_TARGET="$ABI_STL_INCLUDE/$ABI_CONFIGURE_TARGET"
    163     mkdir -p "$ABI_STL_INCLUDE_TARGET"
    164     fail_panic "Can't create directory: $ABI_STL_INCLUDE_TARGET"
    165     case "$ARCH" in
    166         arm)
    167             copy_directory "$OUT_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/bits"
    168             copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib" "libstdc++.*"
    169             copy_directory "$OUT_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/thumb/bits"
    170             copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib/thumb" "libstdc++.*"
    171             copy_directory "$OUT_LIBS/armeabi-v7a/include/bits" "$ABI_STL_INCLUDE_TARGET/armv7-a/bits"
    172             copy_file_list "$OUT_LIBS/armeabi-v7a" "$ABI_STL/lib/armv7-a" "libstdc++.*"
    173             ;;
    174         x86)
    175             copy_directory "$OUT_LIBS/x86/include/bits" "$ABI_STL_INCLUDE_TARGET/bits"
    176             copy_file_list "$OUT_LIBS/x86" "$ABI_STL/lib" "libstdc++.*"
    177             ;;
    178         *)
    179             dump "ERROR: Unsupported NDK architecture!"
    180     esac
    181 fi # REVERSE = yes
    182