find-systype.sh
author tomas@localhost
Thu, 01 Nov 2007 14:46:11 +0100
changeset 0 c045670f36e9
permissions -rw-r--r--
Imported queue-fix-1.4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     1
# oper-:arch-:syst-:chip-:kern-
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     2
# oper = operating system type; e.g., sunos-4.1.4
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     3
# arch = machine language; e.g., sparc
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     4
# syst = which binaries can run; e.g., sun4
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     5
# chip = chip model; e.g., micro-2-80
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     6
# kern = kernel version; e.g., sun4m
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     7
# dependence: arch --- chip
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     8
#                 \        \
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
     9
#          oper --- syst --- kern
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    10
# so, for example, syst is interpreted in light of oper, but chip is not.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    11
# anyway, no slashes, no extra colons, no uppercase letters.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    12
# the point of the extra -'s is to ease parsing: can add hierarchies later.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    13
# e.g., *:i386-*:*:pentium-*:* would handle pentium-100 as well as pentium,
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    14
# and i386-486 (486s do have more instructions, you know) as well as i386.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    15
# the idea here is to include ALL useful available information.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    16
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    17
exec 2>/dev/null
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    18
sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    19
if [ x"$sys" != x ]
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    20
then
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    21
  unamer="`uname -r | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    22
  unamem="`uname -m | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    23
  unamev="`uname -v | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    24
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    25
  case "$sys" in
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    26
  bsd.os)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    27
    # in bsd 4.4, uname -v does not have useful info.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    28
    # in bsd 4.4, uname -m is arch, not chip.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    29
    oper="$sys-$unamer"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    30
    arch="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    31
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    32
    chip="`sysctl -n hw.model`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    33
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    34
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    35
  freebsd)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    36
    # see above about bsd 4.4
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    37
    oper="$sys-$unamer"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    38
    arch="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    39
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    40
    chip="`sysctl -n hw.model`" # hopefully
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    41
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    42
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    43
  netbsd)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    44
    # see above about bsd 4.4
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    45
    oper="$sys-$unamer"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    46
    arch="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    47
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    48
    chip="`sysctl -n hw.model`" # hopefully
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    49
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    50
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    51
  linux)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    52
    # as in bsd 4.4, uname -v does not have useful info.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    53
    oper="$sys-$unamer"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    54
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    55
    chip="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    56
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    57
    case "$chip" in
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    58
    i386|i486|i586|i686)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    59
      arch="i386"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    60
      ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    61
    alpha)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    62
      arch="alpha"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    63
      ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    64
    esac
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    65
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    66
  aix)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    67
    # naturally IBM has to get uname -r and uname -v backwards. dorks.
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    68
    oper="$sys-$unamev-$unamer"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    69
    arch="`arch | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    70
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    71
    chip="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    72
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    73
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    74
  sunos)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    75
    oper="$sys-$unamer-$unamev"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    76
    arch="`(uname -p || mach) | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    77
    syst="`arch | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    78
    chip="$unamem" # this is wrong; is there any way to get the real info?
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    79
    kern="`arch -k | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    80
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    81
  unix_sv)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    82
    oper="$sys-$unamer-$unamev"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    83
    arch="`uname -m`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    84
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    85
    chip="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    86
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    87
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    88
  *)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    89
    oper="$sys-$unamer-$unamev"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    90
    arch="`arch | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    91
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    92
    chip="$unamem"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    93
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    94
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    95
  esac
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    96
else
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    97
  $CC -c trycpp.c
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    98
  $LD -o trycpp trycpp.o
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
    99
  case `./trycpp` in
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   100
  nextstep)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   101
    oper="nextstep-`hostinfo | sed -n 's/^[ 	]*NeXT Mach \([^:]*\):.*$/\1/p'`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   102
    arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   103
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   104
    chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   105
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   106
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   107
  *)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   108
    oper="unknown"
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   109
    arch=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   110
    syst=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   111
    chip=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   112
    kern=""
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   113
    ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   114
  esac
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   115
  rm -f trycpp.o trycpp
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   116
fi
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   117
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   118
case "$chip" in
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   119
80486)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   120
  # let's try to be consistent here. (BSD/OS)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   121
  chip=i486
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   122
  ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   123
i486DX)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   124
  # respect the hyphen hierarchy. (FreeBSD)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   125
  chip=i486-dx
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   126
  ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   127
i486.DX2)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   128
  # respect the hyphen hierarchy. (FreeBSD)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   129
  chip=i486-dx2
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   130
  ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   131
Intel.586)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   132
  # no, you nitwits, there is no such chip. (NeXTStep)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   133
  chip=pentium
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   134
  ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   135
i586)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   136
  # no, you nitwits, there is no such chip. (Linux)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   137
  chip=pentium
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   138
  ;;
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   139
i686)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   140
  # STOP SAYING THAT! (Linux)
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   141
  chip=ppro
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   142
esac
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   143
c045670f36e9 Imported queue-fix-1.4
tomas@localhost
parents:
diff changeset
   144
echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]'