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