1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(nlopt, 2.0.1, stevenj@alum.mit.edu)
3 AC_CONFIG_SRCDIR(api/nlopt.h)
4 SHARED_VERSION_INFO="3:1:3" # CURRENT:REVISION:AGE
7 AM_CONFIG_HEADER(config.h)
8 AC_CONFIG_MACRO_DIR([m4])
10 AC_SUBST(SHARED_VERSION_INFO)
11 AC_DISABLE_SHARED dnl shared libraries are a PITA, disable by default
13 dnl Checks for programs.
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)
28 if test "x$with_cxx" = xyes; then
29 AC_DEFINE([WITH_CXX], 1, [Define if compiled including C++-based routines])
34 AC_SUBST(NLOPT_SUFFIX)
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"
44 dnl Checks for typedefs, structures, and compiler characteristics.
47 AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
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
60 dnl Checks for libraries and functions
62 AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r getpid])
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.])
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.])
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.])
89 dnl -----------------------------------------------------------------------
91 if test "x$with_cxx" = xyes; then
92 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
94 AM_CONDITIONAL(WITH_NOCEDAL, test -n "$have_lbfgs")
95 if test -n "$have_lbfgs"; then
96 AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code])
99 dnl -----------------------------------------------------------------------
103 [AC_HELP_STRING([--without-guile], [don't compile Guile plugin])],
104 with_guile=$withval,with_guile=yes)
106 [AC_HELP_STRING([--without-python], [don't compile Python plugin])],
107 with_python=$withval,with_python=yes)
109 if test "$enable_shared" = no; then
110 AC_MSG_WARN([Python and Guile wrappers require --enable-shared; disabling])
115 if test "x$with_guile" = xno; then
120 AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown)
121 if test "x$GUILE_CONFIG" = "xunknown"; then
122 AC_MSG_WARN([can't find guile-config, disabling Guile wrapper])
124 save_CPPFLAGS=$CPPFLAGS
126 GUILE_CPPFLAGS=`$GUILE_CONFIG compile`
127 GUILE_LIBS=`$GUILE_CONFIG link`
128 CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS"
129 LIBS="$GUILE_LIBS $LIBS"
130 AC_MSG_CHECKING([if linking to guile works])
131 AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
132 AC_MSG_WARN(guile-config is broken, disabling Guile wrapper)
133 GUILE_CONFIG="unknown"])
134 CPPFLAGS=$save_CPPFLAGS
137 AC_CHECK_PROG(GUILE, guile, guile, unknown)
138 if test "x$GUILE" = xunknown; then
139 AC_MSG_WARN([can't find guile, disabling Guile wrapper])
142 AC_MSG_CHECKING([for Guile site installation directory])
143 GUILE_SITEDIR=`guile -c '(display (%site-dir))'`
144 AC_MSG_RESULT([$GUILE_SITEDIR])
149 if test "x$with_python" = xno; then
154 AM_PATH_PYTHON([],[have_python=yes],[have_python=no])
155 if test $have_python = yes; then
156 pdir=`dirname $pythondir | sed 's,/lib/,/include/,'`
157 pdir=`eval echo $pdir`
158 AC_MSG_CHECKING([for Python include directory])
159 for PYTHON_INCLUDE_DIR in "$pdir" /usr/include/python$PYTHON_VERSION /usr/local/include/python$PYTHON_VERSION unknown; do
160 test -d "$PYTHON_INCLUDE_DIR" && break
162 AC_MSG_RESULT([$PYTHON_INCLUDE_DIR])
163 if test "x$PYTHON_INCLUDE_DIR" = xunknown; then
164 AC_MSG_WARN([disabling Python wrappers])
167 save_CPPFLAGS=$CPPFLAGS
168 CPPFLAGS="$CPPFLAGS -I$PYTHON_INCLUDE_DIR"
169 AC_CHECK_HEADER([numpy/arrayobject.h],[],[
170 AC_MSG_WARN([disabling Python wrappers])
171 have_python=no],[#include <Python.h>])
172 CPPFLAGS=$save_CPPFLAGS
178 fi # if enable_shared
180 AC_SUBST(GUILE_SITEDIR)
181 AC_SUBST(GUILE_CPPFLAGS)
183 AC_SUBST(PYTHON_INCLUDE_DIR)
184 AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
185 AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes")
187 dnl -----------------------------------------------------------------------
188 dnl Compiling Octave plug-in
190 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
191 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
192 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
195 [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
196 with_octave=$withval,with_octave=yes)
198 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
200 if test x"$with_octave" = xno; then
202 elif test "$MKOCTFILE" = "echo"; then
203 AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
205 elif test x"$OCT_INSTALL_DIR" = "x"; then
206 # try to find installation directory
207 AC_CHECK_PROGS(OCTAVE, octave, echo)
208 AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
210 AC_MSG_CHECKING(where octave plugins go)
211 OCT_INSTALL_DIR=`octave-config --oct-site-dir 2> /dev/null | grep '/'`
212 if test -z "$OCT_INSTALL_DIR"; then
213 OCT_INSTALL_DIR=`octave-config --print OCTFILEDIR 2> /dev/null | grep '/'`
215 if test -z "$OCT_INSTALL_DIR"; then
216 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
218 if test -z "$OCT_INSTALL_DIR"; then
219 OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
221 if test -n "$OCT_INSTALL_DIR"; then
222 AC_MSG_RESULT($OCT_INSTALL_DIR)
224 AC_MSG_RESULT(unknown)
225 AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
228 AC_MSG_CHECKING(where octave scripts go)
229 M_INSTALL_DIR=`octave-config --m-site-dir 2> /dev/null | grep '/'`
230 if test -z "$M_INSTALL_DIR"; then
231 M_INSTALL_DIR=`octave-config --print FCNFILEDIR 2> /dev/null | grep '/'`
233 if test -z "$M_INSTALL_DIR"; then
234 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
236 if test -z "$M_INSTALL_DIR"; then
237 M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
239 if test -n "$M_INSTALL_DIR"; then
240 AC_MSG_RESULT($M_INSTALL_DIR)
242 AC_MSG_RESULT(unknown)
243 AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
248 if test x"$OCT_INSTALL_DIR" != "x"; then
249 if test "$enable_shared" = no; then
250 AC_MSG_CHECKING([whether mkoctfile can link with static objects])
252 echo 'void foo(void) {};' > conftestfoo.c
253 $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
254 cat > conftest.cc <<EOF
255 #include <octave/oct.h>
256 extern "C" void foo(void);
257 DEFUN_DLD(foobar, args, nargout, "foo bar") { foo(); }
259 if $MKOCTFILE conftest.cc conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
263 AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
269 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
270 AC_SUBST(OCT_INSTALL_DIR)
271 AC_SUBST(M_INSTALL_DIR)
274 dnl -----------------------------------------------------------------------
275 dnl Compiling Matlab plug-in
278 [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
279 with_matlab=$withval,with_matlab=yes)
281 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
282 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
283 AC_CHECK_PROGS(MEX, mex, echo)
284 if test x"$with_matlab" = xno; then
286 elif test "$MEX" = "echo"; then
287 AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
290 AC_MSG_CHECKING([for extension of compiled mex files])
292 cat > conftest.c <<EOF
294 void mexFunction(int nlhs, mxArray *plhs[[]],
295 int nrhs, const mxArray *prhs[[]]) { }
297 if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
298 MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
299 AC_MSG_RESULT($MEXSUFF)
300 AC_CHECK_PROGS(MATLAB, matlab, echo)
302 AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
307 if test x"$MATLAB" != xecho; then
308 if test "$enable_shared" = no; then
309 AC_MSG_CHECKING([whether mex can link with static objects])
311 echo 'void foo(void) {};' > conftestfoo.c
312 $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
313 cat > conftest.c <<EOF
315 extern void foo(void);
316 void mexFunction(int nlhs, mxArray *plhs[[]],
317 int nrhs, const mxArray *prhs[[]]) { foo(); }
319 if $MEX conftest.c conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
323 AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
330 if test x"$MATLAB" != xecho; then
331 # try to find installation directory
332 if test x"$MEX_INSTALL_DIR" = "x"; then
333 AC_MSG_CHECKING(for MATLAB mex installation dir)
334 MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
335 AC_MSG_RESULT($MEX_INSTALL_DIR)
336 if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
339 if test x"$MEX_INSTALL_DIR" = "x"; then
340 AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
347 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
348 AC_SUBST(MEX_INSTALL_DIR)
352 dnl -----------------------------------------------------------------------
353 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
355 AC_MSG_CHECKING([for working HUGE_VAL])
356 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;],
357 [AC_MSG_RESULT([ok])],
358 [AC_TRY_COMPILE([#include <math.h>
361 #define HUGE_VAL __builtin_huge_val()
362 #endif], [double x = -HUGE_VAL;],
363 [AC_MSG_RESULT([__builtin_huge_val()])
364 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
365 [replacement for broken HUGE_VAL macro, if needed])],
366 [AC_MSG_RESULT([unknown])
367 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
369 dnl -----------------------------------------------------------------------
372 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
373 if test "$ok" = "yes"; then
374 AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
377 dnl override CFLAGS selection when debugging
378 if test "${enable_debug}" = "yes"; then
384 dnl add gcc warnings, in debug/maintainer mode only
385 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
386 if test $ac_cv_prog_gcc = yes; then
387 if test "$ac_test_CFLAGS" != "set"; then
388 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"
390 if test "$ac_test_CXXFLAGS" != "set"; then
391 CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
393 if test "x$with_cxx" = xyes; then
399 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
400 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
401 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
402 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
403 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
404 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
406 dnl -----------------------------------------------------------------------