#!/bin/sh
# changed to bash as it is more likely to exist. ksh was not everywhere
#
# However, there is not always /bin/bash. Let's try if the default shell
# works for most of the systems (10.06.2003,MK)
#
# made some additional changes so that it appears to run for the /bin/sh
# on sun,ibm,irix,linux,cygwin (the shells can be ksh,bash,bourne shell)
# still some problems for AIX, but I guess there will be many more (10.06.2003, JVdV)
#
# this script should return some simplified machine code
# corresponding to the machine dependent files in 
# cp2k/arch/*.*
#



### Aliasing of commands ###
#   alias is not know by all shells
#   alias echo="\echo"

### No localization ###

    LANG=C
    LC_MESSAGES=C
    LC_ALL=C
    export LANG LC_MESSAGES LC_ALL

### Load informations for system identification ###

    ostype=`uname -s`
    osversion=`uname -v`
    osrelease=`uname -r`
    machine=`uname -m`

    platform="${ostype}-${osversion}-${osrelease}-${machine}"
    case $platform in
      Darwin-*-*-x86_64)
        if [ -n "$FORT_C_NAME" ] 
        then
          PLATFORM="Darwin-IntelMacintosh-$FORT_C_NAME"
        else
          PLATFORM="Darwin-IntelMacintosh-gfortran"
        fi;;
      Darwin-*-*-i386)
        if [ -n "$FORT_C_NAME" ] 
        then
          PLATFORM="Darwin-IntelMacintosh-$FORT_C_NAME"
        else
          PLATFORM="Darwin-IntelMacintosh-gfortran"
        fi;;
      Darwin-*-*-Power\ Macintosh)
        if [ -n "$FORT_C_NAME" ]
        then
          PLATFORM="Darwin-PowerMacintosh-$FORT_C_NAME"
        else
          PLATFORM="Darwin-PowerMacintosh-absoft"
        fi;;
      AIX-*-*-*)
        proc=`lsdev -C -r name | grep proc | tail -1`
        arch=`lsattr -l $proc -a type -F value`
        if [ -n "$arch" ]
        then
          PLATFORM="AIX-$arch"
        else
          PLATFORM="unknown"
        fi;;
      IRIX-*-*-*)
        PLATFORM="IRIX";;
      IRIX64-*-*-*)
        PLATFORM="IRIX";;
      FreeBSD-*-*-*)
        PLATFORM="FreeBSD-libint-gfortran";;
      Linux-*-*-ppc64)
        PLATFORM="Linux-bgl-ibm";;
      Linux-*-*-alpha)
        PLATFORM="Linux-dec-alpha";;
      OSF1-*-*-alpha)
        PLATFORM="DEC_OS";;
      CYGWIN*-*-i686)
        PLATFORM="Cygwin-i686-gfortran";;
      Linux-*-*-x86_64)
        if [ -n "$FORT_C_NAME" ]
        then
          PLATFORM="Linux-x86-64-$FORT_C_NAME"
        else
          PLATFORM="Linux-x86-64-gfortran"
        fi;;
      Linux-*-*-ia64)
        if [ -n "$FORT_C_NAME" ]
        then
          PLATFORM="Linux-ia64-$FORT_C_NAME"
        else
          PLATFORM="Linux-ia64-intel"
        fi;;
      Linux-*-*-*)
        if [ -n "$FORT_C_NAME" ]
        then
          PLATFORM="Linux-${machine}-$FORT_C_NAME"
        else
          PLATFORM="Linux-${machine}-gfortran"
        fi;;
      *-unicosmk-*-CRAY*T3E)
        PLATFORM="CRAY-T3E";;
      SunOS-*-sun4u)
        PLATFORM="SUN";;
      *)
        PLATFORM="unknown"
    esac

    case $PLATFORM in
        unknown)
        echo "############################################################" >&2
        echo "have a look at cp2k/tools/get_arch_code" >&2
        echo "your system is a $platform" >&2
        echo "but get_arch_code is not able to deal with that "  >&2
        echo "############################################################" >&2
    esac

    echo ${PLATFORM}

### End of procedure ###
