diff options
Diffstat (limited to 'BUILD/check-cpu')
-rwxr-xr-x | BUILD/check-cpu | 146 |
1 files changed, 79 insertions, 67 deletions
diff --git a/BUILD/check-cpu b/BUILD/check-cpu index 9eb390fcec4..5a19c6a0560 100755 --- a/BUILD/check-cpu +++ b/BUILD/check-cpu @@ -20,9 +20,83 @@ # best compiler optimization flags for gcc # Will return result in: # cpu_arg : Type of CPU +# low_cpu_arg : Type of CPU used up until GCC v3.3 # check_cpu_args : Arguments for GCC compiler settings # +check_compiler_cpu_flags () { + # different compiler versions have different option names + # for CPU specific command line options + if test -z "$CC" ; then + cc="gcc"; + else + cc=$CC + fi + + # check if compiler is gcc and dump its version + cc_verno=`$cc -dumpversion 2>/dev/null` + if test "x$?" = "x0" ; then + set -- `echo $cc_verno | tr '.' ' '` + cc_ver="GCC" + cc_major=$1 + cc_minor=$2 + cc_patch=$3 + cc_comp=`expr $cc_major '*' 100 '+' $cc_minor` + fi + + 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=${low_cpu_arg}" + elif test "$cc_comp" -ge 402 ; then + check_cpu_cflags="-mtune=native" + else + check_cpu_cflags="-mtune=${cpu_arg}" + fi + ;; + ppc-*) + check_cpu_cflags="-mcpu=${cpu_arg} -mtune=${cpu_arg}" + ;; + *) + check_cpu_cflags="" + return + ;; + esac + ;; + 2.95.*) + # GCC 2.95 doesn't expose its name in --version output + check_cpu_cflags="-m${cpu_arg}" + ;; + *) + check_cpu_cflags="" + return + ;; + esac + + # now we check whether the compiler really understands the cpu type + touch __test.c + + while [ "$cpu_arg" ] ; do + printf "testing $cpu_arg ... " >&2 + + # compile check + eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null + if test "x$?" = "x0" ; then + echo ok >&2 + break; + fi + + echo failed >&2 + check_cpu_cflags="" + break; + done + rm __test.* + return 0 +} + check_cpu () { CPUINFO=/proc/cpuinfo if test -n "$TEST_CPUINFO" ; then @@ -40,6 +114,7 @@ check_cpu () { if test -z "$cpu_family" ; then cpu_family=`$cpuinfo | grep 'cpu' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -1` fi + # 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` @@ -84,7 +159,7 @@ check_cpu () { # this list is not complete, feel free to add further entries cpu_arg="" low_cpu_arg="" - case "$cpu_vendor--$cpu_family--$model_name--$cpu_arch" in + case "$cpu_vendor--$cpu_family--$model_name--$spu_arch" in # DEC Alpha *Alpha*EV6*) cpu_arg="ev6"; @@ -233,78 +308,15 @@ check_cpu () { return fi - # different compiler versions have different option names - # for CPU specific command line options - if test -z "$CC" ; then - cc="gcc"; - else - cc=$CC + if test "x$compiler" = "x" ; then + check_compiler_cpu_flags fi - # check if compiler is gcc and dump its version - cc_verno=`$cc -dumpversion 2>/dev/null` - if test "x$?" = "x0" ; then - set -- `echo $cc_verno | tr '.' ' '` - cc_ver="GCC" - cc_major=$1 - cc_minor=$2 - cc_patch=$3 - cc_comp=`expr $cc_major '*' 100 '+' $cc_minor` - fi - - 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=${low_cpu_arg}" - elif test "$cc_comp" -ge 402 ; then - check_cpu_cflags="-mtune=native" - else - check_cpu_cflags="-mtune=${cpu_arg}" - fi - ;; - ppc-*) - check_cpu_cflags="-mcpu=${cpu_arg} -mtune=${cpu_arg}" - ;; - *) - check_cpu_cflags="" - return - ;; - esac - ;; - 2.95.*) - # GCC 2.95 doesn't expose its name in --version output - check_cpu_cflags="-m${cpu_arg}" - ;; - *) - check_cpu_cflags="" - return - ;; - esac - - # now we check whether the compiler really understands the cpu type - touch __test.c - if test "x$core2" = "xyes" ; then cpu_arg="core2" fi - while [ "$cpu_arg" ] ; do - printf "testing $cpu_arg ... " >&2 - # compile check - eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null - if test "x$?" = "x0" ; then - echo ok >&2 - break; - fi - - echo failed >&2 - check_cpu_cflags="" - break; - done - rm __test.* + return 0 } check_cpu |