Get glibc version with a distro-agnostic check.
[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