1# Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
2#
3# This file is part of GNU MPC.
4#
5# GNU MPC is free software; you can redistribute it and/or modify it under
6# the terms of the GNU Lesser General Public License as published by the
7# Free Software Foundation; either version 3 of the License, or (at your
8# option) any later version.
9#
10# GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
11# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13# more details.
14#
15# You should have received a copy of the GNU Lesser General Public License
16# along with this program. If not, see http://www.gnu.org/licenses/ .
17
18
19#                                               -*- Autoconf -*-
20# Process this file with autoconf to produce a configure script.
21
22AC_PREREQ(2.61)
23AC_INIT(mpc, 1.0.1, mpc-discuss@lists.gforge.inria.fr)
24AC_CONFIG_SRCDIR([src/mpc-impl.h])
25AC_CONFIG_HEADER([config.h])
26
27AM_INIT_AUTOMAKE([1.9 -Wall -Werror])
28AM_MAINTAINER_MODE
29
30USER_CC=$CC
31USER_CFLAGS=$CFLAGS
32
33AC_CANONICAL_HOST
34AC_CONFIG_MACRO_DIR([m4])
35
36
37# Extra arguments to configure
38AC_ARG_WITH([mpfr_include],
39            [AC_HELP_STRING([--with-mpfr-include=DIR],
40                            [MPFR include directory])],
41            [CPPFLAGS="-I$withval $CPPFLAGS"])
42AC_ARG_WITH([mpfr_lib],
43            [AC_HELP_STRING([--with-mpfr-lib=DIR],
44                            [MPFR lib directory])],
45            [LDFLAGS="-L$withval $LDFLAGS"])
46AC_ARG_WITH([mpfr],
47            [AC_HELP_STRING([--with-mpfr=DIR],
48                           [MPFR install directory])],
49            [
50            if test -z "$with_mpfr_include" -a -z "$with_mpfr_lib" ; then
51               CPPFLAGS="-I$withval/include $CPPFLAGS"
52               LDFLAGS="-L$withval/lib $LDFLAGS"
53            else
54               AC_MSG_FAILURE([Do not use --with-mpfr and --with-mpfr-include/--with-mpfr-lib options simultaneously.])
55            fi
56            ])
57AC_ARG_WITH([gmp_include],
58            [AC_HELP_STRING([--with-gmp-include=DIR],
59                            [GMP include directory])],
60            [CPPFLAGS="-I$withval $CPPFLAGS"])
61AC_ARG_WITH([gmp_lib],
62            [AC_HELP_STRING([--with-gmp-lib=DIR],
63                            [GMP lib directory])],
64            [LDFLAGS="-L$withval $LDFLAGS"])
65AC_ARG_WITH([gmp],
66            [AC_HELP_STRING([--with-gmp=DIR],
67                           [GMP install directory])],
68            [
69            if test -z "$with_gmp_lib" -a -z "$with_gmp_include" ; then
70               CPPFLAGS="-I$withval/include $CPPFLAGS"
71               LDFLAGS="-L$withval/lib $LDFLAGS"
72            else
73               AC_MSG_FAILURE([Do not use --with-gmp and --with-gmp-include/--with-gmp-lib options simultaneously.])
74            fi
75            ])
76AC_ARG_ENABLE([logging],
77             [AC_HELP_STRING([--enable-logging],
78                             [enable logging of function calls to stderr (default = no)])],
79             [case $enableval in
80                 yes) AS_IF([test "x$enable_shared" = "xno"],
81                            AC_MSG_ERROR([Logging works only with shared libraries; do not mix --enable-logging and --disable-shared])) ;;
82                 no)  ;;
83                 *)   AC_MSG_ERROR([Bad value for --enable-logging: Use yes or no]) ;;
84              esac
85             ]
86             )
87AC_ARG_ENABLE([valgrind-tests],
88             [AC_HELP_STRING([--enable-valgrind-tests],
89                             [run checks through valgrind (default = no)])],
90             [case $enableval in
91                 yes) gl_VALGRIND_TESTS ;;
92                 no)  ;;
93                 *)   AC_MSG_ERROR([Bad value for --enable-valgrind-tests: Use yes or no]) ;;
94              esac
95             ]
96             )
97
98# Check for CC and CFLAGS in gmp.h unless the user specified one of them
99# look for EGREP and SED here, see continued problem
100# at http://lists.gforge.inria.fr/pipermail/mpc-discuss/2012-January/001056.html
101AC_PROG_EGREP
102AC_PROG_SED
103if test -z "$USER_CC" && test -z "$USER_CFLAGS"; then
104   MPC_GMP_CC_CFLAGS
105fi
106
107# Setup CC and CFLAGS
108AC_PROG_CC
109AC_LANG(C)
110
111# automake 1.12 seems to require this, but automake 1.11 doesn't recognize it
112m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
113
114# Set up LibTool
115LT_INIT
116
117# Check GMP Header
118AC_MSG_CHECKING(for gmp.h)
119AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
120#include "gmp.h"
121]])],[AC_MSG_RESULT(yes)],[
122 AC_MSG_RESULT(no)
123 AC_MSG_ERROR([gmp.h cannot be found or is unusable.])
124])
125
126# Check (only in development versions) if the compiler accepts warning
127# flags and add them to CFLAGS
128# Note: don't do this if the user defined CFLAGS, since adding new flags
129# might override the user's settings, see
130# http://lists.gforge.inria.fr/pipermail/mpc-discuss/2012-May/001115.html
131if test -z "$USER_CFLAGS"; then
132   MPC_C_CHECK_WARNINGCFLAGS
133fi
134
135
136# Checks for header files.
137AC_HEADER_STDC
138AC_CHECK_HEADERS([locale.h inttypes.h stdint.h limits.h unistd.h sys/time.h])
139AC_HEADER_TIME
140MPC_COMPLEX_H
141
142# Checks for typedefs, structures, and compiler characteristics.
143AC_C_CONST
144AC_TYPE_SIZE_T
145
146# Checks for libraries.
147AC_CHECK_FUNCS([gettimeofday localeconv setlocale])
148AC_CHECK_FUNCS([dup dup2],,
149        [AC_DEFINE([MPC_NO_STREAM_REDIRECTION],1,[Do not check mpc_out_str on stdout])])
150
151AC_CHECK_LIB([gmp], [__gmpz_init],
152             [LIBS="-lgmp $LIBS"],
153             [AC_MSG_ERROR([libgmp not found or uses a different ABI (including static vs shared).])])
154
155AC_MSG_CHECKING(for MPFR)
156LIBS="-lmpfr $LIBS"
157AC_LINK_IFELSE(
158        [AC_LANG_PROGRAM(
159                [[#include "mpfr.h"]],
160                [[mpfr_t x;  mpfr_init(x) ; mpfr_clear(x);]]
161        )],
162        [AC_MSG_RESULT(yes)],
163        [
164        AC_MSG_RESULT(no)
165        AC_MSG_ERROR([libmpfr not found or uses a different ABI (including static vs shared).])
166        ])
167
168# Check for a recent GMP
169# We only guarantee that with a *functional* and recent enough GMP version,
170# MPC will compile; we do not guarantee that GMP will compile.
171# In particular fat builds are broken in GMP 4.3.2 and GMP 5.0.0
172# (at least on 64-bit Core 2 under GNU/Linux),
173# see http://gmplib.org/list-archives/gmp-bugs/2011-August/002345.html.
174AC_MSG_CHECKING(for recent GMP)
175AC_COMPILE_IFELSE(
176        [AC_LANG_SOURCE(
177        [[
178#include "gmp.h"
179#if (__GNU_MP_VERSION*100 + __GNU_MP_VERSION_MINOR*10 + __GNU_MP_VERSION_PATCHLEVEL < 432)
180# error "Minimal GMP version is 4.3.2"
181error
182#endif
183        ]])],
184        [AC_MSG_RESULT(yes)],
185        [
186        AC_MSG_RESULT(no)
187        AC_MSG_ERROR([GMP version >= 4.3.2 required])
188        ])
189
190# Check for a recent MPFR: we require MPFR 2.4.2 so that the tests
191# in log.dat pass
192# The same remark as above for GMP applies.
193AC_MSG_CHECKING(for recent MPFR)
194AC_COMPILE_IFELSE(
195        [AC_LANG_SOURCE(
196        [[
197#include "mpfr.h"
198#if (MPFR_VERSION < MPFR_VERSION_NUM (2,4,2))
199# error "Minimal MPFR version is 2.4.2"
200error
201#endif
202        ]])],
203        [AC_MSG_RESULT(yes)],
204        [
205         AC_MSG_RESULT(no)
206         AC_MSG_ERROR([MPFR version >= 2.4.2 required])
207         ])
208
209# Check for logging feature
210AS_IF([test "x$enable_logging" = "xyes"],
211       [AC_CHECK_HEADERS([dlfcn.h])
212        AC_CHECK_LIB([dl],[dlsym],
213           [
214            AC_DEFINE(HAVE_LIBDL, 1, [Library dl present])
215            LIBS="-ldl $LIBS"
216            AC_TYPE_INTPTR_T
217            AC_LIBOBJ([logging])
218            AC_SUBST([MPC_LOG_H],[src/mpc-log.h])
219           ],
220           [AC_MSG_ERROR([Library dl not found, logging impossible])])
221       ]
222     )
223
224# Configs for Windows DLLs
225AC_SUBST(MPC_LDFLAGS)
226AC_LIBTOOL_WIN32_DLL
227case $host in
228  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
229     MPC_WINDOWS
230esac
231
232# Checks for gcc version, result in variables MPC_GCC etc. inside config.log
233AX_GCC_VERSION
234AC_DEFINE_UNQUOTED([MPC_GCC], ["$GCC"], [Gcc yes or no])
235AC_DEFINE_UNQUOTED([MPC_CC], ["$CC"], [C compiler])
236AC_DEFINE_UNQUOTED([MPC_GCC_VERSION], ["$GCC_VERSION"], [Version of gcc])
237
238# Looks for svn version if the version string contains "dev"
239MPC_SVNVERSION
240
241AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile doc/Makefile])
242AC_OUTPUT
243