🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
8.8 KiB

  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_gcc_archflag.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_GCC_ARCHFLAG([PORTABLE?], [ACTION-SUCCESS], [ACTION-FAILURE])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro tries to guess the "native" arch corresponding to the target
  12. # architecture for use with gcc's -march=arch or -mtune=arch flags. If
  13. # found, the cache variable $ax_cv_gcc_archflag is set to this flag and
  14. # ACTION-SUCCESS is executed; otherwise $ax_cv_gcc_archflag is is set to
  15. # "unknown" and ACTION-FAILURE is executed. The default ACTION-SUCCESS is
  16. # to add $ax_cv_gcc_archflag to the end of $CFLAGS.
  17. #
  18. # PORTABLE? should be either [yes] (default) or [no]. In the former case,
  19. # the flag is set to -mtune (or equivalent) so that the architecture is
  20. # only used for tuning, but the instruction set used is still portable. In
  21. # the latter case, the flag is set to -march (or equivalent) so that
  22. # architecture-specific instructions are enabled.
  23. #
  24. # The user can specify --with-gcc-arch=<arch> in order to override the
  25. # macro's choice of architecture, or --without-gcc-arch to disable this.
  26. #
  27. # When cross-compiling, or if $CC is not gcc, then ACTION-FAILURE is
  28. # called unless the user specified --with-gcc-arch manually.
  29. #
  30. # Requires macros: AX_CHECK_COMPILER_FLAGS, AX_GCC_X86_CPUID
  31. #
  32. # (The main emphasis here is on recent CPUs, on the principle that doing
  33. # high-performance computing on old hardware is uncommon.)
  34. #
  35. # LICENSE
  36. #
  37. # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
  38. # Copyright (c) 2008 Matteo Frigo
  39. #
  40. # This program is free software: you can redistribute it and/or modify it
  41. # under the terms of the GNU General Public License as published by the
  42. # Free Software Foundation, either version 3 of the License, or (at your
  43. # option) any later version.
  44. #
  45. # This program is distributed in the hope that it will be useful, but
  46. # WITHOUT ANY WARRANTY; without even the implied warranty of
  47. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  48. # Public License for more details.
  49. #
  50. # You should have received a copy of the GNU General Public License along
  51. # with this program. If not, see <http://www.gnu.org/licenses/>.
  52. #
  53. # As a special exception, the respective Autoconf Macro's copyright owner
  54. # gives unlimited permission to copy, distribute and modify the configure
  55. # scripts that are the output of Autoconf when processing the Macro. You
  56. # need not follow the terms of the GNU General Public License when using
  57. # or distributing such scripts, even though portions of the text of the
  58. # Macro appear in them. The GNU General Public License (GPL) does govern
  59. # all other use of the material that constitutes the Autoconf Macro.
  60. #
  61. # This special exception to the GPL applies to versions of the Autoconf
  62. # Macro released by the Autoconf Archive. When you make and distribute a
  63. # modified version of the Autoconf Macro, you may extend this special
  64. # exception to the GPL to apply to your modified version as well.
  65. #serial 8
  66. AC_DEFUN([AX_GCC_ARCHFLAG],
  67. [AC_REQUIRE([AC_PROG_CC])
  68. AC_REQUIRE([AC_CANONICAL_HOST])
  69. AC_ARG_WITH(gcc-arch, [AS_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
  70. ax_gcc_arch=$withval, ax_gcc_arch=yes)
  71. AC_MSG_CHECKING([for gcc architecture flag])
  72. AC_MSG_RESULT([])
  73. AC_CACHE_VAL(ax_cv_gcc_archflag,
  74. [
  75. ax_cv_gcc_archflag="unknown"
  76. if test "$GCC" = yes; then
  77. if test "x$ax_gcc_arch" = xyes; then
  78. ax_gcc_arch=""
  79. if test "$cross_compiling" = no; then
  80. case $host_cpu in
  81. i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones
  82. AX_GCC_X86_CPUID(0)
  83. AX_GCC_X86_CPUID(1)
  84. case $ax_cv_gcc_x86_cpuid_0 in
  85. *:756e6547:*:*) # Intel
  86. case $ax_cv_gcc_x86_cpuid_1 in
  87. *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
  88. *5??:*:*:*) ax_gcc_arch=pentium ;;
  89. *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
  90. *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
  91. *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
  92. *6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
  93. *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
  94. *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
  95. *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
  96. case $host_cpu in
  97. x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
  98. *) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
  99. esac ;;
  100. *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
  101. esac ;;
  102. *:68747541:*:*) # AMD
  103. case $ax_cv_gcc_x86_cpuid_1 in
  104. *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
  105. *5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
  106. *5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
  107. *60?:*:*:*) ax_gcc_arch=k7 ;;
  108. *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
  109. *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
  110. *67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
  111. *6[[68a]]?:*:*:*)
  112. AX_GCC_X86_CPUID(0x80000006) # L2 cache size
  113. case $ax_cv_gcc_x86_cpuid_0x80000006 in
  114. *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
  115. ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
  116. *) ax_gcc_arch="athlon-4 athlon k7" ;;
  117. esac ;;
  118. *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
  119. *f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
  120. *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
  121. *f??:*:*:*) ax_gcc_arch="k8" ;;
  122. esac ;;
  123. *:746e6543:*:*) # IDT
  124. case $ax_cv_gcc_x86_cpuid_1 in
  125. *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
  126. *58?:*:*:*) ax_gcc_arch=winchip2 ;;
  127. *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
  128. *69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
  129. esac ;;
  130. esac
  131. if test x"$ax_gcc_arch" = x; then # fallback
  132. case $host_cpu in
  133. i586*) ax_gcc_arch=pentium ;;
  134. i686*) ax_gcc_arch=pentiumpro ;;
  135. esac
  136. fi
  137. ;;
  138. sparc*)
  139. AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
  140. 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`
  141. cputype=`echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters`
  142. case $cputype in
  143. *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
  144. *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
  145. *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
  146. *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
  147. *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
  148. *cypress*) ax_gcc_arch=cypress ;;
  149. esac ;;
  150. alphaev5) ax_gcc_arch=ev5 ;;
  151. alphaev56) ax_gcc_arch=ev56 ;;
  152. alphapca56) ax_gcc_arch="pca56 ev56" ;;
  153. alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
  154. alphaev6) ax_gcc_arch=ev6 ;;
  155. alphaev67) ax_gcc_arch=ev67 ;;
  156. alphaev68) ax_gcc_arch="ev68 ev67" ;;
  157. alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
  158. alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
  159. alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
  160. powerpc*)
  161. 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`
  162. cputype=`echo $cputype | sed -e 's/ppc//g;s/ *//g'`
  163. case $cputype in
  164. *750*) ax_gcc_arch="750 G3" ;;
  165. *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
  166. *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
  167. *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
  168. *970*) ax_gcc_arch="970 G5 power4";;
  169. *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
  170. *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
  171. 603ev|8240) ax_gcc_arch="$cputype 603e 603";;
  172. *) ax_gcc_arch=$cputype ;;
  173. esac
  174. ax_gcc_arch="$ax_gcc_arch powerpc"
  175. ;;
  176. esac
  177. fi # not cross-compiling
  178. fi # guess arch
  179. if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
  180. for arch in $ax_gcc_arch; do
  181. if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
  182. flags="-mtune=$arch"
  183. # -mcpu=$arch and m$arch generate nonportable code on every arch except
  184. # x86. And some other arches (e.g. Alpha) don't accept -mtune. Grrr.
  185. case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
  186. else
  187. flags="-march=$arch -mcpu=$arch -m$arch"
  188. fi
  189. for flag in $flags; do
  190. AX_CHECK_COMPILER_FLAGS($flag, [ax_cv_gcc_archflag=$flag; break])
  191. done
  192. test "x$ax_cv_gcc_archflag" = xunknown || break
  193. done
  194. fi
  195. fi # $GCC=yes
  196. ])
  197. AC_MSG_CHECKING([for gcc architecture flag])
  198. AC_MSG_RESULT($ax_cv_gcc_archflag)
  199. if test "x$ax_cv_gcc_archflag" = xunknown; then
  200. m4_default([$3],:)
  201. else
  202. m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
  203. fi
  204. ])