1 # ===========================================================================
2 # http://autoconf-archive.cryp.to/acx_blas.html
3 # ===========================================================================
7 # ACX_CBLAS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
11 # This macro looks for a library that implements the CBLAS linear-algebra
12 # interface (see http://www.netlib.org/blas/). On success, it sets the
13 # CBLAS_LIBS output variable to hold the requisite library linkages.
15 # To link with BLAS, you should link with:
19 # Many libraries are searched for, from ATLAS to CXML to ESSL. The user
20 # may also use --with-blas=<lib> in order to use some specific CBLAS
21 # library <lib>. In order to link successfully, however, be aware that you
22 # will probably need to use the same Fortran compiler (which can be set
23 # via the F77 env. var.) as was used to compile the BLAS library.
25 # ACTION-IF-FOUND is a list of shell commands to run if a CBLAS library is
26 # found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is
27 # not found. If ACTION-IF-FOUND is not specified, the default action will
30 # This macro requires autoconf 2.50 or later.
38 # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
39 # Copyright (c) 2008 Free Software Foundation, Inc.
41 # This program is free software: you can redistribute it and/or modify it
42 # under the terms of the GNU General Public License as published by the
43 # Free Software Foundation, either version 3 of the License, or (at your
44 # option) any later version.
46 # This program is distributed in the hope that it will be useful, but
47 # WITHOUT ANY WARRANTY; without even the implied warranty of
48 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
49 # Public License for more details.
51 # You should have received a copy of the GNU General Public License along
52 # with this program. If not, see <http://www.gnu.org/licenses/>.
54 # As a special exception, the respective Autoconf Macro's copyright owner
55 # gives unlimited permission to copy, distribute and modify the configure
56 # scripts that are the output of Autoconf when processing the Macro. You
57 # need not follow the terms of the GNU General Public License when using
58 # or distributing such scripts, even though portions of the text of the
59 # Macro appear in them. The GNU General Public License (GPL) does govern
60 # all other use of the material that constitutes the Autoconf Macro.
62 # This special exception to the GPL applies to versions of the Autoconf
63 # Macro released by the Autoconf Macro Archive. When you make and
64 # distribute a modified version of the Autoconf Macro, you may extend this
65 # special exception to the GPL to apply to your modified version as well.
67 AC_DEFUN([ACX_CBLAS], [
69 dnl AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
70 AC_REQUIRE([AC_CANONICAL_HOST])
74 [AC_HELP_STRING([--with-cblas=<lib>], [use CBLAS library <lib>])])
77 no) acx_cblas_ok=disable ;;
78 -* | */* | *.a | *.so | *.so.* | *.o) CBLAS_LIBS="$with_cblas" ;;
79 *) CBLAS_LIBS="-l$with_cblas" ;;
83 acx_cblas_save_LIBS="$LIBS"
86 # First, check CBLAS_LIBS environment variable
87 if test $acx_cblas_ok = no; then
88 if test "x$CBLAS_LIBS" != x; then
89 save_LIBS="$LIBS"; LIBS="$CBLAS_LIBS $LIBS"
90 AC_MSG_CHECKING([for cblas_sgemm in $CBLAS_LIBS])
91 AC_TRY_LINK_FUNC(cblas_sgemm, [acx_cblas_ok=yes], [CBLAS_LIBS=""])
92 AC_MSG_RESULT($acx_cblas_ok)
97 # CBLAS linked to by default? (happens on some supercomputers)
98 if test $acx_cblas_ok = no; then
99 save_LIBS="$LIBS"; LIBS="$LIBS"
100 AC_CHECK_FUNC(cblas_sgemm, [acx_cblas_ok=yes])
104 # CBLAS in ATLAS library? (http://math-atlas.sourceforge.net/)
105 if test $acx_cblas_ok = no; then
106 AC_CHECK_LIB(atlas, ATL_xerbla,
107 [AC_CHECK_LIB(cblas, cblas_dgemm,
109 CBLAS_LIBS="-lcblas -latlas"],
114 # CBLAS in ATLAS library in /usr/lib64/atlas (if not cross-compiling)
115 if test $acx_cblas_ok = no && test "$cross_compiling" = no; then
116 unset ac_cv_lib_atlas_ATL_xerbla
117 unset ac_cv_lib_cblas_cblas_dgemm
118 AC_CHECK_LIB(atlas, ATL_xerbla,
119 [AC_CHECK_LIB(cblas, cblas_dgemm,
121 CBLAS_LIBS="-L/usr/lib64/atlas -lcblas -latlas"],
122 [], [-L/usr/lib64/atlas -latlas])],
123 [], [-L/usr/lib64/atlas -latlas])
126 # CBLAS in ATLAS library in /usr/lib/atlas (if not cross-compiling)
127 if test $acx_cblas_ok = no && test "$cross_compiling" = no; then
128 unset ac_cv_lib_atlas_ATL_xerbla
129 unset ac_cv_lib_cblas_cblas_dgemm
130 AC_CHECK_LIB(atlas, ATL_xerbla,
131 [AC_CHECK_LIB(cblas, cblas_dgemm,
133 CBLAS_LIBS="-L/usr/lib/atlas -lcblas -latlas"],
134 [], [-L/usr/lib/atlas -latlas])],
135 [], [-L/usr/lib/atlas -latlas])
139 # CBLAS in PhiPACK libraries? (requires generic BLAS lib, too)
140 if test $acx_cblas_ok = no; then
141 AC_CHECK_LIB(cblas, cblas_sgemm,
142 [AC_CHECK_LIB(dgemm, cblas_dgemm,
143 [AC_CHECK_LIB(sgemm, cblas_sgemm,
144 [acx_cblas_ok=yes; CBLAS_LIBS="-lsgemm -ldgemm -lblas"],
149 # BLAS in Intel MKL library?
150 if test $acx_cblas_ok = no; then
151 AC_CHECK_LIB(mkl, cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-lmkl"])
154 # CBLAS in Apple vecLib library?
155 if test $acx_cblas_ok = no; then
156 save_LIBS="$LIBS"; LIBS="-framework vecLib $LIBS"
157 AC_CHECK_FUNC(cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-framework vecLib"])
161 # CBLAS in Alpha CXML library?
162 if test $acx_cblas_ok = no; then
163 AC_CHECK_LIB(cxml, cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-lcxml"])
166 # CBLAS in Alpha DXML library? (now called CXML, see above)
167 if test $acx_cblas_ok = no; then
168 AC_CHECK_LIB(dxml, cblas_sgemm, [acx_cblas_ok=yes;CBLAS_LIBS="-ldxml"])
171 # CBLAS in Sun Performance library?
172 if test $acx_cblas_ok = no; then
173 if test "x$GCC" != xyes; then # only works with Sun CC
174 AC_CHECK_LIB(sunmath, acosp,
175 [AC_CHECK_LIB(sunperf, cblas_sgemm,
176 [CBLAS_LIBS="-xlic_lib=sunperf -lsunmath"
177 acx_cblas_ok=yes],[],[-lsunmath])])
181 # CBLAS in SCSL library? (SGI/Cray Scientific Library)
182 if test $acx_cblas_ok = no; then
183 AC_CHECK_LIB(scs, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lscs"])
186 # CBLAS in SGIMATH library?
187 if test $acx_cblas_ok = no; then
188 AC_CHECK_LIB(complib.sgimath, cblas_sgemm,
189 [acx_cblas_ok=yes; CBLAS_LIBS="-lcomplib.sgimath"])
192 # CBLAS in IBM ESSL library? (requires generic CBLAS lib, too)
193 if test $acx_cblas_ok = no; then
194 AC_CHECK_LIB(cblas, cblas_sgemm,
195 [AC_CHECK_LIB(essl, cblas_sgemm,
196 [acx_cblas_ok=yes; CBLAS_LIBS="-lessl -lblas"],
197 [], [-lblas $FLIBS])])
200 # Generic CBLAS library?
201 if test $acx_cblas_ok = no; then
202 AC_CHECK_LIB(cblas, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lcblas"])
205 # Generic BLAS library?
206 if test $acx_cblas_ok = no; then
207 AC_CHECK_LIB(blas, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lblas"])
210 # GSL generic CBLAS library?
211 if test $acx_cblas_ok = no; then
212 AC_CHECK_LIB(gslcblas, cblas_sgemm, [acx_cblas_ok=yes; CBLAS_LIBS="-lgslcblas"])
217 LIBS="$acx_cblas_save_LIBS"
219 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
220 if test x"$acx_cblas_ok" = xyes; then
221 ifelse([$1],,AC_DEFINE(HAVE_CBLAS,1,[Define if you have a CBLAS library.]),[$1])