2 dnl Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
4 dnl This program is free software; you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation; either version 3 of the License, or
7 dnl (at your option) any later version.
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 dnl GNU General Public License for more details.
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program; if not, write to the Free Software
15 dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 dnl Copyright (C) 2006, 2007 Steven G. Johnson <stevenj@alum.mit.edu> and Matteo Frigo.
19 AC_DEFUN([AX_CHECK_COMPILER_FLAGS],
20 [AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX
21 AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1])
22 dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname:
24 [AC_CACHE_VAL(AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1), [
25 ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
26 _AC_LANG_PREFIX[]FLAGS="$1"
27 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
28 AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes,
29 AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no)
30 _AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])],
31 [ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS
32 _AC_LANG_PREFIX[]FLAGS="$1"
33 AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
34 eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes,
35 eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no)
36 _AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])
37 eval ax_check_compiler_flags=$AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)
38 AC_MSG_RESULT($ax_check_compiler_flags)
39 if test "x$ax_check_compiler_flags" = xyes; then
44 ])dnl AX_CHECK_COMPILER_FLAGS
46 AC_DEFUN([AX_GCC_X86_CPUID],
47 [AC_REQUIRE([AC_PROG_CC])
49 AC_CACHE_CHECK(for x86 cpuid $1 output, ax_cv_gcc_x86_cpuid_$1,
50 [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [
51 int op = $1, eax, ebx, ecx, edx;
53 __asm__("push %%ebx\n\t"
56 : "=a" (eax), "=c" (ecx), "=d" (edx)
58 __asm__("push %%ebx\n\t"
60 "mov %%ebx, %%eax\n\t"
62 : "=a" (ebx), "=c" (ecx), "=d" (edx)
64 f = fopen("conftest_cpuid", "w"); if (!f) return 1;
65 fprintf(f, "%x:%x:%x:%x\n", eax, ebx, ecx, edx);
69 [ax_cv_gcc_x86_cpuid_$1=`cat conftest_cpuid`; rm -f conftest_cpuid],
70 [ax_cv_gcc_x86_cpuid_$1=unknown; rm -f conftest_cpuid],
71 [ax_cv_gcc_x86_cpuid_$1=unknown])])
75 AC_DEFUN([AX_GCC_ARCHFLAG],
76 [AC_REQUIRE([AC_PROG_CC])
77 AC_REQUIRE([AC_CANONICAL_HOST])
79 AC_ARG_WITH(gcc-arch, [AC_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
80 ax_gcc_arch=$withval, ax_gcc_arch=yes)
82 AC_MSG_CHECKING([for gcc architecture flag])
84 AC_CACHE_VAL(ax_cv_gcc_archflag,
86 ax_cv_gcc_archflag="unknown"
88 if test "$GCC" = yes; then
90 if test "x$ax_gcc_arch" = xyes; then
92 if test "$cross_compiling" = no; then
94 i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones
97 case $ax_cv_gcc_x86_cpuid_0 in
98 *:756e6547:*:*) # Intel
99 case $ax_cv_gcc_x86_cpuid_1 in
100 *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
101 *5??:*:*:*) ax_gcc_arch=pentium ;;
102 *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
103 *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
104 *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
105 *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
106 *6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
107 *6[[e]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;; # Core Duo
108 *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
109 *f3[[347]]:*:*:*|*f4[[1347]]:*:*:*)
111 x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
112 *) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
114 *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
116 *:68747541:*:*) # AMD
117 case $ax_cv_gcc_x86_cpuid_1 in
118 *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
119 *5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
120 *5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
121 *60?:*:*:*) ax_gcc_arch=k7 ;;
122 *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
123 *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
124 *67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
126 AX_GCC_X86_CPUID(0x80000006) # L2 cache size
127 case $ax_cv_gcc_x86_cpuid_0x80000006 in
128 *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
129 ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
130 *) ax_gcc_arch="athlon-4 athlon k7" ;;
132 *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
133 *f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
134 *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
135 *f??:*:*:*) ax_gcc_arch="k8" ;;
137 *:746e6543:*:*) # IDT
138 case $ax_cv_gcc_x86_cpuid_1 in
139 *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
140 *58?:*:*:*) ax_gcc_arch=winchip2 ;;
141 *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
142 *69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
145 if test x"$ax_gcc_arch" = x; then # fallback
147 i586*) ax_gcc_arch=pentium ;;
148 i686*) ax_gcc_arch=pentiumpro ;;
154 AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
155 cputype="`(((grep cpu /proc/cpuinfo | cut -d: -f2) ; ($PRTDIAG -v |grep -i sparc) ; grep -i cpu /var/run/dmesg.boot ) | head -n 1) 2> /dev/null`"
156 cputype="`echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters`"
158 *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
159 *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
160 *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
161 *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
162 *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
163 *cypress*) ax_gcc_arch=cypress ;;
166 alphaev5) ax_gcc_arch=ev5 ;;
167 alphaev56) ax_gcc_arch=ev56 ;;
168 alphapca56) ax_gcc_arch="pca56 ev56" ;;
169 alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
170 alphaev6) ax_gcc_arch=ev6 ;;
171 alphaev67) ax_gcc_arch=ev67 ;;
172 alphaev68) ax_gcc_arch="ev68 ev67" ;;
173 alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
174 alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
175 alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
178 cputype="`((grep cpu /proc/cpuinfo | head -n 1 | cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; /usr/bin/machine ; /bin/machine; grep CPU /var/run/dmesg.boot | head -n 1 | cut -d" " -f2) 2> /dev/null`"
179 cputype="`echo $cputype | sed -e 's/ppc//g;s/ *//g'`"
181 *750*) ax_gcc_arch="750 G3" ;;
182 *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
183 *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
184 *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
185 *970*) ax_gcc_arch="970 G5 power4";;
186 *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
187 *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
188 603ev|8240) ax_gcc_arch="$cputype 603e 603";;
189 *Cell*) ax_gcc_arch="cellppu cell";;
190 *) ax_gcc_arch=$cputype ;;
192 ax_gcc_arch="$ax_gcc_arch powerpc"
195 fi # not cross-compiling
198 if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
199 for arch in $ax_gcc_arch; do
200 if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
202 # -mcpu=$arch and m$arch generate nonportable code on every arch except
203 # x86. And some other arches (e.g. Alpha) don't accept -mtune. Grrr.
204 case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
206 flags="-march=$arch -mcpu=$arch -m$arch"
208 for flag in $flags; do
209 AX_CHECK_COMPILER_FLAGS($flag, [ax_cv_gcc_archflag=$flag; break])
211 test "x$ax_cv_gcc_archflag" = xunknown || break
217 AC_MSG_CHECKING([for gcc architecture flag])
218 AC_MSG_RESULT($ax_cv_gcc_archflag)
219 if test "x$ax_cv_gcc_archflag" = xunknown; then
222 m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
223 m4_default([$2], [CXXFLAGS="$CXXFLAGS $ax_cv_gcc_archflag"])
230 # indent-tabs-mode: nil