chiark / gitweb /
work around guile 1.8+ swig problems
[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 dnl SWIG wrappers
99
100 AC_ARG_WITH(guile,
101         [AC_HELP_STRING([--without-guile], [don't compile Guile plugin])],
102         with_guile=$withval,with_guile=yes)
103 AC_ARG_WITH(python,
104         [AC_HELP_STRING([--without-python], [don't compile Python plugin])],
105         with_python=$withval,with_python=yes)
106
107 if test "$enable_shared" = no; then
108    AC_MSG_WARN([Python and Guile wrappers require --enable-shared; disabling])
109    GUILE_CONFIG=unknown
110    have_python=no
111 else
112
113 if test "x$with_guile" = xno; then
114    GUILE_CONFIG=unknown
115 else
116
117 dnl Guile:
118 AC_ARG_VAR(GUILE_INSTALL_DIR, [where to install Guile plug-ins])
119 AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown)
120 if test "x$GUILE_CONFIG" = "xunknown"; then
121    AC_MSG_WARN([can't find guile-config, disabling Guile wrapper])
122 else
123    save_CPPFLAGS=$CPPFLAGS
124    save_LIBS=$LIBS
125    GUILE_CPPFLAGS=`$GUILE_CONFIG compile`
126    GUILE_LIBS=`$GUILE_CONFIG link`
127    CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS"
128    LIBS="$GUILE_LIBS $LIBS"
129    AC_MSG_CHECKING([if linking to guile works])
130    AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
131         AC_MSG_WARN(guile-config is broken, disabling Guile wrapper)
132         GUILE_CONFIG="unknown"])
133    CPPFLAGS=$save_CPPFLAGS
134    LIBS=$save_LIBS
135 fi
136 AC_CHECK_PROG(GUILE, guile, guile, unknown)
137 if test "x$GUILE" = xunknown; then
138    AC_MSG_WARN([can't find guile, disabling Guile wrapper])
139    GUILE_CONFIG=unknown
140 elif test x"$GUILE_INSTALL_DIR" = "x"; then
141    AC_MSG_CHECKING([for Guile installation directory])
142    GUILE_INSTALL_DIR=`guile -c '(display (%site-dir))'`
143    AC_MSG_RESULT([$GUILE_INSTALL_DIR])
144 fi
145
146 fi # with_guile
147
148 if test "x$with_python" = xno; then
149   have_python=no
150 else
151
152 dnl Python:
153 AM_PATH_PYTHON([],[have_python=yes],[have_python=no])
154 if test $have_python = yes; then
155   AC_ARG_VAR([PYTHON_CONFIG], [python-config program])
156   AC_PATH_PROGS([PYTHON_CONFIG], [python$PYTHON_VERSION-config python-config],
157                 [unknown], [`dirname $PYTHON`:$PATH])
158   AC_MSG_CHECKING([for Python include flags])
159   if test "x$PYTHON_CONFIG" = "xunknown"; then
160       pinc=-I`echo "import distutils.sysconfig; print distutils.sysconfig.get_python_inc()" | $PYTHON - 2>/dev/null`
161       test "x$pinc" = "x-I" && pinc=""
162   else
163       pinc=`$PYTHON_CONFIG --includes 2>/dev/null`
164   fi
165   AC_MSG_RESULT([${pinc:-unknown}])
166   PYTHON_INCLUDES="$pinc"
167   save_CPPFLAGS=$CPPFLAGS
168   CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
169   AC_CHECK_HEADER([Python.h], [], [AC_MSG_WARN([disabling Python wrappers]) 
170                                    have_python=no])
171   if test $have_python = yes; then
172     AC_MSG_CHECKING([for Numpy include directory])
173     pinc=`echo "import numpy; print numpy.get_include()" | $PYTHON - 2>/dev/null`
174     AC_MSG_RESULT([${pinc:-unknown}])
175     test -n "$pinc" && PYTHON_INCLUDES="$PYTHON_INCLUDES -I$pinc"
176     CPPFLAGS="$save_CPPFLAGS $PYTHON_INCLUDES"
177     AC_CHECK_HEADER([numpy/arrayobject.h],[],[
178       AC_MSG_WARN([disabling Python wrappers])
179       have_python=no],[#include <Python.h>])
180   fi
181   CPPFLAGS=$save_CPPFLAGS
182 fi
183
184 fi # with_python
185
186 fi # if enable_shared
187
188 AC_SUBST(GUILE_INSTALL_DIR)
189 AC_SUBST(GUILE_CPPFLAGS)
190 AC_SUBST(GUILE_LIBS)
191 AC_SUBST(PYTHON_INCLUDES)
192 AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
193 AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes")
194
195 dnl -----------------------------------------------------------------------
196 dnl Compiling Octave plug-in
197
198 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
199 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
200 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
201
202 AC_ARG_WITH(octave,
203         [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
204         with_octave=$withval,with_octave=yes)
205
206 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
207
208 if test x"$with_octave" = xno; then
209         OCT_INSTALL_DIR=""
210 elif test "$MKOCTFILE" = "echo"; then
211         AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
212         OCT_INSTALL_DIR=""
213 elif test x"$OCT_INSTALL_DIR" = "x"; then
214         # try to find installation directory
215         AC_CHECK_PROGS(OCTAVE, octave, echo)
216         AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
217
218         AC_MSG_CHECKING(where octave plugins go)
219         OCT_INSTALL_DIR=`octave-config --oct-site-dir 2> /dev/null | grep '/'`
220         if test -z "$OCT_INSTALL_DIR"; then
221                 OCT_INSTALL_DIR=`octave-config --print OCTFILEDIR 2> /dev/null | grep '/'`
222         fi
223         if test -z "$OCT_INSTALL_DIR"; then
224                 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
225         fi
226         if test -z "$OCT_INSTALL_DIR"; then
227                 OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
228         fi
229         if test -n "$OCT_INSTALL_DIR"; then
230                 AC_MSG_RESULT($OCT_INSTALL_DIR)
231         else
232                 AC_MSG_RESULT(unknown)
233                 AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
234         fi
235
236         AC_MSG_CHECKING(where octave scripts go)
237         M_INSTALL_DIR=`octave-config --m-site-dir 2> /dev/null | grep '/'`
238         if test -z "$M_INSTALL_DIR"; then
239                 M_INSTALL_DIR=`octave-config --print FCNFILEDIR 2> /dev/null | grep '/'`
240         fi
241         if test -z "$M_INSTALL_DIR"; then
242                 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
243         fi
244         if test -z "$M_INSTALL_DIR"; then
245                 M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
246         fi
247         if test -n "$M_INSTALL_DIR"; then
248                 AC_MSG_RESULT($M_INSTALL_DIR)
249         else
250                 AC_MSG_RESULT(unknown)
251                 AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
252                 OCT_INSTALL_DIR=""
253         fi
254 elif test x"$M_INSTALL_DIR" = "x"; then # user-specified OCT_INSTALL_DIR
255      M_INSTALL_DIR=$OCT_INSTALL_DIR
256 fi
257
258 if test x"$OCT_INSTALL_DIR" != "x"; then
259 if test "$enable_shared" = no; then
260         AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
261         OCT_INSTALL_DIR=""
262 fi
263 fi
264
265 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
266 AC_SUBST(OCT_INSTALL_DIR)
267 AC_SUBST(M_INSTALL_DIR)
268 AC_SUBST(MKOCTFILE)
269
270 dnl -----------------------------------------------------------------------
271 dnl Compiling Matlab plug-in
272
273 AC_ARG_WITH(matlab,
274         [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
275         with_matlab=$withval,with_matlab=yes)
276
277 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
278 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
279 AC_CHECK_PROGS(MEX, mex, echo)
280 if test x"$with_matlab" = xno; then
281      MEX_INSTALL_DIR=""
282 elif test "$MEX" = "echo"; then
283      AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
284      MEX_INSTALL_DIR=""
285 else
286      AC_MSG_CHECKING([for extension of compiled mex files])
287      rm -f conftest*
288      cat > conftest.c <<EOF
289 #include <mex.h>
290 void mexFunction(int nlhs, mxArray *plhs[[]],
291                  int nrhs, const mxArray *prhs[[]]) { }
292 EOF
293      if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
294         MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
295         AC_MSG_RESULT($MEXSUFF)
296         AC_CHECK_PROGS(MATLAB, matlab, echo)
297      else
298         AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
299         MEX_INSTALL_DIR=""
300         MATLAB=echo
301      fi
302
303      if test x"$MATLAB" != xecho; then
304      if test "$enable_shared" = no; then
305         AC_MSG_RESULT(no)
306         AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
307         MEX_INSTALL_DIR=""
308         MATLAB=echo
309      fi
310      fi
311
312      if test x"$MATLAB" != xecho; then
313        # try to find installation directory
314        if test x"$MEX_INSTALL_DIR" = "x"; then
315           AC_MSG_CHECKING(for MATLAB mex installation dir)
316           MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
317           AC_MSG_RESULT($MEX_INSTALL_DIR)
318           if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
319              MEX_INSTALL_DIR=""
320           fi
321           if test x"$MEX_INSTALL_DIR" = "x"; then
322             AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
323           fi
324        fi
325      else
326         MEX_INSTALL_DIR=""
327      fi
328 fi
329 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
330 AC_SUBST(MEX_INSTALL_DIR)
331 AC_SUBST(MEX)
332 AC_SUBST(MEXSUFF)
333
334 dnl -----------------------------------------------------------------------
335 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
336
337 AC_MSG_CHECKING([for working HUGE_VAL])
338 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;], 
339 [AC_MSG_RESULT([ok])],
340 [AC_TRY_COMPILE([#include <math.h>
341 #ifdef __GNUC__
342 #undef HUGE_VAL
343 #define HUGE_VAL __builtin_huge_val()
344 #endif], [double x = -HUGE_VAL;], 
345 [AC_MSG_RESULT([__builtin_huge_val()])
346 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
347           [replacement for broken HUGE_VAL macro, if needed])],
348 [AC_MSG_RESULT([unknown])
349 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
350
351 dnl -----------------------------------------------------------------------
352 dnl Debugging
353
354 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
355 if test "$ok" = "yes"; then
356         AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
357 fi
358
359 dnl override CFLAGS selection when debugging
360 if test "${enable_debug}" = "yes"; then
361         CFLAGS="-g"
362         CXXFLAGS="-g"
363         FFLAGS="-g"
364 fi
365
366 dnl add gcc warnings, in debug/maintainer mode only
367 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
368 if test $ac_cv_prog_gcc = yes; then
369    if test "$ac_test_CFLAGS" != "set"; then
370       CFLAGS="$CFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -Wshadow -Wbad-function-cast -Wwrite-strings -Wstrict-prototypes -Wredundant-decls -Wnested-externs -Wundef -Wconversion -Wmissing-prototypes -Wmissing-declarations"
371    fi
372    if test "$ac_test_CXXFLAGS" != "set"; then
373       CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
374    fi
375    if test "x$with_cxx" = xyes; then
376       CFLAGS=$CXXFLAGS
377    fi
378 fi
379 fi
380
381 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
382 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
383 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
384 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
385 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
386 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
387
388 dnl -----------------------------------------------------------------------
389
390 AC_CONFIG_FILES([
391    Makefile
392    nlopt.pc
393    api/Makefile
394    util/Makefile
395    octave/Makefile
396    direct/Makefile
397    cdirect/Makefile
398    stogo/Makefile
399    praxis/Makefile
400    luksan/Makefile
401    crs/Makefile
402    mlsl/Makefile
403    mma/Makefile
404    cobyla/Makefile
405    newuoa/Makefile
406    neldermead/Makefile
407    auglag/Makefile
408    bobyqa/Makefile
409    isres/Makefile
410    slsqp/Makefile
411    esch/Makefile
412    test/Makefile
413    swig/Makefile
414    swig/nlopt.scm
415 ])
416
417 AC_OUTPUT