
# --8<--8<--8<--8<--
#
# Copyright (C) 2006 Smithsonian Astrophysical Observatory
#
# This file is part of sysarch
#
# sysarch is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# sysarch is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
#       Free Software Foundation, Inc.
#       51 Franklin Street, Fifth Floor
#       Boston, MA  02110-1301, USA
#
# -->8-->8-->8-->8--


###############################################################################
# hardware scan


case $os_type in

  linux)
	 exec 4< /proc/cpuinfo
	 while read -u4 hw_cpu; do
	   case "$hw_cpu" in
	     "model name"*) break;;
	     "type"*)       break;;
	   esac
	 done
	 exec 4<&-

	 hw_cpu=${hw_cpu##*:}
	 hw_cpu_generic=$_uname_m

	 case "$hw_cpu" in
	   *Athlon*MP*)   hw_cpu="athlon_mp";;
	   *Athlon*XP*)   hw_cpu="athlon_xp";;
	   *Athlon*64*)   hw_cpu="athlon_64";;
	   *Athlon*)      hw_cpu="athlon";;
	   *Atom*)        hw_cpu=atom;;
	   *Core\(TM\)2\ * ) hw_cpu=core2;;
	   *Core\(TM\)*i?* ) hw_cpu=core$(echo "$hw_cpu" | sed 's/.*\(i[0-9][0-9]*\).*/\1/') ;;
	   *EPYC*)        hw_cpu="epyc";;
	   *Opteron*)     hw_cpu="opteron";;
	   *Pentium*III*) hw_cpu="pentium3";;
	   *Pentium\(R\)\ 4* ) hw_cpu="pentium4";;
	   *Pentium\(R\)\ D* ) hw_cpu="pentiumD";;
           *U7300*)       hw_cpu=core2;;
	   *Xeon*)        hw_cpu="xeon";;
           *Virtual*)     hw_cpu="virtual";;
	   *)
		 warn  "unrecognized CPU type: $hw_cpu"
		 hw_cpu=UNKNOWN
		 ;;
	 esac

	 hw_cpus="${hw_cpu}:${hw_cpu_generic}"

	 hw_cpus_lib="$hw_cpus"

	 ;;

  solaris)

	 hw_cpu=$(/opt/SUNWspro/bin/fpversion -foption)
	 hw_cpu=${hw_cpu##*xtarget=}
	 hw_cpu=${hw_cpu%% *}

	 hw_cpu_generic=$_uname_m

	 hw_cpus="${hw_cpu}:${hw_cpu_generic}"
	 hw_cpus_lib="$hw_cpus"

	 case "$_uname_m" in
	   sun4u)         hw_cpus="$hw_cpus:sun4m:sparc";;
	   sun4*)         hw_cpus="$hw_cpus:sparc";;
	   *)
		 warn  "unrecognized CPU type: $hw_cpu"
		 hw_cpu=UNKNOWN
	 esac

	 ;;

  darwin)

	  hw_cpu=$(machine)
	  hw_cpus=$hw_cpu
	  hw_cpu_generic=$hw_cpu

	  case "$hw_cpu" in

	    # on Intel boxes machine is pretty useless -
	    #  it reports i486!
	    i486 )
		   hw_cpu=$(sysctl -n machdep.cpu.brand_string 2>/dev/null )

		   case "$hw_cpu" in

		       *Core\(TM\)*i?* ) hw_cpu=core$(echo "$hw_cpu" | sed 's/.*\(i[0-9][0-9]*\).*/\1/') ;;

		       *Xeon* ) hw_cpu=xeon ;;

		     # complain about unknown machine
		     * )
			   warn  "unrecognized CPU type: $hw_cpu"
			   hw_cpu=UNKNOWN
			   ;;
		   esac

		   if [ $(sysctl 2>/dev/null -n hw.optional.x86_64) = 1 ];
		   then
		     hw_cpu_generic=x86_64
		     hw_cpus="$hw_cpu:x86_64:i486"
		   fi
		   ;;
	  esac

	  ;;

  *)
    hw_cpu="$_uname_m"
    hw_cpu_generic="$_uname_m"
    hw_cpus="$hw_cpu"
  ;;

esac
