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
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)
36 dnl Checks for typedefs, structures, and compiler characteristics.
39 AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
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
52 dnl Checks for libraries and functions
54 AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r getpid])
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.])
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.])
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.])
81 dnl -----------------------------------------------------------------------
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
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])
91 dnl -----------------------------------------------------------------------
95 AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown)
96 if test "x$GUILE_CONFIG" = "xunknown"; then
97 AC_MSG_WARN([can't find guile-config, disabling Guile wrapper])
99 save_CPPFLAGS=$CPPFLAGS
101 GUILE_CPPFLAGS=`$GUILE_CONFIG compile`
102 GUILE_LIBS=`$GUILE_CONFIG link`
103 CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS"
104 LIBS="$GUILE_LIBS $LIBS"
105 AC_MSG_CHECKING([if linking to guile works])
106 AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
107 AC_MSG_WARN(guile-config is broken, disabling Guile wrapper)
108 GUILE_CONFIG="unknown"])
109 CPPFLAGS=$save_CPPFLAGS
112 AC_CHECK_PROG(GUILE, guile, guile, unknown)
113 if test "x$GUILE" = xunknown; then
114 AC_MSG_WARN([can't find guile, disabling Guile wrapper])
117 AC_MSG_CHECKING([for Guile site installation directory])
118 GUILE_SITEDIR=`guile -c '(display (%site-dir))'`
119 AC_MSG_RESULT([$GUILE_SITEDIR])
121 AC_SUBST(GUILE_SITEDIR)
122 AC_SUBST(GUILE_CPPFLAGS)
124 AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
127 AM_PATH_PYTHON([],[have_python=yes],[have_python=no])
128 if test $have_python = yes; then
129 pdir=`dirname $pythondir | sed 's,/lib/,/include/,'`
130 pdir=`eval echo $pdir`
131 AC_MSG_CHECKING([for Python include directory])
132 for PYTHON_INCLUDE_DIR in "$pdir" /usr/include/python$PYTHON_VERSION /usr/local/include/python$PYTHON_VERSION unknown; do
133 test -d "$PYTHON_INCLUDE_DIR" && break
135 AC_MSG_RESULT([$PYTHON_INCLUDE_DIR])
136 if test "x$PYTHON_INCLUDE_DIR" = xunknown; then
137 AC_MSG_WARN([disabling Python wrappers])
140 AC_SUBST(PYTHON_INCLUDE_DIR)
142 AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes")
144 dnl -----------------------------------------------------------------------
145 dnl Compiling Octave plug-in
147 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
148 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
149 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
152 [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
153 with_octave=$withval,with_octave=yes)
155 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
157 if test x"$with_octave" = xno; then
159 elif test "$MKOCTFILE" = "echo"; then
160 AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
162 elif test x"$OCT_INSTALL_DIR" = "x"; then
163 # try to find installation directory
164 AC_CHECK_PROGS(OCTAVE, octave, echo)
165 AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
167 AC_MSG_CHECKING(where octave plugins go)
168 OCT_INSTALL_DIR=`octave-config --oct-site-dir 2> /dev/null | grep '/'`
169 if test -z "$OCT_INSTALL_DIR"; then
170 OCT_INSTALL_DIR=`octave-config --print OCTFILEDIR 2> /dev/null | grep '/'`
172 if test -z "$OCT_INSTALL_DIR"; then
173 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
175 if test -z "$OCT_INSTALL_DIR"; then
176 OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
178 if test -n "$OCT_INSTALL_DIR"; then
179 AC_MSG_RESULT($OCT_INSTALL_DIR)
181 AC_MSG_RESULT(unknown)
182 AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
185 AC_MSG_CHECKING(where octave scripts go)
186 M_INSTALL_DIR=`octave-config --m-site-dir 2> /dev/null | grep '/'`
187 if test -z "$M_INSTALL_DIR"; then
188 M_INSTALL_DIR=`octave-config --print FCNFILEDIR 2> /dev/null | grep '/'`
190 if test -z "$M_INSTALL_DIR"; then
191 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
193 if test -z "$M_INSTALL_DIR"; then
194 M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
196 if test -n "$M_INSTALL_DIR"; then
197 AC_MSG_RESULT($M_INSTALL_DIR)
199 AC_MSG_RESULT(unknown)
200 AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
205 if test x"$OCT_INSTALL_DIR" != "x"; then
206 if test "$enable_shared" = no; then
207 AC_MSG_CHECKING([whether mkoctfile can link with static objects])
209 echo 'void foo(void) {};' > conftestfoo.c
210 $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
211 cat > conftest.cc <<EOF
212 #include <octave/oct.h>
213 extern "C" void foo(void);
214 DEFUN_DLD(foobar, args, nargout, "foo bar") { foo(); }
216 if $MKOCTFILE conftest.cc conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
220 AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
226 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
227 AC_SUBST(OCT_INSTALL_DIR)
228 AC_SUBST(M_INSTALL_DIR)
231 dnl -----------------------------------------------------------------------
232 dnl Compiling Matlab plug-in
235 [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
236 with_matlab=$withval,with_matlab=yes)
238 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
239 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
240 AC_CHECK_PROGS(MEX, mex, echo)
241 if test x"$with_matlab" = xno; then
243 elif test "$MEX" = "echo"; then
244 AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
247 AC_MSG_CHECKING([for extension of compiled mex files])
249 cat > conftest.c <<EOF
251 void mexFunction(int nlhs, mxArray *plhs[[]],
252 int nrhs, const mxArray *prhs[[]]) { }
254 if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
255 MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
256 AC_MSG_RESULT($MEXSUFF)
257 AC_CHECK_PROGS(MATLAB, matlab, echo)
259 AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
264 if test x"$MATLAB" != xecho; then
265 if test "$enable_shared" = no; then
266 AC_MSG_CHECKING([whether mex can link with static objects])
268 echo 'void foo(void) {};' > conftestfoo.c
269 $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
270 cat > conftest.c <<EOF
272 extern void foo(void);
273 void mexFunction(int nlhs, mxArray *plhs[[]],
274 int nrhs, const mxArray *prhs[[]]) { foo(); }
276 if $MEX conftest.c conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
280 AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
287 if test x"$MATLAB" != xecho; then
288 # try to find installation directory
289 if test x"$MEX_INSTALL_DIR" = "x"; then
290 AC_MSG_CHECKING(for MATLAB mex installation dir)
291 MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
292 AC_MSG_RESULT($MEX_INSTALL_DIR)
293 if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
296 if test x"$MEX_INSTALL_DIR" = "x"; then
297 AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
304 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
305 AC_SUBST(MEX_INSTALL_DIR)
309 dnl -----------------------------------------------------------------------
310 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
312 AC_MSG_CHECKING([for working HUGE_VAL])
313 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;],
314 [AC_MSG_RESULT([ok])],
315 [AC_TRY_COMPILE([#include <math.h>
318 #define HUGE_VAL __builtin_huge_val()
319 #endif], [double x = -HUGE_VAL;],
320 [AC_MSG_RESULT([__builtin_huge_val()])
321 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
322 [replacement for broken HUGE_VAL macro, if needed])],
323 [AC_MSG_RESULT([unknown])
324 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
326 dnl -----------------------------------------------------------------------
329 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
330 if test "$ok" = "yes"; then
331 AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
334 dnl override CFLAGS selection when debugging
335 if test "${enable_debug}" = "yes"; then
341 dnl add gcc warnings, in debug/maintainer mode only
342 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
343 if test $ac_cv_prog_gcc = yes; then
344 if test "$ac_test_CFLAGS" != "set"; then
345 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"
347 if test "$ac_test_CXXFLAGS" != "set"; then
348 CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
350 if test "x$with_cxx" = xyes; then
356 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
357 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
358 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
359 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
360 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
361 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
363 dnl -----------------------------------------------------------------------