1# Check for ATLAS
2# Zhuliang Chen, 2004-07
3# Pascal Giorgi , 2003-03-04
4# Inspired by gnome-bonobo-check.m4 by Miguel de Icaza, 99-04-12
5# Stolen from Chris Lahey       99-2-5
6# stolen from Manish Singh again
7# stolen back from Frank Belew
8# stolen from Manish Singh
9# Shamelessly stolen from Owen Taylor
10
11dnl IML_CHECK_ATLAS ([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
12dnl
13dnl Test for ATLAS and define ATLAS_CFLAGS and ATLAS_LIBS
14
15AC_DEFUN([IML_CHECK_ATLAS],
16[
17
18AC_ARG_WITH(atlas-include,
19	     [  --with-atlas-include=<path>
20		Specify the path of ATLAS header cblas.h
21		If argument is <empty> that means the header is reachable
22            	with the default search path: /usr/include or /usr/local/include
23		or other path you add as default path using --with-default.
24		Otherwise you give the <path> to the directory which contains
25		the ATLAS header cblas.h.
26	      ],
27	      [
28		ATLAS_INPUT_HEADER=$withval
29		ATLAS_HEADER_PATH="${ATLAS_INPUT_HEADER}"
30		for ATLAS_HOME in ${DEFAULT_CHECKING_PATH}
31		do
32			ATLAS_HEADER_PATH="${ATLAS_HEADER_PATH} ${ATLAS_HOME}/include"
33		done
34	      ],
35	      [
36		for ATLAS_HOME in ${DEFAULT_CHECKING_PATH}
37		do
38			ATLAS_HEADER_PATH="${ATLAS_HEADER_PATH} ${ATLAS_HOME}/include"
39		done
40	    ])
41
42AC_ARG_WITH(atlas-lib,
43	    [  --with-atlas-lib=<path>
44		Specify the path of ATLAS library.
45	        If argument is <empty> that means the header is reachable
46                with the default search path: /usr/include or /usr/local/include
47		or path you add as default path using --with-default.
48		Otherwise you give the <path> to the directory which contains
49		the ATLAS library.
50	     ],
51	     [
52		ATLAS_INPUT_LIB=$withval
53		ATLAS_LIBRARY_PATH="${ATLAS_INPUT_LIB}"
54		for ATLAS_HOME in ${DEFAULT_CHECKING_PATH}
55		do
56			ATLAS_LIBRARY_PATH="${ATLAS_LIBRARY_PATH} ${ATLAS_HOME}/lib"
57		done
58	     ],
59	     [
60		for ATLAS_HOME in ${DEFAULT_CHECKING_PATH}
61		do
62			ATLAS_LIBRARY_PATH="${ATLAS_LIBRARY_PATH} ${ATLAS_HOME}/lib"
63		done
64	    ])
65
66
67dnl input data check
68if test  "x${ATLAS_INPUT_HEADER}" != x; then
69	if test -z "${ATLAS_INPUT_LIB}"; then
70		echo 'error: since you have specified the ATLAS header path, you must specify the'
71		echo 'ATLAS library path using --with-atlas-lib.'
72		exit 1
73	fi
74fi
75
76if test "x${ATLAS_INPUT_LIB}" != x; then
77	if test -z "${ATLAS_INPUT_HEADER}"; then
78		echo 'error: since you have specified the ATLAS library path, you must specify the'
79		echo 'ATLAS header path using --with-atlas-include.'
80		exit 1
81	fi
82fi
83
84
85min_atlas_version=ifelse([$1], ,3.0,$1)
86
87dnl Check for existence
88
89BACKUP_CFLAGS=${CFLAGS}
90BACKUP_LIBS=${LIBS}
91
92AC_MSG_CHECKING(for ATLAS >= ${min_atlas_version})
93
94atlas_found="no"
95
96for ATLAS_HEADER in ${ATLAS_HEADER_PATH}
97do
98	if test -r "${ATLAS_HEADER}/cblas.h"; then
99		if test "x${ATLAS_HEADER}" != "x/usr/include" -a "x${ATLAS_HEADER}" != "x/usr/local/include"; then
100			for ATLAS_LIBRARY in ${ATLAS_LIBRARY_PATH}
101			do
102				if test "x${ATLAS_LIBRARY}" != "x/usr/lib" -a "x${ATLAS_LIBRARY}" != "x/usr/local/lib"; then
103					ATLAS_CFLAGS="-I${ATLAS_HEADER}"
104					ATLAS_LIBS="${ATLAS_LIBS} -L${ATLAS_LIBRARY} -lcblas -latlas"
105				fi
106			done
107		else
108			ATLAS_CFLAGS=
109			ATLAS_LIBS="-lcblas -latlas"
110		fi
111
112		CFLAGS="${BACKUP_CFLAGS} ${ATLAS_CFLAGS} ${GMP_CFLAGS}"
113		LIBS="${BACKUP_LIBS} ${ATLAS_LIBS} ${GMP_LIBS}"
114
115		AC_TRY_LINK(
116		[#include <cblas.h>],
117		[double a;],
118		[
119			   atlas_found="yes"
120			   break
121		],
122		[
123		   unset ATLAS_CFLAGS
124		   unset ATLAS_LIBS
125		   ifelse([$3], , :, [$3])
126		])
127	fi
128done
129
130if test "x$atlas_found" = "xyes" ; then
131	AC_SUBST(ATLAS_CFLAGS)
132	AC_SUBST(ATLAS_LIBS)
133	AC_DEFINE(HAVE_ATLAS,1,[Define if ATLAS is installed])
134	AC_DEFINE(BLAS_AVAILABLE,,[Define if BLAS routines are available])
135	HAVE_ATLAS=yes
136	if test "x$atlas_cross" != "xyes"; then
137		AC_MSG_RESULT(found)
138	else
139		AC_MSG_RESULT(unknown)
140		echo 'WARNING: You appear to be cross compiling, so there is'
141		echo 'no way to determine whether your ATLAS version is new'
142		echo 'enough. I am assuming it is.'
143	fi
144	ifelse([$2], , :, [$2])
145elif test -n "$atlas_problem"; then
146	AC_MSG_RESULT(problem, your ATLAS version is too old. Disabling.)
147	ifelse([$3], , :, [$3])
148elif test "x$atlas_found" = "xno" ; then
149	AC_MSG_RESULT(not found)
150	ifelse([$3], , :, [$3])
151fi
152
153CFLAGS=${BACKUP_CFLAGS}
154LIBS=${BACKUP_LIBS}
155#unset LD_LIBRARY_PATH
156
157])
158
159
160