#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/autoconf/processor                   */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Thu Jan 14 15:12:37 1999                          */
#*    Last change :  Tue Aug 27 20:08:14 2002 (serrano)                */
#*    -------------------------------------------------------------    */
#*    Checking the processor type                                      */
#*=====================================================================*/

installinfo=install-info
cc=gcc
path=
tmp=/tmp
user=bigloo
cpuinfo=/proc/cpuinfo

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --user=*)
      user="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --installinfo=*|-installinfo=*)
      installinfo="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --cc=*|-cc=*)
      cc="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --exe=*)
      exe="`echo $1 | sed 's/^[-a-z]*=//'`";;

    --tmp=*|-tmp=*)
      tmp="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=$tmp/actest$user
aout=$tmp/Xactest$user

#*---------------------------------------------------------------------*/
#*    The test C file                                                  */
#*---------------------------------------------------------------------*/
if [ -f $file.c ]; then
   rm -f $file.c || exit $?
fi

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
main( argc, argv )
int   argc;
char *argv[];
{
   printf( "%s", argv[ 1 ] );
   return 0;
}
EOF

$cc $cflags $file.c -o $aout >/dev/null 2> /dev/null

if [ ! -f $cpuinfo ]; then
  echo ""
else
  m=`grep "model name" $cpuinfo 2> /dev/null | grep -i "pentium III"`
  if [ "$m " != " " ]; then
    $aout$exe "pIII"
  else
    m=`grep "model name" $cpuinfo 2> /dev/null | grep -i "pentium IV"`
    if [ "$m " != " " ]; then
      $aout$exe "pIV"
    else
      m=`grep "model name" $cpuinfo 2> /dev/null | grep -i "athlon"`
      if [ "$m " != " " ]; then
        $aout$exe "athlon"
      else
        m=`grep "model name" $cpuinfo 2> /dev/null | grep -i "k6"`
        if [ "$m " != " "  ]; then
          $aout$exe "k6"
        else
          echo ""
        fi
      fi
    fi
  fi
fi

/bin/rm -rf $file.c $file.o $aout$exe $aout
