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 *) 74 ARCH=arm 75 ;; 76 esac 77 log "Auto-config: --arch=$ARCH" 78 fi 79 80 # Check toolchain name 81 if [ -z "$TOOLCHAIN_NAME" ]; then 82 TOOLCHAIN_NAME=$(get_default_toolchain_name_for_arch $ARCH) 83 echo "Auto-config: --toolchain=$TOOLCHAIN_NAME" 84 fi 85 86 # Check PLATFORM 87 if [ -z "$PLATFORM" ]; then 88 case $ARCH in 89 arm) PLATFORM=android-3 90 ;; 91 x86) 92 PLATFORM=android-9 93 ;; 94 esac 95 log "Auto-config: --platform=$PLATFORM" 96 fi 97 98 if [ ! -d "$NDK_DIR/platforms/$PLATFORM" ] ; then 99 echo "Invalid platform name: $PLATFORM" 100 echo "Please use --platform=<name> with one of:" `(cd "$NDK_DIR/platforms" && ls)` 101 exit 1 102 fi 103 104 # Check toolchain name 105 TOOLCHAIN_PATH="$NDK_DIR/toolchains/$TOOLCHAIN_NAME" 106 if [ ! -d "$TOOLCHAIN_PATH" ] ; then 107 echo "Invalid toolchain name: $TOOLCHAIN_NAME" 108 echo "Please use --toolchain=<name> with the name of a toolchain supported by the source NDK." 109 echo "Try one of: " `(cd "$NDK_DIR/toolchains" && ls)` 110 exit 1 111 fi 112 113 # Extract architecture from platform name 114 case "$TOOLCHAIN_NAME" in 115 arm-*) 116 ;; 117 x86-*) 118 ;; 119 *) 120 echo "Unsupported toolchain name: $TOOLCHAIN_NAME" 121 echo "Name must start with arm- or x86- !" 122 exit 1 123 ;; 124 esac 125 126 # Check that there are any platform files for it! 127 (cd $NDK_DIR/platforms && ls -d */arch-${ARCH} >/dev/null 2>&1 ) 128 if [ $? != 0 ] ; then 129 echo "Platform $PLATFORM doesn't have any files for this architecture: $ARCH" 130 echo "Either use --platform=<name> or --toolchain=<name> to select a different" 131 echo "platform or arch-dependent toolchain name (respectively)!" 132 exit 1 133 fi 134 135 # Compute source sysroot 136 SRC_SYSROOT="$NDK_DIR/platforms/$PLATFORM/arch-$ARCH" 137 if [ ! -d "$SRC_SYSROOT" ] ; then 138 echo "No platform files ($PLATFORM) for this architecture: $ARCH" 139 exit 1 140 fi 141 142 # Check that we have any prebuilts here 143 if [ ! -d "$TOOLCHAIN_PATH/prebuilt" ] ; then 144 echo "Toolchain is missing prebuilt files: $TOOLCHAIN_NAME" 145 echo "You must point to a valid NDK release package!" 146 exit 1 147 fi 148 149 if [ ! -d "$TOOLCHAIN_PATH/prebuilt/$SYSTEM" ] ; then 150 echo "Host system '$SYSTEM' is not supported by the source NDK!" 151 echo "Try --system=<name> with one of: " `(cd $TOOLCHAIN_PATH/prebuilt && ls) | grep -v gdbserver` 152 exit 1 153 fi 154 155 TOOLCHAIN_PATH="$TOOLCHAIN_PATH/prebuilt/$SYSTEM" 156 157 # Create temporary directory 158 TMPDIR=$NDK_TMPDIR/standalone/$TOOLCHAIN_NAME 159 160 dump "Copying prebuilt binaries..." 161 # Now copy the toolchain prebuilt binaries 162 run copy_directory "$TOOLCHAIN_PATH" "$TMPDIR" 163 164 dump "Copying sysroot headers and libraries..." 165 # Copy the sysroot under $TMPDIR/sysroot. The toolchain was built to 166 # expect the sysroot files to be placed there! 167 run copy_directory_nolinks "$SRC_SYSROOT" "$TMPDIR/sysroot" 168 169 dump "Copying libstdc++ headers and libraries..." 170 `dirname $0`/copy-libstdcxx.sh --reverse "$TMPDIR" "$NDK_DIR" --toolchain=$TOOLCHAIN_NAME 171 fail_panic "Could not copy libstdc++!" 172 173 # Install or Package 174 if [ -n "$INSTALL_DIR" ] ; then 175 dump "Copying files to: $INSTALL_DIR" 176 run copy_directory "$TMPDIR" "$INSTALL_DIR" 177 else 178 PACKAGE_FILE="$PACKAGE_DIR/$TOOLCHAIN_NAME.tar.bz2" 179 dump "Creating package file: $PACKAGE_FILE" 180 pack_archive "$PACKAGE_FILE" "`dirname $TMPDIR`" "$TOOLCHAIN_NAME" 181 fail_panic "Could not create tarball from $TMPDIR" 182 fi 183 dump "Cleaning up..." 184 run rm -rf $TMPDIR 185 186 dump "Done." 187