summaryrefslogtreecommitdiff
path: root/configure.in
blob: fa537a4783d1534168d2810653ed80eca0557e88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
dnl Process this file with autoconf to produce a configure script.

AC_COPYRIGHT([
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software
Foundation, Inc.

This file is part of the MPFR Library.

The MPFR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.

The MPFR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU Lesser General Public License
along with the MPFR Library; see the file COPYING.LIB.  If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
])

dnl If MPFR becomes GNU MPFR, change the MPFR below to GNU MPFR
dnl Add check-news when it checks for more than 15 lines
AC_INIT(MPFR, 2.2.0)
AM_INIT_AUTOMAKE([no-define dist-zip dist-bzip2])
AM_MAINTAINER_MODE

dnl AC_CONFIG_HEADERS([mpfrconf.h:mpfrconf.in])

dnl Extra arguments to configure
AC_ARG_WITH(gmp_include, 
   [  --with-gmp-include=DIR  GMP include directory ], 
   with_gmp_include=$withval)
AC_ARG_WITH(gmp_lib, 
   [  --with-gmp-lib=DIR      GMP lib directory ], 
   with_gmp_lib=$withval)
AC_ARG_WITH(gmp_build, 
   [  --with-gmp-build=DIR    GMP build directory], 
   [with_gmp_include=$withval/ with_gmp_lib=$withval/.libs
    if test -r $withval/Makefile ; then
     GMP_CFLAGS=`grep -w "CFLAGS =" $withval/Makefile | sed 's/CFLAGS = //'`
     GMP_CC=`grep -w "CC =" $withval/Makefile | sed 's/CC = //'`
    fi
   ])
AC_ARG_WITH(gmp, 
   [  --with-gmp=DIR          GMP install directory ], 
   with_gmp_include=$withval/include with_gmp_lib=$withval/lib)

AC_ARG_WITH(irix64, 
   [  --with-irix64=on/off    Irix 32/64 bits support ], 
   with_irix64=$withval, with_irix64=off)

AC_ARG_ENABLE(assert,
   [  --enable-assert         enable ASSERT checking [[default=no]]],
   [ case $enableval in
      yes) AC_DEFINE([WANT_ASSERT],1,[Want assertion]) ;;
      no)  ;;
      full) AC_DEFINE([WANT_ASSERT],2,[Want assertion]) 
            AC_DEFINE([CHECK_AGAINST_SUB1],1,[Check against sub1]) ;;
      *) AC_MSG_ERROR([bad value for --enable-assert: yes, no or full]) ;;
     esac])
AC_ARG_ENABLE(logging,
   [  --enable-logging        enable MPFR Logging [[default=no]]],
   [ disable_gcc_format_warning=yes
     case $enableval in
      yes) AC_DEFINE([MPFR_USE_LOGGING],1,[Log what MPFR does]) ;;
      no)  ;;
      *)   AC_MSG_ERROR([bad value for --enable-logging: yes or no]) ;;
     esac])
AC_ARG_ENABLE(thread-safe,
   [  --enable-thread-safe    Build MPFR as thread safe [[default=no]]],
   [ case $enableval in
      yes) AC_DEFINE([MPFR_USE_THREAD_SAFE],1,[Build MPFR as thread safe]) ;;
      no)  ;;
      *)   AC_MSG_ERROR([bad value for --enable-thread-safe: yes or no]) ;;
     esac])

test_CFLAGS=${CFLAGS+set}

dnl  Same as in gmp acinclude.m4, though currently we're using the normal
dnl  config.sub, so the additional exact cpu types don't arise.
dnl define(X86_PATTERN,[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-*]])


dnl Check for CC and CFLAGS
dnl 
if test -n "$CFLAGS" || test -n "$CC" ; then
 user_redefine_cc=yes
fi
AC_PROG_CC
AC_LANG(C)

dnl Check for GMP CFLAGS and CC (More optimized for the target)
dnl But they may be invalid, so we must check them first
dnl Don't redefine it if the user force them!
if test -n "$GMP_CFLAGS" && test -z "$user_redefine_cc" ; then
 old_cflags=$CFLAGS
 old_cc=$CC
 CFLAGS=$GMP_CFLAGS
 CC=$GMP_CC
 AC_MSG_CHECKING(for CC=$GMP_CC and CFLAGS=$GMP_CFLAGS)
 AC_RUN_IFELSE([AC_LANG_SOURCE([[
  int main() { return 0; }
 ]])], [
    AC_MSG_RESULT(yes)
 ], [
    AC_MSG_RESULT(no)
    CFLAGS=$old_cflags
    CC=$old_cc
  ], [
    AC_MSG_RESULT([can't test])
    CFLAGS=$old_cflags
    CC=$old_cc
  ])
  dnl CC may have change. Recheck for GCC.
  GCC=
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifndef __GNUC__
# error "GCC Not Found"
#endif
  ]])], [
  GCC=yes
  ])
fi

