|
7 | 7 | # check_cpu_args : Arguments for GCC compiler settings |
8 | 8 | # |
9 | 9 |
|
| 10 | +check_compiler_cpu_flags () { |
| 11 | + # different compiler versions have different option names |
| 12 | + # for CPU specific command line options |
| 13 | + if test -z "$CC" ; then |
| 14 | + cc="gcc"; |
| 15 | + else |
| 16 | + cc=$CC |
| 17 | + fi |
| 18 | + |
| 19 | + # check if compiler is gcc and dump its version |
| 20 | + cc_verno=`$cc -dumpversion 2>/dev/null` |
| 21 | + if test "x$?" = "x0" ; then |
| 22 | + set -- `echo $cc_verno | tr '.' ' '` |
| 23 | + cc_ver="GCC" |
| 24 | + cc_major=$1 |
| 25 | + cc_minor=$2 |
| 26 | + cc_patch=$3 |
| 27 | + cc_comp=`expr $cc_major '*' 100 '+' $cc_minor` |
| 28 | + fi |
| 29 | + |
| 30 | + case "$cc_ver--$cc_verno" in |
| 31 | + *GCC*) |
| 32 | + # different gcc backends (and versions) have different CPU flags |
| 33 | + case `gcc -dumpmachine` in |
| 34 | + i?86-* | x86_64-*) |
| 35 | + if test "$cc_comp" -lt 304 ; then |
| 36 | + check_cpu_cflags="-mcpu=${cpu_arg}" |
| 37 | + elif test "$cc_comp" -ge 402 ; then |
| 38 | + check_cpu_cflags="-mtune=native" |
| 39 | + else |
| 40 | + check_cpu_cflags="-mtune=${cpu_arg}" |
| 41 | + fi |
| 42 | + ;; |
| 43 | + ppc-*) |
| 44 | + check_cpu_cflags="-mcpu=${cpu_arg} -mtune=${cpu_arg}" |
| 45 | + ;; |
| 46 | + *) |
| 47 | + check_cpu_cflags="" |
| 48 | + return |
| 49 | + ;; |
| 50 | + esac |
| 51 | + ;; |
| 52 | + 2.95.*) |
| 53 | + # GCC 2.95 doesn't expose its name in --version output |
| 54 | + check_cpu_cflags="-m${cpu_arg}" |
| 55 | + ;; |
| 56 | + *) |
| 57 | + check_cpu_cflags="" |
| 58 | + return |
| 59 | + ;; |
| 60 | + esac |
| 61 | + |
| 62 | + # now we check whether the compiler really understands the cpu type |
| 63 | + touch __test.c |
| 64 | + |
| 65 | + while [ "$cpu_arg" ] ; do |
| 66 | + printf "testing $cpu_arg ... " >&2 |
| 67 | + |
| 68 | + # compile check |
| 69 | + eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null |
| 70 | + if test "x$?" = "x0" ; then |
| 71 | + echo ok >&2 |
| 72 | + break; |
| 73 | + fi |
| 74 | + |
| 75 | + echo failed >&2 |
| 76 | + check_cpu_cflags="" |
| 77 | + break; |
| 78 | + done |
| 79 | + rm __test.* |
| 80 | + return 0 |
| 81 | +} |
| 82 | + |
10 | 83 | check_cpu () { |
11 | 84 | CPUINFO=/proc/cpuinfo |
12 | 85 | if test -n "$TEST_CPUINFO" ; then |
@@ -179,83 +252,14 @@ check_cpu () { |
179 | 252 | return |
180 | 253 | fi |
181 | 254 |
|
182 | | - # different compiler versions have different option names |
183 | | - # for CPU specific command line options |
184 | | - if test -z "$CC" ; then |
185 | | - cc="gcc"; |
186 | | - else |
187 | | - cc=$CC |
| 255 | + if test "x$compiler" = "x" ; then |
| 256 | + check_compiler_cpu_flags |
188 | 257 | fi |
189 | 258 |
|
190 | 259 | if test "x$core2" = "xyes" ; then |
191 | 260 | cpu_arg="core2" |
192 | 261 | fi |
193 | 262 |
|
194 | | - if test "x$compiler" != "x" ; then |
195 | | - return 0 |
196 | | - fi |
197 | | - |
198 | | - # check if compiler is gcc and dump its version |
199 | | - cc_verno=`$cc -dumpversion 2>/dev/null` |
200 | | - if test "x$?" = "x0" ; then |
201 | | - set -- `echo $cc_verno | tr '.' ' '` |
202 | | - cc_ver="GCC" |
203 | | - cc_major=$1 |
204 | | - cc_minor=$2 |
205 | | - cc_patch=$3 |
206 | | - cc_comp=`expr $cc_major '*' 100 '+' $cc_minor` |
207 | | - fi |
208 | | - |
209 | | - case "$cc_ver--$cc_verno" in |
210 | | - *GCC*) |
211 | | - # different gcc backends (and versions) have different CPU flags |
212 | | - case `gcc -dumpmachine` in |
213 | | - i?86-* | x86_64-*) |
214 | | - if test "$cc_comp" -lt 304 ; then |
215 | | - check_cpu_cflags="-mcpu=${cpu_arg}" |
216 | | - elif test "$cc_comp" -ge 402 ; then |
217 | | - check_cpu_cflags="-mtune=native" |
218 | | - else |
219 | | - check_cpu_cflags="-mtune=${cpu_arg}" |
220 | | - fi |
221 | | - ;; |
222 | | - ppc-*) |
223 | | - check_cpu_cflags="-mcpu=${cpu_arg} -mtune=${cpu_arg}" |
224 | | - ;; |
225 | | - *) |
226 | | - check_cpu_cflags="" |
227 | | - return |
228 | | - ;; |
229 | | - esac |
230 | | - ;; |
231 | | - 2.95.*) |
232 | | - # GCC 2.95 doesn't expose its name in --version output |
233 | | - check_cpu_cflags="-m${cpu_arg}" |
234 | | - ;; |
235 | | - *) |
236 | | - check_cpu_cflags="" |
237 | | - return |
238 | | - ;; |
239 | | - esac |
240 | | - |
241 | | - # now we check whether the compiler really understands the cpu type |
242 | | - touch __test.c |
243 | | - |
244 | | - while [ "$cpu_arg" ] ; do |
245 | | - printf "testing $cpu_arg ... " >&2 |
246 | | - |
247 | | - # compile check |
248 | | - eval "$cc -c $check_cpu_cflags __test.c" 2>/dev/null |
249 | | - if test "x$?" = "x0" ; then |
250 | | - echo ok >&2 |
251 | | - break; |
252 | | - fi |
253 | | - |
254 | | - echo failed >&2 |
255 | | - check_cpu_cflags="" |
256 | | - break; |
257 | | - done |
258 | | - rm __test.* |
259 | 263 | return 0 |
260 | 264 | } |
261 | 265 |
|
|
0 commit comments