Collection of DPF-based plugins for packaging
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.

264 lines
13KB

  1. # ===========================================================================
  2. # https://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 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_COMPILE_FLAG, 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. # Copyright (c) 2014 Tsukasa Oi
  40. # Copyright (c) 2017-2018 Alexey Kopytov
  41. #
  42. # This program is free software: you can redistribute it and/or modify it
  43. # under the terms of the GNU General Public License as published by the
  44. # Free Software Foundation, either version 3 of the License, or (at your
  45. # option) any later version.
  46. #
  47. # This program is distributed in the hope that it will be useful, but
  48. # WITHOUT ANY WARRANTY; without even the implied warranty of
  49. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  50. # Public License for more details.
  51. #
  52. # You should have received a copy of the GNU General Public License along
  53. # with this program. If not, see <https://www.gnu.org/licenses/>.
  54. #
  55. # As a special exception, the respective Autoconf Macro's copyright owner
  56. # gives unlimited permission to copy, distribute and modify the configure
  57. # scripts that are the output of Autoconf when processing the Macro. You
  58. # need not follow the terms of the GNU General Public License when using
  59. # or distributing such scripts, even though portions of the text of the
  60. # Macro appear in them. The GNU General Public License (GPL) does govern
  61. # all other use of the material that constitutes the Autoconf Macro.
  62. #
  63. # This special exception to the GPL applies to versions of the Autoconf
  64. # Macro released by the Autoconf Archive. When you make and distribute a
  65. # modified version of the Autoconf Macro, you may extend this special
  66. # exception to the GPL to apply to your modified version as well.
  67. #serial 21
  68. AC_DEFUN([AX_GCC_ARCHFLAG],
  69. [AC_REQUIRE([AC_PROG_CC])
  70. AC_REQUIRE([AC_CANONICAL_HOST])
  71. AC_REQUIRE([AC_PROG_SED])
  72. AC_REQUIRE([AX_COMPILER_VENDOR])
  73. AC_ARG_WITH(gcc-arch, [AS_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
  74. ax_gcc_arch=$withval, ax_gcc_arch=yes)
  75. AC_MSG_CHECKING([for gcc architecture flag])
  76. AC_MSG_RESULT([])
  77. AC_CACHE_VAL(ax_cv_gcc_archflag,
  78. [
  79. ax_cv_gcc_archflag="unknown"
  80. if test "$GCC" = yes; then
  81. if test "x$ax_gcc_arch" = xyes; then
  82. ax_gcc_arch=""
  83. if test "$cross_compiling" = no; then
  84. case $host_cpu in
  85. i[[3456]]86*|x86_64*|amd64*) # use cpuid codes
  86. AX_GCC_X86_CPUID(0)
  87. AX_GCC_X86_CPUID(1)
  88. case $ax_cv_gcc_x86_cpuid_0 in
  89. *:756e6547:6c65746e:49656e69) # Intel
  90. case $ax_cv_gcc_x86_cpuid_1 in
  91. *5[[4578]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
  92. *5[[123]]?:*:*:*) ax_gcc_arch=pentium ;;
  93. *0?61?:*:*:*|?61?:*:*:*|61?:*:*:*) ax_gcc_arch=pentiumpro ;;
  94. *0?6[[356]]?:*:*:*|?6[[356]]?:*:*:*|6[[356]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
  95. *0?6[[78ab]]?:*:*:*|?6[[78ab]]?:*:*:*|6[[78ab]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
  96. *0?6[[9d]]?:*:*:*|?6[[9d]]?:*:*:*|6[[9d]]?:*:*:*|*1?65?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
  97. *0?6e?:*:*:*|?6e?:*:*:*|6e?:*:*:*) ax_gcc_arch="yonah pentium-m pentium3 pentiumpro" ;;
  98. *0?6f?:*:*:*|?6f?:*:*:*|6f?:*:*:*|*1?66?:*:*:*) ax_gcc_arch="core2 pentium-m pentium3 pentiumpro" ;;
  99. *1?6[[7d]]?:*:*:*) ax_gcc_arch="penryn core2 pentium-m pentium3 pentiumpro" ;;
  100. *1?6[[aef]]?:*:*:*|*2?6e?:*:*:*) ax_gcc_arch="nehalem corei7 core2 pentium-m pentium3 pentiumpro" ;;
  101. *2?6[[5cf]]?:*:*:*) ax_gcc_arch="westmere corei7 core2 pentium-m pentium3 pentiumpro" ;;
  102. *2?6[[ad]]?:*:*:*) ax_gcc_arch="sandybridge corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;;
  103. *3?6[[ae]]?:*:*:*) ax_gcc_arch="ivybridge core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;;
  104. *3?6[[cf]]?:*:*:*|*4?6[[56]]?:*:*:*) ax_gcc_arch="haswell core-avx2 core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;;
  105. *3?6d?:*:*:*|*4?6[[7f]]?:*:*:*|*5?66?:*:*:*) ax_gcc_arch="broadwell core-avx2 core-avx-i corei7-avx corei7 core2 pentium-m pentium3 pentiumpro" ;;
  106. *1?6c?:*:*:*|*2?6[[67]]?:*:*:*|*3?6[[56]]?:*:*:*) ax_gcc_arch="bonnell atom core2 pentium-m pentium3 pentiumpro" ;;
  107. *3?67?:*:*:*|*[[45]]?6[[ad]]?:*:*:*) ax_gcc_arch="silvermont atom core2 pentium-m pentium3 pentiumpro" ;;
  108. *000?f[[012]]?:*:*:*|?f[[012]]?:*:*:*|f[[012]]?:*:*:*) ax_gcc_arch="pentium4 pentiumpro" ;;
  109. *000?f[[346]]?:*:*:*|?f[[346]]?:*:*:*|f[[346]]?:*:*:*) ax_gcc_arch="nocona prescott pentium4 pentiumpro" ;;
  110. # fallback
  111. *5??:*:*:*) ax_gcc_arch=pentium ;;
  112. *??6??:*:*:*) ax_gcc_arch="core2 pentiumpro" ;;
  113. *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
  114. *00??f??:*:*:*|??f??:*:*:*|?f??:*:*:*|f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro" ;;
  115. esac ;;
  116. *:68747541:444d4163:69746e65) # AMD
  117. case $ax_cv_gcc_x86_cpuid_1 in
  118. *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
  119. *5[[8]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
  120. *5[[9d]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
  121. *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
  122. *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
  123. *6[[678a]]?:*:*:*) ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
  124. *000?f[[4578bcef]]?:*:*:*|?f[[4578bcef]]?:*:*:*|f[[4578bcef]]?:*:*:*|*001?f[[4578bcf]]?:*:*:*|1?f[[4578bcf]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
  125. *002?f[[13457bcf]]?:*:*:*|2?f[[13457bcf]]?:*:*:*|*004?f[[138bcf]]?:*:*:*|4?f[[138bcf]]?:*:*:*|*005?f[[df]]?:*:*:*|5?f[[df]]?:*:*:*|*006?f[[8bcf]]?:*:*:*|6?f[[8bcf]]?:*:*:*|*007?f[[cf]]?:*:*:*|7?f[[cf]]?:*:*:*|*00c?f1?:*:*:*|c?f1?:*:*:*|*020?f3?:*:*:*|20?f3?:*:*:*) ax_gcc_arch="athlon64-sse3 k8-sse3 athlon64 k8" ;;
  126. *010?f[[245689a]]?:*:*:*|10?f[[245689a]]?:*:*:*|*030?f1?:*:*:*|30?f1?:*:*:*) ax_gcc_arch="barcelona amdfam10 k8" ;;
  127. *050?f[[12]]?:*:*:*|50?f[[12]]?:*:*:*) ax_gcc_arch="btver1 amdfam10 k8" ;;
  128. *060?f1?:*:*:*|60?f1?:*:*:*) ax_gcc_arch="bdver1 amdfam10 k8" ;;
  129. *060?f2?:*:*:*|60?f2?:*:*:*|*061?f[[03]]?:*:*:*|61?f[[03]]?:*:*:*) ax_gcc_arch="bdver2 bdver1 amdfam10 k8" ;;
  130. *063?f0?:*:*:*|63?f0?:*:*:*) ax_gcc_arch="bdver3 bdver2 bdver1 amdfam10 k8" ;;
  131. *07[[03]]?f0?:*:*:*|7[[03]]?f0?:*:*:*) ax_gcc_arch="btver2 btver1 amdfam10 k8" ;;
  132. # fallback
  133. *0[[13]]??f??:*:*:*|[[13]]??f??:*:*:*) ax_gcc_arch="barcelona amdfam10 k8" ;;
  134. *020?f??:*:*:*|20?f??:*:*:*) ax_gcc_arch="athlon64-sse3 k8-sse3 athlon64 k8" ;;
  135. *05??f??:*:*:*|5??f??:*:*:*) ax_gcc_arch="btver1 amdfam10 k8" ;;
  136. *060?f??:*:*:*|60?f??:*:*:*) ax_gcc_arch="bdver1 amdfam10 k8" ;;
  137. *061?f??:*:*:*|61?f??:*:*:*) ax_gcc_arch="bdver2 bdver1 amdfam10 k8" ;;
  138. *06??f??:*:*:*|6??f??:*:*:*) ax_gcc_arch="bdver3 bdver2 bdver1 amdfam10 k8" ;;
  139. *070?f??:*:*:*|70?f??:*:*:*) ax_gcc_arch="btver2 btver1 amdfam10 k8" ;;
  140. *???f??:*:*:*) ax_gcc_arch="amdfam10 k8" ;;
  141. esac ;;
  142. *:746e6543:736c7561:48727561) # IDT / VIA (Centaur)
  143. case $ax_cv_gcc_x86_cpuid_1 in
  144. *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
  145. *5[[89]]?:*:*:*) ax_gcc_arch=winchip2 ;;
  146. *66?:*:*:*) ax_gcc_arch=winchip2 ;;
  147. *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
  148. *6[[9adf]]?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
  149. esac ;;
  150. esac
  151. if test x"$ax_gcc_arch" = x; then # fallback
  152. case $host_cpu in
  153. i586*) ax_gcc_arch=pentium ;;
  154. i686*) ax_gcc_arch=pentiumpro ;;
  155. esac
  156. fi
  157. ;;
  158. sparc*)
  159. AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
  160. 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`
  161. cputype=`echo "$cputype" | tr -d ' -' | $SED 's/SPARCIIi/SPARCII/' |tr $as_cr_LETTERS $as_cr_letters`
  162. case $cputype in
  163. *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
  164. *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
  165. *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
  166. *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
  167. *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
  168. *cypress*) ax_gcc_arch=cypress ;;
  169. esac ;;
  170. alphaev5) ax_gcc_arch=ev5 ;;
  171. alphaev56) ax_gcc_arch=ev56 ;;
  172. alphapca56) ax_gcc_arch="pca56 ev56" ;;
  173. alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
  174. alphaev6) ax_gcc_arch=ev6 ;;
  175. alphaev67) ax_gcc_arch=ev67 ;;
  176. alphaev68) ax_gcc_arch="ev68 ev67" ;;
  177. alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
  178. alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
  179. alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
  180. powerpc*)
  181. 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`
  182. cputype=`echo $cputype | $SED -e 's/ppc//g;s/ *//g'`
  183. case $cputype in
  184. *750*) ax_gcc_arch="750 G3" ;;
  185. *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
  186. *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
  187. *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
  188. *970*) ax_gcc_arch="970 G5 power4";;
  189. *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
  190. *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
  191. 603ev|8240) ax_gcc_arch="$cputype 603e 603";;
  192. *) ax_gcc_arch=$cputype ;;
  193. esac
  194. ax_gcc_arch="$ax_gcc_arch powerpc"
  195. ;;
  196. aarch64)
  197. cpuimpl=`grep 'CPU implementer' /proc/cpuinfo 2> /dev/null | cut -d: -f2 | tr -d " " | head -n 1`
  198. cpuarch=`grep 'CPU architecture' /proc/cpuinfo 2> /dev/null | cut -d: -f2 | tr -d " " | head -n 1`
  199. cpuvar=`grep 'CPU variant' /proc/cpuinfo 2> /dev/null | cut -d: -f2 | tr -d " " | head -n 1`
  200. case $cpuimpl in
  201. 0x42) case $cpuarch in
  202. 8) case $cpuvar in
  203. 0x0) ax_gcc_arch="thunderx2t99 vulcan armv8.1-a armv8-a+lse armv8-a native" ;;
  204. esac
  205. ;;
  206. esac
  207. ;;
  208. 0x43) case $cpuarch in
  209. 8) case $cpuvar in
  210. 0x0) ax_gcc_arch="thunderx armv8-a native" ;;
  211. 0x1) ax_gcc_arch="thunderx+lse armv8.1-a armv8-a+lse armv8-a native" ;;
  212. esac
  213. ;;
  214. esac
  215. ;;
  216. esac
  217. ;;
  218. esac
  219. fi # not cross-compiling
  220. fi # guess arch
  221. if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
  222. if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
  223. flag_prefixes="-mtune="
  224. if test "x$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor" = xclang; then flag_prefixes="-march="; fi
  225. # -mcpu=$arch and m$arch generate nonportable code on every arch except
  226. # x86. And some other arches (e.g. Alpha) don't accept -mtune. Grrr.
  227. case $host_cpu in i*86|x86_64*|amd64*) flag_prefixes="$flag_prefixes -mcpu= -m";; esac
  228. else
  229. flag_prefixes="-march= -mcpu= -m"
  230. fi
  231. for flag_prefix in $flag_prefixes; do
  232. for arch in $ax_gcc_arch; do
  233. flag="$flag_prefix$arch"
  234. AX_CHECK_COMPILE_FLAG($flag, [if test "x$ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor" = xclang; then
  235. if test "x[]m4_default([$1],yes)" = xyes; then
  236. if test "x$flag" = "x-march=$arch"; then flag=-mtune=$arch; fi
  237. fi
  238. fi; ax_cv_gcc_archflag=$flag; break])
  239. done
  240. test "x$ax_cv_gcc_archflag" = xunknown || break
  241. done
  242. fi
  243. fi # $GCC=yes
  244. ])
  245. AC_MSG_CHECKING([for gcc architecture flag])
  246. AC_MSG_RESULT($ax_cv_gcc_archflag)
  247. if test "x$ax_cv_gcc_archflag" = xunknown; then
  248. m4_default([$3],:)
  249. else
  250. m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
  251. fi
  252. ])