chiark / gitweb /
ec20f5a93679282dbbfe9e026c0617d0ed31c53b
[nlopt.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(nlopt, 1.1, stevenj@alum.mit.edu)
3 AC_CONFIG_SRCDIR(api/nlopt.h)
4 SHARED_VERSION_INFO="1:0:1" # 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 to hell with shared libraries
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 fi
32 AC_SUBST(NLOPT_SUFFIX)
33
34 AC_ARG_WITH(windows-f77-mangling, [AC_HELP_STRING([--with-windows-f77-mangling],[use common Win32 Fortran interface styles])], with_windows_f77_mangling=$withval, with_windows_f77_mangling=no)
35 if test "$with_windows_f77_mangling" = "yes"; then
36         AC_DEFINE(WINDOWS_F77_MANGLING,1,[Use common Windows Fortran mangling styles for the Fortran interfaces.])
37 fi
38
39 dnl Checks for typedefs, structures, and compiler characteristics.
40 AC_HEADER_STDC
41 AC_HEADER_TIME
42 AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
43 AC_C_CONST
44 AC_C_INLINE
45
46 dnl find 32-bit unsigned integer type for random-number generator
47 AC_CHECK_SIZEOF(unsigned int)
48 AC_CHECK_SIZEOF(unsigned long)
49 AC_CHECK_TYPES(uint32_t, [], [], [$ac_includes_default
50 #ifdef HAVE_STDINT_H
51 #  include <stdint.h>
52 #endif])
53
54 dnl Checks for libraries and functions
55 AC_CHECK_LIB(m, sin)
56 AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r])
57
58 AC_MSG_CHECKING([for isnan])
59 AC_TRY_LINK([#include <math.h>
60 ], if (!isnan(3.14159)) isnan(2.7183);, ok=yes, ok=no)
61 if test "$ok" = "yes"; then
62         AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.])
63 fi
64 AC_MSG_RESULT(${ok})
65
66 AC_MSG_CHECKING([for isinf])
67 AC_TRY_LINK([#include <math.h>
68 ], if (!isinf(3.14159)) isinf(2.7183);, ok=yes, ok=no)
69 if test "$ok" = "yes"; then
70         AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.])
71 fi
72 AC_MSG_RESULT(${ok})
73
74 dnl -----------------------------------------------------------------------
75
76 if test "x$with_cxx" = xyes; then
77   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
78 fi
79 AM_CONDITIONAL(WITH_NOCEDAL, test -n "$have_lbfgs")
80 if test -n "$have_lbfgs"; then
81    AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code])
82 fi
83
84 dnl -----------------------------------------------------------------------
85 dnl Compiling Octave plug-in
86
87 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
88 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
89 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
90
91 AC_ARG_WITH(octave,
92         [AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
93         with_octave=$withval,with_octave=yes)
94
95 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
96
97 if test x"$with_octave" = xno; then
98         OCT_INSTALL_DIR=""
99 elif test "$MKOCTFILE" = "echo"; then
100         AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
101         OCT_INSTALL_DIR=""
102 elif test x"$OCT_INSTALL_DIR" = "x"; then
103         # try to find installation directory
104         AC_CHECK_PROGS(OCTAVE, octave, echo)
105         AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
106
107         AC_MSG_CHECKING(where octave plugins go)
108         OCT_INSTALL_DIR=`octave-config --oct-site-dir 2> /dev/null | grep '/'`
109         if test -z "$OCT_INSTALL_DIR"; then
110                 OCT_INSTALL_DIR=`octave-config --print OCTFILEDIR 2> /dev/null | grep '/'`
111         fi
112         if test -z "$OCT_INSTALL_DIR"; then
113                 OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
114         fi
115         if test -z "$OCT_INSTALL_DIR"; then
116                 OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
117         fi
118         if test -n "$OCT_INSTALL_DIR"; then
119                 AC_MSG_RESULT($OCT_INSTALL_DIR)
120         else
121                 AC_MSG_RESULT(unknown)
122                 AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
123         fi
124
125         AC_MSG_CHECKING(where octave scripts go)
126         M_INSTALL_DIR=`octave-config --m-site-dir 2> /dev/null | grep '/'`
127         if test -z "$M_INSTALL_DIR"; then
128                 M_INSTALL_DIR=`octave-config --print FCNFILEDIR 2> /dev/null | grep '/'`
129         fi
130         if test -z "$M_INSTALL_DIR"; then
131                 M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
132         fi
133         if test -z "$M_INSTALL_DIR"; then
134                 M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
135         fi
136         if test -n "$M_INSTALL_DIR"; then
137                 AC_MSG_RESULT($M_INSTALL_DIR)
138         else
139                 AC_MSG_RESULT(unknown)
140                 AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
141                 OCT_INSTALL_DIR=""
142         fi
143 fi
144
145 if test x"$OCT_INSTALL_DIR" != "x"; then
146 if test "$enable_shared" = no; then
147      AC_MSG_CHECKING([whether mkoctfile can link with static objects])
148      rm -f conftest*
149      echo 'void foo(void) {};' > conftestfoo.c
150      $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
151      cat > conftest.cc <<EOF
152 #include <octave/oct.h>
153 extern "C" void foo(void);
154 DEFUN_DLD(foobar, args, nargout, "foo bar") { foo(); }
155 EOF
156      if $MKOCTFILE conftest.cc conftestfoo.o >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
157         AC_MSG_RESULT(yes)
158      else
159         AC_MSG_RESULT(no)
160         AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
161         OCT_INSTALL_DIR=""
162      fi
163 fi
164 fi
165
166 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
167 AC_SUBST(OCT_INSTALL_DIR)
168 AC_SUBST(M_INSTALL_DIR)
169 AC_SUBST(MKOCTFILE)
170
171 dnl -----------------------------------------------------------------------
172 dnl Compiling Matlab plug-in
173
174 AC_ARG_WITH(matlab,
175         [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
176         with_matlab=$withval,with_matlab=yes)
177
178 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
179 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
180 AC_CHECK_PROGS(MEX, mex, echo)
181 if test x"$with_matlab" = xno; then
182      MEX_INSTALL_DIR=""
183 elif test "$MEX" = "echo"; then
184      AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
185      MEX_INSTALL_DIR=""
186 else
187      AC_MSG_CHECKING([for extension of compiled mex files])
188      rm -f conftest*
189      cat > conftest.c <<EOF
190 #include <mex.h>
191 void mexFunction(int nlhs, mxArray *plhs[[]],
192                  int nrhs, const mxArray *prhs[[]]) { }
193 EOF
194      if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
195         MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
196         AC_MSG_RESULT($MEXSUFF)
197         AC_CHECK_PROGS(MATLAB, matlab, echo)
198      else
199         AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
200         MEX_INSTALL_DIR=""
201         MATLAB=echo
202      fi
203
204      if test x"$MATLAB" != xecho; then
205      if test "$enable_shared" = no; then
206      AC_MSG_CHECKING([whether mex can link with static objects])
207      rm -f conftest*
208      echo 'void foo(void) {};' > conftestfoo.c
209      $CC -c conftestfoo.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD
210      cat > conftest.c <<EOF
211 #include <mex.h>
212 extern void foo(void);
213 void mexFunction(int nlhs, mxArray *plhs[[]],
214                  int nrhs, const mxArray *prhs[[]]) { foo(); }
215 EOF
216      if $MEX conftest.c 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([mex requires --enable-shared; won't compile Matlab plugin])
221         MEX_INSTALL_DIR=""
222         MATLAB=echo
223      fi
224      fi
225      fi
226
227      if test x"$MATLAB" != xecho; then
228        # try to find installation directory
229        if test x"$MEX_INSTALL_DIR" = "x"; then
230           AC_MSG_CHECKING(for MATLAB mex installation dir)
231           MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
232           AC_MSG_RESULT($MEX_INSTALL_DIR)
233           if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
234              MEX_INSTALL_DIR=""
235           fi
236           if test x"$MEX_INSTALL_DIR" = "x"; then
237             AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
238           fi
239        else
240           MEX_INSTALL_DIR=""
241        fi
242      fi
243 fi
244 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
245 AC_SUBST(MEX_INSTALL_DIR)
246 AC_SUBST(MEX)
247 AC_SUBST(MEXSUFF)
248
249 dnl -----------------------------------------------------------------------
250 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
251
252 AC_MSG_CHECKING([for working HUGE_VAL])
253 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;], 
254 [AC_MSG_RESULT([ok])],
255 [AC_TRY_COMPILE([#include <math.h>
256 #ifdef __GNUC__
257 #undef HUGE_VAL
258 #define HUGE_VAL __builtin_huge_val()
259 #endif], [double x = -HUGE_VAL;], 
260 [AC_MSG_RESULT([__builtin_huge_val()])
261 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
262           [replacement for broken HUGE_VAL macro, if needed])],
263 [AC_MSG_RESULT([unknown])
264 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
265
266 dnl -----------------------------------------------------------------------
267 dnl Debugging
268
269 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
270 if test "$ok" = "yes"; then
271         AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
272 fi
273
274 dnl override CFLAGS selection when debugging
275 if test "${enable_debug}" = "yes"; then
276         CFLAGS="-g"
277         CXXFLAGS="-g"
278         FFLAGS="-g"
279 fi
280
281 dnl add gcc warnings, in debug/maintainer mode only
282 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
283 if test $ac_cv_prog_gcc = yes; then
284    if test "$ac_test_CFLAGS" != "set"; then
285       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"
286    fi
287    if test "$ac_test_CXXFLAGS" != "set"; then
288       CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
289    fi
290 fi
291 fi
292
293 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
294 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
295 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
296 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
297 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
298 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
299
300 dnl -----------------------------------------------------------------------
301
302 AC_CONFIG_FILES([
303    Makefile
304    nlopt.pc
305    api/Makefile
306    util/Makefile
307    octave/Makefile
308    direct/Makefile
309    cdirect/Makefile
310    stogo/Makefile
311    praxis/Makefile
312    lbfgs/Makefile
313    luksan/Makefile
314    crs/Makefile
315    mlsl/Makefile
316    mma/Makefile
317    cobyla/Makefile
318    newuoa/Makefile
319    neldermead/Makefile
320    auglag/Makefile
321    test/Makefile
322 ])
323
324 AC_OUTPUT