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