Upload Tizen:Base source
[external/gmp.git] / acinclude.m4
1 dnl  GMP specific autoconf macros
2
3
4 dnl  Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 Free Software
5 dnl  Foundation, Inc.
6 dnl
7 dnl  This file is part of the GNU MP Library.
8 dnl
9 dnl  The GNU MP Library is free software; you can redistribute it and/or modify
10 dnl  it under the terms of the GNU Lesser General Public License as published
11 dnl  by the Free Software Foundation; either version 3 of the License, or (at
12 dnl  your option) any later version.
13 dnl
14 dnl  The GNU MP Library is distributed in the hope that it will be useful, but
15 dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
17 dnl  License for more details.
18 dnl
19 dnl  You should have received a copy of the GNU Lesser General Public License
20 dnl  along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
21
22
23 dnl  Some tests use, or must delete, the default compiler output.  The
24 dnl  possible filenames are based on what autoconf looks for, namely
25 dnl
26 dnl    a.out - normal unix style
27 dnl    b.out - i960 systems, including gcc there
28 dnl    a.exe - djgpp
29 dnl    a_out.exe - OpenVMS DEC C called via GNV wrapper (gnv.sourceforge.net)
30 dnl    conftest.exe - various DOS compilers
31
32
33 define(IA64_PATTERN,
34 [[ia64*-*-* | itanium-*-* | itanium2-*-*]])
35
36 dnl  Need to be careful not to match m6811, m6812, m68hc11 and m68hc12, all
37 dnl  of which config.sub accepts.  (Though none of which are likely to work
38 dnl  with GMP.)
39 dnl
40 define(M68K_PATTERN,
41 [[m68k-*-* | m68[0-9][0-9][0-9]-*-*]])
42
43 define(POWERPC64_PATTERN,
44 [[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-* | powerpc970-*-* | power[3-9]-*-*]])
45
46 define(X86_PATTERN,
47 [[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])
48
49 define(X86_64_PATTERN,
50 [[athlon64-*-* | pentium4-*-* | atom-*-* | core2-*-* | corei-*-* | x86_64-*-* | nano-*-*]])
51
52 dnl  GMP_FAT_SUFFIX(DSTVAR, DIRECTORY)
53 dnl  ---------------------------------
54 dnl  Emit code to set shell variable DSTVAR to the suffix for a fat binary
55 dnl  routine from DIRECTORY.  DIRECTORY can be a shell expression like $foo
56 dnl  etc.
57 dnl
58 dnl  The suffix is directory separators / or \ changed to underscores, and
59 dnl  if there's more than one directory part, then the first is dropped.
60 dnl
61 dnl  For instance,
62 dnl
63 dnl      x86         ->  x86
64 dnl      x86/k6      ->  k6
65 dnl      x86/k6/mmx  ->  k6_mmx
66
67 define(GMP_FAT_SUFFIX,
68 [[$1=`echo $2 | sed -e '/\//s:^[^/]*/::' -e 's:[\\/]:_:g'`]])
69
70
71 dnl  GMP_REMOVE_FROM_LIST(listvar,item)
72 dnl  ----------------------------------
73 dnl  Emit code to remove any occurrence of ITEM from $LISTVAR.  ITEM can be a
74 dnl  shell expression like $foo if desired.
75
76 define(GMP_REMOVE_FROM_LIST,
77 [remove_from_list_tmp=
78 for remove_from_list_i in $[][$1]; do
79   if test $remove_from_list_i = [$2]; then :;
80   else
81      remove_from_list_tmp="$remove_from_list_tmp $remove_from_list_i"
82   fi
83 done
84 [$1]=$remove_from_list_tmp
85 ])
86
87
88 dnl  GMP_STRIP_PATH(subdir)
89 dnl  ----------------------
90 dnl  Strip entries */subdir from $path and $fat_path.
91
92 define(GMP_STRIP_PATH,
93 [GMP_STRIP_PATH_VAR(path, [$1])
94 GMP_STRIP_PATH_VAR(fat_path, [$1])
95 ])
96
97 define(GMP_STRIP_PATH_VAR,
98 [tmp_path=
99 for i in $[][$1]; do
100   case $i in
101     */[$2]) ;;
102     *) tmp_path="$tmp_path $i" ;;
103   esac
104 done
105 [$1]="$tmp_path"
106 ])
107
108
109 dnl  GMP_INCLUDE_GMP_H
110 dnl  -----------------
111 dnl  Expand to the right way to #include gmp-h.in.  This must be used
112 dnl  instead of gmp.h, since that file isn't generated until the end of the
113 dnl  configure.
114 dnl
115 dnl  Dummy value for GMP_LIMB_BITS is enough
116 dnl  for all current configure-time uses of gmp.h.
117
118 define(GMP_INCLUDE_GMP_H,
119 [[#define __GMP_WITHIN_CONFIGURE 1   /* ignore template stuff */
120 #define GMP_NAIL_BITS $GMP_NAIL_BITS
121 #define GMP_LIMB_BITS 123
122 $DEFN_LONG_LONG_LIMB
123 #include "$srcdir/gmp-h.in"]
124 ])
125
126
127 dnl  GMP_HEADER_GETVAL(NAME,FILE)
128 dnl  ----------------------------
129 dnl  Expand at autoconf time to the value of a "#define NAME" from the given
130 dnl  FILE.  The regexps here aren't very rugged, but are enough for gmp.
131 dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
132
133 define(GMP_HEADER_GETVAL,
134 [patsubst(patsubst(
135 esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
136 [^.*$1[         ]+],[]),
137 [[
138         ]*$],[])])
139
140
141 dnl  GMP_VERSION
142 dnl  -----------
143 dnl  The gmp version number, extracted from the #defines in gmp-h.in at
144 dnl  autoconf time.  Two digits like 3.0 if patchlevel <= 0, or three digits
145 dnl  like 3.0.1 if patchlevel > 0.
146
147 define(GMP_VERSION,
148 [GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl
149 .GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl
150 .GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])
151
152
153 dnl  GMP_SUBST_CHECK_FUNCS(func,...)
154 dnl  ------------------------------
155 dnl  Setup an AC_SUBST of HAVE_FUNC_01 for each argument.
156
157 AC_DEFUN([GMP_SUBST_CHECK_FUNCS],
158 [m4_if([$1],,,
159 [_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01)
160 GMP_SUBST_CHECK_FUNCS(m4_shift($@))])])
161
162 dnl  Called: _GMP_SUBST_CHECK_FUNCS(cachevar,substvar)
163 AC_DEFUN([_GMP_SUBST_CHECK_FUNCS],
164 [case $[$1] in
165 yes) AC_SUBST([$2],1) ;;
166 no)  [$2]=0 ;;
167 esac
168 ])
169
170
171 dnl  GMP_SUBST_CHECK_HEADERS(foo.h,...)
172 dnl  ----------------------------------
173 dnl  Setup an AC_SUBST of HAVE_FOO_H_01 for each argument.
174
175 AC_DEFUN([GMP_SUBST_CHECK_HEADERS],
176 [m4_if([$1],,,
177 [_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]),
178 HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01)
179 GMP_SUBST_CHECK_HEADERS(m4_shift($@))])])
180
181 dnl  Called: _GMP_SUBST_CHECK_HEADERS(cachevar,substvar)
182 AC_DEFUN([_GMP_SUBST_CHECK_HEADERS],
183 [case $[$1] in
184 yes) AC_SUBST([$2],1) ;;
185 no)  [$2]=0 ;;
186 esac
187 ])
188
189
190 dnl  GMP_COMPARE_GE(A1,B1, A2,B2, ...)
191 dnl  ---------------------------------
192 dnl  Compare two version numbers A1.A2.etc and B1.B2.etc.  Set
193 dnl  $gmp_compare_ge to yes or no according to the result.  The A parts
194 dnl  should be variables, the B parts fixed numbers.  As many parts as
195 dnl  desired can be included.  An empty string in an A part is taken to be
196 dnl  zero, the B parts should be non-empty and non-zero.
197 dnl
198 dnl  For example,
199 dnl
200 dnl      GMP_COMPARE($major,10, $minor,3, $subminor,1)
201 dnl
202 dnl  would test whether $major.$minor.$subminor is greater than or equal to
203 dnl  10.3.1.
204
205 AC_DEFUN([GMP_COMPARE_GE],
206 [gmp_compare_ge=no
207 GMP_COMPARE_GE_INTERNAL($@)
208 ])
209
210 AC_DEFUN([GMP_COMPARE_GE_INTERNAL],
211 [ifelse(len([$3]),0,
212 [if test -n "$1" && test "$1" -ge $2; then
213   gmp_compare_ge=yes
214 fi],
215 [if test -n "$1"; then
216   if test "$1" -gt $2; then
217     gmp_compare_ge=yes
218   else
219     if test "$1" -eq $2; then
220       GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@)))
221     fi
222   fi
223 fi])
224 ])
225
226
227 dnl  GMP_PROG_AR
228 dnl  -----------
229 dnl  GMP additions to $AR.
230 dnl
231 dnl  A cross-"ar" may be necessary when cross-compiling since the build
232 dnl  system "ar" might try to interpret the object files to build a symbol
233 dnl  table index, hence the use of AC_CHECK_TOOL.
234 dnl
235 dnl  A user-selected $AR is always left unchanged.  AC_CHECK_TOOL is still
236 dnl  run to get the "checking" message printed though.
237 dnl
238 dnl  If extra flags are added to AR, then ac_cv_prog_AR and
239 dnl  ac_cv_prog_ac_ct_AR are set too, since libtool (cvs 2003-03-31 at
240 dnl  least) will do an AC_CHECK_TOOL and that will AR from one of those two
241 dnl  cached variables.  (ac_cv_prog_AR is used if there's an ac_tool_prefix,
242 dnl  or ac_cv_prog_ac_ct_AR is used otherwise.)  FIXME: This is highly
243 dnl  dependent on autoconf internals, perhaps it'd work to put our extra
244 dnl  flags into AR_FLAGS instead.
245 dnl
246 dnl  $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru".  The
247 dnl  latter fails when libtool goes into piecewise mode and is unlucky
248 dnl  enough to have two same-named objects in separate pieces, as happens
249 dnl  for instance to random.o (and others) on vax-dec-ultrix4.5.  Naturally
250 dnl  a user-selected $AR_FLAGS is left unchanged.
251 dnl
252 dnl  For reference, $ARFLAGS is used by automake (1.8) for its ".a" archive
253 dnl  file rules.  This doesn't get used by the piecewise linking, so we
254 dnl  leave it at the default "cru".
255 dnl
256 dnl  FIXME: Libtool 1.5.2 has its own arrangements for "cq", but that version
257 dnl  is broken in other ways.  When we can upgrade, remove the forcible
258 dnl  AR_FLAGS=cq.
259
260 AC_DEFUN([GMP_PROG_AR],
261 [dnl  Want to establish $AR before libtool initialization.
262 AC_BEFORE([$0],[AC_PROG_LIBTOOL])
263 gmp_user_AR=$AR
264 AC_CHECK_TOOL(AR, ar, ar)
265 if test -z "$gmp_user_AR"; then
266                         eval arflags=\"\$ar${abi1}_flags\"
267   test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\"
268   if test -n "$arflags"; then
269     AC_MSG_CHECKING([for extra ar flags])
270     AR="$AR $arflags"
271     ac_cv_prog_AR="$AR $arflags"
272     ac_cv_prog_ac_ct_AR="$AR $arflags"
273     AC_MSG_RESULT([$arflags])
274   fi
275 fi
276 if test -z "$AR_FLAGS"; then
277   AR_FLAGS=cq
278 fi
279 ])
280
281
282 dnl  GMP_PROG_M4
283 dnl  -----------
284 dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
285 dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
286 dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
287 dnl  AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
288 dnl  good enough.
289 dnl
290 dnl  See mpn/asm-defs.m4 for details on the known bad m4s.
291
292 AC_DEFUN([GMP_PROG_M4],
293 [AC_ARG_VAR(M4,[m4 macro processor])
294 AC_CACHE_CHECK([for suitable m4],
295                 gmp_cv_prog_m4,
296 [if test -n "$M4"; then
297   gmp_cv_prog_m4="$M4"
298 else
299   cat >conftest.m4 <<\EOF
300 dnl  Must protect this against being expanded during autoconf m4!
301 dnl  Dont put "dnl"s in this as autoconf will flag an error for unexpanded
302 dnl  macros.
303 [define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
304 ``bad: $][# not supported (SunOS /usr/bin/m4)
305 '')ifelse(eval(89),89,`define(t2,Y)',
306 `bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
307 ')ifelse(t1`'t2,YY,`good
308 ')]
309 EOF
310 dnl ' <- balance the quotes for emacs sh-mode
311   echo "trying m4" >&AC_FD_CC
312   gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
313   echo "$gmp_tmp_val" >&AC_FD_CC
314   if test "$gmp_tmp_val" = good; then
315     gmp_cv_prog_m4="m4"
316   else
317     IFS="${IFS=         }"; ac_save_ifs="$IFS"; IFS=":"
318 dnl $ac_dummy forces splitting on constant user-supplied paths.
319 dnl POSIX.2 word splitting is done only on the output of word expansions,
320 dnl not every word.  This closes a longstanding sh security hole.
321     ac_dummy="$PATH:/usr/5bin"
322     for ac_dir in $ac_dummy; do
323       test -z "$ac_dir" && ac_dir=.
324       echo "trying $ac_dir/m4" >&AC_FD_CC
325       gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
326       echo "$gmp_tmp_val" >&AC_FD_CC
327       if test "$gmp_tmp_val" = good; then
328         gmp_cv_prog_m4="$ac_dir/m4"
329         break
330       fi
331     done
332     IFS="$ac_save_ifs"
333     if test -z "$gmp_cv_prog_m4"; then
334       AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
335     fi
336   fi
337   rm -f conftest.m4
338 fi])
339 M4="$gmp_cv_prog_m4"
340 AC_SUBST(M4)
341 ])
342
343
344 dnl  GMP_M4_M4WRAP_SPURIOUS
345 dnl  ----------------------
346 dnl  Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4.
347 dnl
348 dnl  The following systems have been seen with the problem.
349 dnl
350 dnl  - Unicos alpha, but its assembler doesn't seem to mind.
351 dnl  - MacOS X Darwin, its assembler fails.
352 dnl  - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores
353 dnl    the bad last line since it doesn't have a newline.
354 dnl  - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind.
355 dnl  - HP-UX ia64.
356 dnl
357 dnl  Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer
358 dnl  an m4 with a working m4wrap, if it can be found.
359
360 AC_DEFUN([GMP_M4_M4WRAP_SPURIOUS],
361 [AC_REQUIRE([GMP_PROG_M4])
362 AC_CACHE_CHECK([if m4wrap produces spurious output],
363                gmp_cv_m4_m4wrap_spurious,
364 [# hide the d-n-l from autoconf's error checking
365 tmp_d_n_l=d""nl
366 cat >conftest.m4 <<EOF
367 [changequote({,})define(x,)m4wrap({x})$tmp_d_n_l]
368 EOF
369 echo test input is >&AC_FD_CC
370 cat conftest.m4 >&AC_FD_CC
371 tmp_chars=`$M4 conftest.m4 | wc -c`
372 echo produces $tmp_chars chars output >&AC_FD_CC
373 rm -f conftest.m4
374 if test $tmp_chars = 0; then
375   gmp_cv_m4_m4wrap_spurious=no
376 else
377   gmp_cv_m4_m4wrap_spurious=yes
378 fi
379 ])
380 GMP_DEFINE_RAW(["define(<M4WRAP_SPURIOUS>,<$gmp_cv_m4_m4wrap_spurious>)"])
381 ])
382
383
384 dnl  GMP_PROG_NM
385 dnl  -----------
386 dnl  GMP additions to libtool AC_PROG_NM.
387 dnl
388 dnl  Note that if AC_PROG_NM can't find a working nm it still leaves
389 dnl  $NM set to "nm", so $NM can't be assumed to actually work.
390 dnl
391 dnl  A user-selected $NM is always left unchanged.  AC_PROG_NM is still run
392 dnl  to get the "checking" message printed though.
393 dnl
394 dnl  Perhaps it'd be worthwhile checking that nm works, by running it on an
395 dnl  actual object file.  For instance on sparcv9 solaris old versions of
396 dnl  GNU nm don't recognise 64-bit objects.  Checking would give a better
397 dnl  error message than just a failure in later tests like GMP_ASM_W32 etc.
398 dnl
399 dnl  On the other hand it's not really normal autoconf practice to take too
400 dnl  much trouble over detecting a broken set of tools.  And libtool doesn't
401 dnl  do anything at all for say ranlib or strip.  So for now we're inclined
402 dnl  to just demand that the user provides a coherent environment.
403
404 AC_DEFUN([GMP_PROG_NM],
405 [dnl  Make sure we're the first to call AC_PROG_NM, so our extra flags are
406 dnl   used by everyone.
407 AC_BEFORE([$0],[AC_PROG_NM])
408 gmp_user_NM=$NM
409 AC_PROG_NM
410
411 # FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool
412 # defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found.  In this
413 # case run it again to try the native "nm", firstly so that likely locations
414 # are searched, secondly so that -B or -p are added if necessary for BSD
415 # format.  This is necessary for instance on OSF with "./configure
416 # --build=alphaev5-dec-osf --host=alphaev6-dec-osf".
417 #
418 if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then
419   $as_unset lt_cv_path_NM
420   gmp_save_ac_tool_prefix=$ac_tool_prefix
421   ac_tool_prefix=
422   NM=
423   AC_PROG_NM
424   ac_tool_prefix=$gmp_save_ac_tool_prefix
425 fi
426
427 if test -z "$gmp_user_NM"; then
428                         eval nmflags=\"\$nm${abi1}_flags\"
429   test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\"
430   if test -n "$nmflags"; then
431     AC_MSG_CHECKING([for extra nm flags])
432     NM="$NM $nmflags"
433     AC_MSG_RESULT([$nmflags])
434   fi
435 fi
436 ])
437
438
439 dnl  GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS])
440 dnl  --------------------------------------------------------------------
441 dnl  Check if cc+cflags can compile and link.
442 dnl
443 dnl  This test is designed to be run repeatedly with different cc+cflags
444 dnl  selections, so the result is not cached.
445 dnl
446 dnl  For a native build, meaning $cross_compiling == no, we require that the
447 dnl  generated program will run.  This is the same as AC_PROG_CC does in
448 dnl  _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass
449 dnl  a CC/CFLAGS combination that it rejects.
450 dnl
451 dnl  sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel
452 dnl  was booted in 32-bit mode.  The effect of requiring the compiler output
453 dnl  will run is that a plain native "./configure" falls back on ABI=32, but
454 dnl  ABI=64 is still available as a cross-compile.
455 dnl
456 dnl  The various specific problems we try to detect are done in separate
457 dnl  compiles.  Although this is probably a bit slower than one test
458 dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
459 dnl  hence giving the user a clue about why we rejected the compiler.
460
461 AC_DEFUN([GMP_PROG_CC_WORKS],
462 [AC_MSG_CHECKING([compiler $1])
463 gmp_prog_cc_works=yes
464
465 # first see a simple "main()" works, then go on to other checks
466 GMP_PROG_CC_WORKS_PART([$1], [])
467
468 GMP_PROG_CC_WORKS_PART([$1], [function pointer return],
469 [/* The following provokes an internal error from gcc 2.95.2 -mpowerpc64
470    (without -maix64), hence detecting an unusable compiler */
471 void *g() { return (void *) 0; }
472 void *f() { return g(); }
473 ])
474
475 GMP_PROG_CC_WORKS_PART([$1], [cmov instruction],
476 [/* The following provokes an invalid instruction syntax from i386 gcc
477    -march=pentiumpro on Solaris 2.8.  The native sun assembler
478    requires a non-standard syntax for cmov which gcc (as of 2.95.2 at
479    least) doesn't know.  */
480 int n;
481 int cmov () { return (n >= 0 ? n : 0); }
482 ])
483
484 GMP_PROG_CC_WORKS_PART([$1], [double -> ulong conversion],
485 [/* The following provokes a linker invocation problem with gcc 3.0.3
486    on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630".  The -mcpu=630
487    option causes gcc to incorrectly select the 32-bit libgcc.a, not
488    the 64-bit one, and consequently it misses out on the __fixunsdfdi
489    helper (double -> uint64 conversion).  */
490 double d;
491 unsigned long gcc303 () { return (unsigned long) d; }
492 ])
493
494 GMP_PROG_CC_WORKS_PART([$1], [double negation],
495 [/* The following provokes an error from hppa gcc 2.95 under -mpa-risc-2-0 if
496    the assembler doesn't know hppa 2.0 instructions.  fneg is a 2.0
497    instruction, and a negation like this comes out using it.  */
498 double fneg_data;
499 unsigned long fneg () { return -fneg_data; }
500 ])
501
502 GMP_PROG_CC_WORKS_PART([$1], [double -> float conversion],
503 [/* The following makes gcc 3.3 -march=pentium4 generate an SSE2 xmm insn
504    (cvtsd2ss) which will provoke an error if the assembler doesn't recognise
505    those instructions.  Not sure how much of the gmp code will come out
506    wanting sse2, but it's easiest to reject an option we know is bad.  */
507 double ftod_data;
508 float ftod () { return (float) ftod_data; }
509 ])
510
511 GMP_PROG_CC_WORKS_PART([$1], [gnupro alpha ev6 char spilling],
512 [/* The following provokes an internal compiler error from gcc version
513    "2.9-gnupro-99r1" under "-O2 -mcpu=ev6", apparently relating to char
514    values being spilled into floating point registers.  The problem doesn't
515    show up all the time, but has occurred enough in GMP for us to reject
516    this compiler+flags.  */
517 #include <string.h>  /* for memcpy */
518 struct try_t
519 {
520  char dst[2];
521  char size;
522  long d0, d1, d2, d3, d4, d5, d6;
523  char overlap;
524 };
525 struct try_t param[6];
526 int
527 param_init ()
528 {
529  struct try_t *p;
530  memcpy (p, &param[ 2 ], sizeof (*p));
531  memcpy (p, &param[ 2 ], sizeof (*p));
532  p->size = 2;
533  memcpy (p, &param[ 1 ], sizeof (*p));
534  p->dst[0] = 1;
535  p->overlap = 2;
536  memcpy (p, &param[ 3 ], sizeof (*p));
537  p->dst[0] = 1;
538  p->overlap = 8;
539  memcpy (p, &param[ 4 ], sizeof (*p));
540  memcpy (p, &param[ 4 ], sizeof (*p));
541  p->overlap = 8;
542  memcpy (p, &param[ 5 ], sizeof (*p));
543  memcpy (p, &param[ 5 ], sizeof (*p));
544  memcpy (p, &param[ 5 ], sizeof (*p));
545  return 0;
546 }
547 ])
548
549 # __builtin_alloca is not available everywhere, check it exists before
550 # seeing that it works
551 GMP_PROG_CC_WORKS_PART_TEST([$1],[__builtin_alloca availability],
552 [int k; int foo () { __builtin_alloca (k); }],
553   [GMP_PROG_CC_WORKS_PART([$1], [alloca array],
554 [/* The following provokes an internal compiler error from Itanium HP-UX cc
555     under +O2 or higher.  We use this sort of code in mpn/generic/mul_fft.c. */
556 int k;
557 int foo ()
558 {
559   int i, **a;
560   a = __builtin_alloca (k);
561   for (i = 0; i <= k; i++)
562     a[i] = __builtin_alloca (1 << i);
563 }
564 ])])
565
566 GMP_PROG_CC_WORKS_PART([$1], [abs int -> double conversion],
567 [/* The following provokes an internal error from the assembler on
568    power2-ibm-aix4.3.1.0.  gcc -mrios2 compiles to nabs+fcirz, and this
569    results in "Internal error related to the source program domain".
570
571    For reference it seems to be the combination of nabs+fcirz which is bad,
572    not either alone.  This sort of thing occurs in mpz/get_str.c with the
573    way double chars_per_bit_exactly is applied in MPN_SIZEINBASE.  Perhaps
574    if that code changes to a scaled-integer style then we won't need this
575    test.  */
576
577 double fp[1];
578 int x;
579 int f ()
580 {
581   int a;
582   a = (x >= 0 ? x : -x);
583   return a * fp[0];
584 }
585 ])
586
587 GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 1],
588 [/* The following provokes a segfault in the compiler on powerpc-apple-darwin.
589    Extracted from tests/mpn/t-iord_u.c.  Causes Apple's gcc 3.3 build 1640 and
590    1666 to segfault with e.g., -O2 -mpowerpc64.  */
591
592 #if defined (__GNUC__) && ! defined (__cplusplus)
593 typedef unsigned long long t1;typedef t1*t2;
594 static __inline__ t1 e(t2 rp,t2 up,int n,t1 v0)
595 {t1 c,x,r;int i;if(v0){c=1;for(i=1;i<n;i++){x=up[i];r=x+1;rp[i]=r;}}return c;}
596 f(){static const struct{t1 n;t1 src[9];t1 want[9];}d[]={{1,{0},{1}},};t1 got[9];int i;
597 for(i=0;i<1;i++){if(e(got,got,9,d[i].n)==0)h();g(i,d[i].src,d[i].n,got,d[i].want,9);if(d[i].n)h();}}
598 h(){}g(){}
599 #else
600 int dummy;
601 #endif
602 ])
603
604 GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 2],
605 [/* The following provokes an internal compiler error on powerpc-apple-darwin.
606    Extracted from mpz/cfdiv_q_2exp.c.  Causes Apple's gcc 3.3 build 1640 and
607    1666 to get an ICE with -O1 -mpowerpc64.  */
608
609 #if defined (__GNUC__) && ! defined (__cplusplus)
610 f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
611 g(){}
612 #else
613 int dummy;
614 #endif
615 ])
616
617 GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization],
618 [/* The following is mis-compiled by HP ia-64 cc version
619         cc: HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]
620    under "cc +O3", both in +DD32 and +DD64 modes.  The mpn_lshift_com gets
621    inlined and its return value somehow botched to be 0 instead of 1.  This
622    arises in the real mpn_lshift_com in mul_fft.c.  A lower optimization
623    level, like +O2 seems ok.  This code needs to be run to show the problem,
624    but that's fine, the offending cc is a native-only compiler so we don't
625    have to worry about cross compiling.  */
626
627 #if ! defined (__cplusplus)
628 unsigned long
629 lshift_com (rp, up, n, cnt)
630   unsigned long *rp;
631   unsigned long *up;
632   long n;
633   unsigned cnt;
634 {
635   unsigned long retval, high_limb, low_limb;
636   unsigned tnc;
637   long i;
638   tnc = 8 * sizeof (unsigned long) - cnt;
639   low_limb = *up++;
640   retval = low_limb >> tnc;
641   high_limb = low_limb << cnt;
642   for (i = n - 1; i != 0; i--)
643     {
644       low_limb = *up++;
645       *rp++ = ~(high_limb | (low_limb >> tnc));
646       high_limb = low_limb << cnt;
647     }
648   return retval;
649 }
650 int
651 main ()
652 {
653   unsigned long cy, rp[2], up[2];
654   up[0] = ~ 0L;
655   up[1] = 0;
656   cy = lshift_com (rp, up, 2L, 1);
657   if (cy != 1L)
658     return 1;
659   return 0;
660 }
661 #else
662 int
663 main ()
664 {
665   return 0;
666 }
667 #endif
668 ])
669
670 GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization 2],
671 [/* The following is mis-compiled by Intel ia-64 icc version 1.8 under
672     "icc -O3",  After several calls, the function writes parial garbage to
673     the result vector.  Perhaps relates to the chk.a.nc insn.  This code needs
674     to be run to show the problem, but that's fine, the offending cc is a
675     native-only compiler so we don't have to worry about cross compiling.  */
676
677 #if ! defined (__cplusplus)
678 #include <stdlib.h>
679 void
680 lshift_com (rp, up, n, cnt)
681   unsigned long *rp;
682   unsigned long *up;
683   long n;
684   unsigned cnt;
685 {
686   unsigned long high_limb, low_limb;
687   unsigned tnc;
688   long i;
689   up += n;
690   rp += n;
691   tnc = 8 * sizeof (unsigned long) - cnt;
692   low_limb = *--up;
693   high_limb = low_limb << cnt;
694   for (i = n - 1; i != 0; i--)
695     {
696       low_limb = *--up;
697       *--rp = ~(high_limb | (low_limb >> tnc));
698       high_limb = low_limb << cnt;
699     }
700   *--rp = ~high_limb;
701 }
702 int
703 main ()
704 {
705   unsigned long *r, *r2;
706   unsigned long a[88 + 1];
707   long i;
708   for (i = 0; i < 88 + 1; i++)
709     a[i] = ~0L;
710   r = malloc (10000 * sizeof (unsigned long));
711   r2 = r;
712   for (i = 0; i < 528; i += 22)
713     {
714       lshift_com (r2, a,
715                   i / (8 * sizeof (unsigned long)) + 1,
716                   i % (8 * sizeof (unsigned long)));
717       r2 += 88 + 1;
718     }
719   if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
720       r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
721     abort ();
722   return 0;
723 }
724 #else
725 int
726 main ()
727 {
728   return 0;
729 }
730 #endif
731 ])
732
733
734 # A certain _GLOBAL_OFFSET_TABLE_ problem in past versions of gas, tickled
735 # by recent versions of gcc.
736 #
737 if test "$gmp_prog_cc_works" = yes; then
738   case $host in
739     X86_PATTERN)
740       # this problem only arises in PIC code, so don't need to test when
741       # --disable-shared.  We don't necessarily have $enable_shared set to
742       # yes at this point, it will still be unset for the default (which is
743       # yes); hence the use of "!= no".
744       if test "$enable_shared" != no; then
745         GMP_PROG_CC_X86_GOT_EAX_EMITTED([$1],
746           [GMP_ASM_X86_GOT_EAX_OK([$1],,
747             [gmp_prog_cc_works="no, bad gas GOT with eax"])])
748       fi
749       ;;
750   esac
751 fi
752
753 AC_MSG_RESULT($gmp_prog_cc_works)
754 case $gmp_prog_cc_works in
755   yes)
756     [$2]
757     ;;
758   *)
759     [$3]
760     ;;
761 esac
762 ])
763
764 dnl  Called: GMP_PROG_CC_WORKS_PART(CC+CFLAGS,FAIL-MESSAGE [,CODE])
765 dnl  A dummy main() is appended to the CODE given.
766 dnl
767 AC_DEFUN([GMP_PROG_CC_WORKS_PART],
768 [GMP_PROG_CC_WORKS_PART_MAIN([$1],[$2],
769 [$3]
770 [int main () { return 0; }])
771 ])
772
773 dnl  Called: GMP_PROG_CC_WORKS_PART_MAIN(CC+CFLAGS,FAIL-MESSAGE,CODE)
774 dnl  CODE must include a main().
775 dnl
776 AC_DEFUN([GMP_PROG_CC_WORKS_PART_MAIN],
777 [GMP_PROG_CC_WORKS_PART_TEST([$1],[$2],[$3],
778   [],
779   gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2]",
780   gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2][[, program does not run]]")
781 ])
782
783 dnl  Called: GMP_PROG_CC_WORKS_PART_TEST(CC+CFLAGS,TITLE,[CODE],
784 dnl            [ACTION-GOOD],[ACTION-BAD][ACTION-NORUN])
785 dnl
786 AC_DEFUN([GMP_PROG_CC_WORKS_PART_TEST],
787 [if test "$gmp_prog_cc_works" = yes; then
788   # remove anything that might look like compiler output to our "||" expression
789   rm -f conftest* a.out b.out a.exe a_out.exe
790   cat >conftest.c <<EOF
791 [$3]
792 EOF
793   echo "Test compile: [$2]" >&AC_FD_CC
794   gmp_compile="$1 conftest.c >&AC_FD_CC"
795   if AC_TRY_EVAL(gmp_compile); then
796     cc_works_part=yes
797     if test "$cross_compiling" = no; then
798       if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
799       else
800         cc_works_part=norun
801       fi
802     fi
803   else
804     cc_works_part=no
805   fi
806   if test "$cc_works_part" != yes; then
807     echo "failed program was:" >&AC_FD_CC
808     cat conftest.c >&AC_FD_CC
809   fi
810   rm -f conftest* a.out b.out a.exe a_out.exe
811   case $cc_works_part in
812     yes)
813       $4
814       ;;
815     no)
816       $5
817       ;;
818     norun)
819       $6
820       ;;
821   esac
822 fi
823 ])
824
825
826 dnl  GMP_PROG_CC_WORKS_LONGLONG(cc+cflags,[ACTION-YES][,ACTION-NO])
827 dnl  --------------------------------------------------------------
828 dnl  Check that cc+cflags accepts "long long".
829 dnl
830 dnl  This test is designed to be run repeatedly with different cc+cflags
831 dnl  selections, so the result is not cached.
832
833 AC_DEFUN([GMP_PROG_CC_WORKS_LONGLONG],
834 [AC_MSG_CHECKING([compiler $1 has long long])
835 cat >conftest.c <<EOF
836 long long  foo;
837 long long  bar () { return foo; }
838 int main () { return 0; }
839 EOF
840 gmp_prog_cc_works=no
841 gmp_compile="$1 -c conftest.c >&AC_FD_CC"
842 if AC_TRY_EVAL(gmp_compile); then
843   gmp_prog_cc_works=yes
844 else
845   echo "failed program was:" >&AC_FD_CC
846   cat conftest.c >&AC_FD_CC
847 fi
848 rm -f conftest* a.out b.out a.exe a_out.exe
849 AC_MSG_RESULT($gmp_prog_cc_works)
850 if test $gmp_prog_cc_works = yes; then
851   ifelse([$2],,:,[$2])
852 else
853   ifelse([$3],,:,[$3])
854 fi
855 ])
856
857
858 dnl  GMP_C_TEST_SIZEOF(cc/cflags,test,[ACTION-GOOD][,ACTION-BAD])
859 dnl  ------------------------------------------------------------
860 dnl  The given cc/cflags compiler is run to check the size of a type
861 dnl  specified by the "test" argument.  "test" can either be a string, or a
862 dnl  variable like $foo.  The value should be for instance "sizeof-long-4",
863 dnl  to test that sizeof(long)==4.
864 dnl
865 dnl  This test is designed to be run for different compiler and/or flags
866 dnl  combinations, so the result is not cached.
867 dnl
868 dnl  The idea for making an array that has a negative size if the desired
869 dnl  condition test is false comes from autoconf AC_CHECK_SIZEOF.  The cast
870 dnl  to "long" in the array dimension also follows autoconf, apparently it's
871 dnl  a workaround for a HP compiler bug.
872
873 AC_DEFUN([GMP_C_TEST_SIZEOF],
874 [echo "configure: testlist $2" >&AC_FD_CC
875 [gmp_sizeof_type=`echo "$2" | sed 's/sizeof-\([a-z]*\).*/\1/'`]
876 [gmp_sizeof_want=`echo "$2" | sed 's/sizeof-[a-z]*-\([0-9]*\).*/\1/'`]
877 AC_MSG_CHECKING([compiler $1 has sizeof($gmp_sizeof_type)==$gmp_sizeof_want])
878 cat >conftest.c <<EOF
879 [int
880 main ()
881 {
882   static int test_array [1 - 2 * (long) (sizeof ($gmp_sizeof_type) != $gmp_sizeof_want)];
883   test_array[0] = 0;
884   return 0;
885 }]
886 EOF
887 gmp_c_testlist_sizeof=no
888 gmp_compile="$1 -c conftest.c >&AC_FD_CC"
889 if AC_TRY_EVAL(gmp_compile); then
890   gmp_c_testlist_sizeof=yes
891 fi
892 rm -f conftest*
893 AC_MSG_RESULT($gmp_c_testlist_sizeof)
894 if test $gmp_c_testlist_sizeof = yes; then
895   ifelse([$3],,:,[$3])
896 else
897   ifelse([$4],,:,[$4])
898 fi
899 ])
900
901
902 dnl  GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
903 dnl  -------------------------------------------------------
904 dnl  Determine whether the given compiler is GNU C.
905 dnl
906 dnl  This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't
907 dnl  cache the result.  The same "ifndef" style test is used, to avoid
908 dnl  problems with syntax checking cpp's used on NeXT and Apple systems.
909
910 AC_DEFUN([GMP_PROG_CC_IS_GNU],
911 [cat >conftest.c <<EOF
912 #if ! defined (__GNUC__) || defined (__INTEL_COMPILER)
913   choke me
914 #endif
915 EOF
916 gmp_compile="$1 -c conftest.c >&AC_FD_CC"
917 if AC_TRY_EVAL(gmp_compile); then
918   rm -f conftest*
919   AC_MSG_CHECKING([whether $1 is gcc])
920   AC_MSG_RESULT(yes)
921   ifelse([$2],,:,[$2])
922 else
923   rm -f conftest*
924   ifelse([$3],,:,[$3])
925 fi
926 ])
927
928
929 dnl  GMP_PROG_CC_IS_XLC(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
930 dnl  -------------------------------------------------------
931 dnl  Determine whether the given compiler is IBM xlc (on AIX).
932 dnl
933 dnl  There doesn't seem to be a preprocessor symbol to test for this, or if
934 dnl  there is one then it's well hidden in xlc 3.1 on AIX 4.3, so just grep
935 dnl  the man page printed when xlc is invoked with no arguments.
936
937 AC_DEFUN([GMP_PROG_CC_IS_XLC],
938 [gmp_command="$1 2>&1 | grep xlc >/dev/null"
939 if AC_TRY_EVAL(gmp_command); then
940   AC_MSG_CHECKING([whether $1 is xlc])
941   AC_MSG_RESULT(yes)
942   ifelse([$2],,:,[$2])
943 else
944   ifelse([$3],,:,[$3])
945 fi
946 ])
947
948
949 dnl  GMP_PROG_CC_X86_GOT_EAX_EMITTED(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
950 dnl  ----------------------------------------------------------------------
951 dnl  Determine whether CC+CFLAGS emits instructions using %eax with
952 dnl  _GLOBAL_OFFSET_TABLE_.  This test is for use on x86 systems.
953 dnl
954 dnl  Recent versions of gcc will use %eax for the GOT in leaf functions, for
955 dnl  instance gcc 3.3.3 with -O3.  This avoids having to save and restore
956 dnl  %ebx which otherwise usually holds the GOT, and is what gcc used in the
957 dnl  past.
958 dnl
959 dnl  %ecx and %edx are also candidates for this sort of optimization, and
960 dnl  are used under lesser optimization levels, like -O2 in 3.3.3.  FIXME:
961 dnl  It's not quite clear what the conditions for using %eax are, we might
962 dnl  need more test code to provoke it.
963 dnl
964 dnl  The motivation for this test is that past versions of gas have bugs
965 dnl  affecting this usage, see GMP_ASM_X86_GOT_EAX_OK.
966 dnl
967 dnl  This test is not specific to gcc, other compilers might emit %eax GOT
968 dnl  insns like this, though we've not investigated that.
969 dnl
970 dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so we doesn't
971 dnl  cache the result.
972 dnl
973 dnl  -fPIC is hard coded here, because this test is for use before libtool
974 dnl  has established the pic options.  It's right for gcc, but perhaps not
975 dnl  other compilers.
976
977 AC_DEFUN([GMP_PROG_CC_X86_GOT_EAX_EMITTED],
978 [echo "Testing gcc GOT with eax emitted" >&AC_FD_CC
979 cat >conftest.c <<\EOF
980 [int foo;
981 int bar () { return foo; }
982 ]EOF
983 tmp_got_emitted=no
984 gmp_compile="$1 -fPIC -S conftest.c >&AC_FD_CC 2>&1"
985 if AC_TRY_EVAL(gmp_compile); then
986   if grep "addl.*_GLOBAL_OFFSET_TABLE_.*eax" conftest.s >/dev/null; then
987     tmp_got_emitted=yes
988   fi
989 fi
990 rm -f conftest.*
991 echo "Result: $tmp_got_emitted" >&AC_FD_CC
992 if test "$tmp_got_emitted" = yes; then
993   ifelse([$2],,:,[$2])
994 else
995   ifelse([$3],,:,[$3])
996 fi
997 ])
998
999
1000 dnl  GMP_HPC_HPPA_2_0(cc,[ACTION-IF-GOOD][,ACTION-IF-BAD])
1001 dnl  ---------------------------------------------------------
1002 dnl  Find out whether a HP compiler is good enough to generate hppa 2.0.
1003 dnl
1004 dnl  This test might be repeated for different compilers, so the result is
1005 dnl  not cached.
1006
1007 AC_DEFUN([GMP_HPC_HPPA_2_0],
1008 [AC_MSG_CHECKING([whether HP compiler $1 is good for 64-bits])
1009 # Bad compiler output:
1010 #   ccom: HP92453-01 G.10.32.05 HP C Compiler
1011 # Good compiler output:
1012 #   ccom: HP92453-01 A.10.32.30 HP C Compiler
1013 # Let A.10.32.30 or higher be ok.
1014 echo >conftest.c
1015 gmp_tmp_vs=`$1 $2 -V -c -o conftest.$OBJEXT conftest.c 2>&1 | grep "^ccom:"`
1016 echo "Version string: $gmp_tmp_vs" >&AC_FD_CC
1017 rm conftest*
1018 gmp_tmp_v1=`echo $gmp_tmp_vs | sed 's/.* .\.\([[0-9]]*\).*/\1/'`
1019 gmp_tmp_v2=`echo $gmp_tmp_vs | sed 's/.* .\..*\.\(.*\)\..* HP C.*/\1/'`
1020 gmp_tmp_v3=`echo $gmp_tmp_vs | sed 's/.* .\..*\..*\.\(.*\) HP C.*/\1/'`
1021 echo "Version number: $gmp_tmp_v1.$gmp_tmp_v2.$gmp_tmp_v3" >&AC_FD_CC
1022 if test -z "$gmp_tmp_v1"; then
1023   gmp_hpc_64bit=not-applicable
1024 else
1025   GMP_COMPARE_GE($gmp_tmp_v1, 10, $gmp_tmp_v2, 32, $gmp_tmp_v3, 30)
1026   gmp_hpc_64bit=$gmp_compare_ge
1027 fi
1028 AC_MSG_RESULT($gmp_hpc_64bit)
1029 if test $gmp_hpc_64bit = yes; then
1030   ifelse([$2],,:,[$2])
1031 else
1032   ifelse([$3],,:,[$3])
1033 fi
1034 ])
1035
1036
1037 dnl  GMP_GCC_ARM_UMODSI(CC,[ACTIONS-IF-GOOD][,ACTIONS-IF-BAD])
1038 dnl  ---------------------------------------------------------
1039 dnl  gcc 2.95.3 and earlier on arm has a bug in the libgcc __umodsi routine
1040 dnl  making "%" give wrong results for some operands, eg. "0x90000000 % 3".
1041 dnl  We're hoping it'll be fixed in 2.95.4, and we know it'll be fixed in
1042 dnl  gcc 3.
1043 dnl
1044 dnl  There's only a couple of places gmp cares about this, one is the
1045 dnl  size==1 case in mpn/generic/mode1o.c, and this shows up in
1046 dnl  tests/mpz/t-jac.c as a wrong result from mpz_kronecker_ui.
1047
1048 AC_DEFUN([GMP_GCC_ARM_UMODSI],
1049 [AC_MSG_CHECKING([whether ARM gcc unsigned division works])
1050 tmp_version=`$1 --version`
1051 echo "$tmp_version" >&AC_FD_CC
1052 case $tmp_version in
1053   [2.95 | 2.95.[123]])
1054     ifelse([$3],,:,[$3])
1055     gmp_gcc_arm_umodsi_result=["no, gcc 2.95.[0123]"] ;;
1056   *)
1057     ifelse([$2],,:,[$2])
1058     gmp_gcc_arm_umodsi_result=yes ;;
1059 esac
1060 AC_MSG_RESULT([$gmp_gcc_arm_umodsi_result])
1061 ])
1062
1063
1064 dnl  GMP_GCC_MIPS_O32(gcc,[actions-yes][,[actions-no]])
1065 dnl  -------------------------------------------------
1066 dnl  Test whether gcc supports o32.
1067 dnl
1068 dnl  gcc 2.7.2.2 only does o32, and doesn't accept -mabi=32.
1069 dnl
1070 dnl  gcc 2.95 accepts -mabi=32 but it only works on irix5, on irix6 it gives
1071 dnl  "cc1: The -mabi=32 support does not work yet".
1072
1073 AC_DEFUN([GMP_GCC_MIPS_O32],
1074 [AC_MSG_CHECKING([whether gcc supports o32])
1075 echo 'int x;' >conftest.c
1076 echo "$1 -mabi=32 -c conftest.c" >&AC_FD_CC
1077 if $1 -mabi=32 -c conftest.c >conftest.out 2>&1; then
1078   result=yes
1079 else
1080   cat conftest.out >&AC_FD_CC
1081   if grep "cc1: Invalid option \`abi=32'" conftest.out >/dev/null; then
1082     result=yes
1083   else
1084     result=no
1085   fi
1086 fi
1087 rm -f conftest.*
1088 AC_MSG_RESULT($result)
1089 if test $result = yes; then
1090   ifelse([$2],,:,[$2])
1091 else
1092   ifelse([$3],,:,[$3])
1093 fi
1094 ])
1095
1096
1097 dnl  GMP_GCC_NO_CPP_PRECOMP(CCBASE,CC,CFLAGS,[ACTIONS-YES][,ACTIONS-NO])
1098 dnl  -------------------------------------------------------------------
1099 dnl  Check whether -no-cpp-precomp should be used on this compiler, and
1100 dnl  execute the corresponding ACTIONS-YES or ACTIONS-NO.
1101 dnl
1102 dnl  -no-cpp-precomp is only meant for Apple's hacked version of gcc found
1103 dnl  on powerpc*-*-darwin*, but we can give it a try on any gcc.  Normal gcc
1104 dnl  (as of 3.0 at least) only gives a warning, not an actual error, and we
1105 dnl  watch for that and decide against the option in that case, to avoid
1106 dnl  confusing the user.
1107
1108 AC_DEFUN([GMP_GCC_NO_CPP_PRECOMP],
1109 [if test "$ccbase" = gcc; then
1110   AC_MSG_CHECKING([compiler $2 $3 -no-cpp-precomp])
1111   result=no
1112   cat >conftest.c <<EOF
1113 int main () { return 0; }
1114 EOF
1115   gmp_compile="$2 $3 -no-cpp-precomp conftest.c >conftest.out 2>&1"
1116   if AC_TRY_EVAL(gmp_compile); then
1117     if grep "unrecognized option.*-no-cpp-precomp" conftest.out >/dev/null; then : ;
1118     else
1119       result=yes
1120     fi
1121   fi
1122   cat conftest.out >&AC_FD_CC
1123   rm -f conftest* a.out b.out a.exe a_out.exe
1124   AC_MSG_RESULT($result)
1125   if test "$result" = yes; then
1126       ifelse([$4],,:,[$4])
1127   else
1128       ifelse([$5],,:,[$5])
1129   fi
1130 fi
1131 ])
1132
1133
1134 dnl  GMP_GCC_PENTIUM4_SSE2(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
1135 dnl  ---------------------------------------------------------------
1136 dnl  Determine whether gcc CC+CFLAGS is a good enough version for
1137 dnl  -march=pentium4 with sse2.
1138 dnl
1139 dnl  Gcc 3.2.1 was seen generating incorrect code for raw double -> int
1140 dnl  conversions through a union.  We believe the problem is in all 3.1 and
1141 dnl  3.2 versions, but that it's fixed in 3.3.
1142
1143 AC_DEFUN([GMP_GCC_PENTIUM4_SSE2],
1144 [AC_MSG_CHECKING([whether gcc is good for sse2])
1145 case `$1 -dumpversion` in
1146   [3.[012] | 3.[012].*]) result=no ;;
1147   *)                     result=yes ;;
1148 esac
1149 AC_MSG_RESULT($result)
1150 if test "$result" = yes; then
1151   ifelse([$2],,:,[$2])
1152 else
1153   ifelse([$3],,:,[$3])
1154 fi
1155 ])
1156
1157
1158 dnl  GMP_GCC_WA_MCPU(CC+CFLAGS, NEWFLAG [,ACTION-YES [,ACTION-NO]])
1159 dnl  --------------------------------------------------------------
1160 dnl  Check whether gcc (or gas rather) accepts a flag like "-Wa,-mev67".
1161 dnl
1162 dnl  Gas doesn't give an error for an unknown cpu, it only prints a warning
1163 dnl  like "Warning: Unknown CPU identifier `ev78'".
1164 dnl
1165 dnl  This is intended for use on alpha, since only recent versions of gas
1166 dnl  accept -mev67, but there's nothing here that's alpha specific.
1167
1168 AC_DEFUN([GMP_GCC_WA_MCPU],
1169 [AC_MSG_CHECKING([assembler $1 $2])
1170 result=no
1171 cat >conftest.c <<EOF
1172 int main () {}
1173 EOF
1174 gmp_compile="$1 $2 -c conftest.c >conftest.out 2>&1"
1175 if AC_TRY_EVAL(gmp_compile); then
1176   if grep "Unknown CPU identifier" conftest.out >/dev/null; then : ;
1177   else
1178     result=yes
1179   fi
1180 fi
1181 cat conftest.out >&AC_FD_CC
1182 rm -f conftest*
1183 AC_MSG_RESULT($result)
1184 if test "$result" = yes; then
1185   ifelse([$3],,:,[$3])
1186 else
1187   ifelse([$4],,:,[$4])
1188 fi
1189 ])
1190
1191
1192 dnl  GMP_GCC_WA_OLDAS(CC+CFLAGS [,ACTION-YES [,ACTION-NO]])
1193 dnl  ------------------------------------------------------
1194 dnl  Check whether gcc should be run with "-Wa,-oldas".
1195 dnl
1196 dnl  On systems alpha*-*-osf* (or maybe just osf5), apparently there's a
1197 dnl  newish Compaq "as" which doesn't work with the gcc mips-tfile.
1198 dnl  Compiling an empty file with "gcc -c foo.c" produces for instance
1199 dnl
1200 dnl      mips-tfile, /tmp/ccaqUNnF.s:7 Segmentation fault
1201 dnl
1202 dnl  The fix is to pass "-oldas" to that assembler, as noted by
1203 dnl
1204 dnl      http://gcc.gnu.org/install/specific.html#alpha*-dec-osf*
1205 dnl
1206 dnl  The test here tries to compile an empty file, and if that fails but
1207 dnl  adding -Wa,-oldas makes it succeed, then that flag is considered
1208 dnl  necessary.
1209 dnl
1210 dnl  We look for the failing case specifically, since it may not be a good
1211 dnl  idea to use -Wa,-oldas in other circumstances.  For instance gas takes
1212 dnl  "-oldas" to mean the "-o" option and will write a file called "ldas" as
1213 dnl  its output.  Normally gcc puts its own "-o" after any -Wa options, so
1214 dnl  -oldas ends up being harmless, but clearly that's only through good
1215 dnl  luck.
1216 dnl
1217 dnl  This macro is designed for use while probing for a good compiler, and
1218 dnl  so doesn't cache it's result.
1219
1220 AC_DEFUN([GMP_GCC_WA_OLDAS],
1221 [AC_MSG_CHECKING([for $1 -Wa,-oldas])
1222 result=no
1223 cat >conftest.c <<EOF
1224 EOF
1225 echo "with empty conftest.c" >&AC_FD_CC
1226 gmp_compile="$1 -c conftest.c >&AC_FD_CC 2>&1"
1227 if AC_TRY_EVAL(gmp_compile); then : ;
1228 else
1229   # empty fails
1230   gmp_compile="$1 -Wa,-oldas -c conftest.c >&AC_FD_CC 2>&1"
1231   if AC_TRY_EVAL(gmp_compile); then
1232     # but with -Wa,-oldas it works
1233     result=yes
1234   fi
1235 fi
1236 rm -f conftest*
1237 AC_MSG_RESULT($result)
1238 if test "$result" = yes; then
1239   ifelse([$2],,:,[$2])
1240 else
1241   ifelse([$3],,:,[$3])
1242 fi
1243 ])
1244
1245
1246 dnl  GMP_OS_X86_XMM(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
1247 dnl  --------------------------------------------------------
1248 dnl  Determine whether the operating system supports XMM registers.
1249 dnl
1250 dnl  If build==host then a test program is run, executing an SSE2
1251 dnl  instruction using an XMM register.  This will give a SIGILL if the
1252 dnl  system hasn't set the OSFXSR bit in CR4 to say it knows it must use
1253 dnl  fxsave/fxrestor in a context switch (to save xmm registers).
1254 dnl
1255 dnl  If build!=host, we can fallback on:
1256 dnl
1257 dnl      - FreeBSD version 4 is the first supporting xmm.
1258 dnl
1259 dnl      - Linux kernel 2.4 might be the first stable series supporting xmm
1260 dnl        (not sure).  But there's no version number in the GNU/Linux
1261 dnl        config tuple to test anyway.
1262 dnl
1263 dnl  The default is to allow xmm.  This might seem rash, but it's likely
1264 dnl  most systems know xmm by now, so this will normally be what's wanted.
1265 dnl  And cross compiling is a bit hairy anyway, so hopefully anyone doing it
1266 dnl  will be smart enough to know what to do.
1267 dnl
1268 dnl  In the test program, .text and .globl are hard coded because this macro
1269 dnl  is wanted before GMP_ASM_TEXT and GMP_ASM_GLOBL are run.  A .byte
1270 dnl  sequence is used (for xorps %xmm0, %xmm0) to make us independent of
1271 dnl  tests for whether the assembler supports sse2/xmm.  Obviously we need
1272 dnl  both assembler and OS support, but this means we don't force the order
1273 dnl  in which we test.
1274 dnl
1275 dnl  FIXME: Maybe we should use $CCAS to assemble, if it's set.  (Would
1276 dnl  still want $CC/$CFLAGS for the link.)  But this test is used before
1277 dnl  AC_PROG_CC sets $OBJEXT, so we'd need to check for various object file
1278 dnl  suffixes ourselves.
1279
1280 AC_DEFUN([GMP_OS_X86_XMM],
1281 [AC_CACHE_CHECK([whether the operating system supports XMM registers],
1282                 gmp_cv_os_x86_xmm,
1283 [if test "$build" = "$host"; then
1284   # remove anything that might look like compiler output to our "||" expression
1285   rm -f conftest* a.out b.out a.exe a_out.exe
1286   cat >conftest.s <<EOF
1287         .text
1288 main:
1289 _main:
1290         .globl  main
1291         .globl  _main
1292         .byte   0x0f, 0x57, 0xc0
1293         xorl    %eax, %eax
1294         ret
1295 EOF
1296   gmp_compile="$1 conftest.s -o conftest >&AC_FD_CC"
1297   if AC_TRY_EVAL(gmp_compile); then
1298     if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then
1299       gmp_cv_os_x86_xmm=yes
1300     else
1301       gmp_cv_os_x86_xmm=no
1302     fi
1303   else
1304     AC_MSG_WARN([Oops, cannot compile test program])
1305   fi
1306   rm -f conftest*
1307 fi
1308
1309 if test -z "$gmp_cv_os_x86_xmm"; then
1310   case $host_os in
1311     [freebsd[123] | freebsd[123].*])
1312       gmp_cv_os_x86_xmm=no ;;
1313     freebsd*)
1314       gmp_cv_os_x86_xmm=yes ;;
1315     *)
1316       gmp_cv_os_x86_xmm=probably ;;
1317   esac
1318 fi
1319 ])
1320
1321 if test "$gmp_cv_os_x86_xmm" = probably; then
1322   AC_MSG_WARN([Not certain of OS support for xmm when cross compiling.])
1323   AC_MSG_WARN([Will assume it's ok, expect a SIGILL if this is wrong.])
1324 fi
1325
1326 case $gmp_cv_os_x86_xmm in
1327 no)
1328   $3
1329   ;;
1330 *)
1331   $2
1332   ;;
1333 esac
1334 ])
1335
1336
1337 dnl  GMP_CRAY_HOST_TYPES(C90/T90-IEEE, C90/T90-CFP, J90/SV1)
1338 dnl  -------------------------------------------------------
1339 dnl  Execute the actions in the arguments on the respective Cray vector
1340 dnl  systems.  For other hosts, do nothing.
1341 dnl
1342 dnl  This macro should be used after the C compiler has been chosen, since
1343 dnl  on c90 and t90 we ask the compiler whether we're in IEEE or CFP float
1344 dnl  mode.
1345 dnl
1346 dnl  This code is in a macro so that any AC_REQUIRE pre-requisites of
1347 dnl  AC_EGREP_CPP will be expanded at the top-level, ie. for all hosts not
1348 dnl  merely c90 and t90.  In autoconf 2.57 for instance this means
1349 dnl  AC_PROG_EGREP, which is needed by various other macros.
1350
1351 AC_DEFUN([GMP_CRAY_OPTIONS],
1352 [case $host_cpu in
1353   c90 | t90)
1354     AC_EGREP_CPP(yes,
1355 [#ifdef _CRAYIEEE
1356 yes
1357 #endif],
1358     [$1],
1359     [$2])
1360     ;;
1361   j90 | sv1)
1362     [$3]
1363     ;;
1364 esac
1365 ])
1366
1367
1368 dnl  GMP_HPPA_LEVEL_20(cc/cflags [, ACTION-GOOD [,ACTION-BAD]])
1369 dnl  ----------------------------------------------------------
1370 dnl  Check that the given cc/cflags accepts HPPA 2.0n assembler code.
1371 dnl
1372 dnl  Old versions of gas don't know 2.0 instructions.  It rejects ".level
1373 dnl  2.0" for a start, so just test that.
1374 dnl
1375 dnl  This test is designed to be run for various different compiler and
1376 dnl  flags combinations, and hence doesn't cache its result.
1377
1378 AC_DEFUN([GMP_HPPA_LEVEL_20],
1379 [AC_MSG_CHECKING([$1 assembler knows hppa 2.0])
1380 result=no
1381 cat >conftest.s <<EOF
1382         .level 2.0
1383 EOF
1384 gmp_compile="$1 -c conftest.s >&AC_FD_CC 2>&1"
1385 if AC_TRY_EVAL(gmp_compile); then
1386   result=yes
1387 else
1388   echo "failed program was" >&AC_FD_CC
1389   cat conftest.s >&AC_FD_CC
1390 fi
1391 rm -f conftest*
1392 AC_MSG_RESULT($result)
1393 if test "$result" = yes; then
1394   ifelse([$2],,:,[$2])
1395 else
1396   ifelse([$3],,:,[$3])
1397 fi
1398 ])
1399
1400
1401 dnl  GMP_PROG_CXX_WORKS(cxx/cxxflags [, ACTION-YES [,ACTION-NO]])
1402 dnl  ------------------------------------------------------------
1403 dnl  Check whether cxx/cxxflags can compile and link.
1404 dnl
1405 dnl  This test is designed to be run repeatedly with different cxx/cxxflags
1406 dnl  selections, so the result is not cached.
1407 dnl
1408 dnl  For a native build, we insist on being able to run the program, so as
1409 dnl  to detect any problems with the standard C++ library.  During
1410 dnl  development various systems with broken or incomplete C++ installations
1411 dnl  were seen.
1412 dnl
1413 dnl  The various features and problems we try to detect are done in separate
1414 dnl  compiles.  Although this is probably a bit slower than one test
1415 dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
1416 dnl  hence giving the user a clue about why we rejected the compiler.
1417
1418 AC_DEFUN([GMP_PROG_CXX_WORKS],
1419 [AC_MSG_CHECKING([C++ compiler $1])
1420 gmp_prog_cxx_works=yes
1421
1422 # start with a plain "main()", then go on to further checks
1423 GMP_PROG_CXX_WORKS_PART([$1], [])
1424
1425 GMP_PROG_CXX_WORKS_PART([$1], [namespace],
1426 [namespace foo { }
1427 using namespace foo;
1428 ])
1429
1430 # GMP requires the standard C++ iostream classes
1431 GMP_PROG_CXX_WORKS_PART([$1], [std iostream],
1432 [/* This test rejects g++ 2.7.2 which doesn't have <iostream>, only a
1433     pre-standard iostream.h. */
1434 #include <iostream>
1435
1436 /* This test rejects OSF 5.1 Compaq C++ in its default pre-standard iostream
1437    mode, since that mode puts cout in the global namespace, not "std".  */
1438 void someoutput (void) { std::cout << 123; }
1439 ])
1440
1441 AC_MSG_RESULT($gmp_prog_cxx_works)
1442 case $gmp_prog_cxx_works in
1443   yes)
1444     [$2]
1445     ;;
1446   *)
1447     [$3]
1448     ;;
1449 esac
1450 ])
1451
1452 dnl  Called: GMP_PROG_CXX_WORKS_PART(CXX+CXXFLAGS, FAIL-MESSAGE [,CODE])
1453 dnl
1454 AC_DEFUN([GMP_PROG_CXX_WORKS_PART],
1455 [if test "$gmp_prog_cxx_works" = yes; then
1456   # remove anything that might look like compiler output to our "||" expression
1457   rm -f conftest* a.out b.out a.exe a_out.exe
1458   cat >conftest.cc <<EOF
1459 [$3]
1460 int main (void) { return 0; }
1461 EOF
1462   echo "Test compile: [$2]" >&AC_FD_CC
1463   gmp_cxxcompile="$1 conftest.cc >&AC_FD_CC"
1464   if AC_TRY_EVAL(gmp_cxxcompile); then
1465     if test "$cross_compiling" = no; then
1466       if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
1467       else
1468         gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2], program does not run"
1469       fi
1470     fi
1471   else
1472     gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2]"
1473   fi
1474   case $gmp_prog_cxx_works in
1475     no*)
1476       echo "failed program was:" >&AC_FD_CC
1477       cat conftest.cc >&AC_FD_CC
1478       ;;
1479   esac
1480   rm -f conftest* a.out b.out a.exe a_out.exe
1481 fi
1482 ])
1483
1484
1485 dnl  GMP_INIT([M4-DEF-FILE])
1486 dnl  -----------------------
1487 dnl  Initializations for GMP config.m4 generation.
1488 dnl
1489 dnl  FIXME: The generated config.m4 doesn't get recreated by config.status.
1490 dnl  Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.
1491
1492 AC_DEFUN([GMP_INIT],
1493 [ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
1494 gmp_tmpconfigm4=cnfm4.tmp
1495 gmp_tmpconfigm4i=cnfm4i.tmp
1496 gmp_tmpconfigm4p=cnfm4p.tmp
1497 rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p
1498
1499 # CONFIG_TOP_SRCDIR is a path from the mpn builddir to the top srcdir.
1500 # The pattern here tests for an absolute path the same way as
1501 # _AC_OUTPUT_FILES in autoconf acgeneral.m4.
1502 case $srcdir in
1503 [[\\/]]* | ?:[[\\/]]* )  tmp="$srcdir"    ;;
1504 *)                       tmp="../$srcdir" ;;
1505 esac
1506 echo ["define(<CONFIG_TOP_SRCDIR>,<\`$tmp'>)"] >>$gmp_tmpconfigm4
1507
1508 # All CPUs use asm-defs.m4
1509 echo ["include][(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"] >>$gmp_tmpconfigm4i
1510 ])
1511
1512
1513 dnl  GMP_FINISH
1514 dnl  ----------
1515 dnl  Create config.m4 from its accumulated parts.
1516 dnl
1517 dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
1518 dnl  of config.m4 is harmless.
1519 dnl
1520 dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
1521 dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
1522 dnl  fully quoted but are still put under an ifdef in case any have been
1523 dnl  redefined by one of the m4 include files.
1524 dnl
1525 dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
1526 dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
1527 dnl  having a whole file as a macro argument would overflow the string space
1528 dnl  on BSD m4.
1529
1530 AC_DEFUN([GMP_FINISH],
1531 [AC_REQUIRE([GMP_INIT])
1532 echo "creating $gmp_configm4"
1533 echo ["d""nl $gmp_configm4.  Generated automatically by configure."] > $gmp_configm4
1534 if test -f $gmp_tmpconfigm4; then
1535   echo ["changequote(<,>)"] >> $gmp_configm4
1536   echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
1537   cat $gmp_tmpconfigm4 >> $gmp_configm4
1538   echo [">)"] >> $gmp_configm4
1539   echo ["changequote(\`,')"] >> $gmp_configm4
1540   rm $gmp_tmpconfigm4
1541 fi
1542 echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
1543 if test -f $gmp_tmpconfigm4i; then
1544   cat $gmp_tmpconfigm4i >> $gmp_configm4
1545   rm $gmp_tmpconfigm4i
1546 fi
1547 if test -f $gmp_tmpconfigm4p; then
1548   cat $gmp_tmpconfigm4p >> $gmp_configm4
1549   rm $gmp_tmpconfigm4p
1550 fi
1551 echo ["')"] >> $gmp_configm4
1552 echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
1553 ])
1554
1555
1556 dnl  GMP_INCLUDE_MPN(FILE)
1557 dnl  ---------------------
1558 dnl  Add an include_mpn(`FILE') to config.m4.  FILE should be a path
1559 dnl  relative to the mpn source directory, for example
1560 dnl
1561 dnl      GMP_INCLUDE_MPN(`x86/x86-defs.m4')
1562 dnl
1563
1564 AC_DEFUN([GMP_INCLUDE_MPN],
1565 [AC_REQUIRE([GMP_INIT])
1566 echo ["include_mpn(\`$1')"] >> $gmp_tmpconfigm4i
1567 ])
1568
1569
1570 dnl  GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
1571 dnl  ------------------------------------------
1572 dnl  Define M4 macro MACRO as DEFINITION in temporary file.
1573 dnl
1574 dnl  If LOCATION is `POST', the definition will appear after any include()
1575 dnl  directives inserted by GMP_INCLUDE.  Mind the quoting!  No shell
1576 dnl  variables will get expanded.  Don't forget to invoke GMP_FINISH to
1577 dnl  create file config.m4.  config.m4 uses `<' and '>' as quote characters
1578 dnl  for all defines.
1579
1580 AC_DEFUN([GMP_DEFINE],
1581 [AC_REQUIRE([GMP_INIT])
1582 echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
1583                               $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
1584 ])
1585
1586
1587 dnl  GMP_DEFINE_RAW(STRING [, LOCATION])
1588 dnl  ------------------------------------
1589 dnl  Put STRING into config.m4 file.
1590 dnl
1591 dnl  If LOCATION is `POST', the definition will appear after any include()
1592 dnl  directives inserted by GMP_INCLUDE.  Don't forget to invoke GMP_FINISH
1593 dnl  to create file config.m4.
1594
1595 AC_DEFUN([GMP_DEFINE_RAW],
1596 [AC_REQUIRE([GMP_INIT])
1597 echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
1598 ])
1599
1600
1601 dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
1602 dnl  ----------------------------------------------------------
1603 dnl  Attempt to assemble the given code.
1604 dnl  Do "action-success" if this succeeds, "action-fail" if not.
1605 dnl
1606 dnl  conftest.o and conftest.out are available for inspection in
1607 dnl  "action-success".  If either action does a "break" out of a loop then
1608 dnl  an explicit "rm -f conftest*" will be necessary.
1609 dnl
1610 dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
1611 dnl  anything in "asm-code", everything wanted must be given explicitly.
1612
1613 AC_DEFUN([GMP_TRY_ASSEMBLE],
1614 [cat >conftest.s <<EOF
1615 [$1]
1616 EOF
1617 gmp_assemble="$CCAS $CFLAGS $CPPFLAGS conftest.s >conftest.out 2>&1"
1618 if AC_TRY_EVAL(gmp_assemble); then
1619   cat conftest.out >&AC_FD_CC
1620   ifelse([$2],,:,[$2])
1621 else
1622   cat conftest.out >&AC_FD_CC
1623   echo "configure: failed program was:" >&AC_FD_CC
1624   cat conftest.s >&AC_FD_CC
1625   ifelse([$3],,:,[$3])
1626 fi
1627 rm -f conftest*
1628 ])
1629
1630
1631 dnl Checks whether the stack can be marked nonexecutable by passing an option
1632 dnl to the C-compiler when acting on .s files. Appends that option to ASFLAGS.
1633 dnl This macro is adapted from one found in GLIBC-2.3.5.
1634 AC_DEFUN([CL_AS_NOEXECSTACK],[
1635 dnl AC_REQUIRE([AC_PROG_CC]) GMP uses something else
1636 AC_CACHE_CHECK([whether assembler supports --noexecstack option],
1637 cl_cv_as_noexecstack, [dnl
1638   cat > conftest.c <<EOF
1639 void foo() {}
1640 EOF
1641   if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
1642                      -S -o conftest.s conftest.c >/dev/null]) \
1643      && grep .note.GNU-stack conftest.s >/dev/null \
1644      && AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wa,--noexecstack
1645                        -c -o conftest.o conftest.s >/dev/null])
1646   then
1647     cl_cv_as_noexecstack=yes
1648   else
1649     cl_cv_as_noexecstack=no
1650   fi
1651   rm -f conftest*])
1652   if test "$cl_cv_as_noexecstack" = yes; then
1653     ASMFLAGS="$ASMFLAGS -Wa,--noexecstack"
1654   fi
1655   AC_SUBST(ASMFLAGS)
1656 ])
1657
1658
1659 dnl  GMP_ASM_LABEL_SUFFIX
1660 dnl  --------------------
1661 dnl  : - is usual.
1662 dnl  empty - hppa on HP-UX doesn't use a :, just the label name
1663 dnl
1664 dnl  Note that it's necessary to test the empty case first, since HP "as"
1665 dnl  will accept "somelabel:", and take it to mean a label with a name that
1666 dnl  happens to end in a colon.
1667
1668 AC_DEFUN([GMP_ASM_LABEL_SUFFIX],
1669 [AC_REQUIRE([GMP_ASM_TEXT])
1670 AC_CACHE_CHECK([for assembler label suffix],
1671                 gmp_cv_asm_label_suffix,
1672 [gmp_cv_asm_label_suffix=unknown
1673 for i in "" ":"; do
1674   echo "trying $i" >&AC_FD_CC
1675   GMP_TRY_ASSEMBLE(
1676 [       $gmp_cv_asm_text
1677 somelabel$i],
1678     [gmp_cv_asm_label_suffix=$i
1679      rm -f conftest*
1680      break],
1681     [cat conftest.out >&AC_FD_CC])
1682 done
1683 if test "$gmp_cv_asm_label_suffix" = "unknown"; then
1684   AC_MSG_ERROR([Cannot determine label suffix])
1685 fi
1686 ])
1687 echo ["define(<LABEL_SUFFIX>, <$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
1688 ])
1689
1690
1691 dnl  GMP_ASM_UNDERSCORE
1692 dnl  ------------------
1693 dnl  Determine whether global symbols need to be prefixed with an underscore.
1694 dnl  The output from "nm" is grepped to see what a typical symbol looks like.
1695 dnl
1696 dnl  This test used to grep the .o file directly, but that failed with greps
1697 dnl  that don't like binary files (eg. SunOS 4).
1698 dnl
1699 dnl  This test also used to construct an assembler file with and without an
1700 dnl  underscore and try to link that to a C file, to see which worked.
1701 dnl  Although that's what will happen in the real build we don't really want
1702 dnl  to depend on creating asm files within configure for every possible CPU
1703 dnl  (or at least we don't want to do that more than we have to).
1704 dnl
1705 dnl  The fallback on no underscore is based on the assumption that the world
1706 dnl  is moving towards non-underscore systems.  There should actually be no
1707 dnl  good reason for nm to fail though.
1708
1709 AC_DEFUN([GMP_ASM_UNDERSCORE],
1710 [AC_REQUIRE([GMP_PROG_NM])
1711 AC_CACHE_CHECK([if globals are prefixed by underscore],
1712                gmp_cv_asm_underscore,
1713 [gmp_cv_asm_underscore="unknown"
1714 cat >conftest.c <<EOF
1715 int gurkmacka;
1716 EOF
1717 gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC"
1718 if AC_TRY_EVAL(gmp_compile); then
1719   $NM conftest.$OBJEXT >conftest.out
1720   if grep _gurkmacka conftest.out >/dev/null; then
1721     gmp_cv_asm_underscore=yes
1722   elif grep gurkmacka conftest.out >/dev/null; then
1723     gmp_cv_asm_underscore=no
1724   else
1725     echo "configure: $NM doesn't have gurkmacka:" >&AC_FD_CC
1726     cat conftest.out >&AC_FD_CC
1727   fi
1728 else
1729   echo "configure: failed program was:" >&AC_FD_CC
1730   cat conftest.c >&AC_FD_CC
1731 fi
1732 rm -f conftest*
1733 ])
1734 case $gmp_cv_asm_underscore in
1735   yes)
1736     GMP_DEFINE(GSYM_PREFIX, [_]) ;;
1737   no)
1738     GMP_DEFINE(GSYM_PREFIX, []) ;;
1739   *)
1740     AC_MSG_WARN([+----------------------------------------------------------])
1741     AC_MSG_WARN([| Cannot determine global symbol prefix.])
1742     AC_MSG_WARN([| $NM output doesn't contain a global data symbol.])
1743     AC_MSG_WARN([| Will proceed with no underscore.])
1744     AC_MSG_WARN([| If this is wrong then you'll get link errors referring])
1745     AC_MSG_WARN([| to ___gmpn_add_n (note three underscores).])
1746     AC_MSG_WARN([| In this case do a fresh build with an override,])
1747     AC_MSG_WARN([|     ./configure gmp_cv_asm_underscore=yes])
1748     AC_MSG_WARN([+----------------------------------------------------------])
1749     GMP_DEFINE(GSYM_PREFIX, [])
1750     ;;
1751 esac
1752 ])
1753
1754
1755 dnl  GMP_ASM_ALIGN_LOG
1756 dnl  -----------------
1757 dnl  Is parameter to `.align' logarithmic?
1758
1759 AC_DEFUN([GMP_ASM_ALIGN_LOG],
1760 [AC_REQUIRE([GMP_ASM_GLOBL])
1761 AC_REQUIRE([GMP_ASM_BYTE])
1762 AC_REQUIRE([GMP_ASM_DATA])
1763 AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1764 AC_REQUIRE([GMP_PROG_NM])
1765 AC_CACHE_CHECK([if .align assembly directive is logarithmic],
1766                gmp_cv_asm_align_log,
1767 [GMP_TRY_ASSEMBLE(
1768 [       $gmp_cv_asm_data
1769         .align  4
1770         $gmp_cv_asm_globl       foo
1771         $gmp_cv_asm_byte        1
1772         .align  4
1773 foo$gmp_cv_asm_label_suffix
1774         $gmp_cv_asm_byte        2],
1775   [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
1776      sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
1777   if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"; then
1778     gmp_cv_asm_align_log=yes
1779   else
1780     gmp_cv_asm_align_log=no
1781   fi],
1782   [AC_MSG_ERROR([cannot assemble alignment test])])])
1783
1784 GMP_DEFINE_RAW(["define(<ALIGN_LOGARITHMIC>,<$gmp_cv_asm_align_log>)"])
1785 ])
1786
1787
1788 dnl  GMP_ASM_ALIGN_FILL_0x90
1789 dnl  -----------------------
1790 dnl  Determine whether a ",0x90" suffix works on a .align directive.
1791 dnl  This is only meant for use on x86, 0x90 being a "nop".
1792 dnl
1793 dnl  Old gas, eg. 1.92.3
1794 dnl       Needs ",0x90" or else the fill is 0x00, which can't be executed
1795 dnl       across.
1796 dnl
1797 dnl  New gas, eg. 2.91
1798 dnl       Generates multi-byte nop fills even when ",0x90" is given.
1799 dnl
1800 dnl  Solaris 2.6 as
1801 dnl       ",0x90" is not allowed, causes a fatal error.
1802 dnl
1803 dnl  Solaris 2.8 as
1804 dnl       ",0x90" does nothing, generates a warning that it's being ignored.
1805 dnl
1806 dnl  SCO OpenServer 5 as
1807 dnl       Second parameter is max bytes to fill, not a fill pattern.
1808 dnl       ",0x90" is an error due to being bigger than the first parameter.
1809 dnl       Multi-byte nop fills are generated in text segments.
1810 dnl
1811 dnl  Note that both solaris "as"s only care about ",0x90" if they actually
1812 dnl  have to use it to fill something, hence the .byte in the test.  It's
1813 dnl  the second .align which provokes the error or warning.
1814 dnl
1815 dnl  The warning from solaris 2.8 is suppressed to stop anyone worrying that
1816 dnl  something might be wrong.
1817
1818 AC_DEFUN([GMP_ASM_ALIGN_FILL_0x90],
1819 [AC_REQUIRE([GMP_ASM_TEXT])
1820 AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
1821                gmp_cv_asm_align_fill_0x90,
1822 [GMP_TRY_ASSEMBLE(
1823 [       $gmp_cv_asm_text
1824         .align  4, 0x90
1825         .byte   0
1826         .align  4, 0x90],
1827 [if grep "Warning: Fill parameter ignored for executable section" conftest.out >/dev/null; then
1828   echo "Supressing this warning by omitting 0x90" 1>&AC_FD_CC
1829   gmp_cv_asm_align_fill_0x90=no
1830 else
1831   gmp_cv_asm_align_fill_0x90=yes
1832 fi],
1833 [gmp_cv_asm_align_fill_0x90=no])])
1834
1835 GMP_DEFINE_RAW(["define(<ALIGN_FILL_0x90>,<$gmp_cv_asm_align_fill_0x90>)"])
1836 ])
1837
1838
1839 dnl  GMP_ASM_BYTE
1840 dnl  ------------
1841 dnl  .byte - is usual.
1842 dnl  data1 - required by ia64 (on hpux at least).
1843 dnl
1844 dnl  This macro is just to support other configure tests, not any actual asm
1845 dnl  code.
1846
1847 AC_DEFUN([GMP_ASM_BYTE],
1848 [AC_REQUIRE([GMP_ASM_TEXT])
1849 AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1850 AC_CACHE_CHECK([for assembler byte directive],
1851                 gmp_cv_asm_byte,
1852 [for i in .byte data1; do
1853   echo "trying $i" >&AC_FD_CC
1854   GMP_TRY_ASSEMBLE(
1855 [       $gmp_cv_asm_data
1856         $i      0
1857 ],
1858     [gmp_cv_asm_byte=$i
1859      rm -f conftest*
1860      break],
1861     [cat conftest.out >&AC_FD_CC])
1862 done
1863 if test -z "$gmp_cv_asm_byte"; then
1864   AC_MSG_ERROR([Cannot determine how to emit a data byte])
1865 fi
1866 ])
1867 ])
1868
1869
1870 dnl  GMP_ASM_TEXT
1871 dnl  ------------
1872 dnl  .text - is usual.
1873 dnl  .code - is needed by the hppa on HP-UX (but ia64 HP-UX uses .text)
1874 dnl  .csect .text[PR] - is for AIX.
1875
1876 AC_DEFUN([GMP_ASM_TEXT],
1877 [AC_CACHE_CHECK([how to switch to text section],
1878                 gmp_cv_asm_text,
1879 [for i in ".text" ".code" [".csect .text[PR]"]; do
1880   echo "trying $i" >&AC_FD_CC
1881   GMP_TRY_ASSEMBLE([    $i],
1882     [gmp_cv_asm_text=$i
1883      rm -f conftest*
1884      break])
1885 done
1886 if test -z "$gmp_cv_asm_text"; then
1887   AC_MSG_ERROR([Cannot determine text section directive])
1888 fi
1889 ])
1890 echo ["define(<TEXT>, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
1891 ])
1892
1893
1894 dnl  GMP_ASM_DATA
1895 dnl  ------------
1896 dnl  Can we say `.data'?
1897
1898 AC_DEFUN([GMP_ASM_DATA],
1899 [AC_CACHE_CHECK([how to switch to data section],
1900                 gmp_cv_asm_data,
1901 [case $host in
1902   *-*-aix*) gmp_cv_asm_data=[".csect .data[RW]"] ;;
1903   *)        gmp_cv_asm_data=".data" ;;
1904 esac
1905 ])
1906 echo ["define(<DATA>, <$gmp_cv_asm_data>)"] >> $gmp_tmpconfigm4
1907 ])
1908
1909
1910 dnl  GMP_ASM_RODATA
1911 dnl  --------------
1912 dnl  Find out how to switch to the read-only data section.
1913 dnl
1914 dnl  The compiler output is grepped for the right directive.  It's not
1915 dnl  considered wise to just probe for ".section .rodata" or whatever works,
1916 dnl  since arbitrary section names might be accepted, but not necessarily do
1917 dnl  the right thing when they get to the linker.
1918 dnl
1919 dnl  Only a few asm files use RODATA, so this code is perhaps a bit
1920 dnl  excessive right now, but should find more uses in the future.
1921 dnl
1922 dnl  FIXME: gcc on aix generates something like ".csect _foo.ro_c[RO],3"
1923 dnl  where foo is the object file.  Might need to check for that if we use
1924 dnl  RODATA there.
1925
1926 AC_DEFUN([GMP_ASM_RODATA],
1927 [AC_REQUIRE([GMP_ASM_TEXT])
1928 AC_REQUIRE([GMP_ASM_DATA])
1929 AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1930 AC_REQUIRE([GMP_ASM_UNDERSCORE])
1931 AC_CACHE_CHECK([how to switch to read-only data section],
1932                gmp_cv_asm_rodata,
1933 [
1934 dnl Default to DATA on CPUs with split code/data caching, and TEXT
1935 dnl elsewhere.  i386 means generic x86, so use DATA on it.
1936 case $host in
1937 X86_PATTERN | x86_64-*-*)
1938   gmp_cv_asm_rodata="$gmp_cv_asm_data" ;;
1939 *)
1940   gmp_cv_asm_rodata="$gmp_cv_asm_text" ;;
1941 esac
1942
1943 cat >conftest.c <<EOF
1944 const int foo = 123;
1945 EOF
1946 echo "Test program:" >&AC_FD_CC
1947 cat conftest.c >&AC_FD_CC
1948 gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
1949 if AC_TRY_EVAL(gmp_compile); then
1950   echo "Compiler output:" >&AC_FD_CC
1951   cat conftest.s >&AC_FD_CC
1952   if test $gmp_cv_asm_underscore = yes; then
1953     tmp_gsym_prefix=_
1954   else
1955     tmp_gsym_prefix=
1956   fi
1957   # must see our label
1958   if grep "^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" conftest.s >/dev/null 2>&AC_FD_CC; then
1959     # take the last directive before our label (hence skipping segments
1960     # getting debugging info etc)
1961     tmp_match=`sed -n ["/^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix/q
1962                         /^[.    ]*data/p
1963                         /^[.    ]*rdata/p
1964                         /^[.    ]*text/p
1965                         /^[.    ]*section/p
1966                         /^[.    ]*csect/p
1967                         /^[.    ]*CSECT/p"] conftest.s | sed -n '$p'`
1968     echo "Match: $tmp_match" >&AC_FD_CC
1969     if test -n "$tmp_match"; then
1970       gmp_cv_asm_rodata=$tmp_match
1971     fi
1972   else
1973     echo "Couldn't find label: ^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" >&AC_FD_CC
1974   fi
1975 fi
1976 rm -f conftest*
1977 ])
1978 echo ["define(<RODATA>, <$gmp_cv_asm_rodata>)"] >> $gmp_tmpconfigm4
1979 ])
1980
1981
1982 dnl  GMP_ASM_GLOBL
1983 dnl  -------------
1984 dnl  The assembler directive to mark a label as a global symbol.
1985 dnl
1986 dnl  ia64 - .global is standard, according to the Intel documentation.
1987 dnl
1988 dnl  hppa - ".export foo,entry" is demanded by HP hppa "as".  ".global" is a
1989 dnl      kind of import.
1990 dnl
1991 dnl  other - .globl is usual.
1992 dnl
1993 dnl  "gas" tends to accept .globl everywhere, in addition to .export or
1994 dnl  .global or whatever the system assembler demands.
1995
1996 AC_DEFUN([GMP_ASM_GLOBL],
1997 [AC_REQUIRE([GMP_ASM_TEXT])
1998 AC_CACHE_CHECK([for assembler global directive],
1999                 gmp_cv_asm_globl,
2000 [case $host in
2001   hppa*-*-*)     gmp_cv_asm_globl=.export ;;
2002   IA64_PATTERN)  gmp_cv_asm_globl=.global ;;
2003   *)             gmp_cv_asm_globl=.globl  ;;
2004 esac
2005 ])
2006 echo ["define(<GLOBL>, <$gmp_cv_asm_globl>)"] >> $gmp_tmpconfigm4
2007 ])
2008
2009
2010 dnl  GMP_ASM_GLOBL_ATTR
2011 dnl  ------------------
2012 dnl  Do we need something after `GLOBL symbol'?
2013
2014 AC_DEFUN([GMP_ASM_GLOBL_ATTR],
2015 [AC_REQUIRE([GMP_ASM_GLOBL])
2016 AC_CACHE_CHECK([for assembler global directive attribute],
2017                 gmp_cv_asm_globl_attr,
2018 [case $gmp_cv_asm_globl in
2019   .export) gmp_cv_asm_globl_attr=",entry" ;;
2020   *)       gmp_cv_asm_globl_attr="" ;;
2021 esac
2022 ])
2023 echo ["define(<GLOBL_ATTR>, <$gmp_cv_asm_globl_attr>)"] >> $gmp_tmpconfigm4
2024 ])
2025
2026
2027 dnl  GMP_ASM_TYPE
2028 dnl  ------------
2029 dnl  Can we say ".type", and how?
2030 dnl
2031 dnl  For i386 GNU/Linux ELF systems, and very likely other ELF systems,
2032 dnl  .type and .size are important on functions in shared libraries.  If
2033 dnl  .type is omitted and the mainline program references that function then
2034 dnl  the code will be copied down to the mainline at load time like a piece
2035 dnl  of data.  If .size is wrong or missing (it defaults to 4 bytes or some
2036 dnl  such) then incorrect bytes will be copied and a segv is the most likely
2037 dnl  result.  In any case such copying is not what's wanted, a .type
2038 dnl  directive will ensure a PLT entry is used.
2039 dnl
2040 dnl  In GMP the assembler functions are normally only used from within the
2041 dnl  library (since most programs are not interested in the low level
2042 dnl  routines), and in those circumstances a missing .type isn't fatal,
2043 dnl  letting the problem go unnoticed.  tests/mpn/t-asmtype.c aims to check
2044 dnl  for it.
2045
2046 AC_DEFUN([GMP_ASM_TYPE],
2047 [AC_CACHE_CHECK([for assembler .type directive],
2048                 gmp_cv_asm_type,
2049 [gmp_cv_asm_type=
2050 for gmp_tmp_prefix in @ \# %; do
2051   GMP_TRY_ASSEMBLE([    .type   sym,${gmp_tmp_prefix}function],
2052     [if grep "\.type pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
2053     else
2054       gmp_cv_asm_type=".type    \$][1,${gmp_tmp_prefix}\$][2"
2055       break
2056     fi])
2057 done
2058 rm -f conftest*
2059 ])
2060 echo ["define(<TYPE>, <$gmp_cv_asm_type>)"] >> $gmp_tmpconfigm4
2061 ])
2062
2063
2064 dnl  GMP_ASM_SIZE
2065 dnl  ------------
2066 dnl  Can we say `.size'?
2067
2068 AC_DEFUN([GMP_ASM_SIZE],
2069 [AC_CACHE_CHECK([for assembler .size directive],
2070                 gmp_cv_asm_size,
2071 [gmp_cv_asm_size=
2072 GMP_TRY_ASSEMBLE([      .size   sym,1],
2073   [if grep "\.size pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
2074   else
2075     gmp_cv_asm_size=".size      \$][1,\$][2"
2076   fi])
2077 ])
2078 echo ["define(<SIZE>, <$gmp_cv_asm_size>)"] >> $gmp_tmpconfigm4
2079 ])
2080
2081
2082 dnl  GMP_ASM_COFF_TYPE
2083 dnl  -----------------
2084 dnl  Determine whether the assembler supports COFF type information.
2085 dnl
2086 dnl  Currently this is only needed for mingw (and cygwin perhaps) and so is
2087 dnl  run only on the x86s, but it ought to work anywhere.
2088 dnl
2089 dnl  On MINGW, recent versions of the linker have an automatic import scheme
2090 dnl  for data in a DLL which is referenced by a mainline but without
2091 dnl  __declspec (__dllimport__) on the prototype.  It seems functions
2092 dnl  without type information are treated as data, or something, and calls
2093 dnl  to them from the mainline will crash.  gcc puts type information on the
2094 dnl  C functions it generates, we need to do the same for assembler
2095 dnl  functions.
2096 dnl
2097 dnl  This applies only to functions without __declspec(__dllimport__),
2098 dnl  ie. without __GMP_DECLSPEC in the case of libgmp, so it also works just
2099 dnl  to ensure all assembler functions used from outside libgmp have
2100 dnl  __GMP_DECLSPEC on their prototypes.  But this isn't an ideal situation,
2101 dnl  since we don't want perfectly valid calls going wrong just because
2102 dnl  there wasn't a prototype in scope.
2103 dnl
2104 dnl  When an auto-import takes place, the following warning is given by the
2105 dnl  linker.  This shouldn't be seen for any functions.
2106 dnl
2107 dnl      Info: resolving _foo by linking to __imp__foo (auto-import)
2108 dnl
2109 dnl
2110 dnl  COFF type directives look like the following
2111 dnl
2112 dnl      .def    _foo
2113 dnl      .scl    2
2114 dnl      .type   32
2115 dnl      .endef
2116 dnl
2117 dnl  _foo is the symbol with GSYM_PREFIX (_).  .scl is the storage class, 2
2118 dnl  for external, 3 for static.  .type is the object type, 32 for a
2119 dnl  function.
2120 dnl
2121 dnl  On an ELF system, this is (correctly) rejected due to .def, .endef and
2122 dnl  .scl being invalid, and .type not having enough arguments.
2123
2124 AC_DEFUN([GMP_ASM_COFF_TYPE],
2125 [AC_REQUIRE([GMP_ASM_TEXT])
2126 AC_REQUIRE([GMP_ASM_GLOBL])
2127 AC_REQUIRE([GMP_ASM_GLOBL_ATTR])
2128 AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2129 AC_REQUIRE([GMP_ASM_UNDERSCORE])
2130 AC_CACHE_CHECK([for assembler COFF type directives],
2131                 gmp_cv_asm_x86_coff_type,
2132 [GMP_TRY_ASSEMBLE(
2133 [       $gmp_cv_asm_text
2134         $gmp_cv_asm_globl ${tmp_gsym_prefix}foo$gmp_cv_asm_globl_attr
2135         .def    ${tmp_gsym_prefix}foo
2136         .scl    2
2137         .type   32
2138         .endef
2139 ${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix
2140 ],
2141   [gmp_cv_asm_x86_coff_type=yes],
2142   [gmp_cv_asm_x86_coff_type=no])
2143 ])
2144 echo ["define(<HAVE_COFF_TYPE>, <$gmp_cv_asm_x86_coff_type>)"] >> $gmp_tmpconfigm4
2145 ])
2146
2147
2148 dnl  GMP_ASM_LSYM_PREFIX
2149 dnl  -------------------
2150 dnl  What is the prefix for a local label?
2151 dnl
2152 dnl  The prefixes tested are,
2153 dnl
2154 dnl      L  - usual for underscore systems
2155 dnl      .L - usual for non-underscore systems
2156 dnl      $  - alpha (gas and OSF system assembler)
2157 dnl      L$ - hppa (gas and HP-UX system assembler)
2158 dnl
2159 dnl  The default is "L" if the tests fail for any reason.  There's a good
2160 dnl  chance this will be adequate, since on most systems labels are local
2161 dnl  anyway unless given a ".globl", and an "L" will avoid clashes with
2162 dnl  other identifers.
2163 dnl
2164 dnl  For gas, ".L" is normally purely local to the assembler, it doesn't get
2165 dnl  put into the object file at all.  This style is preferred, to keep the
2166 dnl  object files nice and clean.
2167 dnl
2168 dnl  BSD format nm produces a line like
2169 dnl
2170 dnl      00000000 t Lgurkmacka
2171 dnl
2172 dnl  The symbol code is normally "t" for text, but any lower case letter
2173 dnl  indicates a local definition.
2174 dnl
2175 dnl  Code "n" is for a debugging symbol, OSF "nm -B" gives that as an upper
2176 dnl  case "N" for a local.
2177 dnl
2178 dnl  HP-UX nm prints an error message (though seems to give a 0 exit) if
2179 dnl  there's no symbols at all in an object file, hence the use of "dummy".
2180
2181 AC_DEFUN([GMP_ASM_LSYM_PREFIX],
2182 [AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2183 AC_REQUIRE([GMP_ASM_TEXT])
2184 AC_REQUIRE([GMP_PROG_NM])
2185 AC_CACHE_CHECK([for assembler local label prefix],
2186                gmp_cv_asm_lsym_prefix,
2187 [gmp_tmp_pre_appears=yes
2188 for gmp_tmp_pre in L .L $L $ L$; do
2189   echo "Trying $gmp_tmp_pre" >&AC_FD_CC
2190   GMP_TRY_ASSEMBLE(
2191 [       $gmp_cv_asm_text
2192 dummy${gmp_cv_asm_label_suffix}
2193 ${gmp_tmp_pre}gurkmacka${gmp_cv_asm_label_suffix}],
2194   [if $NM conftest.$OBJEXT >conftest.nm 2>&AC_FD_CC; then : ; else
2195     cat conftest.nm >&AC_FD_CC
2196     AC_MSG_WARN(["$NM" failure])
2197     break
2198   fi
2199   cat conftest.nm >&AC_FD_CC
2200   if grep gurkmacka conftest.nm >/dev/null; then : ; else
2201     # no mention of the symbol, this is good
2202     echo "$gmp_tmp_pre label doesn't appear in object file at all (good)" >&AC_FD_CC
2203     gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
2204     gmp_tmp_pre_appears=no
2205     break
2206   fi
2207   if grep [' [a-zN] .*gurkmacka'] conftest.nm >/dev/null; then
2208     # symbol mentioned as a local, use this if nothing better
2209     echo "$gmp_tmp_pre label is local but still in object file" >&AC_FD_CC
2210     if test -z "$gmp_cv_asm_lsym_prefix"; then
2211       gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
2212     fi
2213   else
2214     echo "$gmp_tmp_pre label is something unknown" >&AC_FD_CC
2215   fi
2216   ])
2217 done
2218 rm -f conftest*
2219 if test -z "$gmp_cv_asm_lsym_prefix"; then
2220   gmp_cv_asm_lsym_prefix=L
2221   AC_MSG_WARN([cannot determine local label, using default $gmp_cv_asm_lsym_prefix])
2222 fi
2223 # for development purposes, note whether we got a purely temporary local label
2224 echo "Local label appears in object files: $gmp_tmp_pre_appears" >&AC_FD_CC
2225 ])
2226 echo ["define(<LSYM_PREFIX>, <${gmp_cv_asm_lsym_prefix}>)"] >> $gmp_tmpconfigm4
2227 AC_DEFINE_UNQUOTED(LSYM_PREFIX, "$gmp_cv_asm_lsym_prefix",
2228                    [Assembler local label prefix])
2229 ])
2230
2231
2232 dnl  GMP_ASM_W32
2233 dnl  -----------
2234 dnl  How to define a 32-bit word.
2235 dnl
2236 dnl  FIXME: This test is not right for ia64-*-hpux*.  The directive should
2237 dnl  be "data4", but the W32 macro is not currently used by the mpn/ia64 asm
2238 dnl  files.
2239
2240 AC_DEFUN([GMP_ASM_W32],
2241 [AC_REQUIRE([GMP_ASM_DATA])
2242 AC_REQUIRE([GMP_ASM_BYTE])
2243 AC_REQUIRE([GMP_ASM_GLOBL])
2244 AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2245 AC_REQUIRE([GMP_PROG_NM])
2246 AC_CACHE_CHECK([how to define a 32-bit word],
2247                gmp_cv_asm_w32,
2248 [case $host in
2249   *-*-hpux*)
2250     # FIXME: HPUX puts first symbol at 0x40000000, breaking our assumption
2251     # that it's at 0x0.  We'll have to declare another symbol before the
2252     # .long/.word and look at the distance between the two symbols.  The
2253     # only problem is that the sed expression(s) barfs (on Solaris, for
2254     # example) for the symbol with value 0.  For now, HPUX uses .word.
2255     gmp_cv_asm_w32=".word"
2256     ;;
2257   *-*-*)
2258     gmp_tmp_val=
2259     for gmp_tmp_op in .long .word data4; do
2260       GMP_TRY_ASSEMBLE(
2261 [       $gmp_cv_asm_data
2262         $gmp_cv_asm_globl       foo
2263         $gmp_tmp_op     0
2264 foo$gmp_cv_asm_label_suffix
2265         $gmp_cv_asm_byte        0],
2266         [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
2267           sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
2268         if test "$gmp_tmp_val" = 4; then
2269           gmp_cv_asm_w32="$gmp_tmp_op"
2270           break
2271         fi])
2272     done
2273     rm -f conftest*
2274     ;;
2275 esac
2276 if test -z "$gmp_cv_asm_w32"; then
2277   AC_MSG_ERROR([cannot determine how to define a 32-bit word])
2278 fi
2279 ])
2280 echo ["define(<W32>, <$gmp_cv_asm_w32>)"] >> $gmp_tmpconfigm4
2281 ])
2282
2283
2284 dnl  GMP_X86_ASM_GOT_UNDERSCORE
2285 dnl  --------------------------
2286 dnl  Determine whether i386 _GLOBAL_OFFSET_TABLE_ needs an additional
2287 dnl  underscore prefix.
2288 dnl
2289 dnl    SVR4      - the standard is _GLOBAL_OFFSET_TABLE_
2290 dnl    GNU/Linux - follows SVR4
2291 dnl    OpenBSD   - an a.out underscore system, uses __GLOBAL_OFFSET_TABLE_
2292 dnl    NetBSD    - also an a.out underscore system, but _GLOBAL_OFFSET_TABLE_
2293 dnl
2294 dnl  The test attempts to link a program using _GLOBAL_OFFSET_TABLE_ or
2295 dnl  __GLOBAL_OFFSET_TABLE_ to see which works.
2296 dnl
2297 dnl  $lt_prog_compiler_pic is included in the compile because old versions
2298 dnl  of gas wouldn't accept PIC idioms without the right option (-K).  This
2299 dnl  is the same as what libtool and mpn/Makeasm.am will do.
2300 dnl
2301 dnl  $lt_prog_compiler_pic is also included in the link because OpenBSD ld
2302 dnl  won't accept an R_386_GOTPC relocation without the right options.  This
2303 dnl  is not what's done by the Makefiles when building executables, but
2304 dnl  let's hope it's ok (it works fine with gcc).
2305 dnl
2306 dnl  The fallback is no additional underscore, on the basis that this will
2307 dnl  suit SVR4/ELF style systems, which should be much more common than
2308 dnl  a.out systems with shared libraries.
2309 dnl
2310 dnl  Note that it's not an error for the tests to fail, since for instance
2311 dnl  cygwin, mingw and djgpp don't have a _GLOBAL_OFFSET_TABLE_ scheme at
2312 dnl  all.
2313 dnl
2314 dnl  Perhaps $CCAS could be asked to do the linking as well as the
2315 dnl  assembling, but in the Makefiles it's only used for assembling, so lets
2316 dnl  keep it that way.
2317 dnl
2318 dnl  The test here is run even under --disable-shared, so that PIC objects
2319 dnl  can be built and tested by the tune/many.pl development scheme.  The
2320 dnl  tests will be reasonably quick and won't give a fatal error, so this
2321 dnl  arrangement is ok.  AC_LIBTOOL_PROG_COMPILER_PIC does its
2322 dnl  $lt_prog_compiler_pic setups even for --disable-shared too.
2323
2324 AC_DEFUN([GMP_ASM_X86_GOT_UNDERSCORE],
2325 [AC_REQUIRE([GMP_ASM_TEXT])
2326 AC_REQUIRE([GMP_ASM_GLOBL])
2327 AC_REQUIRE([GMP_ASM_GLOBL_ATTR])
2328 AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
2329 AC_REQUIRE([GMP_ASM_UNDERSCORE])
2330 AC_REQUIRE([AC_LIBTOOL_PROG_COMPILER_PIC])
2331 AC_CACHE_CHECK([if _GLOBAL_OFFSET_TABLE_ is prefixed by underscore],
2332                gmp_cv_asm_x86_got_underscore,
2333 [gmp_cv_asm_x86_got_underscore="not applicable"
2334 if test $gmp_cv_asm_underscore = yes; then
2335   tmp_gsym_prefix=_
2336 else
2337   tmp_gsym_prefix=
2338 fi
2339 for tmp_underscore in "" "_"; do
2340   cat >conftest.s <<EOF
2341         $gmp_cv_asm_text
2342         $gmp_cv_asm_globl ${tmp_gsym_prefix}main$gmp_cv_asm_globl_attr
2343 ${tmp_gsym_prefix}main$gmp_cv_asm_label_suffix
2344         addl    $ ${tmp_underscore}_GLOBAL_OFFSET_TABLE_, %ebx
2345 EOF
2346   gmp_compile="$CCAS $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.s >&AC_FD_CC && $CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&AC_FD_CC"
2347   if AC_TRY_EVAL(gmp_compile); then
2348     if test "$tmp_underscore" = "_"; then
2349       gmp_cv_asm_x86_got_underscore=yes
2350     else
2351       gmp_cv_asm_x86_got_underscore=no
2352     fi
2353     break
2354   fi
2355 done
2356 rm -f conftest* a.out b.out a.exe a_out.exe
2357 ])
2358 if test "$gmp_cv_asm_x86_got_underscore" = "yes"; then
2359   GMP_DEFINE(GOT_GSYM_PREFIX, [_])
2360 else
2361   GMP_DEFINE(GOT_GSYM_PREFIX, [])
2362 fi
2363 ])
2364
2365
2366 dnl  GMP_ASM_X86_GOT_EAX_OK(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
2367 dnl  -------------------------------------------------------------
2368 dnl  Determine whether _GLOBAL_OFFSET_TABLE_ used with %eax is ok.
2369 dnl
2370 dnl  An instruction
2371 dnl
2372 dnl          addl  $_GLOBAL_OFFSET_TABLE_, %eax
2373 dnl
2374 dnl  is incorrectly assembled by gas 2.12 (or thereabouts) and earlier.  It
2375 dnl  puts an addend 2 into the R_386_GOTPC relocation, but it should be 1
2376 dnl  for this %eax form being a 1 byte opcode (with other registers it's 2
2377 dnl  opcode bytes).  See note about this in mpn/x86/README too.
2378 dnl
2379 dnl  We assemble this, surrounded by some unlikely byte sequences as
2380 dnl  delimiters, and check for the bad output.
2381 dnl
2382 dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so the result
2383 dnl  is not cached.
2384 dnl
2385 dnl  This test is not specific to gas, but old gas is the only assembler we
2386 dnl  know of with this problem.  The Solaris has been seen coming out ok.
2387 dnl
2388 dnl  ".text" is hard coded because this macro is wanted before GMP_ASM_TEXT.
2389 dnl  This should be fine, ".text" is normal on x86 systems, and certainly
2390 dnl  will be fine with the offending gas.
2391 dnl
2392 dnl  If an error occurs when assembling, we consider the assembler ok, since
2393 dnl  the bad output does not occur.  This happens for instance on mingw,
2394 dnl  where _GLOBAL_OFFSET_TABLE_ results in a bfd error, since there's no
2395 dnl  GOT etc in PE object files.
2396 dnl
2397 dnl  This test is used before the object file extension has been determined,
2398 dnl  so we force output to conftest.o.  Using -o with -c is not portable,
2399 dnl  but we think all x86 compilers will accept -o with -c, certainly gcc
2400 dnl  does.
2401 dnl
2402 dnl  -fPIC is hard coded here, because this test is for use before libtool
2403 dnl  has established the pic options.  It's right for gcc, but perhaps not
2404 dnl  other compilers.
2405
2406 AC_DEFUN([GMP_ASM_X86_GOT_EAX_OK],
2407 [echo "Testing gas GOT with eax good" >&AC_FD_CC
2408 cat >conftest.awk <<\EOF
2409 [BEGIN {
2410   want[0]  = "001"
2411   want[1]  = "043"
2412   want[2]  = "105"
2413   want[3]  = "147"
2414   want[4]  = "211"
2415   want[5]  = "253"
2416   want[6]  = "315"
2417   want[7]  = "357"
2418
2419   want[8]  = "005"
2420   want[9]  = "002"
2421   want[10] = "000"
2422   want[11] = "000"
2423   want[12] = "000"
2424
2425   want[13] = "376"
2426   want[14] = "334"
2427   want[15] = "272"
2428   want[16] = "230"
2429   want[17] = "166"
2430   want[18] = "124"
2431   want[19] = "062"
2432   want[20] = "020"
2433
2434   result = "yes"
2435 }
2436 {
2437   for (f = 2; f <= NF; f++)
2438     {
2439       for (i = 0; i < 20; i++)
2440         got[i] = got[i+1];
2441       got[20] = $f;
2442
2443       found = 1
2444       for (i = 0; i < 21; i++)
2445         if (got[i] != want[i])
2446           {
2447             found = 0
2448             break
2449           }
2450       if (found)
2451         {
2452           result = "no"
2453           exit
2454         }
2455     }
2456 }
2457 END {
2458   print result
2459 }
2460 ]EOF
2461 cat >conftest.s <<\EOF
2462 [       .text
2463         .byte   1, 35, 69, 103, 137, 171, 205, 239
2464         addl    $_GLOBAL_OFFSET_TABLE_, %eax
2465         .byte   254, 220, 186, 152, 118, 84, 50, 16
2466 ]EOF
2467 tmp_got_good=yes
2468 gmp_compile="$1 -fPIC -o conftest.o -c conftest.s >&AC_FD_CC 2>&1"
2469 if AC_TRY_EVAL(gmp_compile); then
2470   tmp_got_good=`od -b conftest.o | $AWK -f conftest.awk`
2471 fi
2472 rm -f conftest.*
2473 echo "Result: $tmp_got_good" >&AC_FD_CC
2474 if test "$tmp_got_good" = no; then
2475   ifelse([$3],,:,[$3])
2476 else
2477   ifelse([$2],,:,[$2])
2478 fi
2479 ])
2480
2481
2482 dnl  GMP_ASM_X86_MMX([ACTION-IF-YES][,ACTION-IF-NO])
2483 dnl  -----------------------------------------------
2484 dnl  Determine whether the assembler supports MMX instructions.
2485 dnl
2486 dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
2487 dnl  here.  ".text" is believed to be correct on all x86 systems.  Actually
2488 dnl  ".text" probably isn't needed at all, at least for just checking
2489 dnl  instruction syntax.
2490 dnl
2491 dnl  "movq %mm0, %mm1" should assemble to "0f 6f c8", but Solaris 2.6 and
2492 dnl  2.7 wrongly assemble it to "0f 6f c1" (that being the reverse "movq
2493 dnl  %mm1, %mm0").  It seems more trouble than it's worth to work around
2494 dnl  this in the code, so just detect and reject.
2495
2496 AC_DEFUN([GMP_ASM_X86_MMX],
2497 [AC_CACHE_CHECK([if the assembler knows about MMX instructions],
2498                 gmp_cv_asm_x86_mmx,
2499 [GMP_TRY_ASSEMBLE(
2500 [       .text
2501         movq    %mm0, %mm1],
2502 [gmp_cv_asm_x86_mmx=yes
2503 case $host in
2504 *-*-solaris*)
2505   if (dis conftest.$OBJEXT >conftest.out) 2>/dev/null; then
2506     if grep "0f 6f c1" conftest.out >/dev/null; then
2507       gmp_cv_asm_x86_mmx=movq-bug
2508     fi
2509   else
2510     AC_MSG_WARN(["dis" not available to check for "as" movq bug])
2511   fi
2512 esac],
2513 [gmp_cv_asm_x86_mmx=no])])
2514
2515 case $gmp_cv_asm_x86_mmx in
2516 movq-bug)
2517   AC_MSG_WARN([+----------------------------------------------------------])
2518   AC_MSG_WARN([| WARNING WARNING WARNING])
2519   AC_MSG_WARN([| Host CPU has MMX code, but the assembler])
2520   AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
2521   AC_MSG_WARN([| has the Solaris 2.6 and 2.7 bug where register to register])
2522   AC_MSG_WARN([| movq operands are reversed.])
2523   AC_MSG_WARN([| Non-MMX replacements will be used.])
2524   AC_MSG_WARN([| This will be an inferior build.])
2525   AC_MSG_WARN([+----------------------------------------------------------])
2526   ;;
2527 no)
2528   AC_MSG_WARN([+----------------------------------------------------------])
2529   AC_MSG_WARN([| WARNING WARNING WARNING])
2530   AC_MSG_WARN([| Host CPU has MMX code, but it can't be assembled by])
2531   AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
2532   AC_MSG_WARN([| Non-MMX replacements will be used.])
2533   AC_MSG_WARN([| This will be an inferior build.])
2534   AC_MSG_WARN([+----------------------------------------------------------])
2535   ;;
2536 esac
2537 if test "$gmp_cv_asm_x86_mmx" = yes; then
2538   ifelse([$1],,:,[$1])
2539 else
2540   ifelse([$2],,:,[$2])
2541 fi
2542 ])
2543
2544
2545 dnl  GMP_ASM_X86_SHLDL_CL
2546 dnl  --------------------
2547
2548 AC_DEFUN([GMP_ASM_X86_SHLDL_CL],
2549 [AC_REQUIRE([GMP_ASM_TEXT])
2550 AC_CACHE_CHECK([if the assembler takes cl with shldl],
2551                 gmp_cv_asm_x86_shldl_cl,
2552 [GMP_TRY_ASSEMBLE(
2553 [       $gmp_cv_asm_text
2554         shldl   %cl, %eax, %ebx],
2555   gmp_cv_asm_x86_shldl_cl=yes,
2556   gmp_cv_asm_x86_shldl_cl=no)
2557 ])
2558 if test "$gmp_cv_asm_x86_shldl_cl" = "yes"; then
2559   GMP_DEFINE(WANT_SHLDL_CL,1)
2560 else
2561   GMP_DEFINE(WANT_SHLDL_CL,0)
2562 fi
2563 ])
2564
2565
2566 dnl  GMP_ASM_X86_SSE2([ACTION-IF-YES][,ACTION-IF-NO])
2567 dnl  ------------------------------------------------
2568 dnl  Determine whether the assembler supports SSE2 instructions.
2569 dnl
2570 dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
2571 dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
2572 dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
2573 dnl  needed at all, at least for just checking instruction syntax.
2574
2575 AC_DEFUN([GMP_ASM_X86_SSE2],
2576 [AC_CACHE_CHECK([if the assembler knows about SSE2 instructions],
2577                 gmp_cv_asm_x86_sse2,
2578 [GMP_TRY_ASSEMBLE(
2579 [       .text
2580         paddq   %mm0, %mm1],
2581   [gmp_cv_asm_x86_sse2=yes],
2582   [gmp_cv_asm_x86_sse2=no])
2583 ])
2584 case $gmp_cv_asm_x86_sse2 in
2585 yes)
2586   ifelse([$1],,:,[$1])
2587   ;;
2588 *)
2589   AC_MSG_WARN([+----------------------------------------------------------])
2590   AC_MSG_WARN([| WARNING WARNING WARNING])
2591   AC_MSG_WARN([| Host CPU has SSE2 code, but it can't be assembled by])
2592   AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
2593   AC_MSG_WARN([| Non-SSE2 replacements will be used.])
2594   AC_MSG_WARN([| This will be an inferior build.])
2595   AC_MSG_WARN([+----------------------------------------------------------])
2596   ifelse([$2],,:,[$2])
2597   ;;
2598 esac
2599 ])
2600
2601
2602 dnl  GMP_ASM_X86_MCOUNT
2603 dnl  ------------------
2604 dnl  Find out how to call mcount for profiling on an x86 system.
2605 dnl
2606 dnl  A dummy function is compiled and the ".s" output examined.  The pattern
2607 dnl  matching might be a bit fragile, but should work at least with gcc on
2608 dnl  sensible systems.  Certainly it's better than hard coding a table of
2609 dnl  conventions.
2610 dnl
2611 dnl  For non-PIC, any ".data" is taken to mean a counter might be passed.
2612 dnl  It's assumed a movl will set it up, and the right register is taken
2613 dnl  from that movl.  Any movl involving %esp is ignored (a frame pointer
2614 dnl  setup normally).
2615 dnl
2616 dnl  For PIC, any ".data" is similarly interpreted, but a GOTOFF identifies
2617 dnl  the line setting up the right register.
2618 dnl
2619 dnl  In both cases a line with "mcount" identifies the call and that line is
2620 dnl  used literally.
2621 dnl
2622 dnl  On some systems (eg. FreeBSD 3.5) gcc emits ".data" but doesn't use it,
2623 dnl  so it's not an error to have .data but then not find a register.
2624 dnl
2625 dnl  Variations in mcount conventions on different x86 systems can be found
2626 dnl  in gcc config/i386.  mcount can have a "_" prefix or be .mcount or
2627 dnl  _mcount_ptr, and for PIC it can be called through a GOT entry, or via
2628 dnl  the PLT.  If a pointer to a counter is required it's passed in %eax or
2629 dnl  %edx.
2630 dnl
2631 dnl  Flags to specify PIC are taken from $lt_prog_compiler_pic set by
2632 dnl  AC_PROG_LIBTOOL.
2633 dnl
2634 dnl  Enhancement: Cache the values determined here. But what's the right way
2635 dnl  to get two variables (mcount_nonpic_reg and mcount_nonpic_call say) set
2636 dnl  from one block of commands?
2637
2638 AC_DEFUN([GMP_ASM_X86_MCOUNT],
2639 [AC_REQUIRE([AC_ENABLE_SHARED])
2640 AC_REQUIRE([AC_PROG_LIBTOOL])
2641 AC_MSG_CHECKING([how to call x86 mcount])
2642 cat >conftest.c <<EOF
2643 foo(){bar();}
2644 EOF
2645
2646 if test "$enable_static" = yes; then
2647   gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c 1>&AC_FD_CC"
2648   if AC_TRY_EVAL(gmp_asmout_compile); then
2649     if grep '\.data' conftest.s >/dev/null; then
2650       mcount_nonpic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
2651     else
2652       mcount_nonpic_reg=
2653     fi
2654     mcount_nonpic_call=`grep 'call.*mcount' conftest.s`
2655     if test -z "$mcount_nonpic_call"; then
2656       AC_MSG_ERROR([Cannot find mcount call for non-PIC])
2657     fi
2658   else
2659     AC_MSG_ERROR([Cannot compile test program for non-PIC])
2660   fi
2661 fi
2662
2663 if test "$enable_shared" = yes; then
2664   gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic -S conftest.c 1>&AC_FD_CC"
2665   if AC_TRY_EVAL(gmp_asmout_compile); then
2666     if grep '\.data' conftest.s >/dev/null; then
2667       case $lt_prog_compiler_pic in
2668         *-DDLL_EXPORT*)
2669           # Windows DLLs have non-PIC style mcount
2670           mcount_pic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
2671           ;;
2672         *)
2673           mcount_pic_reg=`sed -n ['s/.*GOTOFF.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
2674           ;;
2675       esac
2676     else
2677       mcount_pic_reg=
2678     fi
2679     mcount_pic_call=`grep 'call.*mcount' conftest.s`
2680     if test -z "$mcount_pic_call"; then
2681       AC_MSG_ERROR([Cannot find mcount call for PIC])
2682     fi
2683   else
2684     AC_MSG_ERROR([Cannot compile test program for PIC])
2685   fi
2686 fi
2687
2688 GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_REG>, <\`$mcount_nonpic_reg'>)"])
2689 GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_CALL>,<\`$mcount_nonpic_call'>)"])
2690 GMP_DEFINE_RAW(["define(<MCOUNT_PIC_REG>,    <\`$mcount_pic_reg'>)"])
2691 GMP_DEFINE_RAW(["define(<MCOUNT_PIC_CALL>,   <\`$mcount_pic_call'>)"])
2692
2693 rm -f conftest.*
2694 AC_MSG_RESULT([determined])
2695 ])
2696
2697
2698 dnl  GMP_ASM_IA64_ALIGN_OK
2699 dnl  ---------------------
2700 dnl  Determine whether .align correctly pads with nop instructions in a text
2701 dnl  segment.
2702 dnl
2703 dnl  gas 2.14 and earlier byte swaps its padding bundle on big endian
2704 dnl  systems, which is incorrect (endianness only changes data).  What
2705 dnl  should be "nop.m / nop.f / nop.i" comes out as "break" instructions.
2706 dnl
2707 dnl  The test here detects the bad case, and assumes anything else is ok
2708 dnl  (there are many sensible nop bundles, so it'd be impractical to try to
2709 dnl  match everything good).
2710
2711 AC_DEFUN([GMP_ASM_IA64_ALIGN_OK],
2712 [AC_CACHE_CHECK([whether assembler .align padding is good],
2713                 gmp_cv_asm_ia64_align_ok,
2714 [cat >conftest.awk <<\EOF
2715 [BEGIN {
2716   want[0]  = "011"
2717   want[1]  = "160"
2718   want[2]  = "074"
2719   want[3]  = "040"
2720   want[4]  = "000"
2721   want[5]  = "040"
2722   want[6]  = "020"
2723   want[7]  = "221"
2724   want[8]  = "114"
2725   want[9]  = "000"
2726   want[10] = "100"
2727   want[11] = "200"
2728   want[12] = "122"
2729   want[13] = "261"
2730   want[14] = "000"
2731   want[15] = "200"
2732
2733   want[16] = "000"
2734   want[17] = "004"
2735   want[18] = "000"
2736   want[19] = "000"
2737   want[20] = "000"
2738   want[21] = "000"
2739   want[22] = "002"
2740   want[23] = "000"
2741   want[24] = "000"
2742   want[25] = "000"
2743   want[26] = "000"
2744   want[27] = "001"
2745   want[28] = "000"
2746   want[29] = "000"
2747   want[30] = "000"
2748   want[31] = "014"
2749
2750   want[32] = "011"
2751   want[33] = "270"
2752   want[34] = "140"
2753   want[35] = "062"
2754   want[36] = "000"
2755   want[37] = "040"
2756   want[38] = "240"
2757   want[39] = "331"
2758   want[40] = "160"
2759   want[41] = "000"
2760   want[42] = "100"
2761   want[43] = "240"
2762   want[44] = "343"
2763   want[45] = "371"
2764   want[46] = "000"
2765   want[47] = "200"
2766
2767   result = "yes"
2768 }
2769 {
2770   for (f = 2; f <= NF; f++)
2771     {
2772       for (i = 0; i < 47; i++)
2773         got[i] = got[i+1];
2774       got[47] = $f;
2775
2776       found = 1
2777       for (i = 0; i < 48; i++)
2778         if (got[i] != want[i])
2779           {
2780             found = 0
2781             break
2782           }
2783       if (found)
2784         {
2785           result = "no"
2786           exit
2787         }
2788     }
2789 }
2790 END {
2791   print result
2792 }
2793 ]EOF
2794 GMP_TRY_ASSEMBLE(
2795 [       .text
2796         .align  32
2797 { .mmi; add     r14 = r15, r16
2798         add     r17 = r18, r19
2799         add     r20 = r21, r22 ;; }
2800         .align  32
2801 { .mmi; add     r23 = r24, r25
2802         add     r26 = r27, r28
2803         add     r29 = r30, r31 ;; }
2804 ],
2805   [gmp_cv_asm_ia64_align_ok=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`],
2806   [AC_MSG_WARN([oops, cannot compile test program])
2807    gmp_cv_asm_ia64_align_ok=yes])
2808 ])
2809 GMP_DEFINE_RAW(["define(<IA64_ALIGN_OK>, <\`$gmp_cv_asm_ia64_align_ok'>)"])
2810 ])
2811
2812
2813
2814
2815 dnl  GMP_ASM_M68K_INSTRUCTION
2816 dnl  ------------------------
2817 dnl  Not sure if ".l" and "%" are independent settings, but it doesn't hurt
2818 dnl  to try all four possibilities.  Note that the % ones must be first, so
2819 dnl  "d0" won't be interpreted as a label.
2820 dnl
2821 dnl  gas 1.92.3 on NetBSD 1.4 needs to be tested with a two operand
2822 dnl  instruction.  It takes registers without "%", but a single operand
2823 dnl  "clrl %d0" only gives a warning, not an error.
2824
2825 AC_DEFUN([GMP_ASM_M68K_INSTRUCTION],
2826 [AC_REQUIRE([GMP_ASM_TEXT])
2827 AC_CACHE_CHECK([assembler instruction and register style],
2828                 gmp_cv_asm_m68k_instruction,
2829 [for i in "addl %d0,%d1" "add.l %d0,%d1" "addl d0,d1" "add.l d0,d1"; do
2830   GMP_TRY_ASSEMBLE(
2831     [   $gmp_cv_asm_text
2832         $i],
2833     [gmp_cv_asm_m68k_instruction=$i
2834     rm -f conftest*
2835     break])
2836 done
2837 if test -z "$gmp_cv_asm_m68k_instruction"; then
2838   AC_MSG_ERROR([cannot determine assembler instruction and register style])
2839 fi
2840 ])
2841 case $gmp_cv_asm_m68k_instruction in
2842 "addl d0,d1")    want_dot_size=no;  want_register_percent=no  ;;
2843 "addl %d0,%d1")  want_dot_size=no;  want_register_percent=yes ;;
2844 "add.l d0,d1")   want_dot_size=yes; want_register_percent=no  ;;
2845 "add.l %d0,%d1") want_dot_size=yes; want_register_percent=yes ;;
2846 *) AC_MSG_ERROR([oops, unrecognised instruction and register style]) ;;
2847 esac
2848 GMP_DEFINE_RAW(["define(<WANT_REGISTER_PERCENT>, <\`$want_register_percent'>)"])
2849 GMP_DEFINE_RAW(["define(<WANT_DOT_SIZE>, <\`$want_dot_size'>)"])
2850 ])
2851
2852
2853 dnl  GMP_ASM_M68K_ADDRESSING
2854 dnl  -----------------------
2855
2856 AC_DEFUN([GMP_ASM_M68K_ADDRESSING],
2857 [AC_REQUIRE([GMP_ASM_TEXT])
2858 AC_REQUIRE([GMP_ASM_M68K_INSTRUCTION])
2859 AC_CACHE_CHECK([assembler addressing style],
2860                 gmp_cv_asm_m68k_addressing,
2861 [case $gmp_cv_asm_m68k_instruction in
2862 addl*)  movel=movel ;;
2863 add.l*) movel=move.l ;;
2864 *) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
2865 esac
2866 case $gmp_cv_asm_m68k_instruction in
2867 *"%d0,%d1") dreg=%d0; areg=%a0 ;;
2868 *"d0,d1")   dreg=d0;  areg=a0  ;;
2869 *) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
2870 esac
2871 GMP_TRY_ASSEMBLE(
2872 [       $gmp_cv_asm_text
2873         $movel  $dreg, $areg@-],
2874   [gmp_cv_asm_m68k_addressing=mit],
2875 [GMP_TRY_ASSEMBLE(
2876 [       $gmp_cv_asm_text
2877         $movel  $dreg, -($areg)],
2878   [gmp_cv_asm_m68k_addressing=motorola],
2879 [AC_MSG_ERROR([cannot determine assembler addressing style])])])
2880 ])
2881 GMP_DEFINE_RAW(["define(<WANT_ADDRESSING>, <\`$gmp_cv_asm_m68k_addressing'>)"])
2882 ])
2883
2884
2885 dnl  GMP_ASM_M68K_BRANCHES
2886 dnl  ---------------------
2887 dnl  "bra" is the standard branch instruction.  "jra" or "jbra" are
2888 dnl  preferred where available, since on gas for instance they give a
2889 dnl  displacement only as big as it needs to be, whereas "bra" is always
2890 dnl  16-bits.  This applies to the conditional branches "bcc" etc too.
2891 dnl  However "dbcc" etc on gas are already only as big as they need to be.
2892
2893 AC_DEFUN([GMP_ASM_M68K_BRANCHES],
2894 [AC_REQUIRE([GMP_ASM_TEXT])
2895 AC_CACHE_CHECK([assembler shortest branches],
2896                 gmp_cv_asm_m68k_branches,
2897 [for i in jra jbra bra; do
2898   GMP_TRY_ASSEMBLE(
2899 [       $gmp_cv_asm_text
2900 foo$gmp_cv_asm_label_suffix
2901         $i      foo],
2902   [gmp_cv_asm_m68k_branches=$i
2903   rm -f conftest*
2904   break])
2905 done
2906 if test -z "$gmp_cv_asm_m68k_branches"; then
2907   AC_MSG_ERROR([cannot determine assembler branching style])
2908 fi
2909 ])
2910 GMP_DEFINE_RAW(["define(<WANT_BRANCHES>, <\`$gmp_cv_asm_m68k_branches'>)"])
2911 ])
2912
2913
2914 dnl  GMP_ASM_POWERPC_PIC_ALWAYS
2915 dnl  --------------------------
2916 dnl  Determine whether PIC is the default compiler output.
2917 dnl
2918 dnl  SVR4 style "foo@ha" addressing is interpreted as non-PIC, and anything
2919 dnl  else is assumed to require PIC always (Darwin or AIX).  SVR4 is the
2920 dnl  only non-PIC addressing syntax the asm files have at the moment anyway.
2921 dnl
2922 dnl  Libtool does this by taking "*-*-aix* | *-*-darwin* | *-*-rhapsody*" to
2923 dnl  mean PIC always, but it seems more reliable to grep the compiler
2924 dnl  output.
2925 dnl
2926 dnl The next paragraph is untrue for Tiger.  Was it ever true?  For tiger,
2927 dnl "cc -fast" makes non-PIC the default (and the binaries do run).
2928 dnl  On Darwin "cc -static" is non-PIC with syntax "ha16(_foo)", but that's
2929 dnl  apparently only for use in the kernel, which we're not attempting to
2930 dnl  target at the moment, so don't look for that.
2931
2932 AC_DEFUN([GMP_ASM_POWERPC_PIC_ALWAYS],
2933 [AC_REQUIRE([AC_PROG_CC])
2934 AC_CACHE_CHECK([whether compiler output is PIC by default],
2935                gmp_cv_asm_powerpc_pic,
2936 [gmp_cv_asm_powerpc_pic=yes
2937 cat >conftest.c <<EOF
2938 int foo;
2939 int *bar() { return &foo; }
2940 EOF
2941 echo "Test program:" >&AC_FD_CC
2942 cat conftest.c >&AC_FD_CC
2943 gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
2944 if AC_TRY_EVAL(gmp_compile); then
2945   echo "Compiler output:" >&AC_FD_CC
2946   cat conftest.s >&AC_FD_CC
2947   if grep 'foo@ha' conftest.s >/dev/null 2>&AC_FD_CC; then
2948     gmp_cv_asm_powerpc_pic=no
2949   fi
2950   if grep 'ha16(_foo)' conftest.s >/dev/null 2>&AC_FD_CC; then
2951     gmp_cv_asm_powerpc_pic=no
2952   fi
2953 fi
2954 rm -f conftest*
2955 ])
2956 GMP_DEFINE_RAW(["define(<PIC_ALWAYS>,<$gmp_cv_asm_powerpc_pic>)"])
2957 ])
2958
2959
2960 dnl  GMP_ASM_POWERPC_R_REGISTERS
2961 dnl  ---------------------------
2962 dnl  Determine whether the assembler takes powerpc registers with an "r" as
2963 dnl  in "r6", or as plain "6".  The latter is standard, but NeXT, Rhapsody,
2964 dnl  and MacOS-X require the "r" forms.
2965 dnl
2966 dnl  See also mpn/powerpc32/powerpc-defs.m4 which uses the result of this
2967 dnl  test.
2968
2969 AC_DEFUN([GMP_ASM_POWERPC_R_REGISTERS],
2970 [AC_REQUIRE([GMP_ASM_TEXT])
2971 AC_CACHE_CHECK([if the assembler needs r on registers],
2972                gmp_cv_asm_powerpc_r_registers,
2973 [GMP_TRY_ASSEMBLE(
2974 [       $gmp_cv_asm_text
2975         mtctr   6],
2976 [gmp_cv_asm_powerpc_r_registers=no],
2977 [GMP_TRY_ASSEMBLE(
2978 [       $gmp_cv_asm_text
2979         mtctr   r6],
2980 [gmp_cv_asm_powerpc_r_registers=yes],
2981 [AC_MSG_ERROR([neither "mtctr 6" nor "mtctr r6" works])])])])
2982
2983 GMP_DEFINE_RAW(["define(<WANT_R_REGISTERS>,<$gmp_cv_asm_powerpc_r_registers>)"])
2984 ])
2985
2986
2987 dnl  GMP_ASM_SPARC_REGISTER
2988 dnl  ----------------------
2989 dnl  Determine whether the assembler accepts the ".register" directive.
2990 dnl  Old versions of solaris "as" don't.
2991 dnl
2992 dnl  See also mpn/sparc32/sparc-defs.m4 which uses the result of this test.
2993
2994 AC_DEFUN([GMP_ASM_SPARC_REGISTER],
2995 [AC_REQUIRE([GMP_ASM_TEXT])
2996 AC_CACHE_CHECK([if the assembler accepts ".register"],
2997                gmp_cv_asm_sparc_register,
2998 [GMP_TRY_ASSEMBLE(
2999 [       $gmp_cv_asm_text
3000         .register       %g2,#scratch
3001 ],
3002 [gmp_cv_asm_sparc_register=yes],
3003 [gmp_cv_asm_sparc_register=no])])
3004
3005 GMP_DEFINE_RAW(["define(<HAVE_REGISTER>,<$gmp_cv_asm_sparc_register>)"])
3006 ])
3007
3008
3009 dnl  GMP_C_ATTRIBUTE_CONST
3010 dnl  ---------------------
3011
3012 AC_DEFUN([GMP_C_ATTRIBUTE_CONST],
3013 [AC_CACHE_CHECK([whether gcc __attribute__ ((const)) works],
3014                 gmp_cv_c_attribute_const,
3015 [AC_TRY_COMPILE([int foo (int x) __attribute__ ((const));], ,
3016   gmp_cv_c_attribute_const=yes, gmp_cv_c_attribute_const=no)
3017 ])
3018 if test $gmp_cv_c_attribute_const = yes; then
3019   AC_DEFINE(HAVE_ATTRIBUTE_CONST, 1,
3020   [Define to 1 if the compiler accepts gcc style __attribute__ ((const))])
3021 fi
3022 ])
3023
3024
3025 dnl  GMP_C_ATTRIBUTE_MALLOC
3026 dnl  ----------------------
3027 dnl  gcc 2.95.x accepts __attribute__ ((malloc)) but with a warning that
3028 dnl  it's ignored.  Pretend it doesn't exist in this case, to avoid that
3029 dnl  warning.
3030
3031 AC_DEFUN([GMP_C_ATTRIBUTE_MALLOC],
3032 [AC_CACHE_CHECK([whether gcc __attribute__ ((malloc)) works],
3033                 gmp_cv_c_attribute_malloc,
3034 [cat >conftest.c <<EOF
3035 void *foo (int x) __attribute__ ((malloc));
3036 EOF
3037 gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.out 2>&1"
3038 if AC_TRY_EVAL(gmp_compile); then
3039   if grep "attribute directive ignored" conftest.out >/dev/null; then
3040     gmp_cv_c_attribute_malloc=no
3041   else
3042     gmp_cv_c_attribute_malloc=yes
3043   fi
3044 else
3045   gmp_cv_c_attribute_malloc=no
3046 fi
3047 cat conftest.out >&AC_FD_CC
3048 rm -f conftest*
3049 ])
3050 if test $gmp_cv_c_attribute_malloc = yes; then
3051   AC_DEFINE(HAVE_ATTRIBUTE_MALLOC, 1,
3052   [Define to 1 if the compiler accepts gcc style __attribute__ ((malloc))])
3053 fi
3054 ])
3055
3056
3057 dnl  GMP_C_ATTRIBUTE_MODE
3058 dnl  --------------------
3059 dnl  Introduced in gcc 2.2, but perhaps not in all Apple derived versions.
3060
3061 AC_DEFUN([GMP_C_ATTRIBUTE_MODE],
3062 [AC_CACHE_CHECK([whether gcc __attribute__ ((mode (XX))) works],
3063                 gmp_cv_c_attribute_mode,
3064 [AC_TRY_COMPILE([typedef int SItype __attribute__ ((mode (SI)));], ,
3065   gmp_cv_c_attribute_mode=yes, gmp_cv_c_attribute_mode=no)
3066 ])
3067 if test $gmp_cv_c_attribute_mode = yes; then
3068   AC_DEFINE(HAVE_ATTRIBUTE_MODE, 1,
3069   [Define to 1 if the compiler accepts gcc style __attribute__ ((mode (XX)))])
3070 fi
3071 ])
3072
3073
3074 dnl  GMP_C_ATTRIBUTE_NORETURN
3075 dnl  ------------------------
3076
3077 AC_DEFUN([GMP_C_ATTRIBUTE_NORETURN],
3078 [AC_CACHE_CHECK([whether gcc __attribute__ ((noreturn)) works],
3079                 gmp_cv_c_attribute_noreturn,
3080 [AC_TRY_COMPILE([void foo (int x) __attribute__ ((noreturn));], ,
3081   gmp_cv_c_attribute_noreturn=yes, gmp_cv_c_attribute_noreturn=no)
3082 ])
3083 if test $gmp_cv_c_attribute_noreturn = yes; then
3084   AC_DEFINE(HAVE_ATTRIBUTE_NORETURN, 1,
3085   [Define to 1 if the compiler accepts gcc style __attribute__ ((noreturn))])
3086 fi
3087 ])
3088
3089
3090 dnl  GMP_C_DOUBLE_FORMAT
3091 dnl  -------------------
3092 dnl  Determine the floating point format.
3093 dnl
3094 dnl  The object file is grepped, in order to work when cross compiling.  A
3095 dnl  start and end sequence is included to avoid false matches, and
3096 dnl  allowance is made for the desired data crossing an "od -b" line
3097 dnl  boundary.  The test number is a small integer so it should appear
3098 dnl  exactly, no rounding or truncation etc.
3099 dnl
3100 dnl  "od -b", incidentally, is supported even by Unix V7, and the awk script
3101 dnl  used doesn't have functions or anything, so even an "old" awk should
3102 dnl  suffice.
3103
3104 AC_DEFUN([GMP_C_DOUBLE_FORMAT],
3105 [AC_REQUIRE([AC_PROG_CC])
3106 AC_REQUIRE([AC_PROG_AWK])
3107 AC_CACHE_CHECK([format of `double' floating point],
3108                 gmp_cv_c_double_format,
3109 [gmp_cv_c_double_format=unknown
3110 cat >conftest.c <<\EOF
3111 [struct {
3112   char    before[8];
3113   double  x;
3114   char    after[8];
3115 } foo = {
3116   { '\001', '\043', '\105', '\147', '\211', '\253', '\315', '\357' },
3117   -123456789.0,
3118   { '\376', '\334', '\272', '\230', '\166', '\124', '\062', '\020' },
3119 };]
3120 EOF
3121 gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC 2>&1"
3122 if AC_TRY_EVAL(gmp_compile); then
3123 cat >conftest.awk <<\EOF
3124 [
3125 BEGIN {
3126   found = 0
3127 }
3128
3129 {
3130   for (f = 2; f <= NF; f++)
3131     {
3132       for (i = 0; i < 23; i++)
3133         got[i] = got[i+1];
3134       got[23] = $f;
3135
3136       # match the special begin and end sequences
3137       if (got[0] != "001") continue
3138       if (got[1] != "043") continue
3139       if (got[2] != "105") continue
3140       if (got[3] != "147") continue
3141       if (got[4] != "211") continue
3142       if (got[5] != "253") continue
3143       if (got[6] != "315") continue
3144       if (got[7] != "357") continue
3145       if (got[16] != "376") continue
3146       if (got[17] != "334") continue
3147       if (got[18] != "272") continue
3148       if (got[19] != "230") continue
3149       if (got[20] != "166") continue
3150       if (got[21] != "124") continue
3151       if (got[22] != "062") continue
3152       if (got[23] != "020") continue
3153
3154       saw = " (" got[8] " " got[9] " " got[10] " " got[11] " " got[12] " " got[13] " " got[14] " " got[15] ")"
3155
3156       if (got[8]  == "000" &&  \
3157           got[9]  == "000" &&  \
3158           got[10] == "000" &&  \
3159           got[11] == "124" &&  \
3160           got[12] == "064" &&  \
3161           got[13] == "157" &&  \
3162           got[14] == "235" &&  \
3163           got[15] == "301")
3164         {
3165           print "IEEE little endian"
3166           found = 1
3167           exit
3168         }
3169
3170       # Little endian with the two 4-byte halves swapped, as used by ARM
3171       # when the chip is in little endian mode.
3172       #
3173       if (got[8]  == "064" &&  \
3174           got[9]  == "157" &&  \
3175           got[10] == "235" &&  \
3176           got[11] == "301" &&  \
3177           got[12] == "000" &&  \
3178           got[13] == "000" &&  \
3179           got[14] == "000" &&  \
3180           got[15] == "124")
3181         {
3182           print "IEEE little endian, swapped halves"
3183           found = 1
3184           exit
3185         }
3186
3187       # gcc 2.95.4 on one GNU/Linux ARM system was seen generating 000 in
3188       # the last byte, whereas 124 is correct.  Not sure where the bug
3189       # actually lies, but a running program didn't seem to get a full
3190       # mantissa worth of working bits.
3191       #
3192       # We match this case explicitly so we can give a nice result message,
3193       # but we deliberately exclude it from the normal IEEE double setups
3194       # since it's too broken.
3195       #
3196       if (got[8]  == "064" &&  \
3197           got[9]  == "157" &&  \
3198           got[10] == "235" &&  \
3199           got[11] == "301" &&  \
3200           got[12] == "000" &&  \
3201           got[13] == "000" &&  \
3202           got[14] == "000" &&  \
3203           got[15] == "000")
3204         {
3205           print "bad ARM software floats"
3206           found = 1
3207           exit
3208         }
3209
3210       if (got[8]  == "301" &&  \
3211           got[9]  == "235" &&  \
3212           got[10] == "157" &&  \
3213           got[11] == "064" &&  \
3214           got[12] == "124" &&  \
3215           got[13] == "000" &&  \
3216           got[14] == "000" &&  \
3217           got[15] == "000")
3218         {
3219           print "IEEE big endian"
3220           found = 1
3221           exit
3222         }
3223
3224       if (got[8]  == "353" &&  \
3225           got[9]  == "315" &&  \
3226           got[10] == "242" &&  \
3227           got[11] == "171" &&  \
3228           got[12] == "000" &&  \
3229           got[13] == "240" &&  \
3230           got[14] == "000" &&  \
3231           got[15] == "000")
3232         {
3233           print "VAX D"
3234           found = 1
3235           exit
3236         }
3237
3238       if (got[8]  == "275" &&  \
3239           got[9]  == "301" &&  \
3240           got[10] == "064" &&  \
3241           got[11] == "157" &&  \
3242           got[12] == "000" &&  \
3243           got[13] == "124" &&  \
3244           got[14] == "000" &&  \
3245           got[15] == "000")
3246         {
3247           print "VAX G"
3248           found = 1
3249           exit
3250         }
3251
3252       if (got[8]  == "300" &&  \
3253           got[9]  == "033" &&  \
3254           got[10] == "353" &&  \
3255           got[11] == "171" &&  \
3256           got[12] == "242" &&  \
3257           got[13] == "240" &&  \
3258           got[14] == "000" &&  \
3259           got[15] == "000")
3260         {
3261           print "Cray CFP"
3262           found = 1
3263           exit
3264         }
3265     }
3266 }
3267
3268 END {
3269   if (! found)
3270     print "unknown", saw
3271 }
3272 ]
3273 EOF
3274   gmp_cv_c_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
3275   case $gmp_cv_c_double_format in
3276   unknown*)
3277     echo "cannot match anything, conftest.$OBJEXT contains" >&AC_FD_CC
3278     od -b conftest.$OBJEXT >&AC_FD_CC
3279     ;;
3280   esac
3281 else
3282   AC_MSG_WARN([oops, cannot compile test program])
3283 fi
3284 rm -f conftest*
3285 ])
3286
3287 AH_VERBATIM([HAVE_DOUBLE],
3288 [/* Define one of the following to 1 for the format of a `double'.
3289    If your format is not among these choices, or you don't know what it is,
3290    then leave all undefined.
3291    IEEE_LITTLE_SWAPPED means little endian, but with the two 4-byte halves
3292    swapped, as used by ARM CPUs in little endian mode.  */
3293 #undef HAVE_DOUBLE_IEEE_BIG_ENDIAN
3294 #undef HAVE_DOUBLE_IEEE_LITTLE_ENDIAN
3295 #undef HAVE_DOUBLE_IEEE_LITTLE_SWAPPED
3296 #undef HAVE_DOUBLE_VAX_D
3297 #undef HAVE_DOUBLE_VAX_G
3298 #undef HAVE_DOUBLE_CRAY_CFP])
3299
3300 case $gmp_cv_c_double_format in
3301   "IEEE big endian")
3302     AC_DEFINE(HAVE_DOUBLE_IEEE_BIG_ENDIAN, 1)
3303     GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_DOUBLE_IEEE_BIG_ENDIAN')", POST)
3304     ;;
3305   "IEEE little endian")
3306     AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_ENDIAN, 1)
3307     GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_DOUBLE_IEEE_LITTLE_ENDIAN')", POST)
3308     ;;
3309   "IEEE little endian, swapped halves")
3310     AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_SWAPPED, 1) ;;
3311   "VAX D")
3312     AC_DEFINE(HAVE_DOUBLE_VAX_D, 1) ;;
3313   "VAX G")
3314     AC_DEFINE(HAVE_DOUBLE_VAX_G, 1) ;;
3315   "Cray CFP")
3316     AC_DEFINE(HAVE_DOUBLE_CRAY_CFP, 1) ;;
3317   "bad ARM software floats")
3318     ;;
3319   unknown*)
3320     AC_MSG_WARN([Could not determine float format.])
3321     AC_MSG_WARN([Conversions to and from "double" may be slow.])
3322     ;;
3323   *)
3324     AC_MSG_WARN([oops, unrecognised float format: $gmp_cv_c_double_format])
3325     ;;
3326 esac
3327 ])
3328
3329
3330 dnl  GMP_C_STDARG
3331 dnl  ------------
3332 dnl  Test whether to use <stdarg.h> or <varargs.h>.
3333 dnl
3334 dnl  Notice the AC_DEFINE here is HAVE_STDARG to avoid clashing with
3335 dnl  HAVE_STDARG_H which could arise from AC_CHECK_HEADERS.
3336 dnl
3337 dnl  This test might be slight overkill, after all there's really only going
3338 dnl  to be ANSI or K&R and the two can be differentiated by AC_PROG_CC_STDC
3339 dnl  or very likely by the setups for _PROTO in gmp.h.  On the other hand
3340 dnl  this test is nice and direct, being what we're going to actually use.
3341
3342 AC_DEFUN([GMP_C_STDARG],
3343 [AC_CACHE_CHECK([whether <stdarg.h> exists and works],
3344                 gmp_cv_c_stdarg,
3345 [AC_TRY_COMPILE(
3346 [#include <stdarg.h>
3347 int foo (int x, ...)
3348 {
3349   va_list  ap;
3350   int      y;
3351   va_start (ap, x);
3352   y = va_arg (ap, int);
3353   va_end (ap);
3354   return y;
3355 }],,
3356 gmp_cv_c_stdarg=yes, gmp_cv_c_stdarg=no)
3357 ])
3358 if test $gmp_cv_c_stdarg = yes; then
3359   AC_DEFINE(HAVE_STDARG, 1, [Define to 1 if <stdarg.h> exists and works])
3360 fi
3361 ])
3362
3363
3364 dnl  GMP_FUNC_ALLOCA
3365 dnl  ---------------
3366 dnl  Determine whether "alloca" is available.  This is AC_FUNC_ALLOCA from
3367 dnl  autoconf, but changed so it doesn't use alloca.c if alloca() isn't
3368 dnl  available, and also to use gmp-impl.h for the conditionals detecting
3369 dnl  compiler builtin alloca's.
3370
3371 AC_DEFUN([GMP_FUNC_ALLOCA],
3372 [AC_REQUIRE([GMP_HEADER_ALLOCA])
3373 AC_CACHE_CHECK([for alloca (via gmp-impl.h)],
3374                gmp_cv_func_alloca,
3375 [AC_TRY_LINK(
3376 GMP_INCLUDE_GMP_H
3377 [#include "$srcdir/gmp-impl.h"
3378 ],
3379   [char *p = (char *) alloca (1);],
3380   gmp_cv_func_alloca=yes,
3381   gmp_cv_func_alloca=no)])
3382 if test $gmp_cv_func_alloca = yes; then
3383   AC_DEFINE(HAVE_ALLOCA, 1, [Define to 1 if alloca() works (via gmp-impl.h).])
3384 fi
3385 ])
3386
3387 AC_DEFUN([GMP_HEADER_ALLOCA],
3388 [# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
3389 # for constant arguments.  Useless!
3390 AC_CACHE_CHECK([for working alloca.h],
3391                gmp_cv_header_alloca,
3392 [AC_TRY_LINK([#include <alloca.h>],
3393   [char *p = (char *) alloca (2 * sizeof (int));],
3394   gmp_cv_header_alloca=yes,
3395   gmp_cv_header_alloca=no)])
3396 if test $gmp_cv_header_alloca = yes; then
3397   AC_DEFINE(HAVE_ALLOCA_H, 1,
3398   [Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).])
3399 fi
3400 ])
3401
3402
3403 dnl  GMP_OPTION_ALLOCA
3404 dnl  -----------------
3405 dnl  Decide what to do about --enable-alloca from the user.
3406 dnl  This is a macro so it can require GMP_FUNC_ALLOCA.
3407
3408 AC_DEFUN([GMP_OPTION_ALLOCA],
3409 [AC_REQUIRE([GMP_FUNC_ALLOCA])
3410 AC_CACHE_CHECK([how to allocate temporary memory],
3411                gmp_cv_option_alloca,
3412 [case $enable_alloca in
3413   yes)
3414     gmp_cv_option_alloca=alloca
3415     ;;
3416   no)
3417     gmp_cv_option_alloca=malloc-reentrant
3418     ;;
3419   reentrant | notreentrant)
3420     case $gmp_cv_func_alloca in
3421     yes)  gmp_cv_option_alloca=alloca ;;
3422     *)    gmp_cv_option_alloca=malloc-$enable_alloca ;;
3423     esac
3424     ;;
3425   *)
3426     gmp_cv_option_alloca=$enable_alloca
3427     ;;
3428 esac
3429 ])
3430
3431 AH_VERBATIM([WANT_TMP],
3432 [/* Define one of these to 1 for the desired temporary memory allocation
3433    method, per --enable-alloca. */
3434 #undef WANT_TMP_ALLOCA
3435 #undef WANT_TMP_REENTRANT
3436 #undef WANT_TMP_NOTREENTRANT
3437 #undef WANT_TMP_DEBUG])
3438
3439 case $gmp_cv_option_alloca in
3440   alloca)
3441     if test $gmp_cv_func_alloca = no; then
3442       AC_MSG_ERROR([--enable-alloca=alloca specified, but alloca not available])
3443     fi
3444     AC_DEFINE(WANT_TMP_ALLOCA)
3445     TAL_OBJECT=tal-reent$U.lo
3446     ;;
3447   malloc-reentrant)
3448     AC_DEFINE(WANT_TMP_REENTRANT)
3449     TAL_OBJECT=tal-reent$U.lo
3450     ;;
3451   malloc-notreentrant)
3452     AC_DEFINE(WANT_TMP_NOTREENTRANT)
3453     TAL_OBJECT=tal-notreent$U.lo
3454     ;;
3455   debug)
3456     AC_DEFINE(WANT_TMP_DEBUG)
3457     TAL_OBJECT=tal-debug$U.lo
3458     ;;
3459   *)
3460     # checks at the start of configure.in should protect us
3461     AC_MSG_ERROR([unrecognised --enable-alloca=$gmp_cv_option_alloca])
3462     ;;
3463 esac
3464 AC_SUBST(TAL_OBJECT)
3465 ])
3466
3467
3468 dnl  GMP_FUNC_SSCANF_WRITABLE_INPUT
3469 dnl  ------------------------------
3470 dnl  Determine whether sscanf requires a writable input string.
3471 dnl
3472 dnl  It might be nicer to run a program to determine this when doing a
3473 dnl  native build, but the systems afflicted are few and far between these
3474 dnl  days, so it seems good enough just to list them.
3475
3476 AC_DEFUN([GMP_FUNC_SSCANF_WRITABLE_INPUT],
3477 [AC_CACHE_CHECK([whether sscanf needs writable input],
3478                  gmp_cv_func_sscanf_writable_input,
3479 [case $host in
3480   *-*-hpux9 | *-*-hpux9.*)
3481      gmp_cv_func_sscanf_writable_input=yes ;;
3482   *) gmp_cv_func_sscanf_writable_input=no  ;;
3483 esac
3484 ])
3485 case $gmp_cv_func_sscanf_writable_input in
3486   yes) AC_DEFINE(SSCANF_WRITABLE_INPUT, 1,
3487                  [Define to 1 if sscanf requires writable inputs]) ;;
3488   no)  ;;
3489   *)   AC_MSG_ERROR([unrecognised \$gmp_cv_func_sscanf_writable_input]) ;;
3490 esac
3491 ])
3492
3493
3494 dnl  GMP_FUNC_VSNPRINTF
3495 dnl  ------------------
3496 dnl  Check whether vsnprintf exists, and works properly.
3497 dnl
3498 dnl  Systems without vsnprintf include mingw32, OSF 4.
3499 dnl
3500 dnl  Sparc Solaris 2.7 in 64-bit mode doesn't always truncate, making
3501 dnl  vsnprintf like vsprintf, and hence completely useless.  On one system a
3502 dnl  literal string is enough to provoke the problem, on another a "%n" was
3503 dnl  needed.  There seems to be something weird going on with the optimizer
3504 dnl  or something, since on the first system adding a second check with
3505 dnl  "%n", or even just an initialized local variable, makes it work.  In
3506 dnl  any case, without bothering to get to the bottom of this, the two
3507 dnl  program runs in the code below end up successfully detecting the
3508 dnl  problem.
3509 dnl
3510 dnl  glibc 2.0.x returns either -1 or bufsize-1 for an overflow (both seen,
3511 dnl  not sure which 2.0.x does which), but still puts the correct null
3512 dnl  terminated result into the buffer.
3513
3514 AC_DEFUN([GMP_FUNC_VSNPRINTF],
3515 [AC_REQUIRE([GMP_C_STDARG])
3516 AC_CHECK_FUNC(vsnprintf,
3517               [gmp_vsnprintf_exists=yes],
3518               [gmp_vsnprintf_exists=no])
3519 if test "$gmp_vsnprintf_exists" = no; then
3520   gmp_cv_func_vsnprintf=no
3521 else
3522   AC_CACHE_CHECK([whether vsnprintf works],
3523                  gmp_cv_func_vsnprintf,
3524   [gmp_cv_func_vsnprintf=yes
3525    for i in 'check ("hello world");' 'int n; check ("%nhello world", &n);'; do
3526      AC_TRY_RUN([
3527 #include <string.h>  /* for strcmp */
3528 #include <stdio.h>   /* for vsnprintf */
3529
3530 #if HAVE_STDARG
3531 #include <stdarg.h>
3532 #else
3533 #include <varargs.h>
3534 #endif
3535
3536 int
3537 #if HAVE_STDARG
3538 check (const char *fmt, ...)
3539 #else
3540 check (va_alist)
3541      va_dcl
3542 #endif
3543 {
3544   static char  buf[128];
3545   va_list  ap;
3546   int      ret;
3547
3548 #if HAVE_STDARG
3549   va_start (ap, fmt);
3550 #else
3551   char *fmt;
3552   va_start (ap);
3553   fmt = va_arg (ap, char *);
3554 #endif
3555
3556   ret = vsnprintf (buf, 4, fmt, ap);
3557
3558   if (strcmp (buf, "hel") != 0)
3559     exit (1);
3560
3561   /* allowed return values */
3562   if (ret != -1 && ret != 3 && ret != 11)
3563     exit (2);
3564
3565   return 0;
3566 }
3567
3568 int
3569 main ()
3570 {
3571 $i
3572   exit (0);
3573 }
3574 ],
3575       [:],
3576       [gmp_cv_func_vsnprintf=no; break],
3577       [gmp_cv_func_vsnprintf=probably; break])
3578   done
3579   ])
3580   if test "$gmp_cv_func_vsnprintf" = probably; then
3581     AC_MSG_WARN([cannot check for properly working vsnprintf when cross compiling, will assume it's ok])
3582   fi
3583   if test "$gmp_cv_func_vsnprintf" != no; then
3584     AC_DEFINE(HAVE_VSNPRINTF,1,
3585     [Define to 1 if you have the `vsnprintf' function and it works properly.])
3586   fi
3587 fi
3588 ])
3589
3590
3591 dnl  GMP_H_ANSI
3592 dnl  ----------
3593 dnl  Check whether gmp.h recognises the compiler as ANSI capable.
3594
3595 AC_DEFUN([GMP_H_ANSI],
3596 [AC_REQUIRE([AC_PROG_CC_STDC])
3597 case $ac_cv_prog_cc_stdc in
3598   no)
3599     ;;
3600   *)
3601     AC_TRY_COMPILE(
3602 GMP_INCLUDE_GMP_H
3603 [#if ! __GMP_HAVE_PROTOTYPES
3604 die die die
3605 #endif
3606 ],,,
3607     [AC_MSG_WARN([gmp.h doesnt recognise compiler as ANSI, prototypes and "const" will be unavailable])])
3608     ;;
3609 esac
3610 ])
3611
3612
3613 dnl  GMP_H_EXTERN_INLINE
3614 dnl  -------------------
3615 dnl  If the compiler has an "inline" of some sort, check whether the
3616 dnl  #ifdef's in gmp.h recognise it.
3617
3618 AC_DEFUN([GMP_H_EXTERN_INLINE],
3619 [AC_REQUIRE([AC_C_INLINE])
3620 case $ac_cv_c_inline in
3621 no) ;;
3622 *)
3623   AC_TRY_COMPILE(
3624 [#define __GMP_WITHIN_CONFIGURE_INLINE 1
3625 ]GMP_INCLUDE_GMP_H[
3626 #ifndef __GMP_EXTERN_INLINE
3627 die die die
3628 #endif
3629 ],,,
3630   [case $ac_cv_c_inline in
3631   yes) tmp_inline=inline ;;
3632   *)   tmp_inline=$ac_cv_c_inline ;;
3633   esac
3634   AC_MSG_WARN([gmp.h doesnt recognise compiler "$tmp_inline", inlines will be unavailable])])
3635   ;;
3636 esac
3637 ])
3638
3639
3640 dnl  GMP_H_HAVE_FILE
3641 dnl  ---------------
3642 dnl  Check whether the #ifdef's in gmp.h recognise when stdio.h has been
3643 dnl  included to get FILE.
3644
3645 AC_DEFUN([GMP_H_HAVE_FILE],
3646 [AC_TRY_COMPILE(
3647 [#include <stdio.h>]
3648 GMP_INCLUDE_GMP_H
3649 [#if ! _GMP_H_HAVE_FILE
3650 die die die
3651 #endif
3652 ],,,
3653   [AC_MSG_WARN([gmp.h doesnt recognise <stdio.h>, FILE prototypes will be unavailable])])
3654 ])
3655
3656
3657 dnl  GMP_PROG_CC_FOR_BUILD
3658 dnl  ---------------------
3659 dnl  Establish CC_FOR_BUILD, a C compiler for the build system.
3660 dnl
3661 dnl  If CC_FOR_BUILD is set then it's expected to work, likewise the old
3662 dnl  style HOST_CC, otherwise some likely candidates are tried, the same as
3663 dnl  configfsf.guess.
3664
3665 AC_DEFUN([GMP_PROG_CC_FOR_BUILD],
3666 [AC_REQUIRE([AC_PROG_CC])
3667 if test -n "$CC_FOR_BUILD"; then
3668   GMP_PROG_CC_FOR_BUILD_WORKS($CC_FOR_BUILD,,
3669     [AC_MSG_ERROR([Specified CC_FOR_BUILD doesn't seem to work])])
3670 elif test -n "$HOST_CC"; then
3671   GMP_PROG_CC_FOR_BUILD_WORKS($HOST_CC,
3672     [CC_FOR_BUILD=$HOST_CC],
3673     [AC_MSG_ERROR([Specified HOST_CC doesn't seem to work])])
3674 else
3675   for i in "$CC" "$CC $CFLAGS $CPPFLAGS" cc gcc c89 c99; do
3676     GMP_PROG_CC_FOR_BUILD_WORKS($i,
3677       [CC_FOR_BUILD=$i
3678        break])
3679   done
3680   if test -z "$CC_FOR_BUILD"; then
3681     AC_MSG_ERROR([Cannot find a build system compiler])
3682   fi
3683 fi
3684
3685 AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
3686 AC_SUBST(CC_FOR_BUILD)
3687 ])
3688
3689
3690 dnl  GMP_PROG_CC_FOR_BUILD_WORKS(cc/cflags[,[action-if-good][,action-if-bad]])
3691 dnl  -------------------------------------------------------------------------
3692 dnl  See if the given cc/cflags works on the build system.
3693 dnl
3694 dnl  It seems easiest to just use the default compiler output, rather than
3695 dnl  figuring out the .exe or whatever at this stage.
3696
3697 AC_DEFUN([GMP_PROG_CC_FOR_BUILD_WORKS],
3698 [AC_MSG_CHECKING([build system compiler $1])
3699 # remove anything that might look like compiler output to our "||" expression
3700 rm -f conftest* a.out b.out a.exe a_out.exe
3701 cat >conftest.c <<EOF
3702 int
3703 main ()
3704 {
3705   exit(0);
3706 }
3707 EOF
3708 gmp_compile="$1 conftest.c"
3709 cc_for_build_works=no
3710 if AC_TRY_EVAL(gmp_compile); then
3711   if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&AC_FD_CC 2>&1; then
3712     cc_for_build_works=yes
3713   fi
3714 fi
3715 rm -f conftest* a.out b.out a.exe a_out.exe
3716 AC_MSG_RESULT($cc_for_build_works)
3717 if test "$cc_for_build_works" = yes; then
3718   ifelse([$2],,:,[$2])
3719 else
3720   ifelse([$3],,:,[$3])
3721 fi
3722 ])
3723
3724
3725 dnl  GMP_PROG_CPP_FOR_BUILD
3726 dnl  ---------------------
3727 dnl  Establish CPP_FOR_BUILD, the build system C preprocessor.
3728 dnl  The choices tried here are the same as AC_PROG_CPP, but with
3729 dnl  CC_FOR_BUILD.
3730
3731 AC_DEFUN([GMP_PROG_CPP_FOR_BUILD],
3732 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3733 AC_MSG_CHECKING([for build system preprocessor])
3734 if test -z "$CPP_FOR_BUILD"; then
3735   AC_CACHE_VAL(gmp_cv_prog_cpp_for_build,
3736   [cat >conftest.c <<EOF
3737 #define FOO BAR
3738 EOF
3739   for i in "$CC_FOR_BUILD -E" "$CC_FOR_BUILD -E -traditional-cpp" "/lib/cpp"; do
3740     gmp_compile="$i conftest.c"
3741     if AC_TRY_EVAL(gmp_compile) >&AC_FD_CC 2>&1; then
3742       gmp_cv_prog_cpp_for_build=$i
3743       break
3744     fi
3745   done
3746   rm -f conftest* a.out b.out a.exe a_out.exe
3747   if test -z "$gmp_cv_prog_cpp_for_build"; then
3748     AC_MSG_ERROR([Cannot find build system C preprocessor.])
3749   fi
3750   ])
3751   CPP_FOR_BUILD=$gmp_cv_prog_cpp_for_build
3752 fi
3753 AC_MSG_RESULT([$CPP_FOR_BUILD])
3754
3755 AC_ARG_VAR(CPP_FOR_BUILD,[build system C preprocessor])
3756 AC_SUBST(CPP_FOR_BUILD)
3757 ])
3758
3759
3760 dnl  GMP_PROG_EXEEXT_FOR_BUILD
3761 dnl  -------------------------
3762 dnl  Determine EXEEXT_FOR_BUILD, the build system executable suffix.
3763 dnl
3764 dnl  The idea is to find what "-o conftest$foo" will make it possible to run
3765 dnl  the program with ./conftest.  On Unix-like systems this is of course
3766 dnl  nothing, for DOS it's ".exe", or for a strange RISC OS foreign file
3767 dnl  system cross compile it can be ",ff8" apparently.  Not sure if the
3768 dnl  latter actually applies to a build-system executable, maybe it doesn't,
3769 dnl  but it won't hurt to try.
3770
3771 AC_DEFUN([GMP_PROG_EXEEXT_FOR_BUILD],
3772 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3773 AC_CACHE_CHECK([for build system executable suffix],
3774                gmp_cv_prog_exeext_for_build,
3775 [cat >conftest.c <<EOF
3776 int
3777 main ()
3778 {
3779   exit (0);
3780 }
3781 EOF
3782 for i in .exe ,ff8 ""; do
3783   gmp_compile="$CC_FOR_BUILD conftest.c -o conftest$i"
3784   if AC_TRY_EVAL(gmp_compile); then
3785     if (./conftest) 2>&AC_FD_CC; then
3786       gmp_cv_prog_exeext_for_build=$i
3787       break
3788     fi
3789   fi
3790 done
3791 rm -f conftest*
3792 if test "${gmp_cv_prog_exeext_for_build+set}" != set; then
3793   AC_MSG_ERROR([Cannot determine executable suffix])
3794 fi
3795 ])
3796 AC_SUBST(EXEEXT_FOR_BUILD,$gmp_cv_prog_exeext_for_build)
3797 ])
3798
3799
3800 dnl  GMP_C_FOR_BUILD_ANSI
3801 dnl  --------------------
3802 dnl  Determine whether CC_FOR_BUILD is ANSI, and establish U_FOR_BUILD
3803 dnl  accordingly.
3804 dnl
3805 dnl  FIXME: Use AC_PROG_CC sets ac_cv_prog_cc_c89 which could be used instead
3806
3807 AC_DEFUN([GMP_C_FOR_BUILD_ANSI],
3808 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3809 AC_CACHE_CHECK([whether build system compiler is ANSI],
3810                gmp_cv_c_for_build_ansi,
3811 [cat >conftest.c <<EOF
3812 int
3813 main (int argc, char **argv)
3814 {
3815   exit(0);
3816 }
3817 EOF
3818 gmp_compile="$CC_FOR_BUILD conftest.c"
3819 if AC_TRY_EVAL(gmp_compile); then
3820   gmp_cv_c_for_build_ansi=yes
3821 else
3822   gmp_cv_c_for_build_ansi=no
3823 fi
3824 rm -f conftest* a.out b.out a.exe a_out.exe
3825 ])
3826 if test "$gmp_cv_c_for_build_ansi" = yes; then
3827   U_FOR_BUILD=
3828 else
3829   AC_SUBST(U_FOR_BUILD,_)
3830 fi
3831 ])
3832
3833
3834 dnl  GMP_CHECK_LIBM_FOR_BUILD
3835 dnl  ------------------------
3836 dnl  Establish LIBM_FOR_BUILD as -lm, if that seems to work.
3837 dnl
3838 dnl  Libtool AC_CHECK_LIBM also uses -lmw on *-ncr-sysv4.3*, if it works.
3839 dnl  Don't know what that does, lets assume it's not needed just for log().
3840
3841 AC_DEFUN([GMP_CHECK_LIBM_FOR_BUILD],
3842 [AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
3843 AC_CACHE_CHECK([for build system compiler math library],
3844                gmp_cv_check_libm_for_build,
3845 [cat >conftest.c <<EOF
3846 int
3847 main ()
3848 {
3849   exit(0);
3850 }
3851 double d;
3852 double
3853 foo ()
3854 {
3855   return log (d);
3856 }
3857 EOF
3858 gmp_compile="$CC_FOR_BUILD conftest.c -lm"
3859 if AC_TRY_EVAL(gmp_compile); then
3860   gmp_cv_check_libm_for_build=-lm
3861 else
3862   gmp_cv_check_libm_for_build=no
3863 fi
3864 rm -f conftest* a.out b.out a.exe a_out.exe
3865 ])
3866 case $gmp_cv_check_libm_for_build in
3867   yes) AC_SUBST(LIBM_FOR_BUILD,-lm) ;;
3868   no)  LIBM_FOR_BUILD= ;;
3869   *)   LIBM_FOR_BUILD=$gmp_cv_check_libm_for_build ;;
3870 esac
3871 ])