3 # GMP config.guess wrapper.
6 # Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 Free Software
9 # This file is part of the GNU MP Library.
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.
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.
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/.
27 # Print the host system CPU-VENDOR-OS.
29 # configfsf.guess is run and its guess then sharpened up to take advantage
30 # of the finer grained CPU types that GMP knows.
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
39 if test -f "$configfsf_guess"; then
42 echo "$configfsf_guess not found" 1>&2
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}
50 # Identify ourselves on --version, --help or errors
52 echo "(GNU MP wrapped config.guess)"
53 $SHELL $configfsf_guess "$@"
57 guess_full=`$SHELL $configfsf_guess`
62 guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
63 guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
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.
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
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.
82 trap 'rm -f $dummy.c $dummy.o $dummy.core $dummy ${dummy}1.s ${dummy}2.c ; exit 1' 1 2 15
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"
89 if test x"$CC" != x; then
92 echo 'dummy(){}' >$dummy.c
93 for c in cc gcc c89 c99; do
94 ($c $dummy.c -c) >/dev/null 2>&1
96 CC_FOR_BUILD="$c"; break
99 rm -f $dummy.c $dummy.o
100 if test x"$CC_FOR_BUILD" = x; then
101 CC_FOR_BUILD=no_compiler_found
108 case "$guess_full" in
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.
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.
121 .byte 37,100,45,37,120,10,0 # "%d-%x\n"
127 .frame \$30,16,\$26,0
130 .long 0x47e03d91 # implver \$17
132 .long 0x47e20c21 # amask \$2,\$1
141 $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null
142 if test "$?" = 0 ; then
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 ;;
153 rm -f $dummy.s $dummy.o $dummy
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.
161 # Defining both getcpuid and _getcpuid lets us ignore whether the system
162 # expects underscores or not.
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.
167 cat >${dummy}a.s <<EOF
172 mov r8 = CPUID[r32] ;;
173 br.ret.sptk.many rp ;;
178 mov r8 = CPUID[r32] ;;
179 br.ret.sptk.many rp ;;
182 cat >${dummy}b.c <<EOF
184 unsigned long long getcpuid ();
188 if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
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 */
200 if $CC_FOR_BUILD ${dummy}a.s ${dummy}b.c -o $dummy >/dev/null 2>&1; then
203 rm -f ${dummy}a.s ${dummy}a.o ${dummy}b.c ${dummy}b.o $dummy $dummy.core core
207 # IRIX 6 and up always has a 64-bit mips cpu
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`
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
235 if ($CC_FOR_BUILD $dummy.s -o $dummy && ./$dummy) >/dev/null 2>&1; then
237 # $SHELL -c is used to execute ./$dummy below, since (./$dummy)
238 # 2>/dev/null still prints the SIGILL message on some shells.
249 .byte 0x4e, 0x74, 0x00, 0x00
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
259 if test -z "$exact_cpu"; then
263 # Another possibility for identifying 68000 and 68010 is the
264 # different value stored by "movem a0,(a0)+"
275 if $CC_FOR_BUILD $dummy.s -o $dummy >/dev/null 2>&1; then
276 $SHELL -c ./$dummy >/dev/null 2>&1