acx_atlas.m4 7.38 KB
Newer Older
Emmanuel Bertin's avatar
Emmanuel Bertin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
dnl @synopsis ACX_ATLAS([ATLAS_LIBDIR, ATLAS_INCDIR, ATLAS_PFLAG, [ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]])
dnl This macro figures out if the ATLAS library and header files
dnl are installed.
dnl You may wish to use these variables in your default LIBS:
dnl
dnl        LIBS="$ATLAS_LIBS $LIBS"
dnl
dnl ACTION-IF-FOUND is a list of shell commands to run if BLAS/LAPACK
dnl is found (HAVE_ATLAS is defined first), and ACTION-IF-NOT-FOUND
dnl is a list of commands to run it if it is not found.
dnl
dnl @version $Id: acx_atlas.m4,v 1.0 2007/10/19 21:30:17 bertin Exp $
dnl @author Emmanuel Bertin <bertin@iap.fr>

AC_DEFUN([ACX_ATLAS], [
AC_REQUIRE([AC_CANONICAL_HOST])

dnl --------------------
dnl Search include files
dnl --------------------

acx_atlas_ok=no
if test x$2 = x; then
  if test x$1 = x; then
    AC_CHECK_HEADERS([cblas.h clapack.h],[acx_atlas_ok=yes])
    if test x$acx_atlas_ok = xyes; then
      AC_DEFINE(ATLAS_BLAS_H, "cblas.h", [BLAS header filename.])
      AC_DEFINE(ATLAS_LAPACK_H, "clapack.h", [CLAPACK header filename.])
    else
      AC_CHECK_HEADERS([atlas/cblas.h atlas/clapack.h],[acx_atlas_ok=yes])
      if test x$acx_atlas_ok = xyes; then
        AC_DEFINE(ATLAS_BLAS_H, "atlas/cblas.h", [BLAS header filename.])
        AC_DEFINE(ATLAS_LAPACK_H, "atlas/clapack.h", [CLAPACK header filename.])
      else
        atlas_def=/usr/local/atlas
        AC_CHECK_HEADERS(
		[$atlas_def/include/cblas.h $atlas_def/include/clapack.h],
		[acx_atlas_ok=yes])
        if test x$acx_atlas_ok = xyes; then
          AC_DEFINE_UNQUOTED(ATLAS_BLAS_H, "$atlas_def/include/cblas.h",
		[BLAS header filename.])
          AC_DEFINE_UNQUOTED(ATLAS_LAPACK_H, "$atlas_def/include/clapack.h",
		[CLAPACK header filename.])
        else
          atlas_def=/usr/atlas
          AC_CHECK_HEADERS(
		[$atlas_def/include/cblas.h $atlas_def/include/clapack.h],
		[acx_atlas_ok=yes])
          if test x$acx_atlas_ok = xyes; then
            AC_DEFINE_UNQUOTED(ATLAS_BLAS_H, "$atlas_def/include/cblas.h",
		[BLAS header filename.])
            AC_DEFINE_UNQUOTED(ATLAS_LAPACK_H, "$atlas_def/include/clapack.h",
		[CLAPACK header filename.])
          else
            ATLAS_ERROR="CBLAS/LAPack include files not found!"
          fi
        fi
      fi
    fi
  else
    AC_CHECK_HEADERS([$1/include/cblas.h $1/include/clapack.h],
		[acx_atlas_ok=yes])
    if test x$acx_atlas_ok = xyes; then
      AC_DEFINE_UNQUOTED(ATLAS_BLAS_H, "$1/include/cblas.h",
		[BLAS header filename.])
      AC_DEFINE_UNQUOTED(ATLAS_LAPACK_H, "$1/include/clapack.h",
		[CLAPACK header filename.])
    else
      AC_CHECK_HEADERS([cblas.h clapack.h],[acx_atlas_ok=yes])
      if test x$acx_atlas_ok = xyes; then
        AC_DEFINE_UNQUOTED(ATLAS_BLAS_H, "cblas.h",
		[BLAS header filename.])
        AC_DEFINE_UNQUOTED(ATLAS_LAPACK_H, "clapack.h",
		[CLAPACK header filename.])
      else
        ATLAS_ERROR="CBLAS/LAPack include files not found in $1/include!"
      fi
    fi
  fi
else
  AC_CHECK_HEADERS([$2/cblas.h $2/clapack.h], [acx_atlas_ok=yes])
  if test x$acx_atlas_ok = xyes; then
    AC_DEFINE_UNQUOTED(ATLAS_BLAS_H, "$2/cblas.h",
		[BLAS header filename.])
    AC_DEFINE_UNQUOTED(ATLAS_LAPACK_H, "$2/clapack.h",
		[CLAPACK header filename.])
  else
    ATLAS_ERROR="CBLAS/LAPack include files not found in $2!"
  fi
fi

dnl --------------------
dnl Search library files
dnl --------------------

if test x$acx_atlas_ok = xyes; then
  OLIBS="$LIBS"
  LIBS=""
  if test x$1 = x; then
    AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-lcblas -latlas -lm])
    AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-latlas -lm])
    if test x$acx_atlas_ok = xyes; then
      ATLAS_LIBPATH=""
    else
      atlas_def=/usr/local/atlas
      unset ac_cv_lib_lapack_clapack_dpotrf
      unset ac_cv_lib_cblas_cblas_dgemm
      acx_atlas_ok=yes
      AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-L$atlas_def/lib -lcblas -latlas -lm])
      AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-L$atlas_def/lib -latlas -lm])
      if test x$acx_atlas_ok = xyes; then
        ATLAS_LIBPATH="-L$atlas_def/lib"
      else
        atlas_def=/usr/lib64/atlas
        unset ac_cv_lib_lapack_clapack_dpotrf
        unset ac_cv_lib_cblas_cblas_dgemm
        acx_atlas_ok=yes
        AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-L$atlas_def -lcblas -latlas -lm])
        AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-L$atlas_def -latlas -lm])
        if test x$acx_atlas_ok = xyes; then
          ATLAS_LIBPATH="-L$atlas_def"
        else
          atlas_def=/usr/lib/atlas
          unset ac_cv_lib_lapack_clapack_dpotrf
          unset ac_cv_lib_cblas_cblas_dgemm
          acx_atlas_ok=yes
          AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-L$atlas_def -lcblas -latlas -lm])
          AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-L$atlas_def -latlas -lm])
          if test x$acx_atlas_ok = xyes; then
            ATLAS_LIBPATH="-L$atlas_def"
          else
            atlas_def=/usr/atlas
            unset ac_cv_lib_lapack_clapack_dpotrf
            unset ac_cv_lib_cblas_cblas_dgemm
            acx_atlas_ok=yes
            AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-L$atlas_def/lib -lcblas -latlas -lm])
            AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-L$atlas_def/lib -latlas -lm])
            if test x$acx_atlas_ok = xyes; then
              ATLAS_LIBPATH="-L$atlas_def/lib"
            else
              ATLAS_ERROR="CBLAS/LAPack library files not found at usual locations!"
            fi
          fi
        fi
      fi
    fi
  else
    AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-L$1 -lcblas -latlas -lm])
    AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-L$1 -latlas -lm])
    if test x$acx_atlas_ok = xyes; then
      ATLAS_LIBPATH="-L$1"
    else
      unset ac_cv_lib_lapack_clapack_dpotrf
      unset ac_cv_lib_cblas_cblas_dgemm
      acx_atlas_ok=yes
      AC_CHECK_LIB(lapack, [clapack_dpotrf],, [acx_atlas_ok=no],
		[-L$1/lib -lcblas -latlas -lm])
      AC_CHECK_LIB(cblas, cblas_dgemm,, [acx_atlas_ok=no],
		[-L$1/lib -latlas -lm])
      if test x$acx_atlas_ok = xyes; then
        ATLAS_LIBPATH="-L$1/lib"
      else
        ATLAS_ERROR="CBLAS/LAPack library files not found in $1!"
      fi
    fi
  fi
  LIBS="$OLIBS"
