1dnl Check for FFTW3
2
3FFTW_CFLAGS=
4FFTW_LIBS=
5
6AC_ARG_WITH(fftw,[  --with-fftw=PFX   Prefix where fftw is installed (optional)], fftw_prefix="$withval", fftw_prefix="")
7AC_ARG_WITH(fftw-libraries,[  --with-fftw-libraries=DIR   Directory where fftw library is installed (optional)], fftw_libraries="$withval", fftw_libraries="")
8AC_ARG_WITH(fftw-includes,[  --with-fftw-includes=DIR   Directory where fftw header files are installed (optional)], fftw_includes="$withval", fftw_includes="")
9AC_ARG_ENABLE(fftwtest, [  --disable-fftwtest       Do not try to compile and run a test fftw program],, enable_fftwtest=yes)
10
11  if test "x$fftw_libraries" != "x" ; then
12    FFTW_LIBS="-L$fftw_libraries"
13  elif test "x$fftw_prefix" != "x" ; then
14    FFTW_LIBS="-L$fftw_prefix/lib"
15  elif test "x$prefix" != "xNONE"; then
16    FFTW_LIBS="-L$prefix/lib"
17  fi
18
19if test `uname` = Darwin; then
20  FFTW_LIBS="$FFTW_LIBS -lfftw3"
21else
22  FFTW_LIBS="$FFTW_LIBS -lfftw3f"
23fi
24
25  if test "x$fftw_includes" != "x" ; then
26    FFTW_CFLAGS="-I$fftw_includes"
27  elif test "x$fftw_prefix" != "x" ; then
28    FFTW_CFLAGS="-I$fftw_prefix/include"
29  elif test "x$prefix" != "xNONE"; then
30    FFTW_CFLAGS="-I$prefix/include -I/usr/include"
31  fi
32
33  AC_MSG_CHECKING(for FFTW)
34  no_fftw=""
35
36  if test "x$enable_fftwtest" = "xyes" ; then
37    ac_save_CFLAGS="$CFLAGS"
38    ac_save_LIBS="$LIBS"
39    CFLAGS="$CFLAGS $FFTW_CFLAGS"
40    LIBS="$LIBS $FFTW_LIBS"
41dnl
42dnl Now check if the installed fftw is sufficiently new.
43dnl
44      rm -f conf.fftwtest
45      AC_TRY_RUN([
46#include <stdio.h>
47#include <stdlib.h>
48#include <string.h>
49#include <fftw3.h>
50
51#ifdef FFTW_USE_DOUBLE
52#define FFT_COMPLEX_TYPE fftw_complex
53#define FFT_REAL_TYPE double
54#define FFT_PLAN_TYPE fftw_plan
55#define FFT_CREATE_PLAN fftw_plan_dft_c2r_2d
56#define FFT_DELETE_PLAN fftw_destroy_plan
57#define FFT_EXECUTE_PLAN fftw_execute
58#else
59#define FFT_COMPLEX_TYPE fftwf_complex
60#define FFT_REAL_TYPE float
61#define FFT_PLAN_TYPE fftwf_plan
62#define FFT_CREATE_PLAN fftwf_plan_dft_c2r_2d
63#define FFT_DELETE_PLAN fftwf_destroy_plan
64#define FFT_EXECUTE_PLAN fftwf_execute
65#endif
66
67#define N 10
68
69int main ()
70{
71        FFT_COMPLEX_TYPE fft_in[N*(N/2+1)];
72        FFT_REAL_TYPE fft_out[N*N];
73        FFT_PLAN_TYPE plan;
74
75        plan = FFT_CREATE_PLAN(N, N, fft_in, fft_out, 0);
76
77
78    system("touch conf.fftwtest");
79    return 0;
80}
81
82],, no_fftw=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
83       CFLAGS="$ac_save_CFLAGS"
84       LIBS="$ac_save_LIBS"
85  fi
86
87  if test "x$no_fftw" = "x" ; then
88     AC_MSG_RESULT(yes)
89  else
90     AC_MSG_RESULT(no)
91     if test -f conf.fftwtest ; then
92       :
93     else
94       echo "*** Could not run FFTW test program, checking why..."
95       CFLAGS="$CFLAGS $FFTW_CFLAGS"
96       LIBS="$LIBS $FFTW_LIBS"
97       AC_TRY_LINK([
98#include <stdio.h>
99#include <fftw3.h>
100],     [ return 0; ],
101       [ echo "*** The test program compiled, but did not run. This usually means"
102       echo "*** that the run-time linker is not finding FFTW or finding the wrong"
103       echo "*** version of FFTW. If it is not finding FFTW, you'll need to set your"
104       echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
105       echo "*** to the installed location  Also, make sure you have run ldconfig if that"
106       echo "*** is required on your system"
107       echo "***"
108       echo "*** If you have an old version installed, it is best to remove it, although"
109       echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
110       [ echo "*** The test program failed to compile or link. See the file config.log for the"
111       echo "*** exact error that occured. This usually means FFTW was incorrectly installed"
112       echo "*** or that you have moved FFTW since it was installed." ])
113       CFLAGS="$ac_save_CFLAGS"
114       LIBS="$ac_save_LIBS"
115     fi
116     FFTW_CFLAGS=""
117     FFTW_LIBS=""
118
119            AC_MSG_ERROR([
120                FFTW must be installed on your system but couldn't be found.
121                Please check that FFTW is installed.
122                FFTW version 3 is required.
123        ])
124
125
126  fi
127  rm -f conf.fftwtest
128
129
130AC_SUBST(FFTW_CFLAGS)
131AC_SUBST(FFTW_LIBS)
132