#!/usr/bin/perl




















($Pgm = $0) =~ s|.*/||;

@archs   = ("SGICHALL64","SGI","SP2","PARSYTEC","CONVEXSPP",
            "SunOS","Solaris","LINUX","OSF1","RS6000","HP",
            "HITACHIMPP","CRAYT3D");
@devices = ("SHMEM_SYSV","SHMEM_SGI","MPASS_MPI",
            "MPASS_MPL","MPASS_PARIX","MPASS_EXPRESS", "DRMA_SHMEM");

%archDevice = (
  "SGICHALL64","SHMEM_SGI",
  "SGI"       ,"SHMEM_SYSV",
  "SP2",       "MPASS_MPL",
  "PARSYTEC",  "MPASS_PARIX",
  "CONVEXSPP", "SHMEM_SYSV",
  "SunOS",     "SHMEM_SYSV",
  "Solaris",   "SHMEM_SYSV",
  "LINUX",     "SHMEM_SYSV",
  "OSF1",      "SHMEM_SYSV",
  "RS6000",    "MPASS_MPI",
  "HP",        "MPASS_MPI",
  "HITACHIMPP","MPASS_EXPRESS",
  "CRAYT3D",   "DRMA_SHMEM");

%machineName = (
  "SGICHALL64","SGI Power Challenge",
  "SGI"       ,"SGI Workstation",
  "SP2",       "IBM SP2",
  "PARSYTEC",  "Parsytec Explorer",
  "CONVEXSPP", "Convex SPP",
  "SunOS",     "Sun workstation",
  "Solaris",   "Sun workstation",
  "LINUX",     "PC running Linux",
  "OSF1",      "Digital Alpha",
  "RS6000",    "IBM RS6000",
  "HP",        "HP Workstation",
  "HITACHIMPP","Hitachi SR2001",
  "CRAYT3D",   "Cray T3D");

$default_device="MPASS_MPI";

&main();
exit(0);






sub main {
  local($do_arch)  =1;
  local($do_device)=0;
  local($do_name)  =0;
  local($device,$valid_device,$machine);
  local($do_help);

  arg: while($_ = $ARGV[0]) {
    shift(@ARGV);
    /-arch/        && do {$do_arch   = 1; next arg;};
    /-device/      && do {$do_device = 1; next arg;};
    /-name/        && do {$do_name   = 1; next arg;};
    /-convertname/ && do {$do_convertname=1; $machine=shift(@ARGV);next arg;};
    /-help/        && do {$do_help   = 1; next arg;};
  }
  if ($do_help) {
    print STDERR "usage $Pgm [-arch] [-device]\n";
    print STDERR "\ntested architectures:\n";
    foreach $i (@archs) {
      print STDERR "\t$i\n";
    }
    print STDERR "\ntested devices:\n";
    foreach $i (@devices) {
      print STDERR "\t$i\n";
    }
    print STDERR "\nenvironment variable BSP_MACHINE overrides architecture",
                 "\nenvironment variable BSP_DEVICE  overrides device\n";
    exit(1);
  } elsif ($do_device) {
    $machine = &archName();
    if ($ENV{'BSP_DEVICE'}) {
      $device = $ENV{'BSP_DEVICE'}; 
    } elsif (!$archDevice{$machine}) {
      $device = $default_device;
    } else {
      $device = $archDevice{$machine};
    }
    print $device;
  } elsif ($do_name) {
    $machine = &archName();
    if ($machineName{$machine}) {
      print $machineName{$machine};
    } else {
      print "Unknown machine";
    }
  } elsif ($do_convertname) {
    if ($machineName{$machine}) {
      print $machineName{$machine};
    } else {
      print "Unknown machine";
    }
  } else {
    print &archName();
  }
}



sub archName {

  if ($ENV{'BSP_MACHINE'}) {
    return($ENV{'BSP_MACHINE'});
  }
  chop($_ = `uname -s`);
  /IRIX64/     && do { return("SGICHALL64");};
  /Linux/      && do { return("LINUX");};
  /IRIX/       && do { return("SGI");};
  /AIX/        && do { if (-e "/usr/bin/poe") {
                         return("SP2");
                       } else {
                         return("RS6000");
                       }
                     };
  /HP-UX/      && do { if (-e "/usr/convex") {
                         return("CONVEXSPP");
                       } else {
                         return("HP");
                       }
                     };

  /SunOS/      && do { if (-e "/usr/parix") {
                          return("PARSYTEC");
                       } else {
                           chop($_ = `uname -a`);
                           if (/(\d+)\.(\d+)/  && ("$1.$2"/1.0)>5.0) {
                             return ("Solaris");
                           } else {
                            return("SunOS");
                           }
                       }
                     };

  /HI-UX/      && do { return("HITACHIMPP");};

  /OSF1/       && do { return("OSF1");};

  chop($_ = `uname -m`);
  /CRAY/       && do { if (-e "/mpp/bin/mppstat") {
                         return ("CRAYT3D");
                       } else {
                         return ("CRAYUNKNOWN");
                       }
                     };
  return("GENERIC");
}



