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