chiark / gitweb /
use thread-local storage for Mersenne twister to make thread-safe (for compilers...
[nlopt.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(nlopt, 1.3, 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 to hell with shared libraries
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 AC_ARG_WITH(windows-f77-mangling, [AC_HELP_STRING([--with-windows-f77-mangling],[use common Win32 Fortran interface styles])], with_windows_f77_mangling=$withval, with_windows_f77_mangling=no)
37 if test "$with_windows_f77_mangling" = "yes"; then
38         AC_DEFINE(WINDOWS_F77_MANGLING,1,[Use common Windows Fortran mangling styles for the Fortran interfaces.])
39 fi
40
41 dnl Checks for typedefs, structures, and compiler characteristics.
42 AC_HEADER_STDC
43 AC_HEADER_TIME
44 AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
45 AC_C_CONST
46 AC_C_INLINE
47 AX_C_THREADLOCAL
48
49 dnl find 32-bit unsigned integer type for random-number generator
50 AC_CHECK_SIZEOF(unsigned int)
51 AC_CHECK_SIZEOF(unsigned long)
52 AC_CHECK_TYPES(uint32_t, [], [], [$ac_includes_default
53 #ifdef HAVE_STDINT_H
54 #  include <stdint.h>
55 #endif])
56
57 dnl Checks for libraries and functions
58 AC_CHECK_LIB(m, sin)
59 AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r])
60
61 AC_MSG_CHECKING([for isnan])
62 AC_TRY_LINK([#include <math.h>
63 ], if (!isnan(3.14159)) isnan(2.7183);, ok=yes, ok=no)
64 if test "$ok" = "yes"; then
65         AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.])
66 fi
67 AC_MSG_RESULT(${ok})
68
69 AC_MSG_CHECKING([for isinf])
70 AC_TRY_LINK([#include <math.h>
71 ], if (!isinf(3.14159)) isinf(2.7183);, ok=yes, ok=no)
72 if test "$ok" = "yes"; then
73         AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.])
74 fi
75 AC_MSG_RESULT(${ok})
76
77 dnl -----------------------------------------------------------------------
78
79 if test "x$with_cxx" = xyes; then
80   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
81 fi
82 AM_CONDITIONAL(WITH_NOCEDAL, test -n "$have_lbfgs")
83 if test -n "$have_lbfgs"; then
84    AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code])
85 fi
86
87 dnl -----------------------------------------------------------------------
88 dnl Compiling Octave plug-in
89
90 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
91 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
92 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
93
94 AC_ARG_WITH(octave,
95         [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
96         with_octave=$withval,with_octave=yes)
97
98 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
99
100 if test x"$with_octave" = xno; then
101         OCT_INSTALL_DIR=""
102 elif test "$MKOCTFILE" = "echo"; then
103         AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
104         OCT_INSTALL_DIR=""
105 elif test x"$OCT_INSTALL_DIR" = "x"; then
106         # try to find installation directory
107         AC_CHECK_PROGS(OCTAVE, octave, echo)
108         AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
109
110         AC_MSG_CHECKING(where octave plugins go)
111         OCT_INSTALL_DIR=`octave-config --oct-site-dir 2> /dev/null | grep '/'`
112         if test -z "$OCT_INSTALL_DIR"; then
113                 OCT_INSTALL_DIR=`octave-config --print OCTFILEDIR 2> /dev/null | grep '/'`
114         fi
115         if test -z "$OCT_INSTALL_DIR"; then
116                 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
117         fi
118         if test -z "$OCT_INSTALL_DIR"; then
119                 OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
120         fi
121         if test -n "$OCT_INSTALL_DIR"; then
122                 AC_MSG_RESULT($OCT_INSTALL_DIR)
123         else
124                 AC_MSG_RESULT(unknown)
125                 AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
126         fi
127
128         AC_MSG_CHECKING(where octave scripts go)
129         M_INSTALL_DIR=`octave-config --m-site-dir 2> /dev/null | grep '/'`
130         if test -z "$M_INSTALL_DIR"; then
131                 M_INSTALL_DIR=`octave-config --print FCNFILEDIR 2> /dev/null | grep '/'`
132         fi
133         if test -z "$M_INSTALL_DIR"; then
134                 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
135         fi
136         if test -z "$M_INSTALL_DIR"; then
137                 M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
138         fi
139         if test -n "$M_INSTALL_DIR"; then
140                 AC_MSG_RESULT($M_INSTALL_DIR)
141         else
142                 AC_MSG_RESULT(unknown)
143                 AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
144                 OCT_INSTALL_DIR=""
145         fi
146 fi
147
148 if test x"$OCT_INSTALL_DIR" != "x"; then
149 if test "$enable_shared" = no; then
150      AC_MSG_CHECKING([whether mkoctfile can link with static objects])
151      rm -f conftest*
152      echo 'void foo(void) {};' > conftestfoo.c
153      $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
154      cat > conftest.cc <<EOF
155 #include <octave/oct.h>
156 extern "C" void foo(void);
157 DEFUN_DLD(foobar, args, nargout, "foo bar") { foo(); }
158 EOF
159      if $MKOCTFILE conftest.cc conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
160         AC_MSG_RESULT(yes)
161      else
162         AC_MSG_RESULT(no)
163         AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
164         OCT_INSTALL_DIR=""
165      fi
166 fi
167 fi
168
169 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
170 AC_SUBST(OCT_INSTALL_DIR)
171 AC_SUBST(M_INSTALL_DIR)
172 AC_SUBST(MKOCTFILE)
173
174 dnl -----------------------------------------------------------------------
175 dnl Compiling Matlab plug-in
176
177 AC_ARG_WITH(matlab,
178         [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
179         with_matlab=$withval,with_matlab=yes)
180
181 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
182 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
183 AC_CHECK_PROGS(MEX, mex, echo)
184 if test x"$with_matlab" = xno; then
185      MEX_INSTALL_DIR=""
186 elif test "$MEX" = "echo"; then
187      AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
188      MEX_INSTALL_DIR=""
189 else
190      AC_MSG_CHECKING([for extension of compiled mex files])
191      rm -f conftest*
192      cat > conftest.c <<EOF
193 #include <mex.h>
194 void mexFunction(int nlhs, mxArray *plhs[[]],
195                  int nrhs, const mxArray *prhs[[]]) { }
196 EOF
197      if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
198         MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
199         AC_MSG_RESULT($MEXSUFF)
200         AC_CHECK_PROGS(MATLAB, matlab, echo)
201      else
202         AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
203         MEX_INSTALL_DIR=""
204         MATLAB=echo
205      fi
206
207      if test x"$MATLAB" != xecho; then
208      if test "$enable_shared" = no; then
209      AC_MSG_CHECKING([whether mex can link with static objects])
210      rm -f conftest*
211      echo 'void foo(void) {};' > conftestfoo.c
212      $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
213      cat > conftest.c <<EOF
214 #include <mex.h>
215 extern void foo(void);
216 void mexFunction(int nlhs, mxArray *plhs[[]],
217                  int nrhs, const mxArray *prhs[[]]) { foo(); }
218 EOF
219      if $MEX conftest.c conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
220         AC_MSG_RESULT(yes)
221      else
222         AC_MSG_RESULT(no)
223         AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
224         MEX_INSTALL_DIR=""
225         MATLAB=echo
226      fi
227      fi
228      fi
229
230      if test x"$MATLAB" != xecho; then
231        # try to find installation directory
232        if test x"$MEX_INSTALL_DIR" = "x"; then
233           AC_MSG_CHECKING(for MATLAB mex installation dir)
234           MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
235           AC_MSG_RESULT($MEX_INSTALL_DIR)
236           if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
237              MEX_INSTALL_DIR=""
238           fi
239           if test x"$MEX_INSTALL_DIR" = "x"; then
240             AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
241           fi
242        fi
243      else
244         MEX_INSTALL_DIR=""
245      fi
246 fi
247 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
248 AC_SUBST(MEX_INSTALL_DIR)
249 AC_SUBST(MEX)
250 AC_SUBST(MEXSUFF)
251
252 dnl -----------------------------------------------------------------------
253 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
254
255 AC_MSG_CHECKING([for working HUGE_VAL])
256 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;], 
257 [AC_MSG_RESULT([ok])],
258 [AC_TRY_COMPILE([#include <math.h>
259 #ifdef __GNUC__
260 #undef HUGE_VAL
261 #define HUGE_VAL __builtin_huge_val()
262 #endif], [double x = -HUGE_VAL;], 
263 [AC_MSG_RESULT([__builtin_huge_val()])
264 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
265           [replacement for broken HUGE_VAL macro, if needed])],
266 [AC_MSG_RESULT([unknown])
267 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
268
269 dnl -----------------------------------------------------------------------
270 dnl Debugging
271
272 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
273 if test "$ok" = "yes"; then
274         AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
275 fi
276
277 dnl override CFLAGS selection when debugging
278 if test "${enable_debug}" = "yes"; then
279         CFLAGS="-g"
280         CXXFLAGS="-g"
281         FFLAGS="-g"
282 fi
283
284 dnl add gcc warnings, in debug/maintainer mode only
285 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
286 if test $ac_cv_prog_gcc = yes; then
287    if test "$ac_test_CFLAGS" != "set"; then
288       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"
289    fi
290    if test "$ac_test_CXXFLAGS" != "set"; then
291       CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
292    fi
293    if test "x$with_cxx" = xyes; then
294       CFLAGS=$CXXFLAGS
295    fi
296 fi
297 fi
298
299 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
300 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
301 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
302 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
303 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
304 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
305
306 dnl -----------------------------------------------------------------------
307
308 AC_CONFIG_FILES([
309    Makefile
310    nlopt.pc
311    api/Makefile
312    util/Makefile
313    octave/Makefile
314    direct/Makefile
315    cdirect/Makefile
316    stogo/Makefile
317    praxis/Makefile
318    lbfgs/Makefile
319    luksan/Makefile
320    crs/Makefile
321    mlsl/Makefile
322    mma/Makefile
323    cobyla/Makefile
324    newuoa/Makefile
325    neldermead/Makefile
326    auglag/Makefile
327    bobyqa/Makefile
328    isres/Makefile
329    test/Makefile
330 ])
331
332 AC_OUTPUT