#!/bin/sh

# Idea borrowed from SML's .arch-n-opsys - thanks!

if [ "$1" = "_" ] ; then
 SEP="_"
else
 SEP="-"
fi

if [ -x "/bin/uname" ] ; then
  UNAME=/bin/uname
  OS=`$UNAME -s`
elif [ -x "/usr/bin/uname" ] ; then
  UNAME=/usr/bin/uname
  OS=`$UNAME -s`
else
 echo archsys: cannot find uname
 exit 1
fi

case $OS in
  SunOS)
    case `$UNAME -r` in
      5.*)
      case `$UNAME -p` in
       sparc)
         SYS=sparc${SEP}solaris
         ;;
       i386)
        SYS=i386${SEP}solaris
        ;;
      esac
      ;;
     *)
      SYS=sparc${SEP}sunos4
      ;;
    esac
    ;;
  AIX)
    SYS=rs6k${SEP}aix
    ;;
  Linux)
    case `$UNAME -m` in
     ppc)
      SYS=ppc${SEP}linux
      ;;
     alpha)
      SYS=alpha{SEP}linux
      ;;
     m68k)
      SYS=m68k{SEP}linux
      ;;
     *)
      if [ -r /lib/libdl.so.1 ]; then
        SYS=i386${SEP}linux
      elif [ `file /bin/ls | grep ELF | wc -l` = 1 ]; then
        SYS=i386${SEP}linux
      else
        SYS=i386${SEP}linux${SEP}aout
      fi
      ;;
    esac
    ;;
  FreeBSD)
    SYS=i386${SEP}freebsd
    ;;
  OpenBSD)
    SYS=i386${SEP}openbsd
    ;;
  IRIX*)
    SYS=mips${SEP}irix
    ;;
  ULTRIX)
    SYS=mips${SEP}ultrix
    ;;
  OSF1)
    SYS=alpha${SEP}osf1
    ;;
  HP-UX)
    SYS=parisc${SEP}hpux
    ;;
  BeOS)
    case `$UNAME -m` in
      BePC)
       SYS=i586${SEP}beos
       ;;
      *)
       SYS=ppc${SEP}beos
       ;;
    esac
    ;;
  *)
    echo Unsupported platform $OS
    exit 1
    ;;
esac

if [ "$1" = "-" ] ; then
 echo ${SYS}
elif [ "$1" = "z" ] ; then
 echo ${SYS}${PLTMZEXTENSION}
else
 echo ${SYS}${PLTEXTENSION}
fi
