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