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