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