• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
24PROGRAM_PARAMETERS="<toolchain-dir> <ndk-dir>"
25PROGRAM_DESCRIPTION="\
26This program is used to extract fresh GNU libstdc++ binaries from a
27toolchain directory that was generated with a command like:
28
29  build-gcc.sh --keep-libstdcxx <toolchain-dir> <ndk-dir>
30
31It will copy the files (headers and libraries) under <ndk-dir>/$GNUSTL_SUBDIR
32unless you use the --out-dir option.
33"
34
35NDK_DIR="$ANDROID_NDK_ROOT"
36register_var_option "--ndk-dir=<path>" NDK_DIR "Source NDK installation."
37
38OUT_DIR=
39register_var_option "--out-dir=<path>" OUT_DIR "Alternate installation location."
40
41CLEAN_NDK=no
42register_var_option "--clean-ndk" CLEAN_NDK "Remove binaries from NDK installation."
43
44TOOLCHAIN=$DEFAULT_ARCH_TOOLCHAIN_NAME_arm
45register_var_option "--toolchain=<name>" TOOLCHAIN "Specify toolchain name."
46
47REVERSE=no
48register_var_option "--reverse" REVERSE "Reverse copy direction."
49
50extract_parameters "$@"
51
52# Set HOST_TAG to linux-x86 on 64-bit Linux systems
53force_32bit_binaries
54
55set_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
95set_parameters $PARAMETERS
96
97parse_toolchain_name
98
99# Determine output directory
100if [ -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
106else
107    OUT_DIR="$NDK_DIR/$GNUSTL_SUBDIR"
108    log "Using default output directory: $OUT_DIR"
109    mkdir -p "$OUT_DIR"
110fi
111
112if [ ! -d "$OUT_DIR" ] ; then
113    panic "Directory does not exist: $OUT_DIR"
114fi
115
116ABI_STL="$TOOLCHAIN_DIR/$ABI_CONFIGURE_TARGET"
117ABI_STL_INCLUDE="$ABI_STL/include/c++/$GCC_VERSION"
118
119OUT_INCLUDE="$OUT_DIR/include"
120OUT_INCLUDE_ABI="$OUT_INCLUDE/$ABI_CONFIGURE_TARGET"
121OUT_LIBS="$OUT_DIR/libs"
122OUT_ABI="$OUT_DIR/$ABI_CONFIGURE_TARGET"
123
124if [ "$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++.so libgnustl_shared.so"
143            cp "$ABI_STL/lib/thumb/libstdc++.a" "$OUT_LIBS/armeabi-v7a/libgnustl_static.a"
144
145            copy_directory "$OUT_INCLUDE_ABI/armv7-a/bits" "$OUT_LIBS/armeabi-v7a/include/bits"
146            copy_file_list "$ABI_STL/lib/armv7-a" "$OUT_LIBS/armeabi-v7a" "libstdc++.so libgnustl_shared.so"
147            cp "$ABI_STL/lib/armv7-a/libstdc++.a" "$OUT_LIBS/armeabi/libgnustl_static.a"
148            ;;
149        x86)
150            copy_directory "$OUT_INCLUDE_ABI/bits" "$OUT_LIBS/x86/include/bits"
151            copy_file_list "$ABI_STL/lib" "$OUT_LIBS/x86" "libstdc++.so"
152            cp "$ABI_STL/lib/libstdc++.a" "$OUT_LIBS/x86/libgnustl_static.a"
153            ;;
154        *)
155            dump "ERROR: Unsupported NDK architecture!"
156    esac
157
158    # Remove ABI-specific include headers
159    run rm -rf "$OUT_INCLUDE_ABI"
160    # We don't need the versioned libraries anymore (e.g. libstdc++.so.6
161    # and libstdc++.so.6.0.13)
162    run rm -f "$OUT_LIBS/"*/libstdc++.so.*
163else # REVERSE = yes
164    copy_directory "$OUT_DIR/include" "$ABI_STL_INCLUDE"
165    ABI_STL_INCLUDE_TARGET="$ABI_STL_INCLUDE/$ABI_CONFIGURE_TARGET"
166    mkdir -p "$ABI_STL_INCLUDE_TARGET"
167    fail_panic "Can't create directory: $ABI_STL_INCLUDE_TARGET"
168    case "$ARCH" in
169        arm)
170            copy_directory "$OUT_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/bits"
171            copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib" "libstdc++.so"
172            cp "$OUT_LIBS/armeabi/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a"
173
174            copy_directory "$OUT_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/thumb/bits"
175            copy_file_list "$OUT_LIBS/armeabi" "$ABI_STL/lib/thumb" "libstdc++.so"
176            cp "$OUT_LIBS/armeabi/libgnustl_static.a" "$ABI_STL/lib/thumb/libstdc++.a"
177
178            copy_directory "$OUT_LIBS/armeabi-v7a/include/bits" "$ABI_STL_INCLUDE_TARGET/armv7-a/bits"
179            copy_file_list "$OUT_LIBS/armeabi-v7a" "$ABI_STL/lib/armv7-a" "libstdc++.so"
180            cp "$OUT_LIBS/armeabi-v7a/libgnustl_static.a" "$ABI_STL/lib/armv7-a/libstdc++.a"
181            ;;
182        x86)
183            copy_directory "$OUT_LIBS/x86/include/bits" "$ABI_STL_INCLUDE_TARGET/bits"
184            copy_file_list "$OUT_LIBS/x86" "$ABI_STL/lib" "libstdc++.so"
185            cp "$OUT_LIBS/x86/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a"
186            ;;
187        *)
188            dump "ERROR: Unsupported NDK architecture!"
189    esac
190fi # REVERSE = yes
191