#!/bin/sh
# Copyright (c) 2002-20 Peter Guentert. All rights reserved.

# Identify system type
# PG, 04-09-2012

# ---- compiler ----

if [ "$2" = "compiler" ]; then
  for compiler in intel gfortran unknown; do
    case $compiler in
    intel) ifort -V 2>/dev/null
           if [ $? = 0 ]; then break; fi;;
    gfortran) gfortran --version >/dev/null 2>/dev/null
           if [ $? = 0 ]; then break; fi;;
    esac
  done
fi

# ---- operating system ----

system=`(uname) 2>/dev/null`
hosttype=${HOSTTYPE:-generic}
system=${system:-$hosttype}
case $system in
#Linux)            os=linux;;
Linux)
  case `uname -i` in
  x86_64) os=linux64;;
  *)      os=linux32;;
  esac
  ;;
Darwin)
  case `uname -m` in
  arm64) os=macarm;;
  *)     os=mac;;
  esac
  ;;
CYGWIN*)          os=cygwin;;
#SunOS)            os=sunos;;
#AIX)              os=aix;;
#OSF1)             os=osf1;;
#IRIX | IRIX64)    os=irix;;
#HP-UX)            os=hpux;;
#ConvexOS)         os=convex;;
#SUPER-UX)         os=nec;;
*)                os=unknown;;
esac

# ---- compiler ----

if [ "$1" = "compiler" ]; then
  for compiler in intel gfortran unknown; do
    case $compiler in
    intel) ifort -V 2>/dev/null
           if [ $? = 0 ]; then break; fi;;
    gfortran) gfortran --version >/dev/null 2>/dev/null
           if [ $? = 0 ]; then break; fi;;
    esac
  done
  echo $os-$compiler
else
  echo $os
fi
