chiark / gitweb /
a8030849fc1cde0f097b534d79cb105cd7d23ca9
[nlopt.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 AC_INIT(nlopt, 0.1, stevenj@alum.mit.edu)
3 AC_CONFIG_SRCDIR(api/nlopt.h)
4 SHARED_VERSION_INFO="0:0:0" # CURRENT:REVISION:AGE
5
6 AM_INIT_AUTOMAKE(1.7)
7 AM_CONFIG_HEADER(config.h)
8 AM_MAINTAINER_MODE
9 AC_SUBST(SHARED_VERSION_INFO)
10 AC_DISABLE_SHARED dnl to hell with shared libraries
11
12 dnl Checks for programs.
13 AC_PROG_CC
14 AC_PROG_CC_STDC
15 AC_PROG_INSTALL
16 AC_PROG_LN_S
17 AC_PROG_MAKE_SET
18 AC_LIBTOOL_WIN32_DLL
19 AC_PROG_LIBTOOL
20
21 NLOPT_SUFFIX=""
22 AC_ARG_WITH(cxx,
23         [AC_HELP_STRING([--with-cxx], [include C++-based routines])],
24         with_cxx=$withval,with_cxx=no)
25 AM_CONDITIONAL(WITH_CXX, test "x$with_cxx" = xyes)
26 if test "x$with_cxx" = xyes; then
27    AC_PROG_CXX
28    AC_DEFINE([WITH_CXX], 1, [Define if compiled including C++-based routines])
29    NLOPT_SUFFIX="_cxx"
30 fi
31 AC_SUBST(NLOPT_SUFFIX)
32
33 dnl Checks for typedefs, structures, and compiler characteristics.
34 AC_HEADER_STDC
35 AC_HEADER_TIME
36 AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
37 AC_C_CONST
38 AC_C_INLINE
39
40 dnl find 32-bit unsigned integer type for random-number generator
41 AC_CHECK_SIZEOF(unsigned int)
42 AC_CHECK_SIZEOF(unsigned long)
43 AC_CHECK_TYPES(uint32_t, [], [], [$ac_includes_default
44 #ifdef HAVE_STDINT_H
45 #  include <stdint.h>
46 #endif])
47
48 dnl Checks for libraries and functions
49 AC_CHECK_LIB(m, sin)
50 AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time])
51
52 AC_MSG_CHECKING([for isnan])
53 AC_TRY_LINK([#include <math.h>
54 ], if (!isnan(3.14159)) isnan(2.7183);, ok=yes, ok=no)
55 if test "$ok" = "yes"; then
56         AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.])
57 fi
58 AC_MSG_RESULT(${ok})
59
60 AC_MSG_CHECKING([for isinf])
61 AC_TRY_LINK([#include <math.h>
62 ], if (!isinf(3.14159)) isinf(2.7183);, ok=yes, ok=no)
63 if test "$ok" = "yes"; then
64         AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.])
65 fi
66 AC_MSG_RESULT(${ok})
67
68 dnl -----------------------------------------------------------------------
69
70 if test "x$with_cxx" = xyes; then
71   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
72 fi
73 AM_CONDITIONAL(WITH_NOCEDAL, test -n "$have_lbfgs")
74 if test -n "$have_lbfgs"; then
75    AC_DEFINE(WITH_NOCEDAL, [1], [Define if we have the non-free Nocedal LBFGS code])
76 fi
77
78 dnl -----------------------------------------------------------------------
79 dnl Compiling Octave plug-in
80
81 AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
82 AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
83 AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
84
85 AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
86 if test "$MKOCTFILE" = "echo"; then
87         AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
88 elif test x"$OCT_INSTALL_DIR" = "x"; then
89         # try to find installation directory
90         AC_CHECK_PROGS(OCTAVE, octave, echo)
91         AC_MSG_CHECKING(for Octave loadpath)
92         OCTAVE_LOADPATH=`echo "DEFAULT_LOADPATH" | $OCTAVE -q | cut -d'=' -f2`
93         AC_MSG_RESULT($OCTAVE_LOADPATH)
94         AC_MSG_CHECKING(where Octave plugins go)
95         OCT_INSTALL_DIR=`echo "$OCTAVE_LOADPATH" | tr ':' '\n' | grep "site/oct" | head -1`
96         if test -n "$OCT_INSTALL_DIR"; then
97                 AC_MSG_RESULT($OCT_INSTALL_DIR)
98         else
99                 AC_MSG_RESULT(unknown)
100                 AC_MSG_WARN([can't find where to install GNU Octave plugins])
101         fi
102         AC_MSG_CHECKING(where Octave scripts go)
103         M_INSTALL_DIR=`echo "$OCTAVE_LOADPATH" | tr ':' '\n' | grep "site/m" | head -1`
104         if test -n "$M_INSTALL_DIR"; then
105                 AC_MSG_RESULT($M_INSTALL_DIR)
106         else
107                 AC_MSG_RESULT(unknown)
108                 AC_MSG_WARN([can't find where to install GNU Octave scripts])
109         fi
110 fi
111 AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
112 AC_SUBST(OCT_INSTALL_DIR)
113 AC_SUBST(M_INSTALL_DIR)
114 AC_SUBST(MKOCTFILE)
115
116 dnl -----------------------------------------------------------------------
117 dnl Compiling Matlab plug-in
118
119 AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
120 AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
121 AC_CHECK_PROGS(MEX, mex, echo)
122 if test "$MEX" = "echo"; then
123         AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
124 elif test x"$MEX_INSTALL_DIR" = "x"; then
125      AC_MSG_CHECKING([for extension of compiled mex files])
126      rm -f conftest*
127      cat > conftest.c <<EOF
128 #include <mex.h>
129 void mexFunction(int nlhs, mxArray *plhs[[]],
130                  int nrhs, const mxArray *prhs[[]]) { }
131 EOF
132      if $MEX conftest.c; then
133         MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
134         AC_MSG_RESULT($MEXSUFF)
135         AC_CHECK_PROGS(MATLAB, matlab, echo)
136      else
137            AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
138         MATLAB=echo
139      fi
140
141      # try to find installation directory
142      if test x"$MATLAB" = xecho; then
143         AC_MSG_WARN([can't fine Matlab; won't compile Matlab plugin])
144      else
145         AC_MSG_CHECKING(for MATLAB mex installation dir)
146         matlabpath_line=`matlab -n | grep -n MATLABPATH |head -1 |cut -d: -f1`
147         matlabpath_line=`expr $matlabpath_line + 1`
148         MEX_INSTALL_DIR=`matlab -n | tail -n +$matlabpath_line | head -1 | tr -d ' '`
149         AC_MSG_RESULT($MEX_INSTALL_DIR)
150       fi
151 fi
152 AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
153 AC_SUBST(MEX_INSTALL_DIR)
154 AC_SUBST(MEX)
155 AC_SUBST(MEXSUFF)
156
157 dnl -----------------------------------------------------------------------
158 dnl Debugging
159
160 AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
161 if test "$ok" = "yes"; then
162         AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
163 fi
164
165 dnl override CFLAGS selection when debugging
166 if test "${enable_debug}" = "yes"; then
167         CFLAGS="-g"
168         CXXFLAGS="-g"
169         FFLAGS="-g"
170 fi
171
172 dnl add gcc warnings, in debug/maintainer mode only
173 if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
174 if test $ac_cv_prog_gcc = yes; then
175    if test "$ac_test_CFLAGS" != "set"; then
176       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"
177    fi
178    if test "$ac_test_CXXFLAGS" != "set"; then
179       CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
180    fi
181 fi
182 fi
183
184 vers=`echo ${VERSION}.0.0 | cut -d. -f1`
185 AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
186 vers=`echo ${VERSION}.0.0 | cut -d. -f2`
187 AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
188 vers=`echo ${VERSION}.0.0 | cut -d. -f3`
189 AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
190
191 dnl -----------------------------------------------------------------------
192
193 AC_CONFIG_FILES([
194    Makefile
195    nlopt.pc
196    api/Makefile
197    util/Makefile
198    octave/Makefile
199    direct/Makefile
200    cdirect/Makefile
201    stogo/Makefile
202    subplex/Makefile
203    praxis/Makefile
204    lbfgs/Makefile
205    luksan/Makefile
206    crs/Makefile
207    mlsl/Makefile
208    mma/Makefile
209    test/Makefile
210 ])
211
212 AC_OUTPUT