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