ax_blas.m4 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_blas.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_BLAS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro looks for a library that implements the BLAS linear-algebra
  12. # interface (see http://www.netlib.org/blas/). On success, it sets the
  13. # BLAS_LIBS output variable to hold the requisite library linkages.
  14. #
  15. # To link with BLAS, you should link with:
  16. #
  17. # $BLAS_LIBS $LIBS $FLIBS
  18. #
  19. # in that order. FLIBS is the output variable of the
  20. # AC_F77_LIBRARY_LDFLAGS macro (called if necessary by AX_BLAS), and is
  21. # sometimes necessary in order to link with F77 libraries. Users will also
  22. # need to use AC_F77_DUMMY_MAIN (see the autoconf manual), for the same
  23. # reason.
  24. #
  25. # Many libraries are searched for, from ATLAS to CXML to ESSL. The user
  26. # may also use --with-blas=<lib> in order to use some specific BLAS
  27. # library <lib>. In order to link successfully, however, be aware that you
  28. # will probably need to use the same Fortran compiler (which can be set
  29. # via the F77 env. var.) as was used to compile the BLAS library.
  30. #
  31. # ACTION-IF-FOUND is a list of shell commands to run if a BLAS library is
  32. # found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is
  33. # not found. If ACTION-IF-FOUND is not specified, the default action will
  34. # define HAVE_BLAS.
  35. #
  36. # LICENSE
  37. #
  38. # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
  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 14
  66. AU_ALIAS([ACX_BLAS], [AX_BLAS])
  67. AC_DEFUN([AX_BLAS], [
  68. AC_PREREQ(2.50)
  69. AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
  70. AC_REQUIRE([AC_CANONICAL_HOST])
  71. ax_blas_ok=no
  72. AC_ARG_WITH(blas,
  73. [AS_HELP_STRING([--with-blas=<lib>], [use BLAS library <lib>])])
  74. case $with_blas in
  75. yes | "") ;;
  76. no) ax_blas_ok=disable ;;
  77. -* | */* | *.a | *.so | *.so.* | *.o) BLAS_LIBS="$with_blas" ;;
  78. *) BLAS_LIBS="-l$with_blas" ;;
  79. esac
  80. # Get fortran linker names of BLAS functions to check for.
  81. AC_F77_FUNC(sgemm)
  82. AC_F77_FUNC(dgemm)
  83. ax_blas_save_LIBS="$LIBS"
  84. LIBS="$LIBS $FLIBS"
  85. # First, check BLAS_LIBS environment variable
  86. if test $ax_blas_ok = no; then
  87. if test "x$BLAS_LIBS" != x; then
  88. save_LIBS="$LIBS"; LIBS="$BLAS_LIBS $LIBS"
  89. AC_MSG_CHECKING([for $sgemm in $BLAS_LIBS])
  90. AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes], [BLAS_LIBS=""])
  91. AC_MSG_RESULT($ax_blas_ok)
  92. LIBS="$save_LIBS"
  93. fi
  94. fi
  95. # BLAS linked to by default? (happens on some supercomputers)
  96. if test $ax_blas_ok = no; then
  97. save_LIBS="$LIBS"; LIBS="$LIBS"
  98. AC_MSG_CHECKING([if $sgemm is being linked in already])
  99. AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes])
  100. AC_MSG_RESULT($ax_blas_ok)
  101. LIBS="$save_LIBS"
  102. fi
  103. # BLAS in OpenBLAS library? (http://xianyi.github.com/OpenBLAS/)
  104. if test $ax_blas_ok = no; then
  105. AC_CHECK_LIB(openblas, $sgemm, [ax_blas_ok=yes
  106. BLAS_LIBS="-lopenblas"])
  107. fi
  108. # BLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
  109. if test $ax_blas_ok = no; then
  110. AC_CHECK_LIB(atlas, ATL_xerbla,
  111. [AC_CHECK_LIB(f77blas, $sgemm,
  112. [AC_CHECK_LIB(cblas, cblas_dgemm,
  113. [ax_blas_ok=yes
  114. BLAS_LIBS="-lcblas -lf77blas -latlas"],
  115. [], [-lf77blas -latlas])],
  116. [], [-latlas])])
  117. fi
  118. # BLAS in PhiPACK libraries? (requires generic BLAS lib, too)
  119. if test $ax_blas_ok = no; then
  120. AC_CHECK_LIB(blas, $sgemm,
  121. [AC_CHECK_LIB(dgemm, $dgemm,
  122. [AC_CHECK_LIB(sgemm, $sgemm,
  123. [ax_blas_ok=yes; BLAS_LIBS="-lsgemm -ldgemm -lblas"],
  124. [], [-lblas])],
  125. [], [-lblas])])
  126. fi
  127. # BLAS in Intel MKL library?
  128. # New MKL link flag
  129. if test $ax_blas_ok = no; then
  130. save_LIBS="$LIBS"; LIBS="$LIBS -mkl"
  131. AC_MSG_CHECKING([for $sgemm in -mkl])
  132. AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes;BLAS_LIBS="-mkl"])
  133. AC_MSG_RESULT($ax_blas_ok)
  134. LIBS="$save_LIBS"
  135. fi
  136. if test $ax_blas_ok = no; then
  137. # MKL for gfortran
  138. if test x"$ac_cv_fc_compiler_gnu" = xyes; then
  139. # 64 bit
  140. if test $host_cpu = x86_64; then
  141. AC_CHECK_LIB(mkl_gf_lp64, $sgemm,
  142. [ax_blas_ok=yes;BLAS_LIBS="-lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread"],,
  143. [-lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread])
  144. # 32 bit
  145. elif test $host_cpu = i686; then
  146. AC_CHECK_LIB(mkl_gf, $sgemm,
  147. [ax_blas_ok=yes;BLAS_LIBS="-lmkl_gf -lmkl_sequential -lmkl_core -lpthread"],,
  148. [-lmkl_gf -lmkl_sequential -lmkl_core -lpthread])
  149. fi
  150. # MKL for other compilers (Intel, PGI, ...?)
  151. else
  152. # 64-bit
  153. if test $host_cpu = x86_64; then
  154. AC_CHECK_LIB(mkl_intel_lp64, $sgemm,
  155. [ax_blas_ok=yes;BLAS_LIBS="-lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread"],,
  156. [-lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lpthread])
  157. # 32-bit
  158. elif test $host_cpu = i686; then
  159. AC_CHECK_LIB(mkl_intel, $sgemm,
  160. [ax_blas_ok=yes;BLAS_LIBS="-lmkl_intel -lmkl_sequential -lmkl_core -lpthread"],,
  161. [-lmkl_intel -lmkl_sequential -lmkl_core -lpthread])
  162. fi
  163. fi
  164. fi
  165. # Old versions of MKL
  166. if test $ax_blas_ok = no; then
  167. AC_CHECK_LIB(mkl, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-lmkl -lguide -lpthread"],,[-lguide -lpthread])
  168. fi
  169. # BLAS in Apple vecLib library?
  170. if test $ax_blas_ok = no; then
  171. save_LIBS="$LIBS"; LIBS="-framework vecLib $LIBS"
  172. AC_MSG_CHECKING([for $sgemm in -framework vecLib])
  173. AC_TRY_LINK_FUNC($sgemm, [ax_blas_ok=yes;BLAS_LIBS="-framework vecLib"])
  174. AC_MSG_RESULT($ax_blas_ok)
  175. LIBS="$save_LIBS"
  176. fi
  177. # BLAS in Alpha CXML library?
  178. if test $ax_blas_ok = no; then
  179. AC_CHECK_LIB(cxml, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-lcxml"])
  180. fi
  181. # BLAS in Alpha DXML library? (now called CXML, see above)
  182. if test $ax_blas_ok = no; then
  183. AC_CHECK_LIB(dxml, $sgemm, [ax_blas_ok=yes;BLAS_LIBS="-ldxml"])
  184. fi
  185. # BLAS in Sun Performance library?
  186. if test $ax_blas_ok = no; then
  187. if test "x$GCC" != xyes; then # only works with Sun CC
  188. AC_CHECK_LIB(sunmath, acosp,
  189. [AC_CHECK_LIB(sunperf, $sgemm,
  190. [BLAS_LIBS="-xlic_lib=sunperf -lsunmath"
  191. ax_blas_ok=yes],[],[-lsunmath])])
  192. fi
  193. fi
  194. # BLAS in SCSL library? (SGI/Cray Scientific Library)
  195. if test $ax_blas_ok = no; then
  196. AC_CHECK_LIB(scs, $sgemm, [ax_blas_ok=yes; BLAS_LIBS="-lscs"])
  197. fi
  198. # BLAS in SGIMATH library?
  199. if test $ax_blas_ok = no; then
  200. AC_CHECK_LIB(complib.sgimath, $sgemm,
  201. [ax_blas_ok=yes; BLAS_LIBS="-lcomplib.sgimath"])
  202. fi
  203. # BLAS in IBM ESSL library? (requires generic BLAS lib, too)
  204. if test $ax_blas_ok = no; then
  205. AC_CHECK_LIB(blas, $sgemm,
  206. [AC_CHECK_LIB(essl, $sgemm,
  207. [ax_blas_ok=yes; BLAS_LIBS="-lessl -lblas"],
  208. [], [-lblas $FLIBS])])
  209. fi
  210. # Generic BLAS library?
  211. if test $ax_blas_ok = no; then
  212. AC_CHECK_LIB(blas, $sgemm, [ax_blas_ok=yes; BLAS_LIBS="-lblas"])
  213. fi
  214. AC_SUBST(BLAS_LIBS)
  215. LIBS="$ax_blas_save_LIBS"
  216. # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
  217. if test x"$ax_blas_ok" = xyes; then
  218. ifelse([$1],,AC_DEFINE(HAVE_BLAS,1,[Define if you have a BLAS library.]),[$1])
  219. :
  220. else
  221. ax_blas_ok=no
  222. $2
  223. fi
  224. ])dnl AX_BLAS