1dnl Process this file with autoconf to produce a configure script.
2AC_INIT(nlopt, 2.4.2, stevenj@alum.mit.edu)
3AC_CONFIG_SRCDIR(api/nlopt.h)
4SHARED_VERSION_INFO="8:2:8" # CURRENT:REVISION:AGE
5
6AM_INIT_AUTOMAKE(1.7)
7AM_CONFIG_HEADER(config.h)
8AC_CONFIG_MACRO_DIR([m4])
9AM_MAINTAINER_MODE
10AC_SUBST(SHARED_VERSION_INFO)
11AC_DISABLE_SHARED dnl shared libraries are a PITA, disable by default
12
13dnl Checks for programs.
14AC_PROG_CC
15AC_PROG_CC_STDC
16AC_PROG_INSTALL
17AC_PROG_LN_S
18AC_PROG_MAKE_SET
19AC_LIBTOOL_WIN32_DLL
20AC_PROG_LIBTOOL
21
22NLOPT_SUFFIX=""
23AC_ARG_WITH(cxx,
24	[AC_HELP_STRING([--with-cxx], [include C++-based routines])],
25        with_cxx=$withval,with_cxx=no)
26AM_CONDITIONAL(WITH_CXX, test "x$with_cxx" = xyes)
27AC_PROG_CXX
28if 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
33fi
34AC_SUBST(NLOPT_SUFFIX)
35
36AC_ARG_WITH(mthreads,
37        [AC_HELP_STRING([--with-mthreads], [use -mthreads compiler flag])],
38        with_mthrads=$withval,with_mthreads=no)
39if test "x$with_mthreads" = xyes; then
40   CFLAGS="$CFLAGS -mthreads"
41   CXXFLAGS="$CXXFLAGS -mthreads"
42fi
43
44dnl Checks for typedefs, structures, and compiler characteristics.
45AC_HEADER_STDC
46AC_HEADER_TIME
47AC_CHECK_HEADERS([unistd.h getopt.h stdint.h])
48AC_C_CONST
49AC_C_INLINE
50AX_C_THREADLOCAL
51
52dnl find 32-bit unsigned integer type for random-number generator
53AC_CHECK_SIZEOF(unsigned int)
54AC_CHECK_SIZEOF(unsigned long)
55AC_CHECK_TYPES(uint32_t, [], [], [$ac_includes_default
56#ifdef HAVE_STDINT_H
57#  include <stdint.h>
58#endif])
59
60dnl Checks for libraries and functions
61AC_CHECK_LIB(m, sin)
62AC_CHECK_FUNCS([BSDgettimeofday gettimeofday time qsort_r getpid])
63
64AC_MSG_CHECKING([for gettid syscall])
65AC_TRY_LINK([#include <unistd.h>
66#include <sys/syscall.h>
67], [syscall(SYS_gettid);], [ok=yes], [ok=no])
68if test "$ok" = "yes"; then
69	AC_DEFINE(HAVE_GETTID_SYSCALL,1,[Define if syscall(SYS_gettid) available.])
70fi
71AC_MSG_RESULT(${ok})
72
73AC_MSG_CHECKING([for isnan])
74AC_TRY_LINK([#include <math.h>
75], [if (!isnan(3.14159)) isnan(2.7183);], ok=yes, ok=no)
76if test "$ok" = "yes"; then
77	AC_DEFINE(HAVE_ISNAN,1,[Define if the isnan() function/macro is available.])
78fi
79AC_MSG_RESULT(${ok})
80
81AC_MSG_CHECKING([for isinf])
82AC_TRY_LINK([#include <math.h>
83], [if (!isinf(3.14159)) isinf(2.7183);], ok=yes, ok=no)
84if test "$ok" = "yes"; then
85	AC_DEFINE(HAVE_ISINF,1,[Define if the isinf() function/macro is available.])
86fi
87AC_MSG_RESULT(${ok})
88
89AC_MSG_CHECKING([for copysign])
90AC_TRY_LINK([#include <math.h>
91], [double x = copysign(3.14159, -2.7183);], ok=yes, ok=no)
92if test "$ok" = "yes"; then
93	AC_DEFINE(HAVE_COPYSIGN,1,[Define if the copysign function/macro is available.])
94fi
95AC_MSG_RESULT(${ok})
96
97dnl -----------------------------------------------------------------------
98dnl SWIG wrappers
99
100AC_ARG_WITH(guile,
101	[AC_HELP_STRING([--without-guile], [don't compile Guile plugin])],
102        with_guile=$withval,with_guile=yes)
103AC_ARG_WITH(python,
104	[AC_HELP_STRING([--without-python], [don't compile Python plugin])],
105        with_python=$withval,with_python=yes)
106
107if test "$enable_shared" = no; then
108   AC_MSG_WARN([Python and Guile wrappers require --enable-shared; disabling])
109   GUILE_CONFIG=unknown
110   have_python=no
111else
112
113if test "x$with_guile" = xno; then
114   GUILE_CONFIG=unknown
115else
116
117dnl Guile:
118AC_ARG_VAR(GUILE_INSTALL_DIR, [where to install Guile plug-ins])
119AC_CHECK_PROG(GUILE_CONFIG, guile-config, guile-config, unknown)
120if test "x$GUILE_CONFIG" = "xunknown"; then
121   AC_MSG_WARN([can't find guile-config, disabling Guile wrapper])
122else
123   save_CPPFLAGS=$CPPFLAGS
124   save_LIBS=$LIBS
125   GUILE_CPPFLAGS=`$GUILE_CONFIG compile`
126   GUILE_LIBS=`$GUILE_CONFIG link`
127   CPPFLAGS="$CPPFLAGS $GUILE_CPPFLAGS"
128   LIBS="$GUILE_LIBS $LIBS"
129   AC_MSG_CHECKING([if linking to guile works])
130   AC_TRY_LINK_FUNC(scm_is_vector, [AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)
131        AC_MSG_WARN(guile-config is broken, disabling Guile wrapper)
132        GUILE_CONFIG="unknown"])
133   CPPFLAGS=$save_CPPFLAGS
134   LIBS=$save_LIBS
135fi
136AC_CHECK_PROG(GUILE, guile, guile, unknown)
137if test "x$GUILE" = xunknown; then
138   AC_MSG_WARN([can't find guile, disabling Guile wrapper])
139   GUILE_CONFIG=unknown
140elif test x"$GUILE_INSTALL_DIR" = "x"; then
141   AC_CHECK_PROGS(GUILE_CONFIG, guile-config, echo)
142   AC_MSG_CHECKING(guile prefix)
143   GUILE_PREFIX=`$GUILE_CONFIG info prefix`
144   AC_MSG_RESULT($GUILE_PREFIX)
145   AC_MSG_CHECKING([for Guile installation directory])
146   GUILE_INSTALL_DIR=`guile -c '(display (%site-dir))'`
147   if test "$prefix" != "NONE"; then
148        # strip guile install path to honor prefix
149        GUILE_INSTALL_DIR=`echo "$GUILE_INSTALL_DIR" | sed "s|$GUILE_PREFIX|$prefix|g"`
150   fi
151
152   AC_MSG_RESULT([$GUILE_INSTALL_DIR])
153fi
154
155fi # with_guile
156
157if test "x$with_python" = xno; then
158  have_python=no
159else
160
161dnl Python:
162AM_PATH_PYTHON([],[have_python=yes],[have_python=no])
163if test $have_python = yes; then
164  AC_ARG_VAR([PYTHON_CONFIG], [python-config program])
165  AC_PATH_PROGS([PYTHON_CONFIG], [python$PYTHON_VERSION-config python-config],
166                [unknown], [`dirname $PYTHON`:$PATH])
167  AC_MSG_CHECKING([for Python include flags])
168  if test "x$PYTHON_CONFIG" = "xunknown"; then
169      pinc=-I`echo "import distutils.sysconfig; print (distutils.sysconfig.get_python_inc())" | $PYTHON - 2>/dev/null`
170      test "x$pinc" = "x-I" && pinc=""
171  else
172      pinc=`$PYTHON_CONFIG --includes 2>/dev/null`
173  fi
174  AC_MSG_RESULT([${pinc:-unknown}])
175  PYTHON_INCLUDES="$pinc"
176  save_CPPFLAGS=$CPPFLAGS
177  CPPFLAGS="$CPPFLAGS $PYTHON_INCLUDES"
178  AC_CHECK_HEADER([Python.h], [], [AC_MSG_WARN([disabling Python wrappers])
179                                   have_python=no])
180  if test $have_python = yes; then
181    AC_MSG_CHECKING([for Numpy include directory])
182    pinc=`echo "import numpy; print (numpy.get_include())" | $PYTHON - 2>/dev/null`
183    AC_MSG_RESULT([${pinc:-unknown}])
184    test -n "$pinc" && PYTHON_INCLUDES="$PYTHON_INCLUDES -I$pinc"
185    CPPFLAGS="$save_CPPFLAGS $PYTHON_INCLUDES"
186    AC_CHECK_HEADER([numpy/arrayobject.h],[],[
187      AC_MSG_WARN([disabling Python wrappers])
188      have_python=no],[#include <Python.h>])
189  fi
190  CPPFLAGS=$save_CPPFLAGS
191fi
192
193fi # with_python
194
195fi # if enable_shared
196
197AC_SUBST(GUILE_INSTALL_DIR)
198AC_SUBST(GUILE_CPPFLAGS)
199AC_SUBST(GUILE_LIBS)
200AC_SUBST(PYTHON_INCLUDES)
201AM_CONDITIONAL(WITH_GUILE, test x"$GUILE_CONFIG" != "xunknown")
202AM_CONDITIONAL(WITH_PYTHON, test x"$have_python" = "xyes")
203
204dnl -----------------------------------------------------------------------
205dnl Compiling Octave plug-in
206
207AC_ARG_VAR(OCT_INSTALL_DIR, [where to install GNU Octave .oct plug-ins])
208AC_ARG_VAR(M_INSTALL_DIR, [where to install GNU Octave .m plug-ins])
209AC_ARG_VAR(MKOCTFILE, [name of mkoctfile program to compile Octave plug-ins])
210
211AC_ARG_WITH(octave,
212	[AC_HELP_STRING([--without-octave], [don't compile Octave plugin])],
213        with_octave=$withval,with_octave=yes)
214
215AC_CHECK_PROGS(MKOCTFILE, mkoctfile, echo)
216
217if test x"$with_octave" = xno; then
218	OCT_INSTALL_DIR=""
219elif test "$MKOCTFILE" = "echo"; then
220	AC_MSG_WARN([can't find mkoctfile: won't be able to compile GNU Octave plugin])
221	OCT_INSTALL_DIR=""
222elif test x"$OCT_INSTALL_DIR" = "x"; then
223	# try to find installation directory
224	AC_CHECK_PROGS(OCTAVE, octave, echo)
225	AC_CHECK_PROGS(OCTAVE_CONFIG, octave-config, echo)
226
227	AC_MSG_CHECKING(octave prefix)
228	OCTAVE_PREFIX=`$OCTAVE_CONFIG --print PREFIX 2> /dev/null`
229	AC_MSG_RESULT($OCTAVE_PREFIX)
230
231	AC_MSG_CHECKING(where octave plugins go)
232	OCT_INSTALL_DIR=`$OCTAVE_CONFIG --oct-site-dir 2> /dev/null | grep '/'`
233	if test -z "$OCT_INSTALL_DIR"; then
234		OCT_INSTALL_DIR=`$OCTAVE_CONFIG --print OCTFILEDIR 2> /dev/null | grep '/'`
235	fi
236	if test -z "$OCT_INSTALL_DIR"; then
237		OCT_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/oct/" | head -1`
238	fi
239	if test -z "$OCT_INSTALL_DIR"; then
240		OCT_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/oct" | head -1`
241        fi
242	if test -n "$OCT_INSTALL_DIR"; then
243		if test "$prefix" != "NONE"; then
244			# strip octave install path to honor prefix
245			OCT_INSTALL_DIR=`echo "$OCT_INSTALL_DIR" | sed "s|$OCTAVE_PREFIX|$prefix|g"`
246		fi
247		AC_MSG_RESULT($OCT_INSTALL_DIR)
248	else
249		AC_MSG_RESULT(unknown)
250		AC_MSG_WARN([can't find where to install octave plugins: won't be able to compile octave plugin])
251	fi
252
253	AC_MSG_CHECKING(where octave scripts go)
254	M_INSTALL_DIR=`$OCTAVE_CONFIG --m-site-dir 2> /dev/null | grep '/'`
255	if test -z "$M_INSTALL_DIR"; then
256		M_INSTALL_DIR=`$OCTAVE_CONFIG --print FCNFILEDIR 2> /dev/null | grep '/'`
257	fi
258	if test -z "$M_INSTALL_DIR"; then
259		M_INSTALL_DIR=`echo "path" | $OCTAVE -q 2> /dev/null | grep "/m" | head -1`
260	fi
261	if test -z "$M_INSTALL_DIR"; then
262		M_INSTALL_DIR=`echo "DEFAULT_LOADPATH" | $OCTAVE -q 2> /dev/null | tr ':' '\n' | grep "site/m" | head -1`
263        fi
264	if test -n "$M_INSTALL_DIR"; then
265		if test "$prefix" != "NONE"; then
266			# strip octave install path to honor prefix
267			M_INSTALL_DIR=`echo "$M_INSTALL_DIR" | sed "s|$OCTAVE_PREFIX|$prefix|g"`
268		fi
269		AC_MSG_RESULT($M_INSTALL_DIR)
270	else
271		AC_MSG_RESULT(unknown)
272		AC_MSG_WARN([can't find where to install octave scripts: won't be able to install octave plugin])
273		OCT_INSTALL_DIR=""
274	fi
275elif test x"$M_INSTALL_DIR" = "x"; then # user-specified OCT_INSTALL_DIR
276     M_INSTALL_DIR=$OCT_INSTALL_DIR
277fi
278
279if test x"$OCT_INSTALL_DIR" != "x"; then
280if test "$enable_shared" = no; then
281        AC_MSG_WARN([mkoctfile requires --enable-shared; won't compile Octave plugin])
282	OCT_INSTALL_DIR=""
283fi
284fi
285
286AM_CONDITIONAL(WITH_OCTAVE, test x"$OCT_INSTALL_DIR" != "x")
287AC_SUBST(OCT_INSTALL_DIR)
288AC_SUBST(M_INSTALL_DIR)
289AC_SUBST(MKOCTFILE)
290
291dnl -----------------------------------------------------------------------
292dnl Compiling Matlab plug-in
293
294AC_ARG_WITH(matlab,
295	[AC_HELP_STRING([--without-matlab], [don't compile Matlab plugin])],
296        with_matlab=$withval,with_matlab=yes)
297
298AC_ARG_VAR(MEX_INSTALL_DIR, [where to install Matlab .mex plug-ins])
299AC_ARG_VAR(MEX, [name of mex program to compile Matlab plug-ins])
300AC_CHECK_PROGS(MEX, mex, echo)
301if test x"$with_matlab" = xno; then
302     MEX_INSTALL_DIR=""
303elif test "$MEX" = "echo"; then
304     AC_MSG_WARN([can't find mex: won't be able to compile Matlab plugin])
305     MEX_INSTALL_DIR=""
306else
307     AC_MSG_CHECKING([for extension of compiled mex files])
308     rm -f conftest*
309     cat > conftest.c <<EOF
310#include <mex.h>
311void mexFunction(int nlhs, mxArray *plhs[[]],
312                 int nrhs, const mxArray *prhs[[]]) { }
313EOF
314     if $MEX conftest.c >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
315        MEXSUFF=`ls conftest.m* | head -1 | cut -d'.' -f2`
316	AC_MSG_RESULT($MEXSUFF)
317	AC_CHECK_PROGS(MATLAB, matlab, echo)
318     else
319        AC_MSG_WARN([$MEX failed to compile a simple file; won't compile Matlab plugin])
320	MEX_INSTALL_DIR=""
321	MATLAB=echo
322     fi
323
324     if test x"$MATLAB" != xecho; then
325     if test "$enable_shared" = no; then
326	AC_MSG_RESULT(no)
327        AC_MSG_WARN([mex requires --enable-shared; won't compile Matlab plugin])
328	MEX_INSTALL_DIR=""
329	MATLAB=echo
330     fi
331     fi
332
333     if test x"$MATLAB" != xecho; then
334       # try to find installation directory
335       if test x"$MEX_INSTALL_DIR" = "x"; then
336          AC_MSG_CHECKING(for MATLAB mex installation dir)
337	  MEX_INSTALL_DIR=`matlab -nodisplay -nodesktop -nojvm -r 'path;quit' | grep toolbox/local |sed 's,^[[^/]]*,,g' |sort |head -1`
338	  AC_MSG_RESULT($MEX_INSTALL_DIR)
339	  if test x`basename "$MEX_INSTALL_DIR"` != xlocal; then
340	     MEX_INSTALL_DIR=""
341	  fi
342          if test x"$MEX_INSTALL_DIR" = "x"; then
343            AC_MSG_WARN([can't find reasonable Matlab installation directory; Matlab plugins will not be compiled unless you manually specify MEX_INSTALL_DIR])
344          fi
345       fi
346     else
347	MEX_INSTALL_DIR=""
348     fi
349fi
350AM_CONDITIONAL(WITH_MATLAB, test x"$MEX_INSTALL_DIR" != "x")
351AC_SUBST(MEX_INSTALL_DIR)
352AC_SUBST(MEX)
353AC_SUBST(MEXSUFF)
354
355dnl -----------------------------------------------------------------------
356dnl Check for broken Solaris HUGE_VAL macro under gcc 3.4.x and similar
357
358AC_MSG_CHECKING([for working HUGE_VAL])
359AC_TRY_COMPILE([#include <math.h>], [double x = -HUGE_VAL;],
360[AC_MSG_RESULT([ok])],
361[AC_TRY_COMPILE([#include <math.h>
362#ifdef __GNUC__
363#undef HUGE_VAL
364#define HUGE_VAL __builtin_huge_val()
365#endif], [double x = -HUGE_VAL;],
366[AC_MSG_RESULT([__builtin_huge_val()])
367AC_DEFINE(REPLACEMENT_HUGE_VAL,[__builtin_huge_val()],
368          [replacement for broken HUGE_VAL macro, if needed])],
369[AC_MSG_RESULT([unknown])
370AC_MSG_ERROR([broken HUGE_VAL macro with this compiler, unknown workaround])])])
371
372dnl -----------------------------------------------------------------------
373dnl Debugging
374
375AC_ARG_ENABLE(debug, [AC_HELP_STRING([--enable-debug],[compile with extra runtime checks for debugging])], ok=$enableval, ok=no)
376if test "$ok" = "yes"; then
377	AC_DEFINE(DEBUG,1,[Define to enable extra debugging code.])
378fi
379
380dnl override CFLAGS selection when debugging
381if test "${enable_debug}" = "yes"; then
382        CFLAGS="-g"
383        CXXFLAGS="-g"
384        FFLAGS="-g"
385fi
386
387dnl add gcc warnings, in debug/maintainer mode only
388if test "$enable_debug" = yes || test "$USE_MAINTAINER_MODE" = yes; then
389if test $ac_cv_prog_gcc = yes; then
390   if test "$ac_test_CFLAGS" != "set"; then
391      CFLAGS="$CFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -Wshadow -Wbad-function-cast -Wwrite-strings -Wstrict-prototypes -Wredundant-decls -Wnested-externs -Wundef -Wconversion -Wmissing-prototypes -Wmissing-declarations"
392   fi
393   if test "$ac_test_CXXFLAGS" != "set"; then
394      CXXFLAGS="$CXXFLAGS -Wall -W -Wcast-qual -Wpointer-arith -Wcast-align -Wno-long-long -pedantic -Wshadow -Wwrite-strings -Wredundant-decls -Wundef -Wconversion"
395   fi
396   if test "x$with_cxx" = xyes; then
397      CFLAGS=$CXXFLAGS
398   fi
399fi
400fi
401
402vers=`echo ${VERSION}.0.0 | cut -d. -f1`
403AC_DEFINE_UNQUOTED(MAJOR_VERSION, $vers, [Major version number.])
404vers=`echo ${VERSION}.0.0 | cut -d. -f2`
405AC_DEFINE_UNQUOTED(MINOR_VERSION, $vers, [Minor version number.])
406vers=`echo ${VERSION}.0.0 | cut -d. -f3`
407AC_DEFINE_UNQUOTED(BUGFIX_VERSION, $vers, [Bugfix version number.])
408
409dnl -----------------------------------------------------------------------
410
411AC_CONFIG_FILES([
412   Makefile
413   nlopt.pc
414   api/Makefile
415   util/Makefile
416   octave/Makefile
417   direct/Makefile
418   cdirect/Makefile
419   stogo/Makefile
420   praxis/Makefile
421   luksan/Makefile
422   crs/Makefile
423   mlsl/Makefile
424   mma/Makefile
425   cobyla/Makefile
426   newuoa/Makefile
427   neldermead/Makefile
428   auglag/Makefile
429   bobyqa/Makefile
430   isres/Makefile
431   slsqp/Makefile
432   esch/Makefile
433   test/Makefile
434   swig/Makefile
435   swig/nlopt.scm
436])
437
438AC_OUTPUT
439