blob: eac1c476ab63a70039c6599468f47a7bfd634ead [file] [log] [blame]
Andrew Hsiehde74c4b2012-03-12 09:39:50 -07001#!/bin/bash
2
3HOST_OS=`uname -s | tr '[:upper:]' '[:lower:]'`
4if [ "$HOST_OS" != "linux" ] ; then
5 echo "ERROR: The gcc this script points to can only run on linux"
6 exit 1
7fi
8
9PROGNAME=`basename $0`
10
11#PREFIX32=../../gcc/linux-x86/host/i686-linux-glibc2.7-4.4.3/bin/i686-linux # previous version
12PREFIX32=../../gcc/linux-x86/host/i686-linux-glibc2.7-4.6/bin/i686-linux
13PREFIX64=../../gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin/x86_64-linux
14
15options=" ${@} " # sentinel prefix/suffix space to simplify pattern match below
16
17suffix_m32=${options##* -m32 } # suffix after the last -m32
18suffix_m64=${options##* -m64 } # suffix after the last -m64
19
20len_m32=${#suffix_m32} # length of suffix after the last -m32
21len_m64=${#suffix_m64} # length of suffix after the last -m64
22
23if [ $len_m32 -ge $len_m64 ] ; then
24 # Choose 64-bit if -m64 only, -m64 appears after -m32, or neither exist (-eq)
25 MY_TOOL=`dirname $0`/${PREFIX64}-${PROGNAME}
26 # Make sure host is running 64-bit OS.
27 # Note that "uname -m" only show host CPU is capable of. Use the following technique
28 # from ndk/build/core/ndk-common.sh instead
29 file -L "$SHELL" | grep -q "x86[_-]64"
30 if [ $? != 0 ]; then
31 # $SHELL is not a 64-bit executable, so assume our userland is too.
32 echo "ERROR: $MY_TOOL only run on 64-bit linux"
33 exit 1
34 fi
35else
36 # Otherwise, choose 32-bit
37 MY_TOOL=`dirname $0`/${PREFIX32}-${PROGNAME}
38fi
39
40$MY_TOOL "$@"