chiark / gitweb /
check for numpy
[nlopt.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(nlopt, 2.0, stevenj@alum.mit.edu)
3 AC_CONFIG_SRCDIR(api/nlopt.h)
4 SHARED_VERSION_INFO="3:0:3" # CURRENT:REVISION:AGE
5
6 AM_INIT_AUTOMAKE(1.7)
7 AM_CONFIG_HEADER(config.h)
8 AC_CONFIG_MACRO_DIR([m4])
9 AM_MAINTAINER_MODE
10 AC_SUBST(SHARED_VERSION_INFO)
11 AC_DISABLE_SHARED dnl shared libraries are a PITA, disable by default
12
13 dnl Checks for programs.
14 AC_PROG_CC
15 AC_PROG_CC_STDC
16 AC_PROG_INSTALL
17 AC_PROG_LN_S
18 AC_PROG_MAKE_SET
19 AC_LIBTOOL_WIN32_DLL
20 AC_PROG_LIBTOOL
21
22 NLOPT_SUFFIX=""
23 AC_ARG_WITH(cxx,
24         [AC_HELP_STRING([--with-cxx], [include C++-based routines])],
25         with_cxx=$withval,with_cxx=no)
26 AM_CONDITIONAL(WITH_CXX, test "x$with_cxx" = xyes)
27 AC_PROG_CXX
28 if test "x$with_cxx" = xyes; then
29    AC_DEFINE([WITH_CXX], 1, [Define if compiled including C++-based routines])
30    NLOPT_SUFFIX="_cxx"
31    CC=$CXX
32    CFLAGS=$CXXFLAGS
33 fi
34 AC_SUBST(NLOPT_SUFFIX)
35
36 dnl Checks for typedefs, structures, and compiler characteristics.
37 AC_HEADER_STDC
38 AC_HEADER_TIME
39 AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
40 AC_C_CONST
41 AC_C_INLINE
42 AX_C_THREADLOCAL
43
44 dnl find 32-bit unsigned integer type for random-number generator
45 AC_CHECK_SIZEOF(unsigned int)
46 AC_CHECK_SIZEOF(unsigned long)
47 AC_CHECK_TYPES(uint32_t, [], [], [$ac_includes_default
48 #ifdef HAVE_STDINT_H
49 #  include <stdint.h>
50 #endif])
51
52 dnl Checks for libraries and functions
53 AC_CHECK_LIB(m, sin)
54 AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r getpid])
55
56 AC_MSG_CHECKING([for gettid syscall])
57 AC_TRY_LINK([#include <unistd.h>
58 #include <sys/syscall.h>
59 ], [syscall(SYS_gettid);], [ok=yes], [ok=no])
60 if test "$ok" = "yes"; then
61         AC_DEFINE(HAVE_GETTID_SYSCALL,1,[Define if syscall(SYS_gettid) available.])
62 fi
63 AC_MSG_RESULT(${ok})
64
65 AC_MSG_CHECKING([for isnan])
66 AC_TRY_LINK([#include <math.h>
67 ], [if (!isnan(3.14159)) isnan(2.7183);], ok=yes, ok=no)
68 if test "$ok" = "yes"; then
69         AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.])
70 fi
71 AC_MSG_RESULT(${ok})
72
73 AC_MSG_CHECKING([for isinf])
74 AC_TRY_LINK([#include <math.h>
75 ], [if (!isinf(3.14159)) isinf(2.7183);], ok=yes, ok=no)
76 if test "$ok" = "yes"; then
77         AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.])
78 fi
79 AC_MSG_RESULT(${ok})
80
81 dnl -----------------------------------------------------------------------
82
83 if test "x$with_cxx" = xyes; then
84   test -r $srcdir/lbfgs/ap.cpp && test -r $srcdir/lbfgs/ap.h && test -r $srcdir/lbfgs/l-bfgs-b.cpp && test -r $srcdir/lbfgs/l-bfgs-b.h && have_lbfgs=yes
85 fi
86 AM_CONDITIONAL(WITH_NOCEDAL, test -n "$have_lbfgs")
87 if test -n "$have_lbfgs"; then
88    AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code])
89 fi
90
91 dnl -----------------------------------------------------------------------
92 dnl SWIG wrappers
93
94 if test "$enable_shared" = no; then
95    AC_MSG_WARN([Python and Guile wrappers require --enable-shared; disabling])
96 else
97
98 dnl Guile:
99 AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown)
100 if test "x$GUILE_CONFIG" = "xunknown"; then
101    AC_MSG_WARN([can't find guile-config, disabling Guile wrapper])
102 else
103    save_CPPFLAGS=$CPPFLAGS
104    save_LIBS=$LIBS
105    GUILE_CPPFLAGS=`$GUILE_CONFIG compile`
106    GUILE_LIBS=`$GUILE_CONFIG link`
107    CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS"
108    LIBS="$GUILE_LIBS $LIBS"
109    AC_MSG_CHECKING([if linking to guile works])
110    AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
111         AC_MSG_WARN(guile-config is broken, disabling Guile wrapper)
112         GUILE_CONFIG="unknown"])
113    CPPFLAGS=$save_CPPFLAGS
114    LIBS=$save_LIBS
115 fi
116 AC_CHECK_PROG(GUILE, guile, guile, unknown)
117 if test "x$GUILE" = xunknown; then
118    AC_MSG_WARN([can't find guile, disabling Guile wrapper])
119    GUILE_CONFIG=unknown
120 else
121    AC_MSG_CHECKING([for Guile site installation directory])
122    GUILE_SITEDIR=`guile -c '(display (%site-dir))'`
123    AC_MSG_RESULT([$GUILE_SITEDIR])
124 fi
125 AC_SUBST(GUILE_SITEDIR)
126 AC_SUBST(GUILE_CPPFLAGS)
127 AC_SUBST(GUILE_LIBS)
128 AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
129
130 dnl Python:
131 AM_PATH_PYTHON([],[have_python=yes],[have_python=no])
132 if test $have_python = yes; then
133   pdir=`dirname $pythondir | sed 's,/lib/,/include/,'`
134   pdir=`eval echo $pdir`
135   AC_MSG_CHECKING([for Python include directory])
136   for PYTHON_INCLUDE_DIR in "$pdir" /usr/include/python$PYTHON_VERSION /usr/local/include/python$PYTHON_VERSION unknown; do
137     test -d "$PYTHON_INCLUDE_DIR" && break
138   done
139   AC_MSG_RESULT([$PYTHON_INCLUDE_DIR])
140   if test "x$PYTHON_INCLUDE_DIR" = xunknown; then
141      AC_MSG_WARN([disabling Python wrappers])
142      have_python=no
143   else
144      save_CPPFLAGS=$CPPFLAGS
145      CPPFLAGS="$CPPFLAGS -I$PYTHON_INCLUDE_DIR"
146      AC_CHECK_HEADER([numpy/arrayobject.h],[],[
147           AC_MSG_WARN([disabling Python wrappers])
148           have_python=no],[#include <Python.h>])
149      CPPFLAGS=$save_CPPFLAGS
150   fi
151   AC_SUBST(PYTHON_INCLUDE_DIR)
152 fi
153 AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes")
154
155 fi
156
157 dnl -----------------------------------------------------------------------
158 dnl Compiling Octave plug-in
159
160 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
161 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
162 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
163
164 AC_ARG_WITH(octave,
165         [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
166         with_octave=$withval,with_octave=yes)
167
168 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
169
170 if test x"$with_octave" = xno; then
171         OCT_INSTALL_DIR=""
172 elif test "$MKOCTFILE" = "echo"; then
173         AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
174         OCT_INSTALL_DIR=""
175 elif test x"$OCT_INSTALL_DIR" = "x"; then
176         # try to find installation directory
177         AC_CHECK_PROGS(OCTAVE, octave, echo)
178         AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
179
180         AC_MSG_CHECKING(where octave plugins go)
181         OCT_INSTALL_DIR=`octave-config --oct-site-dir 2> /dev/null | grep '/'`
182         if test -z "$OCT_INSTALL_DIR"; then
183                 OCT_INSTALL_DIR=`octave-config --print OCTFILEDIR 2> /dev/null | grep '/'`
184         fi
185         if test -z "$OCT_INSTALL_DIR"; then
186                 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
187         fi
188         if test -z "$OCT_INSTALL_DIR"; then
189                 OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
190         fi
191         if test -n "$OCT_INSTALL_DIR"; then
192                 AC_MSG_RESULT($OCT_INSTALL_DIR)
193         else
194                 AC_MSG_RESULT(unknown)
195                 AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
196         fi
197
198         AC_MSG_CHECKING(where octave scripts go)
199         M_INSTALL_DIR=`octave-config --m-site-dir 2> /dev/null | grep '/'`
200         if test -z "$M_INSTALL_DIR"; then
201                 M_INSTALL_DIR=`octave-config --print FCNFILEDIR 2> /dev/null | grep '/'`
202         fi
203         if test -z "$M_INSTALL_DIR"; then
204                 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
205         fi
206         if test -z "$M_INSTALL_DIR"; then
207                 M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
208         fi
209         if test -n "$M_INSTALL_DIR"; then
210                 AC_MSG_RESULT($M_INSTALL_DIR)
211         else
212                 AC_MSG_RESULT(unknown)
213                 AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
214                 OCT_INSTALL_DIR=""
215         fi
216 fi
217
218 if test x"$OCT_INSTALL_DIR" != "x"; then
219 if test "$enable_shared" = no; then
220      AC_MSG_CHECKING([whether mkoctfile can link with static objects])
221      rm -f conftest*
222      echo 'void foo(void) {};' > conftestfoo.c
223      $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
224      cat > conftest.cc <<EOF
225 #include <octave/oct.h>
226 extern "C" void foo(void);
227 DEFUN_DLD(foobar, args, nargout, "foo bar") { foo(); }
228 EOF
229      if $MKOCTFILE conftest.cc conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
230         AC_MSG_RESULT(yes)
231      else
232         AC_MSG_RESULT(no)
233         AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
234         OCT_INSTALL_DIR=""
235      fi
236 fi
237 fi
238
239 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
240 AC_SUBST(OCT_INSTALL_DIR)
241 AC_SUBST(M_INSTALL_DIR)
242 AC_SUBST(MKOCTFILE)
243
244 dnl -----------------------------------------------------------------------
245 dnl Compiling Matlab plug-in
246
247 AC_ARG_WITH(matlab,
248         [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
249         with_matlab=$withval,with_matlab=yes)
250
251 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
252 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
253 AC_CHECK_PROGS(MEX, mex, echo)
254 if test x"$with_matlab" = xno; then
255      MEX_INSTALL_DIR=""
256 elif test "$MEX" = "echo"; then
257      AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
258      MEX_INSTALL_DIR=""
259 else
260      AC_MSG_CHECKING([for extension of compiled mex files])
261      rm -f conftest*
262      cat > conftest.c <<EOF
263 #include <mex.h>
264 void mexFunction(int nlhs, mxArray *plhs[[]],
265                  int nrhs, const mxArray *prhs[[]]) { }
266 EOF
267      if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
268         MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
269         AC_MSG_RESULT($MEXSUFF)
270         AC_CHECK_PROGS(MATLAB, matlab, echo)
271      else
272         AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
273         MEX_INSTALL_DIR=""
274         MATLAB=echo
275      fi
276
277      if test x"$MATLAB" != xecho; then
278      if test "$enable_shared" = no; then
279      AC_MSG_CHECKING([whether mex can link with static objects])
280      rm -f conftest*
281      echo 'void foo(void) {};' > conftestfoo.c
282      $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
283      cat > conftest.c <<EOF
284 #include <mex.h>
285 extern void foo(void);
286 void mexFunction(int nlhs, mxArray *plhs[[]],
287                  int nrhs, const mxArray *prhs[[]]) { foo(); }
288 EOF
289      if $MEX conftest.c conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
290         AC_MSG_RESULT(yes)
291      else
292         AC_MSG_RESULT(no)
293         AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
294         MEX_INSTALL_DIR=""
295         MATLAB=echo
296      fi
297      fi
298      fi
299
300      if test x"$MATLAB" != xecho; then
301        # try to find installation directory
302        if test x"$MEX_INSTALL_DIR" = "x"; then
303           AC_MSG_CHECKING(for MATLAB mex installation dir)
304           MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
305           AC_MSG_RESULT($MEX_INSTALL_DIR)
306           if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
307              MEX_INSTALL_DIR=""
308           fi
309           if test x"$MEX_INSTALL_DIR" = "x"; then
310             AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
311           fi
312        fi
313      else
314         MEX_INSTALL_DIR=""
315      fi
316 fi
317 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
318 AC_SUBST(MEX_INSTALL_DIR)
319 AC_SUBST(MEX)
320 AC_SUBST(MEXSUFF)
321
322 dnl -----------------------------------------------------------------------
323 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
324
325 AC_MSG_CHECKING([for working HUGE_VAL])
326 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;], 
327 [AC_MSG_RESULT([ok])],
328 [AC_TRY_COMPILE([#include <math.h>
329 #ifdef __GNUC__
330 #undef HUGE_VAL
331 #define HUGE_VAL __builtin_huge_val()
332 #endif], [double x = -HUGE_VAL;], 
333 [AC_MSG_RESULT([__builtin_huge_val()])
334 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
335           [replacement for broken HUGE_VAL macro, if needed])],
336 [AC_MSG_RESULT([unknown])
337 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
338
339 dnl -----------------------------------------------------------------------
340 dnl Debugging
341
342 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
343 if test "$ok" = "yes"; then
344         AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
345 fi
346
347 dnl override CFLAGS selection when debugging
348 if test "${enable_debug}" = "yes"; then
349         CFLAGS="-g"
350         CXXFLAGS="-g"
351         FFLAGS="-g"
352 fi
353
354 dnl add gcc warnings, in debug/maintainer mode only
355 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
356 if test $ac_cv_prog_gcc = yes; then
357    if test "$ac_test_CFLAGS" != "set"; then
358       CFLAGS="$CFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wbad-function-cast -Wwrite-strings -Wstrict-prototypes -Wredundant-decls -Wnested-externs -Wundef -Wconversion -Wmissing-prototypes -Wmissing-declarations"
359    fi
360    if test "$ac_test_CXXFLAGS" != "set"; then
361       CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
362    fi
363    if test "x$with_cxx" = xyes; then
364       CFLAGS=$CXXFLAGS
365    fi
366 fi
367 fi
368
369 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
370 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
371 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
372 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
373 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
374 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
375
376 dnl -----------------------------------------------------------------------
377
378 AC_CONFIG_FILES([
379    Makefile
380    nlopt.pc
381    api/Makefile
382    util/Makefile
383    octave/Makefile
384    direct/Makefile
385    cdirect/Makefile
386    stogo/Makefile
387    praxis/Makefile
388    lbfgs/Makefile
389    luksan/Makefile
390    crs/Makefile
391    mlsl/Makefile
392    mma/Makefile
393    cobyla/Makefile
394    newuoa/Makefile
395    neldermead/Makefile
396    auglag/Makefile
397    bobyqa/Makefile
398    isres/Makefile
399    test/Makefile
400    swig/Makefile
401    swig/nlopt.scm
402 ])
403
404 AC_OUTPUT