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