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