mpir/config.guess

650 lines
19 KiB
Plaintext
Raw Normal View History

2008-07-04 20:29:18 -04:00
#! /bin/sh
#
# GMP config.guess wrapper.
2008-07-04 20:29:18 -04:00
# Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
2008-07-04 20:29:18 -04:00
#
# Copyright 2008 William Hart, Gonzalo Tornaria
#
# This file is part of the MPIR Library.
2008-07-04 20:29:18 -04:00
#
# The MPIR Library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or (at
# your option) any later version.
2008-07-04 20:29:18 -04:00
#
# The MPIR Library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
2008-07-04 20:29:18 -04:00
#
# You should have received a copy of the GNU Lesser General Public License
# along with the MPIR Library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
# Usage: config.guess
#
# Print the host system CPU-VENDOR-OS.
#
# configfsf.guess is run and its guess then sharpened up to take advantage
# of the finer grained CPU types that GMP knows.
2008-07-04 20:29:18 -04:00
# Expect to find configfsf.guess in the same directory as this config.guess
configfsf_guess="`echo \"$0\" | sed 's/config.guess$/configfsf.guess/'`"
cpuid_c_path="`echo \"$0\" | sed 's/config.guess$/cpuid.c/'`"
if test "$configfsf_guess" = "$0"; then
echo "Cannot derive configfsf.guess from $0" 1>&2
exit 1
fi
if test -f "$configfsf_guess"; then
:
else
echo "$configfsf_guess not found" 1>&2
exit 1
fi
# Setup a $SHELL with which to run configfsf.guess, using the same
# $CONFIG_SHELL or /bin/sh as autoconf does when running config.guess
SHELL=${CONFIG_SHELL-/bin/sh}
# Identify ourselves on --version, --help or errors
if test $# != 0; then
echo "(GNU MP wrapped config.guess)"
$SHELL $configfsf_guess "$@"
2008-07-04 20:29:18 -04:00
exit 1
fi
guess_full=`$SHELL $configfsf_guess`
if test $? != 0; then
exit 1
fi
2008-07-04 20:29:18 -04:00
guess_cpu=`echo "$guess_full" | sed 's/-.*$//'`
guess_rest=`echo "$guess_full" | sed 's/^[^-]*//'`
exact_cpu=
2008-07-04 20:29:18 -04:00
# -------------------------------------------------------------------------
# The following should look at the current guess and probe the system to
# establish a better guess in exact_cpu. Leave exact_cpu empty if probes
# can't be done, or don't work.
#
# When a number of probes are done, test -z "$exact_cpu" can be used instead
# of putting each probe under an "else" of the preceeding. That can stop
# the code getting horribly nested and marching off the right side of the
# screen.
2008-07-04 20:29:18 -04:00
# Note that when a compile-and-link is done in one step we need to remove .o
# files, since lame C compilers generate these even when not asked.
#
dummy=dummy-$$
trap 'rm -f $dummy.c $dummy.o $dummy.core $dummy ${dummy}1.s ${dummy}2.c ; exit 1' 1 2 15
2008-07-04 20:29:18 -04:00
# Use $HOST_CC if defined. $CC may point to a cross-compiler
if test x"$CC_FOR_BUILD" = x; then
if test x"$HOST_CC" != x; then
CC_FOR_BUILD="$HOST_CC"
else
if test x"$CC" != x; then
CC_FOR_BUILD="$CC"
else
echo 'dummy(){}' >$dummy.c
for c in cc gcc c89 c99; do
($c $dummy.c -c) >/dev/null 2>&1
if test $? = 0; then
CC_FOR_BUILD="$c"; break
fi
done
rm -f $dummy.c $dummy.o
if test x"$CC_FOR_BUILD" = x; then
CC_FOR_BUILD=no_compiler_found
fi
fi
fi
2008-07-04 20:29:18 -04:00
fi
#here we have to distinguish between mingw32 32bit and 64bit , as the msys people refuse to
#as we changing the middle part of the triple we do this first
# find the size of a limb
case "$guess_full" in
*-pc-mingw32)
cat <<EOF >${dummy}.c
main(){
#ifdef _WIN64
printf("-w64-mingw32\n");
#endif
return 0;}
EOF
if ($CC_FOR_BUILD ${dummy}.c -o $dummy) >/dev/null 2>&1; then
x=`$SHELL -c ./$dummy 2>/dev/null`
if test $? = 0 && test -n "$x"; then
guess_rest=$x
fi
fi
rm -f ${dummy}.c $dummy
;;
esac
2008-07-04 20:29:18 -04:00
case "$guess_full" in
ia64*-*-*)
# CPUID[3] bits 24 to 31 is the processor family. itanium2 is documented
# as 0x1f, plain itanium has been seen returning 0x07 on two systems, but
# haven't found any documentation on it as such.
#
# Defining both getcpuid and _getcpuid lets us ignore whether the system
# expects underscores or not.
#
# "unsigned long long" is always 64 bits, in fact on hpux in ilp32 mode
# (which is the default there), it's the only 64-bit type.
#
cat >${dummy}a.s <<EOF
.text
.global _getcpuid
.proc _getcpuid
_getcpuid:
mov r8 = CPUID[r32] ;;
br.ret.sptk.many rp ;;
.endp _getcpuid
.global getcpuid
.proc getcpuid
getcpuid:
mov r8 = CPUID[r32] ;;
br.ret.sptk.many rp ;;
.endp getcpuid
2008-07-04 20:29:18 -04:00
EOF
cat >${dummy}b.c <<EOF
#include <stdio.h>
unsigned long long getcpuid ();
int
main ()
{
if (getcpuid(0LL) == 0x49656E69756E6547LL && getcpuid(1LL) == 0x6C65746ELL)
{
/* "GenuineIntel" */
switch ((getcpuid(3LL) >> 24) & 0xFF) {
case 0x07: puts ("itanium"); break;
case 0x1F: puts ("itanium2"); break;
}
}
return 0;
}
2008-07-04 20:29:18 -04:00
EOF
if $CC_FOR_BUILD ${dummy}a.s ${dummy}b.c -o $dummy >/dev/null 2>&1; then
exact_cpu=`./$dummy`
fi
rm -f ${dummy}a.s ${dummy}a.o ${dummy}b.c ${dummy}b.o $dummy $dummy.core core
;;
rs6000-*-* | powerpc*-*-*)
# Enhancement: On MacOS the "machine" command prints for instance
# "ppc750". Interestingly on powerpc970-apple-darwin6.8.5 it prints
# "ppc970" where there's no actual #define for 970 from NXGetLocalArchInfo
# (as noted below). But the man page says the command is still "under
# development", so it doesn't seem wise to use it just yet, not while
# there's an alternative.
#
# Try to read the PVR. mfpvr is a protected instruction, NetBSD, MacOS
# and AIX don't allow it in user mode, but the Linux kernel does.
#
# Using explicit bytes for mfpvr avoids worrying about assembler syntax
# and underscores. "char"s are used instead of "int"s to avoid worrying
# whether sizeof(int)==4 or if it's the right endianness.
#
# Note this is no good on AIX, since a C function there is the address of
# a function descriptor, not actual code. But this doesn't matter since
# AIX doesn't allow mfpvr anyway.
#
cat >$dummy.c <<\EOF
#include <stdio.h>
struct {
int n; /* force 4-byte alignment */
char a[8];
} getpvr = {
0,
{
0x7c, 0x7f, 0x42, 0xa6, /* mfpvr r3 */
0x4e, 0x80, 0x00, 0x20, /* blr */
}
};
int
main ()
{
unsigned (*fun)();
unsigned pvr;
/* a separate "fun" variable is necessary for gcc 2.95.2 on MacOS,
it gets a compiler error on a combined cast and call */
fun = (unsigned (*)()) getpvr.a;
pvr = (*fun) ();
switch (pvr >> 16) {
case 0x0001: puts ("powerpc601"); break;
case 0x0003: puts ("powerpc603"); break;
case 0x0004: puts ("powerpc604"); break;
case 0x0006: puts ("powerpc603e"); break;
case 0x0007: puts ("powerpc603e"); break; /* 603ev */
case 0x0008: puts ("powerpc750"); break;
case 0x0009: puts ("powerpc604e"); break;
case 0x000a: puts ("powerpc604e"); break; /* 604ev5 */
case 0x000c: puts ("powerpc7400"); break;
case 0x0041: puts ("powerpc630"); break;
case 0x0050: puts ("powerpc860"); break;
case 0x8000: puts ("powerpc7450"); break;
case 0x8001: puts ("powerpc7455"); break;
case 0x8002: puts ("powerpc7457"); break;
case 0x800c: puts ("powerpc7410"); break;
}
return 0;
}
EOF
if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
# This style construct is needed on AIX 4.3 to suppress the SIGILL error
# from (*fun)(). Using $SHELL -c ./$dummy 2>/dev/null doesn't work.
{ x=`./$dummy`; } 2>/dev/null
if test -n "$x"; then
exact_cpu=$x
fi
fi
rm -f $dummy.c $dummy.o $dummy $dummy.core
# Grep the linux kernel /proc/cpuinfo pseudo-file.
# Anything unrecognised is ignored, since of course we mustn't spit out
# a cpu type config.sub doesn't know.
if test -z "$exact_cpu" && test -f /proc/cpuinfo; then
x=`grep "^cpu[ ]" /proc/cpuinfo | head -n 1`
x=`echo $x | sed -n 's/^cpu[ ]*:[ ]*\([A-Za-z0-9]*\).*/\1/p'`
x=`echo $x | sed 's/PPC//'`
case $x in
601) exact_cpu="power" ;;
603ev) exact_cpu="powerpc603e" ;;
604ev5) exact_cpu="powerpc604e" ;;
603 | 603e | 604 | 604e | 750 | 821 | 860 | 970)
exact_cpu="powerpc$x" ;;
POWER[4-9])
exact_cpu=`echo $x | sed "s;POWER;power;"` ;;
esac
fi
if test -z "$exact_cpu"; then
# On AIX, try looking at _system_configuration. This is present in
# version 4 at least.
cat >$dummy.c <<EOF
#include <stdio.h>
#include <sys/systemcfg.h>
int
2008-07-04 20:29:18 -04:00
main ()
{
switch (_system_configuration.implementation) {
/* Old versions of AIX don't have all these constants,
use ifdef for safety. */
#ifdef POWER_RS2
case POWER_RS2: puts ("power2"); break;
#endif
#ifdef POWER_601
case POWER_601: puts ("power"); break;
#endif
#ifdef POWER_603
case POWER_603: puts ("powerpc603"); break;
#endif
#ifdef POWER_604
case POWER_604: puts ("powerpc604"); break;
#endif
#ifdef POWER_620
case POWER_620: puts ("powerpc620"); break;
#endif
#ifdef POWER_630
case POWER_630: puts ("powerpc630"); break;
#endif
/* Dunno what this is, leave it out for now.
case POWER_A35: puts ("powerpca35"); break;
*/
/* This is waiting for a bit more info.
case POWER_RS64II: puts ("powerpcrs64ii"); break;
*/
default:
if (_system_configuration.architecture == POWER_RS)
puts ("power");
else if (_system_configuration.width == 64)
puts ("powerpc64");
}
return 0;
}
EOF
if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
x=`./$dummy`
if test -n "$x"; then
exact_cpu=$x
fi
fi
rm -f $dummy.c $dummy.o $dummy
fi
if test -z "$exact_cpu"; then
# On MacOS X (or any Mach-O presumably), NXGetLocalArchInfo cpusubtype
# can tell us the exact cpu.
cat >$dummy.c <<EOF
#include <stdio.h>
#include <mach-o/arch.h>
int
main (void)
{
const NXArchInfo *a = NXGetLocalArchInfo();
if (a->cputype == CPU_TYPE_POWERPC)
{
switch (a->cpusubtype) {
/* The following known to Darwin 1.3. */
case CPU_SUBTYPE_POWERPC_601: puts ("powerpc601"); break;
case CPU_SUBTYPE_POWERPC_602: puts ("powerpc602"); break;
case CPU_SUBTYPE_POWERPC_603: puts ("powerpc603"); break;
case CPU_SUBTYPE_POWERPC_603e: puts ("powerpc603e"); break;
case CPU_SUBTYPE_POWERPC_603ev: puts ("powerpc603e"); break;
case CPU_SUBTYPE_POWERPC_604: puts ("powerpc604"); break;
case CPU_SUBTYPE_POWERPC_604e: puts ("powerpc604e"); break;
case CPU_SUBTYPE_POWERPC_620: puts ("powerpc620"); break;
case CPU_SUBTYPE_POWERPC_750: puts ("powerpc750"); break;
case CPU_SUBTYPE_POWERPC_7400: puts ("powerpc7400"); break;
case CPU_SUBTYPE_POWERPC_7450: puts ("powerpc7450"); break;
/* Darwin 6.8.5 doesn't define a constant for 970, but gives 100 */
case 100: puts ("powerpc970"); break;
}
2008-07-04 20:29:18 -04:00
}
return 0;
2008-07-04 20:29:18 -04:00
}
EOF
if ($CC_FOR_BUILD $dummy.c -o $dummy) >/dev/null 2>&1; then
x=`./$dummy`
if test -n "$x"; then
exact_cpu=$x
fi
fi
rm -f $dummy.c $dummy.o $dummy
fi
;;
sparc-*-* | sparc64-*-*)
# If we can recognise an actual v7 then $exact_cpu is set to "sparc" so as
# to short-circuit subsequent tests.
# Grep the linux kernel /proc/cpuinfo pseudo-file.
# A typical line is "cpu\t\t: TI UltraSparc II (BlackBird)"
# See arch/sparc/kernel/cpu.c and arch/sparc64/kernel/cpu.c.
#
if test -f /proc/cpuinfo; then
if grep 'cpu.*Cypress' /proc/cpuinfo >/dev/null; then
exact_cpu="sparc" # ie. v7
elif grep 'cpu.*Power-UP' /proc/cpuinfo >/dev/null; then
exact_cpu="sparc" # ie. v7
elif grep 'cpu.*HyperSparc' /proc/cpuinfo >/dev/null; then
exact_cpu="sparcv8"
elif grep 'cpu.*SuperSparc' /proc/cpuinfo >/dev/null; then
exact_cpu="supersparc"
elif grep 'cpu.*MicroSparc' /proc/cpuinfo >/dev/null; then
exact_cpu="microsparc"
elif grep 'cpu.*MB86904' /proc/cpuinfo >/dev/null; then
# actually MicroSPARC-II
exact_cpu=microsparc
elif grep 'cpu.*UltraSparc T1' /proc/cpuinfo >/dev/null; then
# this grep pattern has not been tested against any Linux
exact_cpu="ultrasparct1"
elif grep 'cpu.*UltraSparc III' /proc/cpuinfo >/dev/null; then
exact_cpu="ultrasparc3"
elif grep 'cpu.*UltraSparc IIi' /proc/cpuinfo >/dev/null; then
exact_cpu="ultrasparc2i"
elif grep 'cpu.*UltraSparc II' /proc/cpuinfo >/dev/null; then
exact_cpu="ultrasparc2"
elif grep 'cpu.*UltraSparc' /proc/cpuinfo >/dev/null; then
exact_cpu="ultrasparc"
fi
fi
# Grep the output from sysinfo on SunOS.
# sysinfo has been seen living in /bin or in /usr/kvm
# cpu0 is a "SuperSPARC Model 41 SPARCmodule" CPU
# cpu0 is a "75 MHz TI,TMS390Z55" CPU
#
if test -z "$exact_cpu"; then
for i in sysinfo /usr/kvm/sysinfo; do
if $SHELL -c $i 2>/dev/null >conftest.dat; then
if grep 'cpu0 is a "SuperSPARC' conftest.dat >/dev/null; then
exact_cpu=supersparc
break
elif grep 'cpu0 is a .*TMS390Z5.' conftest.dat >/dev/null; then
# TMS390Z50 and TMS390Z55
exact_cpu=supersparc
break
fi
fi
done
rm -f conftest.dat
fi
# Grep the output from prtconf on Solaris.
# Use an explicit /usr/sbin, since that directory might not be in a normal
# user's path.
#
# SUNW,UltraSPARC (driver not attached)
# SUNW,UltraSPARC-II (driver not attached)
# SUNW,UltraSPARC-IIi (driver not attached)
# SUNW,UltraSPARC-III+ (driver not attached)
# Ross,RT625 (driver not attached)
# TI,TMS390Z50 (driver not attached)
#
# /usr/sbin/sysdef prints similar information, but includes all loadable
# cpu modules, not just the real cpu.
#
# We first try a plain prtconf, since that is known to work on older systems.
# But for newer T1 systems, that doesn't produce any useful output, we need
# "prtconf -vp" there.
#
for prtconfopt in "" "-vp"; do
if test -z "$exact_cpu"; then
if $SHELL -c "/usr/sbin/prtconf $prtconfopt" 2>/dev/null >conftest.dat; then
if grep 'SUNW,UltraSPARC-T1' conftest.dat >/dev/null; then
exact_cpu=ultrasparct1
elif grep 'SUNW,UltraSPARC-III' conftest.dat >/dev/null; then
exact_cpu=ultrasparc3
elif grep 'SUNW,UltraSPARC-IIi' conftest.dat >/dev/null; then
exact_cpu=ultrasparc2i
elif grep 'SUNW,UltraSPARC-II' conftest.dat >/dev/null; then
exact_cpu=ultrasparc2
elif grep 'SUNW,UltraSPARC' conftest.dat >/dev/null; then
exact_cpu=ultrasparc
elif grep 'Ross,RT62.' conftest.dat >/dev/null; then
# RT620, RT625, RT626 hypersparcs (v8).
exact_cpu=sparcv8
elif grep 'TI,TMS390Z5.' conftest.dat >/dev/null; then
# TMS390Z50 and TMS390Z55
exact_cpu=supersparc
elif grep 'TI,TMS390S10' conftest.dat >/dev/null; then
exact_cpu=microsparc
elif grep 'FMI,MB86904' conftest.dat >/dev/null; then
# actually MicroSPARC-II
exact_cpu=microsparc
2008-07-04 20:29:18 -04:00
fi
fi
rm -f conftest.dat
fi
done
# Grep the output from sysctl hw.model on sparc or sparc64 *BSD.
# Use an explicit /sbin, since that directory might not be in a normal
# user's path. Example outputs,
#
# hw.model: Sun Microsystems UltraSparc-IIi
#
if test -z "$exact_cpu"; then
if $SHELL -c "/sbin/sysctl hw.model" 2>/dev/null >conftest.dat; then
if grep 'UltraSparc-T1' conftest.dat >/dev/null; then
# this grep pattern has not been tested against any BSD
exact_cpu=ultrasparct1
elif grep 'UltraSparc-III' conftest.dat >/dev/null; then
exact_cpu=ultrasparc3
elif grep 'UltraSparc-IIi' conftest.dat >/dev/null; then
exact_cpu=ultrasparc2i
elif grep 'UltraSparc-II' conftest.dat >/dev/null; then
exact_cpu=ultrasparc2
elif grep 'UltraSparc' conftest.dat >/dev/null; then
exact_cpu=ultrasparc
elif grep 'TMS390Z5.' conftest.dat >/dev/null; then
# TMS390Z50 and TMS390Z55
exact_cpu=supersparc
elif grep 'TMS390S10' conftest.dat >/dev/null; then
exact_cpu=microsparc
elif grep 'MB86904' conftest.dat >/dev/null; then
# actually MicroSPARC-II
exact_cpu=microsparc
elif grep 'MB86907' conftest.dat >/dev/null; then
exact_cpu=turbosparc
fi
fi
rm -f conftest.dat
fi
# sun4m and sun4d are v8s of some sort, sun4u is a v9 of some sort
#
if test -z "$exact_cpu"; then
case `uname -m` in
sun4[md]) exact_cpu=sparcv8 ;;
sun4u) exact_cpu=sparcv9 ;;
2008-07-04 20:29:18 -04:00
esac
fi
;;
i?86-*-*|x86_64-*-*|amd64-*-*)
cat <<EOF >${dummy}032.s
.globl cpuid
.globl _cpuid
cpuid:
_cpuid:
pushl %esi
pushl %ebx
movl 16(%esp),%eax
.byte 0x0f
.byte 0xa2
movl 12(%esp),%esi
movl %ebx,(%esi)
movl %edx,4(%esi)
movl %ecx,8(%esi)
popl %ebx
popl %esi
ret
EOF
cat <<EOF >${dummy}064.s
.globl cpuid
.globl _cpuid
cpuid:
_cpuid:
movq %rbx,%r11
movq %rdi,%r9
movq %rsi,%rax
orq %r8,%r8
cmovne %rcx,%r9
cmovne %rdx,%rax
.byte 0x0f
.byte 0xa2
movl %ebx,(%r9)
movl %edx,4(%r9)
movl %ecx,8(%r9)
movq %r11,%rbx
ret
EOF
cat <<EOF >${dummy}32.c
#define CONFIG_GUESS 1
#define CONFIG_GUESS_32BIT 1
#define CONFIG_GUESS_64BIT 0
#define FAT32 0
#define FAT64 0
#define INFAT 0
EOF
cat $cpuid_c_path >> ${dummy}32.c
cat <<EOF >>${dummy}32.c
main (){char *modelstr;
modelstr=__gmpn_cpu(0);
printf ("%s\n", modelstr);
return 0;}
EOF
cat <<EOF >${dummy}64.c
#define CONFIG_GUESS 1
#define CONFIG_GUESS_32BIT 0
#define CONFIG_GUESS_64BIT 1
#define FAT32 0
#define FAT64 0
#define INFAT 0
EOF
cat $cpuid_c_path >> ${dummy}64.c
cat <<EOF >>${dummy}64.c
main (){char *modelstr;
modelstr=__gmpn_cpu(0);
printf ("%s\n", modelstr);
return 0;}
EOF
2008-07-04 20:29:18 -04:00
if ($CC_FOR_BUILD ${dummy}064.s ${dummy}64.c -o $dummy) >/dev/null 2>&1; then
# On 80386 and early 80486 cpuid is not available and will result in a
# SIGILL message, hence 2>/dev/null.
#
# On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
# "Illegal instruction (core dumped)" message to stdout, so we test $?
# to check if the program run was successful.
#
x=`$SHELL -c ./$dummy 2>/dev/null`
if test $? = 0 && test -n "$x"; then
exact_cpu=$x
fi
fi
if test -z "$exact_cpu"; then
if ($CC_FOR_BUILD ${dummy}032.s ${dummy}32.c -o $dummy) >/dev/null 2>&1; then
# On 80386 and early 80486 cpuid is not available and will result in a
# SIGILL message, hence 2>/dev/null.
#
# On i386-unknown-freebsd4.9, "/bin/sh -c ./dummy" seems to send an
# "Illegal instruction (core dumped)" message to stdout, so we test $?
# to check if the program run was successful.
#
# NOTE : Pathscale CC doesn't like name1.s name2.c with name1==name2
x=`$SHELL -c ./$dummy 2>/dev/null`
if test $? = 0 && test -n "$x"; then
exact_cpu=$x
fi
fi
fi
# We need to remove some .o files here since lame C compilers
# generate these even when not asked.
rm -f ${dummy}032.s ${dummy}32.o ${dummy}32.c ${dummy}032.o ${dummy}064.s ${dummy}64.o ${dummy}64.c ${dummy}064.o $dummy ${dummy}.exe
;;
2008-07-04 20:29:18 -04:00
esac
2008-07-04 20:29:18 -04:00
# -------------------------------------------------------------------------
# Use an exact cpu, if possible
if test -n "$exact_cpu"; then
echo "$exact_cpu$guess_rest"
else
echo "$guess_full"
fi
exit 0
2008-07-04 20:29:18 -04:00
# Local variables:
# fill-column: 76
2008-07-04 20:29:18 -04:00
# End: