chiark / gitweb /
--without-octave and --without-matlab options
[nlopt.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(nlopt, 1.0.2, stevenj@alum.mit.edu)
3 AC_CONFIG_SRCDIR(api/nlopt.h)
4 SHARED_VERSION_INFO="0:2:0" # 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_MSG_CHECKING(for Octave loadpath)
106         OCTAVE_LOADPATH=`echo "DEFAULT_LOADPATH" | $OCTAVE -q | cut -d'=' -f2`
107         AC_MSG_RESULT($OCTAVE_LOADPATH)
108         AC_MSG_CHECKING(where Octave plugins go)
109         OCT_INSTALL_DIR=`echo "$OCTAVE_LOADPATH" | tr ':' '\n' | grep "site/oct" | head -1`
110         if test -n "$OCT_INSTALL_DIR"; then
111                 AC_MSG_RESULT($OCT_INSTALL_DIR)
112         else
113                 AC_MSG_RESULT(unknown)
114                 AC_MSG_WARN([can't find where to install GNU Octave plugins])
115         fi
116         AC_MSG_CHECKING(where Octave scripts go)
117         M_INSTALL_DIR=`echo "$OCTAVE_LOADPATH" | tr ':' '\n' | grep "site/m" | head -1`
118         if test -n "$M_INSTALL_DIR"; then
119                 AC_MSG_RESULT($M_INSTALL_DIR)
120         else
121                 AC_MSG_RESULT(unknown)
122                 AC_MSG_WARN([can't find where to install GNU Octave scripts])
123         fi
124 fi
125 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
126 AC_SUBST(OCT_INSTALL_DIR)
127 AC_SUBST(M_INSTALL_DIR)
128 AC_SUBST(MKOCTFILE)
129
130 dnl -----------------------------------------------------------------------
131 dnl Compiling Matlab plug-in
132
133 AC_ARG_WITH(matlab,
134         [AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
135         with_matlab=$withval,with_matlab=yes)
136
137 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
138 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
139 AC_CHECK_PROGS(MEX, mex, echo)
140 if test x"$with_matlab" = xno; then
141      MEX_INSTALL_DIR=""
142 elif test "$MEX" = "echo"; then
143      AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
144      MEX_INSTALL_DIR=""
145 else
146      AC_MSG_CHECKING([for extension of compiled mex files])
147      rm -f conftest*
148      cat > conftest.c <<EOF
149 #include <mex.h>
150 void mexFunction(int nlhs, mxArray *plhs[[]],
151                  int nrhs, const mxArray *prhs[[]]) { }
152 EOF
153      if $MEX conftest.c; then
154         MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
155         AC_MSG_RESULT($MEXSUFF)
156         AC_CHECK_PROGS(MATLAB, matlab, echo)
157      else
158            AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
159         MATLAB=echo
160      fi
161
162      if test x"$MEX_INSTALL_DIR" = "x"; then
163        # try to find installation directory
164        if test x"$MATLAB" != xecho; then
165           AC_MSG_CHECKING(for MATLAB mex installation dir)
166           MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
167           AC_MSG_RESULT($MEX_INSTALL_DIR)
168           if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
169              MEX_INSTALL_DIR=""
170           fi
171         fi
172      fi
173      if test x"$MEX_INSTALL_DIR" = "x"; then
174          AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
175      fi
176 fi
177 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
178 AC_SUBST(MEX_INSTALL_DIR)
179 AC_SUBST(MEX)
180 AC_SUBST(MEXSUFF)
181
182 dnl -----------------------------------------------------------------------
183 dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
184
185 AC_MSG_CHECKING([for working HUGE_VAL])
186 AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;], 
187 [AC_MSG_RESULT([ok])],
188 [AC_TRY_COMPILE([#include <math.h>
189 #ifdef __GNUC__
190 #undef HUGE_VAL
191 #define HUGE_VAL __builtin_huge_val()
192 #endif], [double x = -HUGE_VAL;], 
193 [AC_MSG_RESULT([__builtin_huge_val()])
194 AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
195           [replacement for broken HUGE_VAL macro, if needed])],
196 [AC_MSG_RESULT([unknown])
197 AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
198
199 dnl -----------------------------------------------------------------------
200 dnl Debugging
201
202 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
203 if test "$ok" = "yes"; then
204         AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
205 fi
206
207 dnl override CFLAGS selection when debugging
208 if test "${enable_debug}" = "yes"; then
209         CFLAGS="-g"
210         CXXFLAGS="-g"
211         FFLAGS="-g"
212 fi
213
214 dnl add gcc warnings, in debug/maintainer mode only
215 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
216 if test $ac_cv_prog_gcc = yes; then
217    if test "$ac_test_CFLAGS" != "set"; then
218       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"
219    fi
220    if test "$ac_test_CXXFLAGS" != "set"; then
221       CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
222    fi
223 fi
224 fi
225
226 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
227 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
228 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
229 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
230 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
231 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
232
233 dnl -----------------------------------------------------------------------
234
235 AC_CONFIG_FILES([
236    Makefile
237    nlopt.pc
238    api/Makefile
239    util/Makefile
240    octave/Makefile
241    direct/Makefile
242    cdirect/Makefile
243    stogo/Makefile
244    praxis/Makefile
245    lbfgs/Makefile
246    luksan/Makefile
247    crs/Makefile
248    mlsl/Makefile
249    mma/Makefile
250    cobyla/Makefile
251    newuoa/Makefile
252    neldermead/Makefile
253    auglag/Makefile
254    test/Makefile
255 ])
256
257 AC_OUTPUT