xref: /netbsd-src/external/lgpl3/mpfr/dist/acinclude.m4 (revision 9ddb6ab554e70fb9bbd90c3d96b812bc57755a14)
1dnl  MPFR specific autoconf macros
2
3dnl  Copyright 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4dnl  Contributed by the Arenaire and Cacao projects, INRIA.
5dnl
6dnl  This file is part of the GNU MPFR Library.
7dnl
8dnl  The GNU MPFR Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of the GNU Lesser General Public License as published
10dnl  by the Free Software Foundation; either version 3 of the License, or (at
11dnl  your option) any later version.
12dnl
13dnl  The GNU MPFR Library is distributed in the hope that it will be useful, but
14dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16dnl  License for more details.
17dnl
18dnl  You should have received a copy of the GNU Lesser General Public License
19dnl  along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20dnl  http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21dnl  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
22
23dnl  autoconf 2.60 is necessary because of the use of AC_PROG_SED.
24dnl  The following line allows the autoconf wrapper (when installed)
25dnl  to work as expected.
26dnl  If you change the required version, please update README.dev too!
27AC_PREREQ(2.60)
28
29dnl ------------------------------------------------------------
30dnl You must put in MPFR_CONFIGS everything which configure MPFR
31dnl except:
32dnl   -everything dealing with CC and CFLAGS in particular the ABI
33dnl   but the IEEE-754 specific flags must be set here.
34dnl   -GMP's linkage.
35dnl   -Libtool stuff.
36dnl   -Handling of special arguments of MPFR's configure.
37AC_DEFUN([MPFR_CONFIGS],
38[
39AC_REQUIRE([AC_OBJEXT])
40AC_REQUIRE([MPFR_CHECK_LIBM])
41AC_REQUIRE([AC_HEADER_TIME])
42AC_REQUIRE([AC_CANONICAL_HOST])
43
44AC_CHECK_HEADER([limits.h],, AC_MSG_ERROR([limits.h not found]))
45AC_CHECK_HEADER([float.h],,  AC_MSG_ERROR([float.h not found]))
46AC_CHECK_HEADER([string.h],, AC_MSG_ERROR([string.h not found]))
47
48dnl Check for locales
49AC_CHECK_HEADERS([locale.h])
50
51dnl Check for wide characters (wchar_t and wint_t)
52AC_CHECK_HEADERS([wchar.h])
53
54dnl Check for stdargs
55AC_CHECK_HEADER([stdarg.h],[AC_DEFINE([HAVE_STDARG],1,[Define if stdarg])],
56  [AC_CHECK_HEADER([varargs.h],,
57    AC_MSG_ERROR([stdarg.h or varargs.h not found]))])
58
59dnl sys/fpu.h - MIPS specific
60AC_CHECK_HEADERS([sys/time.h sys/fpu.h])
61
62dnl Check how to get `alloca'
63AC_FUNC_ALLOCA
64
65dnl SIZE_MAX macro
66gl_SIZE_MAX
67
68dnl va_copy macro
69AC_MSG_CHECKING([how to copy va_list])
70AC_LINK_IFELSE([AC_LANG_PROGRAM([[
71#include <stdarg.h>
72]], [[
73   va_list ap1, ap2;
74   va_copy(ap1, ap2);
75]])], [
76   AC_MSG_RESULT([va_copy])
77   AC_DEFINE(HAVE_VA_COPY)
78], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
79#include <stdarg.h>
80]], [[
81   va_list ap1, ap2;
82   __va_copy(ap1, ap2);
83]])], [AC_DEFINE([HAVE___VA_COPY]) AC_MSG_RESULT([__va_copy])],
84   [AC_MSG_RESULT([memcpy])])])
85
86dnl FIXME: The functions memmove, memset and strtol are really needed by
87dnl MPFR, but if they are implemented as macros, this is also OK (in our
88dnl case).  So, we do not return an error, but their tests are currently
89dnl useless.
90dnl gettimeofday is not defined for MinGW
91AC_CHECK_FUNCS([memmove memset setlocale strtol gettimeofday])
92
93dnl Check for IEEE-754 switches on Alpha
94case $host in
95alpha*-*-*)
96  saved_CFLAGS="$CFLAGS"
97  AC_CACHE_CHECK([for IEEE-754 switches], mpfr_cv_ieee_switches, [
98  if test -n "$GCC"; then
99    mpfr_cv_ieee_switches="-mfp-rounding-mode=d -mieee-with-inexact"
100  else
101    mpfr_cv_ieee_switches="-fprm d -ieee_with_inexact"
102  fi
103  CFLAGS="$CFLAGS $mpfr_cv_ieee_switches"
104  AC_TRY_COMPILE(,,, mpfr_cv_ieee_switches="none")
105  ])
106  if test "$mpfr_cv_ieee_switches" = "none"; then
107    CFLAGS="$saved_CFLAGS"
108  else
109    CFLAGS="$saved_CFLAGS $mpfr_cv_ieee_switches"
110  fi
111esac
112
113dnl check for long long
114AC_CHECK_TYPE([long long int],
115   AC_DEFINE(HAVE_LONG_LONG, 1, [Define if compiler supports long long]),,)
116
117dnl intmax_t is C99
118AC_CHECK_TYPES([intmax_t])
119if test "$ac_cv_type_intmax_t" = yes; then
120  AC_CACHE_CHECK([for working INTMAX_MAX], mpfr_cv_have_intmax_max, [
121    AC_TRY_COMPILE([#include <stdint.h>], [intmax_t x = INTMAX_MAX;],
122      mpfr_cv_have_intmax_max=yes, mpfr_cv_have_intmax_max=no)
123  ])
124  if test "$mpfr_cv_have_intmax_max" = "yes"; then
125    AC_DEFINE(MPFR_HAVE_INTMAX_MAX,1,[Define if you have a working INTMAX_MAX.])
126  fi
127fi
128
129AC_CHECK_TYPE( [union fpc_csr],
130   AC_DEFINE(HAVE_FPC_CSR,1,[Define if union fpc_csr is available]), ,
131[
132#if HAVE_SYS_FPU_H
133#  include <sys/fpu.h>
134#endif
135])
136
137dnl Check for fesetround
138AC_CACHE_CHECK([for fesetround], mpfr_cv_have_fesetround, [
139saved_LIBS="$LIBS"
140LIBS="$LIBS $MPFR_LIBM"
141AC_TRY_LINK([#include <fenv.h>], [fesetround(FE_TONEAREST);],
142  mpfr_cv_have_fesetround=yes, mpfr_cv_have_fesetround=no)
143LIBS="$saved_LIBS"
144])
145if test "$mpfr_cv_have_fesetround" = "yes"; then
146  AC_DEFINE(MPFR_HAVE_FESETROUND,1,[Define if you have the `fesetround' function via the <fenv.h> header file.])
147fi
148
149dnl Check for gcc float-conversion bug; if need be, -ffloat-store is used to
150dnl force the conversion to the destination type when a value is stored to
151dnl a variable (see ISO C99 standard 5.1.2.3#13, 6.3.1.5#2, 6.3.1.8#2). This
152dnl is important concerning the exponent range. Note that this doesn't solve
153dnl the double-rounding problem.
154if test -n "$GCC"; then
155  AC_CACHE_CHECK([for gcc float-conversion bug], mpfr_cv_gcc_floatconv_bug, [
156  saved_LIBS="$LIBS"
157  LIBS="$LIBS $MPFR_LIBM"
158  AC_TRY_RUN([
159#include <float.h>
160#ifdef MPFR_HAVE_FESETROUND
161#include <fenv.h>
162#endif
163static double get_max (void);
164int main() {
165  double x = 0.5;
166  double y;
167  int i;
168  for (i = 1; i <= 11; i++)
169    x *= x;
170  if (x != 0)
171    return 1;
172#ifdef MPFR_HAVE_FESETROUND
173  /* Useful test for the G4 PowerPC */
174  fesetround(FE_TOWARDZERO);
175  x = y = get_max ();
176  x *= 2.0;
177  if (x != y)
178    return 1;
179#endif
180  return 0;
181}
182static double get_max (void) { static volatile double d = DBL_MAX; return d; }
183  ], [mpfr_cv_gcc_floatconv_bug="no"],
184     [mpfr_cv_gcc_floatconv_bug="yes, use -ffloat-store"],
185     [mpfr_cv_gcc_floatconv_bug="cannot test, use -ffloat-store"])
186  LIBS="$saved_LIBS"
187  ])
188  if test "$mpfr_cv_gcc_floatconv_bug" != "no"; then
189    CFLAGS="$CFLAGS -ffloat-store"
190  fi
191fi
192
193dnl Check if denormalized numbers are supported
194AC_CACHE_CHECK([for denormalized numbers], mpfr_cv_have_denorms, [
195AC_TRY_RUN([
196#include <math.h>
197#include <stdio.h>
198int main() {
199  double x = 2.22507385850720138309e-308;
200  fprintf (stderr, "%e\n", x / 2.0);
201  return 2.0 * (x / 2.0) != x;
202}
203], mpfr_cv_have_denorms=yes, mpfr_cv_have_denorms=no, mpfr_cv_have_denorms=no)
204])
205if test "$mpfr_cv_have_denorms" = "yes"; then
206  AC_DEFINE(HAVE_DENORMS,1,[Define if denormalized floats work.])
207fi
208
209dnl Check whether NAN != NAN (as required by the IEEE-754 standard,
210dnl but not by the ISO C standard). For instance, this is false with
211dnl MIPSpro 7.3.1.3m under IRIX64. By default, assume this is true.
212AC_CACHE_CHECK([if NAN == NAN], mpfr_cv_nanisnan, [
213AC_TRY_RUN([
214#include <stdio.h>
215#include <math.h>
216#ifndef NAN
217# define NAN (0.0/0.0)
218#endif
219int main() {
220  double d;
221  d = NAN;
222  return d != d;
223}
224], [mpfr_cv_nanisnan="yes"],
225   [mpfr_cv_nanisnan="no"],
226   [mpfr_cv_nanisnan="cannot test, assume no"])
227])
228if test "$mpfr_cv_nanisnan" = "yes"; then
229  AC_DEFINE(MPFR_NANISNAN,1,[Define if NAN == NAN.])
230  AC_MSG_WARN([The test NAN != NAN is false. The probable reason is that])
231  AC_MSG_WARN([your compiler optimizes floating-point expressions in an])
232  AC_MSG_WARN([unsafe way because some option, such as -ffast-math or])
233  AC_MSG_WARN([-fast (depending on the compiler), has been used.  You])
234  AC_MSG_WARN([should NOT use such an option, otherwise MPFR functions])
235  AC_MSG_WARN([such as mpfr_get_d and mpfr_set_d may return incorrect])
236  AC_MSG_WARN([results on special FP numbers (e.g. NaN or signed zeros).])
237  AC_MSG_WARN([If you did not use such an option, please send us a bug])
238  AC_MSG_WARN([report so that we can try to find a workaround for your])
239  AC_MSG_WARN([platform and/or document the behavior.])
240fi
241
242dnl Check if the chars '0' to '9' are consecutive values
243AC_MSG_CHECKING([if charset has consecutive values])
244AC_RUN_IFELSE(AC_LANG_PROGRAM([[
245char *number = "0123456789";
246char *lower  = "abcdefghijklmnopqrstuvwxyz";
247char *upper  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
248]],[[
249 int i;
250 unsigned char *p;
251 for (p = (unsigned char*) number, i = 0; i < 9; i++)
252   if ( (*p)+1 != *(p+1) ) return 1;
253 for (p = (unsigned char*) lower, i = 0; i < 25; i++)
254   if ( (*p)+1 != *(p+1) ) return 1;
255 for (p = (unsigned char*) upper, i = 0; i < 25; i++)
256   if ( (*p)+1 != *(p+1) ) return 1;
257]]), [AC_MSG_RESULT(yes)],[
258 AC_MSG_RESULT(no)
259 AC_DEFINE(MPFR_NO_CONSECUTIVE_CHARSET,1,[Charset is not consecutive])
260], [AC_MSG_RESULT(can not test)])
261
262dnl Must be checked with the LIBM
263dnl but we don't want to add the LIBM to MPFR dependency.
264dnl Can't use AC_CHECK_FUNCS since the function may be in LIBM but
265dnl not exported in math.h
266saved_LIBS="$LIBS"
267LIBS="$LIBS $MPFR_LIBM"
268dnl AC_CHECK_FUNCS([round trunc floor ceil nearbyint])
269AC_MSG_CHECKING(for math/round)
270AC_LINK_IFELSE([AC_LANG_PROGRAM([[
271#include <math.h>
272int f (double (*func)(double)) { return 0;}
273]], [[
274 double a = 17.42;
275 a = f (round);
276 return 0;
277]])], [
278   AC_MSG_RESULT(yes)
279   AC_DEFINE(HAVE_ROUND, 1,[Have ISO-C99 round function])
280],[AC_MSG_RESULT(no)])
281
282AC_MSG_CHECKING(for math/trunc)
283AC_LINK_IFELSE([AC_LANG_PROGRAM([[
284#include <math.h>
285int f (double (*func)(double)) { return 0;}
286]], [[
287 double a = 17.42;
288 a = f(trunc);
289 return 0;
290]])], [
291   AC_MSG_RESULT(yes)
292   AC_DEFINE(HAVE_TRUNC, 1,[Have ISO-C99 trunc function])
293],[AC_MSG_RESULT(no)])
294
295AC_MSG_CHECKING(for math/floor)
296AC_LINK_IFELSE([AC_LANG_PROGRAM([[
297#include <math.h>
298int f (double (*func)(double)) { return 0;}
299]], [[
300 double a = 17.42;
301 a = f(floor);
302 return 0;
303]])], [
304   AC_MSG_RESULT(yes)
305   AC_DEFINE(HAVE_FLOOR, 1,[Have ISO-C99 floor function])
306],[AC_MSG_RESULT(no)])
307
308AC_MSG_CHECKING(for math/ceil)
309AC_LINK_IFELSE([AC_LANG_PROGRAM([[
310#include <math.h>
311int f (double (*func)(double)) { return 0;}
312]], [[
313 double a = 17.42;
314 a = f(ceil);
315 return 0;
316]])], [
317   AC_MSG_RESULT(yes)
318   AC_DEFINE(HAVE_CEIL, 1,[Have ISO-C99 ceil function])
319],[AC_MSG_RESULT(no)])
320
321AC_MSG_CHECKING(for math/rint)
322AC_LINK_IFELSE([AC_LANG_PROGRAM([[
323#include <math.h>
324int f (double (*func)(double)) { return 0;}
325]], [[
326 double a = 17.42;
327 a = f(nearbyint);
328 return 0;
329]])], [
330   AC_MSG_RESULT(yes)
331   AC_DEFINE(HAVE_NEARBYINT, 1,[Have ISO-C99 rint function])
332],[AC_MSG_RESULT(no)])
333
334LIBS="$saved_LIBS"
335
336dnl Now try to check the long double format
337MPFR_C_LONG_DOUBLE_FORMAT
338
339dnl Check if thread-local variables are supported.
340dnl At least two problems can occur in practice:
341dnl 1. The compilation fails, e.g. because the compiler doesn't know
342dnl    about the __thread keyword.
343dnl 2. The compilation succeeds, but the system doesn't support TLS or
344dnl    there is some ld configuration problem. One of the effects can
345dnl    be that thread-local variables always evaluate to 0. So, it is
346dnl    important to run the test below.
347if test "$enable_thread_safe" = yes; then
348AC_CACHE_CHECK([for TLS support], mpfr_cv_working_tls, [
349saved_CPPFLAGS="$CPPFLAGS"
350# The -I$srcdir is necessary when objdir is different from srcdir.
351CPPFLAGS="$CPPFLAGS -I$srcdir"
352AC_RUN_IFELSE([
353#define MPFR_USE_THREAD_SAFE 1
354#include "mpfr-thread.h"
355MPFR_THREAD_ATTR int x = 17;
356int main() {
357  return x != 17;
358}
359  ], [mpfr_cv_working_tls="yes"],
360     [AC_MSG_RESULT(no)
361      AC_MSG_ERROR([please configure with --disable-thread-safe])],
362     [mpfr_cv_working_tls="cannot test, assume yes"])
363CPPFLAGS="$saved_CPPFLAGS"
364])
365fi
366])
367
368
369dnl  MPFR_C_LONG_DOUBLE_FORMAT
370dnl  -------------------------
371dnl  Determine the format of a long double.
372dnl
373dnl  The object file is grepped, so as to work when cross compiling.  A
374dnl  start and end sequence is included to avoid false matches, and
375dnl  allowance is made for the desired data crossing an "od -b" line
376dnl  boundary.  The test number is a small integer so it should appear
377dnl  exactly, no rounding or truncation etc.
378dnl
379dnl  "od -b" is supported even by Unix V7, and the awk script used doesn't
380dnl  have functions or anything, so even an "old" awk should suffice.
381dnl
382dnl  The 10-byte IEEE extended format is generally padded to either 12 or 16
383dnl  bytes for alignment purposes.  The SVR4 i386 ABI is 12 bytes, or i386
384dnl  gcc -m128bit-long-double selects 16 bytes.  IA-64 is 16 bytes in LP64
385dnl  mode, or 12 bytes in ILP32 mode.  The first 10 bytes is the relevant
386dnl  part in all cases (big and little endian).
387dnl
388dnl  Enhancements:
389dnl
390dnl  Could match more formats, but no need to worry until there's code
391dnl  wanting to use them.
392dnl
393dnl  Don't want to duplicate the double matching from GMP_C_DOUBLE_FORMAT,
394dnl  perhaps we should merge with that macro, to match data formats
395dnl  irrespective of the C type in question.  Or perhaps just let the code
396dnl  use DOUBLE macros when sizeof(double)==sizeof(long double).
397
398AC_DEFUN([MPFR_C_LONG_DOUBLE_FORMAT],
399[AC_REQUIRE([AC_PROG_CC])
400AC_REQUIRE([AC_PROG_AWK])
401AC_REQUIRE([AC_OBJEXT])
402AC_CHECK_TYPES([long double])
403AC_CACHE_CHECK([format of `long double' floating point],
404                mpfr_cv_c_long_double_format,
405[mpfr_cv_c_long_double_format=unknown
406if test "$ac_cv_type_long_double" != yes; then
407  mpfr_cv_c_long_double_format="not available"
408else
409  cat >conftest.c <<\EOF
410[
411/* "before" is 16 bytes to ensure there's no padding between it and "x".
412   We're not expecting any "long double" bigger than 16 bytes or with
413   alignment requirements stricter than 16 bytes.  */
414struct {
415  char         before[16];
416  long double  x;
417  char         after[8];
418} foo = {
419  { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0',
420    '\001', '\043', '\105', '\147', '\211', '\253', '\315', '\357' },
421  -123456789.0,
422  { '\376', '\334', '\272', '\230', '\166', '\124', '\062', '\020' }
423};
424]
425EOF
426  mpfr_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC 2>&1"
427  if AC_TRY_EVAL(mpfr_compile); then
428    cat >conftest.awk <<\EOF
429[
430BEGIN {
431  found = 0
432}
433
434# got[] holds a sliding window of bytes read the input.  got[0] is the most
435# recent byte read, and got[31] the oldest byte read, so when looking to
436# match some data the indices are "reversed".
437#
438{
439  for (f = 2; f <= NF; f++)
440    {
441      # new byte, shift others up
442      for (i = 31; i >= 0; i--)
443        got[i+1] = got[i];
444      got[0] = $f;
445
446      # end sequence
447      if (got[7] != "376") continue
448      if (got[6] != "334") continue
449      if (got[5] != "272") continue
450      if (got[4] != "230") continue
451      if (got[3] != "166") continue
452      if (got[2] != "124") continue
453      if (got[1] != "062") continue
454      if (got[0] != "020") continue
455
456      # start sequence, with 8-byte body
457      if (got[23] == "001" && \
458          got[22] == "043" && \
459          got[21] == "105" && \
460          got[20] == "147" && \
461          got[19] == "211" && \
462          got[18] == "253" && \
463          got[17] == "315" && \
464          got[16] == "357")
465        {
466          saw = " (" got[15] \
467                 " " got[14] \
468                 " " got[13] \
469                 " " got[12] \
470                 " " got[11] \
471                 " " got[10] \
472                 " " got[9]  \
473                 " " got[8] ")"
474
475          if (got[15] == "301" && \
476              got[14] == "235" && \
477              got[13] == "157" && \
478              got[12] == "064" && \
479              got[11] == "124" && \
480              got[10] == "000" && \
481              got[9] ==  "000" && \
482              got[8] ==  "000")
483            {
484              print "IEEE double, big endian"
485              found = 1
486              exit
487            }
488
489          if (got[15] == "000" && \
490              got[14] == "000" && \
491              got[13] == "000" && \
492              got[12] == "124" && \
493              got[11] == "064" && \
494              got[10] == "157" && \
495              got[9] ==  "235" && \
496              got[8] ==  "301")
497            {
498              print "IEEE double, little endian"
499              found = 1
500              exit
501            }
502        }
503
504      # start sequence, with 12-byte body
505      if (got[27] == "001" && \
506          got[26] == "043" && \
507          got[25] == "105" && \
508          got[24] == "147" && \
509          got[23] == "211" && \
510          got[22] == "253" && \
511          got[21] == "315" && \
512          got[20] == "357")
513        {
514          saw = " (" got[19] \
515                 " " got[18] \
516                 " " got[17] \
517                 " " got[16] \
518                 " " got[15] \
519                 " " got[14] \
520                 " " got[13] \
521                 " " got[12] \
522                 " " got[11] \
523                 " " got[10] \
524                 " " got[9]  \
525                 " " got[8] ")"
526
527          if (got[19] == "000" && \
528              got[18] == "000" && \
529              got[17] == "000" && \
530              got[16] == "000" && \
531              got[15] == "240" && \
532              got[14] == "242" && \
533              got[13] == "171" && \
534              got[12] == "353" && \
535              got[11] == "031" && \
536              got[10] == "300")
537            {
538              print "IEEE extended, little endian"
539              found = 1
540              exit
541            }
542        }
543
544      # start sequence, with 16-byte body
545      if (got[31] == "001" && \
546          got[30] == "043" && \
547          got[29] == "105" && \
548          got[28] == "147" && \
549          got[27] == "211" && \
550          got[26] == "253" && \
551          got[25] == "315" && \
552          got[24] == "357")
553        {
554          saw = " (" got[23] \
555                 " " got[22] \
556                 " " got[21] \
557                 " " got[20] \
558                 " " got[19] \
559                 " " got[18] \
560                 " " got[17] \
561                 " " got[16] \
562                 " " got[15] \
563                 " " got[14] \
564                 " " got[13] \
565                 " " got[12] \
566                 " " got[11] \
567                 " " got[10] \
568                 " " got[9]  \
569                 " " got[8] ")"
570
571          if (got[23] == "000" && \
572              got[22] == "000" && \
573              got[21] == "000" && \
574              got[20] == "000" && \
575              got[19] == "240" && \
576              got[18] == "242" && \
577              got[17] == "171" && \
578              got[16] == "353" && \
579              got[15] == "031" && \
580              got[14] == "300")
581            {
582              print "IEEE extended, little endian"
583              found = 1
584              exit
585            }
586
587          if (got[23] == "300" && \
588              got[22] == "031" && \
589              got[21] == "326" && \
590              got[20] == "363" && \
591              got[19] == "105" && \
592              got[18] == "100" && \
593              got[17] == "000" && \
594              got[16] == "000" && \
595              got[15] == "000" && \
596              got[14] == "000" && \
597              got[13] == "000" && \
598              got[12] == "000" && \
599              got[11] == "000" && \
600              got[10] == "000" && \
601              got[9]  == "000" && \
602              got[8]  == "000")
603            {
604              print "IEEE quad, big endian"
605              found = 1
606              exit
607            }
608
609          if (got[23] == "000" && \
610              got[22] == "000" && \
611              got[21] == "000" && \
612              got[20] == "000" && \
613              got[19] == "000" && \
614              got[18] == "000" && \
615              got[17] == "000" && \
616              got[16] == "000" && \
617              got[15] == "000" && \
618              got[14] == "000" && \
619              got[13] == "100" && \
620              got[12] == "105" && \
621              got[11] == "363" && \
622              got[10] == "326" && \
623              got[9]  == "031" && \
624	      got[8]  == "300")
625            {
626              print "IEEE quad, little endian"
627              found = 1
628              exit
629            }
630
631          if (got[23] == "301" && \
632              got[22] == "235" && \
633              got[21] == "157" && \
634              got[20] == "064" && \
635              got[19] == "124" && \
636              got[18] == "000" && \
637              got[17] == "000" && \
638              got[16] == "000" && \
639              got[15] == "000" && \
640              got[14] == "000" && \
641              got[13] == "000" && \
642              got[12] == "000" && \
643              got[11] == "000" && \
644              got[10] == "000" && \
645              got[9]  == "000" && \
646              got[8]  == "000")
647            {
648              print "possibly double-double, big endian"
649              found = 1
650              exit
651            }
652        }
653    }
654}
655
656END {
657  if (! found)
658    print "unknown", saw
659}
660]
661EOF
662    mpfr_cv_c_long_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
663    case $mpfr_cv_c_long_double_format in
664    unknown*)
665      echo "cannot match anything, conftest.$OBJEXT contains" >&AC_FD_CC
666      od -b conftest.$OBJEXT >&AC_FD_CC
667      ;;
668    esac
669  else
670    AC_MSG_WARN([oops, cannot compile test program])
671  fi
672fi
673rm -f conftest*
674])
675
676AH_VERBATIM([HAVE_LDOUBLE],
677[/* Define one of the following to 1 for the format of a `long double'.
678   If your format is not among these choices, or you don't know what it is,
679   then leave all undefined.
680   IEEE_EXT is the 10-byte IEEE extended precision format.
681   IEEE_QUAD is the 16-byte IEEE quadruple precision format.
682   LITTLE or BIG is the endianness.  */
683#undef HAVE_LDOUBLE_IEEE_EXT_LITTLE
684#undef HAVE_LDOUBLE_IEEE_QUAD_BIG])
685
686case $mpfr_cv_c_long_double_format in
687  "IEEE extended, little endian")
688    AC_DEFINE(HAVE_LDOUBLE_IEEE_EXT_LITTLE, 1)
689    ;;
690  "IEEE quad, big endian")
691    AC_DEFINE(HAVE_LDOUBLE_IEEE_QUAD_BIG, 1)
692    ;;
693  "IEEE quad, little endian")
694    AC_DEFINE(HAVE_LDOUBLE_IEEE_QUAD_LITTLE, 1)
695    ;;
696  "possibly double-double, big endian")
697    AC_MSG_WARN([This format is known on GCC/PowerPC platforms,])
698    AC_MSG_WARN([but due to GCC PR26374, we can't test further.])
699    AC_MSG_WARN([You can safely ignore this warning, though.])
700    # Since we are not sure, we do not want to define a macro.
701    ;;
702  unknown* | "not available")
703    ;;
704  *)
705    AC_MSG_WARN([oops, unrecognised float format: $mpfr_cv_c_long_double_format])
706    ;;
707esac
708])
709
710
711dnl  MPFR_CHECK_LIBM
712dnl  ---------------
713dnl  Determine a math library -lm to use.
714
715AC_DEFUN([MPFR_CHECK_LIBM],
716[AC_REQUIRE([AC_CANONICAL_HOST])
717AC_SUBST(MPFR_LIBM,'')
718case $host in
719  *-*-beos* | *-*-cygwin* | *-*-pw32*)
720    # According to libtool AC CHECK LIBM, these systems don't have libm
721    ;;
722  *-*-solaris*)
723    # On Solaris the math functions new in C99 are in -lm9x.
724    # FIXME: Do we need -lm9x as well as -lm, or just instead of?
725    AC_CHECK_LIB(m9x, main, MPFR_LIBM="-lm9x")
726    AC_CHECK_LIB(m,   main, MPFR_LIBM="$MPFR_LIBM -lm")
727    ;;
728  *-ncr-sysv4.3*)
729    # FIXME: What does -lmw mean?  Libtool AC CHECK LIBM does it this way.
730    AC_CHECK_LIB(mw, _mwvalidcheckl, MPFR_LIBM="-lmw")
731    AC_CHECK_LIB(m, main, MPFR_LIBM="$MPFR_LIBM -lm")
732    ;;
733  *)
734    AC_CHECK_LIB(m, main, MPFR_LIBM="-lm")
735    ;;
736esac
737])
738
739
740dnl  MPFR_LD_SEARCH_PATHS_FIRST
741dnl  --------------------------
742
743AC_DEFUN([MPFR_LD_SEARCH_PATHS_FIRST],
744[case "$LD $LDFLAGS" in
745  *-Wl,-search_paths_first*) ;;
746  *) AC_MSG_CHECKING([if the compiler understands -Wl,-search_paths_first])
747     saved_LDFLAGS="$LDFLAGS"
748     LDFLAGS="-Wl,-search_paths_first $LDFLAGS"
749     AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
750       [AC_MSG_RESULT(yes)],
751       [AC_MSG_RESULT(no)]
752        LDFLAGS="$saved_LDFLAGS")
753     ;;
754 esac
755])
756
757
758dnl  GMP_C_ATTRIBUTE_MODE
759dnl  --------------------
760dnl  Introduced in gcc 2.2, but perhaps not in all Apple derived versions.
761dnl  Needed for mpfr-longlong.h; this is currently necessary for s390.
762dnl
763dnl  TODO: Replace this with a cleaner type size detection, as this
764dnl  solution only works with gcc and assumes CHAR_BIT == 8. Probably use
765dnl  <stdint.h>, and <http://gcc.gnu.org/viewcvs/trunk/config/stdint.m4>
766dnl  as a fallback.
767
768AC_DEFUN([GMP_C_ATTRIBUTE_MODE],
769[AC_CACHE_CHECK([whether gcc __attribute__ ((mode (XX))) works],
770               gmp_cv_c_attribute_mode,
771[AC_TRY_COMPILE([typedef int SItype __attribute__ ((mode (SI)));], ,
772 gmp_cv_c_attribute_mode=yes, gmp_cv_c_attribute_mode=no)
773])
774if test $gmp_cv_c_attribute_mode = yes; then
775 AC_DEFINE(HAVE_ATTRIBUTE_MODE, 1,
776 [Define to 1 if the compiler accepts gcc style __attribute__ ((mode (XX)))])
777fi
778])
779
780
781dnl  MPFR_FUNC_GMP_PRINTF_SPEC
782dnl  ------------------------------------
783dnl  MPFR_FUNC_GMP_PRINTF_SPEC(spec, type, [includes], [if-true], [if-false])
784dnl  Check if gmp_sprintf supports the conversion specification 'spec'
785dnl  with type 'type'.
786dnl  Expand 'if-true' if printf supports 'spec', 'if-false' otherwise.
787
788AC_DEFUN([MPFR_FUNC_GMP_PRINTF_SPEC],[
789AC_MSG_CHECKING(if gmp_printf supports "%$1")
790AC_RUN_IFELSE([AC_LANG_PROGRAM([[
791#include <stdio.h>
792$3
793#include <gmp.h>
794]], [[
795  char s[256];
796  $2 a = 17;
797
798  if (gmp_sprintf (s, "(%0.0$1)(%d)", a, 42) == -1) return 1;
799  return (strcmp (s, "(17)(42)") != 0);
800]])],
801  [AC_MSG_RESULT(yes)
802  $4],
803  [AC_MSG_RESULT(no)
804  $5])
805])
806
807
808dnl MPFR_CHECK_PRINTF_SPEC
809dnl ----------------------
810dnl Check if gmp_printf supports some optional length modifiers.
811dnl Defined symbols are negative to shorten the gcc command line.
812
813AC_DEFUN([MPFR_CHECK_PRINTF_SPEC], [
814AC_REQUIRE([MPFR_CONFIGS])dnl
815if test "$ac_cv_type_intmax_t" = yes; then
816 MPFR_FUNC_GMP_PRINTF_SPEC([jd], [intmax_t], [
817#ifdef HAVE_STDINT_H
818# include <stdint.h>
819#endif
820#ifdef HAVE_INTTYPES_H
821# include <inttypes.h>
822#endif
823         ],,
824         [AC_DEFINE([NPRINTF_J], 1, [gmp_printf cannot read intmax_t])])
825fi
826
827MPFR_FUNC_GMP_PRINTF_SPEC([hhd], [char], [
828#include <gmp.h>
829         ],,
830         [AC_DEFINE([NPRINTF_HH], 1, [gmp_printf cannot use 'hh' length modifier])])
831
832MPFR_FUNC_GMP_PRINTF_SPEC([lld], [long long int], [
833#include <gmp.h>
834         ],,
835         [AC_DEFINE([NPRINTF_LL], 1, [gmp_printf cannot read long long int])])
836
837MPFR_FUNC_GMP_PRINTF_SPEC([Lf], [long double], [
838#include <gmp.h>
839         ],,
840         [AC_DEFINE([NPRINTF_L], 1, [gmp_printf cannot read long double])])
841
842MPFR_FUNC_GMP_PRINTF_SPEC([td], [ptrdiff_t], [
843#if defined (__cplusplus)
844#include <cstddef>
845#else
846#include <stddef.h>
847#endif
848#include "gmp.h"
849    ],,
850    [AC_DEFINE([NPRINTF_T], 1, [gmp_printf cannot read ptrdiff_t])])
851])
852