dnl Check if compiler is ICC, and if such a case, disable GCC
dnl And add some specific flags.
dnl Don't add Warnings Flags (Otherwise you'll get more than 20000 warnings).
dnl Add -long_double flags? Don't use -pc64 !
AC_MSG_CHECKING(for ICC)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#if !defined(__ICC)
# error "ICC Not Found"
#endif
]], [[]])],[AC_MSG_RESULT(yes)
 GCC=
 CFLAGS="-fp_port -mp -wd1572 -wd265 -wd186 -wd239 $CFLAGS"
],[AC_MSG_RESULT(no)])

dnl If compiler is gcc, then use some specific flags.
dnl But don't touch user other flags.
if test "$test_CFLAGS" != set && test -n "$GCC"; then
  CFLAGS="-Wall -Wmissing-prototypes $CFLAGS"
  if test -n "$disable_gcc_format_warning" ; then
   CFLAGS="$CFLAGS -Wno-format"
  fi
fi

AM_C_PROTOTYPES
AC_CANONICAL_HOST
AC_CHECK_OS
AC_CHECK_MACHTYPE

dnl Set the OS-dependent flags.
case $OS_TYPE in
	HP-UX*)
		if test -n "$GCC"; then
		  LDFLAGS="-Xlinker +allowunsats $LDFLAGS"
		fi
		;;
	IRIX64)
		if [[ "$irix64" = "on" ]]; then
		  CFLAGS ="-mabi=64 $CFLAGS"
		else
		  CFLAGS ="-mabi=n32 $CFLAGS"
		fi
		;;
esac

dnl Update CPPFLAGS.
if test -d "$with_gmp_include"; then
  CPPFLAGS="$CPPFLAGS -I$with_gmp_include"
else
  with_gmp_include=
fi

AC_C_CONST
AC_C_VOLATILE
MPFR_CONFIGS

dnl Check for GMP
AC_MSG_CHECKING(for gmp.h)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "gmp.h"
]], [[]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
     AC_MSG_ERROR([gmp.h may be missing ${with_gmp_include:+in $with_gmp_include}])
])

AC_MSG_CHECKING(for recent GMP)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "gmp.h"
#if (__GNU_MP_VERSION*100+__GNU_MP_VERSION_MINOR*10 < 410)
# error "min GMP version is 4.1.0"
#endif
]], [[]])],[AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)
     AC_MSG_ERROR([GMP 4.1.0 min required])
])

