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