mariadb/BUILD/check-cpu

247 lines
5.7 KiB
Text
Raw Normal View History

#!/bin/sh
#
# Check cpu of current machine and find the
# best compiler optimization flags for gcc
# Will return result in:
# cpu_arg : Type of CPU
# check_cpu_args : Arguments for GCC compiler settings
#
2006-08-30 21:24:09 +02:00
check_cpu () {
CPUINFO=/proc/cpuinfo
if test -n "$TEST_CPUINFO" ; then
CPUINFO=$TEST_CPUINFO
fi
if test -r "$CPUINFO" -a "$CPUINFO" != " " ; then
2006-08-30 21:24:09 +02:00
# on Linux (and others?) we can get detailed CPU information out of /proc
cpuinfo="cat $CPUINFO"
2006-08-30 21:24:09 +02:00
# detect CPU family
cpu_family=`$cpuinfo | grep 'family' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1`
if test -z "$cpu_family" ; then
cpu_family=`$cpuinfo | grep 'cpu' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1`
fi
2006-08-30 21:24:09 +02:00
# detect CPU vendor and model
cpu_vendor=`$cpuinfo | grep 'vendor_id' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1`
model_name=`$cpuinfo | grep 'model name' | cut -d ':' -f 2 | head -1`
if test -z "$model_name" ; then
model_name=`$cpuinfo | grep 'cpu model' | cut -d ':' -f 2 | head -1`
fi
# fallback: get CPU model from uname output
if test -z "$model_name" ; then
model_name=`uname -m`
fi
2006-08-30 21:24:09 +02:00
# parse CPU flags
for flag in `$cpuinfo | grep '^flags' | sed -e 's/^flags.*: //' -e 's/[^a-zA-Z0-9_ ]/_/g'`; do
eval cpu_flag_$flag=yes
2006-08-30 21:24:09 +02:00
done
else
# Fallback when there is no /proc/cpuinfo
CPUINFO=" "
2006-08-30 21:24:09 +02:00
case "`uname -s`" in
FreeBSD|OpenBSD)
cpu_family=`uname -m`;
model_name=`sysctl -n hw.model`
;;
Darwin)
2009-07-10 15:00:17 +02:00
cpu_family=`sysctl -n machdep.cpu.vendor`
model_name=`sysctl -n machdep.cpu.brand_string`
if [ -z "$cpu_family" -o -z "$model_name" ]
then
cpu_family=`uname -p`
model_name=`machine`
fi
2006-08-30 21:24:09 +02:00
;;
*)
cpu_family=`uname -m`;
model_name=`uname -p`;
;;
esac
fi
2006-08-30 21:24:09 +02:00
# detect CPU shortname as used by gcc options
# this list is not complete, feel free to add further entries
cpu_arg=""
case "$cpu_family--$model_name" in
# DEC Alpha
Alpha*EV6*)
cpu_arg="ev6";
;;
2006-08-30 21:24:09 +02:00
# Intel ia32
*Intel*Core*|*X[eE][oO][nN]*)
2006-08-30 21:24:09 +02:00
# a Xeon is just another pentium4 ...
# ... unless it has the "lm" (long-mode) flag set,
# in that case it's a Xeon with EM64T support
# If SSE3 support exists it is a Core2 Duo or newer
# So is Intel Core.
if [ -z "$cpu_flag_lm" ]; then
cpu_arg="pentium4"
else
cpu_arg="nocona"
fi
if test -z "$cpu_flag_ssse3" ; then
core2="no"
else
core2="yes"
2006-08-30 21:24:09 +02:00
fi
;;
2006-08-30 21:24:09 +02:00
*Pentium*4*Mobile*)
cpu_arg="pentium4m"
;;
2006-08-30 21:24:09 +02:00
*Pentium*4*)
cpu_arg="pentium4"
2006-08-30 21:24:09 +02:00
;;
*Pentium*III*Mobile*)
cpu_arg="pentium3m"
;;
2006-08-30 21:24:09 +02:00
*Pentium*III*)
cpu_arg="pentium3"
;;
2006-08-30 21:24:09 +02:00
*Pentium*M*pro*)
cpu_arg="pentium-m"
;;
*Celeron\(R\)*\ M*)
cpu_arg="pentium-m"
;;
*Celeron*Coppermine*)
cpu_arg="pentium3"
;;
*Celeron\(R\)*)
cpu_arg="pentium4"
;;
*Celeron*)
cpu_arg="pentium2"
2006-08-30 21:24:09 +02:00
;;
*Turion*)
cpu_arg="athlon64"
;;
*Athlon*64*)
cpu_arg="athlon64"
;;
2006-08-30 21:24:09 +02:00
*Athlon*)
cpu_arg="athlon"
2006-08-30 21:24:09 +02:00
;;
*Opteron*)
cpu_arg="opteron"
;;
Merge maint2.mysql.com:/data/localhome/tsmith/bk/g51 into maint2.mysql.com:/data/localhome/tsmith/bk/51 client/mysqltest.c: Auto merged configure.in: Auto merged include/config-netware.h: Auto merged include/mysql_com.h: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/lib/mtr_process.pl: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/grant.result: Auto merged mysql-test/r/innodb_mysql.result: Auto merged mysql-test/r/partition.result: Auto merged mysql-test/r/partition_mgm.result: Auto merged mysql-test/t/disabled.def: Auto merged mysql-test/t/func_time.test: Auto merged mysql-test/t/grant.test: Auto merged mysql-test/t/innodb_mysql.test: Auto merged sql/ha_innodb.cc: Auto merged sql/item_func.h: Auto merged sql/item_strfunc.cc: Auto merged sql/item_strfunc.h: Auto merged sql/item_timefunc.cc: Auto merged sql/mysqld.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_show.cc: Auto merged storage/innobase/btr/btr0btr.c: Auto merged storage/innobase/buf/buf0buf.c: Auto merged storage/innobase/dict/dict0dict.c: Auto merged storage/innobase/fil/fil0fil.c: Auto merged storage/innobase/fsp/fsp0fsp.c: Auto merged storage/innobase/include/btr0cur.ic: Auto merged storage/innobase/include/buf0buf.ic: Auto merged storage/innobase/log/log0log.c: Auto merged storage/innobase/log/log0recv.c: Auto merged storage/innobase/os/os0file.c: Auto merged storage/innobase/row/row0sel.c: Auto merged storage/innobase/srv/srv0start.c: Auto merged storage/innobase/ut/ut0dbg.c: Auto merged tests/mysql_client_test.c: Auto merged BUILD/check-cpu: Manual merge storage/innobase/row/row0mysql.c: Manual merge
2006-09-04 23:05:17 +02:00
# MacOSX / Intel
*i386*i486*)
cpu_arg="pentium-m"
;;
*i386*)
cpu_arg="i386"
Merge maint2.mysql.com:/data/localhome/tsmith/bk/g51 into maint2.mysql.com:/data/localhome/tsmith/bk/51 client/mysqltest.c: Auto merged configure.in: Auto merged include/config-netware.h: Auto merged include/mysql_com.h: Auto merged mysql-test/mysql-test-run.pl: Auto merged mysql-test/lib/mtr_process.pl: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/grant.result: Auto merged mysql-test/r/innodb_mysql.result: Auto merged mysql-test/r/partition.result: Auto merged mysql-test/r/partition_mgm.result: Auto merged mysql-test/t/disabled.def: Auto merged mysql-test/t/func_time.test: Auto merged mysql-test/t/grant.test: Auto merged mysql-test/t/innodb_mysql.test: Auto merged sql/ha_innodb.cc: Auto merged sql/item_func.h: Auto merged sql/item_strfunc.cc: Auto merged sql/item_strfunc.h: Auto merged sql/item_timefunc.cc: Auto merged sql/mysqld.cc: Auto merged sql/sql_acl.cc: Auto merged sql/sql_show.cc: Auto merged storage/innobase/btr/btr0btr.c: Auto merged storage/innobase/buf/buf0buf.c: Auto merged storage/innobase/dict/dict0dict.c: Auto merged storage/innobase/fil/fil0fil.c: Auto merged storage/innobase/fsp/fsp0fsp.c: Auto merged storage/innobase/include/btr0cur.ic: Auto merged storage/innobase/include/buf0buf.ic: Auto merged storage/innobase/log/log0log.c: Auto merged storage/innobase/log/log0recv.c: Auto merged storage/innobase/os/os0file.c: Auto merged storage/innobase/row/row0sel.c: Auto merged storage/innobase/srv/srv0start.c: Auto merged storage/innobase/ut/ut0dbg.c: Auto merged tests/mysql_client_test.c: Auto merged BUILD/check-cpu: Manual merge storage/innobase/row/row0mysql.c: Manual merge
2006-09-04 23:05:17 +02:00
;;
#Core 2 Duo
*Intel*Core\(TM\)2*)
cpu_arg="nocona"
;;
2006-08-30 21:24:09 +02:00
# Intel ia64
*Itanium*)
cpu_arg="itanium"
2006-08-30 21:24:09 +02:00
;;
# Solaris Sparc
*sparc*sun4u*)
cpu_arg="sparc"
;;
# Power PC
2006-08-30 21:24:09 +02:00
*ppc*)
cpu_arg="powerpc"
2006-08-30 21:24:09 +02:00
;;
*powerpc*)
cpu_arg="powerpc"
2006-08-30 21:24:09 +02:00
;;
# unknown
*)
cpu_arg=""
2006-08-30 21:24:09 +02:00
;;
esac
if test -z "$cpu_arg" ; then
if test "$CPUINFO" != " " ; then
# fallback to uname if necessary
TEST_CPUINFO=" "
check_cpu_cflags=""
check_cpu
return
fi
2006-08-30 21:24:09 +02:00
echo "BUILD/check-cpu: Oops, could not find out what kind of cpu this machine is using." >&2
check_cpu_cflags=""
return
fi
2006-08-30 21:24:09 +02:00
# different compiler versions have different option names
# for CPU specific command line options
if test -z "$CC" ; then
cc="gcc";
else
cc=$CC
fi
2006-08-30 21:24:09 +02:00
cc_ver=`$cc --version | sed 1q`
cc_verno=`echo $cc_ver | sed -e 's/^.*(GCC)//g; s/[^0-9. ]//g; s/^ *//g; s/ .*//g'`
set -- `echo $cc_verno | tr '.' ' '`
cc_major=$1
cc_minor=$2
cc_patch=$3
cc_comp=`expr $cc_major '*' 100 '+' $cc_minor`
2006-08-30 21:24:09 +02:00
case "$cc_ver--$cc_verno" in
*GCC*)
# different gcc backends (and versions) have different CPU flags
case `gcc -dumpmachine` in
i?86-* | x86_64-*)
if test "$cc_comp" -lt 304 ; then
check_cpu_cflags="-mcpu=${cpu_arg}"
elif test "$cc_comp" -ge 402 ; then
check_cpu_cflags="-mtune=native"
else
check_cpu_cflags="-mtune=${cpu_arg}"
fi
2006-08-30 21:24:09 +02:00
;;
ppc-*)
check_cpu_cflags="-mcpu=${cpu_arg} -mtune=${cpu_arg}"
;;
2006-08-30 21:24:09 +02:00
*)
check_cpu_cflags=""
return
;;
esac
;;
2.95.*)
# GCC 2.95 doesn't expose its name in --version output
check_cpu_cflags="-m${cpu_arg}"
2006-08-30 21:24:09 +02:00
;;
*)
check_cpu_cflags=""
return
;;
esac
2006-08-30 21:24:09 +02:00
# now we check whether the compiler really understands the cpu type
touch __test.c
if test "x$core2" = "xyes" ; then
cpu_arg="core2"
fi
2006-08-30 21:24:09 +02:00
while [ "$cpu_arg" ] ; do
printf "testing $cpu_arg ... " >&2
2006-08-30 21:24:09 +02:00
# compile check
eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null
if test "x$?" = "x0" ; then
echo ok >&2
break;
2006-08-30 21:24:09 +02:00
fi
echo failed >&2
check_cpu_cflags=""
break;
2006-08-30 21:24:09 +02:00
done
rm __test.*
}
2006-08-30 21:24:09 +02:00
check_cpu