1 # Copyright (C) 2010 The Android Open Source Project 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 16 # Create a standalone toolchain package for Android. 17 18 . `dirname $0`/prebuilt-common.sh 19 20 PROGRAM_PARAMETERS="" 21 PROGRAM_DESCRIPTION=\ 22 "Generate a customized Android toolchain installation that includes 23 a working sysroot. The result is something that can more easily be 24 used as a standalone cross-compiler, e.g. to run configure and 25 make scripts." 26 27 force_32bit_binaries 28 29 # For now, this is the only toolchain that works reliably. 30 TOOLCHAIN_NAME= 31 register_var_option "--toolchain=<name>" TOOLCHAIN_NAME "Specify toolchain name" 32 33 ARCH= 34 register_option "--arch=<name>" do_arch "Specify target architecture" "arm" 35 do_arch () { ARCH=$1; } 36 37 NDK_DIR=`dirname $0` 38 NDK_DIR=`dirname $NDK_DIR` 39 NDK_DIR=`dirname $NDK_DIR` 40 register_var_option "--ndk-dir=<path>" NDK_DIR "Take source files from NDK at <path>" 41 42 SYSTEM=$HOST_TAG 43 register_var_option "--system=<name>" SYSTEM "Specify host system" 44 45 PACKAGE_DIR=/tmp/ndk-$USER 46 register_var_option "--package-dir=<path>" PACKAGE_DIR "Place package file in <path>" 47 48 INSTALL_DIR= 49 register_var_option "--install-dir=<path>" INSTALL_DIR "Don't create package, install files to <path> instead." 50 51 PLATFORM= 52 register_option "--platform=<name>" do_platform "Specify target Android platform/API level." "android-3" 53 do_platform () { PLATFORM=$1; } 54 55 extract_parameters "$@" 56 57 # Check NDK_DIR 58 if [ ! -d "$NDK_DIR/build/core" ] ; then 59 echo "Invalid source NDK directory: $NDK_DIR" 60 echo "Please use --ndk-dir=<path> to specify the path of an installed NDK." 61 exit 1 62 fi 63 64 # Check ARCH 65 if [ -z "$ARCH" ]; then 66 case $TOOLCHAIN_NAME in 67 arm-*) 68 ARCH=arm 69 ;; 70 x86-*) 71 ARCH=x86 72 ;; 73 mips*) 74 ARCH=mips 75 ;; 76 *) 77 ARCH=arm 78 ;; 79 esac 80 log "Auto-config: --arch=$ARCH" 81 fi 82 83 # Check toolchain name 84 if [ -z "$TOOLCHAIN_NAME" ]; then 85 TOOLCHAIN_NAME=$(get_default_toolchain_name_for_arch $ARCH) 86 echo "Auto-config: --toolchain=$TOOLCHAIN_NAME" 87 fi 88 89 # Check PLATFORM 90 if [ -z "$PLATFORM" ]; then 91 case $ARCH in 92 arm) PLATFORM=android-3 93 ;; 94 x86) 95 PLATFORM=android-9 96 ;; 97 mips) 98 # Set it to android-9 99 PLATFORM=android-9 100 ;; 101 esac 102 log "Auto-config: --platform=$PLATFORM" 103 fi 104 105 if [ ! -d "$NDK_DIR/platforms/$PLATFORM" ] ; then 106 echo "Invalid platform name: $PLATFORM" 107 echo "Please use --platform=<name> with one of:" `(cd "$NDK_DIR/platforms" && ls)` 108 exit 1 109 fi 110 111 # Check toolchain name 112 TOOLCHAIN_PATH="$NDK_DIR/toolchains/$TOOLCHAIN_NAME" 113 if [ ! -d "$TOOLCHAIN_PATH" ] ; then 114 echo "Invalid toolchain name: $TOOLCHAIN_NAME" 115 echo "Please use --toolchain=<name> with the name of a toolchain supported by the source NDK." 116 echo "Try one of: " `(cd "$NDK_DIR/toolchains" && ls)` 117 exit 1 118 fi 119 120 # Extract architecture from platform name 121 parse_toolchain_name $TOOLCHAIN_NAME 122 123 # Check that there are any platform files for it! 124 (cd $NDK_DIR/platforms && ls -d */arch-${ARCH} >/dev/null 2>&1 ) 125 if [ $? != 0 ] ; then 126 echo "Platform $PLATFORM doesn't have any files for this architecture: $ARCH" 127 echo "Either use --platform=<name> or --toolchain=<name> to select a different" 128 echo "platform or arch-dependent toolchain name (respectively)!" 129 exit 1 130 fi 131 132 # Compute source sysroot 133 SRC_SYSROOT="$NDK_DIR/platforms/$PLATFORM/arch-$ARCH" 134 if [ ! -d "$SRC_SYSROOT" ] ; then 135 echo "No platform files ($PLATFORM) for this architecture: $ARCH" 136 exit 1 137 fi 138 139 # Check that we have any prebuilts here 140 if [ ! -d "$TOOLCHAIN_PATH/prebuilt" ] ; then 141 echo "Toolchain is missing prebuilt files: $TOOLCHAIN_NAME" 142 echo "You must point to a valid NDK release package!" 143 exit 1 144 fi 145 146 if [ ! -d "$TOOLCHAIN_PATH/prebuilt/$SYSTEM" ] ; then 147 echo "Host system '$SYSTEM' is not supported by the source NDK!" 148 echo "Try --system=<name> with one of: " `(cd $TOOLCHAIN_PATH/prebuilt && ls) | grep -v gdbserver` 149 exit 1 150 fi 151 152 TOOLCHAIN_PATH="$TOOLCHAIN_PATH/prebuilt/$SYSTEM" 153 154 # Create temporary directory 155 TMPDIR=$NDK_TMPDIR/standalone/$TOOLCHAIN_NAME 156 157 dump "Copying prebuilt binaries..." 158 # Now copy the toolchain prebuilt binaries 159 run copy_directory "$TOOLCHAIN_PATH" "$TMPDIR" 160 161 dump "Copying sysroot headers and libraries..." 162 # Copy the sysroot under $TMPDIR/sysroot. The toolchain was built to 163 # expect the sysroot files to be placed there! 164 run copy_directory_nolinks "$SRC_SYSROOT" "$TMPDIR/sysroot" 165 166 dump "Copying libstdc++ headers and libraries..." 167 168 GNUSTL_DIR=$NDK_DIR/$GNUSTL_SUBDIR 169 GNUSTL_LIBS=$GNUSTL_DIR/libs 170 171 ABI_STL="$TMPDIR/$ABI_CONFIGURE_TARGET" 172 ABI_STL_INCLUDE="$ABI_STL/include/c++/$GCC_VERSION" 173 174 copy_directory "$GNUSTL_DIR/include" "$ABI_STL_INCLUDE" 175 ABI_STL_INCLUDE_TARGET="$ABI_STL_INCLUDE/$ABI_CONFIGURE_TARGET" 176 mkdir -p "$ABI_STL_INCLUDE_TARGET" 177 fail_panic "Can't create directory: $ABI_STL_INCLUDE_TARGET" 178 case "$ARCH" in 179 arm) 180 copy_directory "$GNUSTL_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/bits" 181 copy_file_list "$GNUSTL_LIBS/armeabi" "$ABI_STL/lib" "libgnustl_shared.so" 182 copy_file_list "$GNUSTL_LIBS/armeabi" "$ABI_STL/lib" "libsupc++.a" 183 cp "$GNUSTL_LIBS/armeabi/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a" 184 185 copy_directory "$GNUSTL_LIBS/armeabi/include/bits" "$ABI_STL_INCLUDE_TARGET/thumb/bits" 186 copy_file_list "$GNUSTL_LIBS/armeabi" "$ABI_STL/lib/thumb" "libgnustl_shared.so" 187 copy_file_list "$GNUSTL_LIBS/armeabi" "$ABI_STL/lib/thumb" "libsupc++.a" 188 cp "$GNUSTL_LIBS/armeabi/libgnustl_static.a" "$ABI_STL/lib/thumb/libstdc++.a" 189 190 copy_directory "$GNUSTL_LIBS/armeabi-v7a/include/bits" "$ABI_STL_INCLUDE_TARGET/armv7-a/bits" 191 copy_file_list "$GNUSTL_LIBS/armeabi-v7a" "$ABI_STL/lib/armv7-a" "libgnustl_shared.so" 192 copy_file_list "$GNUSTL_LIBS/armeabi-v7a" "$ABI_STL/lib/armv7-a" "libsupc++.a" 193 cp "$GNUSTL_LIBS/armeabi-v7a/libgnustl_static.a" "$ABI_STL/lib/armv7-a/libstdc++.a" 194 ;; 195 x86) 196 copy_directory "$GNUSTL_LIBS/x86/include/bits" "$ABI_STL_INCLUDE_TARGET/bits" 197 copy_file_list "$GNUSTL_LIBS/x86" "$ABI_STL/lib" "libgnustl_shared.so" 198 copy_file_list "$GNUSTL_LIBS/x86" "$ABI_STL/lib" "libsupc++.a" 199 cp "$GNUSTL_LIBS/x86/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a" 200 ;; 201 mips) 202 copy_directory "$GNUSTL_LIBS/mips/include/bits" "$ABI_STL_INCLUDE_TARGET/bits" 203 copy_file_list "$GNUSTL_LIBS/mips" "$ABI_STL/lib" "libgnustl_shared.so" 204 copy_file_list "$GNUSTL_LIBS/mips" "$ABI_STL/lib" "libsupc++.a" 205 cp "$GNUSTL_LIBS/mips/libgnustl_static.a" "$ABI_STL/lib/libstdc++.a" 206 ;; 207 *) 208 dump "ERROR: Unsupported NDK architecture!" 209 esac 210 211 # Install or Package 212 if [ -n "$INSTALL_DIR" ] ; then 213 dump "Copying files to: $INSTALL_DIR" 214 run copy_directory "$TMPDIR" "$INSTALL_DIR" 215 else 216 PACKAGE_FILE="$PACKAGE_DIR/$TOOLCHAIN_NAME.tar.bz2" 217 dump "Creating package file: $PACKAGE_FILE" 218 pack_archive "$PACKAGE_FILE" "`dirname $TMPDIR`" "$TOOLCHAIN_NAME" 219 fail_panic "Could not create tarball from $TMPDIR" 220 fi 221 dump "Cleaning up..." 222 run rm -rf $TMPDIR 223 224 dump "Done." 225