chiark / gitweb /
version bump
[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 dnl Guile:
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])
98 else
99    save_CPPFLAGS=$CPPFLAGS
100    save_LIBS=$LIBS
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
110    LIBS=$save_LIBS
111 fi
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])
115    GUILE_CONFIG=unknown
116 else
117    AC_MSG_CHECKING([for Guile site installation directory])
118    GUILE_SITEDIR=`guile -c '(display (%site-dir))'`
119    AC_MSG_RESULT([$GUILE_SITEDIR])
120 fi
121 AC_SUBST(GUILE_SITEDIR)
122 AC_SUBST(GUILE_CPPFLAGS)
123 AC_SUBST(GUILE_LIBS)
124 AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
125
126 dnl Python:
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
134   done
135   AC_MSG_RESULT([$PYTHON_INCLUDE_DIR])
136   if test "x$PYTHON_INCLUDE_DIR" = xunknown; then
137      AC_MSG_WARN([disabling Python wrappers])
138      have_python=no
139   fi
140   AC_SUBST(PYTHON_INCLUDE_DIR)
141 fi
142 AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes")
143
144 dnl -----------------------------------------------------------------------
145 dnl Compiling Octave plug-in
146
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])
150
151 AC_ARG_WITH(octave,
152         [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
153         with_octave=$withval,with_octave=yes)
154
155 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
156
157 if test x"$with_octave" = xno; then
158         OCT_INSTALL_DIR=""
159 elif test "$MKOCTFILE" = "echo"; then
160         AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
161         OCT_INSTALL_DIR=""
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)
166
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 '/'`
171         fi
172         if test -z "$OCT_INSTALL_DIR"; then
173                 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
174         fi
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`
177         fi
178         if test -n "$OCT_INSTALL_DIR"; then
179                 AC_MSG_RESULT($OCT_INSTALL_DIR)
180         else
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])
183         fi
184
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 '/'`
189         fi
190         if test -z "$M_INSTALL_DIR"; then
191                 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
192         fi
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`
195         fi
196         if test -n "$M_INSTALL_DIR"; then
197                 AC_MSG_RESULT($M_INSTALL_DIR)
198         else
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])
201                 OCT_INSTALL_DIR=""
202         fi
203 fi
204
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])
208      rm -f conftest*
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(); }
215 EOF
216      if $MKOCTFILE conftest.cc conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
217         AC_MSG_RESULT(yes)
218      else
219         AC_MSG_RESULT(no)
220         AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
221         OCT_INSTALL_DIR=""
222      fi
223 fi
224 fi
225
226 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
227 AC_SUBST(OCT_INSTALL_DIR)
228 AC_SUBST(M_INSTALL_DIR)
229 AC_SUBST(MKOCTFILE)
230
231 dnl -----------------------------------------------------------------------
232 dnl Compiling Matlab plug-in
233
234 AC_ARG_WITH(matlab,
235         [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
236         with_matlab=$withval,with_matlab=yes)
237
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
242      MEX_INSTALL_DIR=""
243 elif test "$MEX" = "echo"; then
244      AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
245      MEX_INSTALL_DIR=""
246 else
247      AC_MSG_CHECKING([for extension of compiled mex files])
248      rm -f conftest*
249      cat > conftest.c <<EOF
250 #include <mex.h>
251 void mexFunction(int nlhs, mxArray *plhs[[]],
252                  int nrhs, const mxArray *prhs[[]]) { }
253 EOF
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)
258      else
259         AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
260         MEX_INSTALL_DIR=""
261         MATLAB=echo
262      fi
263
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])
267      rm -f conftest*
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
271 #include <mex.h>
272 extern void foo(void);
273 void mexFunction(int nlhs, mxArray *plhs[[]],
274                  int nrhs, const mxArray *prhs[[]]) { foo(); }
275 EOF
276      if $MEX conftest.c conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
277         AC_MSG_RESULT(yes)
278      else
279         AC_MSG_RESULT(no)
280         AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
281         MEX_INSTALL_DIR=""
282         MATLAB=echo
283      fi
284      fi
285      fi
286
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
294              MEX_INSTALL_DIR=""
295           fi
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])
298           fi
299        fi
300      else
301         MEX_INSTALL_DIR=""
302      fi
303 fi
304 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
305 AC_SUBST(MEX_INSTALL_DIR)
306 AC_SUBST(MEX)
307 AC_SUBST(MEXSUFF)
308
309 dnl -----------------------------------------------------------------------
310 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
311
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>
316 #ifdef __GNUC__
317 #undef HUGE_VAL
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])])])
325
326 dnl -----------------------------------------------------------------------
327 dnl Debugging
328
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.])
332 fi
333
334 dnl override CFLAGS selection when debugging
335 if test "${enable_debug}" = "yes"; then
336         CFLAGS="-g"
337         CXXFLAGS="-g"
338         FFLAGS="-g"
339 fi
340
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"
346    fi
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"
349    fi
350    if test "x$with_cxx" = xyes; then
351       CFLAGS=$CXXFLAGS
352    fi
353 fi
354 fi
355
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.])
362
363 dnl -----------------------------------------------------------------------
364
365 AC_CONFIG_FILES([
366    Makefile
367    nlopt.pc
368    api/Makefile
369    util/Makefile
370    octave/Makefile
371    direct/Makefile
372    cdirect/Makefile
373    stogo/Makefile
374    praxis/Makefile
375    lbfgs/Makefile
376    luksan/Makefile
377    crs/Makefile
378    mlsl/Makefile
379    mma/Makefile
380    cobyla/Makefile
381    newuoa/Makefile
382    neldermead/Makefile
383    auglag/Makefile
384    bobyqa/Makefile
385    isres/Makefile
386    test/Makefile
387    swig/Makefile
388    swig/nlopt.scm
389 ])
390
391 AC_OUTPUT