fi

AC_SUBST(ATLAS_LIBPATH)
AC_SUBST(ATLAS_CFLAGS)

dnl -------------------------------------------------------------------------
dnl Finally, check MP version and execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND
dnl -------------------------------------------------------------------------
if test x"$acx_atlas_ok" = xyes; then
  AC_DEFINE(HAVE_ATLAS,1,
	[Define if you have the ATLAS libraries and header files.])
  if test x$3 = xyes; then
dnl Check whether the multithreaded version of ATLAS is there too:
    AC_CHECK_LIB(ptcblas, cblas_dgemm,, [acx_atlas_ok=no],
	[$ATLAS_LIBPATH -lcblas -latlas -lm])
    if test x$acx_atlas_ok = xyes; then
      ATLAS_LIB="$ATLAS_LIBPATH -llapack -lptcblas -lcblas -latlas"
      LIBS="$OLIBS"
      AC_SUBST(ATLAS_LIB)
      AC_DEFINE(HAVE_ATLAS_MP,1,
	[Define if you have the parallel ATLAS libraries.])
      $4
    else
      ATLAS_ERROR="CBLAS/LAPack was compiled without multithreading support!"
      AC_SUBST(ATLAS_ERROR)
      $5         
    fi
  else
    ATLAS_LIB="$ATLAS_LIBPATH -llapack -lcblas -latlas"
    LIBS="$OLIBS"
    AC_SUBST(ATLAS_LIB)
    $4
  fi
else
  AC_SUBST(ATLAS_ERROR)
  $5
fi

])dnl ACX_ATLAS