dnl Check if we can use internal header files of GMP.
AC_MSG_CHECKING(for gmp internal files)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "gmp.h"
#include "gmp-impl.h"
#include "longlong.h"
]], [[]])],[AC_MSG_RESULT(yes)
     AC_DEFINE([MPFR_HAVE_GMP_IMPL],1,[Use GMP Internal Files])
     dnl Check for valid BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB
     AC_MSG_CHECKING(for valid BITS_PER_MP_LIMB and BYTES_PER_MP_LIMB)
     AC_TRY_RUN([
#include <limits.h>
#include "gmp.h"
#include "gmp-impl.h"
int main()
{
  return BITS_PER_MP_LIMB == BYTES_PER_MP_LIMB * CHAR_BIT
         && sizeof(mp_limb_t) == BYTES_PER_MP_LIMB ? 0 : 1;
}
	], AC_MSG_RESULT(yes),
	  [AC_MSG_RESULT(no)
	   AC_MSG_ERROR([BITS_PER_MP_LIMB or BYTES_PER_MP_LIMB are incorrect.
You probably need to change some of the GMP or MPFR compile options:
MPFR doesn't currently do as many architecture checks as GMP, so the
default target architecture may be different, hence the error.])],
	AC_MSG_RESULT([can't test])
   )
   ],[AC_MSG_RESULT(no) AC_FUNC_ALLOCA
])

dnl AC_CHECK_LIB doesn't do what we want
AC_MSG_CHECKING(for GMP library)
if test -r "$with_gmp_lib/libgmp.a"; then
  LIBS="$with_gmp_lib/libgmp.a $LIBS"
elif test -r "$with_gmp_lib/libgmp.so"; then
  LIBS="$with_gmp_lib/libgmp.so $LIBS"
elif test -r "$with_gmp_lib/libgmp.lib"; then
  LIBS="$with_gmp_lib/libgmp.lib $LIBS"
else
  if test -d "$with_gmp_lib"; then
    LDFLAGS="-L$with_gmp_lib $LDFLAGS"
  fi  
  LIBS="-lgmp $LIBS"
fi

dnl FIXME: If AC_RUN_IFELSE failed try with AC_LINK_IFELSE?
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include "gmp.h"
int main() { return !gmp_version; }
  ]])], [
    AC_MSG_RESULT(yes)
  ], [
    AC_MSG_RESULT(no)
    AC_MSG_ERROR(libgmp not found)
  ], [
    AC_MSG_RESULT([can't test])
  ])

dnl Check for corresponding 'gmp.h' and libgmp.a
AC_MSG_CHECKING(if gmp.h version and libgmp version are the same)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <string.h>
#include "gmp.h"
int main()
{
  char buffer[100];
  if (__GNU_MP_VERSION_PATCHLEVEL != 0)
    sprintf (buffer, "%d.%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR,
	    __GNU_MP_VERSION_PATCHLEVEL);
  else
    sprintf (buffer, "%d.%d", __GNU_MP_VERSION, __GNU_MP_VERSION_MINOR);
  printf ("(%s/%s) ", buffer, gmp_version);
  return (strcmp (buffer, gmp_version) != 0) ? 1 : 0;
}
]])], AC_MSG_RESULT(yes),
   [AC_MSG_RESULT(no)
    AC_MSG_ERROR(['gmp.h' and 'libgmp' have different versions! you have to properly reinstall GMP.])],
    AC_MSG_RESULT([can't test])
)

dnl Check if Function mpn_sub_nc is in the header AND in the library!
dnl Since this function may or may not be really defined
AC_MSG_CHECKING(for GMP's mpn_sub_nc)
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include "gmp.h"
#ifdef MPFR_HAVE_GMP_IMPL
# include "gmp-impl.h"
#endif 
mp_limb_t f() {mp_limb_t x=2; return mpn_sub_nc(&x, &x, &x, 1, 0); }
int main () { f (); return 0; }
]], [[]])],[
    AC_MSG_RESULT(yes) 
    AC_DEFINE([MPFR_HAVE_MPN_SUB_NC],1,[Function mpn_sub_nc is available])
  ], [
    AC_MSG_RESULT(no)
  ], [
    AC_MSG_RESULT([can't test])
  ])

dnl Configs for Windows DLLs.
dnl libtool requires "-no-undefined" for win32 dll
AC_DISABLE_SHARED
AC_LIBTOOL_WIN32_DLL
case $host in
  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
   AC_MSG_CHECKING(for DLL/static GMP)
   if test "$enable_shared" = yes; then
     LDFLAGS="$LDFLAGS -no-undefined"
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "gmp.h"
#if !__GMP_LIBGMP_DLL
# error "Dead man"
#endif
     ]], [[]])],[AC_MSG_RESULT(DLL)],[ 
  AC_MSG_RESULT(static)
  AC_MSG_ERROR([gmp.h isn't a DLL: use --enable-static --disable-shared]) ])
   else
     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include "gmp.h"
#if __GMP_LIBGMP_DLL
# error "Dead man"
#endif
     ]], [[]])],[AC_MSG_RESULT(static)],[
  AC_MSG_RESULT(DLL) 
  AC_MSG_ERROR([gmp.h is a DLL: use --disable-static --enable-shared]) ])
  fi
  ;;
esac
dnl Finally set up LibTool
AC_PROG_LIBTOOL

dnl Recent autoconf creates AC_DEFINEs of PACKAGE_VERSION etc, unfortunately
dnl those -D defines in $DEFS conflict with the same defines in config.h from
dnl GMP.  Unless or until autoconf gives us a better way for two closely
dnl related packages to cooperate, use this hack to get rid of them from $DEFS
dnl here.
dnl
dnl We remove also many MACROS which are unused by MPFR.
if test -f confdefs.h; then
  sed '/#define PACKAGE_/d' <confdefs.h >confdefs.tmp
  sed '/#define HAVE_STRING/d' <confdefs.tmp >confdefs.h
  sed '/#define HAVE_ALLOCA /d' <confdefs.h >confdefs.tmp
  sed '/#define HAVE_DLFCN_H/d' <confdefs.tmp >confdefs.h
  sed '/#define HAVE_MEM/d' <confdefs.h >confdefs.tmp
  sed '/#define STDC_HEADERS/d' <confdefs.tmp >confdefs.h
  sed '/#define HAVE_STRTOL/d' <confdefs.h >confdefs.tmp
  sed '/#define HAVE_STDLIB_H/d' <confdefs.tmp >confdefs.h
  sed '/#define HAVE_UNISTD_H/d' <confdefs.h >confdefs.tmp
  sed '/#define HAVE_STDC_HEADERS/d' <confdefs.tmp >confdefs.h
  sed '/#define HAVE_LONG_DOUBLE/d' <confdefs.h >confdefs.tmp
  sed '/#define HAVE_SYS_STAT_H/d' <confdefs.tmp >confdefs.h
  sed '/#define HAVE_SYS_TYPES_H/d' <confdefs.h >confdefs.tmp
  sed '/#define PROTOTYPES/d' <confdefs.tmp >confdefs.h
  sed '/#define __PROTOTYPES/d' <confdefs.h >confdefs.tmp

  mv confdefs.tmp confdefs.h
fi

AC_SUBST(INCLUDES)
AC_SUBST(LDADD)
AC_SUBST(LDFLAGS)
AC_SUBST(CFLAGS)
AC_CONFIG_FILES([Makefile tests/Makefile])
AC_OUTPUT

dnl NEWS README AUTHORS Changelog