release
[hcoop/zz_old/debian/djbdns.git] / find-systype.sh
CommitLineData
dc0d77d7
CE
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
17exec 2>/dev/null
18
19sys="`uname -s | tr '/:[A-Z]' '..[a-z]'`"
20if [ x"$sys" != x ]
21then
22 unamer="`uname -r | tr /: ..`"
23 unamem="`uname -m | tr /: ..`"
24 unamev="`uname -v | tr /: ..`"
25
26 case "$sys" in
27 bsd.os|freebsd|netbsd|openbsd)
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`" # hopefully
34 kern=""
35 ;;
36 linux)
37 # as in bsd 4.4, uname -v does not have useful info.
38 oper="$sys-$unamer"
39 syst=""
40 chip="$unamem"
41 kern=""
42 case "$chip" in
43 i386|i486|i586|i686)
44 arch="i386"
45 ;;
46 alpha)
47 arch="alpha"
48 ;;
49 esac
50 ;;
51 aix)
52 # naturally IBM has to get uname -r and uname -v backwards. dorks.
53 oper="$sys-$unamev-$unamer"
54 arch="`arch | tr /: ..`"
55 syst=""
56 chip="$unamem"
57 kern=""
58 ;;
59 sunos)
60 oper="$sys-$unamer-$unamev"
61 arch="`(uname -p || mach) | tr /: ..`"
62 syst="`arch | tr /: ..`"
63 chip="$unamem" # this is wrong; is there any way to get the real info?
64 kern="`arch -k | tr /: ..`"
65 ;;
66 unix_sv)
67 oper="$sys-$unamer-$unamev"
68 arch="`uname -m`"
69 syst=""
70 chip="$unamem"
71 kern=""
72 ;;
73 *)
74 oper="$sys-$unamer-$unamev"
75 arch="`arch | tr /: ..`"
76 syst=""
77 chip="$unamem"
78 kern=""
79 ;;
80 esac
81else
82 gcc -c trycpp.c
83 gcc -o trycpp trycpp.o
84 case `./trycpp` in
85 nextstep)
86 oper="nextstep-`hostinfo | sed -n 's/^[ ]*NeXT Mach \([^:]*\):.*$/\1/p'`"
87 arch="`hostinfo | sed -n 's/^Processor type: \(.*\) (.*)$/\1/p' | tr /: ..`"
88 syst=""
89 chip="`hostinfo | sed -n 's/^Processor type: .* (\(.*\))$/\1/p' | tr ' /:' '...'`"
90 kern=""
91 ;;
92 *)
93 oper="unknown"
94 arch=""
95 syst=""
96 chip=""
97 kern=""
98 ;;
99 esac
100 rm -f trycpp.o trycpp
101fi
102
103case "$chip" in
10480486)
105 # let's try to be consistent here. (BSD/OS)
106 chip=i486
107 ;;
108i486DX)
109 # respect the hyphen hierarchy. (FreeBSD)
110 chip=i486-dx
111 ;;
112i486.DX2)
113 # respect the hyphen hierarchy. (FreeBSD)
114 chip=i486-dx2
115 ;;
116Intel.586)
117 # no, you nitwits, there is no such chip. (NeXTStep)
118 chip=pentium
119 ;;
120i586)
121 # no, you nitwits, there is no such chip. (Linux)
122 chip=pentium
123 ;;
124i686)
125 # STOP SAYING THAT! (Linux)
126 chip=ppro
127esac
128
129if gcc -c x86cpuid.c
130then
131 if gcc -o x86cpuid x86cpuid.o
132 then
133 x86cpuid="`./x86cpuid | tr /: ..`"
134 case "$x86cpuid" in
135 ?*)
136 chip="$x86cpuid"
137 ;;
138 esac
139 fi
140fi
141rm -f x86cpuid x86cpuid.o
142
143echo "$oper-:$arch-:$syst-:$chip-:$kern-" | tr ' [A-Z]' '.[a-z]'