Imported Upstream version 3.2.2
[debian/gnuradio] / config / acx_cblas.m4
1 # ===========================================================================
2 #                http://autoconf-archive.cryp.to/acx_blas.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   ACX_CBLAS([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
8 #
9 # DESCRIPTION
10 #
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.
14 #
15 #   To link with BLAS, you should link with:
16 #
17 #       $CBLAS_LIBS $LIBS
18 #
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.
24 #
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
28 #   define HAVE_CBLAS.
29 #
30 #   This macro requires autoconf 2.50 or later.
31 #
32 # LAST MODIFICATION
33 #
34 #   2008-04-12
35 #
36 # COPYLEFT
37 #
38 #   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
39 #   Copyright (c) 2008 Free Software Foundation, Inc.
40 #
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.
45 #
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.
50 #
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/>.
53 #
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.
61 #
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.
66
67 AC_DEFUN([ACX_CBLAS], [
68 AC_PREREQ(2.50)
69 dnl AC_REQUIRE([AC_F77_LIBRARY_LDFLAGS])
70 AC_REQUIRE([AC_CANONICAL_HOST])
71 acx_cblas_ok=no
72
73 AC_ARG_WITH(cblas,
74         [AC_HELP_STRING([--with-cblas=<lib>], [use CBLAS library <lib>])])
75 case $with_cblas in
76         yes | "") ;;
77         no) acx_cblas_ok=disable ;;
78         -* | */* | *.a | *.so | *.so.* | *.o) CBLAS_LIBS="$with_cblas" ;;
79         *) CBLAS_LIBS="-l$with_cblas" ;;
80 esac
81
82
83 acx_cblas_save_LIBS="$LIBS"
84 LIBS="$LIBS $FLIBS"
85
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)
93         LIBS="$save_LIBS"
94 fi
95 fi
96
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])
101         LIBS="$save_LIBS"
102 fi
103
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,
108                 [acx_cblas_ok=yes
109                  CBLAS_LIBS="-lcblas -latlas"],
110                 [], [-latlas])],
111             [], [-latlas])
112 fi
113
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,
120                 [acx_cblas_ok=yes
121                  CBLAS_LIBS="-L/usr/lib64/atlas -lcblas -latlas"],
122                 [], [-L/usr/lib64/atlas -latlas])],
123             [], [-L/usr/lib64/atlas -latlas])
124 fi
125
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,
132                 [acx_cblas_ok=yes
133                  CBLAS_LIBS="-L/usr/lib/atlas -lcblas -latlas"],
134                 [], [-L/usr/lib/atlas -latlas])],
135             [], [-L/usr/lib/atlas -latlas])
136 fi
137
138
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"],
145                         [], [-lblas])],
146                         [], [-lblas])])
147 fi
148
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"])
152 fi
153
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"])
158         LIBS="$save_LIBS"
159 fi
160
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"])
164 fi
165
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"])
169 fi
170
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])])
178         fi
179 fi
180
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"])
184 fi
185
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"])
190 fi
191
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])])
198 fi
199
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"])
203 fi
204
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"])
208 fi
209
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"])
213 fi
214
215 AC_SUBST(CBLAS_LIBS)
216
217 LIBS="$acx_cblas_save_LIBS"
218
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])
222         :
223 else
224         acx_cblas_ok=no
225         $2
226 fi
227 ])dnl ACX_CBLAS