#!/bin/sh
# etc/config.guess -- guess the value for the TARGET configuration variable

export PATH
PATH="/bin:/usr/bin:$PATH"

case `uname -s` in
  AIX)
    OPSYS=aix
    ARCH=rs6000
    ;;
  HP-UX)
    OPSYS=hpux
    ARCH=hppa
    ;; 
  IRIX*)
    OPSYS=irix
    ARCH=mips
    ;;
  FreeBSD)
    OPSYS=linux
    ARCH=x86
    ;;
  Linux)
    OPSYS=linux
    case `uname -m` in
      ppc*) ARCH=ppc;;
      i[3456]86|x86_64)
          # We only know if the kernel is 32/64-bit. Now we ask the OS if it is running 32 or 64-bit executables.
          if test "`getconf LONG_BIT`" = 32; then
            ARCH=x86
          else
            ARCH=x86_64
          fi
        ;;
      *) exit 1;;
    esac
    ;;
  Darwin)
    OPSYS=darwin
    case `uname -m` in
      ppc*) ARCH=ppc;;
      i[3456]86|x86_64)
          if test "`getconf LONG_BIT`" = 32; then
            ARCH=x86
          else
            ARCH=x86_64
          fi
        ;;
      *) exit 1;;
     esac
    ;;
  OSF1)
    OPSYS=osf1
    case `uname -m` in
      alpha) ARCH=alpha;;
      *) exit 1;;
    esac
    ;;
  SunOS)
    case `uname -r` in
      4.*)
	OPSYS=sos4
	case `/usr/bin/arch` in
	  sun4) ARCH=sparc;;
	  *) exit 1;;
	esac
      ;;
      5.*)
	OPSYS=sol2
	case `uname -p` in
	  sparc) ARCH=sparc;;
	  i[3456]86) ARCH=x86;;
	  *) exit 1;;
	esac
      ;;
      *) exit 1;;
    esac
    ;;
  ULTRIX)
    OPSYS=ultrix
    case `uname -m` in
      RISC) ARCH=mips;;
      *) exit 1;;
    esac
    ;;
  CYGWIN_*)
    OPSYS=cygwin
    case `uname -m` in
      i[3456]86) ARCH=x86;;
      *) exit 1;;
    esac
    ;;
  MINGW32_*)
    OPSYS=mingw32
    if [ "$CC" = "" ] 
    then
      CC=gcc
    fi
    case `$CC -dumpmachine` in
      mingw32) ARCH=x86;;
      i686*) ARCH=x86;;
      x86_64*) ARCH=x86_64;;
      *) exit 1;;
    esac
    ;;
  *) exit 1;;
esac

TARGET="$ARCH-$OPSYS"
if [ -d config/$TARGET-gcc ]; then
  echo "TARGET=$TARGET-gcc"
elif [ -d config/$TARGET-cc ]; then
  echo "TARGET=$TARGET-cc"
elif [ -d config/$TARGET ]; then
  echo "TARGET=$TARGET"
else
  exit 1
fi
