Fix bug 181: log does not take base into account without mpfr
[sxemacs] / configgmp.guess
1 #! /bin/sh
2 #
3 # GMP config.guess wrapper.
4
5
6 # Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 Free Software
7 # Foundation, Inc.
8 #
9 # This file is part of the GNU MP Library.
10 #
11 # The GNU MP Library is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU Lesser General Public License as published
13 # by the Free Software Foundation; either version 3 of the License, or (at
14 # your option) any later version.
15 #
16 # The GNU MP Library is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19 # License for more details.
20 #
21 # You should have received a copy of the GNU Lesser General Public License
22 # along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
23
24
25 # Usage: config.guess
26 #
27 # Print the host system CPU-VENDOR-OS.
28 #
29 # configfsf.guess is run and its guess then sharpened up to take advantage
30 # of the finer grained CPU types that GMP knows.
31
32
33 # Expect to find configfsf.guess in the same directory as this config.guess
34 configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
35 if test "$configfsf_guess" = "$0"; then
36   echo "Cannot derive configfsf.guess from $0" 1>&2
37   exit 1
38 fi
39 if test -f "$configfsf_guess"; then
40   :
41 else
42   echo "$configfsf_guess not found" 1>&2
43   exit 1
44 fi
45
46 # Setup a $SHELL with which to run configfsf.guess, using the same
47 # $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess
48 SHELL=${CONFIG_SHELL-/bin/sh}
49
50 # Identify ourselves on --version, --help or errors
51 if test $# != 0; then
52   echo "(GNU MP wrapped config.guess)"
53   $SHELL $configfsf_guess "$@"
54   exit 1
55 fi
56
57 guess_full=`$SHELL $configfsf_guess`
58 if test $? != 0; then
59   exit 1
60 fi
61
62 guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
63 guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
64 exact_cpu=
65
66
67 # -------------------------------------------------------------------------
68 # The following should look at the current guess and probe the system to
69 # establish a better guess in exact_cpu.  Leave exact_cpu empty if probes
70 # can't be done, or don't work.
71 #
72 # When a number of probes are done, test -z "$exact_cpu" can be used instead
73 # of putting each probe under an "else" of the preceeding.  That can stop
74 # the code getting horribly nested and marching off the right side of the
75 # screen.
76
77 # Note that when a compile-and-link is done in one step we need to remove .o
78 # files, since lame C compilers generate these even when not asked.
79 #
80
81 dummy=dummy-$$
82 trap 'rm -f $dummy.c $dummy.o $dummy.core $dummy ${dummy}1.s ${dummy}2.c ; exit 1' 1 2 15
83
84 # Use $HOST_CC if defined. $CC may point to a cross-compiler
85 if test x"$CC_FOR_BUILD" = x; then
86   if test x"$HOST_CC" != x; then
87     CC_FOR_BUILD="$HOST_CC"
88   else
89     if test x"$CC" != x; then
90       CC_FOR_BUILD="$CC"
91     else
92       echo 'dummy(){}' >$dummy.c
93       for c in cc gcc c89 c99; do
94           ($c $dummy.c -c) >/dev/null 2>&1
95           if test $? = 0; then
96               CC_FOR_BUILD="$c"; break
97           fi
98       done
99       rm -f $dummy.c $dummy.o
100       if test x"$CC_FOR_BUILD" = x; then
101         CC_FOR_BUILD=no_compiler_found
102       fi
103     fi
104   fi
105 fi
106
107
108 case "$guess_full" in
109
110 alpha-*-*)
111   # configfsf.guess detects exact alpha cpu types for OSF and GNU/Linux, but
112   # not for *BSD and other systems.  We try to get an exact type for any
113   # plain "alpha" it leaves.
114   #
115   # configfsf.guess used to have a block of code not unlike this, but these
116   # days does its thing with Linux kernel /proc/cpuinfo or OSF psrinfo.
117   #
118   cat <<EOF >$dummy.s
119         .data
120 Lformat:
121         .byte 37,100,45,37,120,10,0     # "%d-%x\n"
122         .text
123         .globl main
124         .align 4
125         .ent main
126 main:
127         .frame \$30,16,\$26,0
128         ldgp \$29,0(\$27)
129         .prologue 1
130         .long 0x47e03d91 # implver \$17
131         lda \$2,-1
132         .long 0x47e20c21 # amask \$2,\$1
133         lda \$16,Lformat
134         not \$1,\$18
135         jsr \$26,printf
136         ldgp \$29,0(\$26)
137         mov 0,\$16
138         jsr \$26,exit
139         .end main
140 EOF
141   $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
142   if test "$?" = 0 ; then
143     case `./$dummy` in
144     0-0)        exact_cpu=alpha      ;;
145     1-0)        exact_cpu=alphaev5   ;;
146     1-1)        exact_cpu=alphaev56  ;;
147     1-101)      exact_cpu=alphapca56 ;;
148     2-303)      exact_cpu=alphaev6   ;;
149     2-307)      exact_cpu=alphaev67  ;;
150     2-1307)     exact_cpu=alphaev68  ;;
151     esac
152   fi
153   rm -f $dummy.s $dummy.o $dummy
154   ;;
155
156 ia64*-*-*)
157   # CPUID[3] bits 24 to 31 is the processor family.  itanium2 is documented
158   # as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
159   # haven't found any documentation on it as such.
160   #
161   # Defining both getcpuid and _getcpuid lets us ignore whether the system
162   # expects underscores or not.
163   #
164   # "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
165   # (which is the default there), it's the only 64-bit type.
166   #
167   cat >${dummy}a.s <<EOF
168         .text
169         .global _getcpuid
170         .proc   _getcpuid
171 _getcpuid:
172         mov     r8 = CPUID[r32] ;;
173         br.ret.sptk.many rp ;;
174         .endp   _getcpuid
175         .global getcpuid
176         .proc   getcpuid
177 getcpuid:
178         mov     r8 = CPUID[r32] ;;
179         br.ret.sptk.many rp ;;
180         .endp   getcpuid
181 EOF
182   cat >${dummy}b.c <<EOF
183 #include <stdio.h>
184 unsigned long long getcpuid ();
185 int
186 main ()
187 {
188   if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
189     {
190       /* "GenuineIntel" */
191       switch ((getcpuid(3LL) >> 24) & 0xFF) {
192       case 0x07: puts ("itanium");  break;
193       case 0x1F: puts ("itanium2"); break; /* McKinley, Madison */
194       case 0x20: puts ("itanium2"); break; /* Montecito */
195       }
196     }
197   return 0;
198 }
199 EOF
200   if $CC_FOR_BUILD ${dummy}a.s ${dummy}b.c -o $dummy >/dev/null 2>&1; then
201     exact_cpu=`./$dummy`
202   fi
203   rm -f ${dummy}a.s ${dummy}a.o ${dummy}b.c ${dummy}b.o $dummy $dummy.core core
204   ;;
205
206 mips-*-irix[6789]*)
207   # IRIX 6 and up always has a 64-bit mips cpu
208   exact_cpu=mips64
209   ;;
210
211 m68k-*-*)
212   # NetBSD (and presumably other *BSD) "sysctl hw.model" gives for example
213   #   hw.model = Apple Macintosh Quadra 610  (68040)
214   exact_cpu=`(sysctl hw.model) 2>/dev/null | sed -n 's/^.*\(680[012346]0\).*$/m\1/p'`
215   if test -z "$exact_cpu"; then
216     # Linux kernel 2.2 gives for example "CPU: 68020" (tabs in between).
217     exact_cpu=`sed -n 's/^CPU:.*\(680[012346]0\).*$/m\1/p' /proc/cpuinfo 2>/dev/null`
218   fi
219   if test -z "$exact_cpu"; then
220     # Try: movel #0,%d0; rts
221     # This is to check the compiler and our asm code works etc, before
222     # assuming failures below indicate cpu characteristics.
223     # .byte is used to avoid problems with assembler syntax variations.
224     # For testing, provoke failures by adding "illegal" possibly as
225     # ".byte 0x4A, 0xFC"
226     cat >$dummy.s <<EOF
227         .text
228         .globl main
229         .globl _main
230 main:
231 _main:
232         .byte   0x70, 0x00
233         .byte   0x4e, 0x75
234 EOF
235     if ($CC_FOR_BUILD $dummy.s -o $dummy && ./$dummy) >/dev/null 2>&1; then
236
237       # $SHELL -c is used to execute ./$dummy below, since (./$dummy)
238       # 2>/dev/null still prints the SIGILL message on some shells.
239       #
240         # Try: movel #0,%d0
241         #      rtd #0
242         cat >$dummy.s <<EOF
243         .text
244         .globl main
245         .globl _main
246 main:
247 _main:
248         .byte   0x70, 0x00
249         .byte   0x4e, 0x74, 0x00, 0x00
250 EOF
251         if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
252           $SHELL -c ./$dummy >/dev/null 2>&1
253           if test $? != 0; then
254             exact_cpu=m68000    # because rtd didn't work
255           fi
256         fi
257       #
258
259       if test -z "$exact_cpu"; then
260         # Try: trapf
261         #      movel #0,%d0
262         #      rts
263         # Another possibility for identifying 68000 and 68010 is the
264         # different value stored by "movem a0,(a0)+"
265         cat >$dummy.s <<EOF
266         .text
267         .globl main
268         .globl _main
269 main:
270 _main:
271         .byte   0x51, 0xFC
272         .byte   0x70, 0x00
273         .byte   0x4e, 0x75
274 EOF
275         if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
276           $SHELL -c ./$dummy >/dev/null 2>&1
277           if test $? != 0; then
278             exact_cpu=m68010    # because trapf didn't work
279           fi
280         fi
281       fi
282
283       if test -z "$exact_cpu"; then
284         # Try: bfffo %d1{0:31},%d0
285         #      movel #0,%d0
286         #      rts
287         cat >$dummy.s <<EOF
288         .text
289         .globl main
290         .globl _main
291 main:
292 _main:
293         .byte   0xED, 0xC1, 0x00, 0x1F
294         .byte   0x70, 0x00
295         .byte   0x4e, 0x75
296 EOF
297         if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
298           $SHELL -c ./$dummy >/dev/null 2>&1
299           if test $? != 0; then
300             exact_cpu=m68360  # cpu32, because bfffo didn't work
301           fi
302         fi
303       fi
304
305       if test -z "$exact_cpu"; then
306         # FIXME: Now we know 68020 or up, but how to detect 030, 040 and 060?
307         exact_cpu=m68020
308       fi
309     fi
310     rm -f $dummy.s $dummy.o $dummy $dummy.core core
311   fi
312   if test -z "$exact_cpu"; then
313     case "$guess_full" in
314       *-*-next* | *-*-openstep*)  # NeXTs are 68020 or better
315         exact_cpu=m68020 ;;
316     esac
317   fi
318   ;;
319
320
321 powerpc*-*-*bsd* )
322   # FreeBSD and OpenBSD are potentially narcy when we try to squeeze more
323   # information out of the CPU, so instead we use sysctl and parse the output.
324   # One hopes that someday this kludge will be unnecessary.
325   # As with the sparc tests, the use of a hardcoded path is necessary for sysctl.
326   #
327   # Example output:        hw.model: Motorola PowerPC 7400
328   #
329   if test -z "$exact_cpu"; then
330       model=$(/sbin/sysctl hw.model|sed 's/.* \([[:digit:]].*$\)/\1/')
331       case $model in
332           # These are the only powerpcs we're likely to see.
333           # 7400 or newer and we can use Altivec (theoretically).
334           60[134]|750|7400|745[05]|970)  exact_cpu=powerpc$model ;;
335           # Then for prototype/testing powerpc chips that
336           # didn't really make it into the wild. We don't see
337           # these usually, but just in case...
338           630|860|74[45]7|7410)          exact_cpu=powerpc$model ;;
339           *)                             exact_cpu=powerpc ;;
340       esac
341   fi
342   ;;
343
344 rs6000-*-* | powerpc*-*-*)
345   # Enhancement: On MacOS the "machine" command prints for instance
346   # "ppc750".  Interestingly on powerpc970-apple-darwin6.8.5 it prints
347   # "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
348   # (as noted below).  But the man page says the command is still "under
349   # development", so it doesn't seem wise to use it just yet, not while
350   # there's an alternative.
351   #
352   # Try to read the PVR.  mfpvr is a protected instruction, NetBSD, MacOS
353   # and AIX don't allow it in user mode, but the Linux kernel does.
354   #
355   # Using explicit bytes for mfpvr avoids worrying about assembler syntax
356   # and underscores.  "char"s are used instead of "int"s to avoid worrying
357   # whether sizeof(int)==4 or if it's the right endianness.
358   #
359   # Note this is no good on AIX, since a C function there is the address of
360   # a function descriptor, not actual code.  But this doesn't matter since
361   # AIX doesn't allow mfpvr anyway.
362   #
363   cat >$dummy.c <<\EOF
364 #include <stdio.h>
365 struct {
366   int   n;  /* force 4-byte alignment */
367   char  a[8];
368 } getpvr = {
369   0,
370   {
371     0x7c, 0x7f, 0x42, 0xa6,  /* mfpvr r3 */
372     0x4e, 0x80, 0x00, 0x20,  /* blr      */
373   }
374 };
375 int
376 main ()
377 {
378   unsigned  (*fun)();
379   unsigned  pvr;
380
381   /* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS,
382      it gets a compiler error on a combined cast and call */
383   fun = (unsigned (*)()) getpvr.a;
384   pvr = (*fun) ();
385
386   switch (pvr >> 16) {
387   case 0x0001: puts ("powerpc601");  break;
388   case 0x0003: puts ("powerpc603");  break;
389   case 0x0004: puts ("powerpc604");  break;
390   case 0x0006: puts ("powerpc603e"); break;
391   case 0x0007: puts ("powerpc603e"); break;  /* 603ev */
392   case 0x0008: puts ("powerpc750");  break;
393   case 0x0009: puts ("powerpc604e"); break;
394   case 0x000a: puts ("powerpc604e"); break;  /* 604ev5 */
395   case 0x000c: puts ("powerpc7400"); break;
396   case 0x0041: puts ("powerpc630");  break;
397   case 0x0050: puts ("powerpc860");  break;
398   case 0x8000: puts ("powerpc7450"); break;
399   case 0x8001: puts ("powerpc7455"); break;
400   case 0x8002: puts ("powerpc7457"); break;
401   case 0x8003: puts ("powerpc7447"); break; /* really 7447A */
402   case 0x800c: puts ("powerpc7410"); break;
403   }
404   return 0;
405 }
406 EOF
407   if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
408     # This style construct is needed on AIX 4.3 to suppress the SIGILL error
409     # from (*fun)().  Using $SHELL -c ./$dummy 2>/dev/null doesn't work.
410     { x=`./$dummy`; } 2>/dev/null
411     if test -n "$x"; then
412       exact_cpu=$x
413     fi
414   fi
415   rm -f $dummy.c $dummy.o $dummy $dummy.core
416
417   # Grep the linux kernel /proc/cpuinfo pseudo-file.
418   # Anything unrecognised is ignored, since of course we mustn't spit out
419   # a cpu type config.sub doesn't know.
420   if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
421     x=`grep "^cpu[      ]" /proc/cpuinfo | head -n 1`
422     x=`echo $x | sed -n 's/^cpu[        ]*:[    ]*\([A-Za-z0-9]*\).*/\1/p'`
423     x=`echo $x | sed 's/PPC//'`
424     case $x in
425       601)     exact_cpu="power" ;;
426       603ev)   exact_cpu="powerpc603e" ;;
427       604ev5)  exact_cpu="powerpc604e" ;;
428       603 | 603e | 604 | 604e | 750 | 821 | 860 | 970)
429         exact_cpu="powerpc$x" ;;
430       POWER[4-9])
431         exact_cpu=`echo $x | sed "s;POWER;power;"` ;;
432     esac
433   fi
434
435   if test -z "$exact_cpu"; then
436     # On AIX, try looking at _system_configuration.  This is present in
437     # version 4 at least.
438     cat >$dummy.c <<EOF
439 #include <stdio.h>
440 #include <sys/systemcfg.h>
441 int
442 main ()
443 {
444   switch (_system_configuration.implementation) {
445   /* Old versions of AIX don't have all these constants,
446      use ifdef for safety. */
447 #ifdef POWER_RS2
448   case POWER_RS2:    puts ("power2");     break;
449 #endif
450 #ifdef POWER_601
451   case POWER_601:    puts ("power");      break;
452 #endif
453 #ifdef POWER_603
454   case POWER_603:    puts ("powerpc603"); break;
455 #endif
456 #ifdef POWER_604
457   case POWER_604:    puts ("powerpc604"); break;
458 #endif
459 #ifdef POWER_620
460   case POWER_620:    puts ("powerpc620"); break;
461 #endif
462 #ifdef POWER_630
463   case POWER_630:    puts ("powerpc630"); break;
464 #endif
465   /* Dunno what this is, leave it out for now.
466   case POWER_A35:    puts ("powerpca35"); break;
467   */
468   /* This is waiting for a bit more info.
469   case POWER_RS64II: puts ("powerpcrs64ii"); break;
470   */
471   default:
472     if (_system_configuration.architecture == POWER_RS)
473       puts ("power");
474     else if (_system_configuration.width == 64)
475       puts ("powerpc64");
476   }
477   return 0;
478 }
479 EOF
480     if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
481       x=`./$dummy`
482       if test -n "$x"; then
483         exact_cpu=$x
484       fi
485     fi
486     rm -f $dummy.c $dummy.o $dummy
487   fi
488
489   if test -z "$exact_cpu"; then
490     # On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
491     # can tell us the exact cpu.
492     cat >$dummy.c <<EOF
493 #include <stdio.h>
494 #include <mach-o/arch.h>
495 int
496 main (void)
497 {
498   const NXArchInfo *a = NXGetLocalArchInfo();
499   if (a->cputype == CPU_TYPE_POWERPC)
500     {
501       switch (a->cpusubtype) {
502       /* The following known to Darwin 1.3. */
503       case CPU_SUBTYPE_POWERPC_601:   puts ("powerpc601");  break;
504       case CPU_SUBTYPE_POWERPC_602:   puts ("powerpc602");  break;
505       case CPU_SUBTYPE_POWERPC_603:   puts ("powerpc603");  break;
506       case CPU_SUBTYPE_POWERPC_603e:  puts ("powerpc603e"); break;
507       case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
508       case CPU_SUBTYPE_POWERPC_604:   puts ("powerpc604");  break;
509       case CPU_SUBTYPE_POWERPC_604e:  puts ("powerpc604e"); break;
510       case CPU_SUBTYPE_POWERPC_620:   puts ("powerpc620");  break;
511       case CPU_SUBTYPE_POWERPC_750:   puts ("powerpc750");  break;
512       case CPU_SUBTYPE_POWERPC_7400:  puts ("powerpc7400"); break;
513       case CPU_SUBTYPE_POWERPC_7450:  puts ("powerpc7450"); break;
514       /* Darwin 6.8.5 doesn't define the following */
515       case 0x8001:                    puts ("powerpc7455"); break;
516       case 0x8002:                    puts ("powerpc7457"); break;
517       case 0x8003:                    puts ("powerpc7447"); break;
518       case 100:                       puts ("powerpc970");  break;
519       }
520     }
521   return 0;
522 }
523 EOF
524     if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
525       x=`./$dummy`
526       if test -n "$x"; then
527         exact_cpu=$x
528       fi
529     fi
530     rm -f $dummy.c $dummy.o $dummy
531   fi
532   ;;
533
534 sparc-*-* | sparc64-*-*)
535   # If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
536   # to short-circuit subsequent tests.
537
538   # Grep the linux kernel /proc/cpuinfo pseudo-file.
539   # A typical line is "cpu\t\t: TI UltraSparc II  (BlackBird)"
540   # See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
541   #
542   if test -f /proc/cpuinfo; then
543     if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
544       exact_cpu="sparc"   # ie. v7
545     elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
546       exact_cpu="sparc"   # ie. v7
547     elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
548       exact_cpu="sparcv8"
549     elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
550       exact_cpu="supersparc"
551     elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
552       exact_cpu="microsparc"
553     elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
554       # actually MicroSPARC-II
555       exact_cpu=microsparc
556     elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
557       # this grep pattern has not been tested against any Linux
558       exact_cpu="ultrasparct1"
559     elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
560       exact_cpu="ultrasparc3"
561     elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
562       exact_cpu="ultrasparc2i"
563     elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
564       exact_cpu="ultrasparc2"
565     elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
566       exact_cpu="ultrasparc"
567     fi
568   fi
569
570   # Grep the output from sysinfo on SunOS.
571   # sysinfo has been seen living in /bin or in /usr/kvm
572   #     cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
573   #     cpu0 is a "75 MHz TI,TMS390Z55" CPU
574   #
575   if test -z "$exact_cpu"; then
576     for i in sysinfo /usr/kvm/sysinfo; do
577       if $SHELL -c $i 2>/dev/null >conftest.dat; then
578         if grep 'cpu0 is a "SuperSPARC' conftest.dat >/dev/null; then
579           exact_cpu=supersparc
580           break
581         elif grep 'cpu0 is a .*TMS390Z5.' conftest.dat >/dev/null; then
582           # TMS390Z50 and TMS390Z55
583           exact_cpu=supersparc
584           break
585         fi
586       fi
587     done
588     rm -f conftest.dat
589   fi
590
591   # Grep the output from prtconf on Solaris.
592   # Use an explicit /usr/sbin, since that directory might not be in a normal
593   # user's path.
594   #
595   #     SUNW,UltraSPARC (driver not attached)
596   #     SUNW,UltraSPARC-II (driver not attached)
597   #     SUNW,UltraSPARC-IIi (driver not attached)
598   #     SUNW,UltraSPARC-III+ (driver not attached)
599   #     Ross,RT625 (driver not attached)
600   #     TI,TMS390Z50 (driver not attached)
601   #
602   # /usr/sbin/sysdef prints similar information, but includes all loadable
603   # cpu modules, not just the real cpu.
604   #
605   # We first try a plain prtconf, since that is known to work on older systems.
606   # But for newer T1 systems, that doesn't produce any useful output, we need
607   # "prtconf -vp" there.
608   #
609   for prtconfopt in "" "-vp"; do
610     if test -z "$exact_cpu"; then
611       if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >conftest.dat; then
612         if grep 'SUNW,UltraSPARC-T1' conftest.dat >/dev/null; then
613           exact_cpu=ultrasparct1
614         elif grep 'SUNW,UltraSPARC-III' conftest.dat >/dev/null; then
615           exact_cpu=ultrasparc3
616         elif grep 'SUNW,UltraSPARC-IIi' conftest.dat >/dev/null; then
617           exact_cpu=ultrasparc2i
618         elif grep 'SUNW,UltraSPARC-II' conftest.dat >/dev/null; then
619           exact_cpu=ultrasparc2
620         elif grep 'SUNW,UltraSPARC' conftest.dat >/dev/null; then
621           exact_cpu=ultrasparc
622         elif grep 'Ross,RT62.' conftest.dat >/dev/null; then
623           # RT620, RT625, RT626 hypersparcs (v8).
624           exact_cpu=sparcv8
625         elif grep 'TI,TMS390Z5.' conftest.dat >/dev/null; then
626           # TMS390Z50 and TMS390Z55
627           exact_cpu=supersparc
628         elif grep 'TI,TMS390S10' conftest.dat >/dev/null; then
629           exact_cpu=microsparc
630         elif grep 'FMI,MB86904' conftest.dat >/dev/null; then
631           # actually MicroSPARC-II
632           exact_cpu=microsparc
633         fi
634       fi
635       rm -f conftest.dat
636     fi
637   done
638
639   # Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
640   # Use an explicit /sbin, since that directory might not be in a normal
641   # user's path.  Example outputs,
642   #
643   #     hw.model: Sun Microsystems UltraSparc-IIi
644   #
645   if test -z "$exact_cpu"; then
646     if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >conftest.dat; then
647       if grep 'UltraSparc-T1' conftest.dat >/dev/null; then
648         # this grep pattern has not been tested against any BSD
649         exact_cpu=ultrasparct1
650       elif grep 'UltraSparc-III' conftest.dat >/dev/null; then
651         exact_cpu=ultrasparc3
652       elif grep 'UltraSparc-IIi' conftest.dat >/dev/null; then
653         exact_cpu=ultrasparc2i
654       elif grep 'UltraSparc-II' conftest.dat >/dev/null; then
655         exact_cpu=ultrasparc2
656       elif grep 'UltraSparc' conftest.dat >/dev/null; then
657         exact_cpu=ultrasparc
658       elif grep 'TMS390Z5.' conftest.dat >/dev/null; then
659         # TMS390Z50 and TMS390Z55
660         exact_cpu=supersparc
661       elif grep 'TMS390S10' conftest.dat >/dev/null; then
662         exact_cpu=microsparc
663       elif grep 'MB86904' conftest.dat >/dev/null; then
664         # actually MicroSPARC-II
665         exact_cpu=microsparc
666       elif grep 'MB86907' conftest.dat >/dev/null; then
667         exact_cpu=turbosparc
668       fi
669     fi
670     rm -f conftest.dat
671   fi
672
673   # sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
674   #
675   if test -z "$exact_cpu"; then
676     case `uname -m` in
677       sun4[md]) exact_cpu=sparcv8 ;;
678       sun4u)    exact_cpu=sparcv9 ;;
679     esac
680   fi
681   ;;
682
683 i?86-*-* | amd64-*-* | x86_64-*-*)
684   cat <<EOF >${dummy}0.s
685         .globl cpuid
686         .globl _cpuid
687 cpuid:
688 _cpuid:
689         pushl %esi
690         pushl %ebx
691         movl 16(%esp),%eax
692         .byte 0x0f
693         .byte 0xa2
694         movl 12(%esp),%esi
695         movl %ebx,(%esi)
696         movl %edx,4(%esi)
697         movl %ecx,8(%esi)
698         popl %ebx
699         popl %esi
700         ret
701 EOF
702   cat <<EOF >${dummy}1.s
703         .globl cpuid
704         .globl _cpuid
705 cpuid:
706 _cpuid:
707         push %rbx
708         mov %esi,%eax
709         .byte 0x0f
710         .byte 0xa2
711         mov %ebx,(%rdi)
712         mov %edx,4(%rdi)
713         mov %ecx,8(%rdi)
714         pop %rbx
715         ret
716 EOF
717   cat <<EOF >${dummy}2.c
718 main ()
719 {
720   char vendor_string[13];
721   char dummy_string[12];
722   long fms;
723   int family, model, stepping;
724   char *modelstr;
725
726   cpuid (vendor_string, 0);
727   vendor_string[12] = 0;
728
729   fms = cpuid (dummy_string, 1);
730
731   family = ((fms >> 8) & 0xf) + ((fms >> 20) & 0xff);
732   model = ((fms >> 4) & 0xf) + ((fms >> 12) & 0xf0);
733   stepping = fms & 0xf;
734
735   modelstr = "$guess_cpu";
736   if (strcmp (vendor_string, "GenuineIntel") == 0)
737     {
738       switch (family)
739         {
740         case 5:
741           if (model <= 2)       modelstr = "pentium";
742           else if (model >= 4)  modelstr = "pentiummmx";
743           break;
744         case 6:
745           if (model <= 1)       modelstr = "pentiumpro";
746           else if (model <= 6)  modelstr = "pentium2";
747           else if (model <= 8)  modelstr = "pentium3";
748           else if (model <= 9)  modelstr = "pentiumm";
749           else if (model <= 12) modelstr = "pentium3";
750           else if (model <= 14) modelstr = "pentiumm";
751           else                  modelstr = "core2";
752           break;
753         case 15:
754           modelstr = "pentium4";
755           break;
756         }
757     }
758   else if (strcmp (vendor_string, "AuthenticAMD") == 0)
759     {
760       switch (family)
761         {
762         case 5:
763           if (model <= 3)       modelstr = "k5";
764           else if (model <= 7)  modelstr = "k6";
765           else if (model == 8)  modelstr = "k62";
766           else if (model == 9)  modelstr = "k63";
767           else if (model == 10) modelstr = "geode";
768           else if (model == 13) modelstr = "k63";
769           break;
770         case 6:
771           modelstr = "athlon";
772           break;
773         case 15:
774         case 16:
775           modelstr = "athlon64";
776           break;
777         }
778     }
779   else if (strcmp (vendor_string, "CyrixInstead") == 0)
780     {
781       /* Should recognize Cyrix' processors too.  */
782     }
783   else if (strcmp (vendor_string, "CentaurHauls") == 0)
784     {
785       switch (family)
786         {
787         case 6:
788           if (model < 9)        modelstr = "viac3";
789           else                  modelstr = "viac32";
790           break;
791         }
792     }
793
794   printf ("%s\n", modelstr);
795   return 0;
796 }
797 EOF
798
799   if ($CC_FOR_BUILD ${dummy}1.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
800     # On 80386 and early 80486 cpuid is not available and will result in a
801     # SIGILL message, hence 2>/dev/null.
802     #
803     # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
804     # "Illegal instruction (core dumped)" message to stdout, so we test $?
805     # to check if the program run was successful.
806     #
807     x=`$SHELL -c ./$dummy 2>/dev/null`
808     if test $? = 0 && test -n "$x"; then
809       exact_cpu=$x
810     fi
811   fi
812
813   if test -z "$exact_cpu"; then
814   if ($CC_FOR_BUILD ${dummy}0.s ${dummy}2.c -o $dummy) >/dev/null 2>&1; then
815     # On 80386 and early 80486 cpuid is not available and will result in a
816     # SIGILL message, hence 2>/dev/null.
817     #
818     # On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
819     # "Illegal instruction (core dumped)" message to stdout, so we test $?
820     # to check if the program run was successful.
821     #
822     x=`$SHELL -c ./$dummy 2>/dev/null`
823     if test $? = 0 && test -n "$x"; then
824       exact_cpu=$x
825     fi
826   fi
827   fi
828
829   # We need to remove some .o files here since lame C compilers
830   # generate these even when not asked.
831   rm -f ${dummy}0.s ${dummy}0.o ${dummy}1.s ${dummy}1.o ${dummy}2.c ${dummy}2.o $dummy
832   ;;
833
834 esac
835
836
837
838 # -------------------------------------------------------------------------
839 # Use an exact cpu, if possible
840
841 if test -n "$exact_cpu"; then
842   echo "$exact_cpu$guess_rest"
843 else
844   echo "$guess_full"
845 fi
846 exit 0
847
848
849
850 # Local variables:
851 # fill-column: 76
852 # End: