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