source: trunk/third/gmp/acinclude.m4 @ 22254

Revision 22254, 77.0 KB checked in by ghudson, 19 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r22253, which included commits to RCS files with non-trunk default branches.
Line 
1dnl  GMP specific autoconf macros
2
3
4dnl  Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
5dnl
6dnl  This file is part of the GNU MP Library.
7dnl
8dnl  The GNU MP Library is free software; you can redistribute it and/or modify
9dnl  it under the terms of the GNU Lesser General Public License as published
10dnl  by the Free Software Foundation; either version 2.1 of the License, or (at
11dnl  your option) any later version.
12dnl
13dnl  The GNU MP Library is distributed in the hope that it will be useful, but
14dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16dnl  License for more details.
17dnl
18dnl  You should have received a copy of the GNU Lesser General Public License
19dnl  along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
20dnl  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21dnl  MA 02111-1307, USA.
22
23
24define(X86_PATTERN,
25[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-*]])
26
27define(POWERPC64_PATTERN,
28[[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-*]])
29
30
31dnl  GMP_STRIP_PATH(subdir)
32dnl  ----------------------
33dnl  Strip entries */subdir from $path.
34
35define(GMP_STRIP_PATH,
36[tmp_path=
37for i in $path; do
38  case $i in
39    */$1) ;;
40    *) tmp_path="$tmp_path $i" ;;
41  esac
42done
43path="$tmp_path"
44])
45
46
47dnl  GMP_INCLUDE_GMP_H
48dnl  -----------------
49dnl  Expand to the right way to #include gmp-h.in.  This must be used
50dnl  instead of gmp.h, since that file isn't generated until the end of the
51dnl  configure.
52dnl
53dnl  GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB starts as a dummy, but gets
54dnl  redefined in GMP_C_SIZES when the right value is known.
55
56define(GMP_INCLUDE_GMP_H,
57[[#define __GMP_WITHIN_CONFIGURE 1   /* ignore template stuff */
58#define GMP_NAIL_BITS $GMP_NAIL_BITS]
59GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB
60[$DEFN_LONG_LONG_LIMB
61#include "$srcdir/gmp-h.in"]
62])
63
64define(GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB,
65[[#define __GMP_BITS_PER_MP_LIMB 123 /* dummy for GMP_NUMB_BITS etc */
66#define GMP_LIMB_BITS 123]])
67
68
69dnl  GMP_HEADER_GETVAL(NAME,FILE)
70dnl  ----------------------------
71dnl  Expand at autoconf time to the value of a "#define NAME" from the given
72dnl  FILE.  The regexps here aren't very rugged, but are enough for gmp.
73dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
74
75define(GMP_HEADER_GETVAL,
76[patsubst(patsubst(
77esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
78[^.*$1[         ]+],[]),
79[[
80        ]*$],[])])
81
82
83dnl  GMP_VERSION
84dnl  -----------
85dnl  The gmp version number, extracted from the #defines in gmp-h.in at
86dnl  autoconf time.  Two digits like 3.0 if patchlevel <= 0, or three digits
87dnl  like 3.0.1 if patchlevel > 0.
88
89define(GMP_VERSION,
90[GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl
91.GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl
92ifelse(m4_eval(GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in) > 0),1,
93[.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])])
94
95
96dnl  GMP_SUBST_CHECK_FUNCS(func,...)
97dnl  ------------------------------
98dnl  Setup an AC_SUBST of HAVE_FUNC_01 for each argument.
99
100AC_DEFUN(GMP_SUBST_CHECK_FUNCS,
101[m4_if([$1],,,
102[_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01)
103GMP_SUBST_CHECK_FUNCS(m4_shift($@))])])
104
105dnl  Called: _GMP_SUBST_CHECK_FUNCS(cachvar,substvar)
106AC_DEFUN(_GMP_SUBST_CHECK_FUNCS,
107[case $[$1] in
108yes) AC_SUBST([$2],1) ;;
109no)  [$2]=0 ;;
110esac
111])
112
113
114dnl  GMP_SUBST_CHECK_HEADERS(foo.h,...)
115dnl  ----------------------------------
116dnl  Setup an AC_SUBST of HAVE_FOO_H_01 for each argument.
117
118AC_DEFUN(GMP_SUBST_CHECK_HEADERS,
119[m4_if([$1],,,
120[_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]),
121HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01)
122GMP_SUBST_CHECK_HEADERS(m4_shift($@))])])
123
124dnl  Called: _GMP_SUBST_CHECK_HEADERS(cachvar,substvar)
125AC_DEFUN(_GMP_SUBST_CHECK_HEADERS,
126[case $[$1] in
127yes) AC_SUBST([$2],1) ;;
128no)  [$2]=0 ;;
129esac
130])
131
132
133dnl  GMP_COMPARE_GE(A1,B1, A2,B2, ...)
134dnl  ---------------------------------
135dnl  Compare two version numbers A1.A2.etc and B1.B2.etc.  Set
136dnl  $gmp_compare_ge to yes or no accoring to the result.  The A parts
137dnl  should be variables, the B parts fixed numbers.  As many parts as
138dnl  desired can be included.  An empty string in an A part is taken to be
139dnl  zero, the B parts should be non-empty and non-zero.
140dnl
141dnl  For example,
142dnl
143dnl      GMP_COMPARE($major,10, $minor,3, $subminor,1)
144dnl
145dnl  would test whether $major.$minor.$subminor is greater than or equal to
146dnl  10.3.1.
147
148AC_DEFUN(GMP_COMPARE_GE,
149[gmp_compare_ge=no
150GMP_COMPARE_GE_INTERNAL($@)
151])
152
153AC_DEFUN(GMP_COMPARE_GE_INTERNAL,
154[ifelse(len([$3]),0,
155[if test -n "$1" && test "$1" -ge $2; then
156  gmp_compare_ge=yes
157fi],
158[if test -n "$1"; then
159  if test "$1" -gt $2; then
160    gmp_compare_ge=yes
161  else
162    if test "$1" -eq $2; then
163      GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@)))
164    fi
165  fi
166fi])
167])
168 
169
170dnl  GMP_PROG_AR
171dnl  -----------
172dnl  GMP additions to $AR.
173dnl
174dnl  A cross-"ar" may be necessary when cross-compiling since the build
175dnl  system "ar" might try to interpret the object files to build a symbol
176dnl  table index, hence the use of AC_CHECK_TOOL.
177dnl
178dnl  A user-selected $AR is always left unchanged.  AC_CHECK_TOOL is still
179dnl  run to get the "checking" message printed though.
180dnl
181dnl  $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru".  The
182dnl  latter fails when libtool goes into piecewise mode and is unlucky
183dnl  enough to have two same-named objects in separate pieces, as happens
184dnl  for instance to random.o (and others) on vax-dec-ultrix4.5.  Naturally
185dnl  a user-selected $AR_FLAGS is left unchanged.
186
187AC_DEFUN(GMP_PROG_AR,
188[dnl  Want to establish $AR before libtool initialization.
189AC_BEFORE([$0],[AC_PROG_LIBTOOL])
190gmp_user_AR=$AR
191AC_CHECK_TOOL(AR, ar, ar)
192if test -z "$gmp_user_AR"; then
193                        eval arflags=\"\$ar${abi1}_flags\"
194  test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\"
195  if test -n "$arflags"; then
196    AC_MSG_CHECKING([for extra ar flags])
197    AR="$AR $arflags"
198    AC_MSG_RESULT([$arflags])
199  fi
200fi
201if test -z "$AR_FLAGS"; then
202  AR_FLAGS=cq
203fi
204])
205
206
207dnl  GMP_PROG_HOST_CC
208dnl  ----------------
209dnl  Establish a value for $HOST_CC.
210dnl
211dnl  Any HOST_CC already set is used without testing.  Likewise any
212dnl  CC_FOR_BUILD is used without testing.  CC_FOR_BUILD is the new name for
213dnl  a build system compiler, see configfsf.guess.
214
215AC_DEFUN(GMP_PROG_HOST_CC,
216[AC_BEFORE([$0],[AC_PROG_LIBTOOL])
217AC_REQUIRE([AC_PROG_CC])
218AC_CACHE_CHECK([for HOST_CC build system compiler],
219               gmp_cv_prog_host_cc,
220[if test -n "$HOST_CC"; then
221  gmp_cv_prog_host_cc=$HOST_CC
222else
223  if test -n "$CC_FOR_BUILD"; then
224    gmp_cv_prog_host_cc=$CC_FOR_BUILD
225  else
226    cat >conftest.c <<EOF
227int main () { exit(0); }
228EOF
229    for c in "$CC" cc gcc c89; do
230      echo "trying $c" >&AC_FD_CC       
231      if ($c conftest.c -o conftest) >&AC_FD_CC 2>&1; then
232        if (./conftest) >&AC_FD_CC 2>&1; then
233          gmp_cv_prog_host_cc=$c
234          break
235        fi
236      fi
237    done
238    rm -f conftest*
239    if test -z "$gmp_cv_prog_host_cc"; then
240      AC_MSG_ERROR([cannot find a build system compiler])
241    fi
242  fi
243fi
244])
245HOST_CC=$gmp_cv_prog_host_cc
246])
247
248
249dnl  GMP_PROG_LEX
250dnl  ------------
251dnl  AC_PROG_LEX bombs if $LEX is set to ${am_missing_run}flex by
252dnl  AM_PROG_LEX.  It needs to see LEX=: if lex is missing.  Avoid this by
253dnl  running AC_PROG_LEX first and then using "missing".
254dnl
255dnl  FIXME: This can be removed and just AM_PROG_LEX used, one that macro
256dnl  works properly.
257
258AC_DEFUN(GMP_PROG_LEX,
259[AC_REQUIRE([AC_PROG_LEX])
260if test "$LEX" = :; then
261  LEX=${am_missing_run}flex
262fi
263])
264
265
266dnl  GMP_PROG_M4
267dnl  -----------
268dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
269dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
270dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
271dnl  AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
272dnl  good enough.
273dnl
274dnl  See mpn/asm-defs.m4 for details on the known bad m4s.
275
276AC_DEFUN(GMP_PROG_M4,
277[AC_ARG_VAR(M4,[m4 macro processor])
278AC_CACHE_CHECK([for suitable m4],
279                gmp_cv_prog_m4,
280[if test -n "$M4"; then
281  gmp_cv_prog_m4="$M4"
282else
283  cat >conftest.m4 <<\EOF
284dnl  Must protect this against being expanded during autoconf m4!
285dnl  Dont put "dnl"s in this as autoconf will flag an error for unexpanded
286dnl  macros.
287[define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
288``bad: $][# not supported (SunOS /usr/bin/m4)
289'')ifelse(eval(89),89,`define(t2,Y)',
290`bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
291')ifelse(t1`'t2,YY,`good
292')]
293EOF
294dnl ' <- balance the quotes for emacs sh-mode
295  echo "trying m4" >&AC_FD_CC
296  gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
297  echo "$gmp_tmp_val" >&AC_FD_CC
298  if test "$gmp_tmp_val" = good; then
299    gmp_cv_prog_m4="m4"
300  else
301    IFS="${IFS=         }"; ac_save_ifs="$IFS"; IFS=":"
302dnl $ac_dummy forces splitting on constant user-supplied paths.
303dnl POSIX.2 word splitting is done only on the output of word expansions,
304dnl not every word.  This closes a longstanding sh security hole.
305    ac_dummy="$PATH:/usr/5bin"
306    for ac_dir in $ac_dummy; do
307      test -z "$ac_dir" && ac_dir=.
308      echo "trying $ac_dir/m4" >&AC_FD_CC
309      gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
310      echo "$gmp_tmp_val" >&AC_FD_CC
311      if test "$gmp_tmp_val" = good; then
312        gmp_cv_prog_m4="$ac_dir/m4"
313        break
314      fi
315    done
316    IFS="$ac_save_ifs"
317    if test -z "$gmp_cv_prog_m4"; then
318      AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
319    fi
320  fi
321  rm -f conftest.m4
322fi])
323M4="$gmp_cv_prog_m4"
324AC_SUBST(M4)
325])
326
327
328dnl  GMP_M4_M4WRAP_SPURIOUS
329dnl  ----------------------
330dnl  Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4.
331dnl
332dnl  The following systems have been seen with the problem.
333dnl
334dnl  - Unicos alpha, but its assembler doesn't seem to mind.
335dnl  - MacOS X Darwin, its assembler fails.
336dnl  - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores
337dnl    the bad last line since it doesn't have a newline.
338dnl  - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind.
339dnl
340dnl  Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer
341dnl  an m4 with a working m4wrap, if it can be found.
342
343AC_DEFUN(GMP_M4_M4WRAP_SPURIOUS,
344[AC_REQUIRE([GMP_PROG_M4])
345AC_CACHE_CHECK([if m4wrap produces spurious output],
346               gmp_cv_m4_m4wrap_spurious,
347[# hide the d-n-l from autoconf's error checking
348tmp_d_n_l=d""nl
349cat >conftest.m4 <<EOF
350[changequote({,})define(x,)m4wrap({x})$tmp_d_n_l]
351EOF
352echo test input is >&AC_FD_CC
353cat conftest.m4 >&AC_FD_CC
354tmp_chars=`$M4 conftest.m4 | wc -c`
355echo produces $tmp_chars chars output >&AC_FD_CC
356rm -f conftest.m4
357if test $tmp_chars = 0; then
358  gmp_cv_m4_m4wrap_spurious=no
359else
360  gmp_cv_m4_m4wrap_spurious=yes
361fi
362])
363GMP_DEFINE_RAW(["define(<M4WRAP_SPURIOUS>,<$gmp_cv_m4_m4wrap_spurious>)"])
364])
365
366
367dnl  GMP_PROG_NM
368dnl  -----------
369dnl  GMP additions to libtool AC_PROG_NM.
370dnl
371dnl  Note that if AC_PROG_NM can't find a working nm it still leaves
372dnl  $NM set to "nm", so $NM can't be assumed to actually work.
373dnl
374dnl  A user-selected $NM is always left unchanged.  AC_PROG_NM is still run
375dnl  to get the "checking" message printed though.
376
377AC_DEFUN(GMP_PROG_NM,
378[dnl  Make sure we're the first to call AC_PROG_NM, so our extra flags are
379dnl   used by everyone.
380AC_BEFORE([$0],[AC_PROG_NM])
381gmp_user_NM=$NM
382AC_PROG_NM
383
384# FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool
385# defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found.  In this
386# case run it again to try the native "nm", firstly so that likely locations
387# are searched, secondly so that -B or -p are added if necessary for BSD
388# format.  This is necessary for instance on OSF with "./configure
389# --build=alphaev5-dec-osf --host=alphaev6-dec-osf".
390#
391if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then
392  $as_unset lt_cv_path_NM
393  gmp_save_ac_tool_prefix=$ac_tool_prefix
394  ac_tool_prefix=
395  NM=
396  AC_PROG_NM
397  ac_tool_prefix=$gmp_save_ac_tool_prefix
398fi
399
400if test -z "$gmp_user_NM"; then
401                        eval nmflags=\"\$nm${abi1}_flags\"
402  test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\"
403  if test -n "$nmflags"; then
404    AC_MSG_CHECKING([for extra nm flags])
405    NM="$NM $nmflags"
406    AC_MSG_RESULT([$nmflags])
407  fi
408fi
409])
410
411
412dnl  GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS])
413dnl  --------------------------------------------------------------------
414dnl  Check if cc+cflags can compile and link.
415dnl
416dnl  This test is designed to be run repeatedly with different cc+cflags
417dnl  selections, so the result is not cached.
418dnl
419dnl  For a native build, meaning $cross_compiling == no, we require that the
420dnl  generated program will run.  This is the same as AC_PROG_CC does in
421dnl  _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass
422dnl  a CC/CFLAGS combination that it rejects.
423dnl
424dnl  sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel
425dnl  was booted in 32-bit mode.  The effect of requiring the compiler output
426dnl  will run is that a plain native "./configure" falls back on ABI=32, but
427dnl  ABI=64 is still available as a cross-compile.
428
429AC_DEFUN(GMP_PROG_CC_WORKS,
430[AC_MSG_CHECKING([compiler $1])
431cat >conftest.c <<EOF
432
433/* The following provokes an internal error from gcc 2.95.2 -mpowerpc64
434   (without -maix64), hence detecting an unusable compiler */
435void *g() { return (void *) 0; }
436void *f() { return g(); }
437
438/* The following provokes an invalid instruction syntax from i386 gcc
439   -march=pentiumpro on Solaris 2.8.  The native sun assembler
440   requires a non-standard syntax for cmov which gcc (as of 2.95.2 at
441   least) doesn't know.  */
442int n;
443int cmov () { return (n >= 0 ? n : 0); }
444
445/* The following provokes a linker invocation problem with gcc 3.0.3
446   on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630".  The -mcpu=630
447   option causes gcc to incorrectly select the 32-bit libgcc.a, not
448   the 64-bit one, and consequently it misses out on the __fixunsdfdi
449   helper (double -> uint64 conversion).  */
450double d;
451unsigned long gcc303 () { return (unsigned long) d; }
452
453int main () { return 0; }
454EOF
455gmp_prog_cc_works=no
456gmp_compile="$1 conftest.c >&AC_FD_CC"
457if AC_TRY_EVAL(gmp_compile); then
458  if test "$cross_compiling" = no; then
459    if AC_TRY_COMMAND([./a.out || ./a.exe || ./conftest]); then
460      gmp_prog_cc_works=yes
461    fi
462  else
463    gmp_prog_cc_works=yes
464  fi
465fi
466rm -f conftest* a.out a.exe
467AC_MSG_RESULT($gmp_prog_cc_works)
468if test $gmp_prog_cc_works = yes; then
469  ifelse([$2],,:,[$2])
470else
471  ifelse([$3],,:,[$3])
472fi
473])
474
475
476dnl  GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
477dnl  -------------------------------------------------------
478dnl  Determine whether the given compiler is GNU C.
479dnl
480dnl  This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't
481dnl  cache the result.  The same "ifndef" style test is used, to avoid
482dnl  problems with syntax checking cpp's used on NeXT and Apple systems.
483
484AC_DEFUN(GMP_PROG_CC_IS_GNU,
485[cat >conftest.c <<EOF
486#ifndef __GNUC__
487  choke me
488#endif
489EOF
490gmp_compile="$1 -c conftest.c >&AC_FD_CC"
491if AC_TRY_EVAL(gmp_compile); then
492  rm -f conftest*
493  AC_MSG_CHECKING([whether $1 is gcc])
494  AC_MSG_RESULT(yes)
495  ifelse([$2],,:,[$2])
496else
497  rm -f conftest*
498  ifelse([$3],,:,[$3])
499fi
500])
501
502
503dnl  GMP_PROG_CC_IS_XLC(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
504dnl  -------------------------------------------------------
505dnl  Determine whether the given compiler is IBM xlc (on AIX).
506dnl
507dnl  There doesn't seem to be a preprocessor symbol to test for this, or if
508dnl  there is one then it's well hidden in xlc 3.1 on AIX 4.3, so just grep
509dnl  the man page printed when xlc is invoked with no arguments.
510
511AC_DEFUN(GMP_PROG_CC_IS_XLC,
512[gmp_command="$1 2>&1 | grep xlc >/dev/null"
513if AC_TRY_EVAL(gmp_command); then
514  AC_MSG_CHECKING([whether $1 is xlc])
515  AC_MSG_RESULT(yes)
516  ifelse([$2],,:,[$2])
517else
518  ifelse([$3],,:,[$3])
519fi
520])
521
522
523dnl  GMP_HPC_HPPA_2_0(cc,[ACTION-IF-GOOD][,ACTION-IF-BAD])
524dnl  ---------------------------------------------------------
525dnl  Find out whether a HP compiler is good enough to generate hppa 2.0.
526dnl
527dnl  This test might be repeated for different compilers, so the result is
528dnl  not cached.
529
530AC_DEFUN(GMP_HPC_HPPA_2_0,
531[AC_MSG_CHECKING([whether HP compiler $1 is good for 64-bits])
532# Bad compiler output:
533#   ccom: HP92453-01 G.10.32.05 HP C Compiler
534# Good compiler output:
535#   ccom: HP92453-01 A.10.32.30 HP C Compiler
536# Let A.10.32.30 or higher be ok.
537echo >conftest.c
538gmp_tmp_vs=`$1 $2 -V -c -o conftest.$OBJEXT conftest.c 2>&1 | grep "^ccom:"`
539echo "Version string: $gmp_tmp_vs" >&AC_FD_CC
540rm conftest*
541gmp_tmp_v1=`echo $gmp_tmp_vs | sed 's/.* .\.\(.*\)\..*\..* HP C.*/\1/'`
542gmp_tmp_v2=`echo $gmp_tmp_vs | sed 's/.* .\..*\.\(.*\)\..* HP C.*/\1/'`
543gmp_tmp_v3=`echo $gmp_tmp_vs | sed 's/.* .\..*\..*\.\(.*\) HP C.*/\1/'`
544echo "Version number: $gmp_tmp_v1.$gmp_tmp_v2.$gmp_tmp_v3" >&AC_FD_CC
545if test -z "$gmp_tmp_v1"; then
546  gmp_hpc_64bit=not-applicable
547else
548  GMP_COMPARE_GE($gmp_tmp_v1, 10, $gmp_tmp_v2, 32, $gmp_tmp_v3, 30)
549  gmp_hpc_64bit=$gmp_compare_ge
550fi
551AC_MSG_RESULT($gmp_hpc_64bit)
552if test $gmp_hpc_64bit = yes; then
553  ifelse([$2],,:,[$2])
554else
555  ifelse([$3],,:,[$3])
556fi
557])
558
559
560dnl  GMP_GCC_VERSION_GE(CC,MAJOR[,MINOR[,SUBMINOR]])
561dnl  -----------------------------------------------
562dnl  Test whether the version of CC (which must be GNU C) is >=
563dnl  MAJOR.MINOR.SUBMINOR.  Set $gmp_compare_ge to "yes" or "no"
564dnl  accordingly, or to "error" if the version number string can't be
565dnl  parsed.
566dnl
567dnl  gcc --version is normally just "2.7.2.3" or "2.95.3" or whatever, but
568dnl  egcs gives something like "egcs-2.91".  "[a-z-]*" is used to match that
569dnl  (Solaris 8 sed doesn't support "?" or "*" of a group, like "\(...\)?"
570dnl  or "\(...\)*".)
571dnl
572dnl  There's no caching here, so that different CC's can be tested.
573
574AC_DEFUN(GMP_GCC_VERSION_GE,
575[tmp_version=`($1 --version) 2>&AC_FD_CC`
576echo "$1 --version '$tmp_version'" >&AC_FD_CC
577
578major=`(echo "$tmp_version" | sed -n ['s/^[a-z-]*\([0-9][0-9]*\).*/\1/p']) 2>&AC_FD_CC`
579echo "    major '$major'" >&AC_FD_CC
580
581ifelse([$3],,,
582[minor=`(echo "$tmp_version" | sed -n ['s/^[a-z-]*[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/p']) 2>&AC_FD_CC`
583echo "    minor '$minor'" >&AC_FD_CC])
584
585ifelse([$4],,,
586[subminor=`(echo "$tmp_version" | sed -n ['s/^[a-z-]*[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/p']) 2>&AC_FD_CC`
587echo "    subminor '$subminor'" >&AC_FD_CC])
588
589if test -z "$major"; then
590  AC_MSG_WARN([unrecognised gcc version string: $tmp_version])
591  gmp_compare_ge=error
592else
593  ifelse([$3],, [GMP_COMPARE_GE($major, $2)],
594  [ifelse([$4],,[GMP_COMPARE_GE($major, $2, $minor, $3)],
595                [GMP_COMPARE_GE($major, $2, $minor, $3, $subminor, $4)])])
596fi
597])
598
599
600dnl  GMP_GCC_ARM_UMODSI(CC,[ACTIONS-IF-GOOD][,ACTIONS-IF-BAD])
601dnl  ---------------------------------------------------------
602dnl  gcc 2.95.3 and earlier on arm has a bug in the libgcc __umodsi routine
603dnl  making "%" give wrong results for some operands, eg. "0x90000000 % 3".
604dnl  We're hoping it'll be fixed in 2.95.4, and we know it'll be fixed in
605dnl  gcc 3.
606dnl
607dnl  There's only a couple of places gmp cares about this, one is the
608dnl  size==1 case in mpn/generic/mode1o.c, and this shows up in
609dnl  tests/mpz/t-jac.c as a wrong result from mpz_kronecker_ui.
610
611AC_DEFUN(GMP_GCC_ARM_UMODSI,
612[AC_MSG_CHECKING([whether ARM gcc unsigned division works])
613tmp_version=`$1 --version`
614echo "$tmp_version" >&AC_FD_CC
615case $tmp_version in
616  [2.95 | 2.95.[123]])
617    ifelse([$3],,:,[$3])
618    gmp_gcc_arm_umodsi_result="no, gcc 2.95.[0123]" ;;
619  *)
620    ifelse([$2],,:,[$2])
621    gmp_gcc_arm_umodsi_result=yes ;;
622esac
623AC_MSG_RESULT([$gmp_gcc_arm_umodsi_result])
624])
625
626
627dnl  GMP_GCC_MARCH_PENTIUMPRO(CC,[ACTIONS-IF-GOOD][,ACTIONS-IF-BAD])
628dnl  ---------------------------------------------------------------
629dnl  mpz/powm.c swox cvs rev 1.4 tickled a bug in gcc 2.95.2 and 2.95.3 when
630dnl  -march=pentiumpro was used.  The bug was wrong handling of the input to
631dnl  an ABSIZ(z) expression in mpz_redc().  Fixed in 2.95.4 and pre-release
632dnl  3.0, and didn't seem to occur in unofficial 2.96, so test for 2.95.4
633dnl  and up.
634dnl
635dnl  This macro is used only once, after finalizing a choice of CC, so the
636dnl  result is cached.
637
638AC_DEFUN(GMP_GCC_MARCH_PENTIUMPRO,
639[AC_CACHE_CHECK([whether gcc -march=pentiumpro is good],
640                gmp_cv_gcc_march_pentiumpro,
641[GMP_GCC_VERSION_GE([$1], 2,95,4)
642case $gmp_compare_ge in
643yes|no)  gmp_cv_gcc_march_pentiumpro=$gmp_compare_ge ;;
644error|*) gmp_cv_gcc_march_pentiumpro=no ;;
645esac])
646if test $gmp_cv_gcc_march_pentiumpro = yes; then
647  ifelse([$2],,:,[$2])
648else
649  ifelse([$3],,:,[$3])
650fi
651])
652
653
654dnl  GMP_GCC_M68K_OPTIMIZE(CCBASE,CC,FLAG-VARIABLE)
655dnl  ----------------------------------------------
656dnl  m68k gcc 2.95.x gets an internal compiler error when compiling the
657dnl  current mpn/generic/gcdext.c (swox cvs rev 1.20) under -O2 or higher,
658dnl  so just use -O for the offending gcc versions.  Naturally if gcdext.c
659dnl  gets rearranged or rewritten so the ICE doesn't happen then this can be
660dnl  removed.
661
662AC_DEFUN(GMP_GCC_M68K_OPTIMIZE,
663[case $host in
664m68*-*-*)
665  if test $1 = gcc; then
666    case `$2 --version` in
667    2.95*) $3=-O ;;
668    esac
669  fi
670  ;;
671esac
672])
673
674
675dnl  GMP_GCC_MIPS_O32(gcc,[actions-yes][,[actions-no]])
676dnl  -------------------------------------------------
677dnl  Test whether gcc supports o32.
678dnl
679dnl  gcc 2.7.2.2 only does o32, and doesn't accept -mabi=32.
680dnl
681dnl  gcc 2.95 accepts -mabi=32 but it only works on irix5, on irix6 it gives
682dnl  "cc1: The -mabi=32 support does not work yet".
683
684AC_DEFUN(GMP_GCC_MIPS_O32,
685[AC_MSG_CHECKING([whether gcc supports o32])
686echo 'int x;' >conftest.c
687echo "$1 -mabi=32 -c conftest.c" >&AC_FD_CC
688if $1 -mabi=32 -c conftest.c >conftest.out 2>&1; then
689  result=yes
690else
691  cat conftest.out >&AC_FD_CC
692  if grep "cc1: Invalid option \`abi=32'" conftest.out >/dev/null; then
693    result=yes
694  else
695    result=no
696  fi
697fi
698rm -f conftest.*
699AC_MSG_RESULT($result)
700if test $result = yes; then
701  ifelse([$2],,:,[$2])
702else
703  ifelse([$3],,:,[$3])
704fi
705])
706
707
708dnl  GMP_GCC_NO_CPP_PRECOMP(CCBASE,CC,CFLAGS,[ACTIONS-YES][,ACTIONS-NO])
709dnl  -------------------------------------------------------------------
710dnl  Check whether -no-cpp-precomp should be used on this compiler, and
711dnl  execute the corresponding ACTIONS-YES or ACTIONS-NO.
712dnl
713dnl  -no-cpp-precomp is only meant for Apple's hacked version of gcc found
714dnl  on powerpc*-*-darwin*, but we can give it a try on any gcc.  Normal gcc
715dnl  (as of 3.0 at least) only gives a warning, not an actual error, and we
716dnl  watch for that and decide against the option in that case, to avoid
717dnl  confusing the user.
718
719AC_DEFUN(GMP_GCC_NO_CPP_PRECOMP,
720[if test "$ccbase" = gcc; then
721  AC_MSG_CHECKING([compiler $2 $3 -no-cpp-precomp])
722  result=no
723  cat >conftest.c <<EOF
724int main () { return 0; }
725EOF
726  gmp_compile="$2 $3 -no-cpp-precomp conftest.c >conftest.out 2>&1"
727  if AC_TRY_EVAL(gmp_compile); then
728    if grep "unrecognized option.*-no-cpp-precomp" conftest.out >/dev/null; then : ;
729    else
730      result=yes
731    fi
732  fi
733  cat conftest.out >&AC_FD_CC
734  rm -f conftest* a.out
735  AC_MSG_RESULT($result)
736  if test "$result" = yes; then
737      ifelse([$4],,:,[$4])
738  else
739      ifelse([$5],,:,[$5])
740  fi
741fi
742])
743
744
745dnl  GMP_GCC_WA_MCPU(CC+CFLAGS, NEWFLAG [,ACTION-YES [,ACTION-NO]])
746dnl  --------------------------------------------------------------
747dnl  Check whether gcc (or gas rather) accepts a flag like "-Wa,-mev67".
748dnl
749dnl  Gas doesn't give an error for an unknown cpu, it only prints a warning
750dnl  like "Warning: Unknown CPU identifier `ev78'".
751dnl
752dnl  This is intended for use on alpha, since only recent versions of gas
753dnl  accept -mev67, but there's nothing here that's alpha specific.
754
755AC_DEFUN(GMP_GCC_WA_MCPU,
756[AC_MSG_CHECKING([assembler $1 $2])
757result=no
758cat >conftest.c <<EOF
759int main () {}
760EOF
761gmp_compile="$1 $2 -c conftest.c >conftest.out 2>&1"
762if AC_TRY_EVAL(gmp_compile); then
763  if grep "Unknown CPU identifier" conftest.out >/dev/null; then : ;
764  else
765    result=yes
766  fi   
767fi
768cat conftest.out >&AC_FD_CC
769rm -f conftest*
770AC_MSG_RESULT($result)
771if test "$result" = yes; then
772  ifelse([$3],,:,[$3])
773else
774  ifelse([$4],,:,[$4])
775fi
776])
777
778
779dnl  GMP_PROG_CXX_WORKS(cxx/cxxflags [, ACTION-YES [,ACTION-NO]])
780dnl  ------------------------------------------------------------
781dnl  Check whether cxx/cxxflags can compile and link.
782dnl
783dnl  This test is designed to be run repeatedly with different cxx/cxxflags
784dnl  selections, so the result is not cached.
785
786AC_DEFUN(GMP_PROG_CXX_WORKS,
787[AC_MSG_CHECKING([C++ compiler $1])
788cat >conftest.cc <<EOF
789#include <iostream>
790using namespace std;
791int
792main (void)
793{
794  cout.setf (ios::hex);
795  cout << 123;
796  return 0;
797}
798EOF
799
800gmp_cxxcompile="$1 conftest.cc -o conftest >&AC_FD_CC"
801if AC_TRY_EVAL(gmp_cxxcompile); then
802  rm -f conftest*
803  AC_MSG_RESULT(yes)
804  ifelse([$2],,:,[$2])
805else
806  rm -f conftest*
807  AC_MSG_RESULT(no)
808  ifelse([$3],,:,[$3])
809fi
810])
811
812
813dnl  GMP_INIT([M4-DEF-FILE])
814dnl  -----------------------
815dnl  Initializations for GMP config.m4 generation.
816dnl
817dnl  FIXME: The generated config.m4 doesn't get recreated by config.status.
818dnl  Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.
819
820AC_DEFUN(GMP_INIT,
821[ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
822gmp_tmpconfigm4=cnfm4.tmp
823gmp_tmpconfigm4i=cnfm4i.tmp
824gmp_tmpconfigm4p=cnfm4p.tmp
825rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p
826
827# CONFIG_TOP_SRCDIR is a path from the mpn builddir to the top srcdir.
828# The pattern here tests for an absolute path the same way as
829# _AC_OUTPUT_FILES in autoconf acgeneral.m4.
830case $srcdir in
831[[\\/]]* | ?:[[\\/]]* )  tmp="$srcdir"    ;;
832*)                       tmp="../$srcdir" ;;
833esac
834echo ["define(<CONFIG_TOP_SRCDIR>,<\`$tmp'>)"] >>$gmp_tmpconfigm4
835
836# All CPUs use asm-defs.m4
837echo ["include(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"] >>$gmp_tmpconfigm4i
838])
839
840
841dnl  GMP_FINISH
842dnl  ----------
843dnl  Create config.m4 from its accumulated parts.
844dnl
845dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
846dnl  of config.m4 is harmless.
847dnl
848dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
849dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
850dnl  fully quoted but are still put under an ifdef in case any have been
851dnl  redefined by one of the m4 include files.
852dnl
853dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
854dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
855dnl  having a whole file as a macro argument would overflow the string space
856dnl  on BSD m4.
857
858AC_DEFUN(GMP_FINISH,
859[AC_REQUIRE([GMP_INIT])
860echo "creating $gmp_configm4"
861echo ["d""nl $gmp_configm4.  Generated automatically by configure."] > $gmp_configm4
862if test -f $gmp_tmpconfigm4; then
863  echo ["changequote(<,>)"] >> $gmp_configm4
864  echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
865  cat $gmp_tmpconfigm4 >> $gmp_configm4
866  echo [">)"] >> $gmp_configm4
867  echo ["changequote(\`,')"] >> $gmp_configm4
868  rm $gmp_tmpconfigm4
869fi
870echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
871if test -f $gmp_tmpconfigm4i; then
872  cat $gmp_tmpconfigm4i >> $gmp_configm4
873  rm $gmp_tmpconfigm4i
874fi
875if test -f $gmp_tmpconfigm4p; then
876  cat $gmp_tmpconfigm4p >> $gmp_configm4
877  rm $gmp_tmpconfigm4p
878fi
879echo ["')"] >> $gmp_configm4
880echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
881])
882
883
884dnl  GMP_INCLUDE_MPN(FILE)
885dnl  ---------------------
886dnl  Add an include_mpn(`FILE') to config.m4.  FILE should be a path
887dnl  relative to the mpn source directory, for example
888dnl
889dnl      GMP_INCLUDE_MPN(`x86/x86-defs.m4')
890dnl
891
892AC_DEFUN(GMP_INCLUDE_MPN,
893[AC_REQUIRE([GMP_INIT])
894echo ["include_mpn(\`$1')"] >> $gmp_tmpconfigm4i
895])
896
897
898dnl  GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
899dnl  ------------------------------------------
900dnl  Define M4 macro MACRO as DEFINITION in temporary file.
901dnl
902dnl  If LOCATION is `POST', the definition will appear after any include()
903dnl  directives inserted by GMP_INCLUDE.  Mind the quoting!  No shell
904dnl  variables will get expanded.  Don't forget to invoke GMP_FINISH to
905dnl  create file config.m4.  config.m4 uses `<' and '>' as quote characters
906dnl  for all defines.
907
908AC_DEFUN(GMP_DEFINE,
909[AC_REQUIRE([GMP_INIT])
910echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
911                              $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
912])
913
914
915dnl  GMP_DEFINE_RAW(STRING, [, LOCATION])
916dnl  ------------------------------------
917dnl  Put STRING into config.m4 file.
918dnl
919dnl  If LOCATION is `POST', the definition will appear after any include()
920dnl  directives inserted by GMP_INCLUDE.  Don't forget to invoke GMP_FINISH
921dnl  to create file config.m4.
922
923AC_DEFUN(GMP_DEFINE_RAW,
924[AC_REQUIRE([GMP_INIT])
925echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
926])
927
928
929dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
930dnl  ----------------------------------------------------------
931dnl  Attempt to assemble the given code.
932dnl  Do "action-success" if this succeeds, "action-fail" if not.
933dnl
934dnl  conftest.o and conftest.out are available for inspection in
935dnl  "action-success".  If either action does a "break" out of a loop then
936dnl  an explicit "rm -f conftest*" will be necessary.
937dnl
938dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
939dnl  anything in "asm-code", everything wanted must be given explicitly.
940
941AC_DEFUN(GMP_TRY_ASSEMBLE,
942[cat >conftest.s <<EOF
943[$1]
944EOF
945gmp_assemble="$CCAS $CFLAGS conftest.s >conftest.out 2>&1"
946if AC_TRY_EVAL(gmp_assemble); then
947  cat conftest.out >&AC_FD_CC
948  ifelse([$2],,:,[$2])
949else
950  cat conftest.out >&AC_FD_CC
951  echo "configure: failed program was:" >&AC_FD_CC
952  cat conftest.s >&AC_FD_CC
953  ifelse([$3],,:,[$3])
954fi
955rm -f conftest*
956])
957
958
959dnl  GMP_ASM_LABEL_SUFFIX
960dnl  --------------------
961dnl  Should a label have a colon or not?
962
963AC_DEFUN(GMP_ASM_LABEL_SUFFIX,
964[AC_CACHE_CHECK([what assembly label suffix to use],
965                gmp_cv_asm_label_suffix,
966[case $host in
967  # Empty is only for the HP-UX hppa assembler; hppa gas requires a colon.
968  *-*-hpux*) gmp_cv_asm_label_suffix=  ;;
969  *)         gmp_cv_asm_label_suffix=: ;;
970esac
971])
972echo ["define(<LABEL_SUFFIX>, <\$][1$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
973])
974
975
976dnl  GMP_ASM_UNDERSCORE
977dnl  ------------------
978dnl  Determine whether global symbols need to be prefixed with an underscore.
979dnl  A test program is linked to an assembler module with or without an
980dnl  underscore to see which works.
981dnl
982dnl  This method should be more reliable than grepping a .o file or using
983dnl  nm, since it corresponds to what a real program is going to do.  Note
984dnl  in particular that grepping doesn't work with SunOS 4 native grep since
985dnl  that grep seems to have trouble with '\0's in files.
986
987AC_DEFUN(GMP_ASM_UNDERSCORE,
988[AC_REQUIRE([GMP_ASM_TEXT])
989AC_REQUIRE([GMP_ASM_GLOBL])
990AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
991AC_CACHE_CHECK([if globals are prefixed by underscore],
992               gmp_cv_asm_underscore,
993[cat >conftes1.c <<EOF
994#ifdef __cplusplus
995extern "C" { void underscore_test(); }
996#endif
997main () { underscore_test(); }
998EOF
999for tmp_underscore in "" "_"; do
1000  cat >conftes2.s <<EOF
1001        $gmp_cv_asm_text
1002        $gmp_cv_asm_globl ${tmp_underscore}underscore_test
1003${tmp_underscore}underscore_test$gmp_cv_asm_label_suffix
1004EOF
1005  case $host in
1006  *-*-aix*)
1007    cat >>conftes2.s <<EOF
1008        $gmp_cv_asm_globl .${tmp_underscore}underscore_test
1009.${tmp_underscore}underscore_test$gmp_cv_asm_label_suffix
1010EOF
1011    ;;
1012  esac
1013  gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftes1.c >&AC_FD_CC && $CCAS $CFLAGS conftes2.s >&AC_FD_CC && $CC $CFLAGS conftes1.$OBJEXT conftes2.$OBJEXT >&AC_FD_CC"
1014  if AC_TRY_EVAL(gmp_compile); then
1015    eval tmp_result$tmp_underscore=yes
1016  else
1017    eval tmp_result$tmp_underscore=no
1018  fi
1019done
1020
1021if test $tmp_result_ = yes; then
1022  if test $tmp_result = yes; then
1023    AC_MSG_ERROR([Test program unexpectedly links both with and without underscore.])
1024  else
1025    gmp_cv_asm_underscore=yes
1026  fi
1027else
1028  if test $tmp_result = yes; then
1029    gmp_cv_asm_underscore=no
1030  else
1031    AC_MSG_ERROR([Test program links neither with nor without underscore.])
1032  fi
1033fi
1034rm -f conftes1* conftes2* a.out
1035])
1036if test "$gmp_cv_asm_underscore" = "yes"; then
1037  GMP_DEFINE(GSYM_PREFIX, [_])
1038else
1039  GMP_DEFINE(GSYM_PREFIX, [])
1040fi   
1041])
1042
1043
1044dnl  GMP_ASM_ALIGN_LOG
1045dnl  -----------------
1046dnl  Is parameter to `.align' logarithmic?
1047
1048AC_DEFUN(GMP_ASM_ALIGN_LOG,
1049[AC_REQUIRE([GMP_ASM_GLOBL])
1050AC_REQUIRE([GMP_ASM_DATA])
1051AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1052AC_REQUIRE([GMP_PROG_NM])
1053AC_CACHE_CHECK([if .align assembly directive is logarithmic],
1054               gmp_cv_asm_align_log,
1055[GMP_TRY_ASSEMBLE(
1056[       $gmp_cv_asm_data
1057        .align  4
1058        $gmp_cv_asm_globl       foo
1059        .byte   1
1060        .align  4
1061foo$gmp_cv_asm_label_suffix
1062        .byte   2],
1063  [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
1064     sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
1065  if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"; then
1066    gmp_cv_asm_align_log=yes
1067  else
1068    gmp_cv_asm_align_log=no
1069  fi],
1070  [AC_MSG_ERROR([cannot assemble alignment test])])])
1071
1072GMP_DEFINE_RAW(["define(<ALIGN_LOGARITHMIC>,<$gmp_cv_asm_align_log>)"])
1073])
1074
1075
1076dnl  GMP_ASM_ALIGN_FILL_0x90
1077dnl  -----------------------
1078dnl  Determine whether a ",0x90" suffix works on a .align directive.
1079dnl  This is only meant for use on x86, 0x90 being a "nop".
1080dnl
1081dnl  Old gas, eg. 1.92.3
1082dnl       Needs ",0x90" or else the fill is 0x00, which can't be executed
1083dnl       across.
1084dnl
1085dnl  New gas, eg. 2.91
1086dnl       Generates multi-byte nop fills even when ",0x90" is given.
1087dnl
1088dnl  Solaris 2.6 as
1089dnl       ",0x90" is not allowed, causes a fatal error.
1090dnl
1091dnl  Solaris 2.8 as
1092dnl       ",0x90" does nothing, generates a warning that it's being ignored.
1093dnl
1094dnl  SCO OpenServer 5 as
1095dnl       Second parameter is max bytes to fill, not a fill pattern.
1096dnl       ",0x90" is an error due to being bigger than the first parameter.
1097dnl       Multi-byte nop fills are generated in text segments.
1098dnl
1099dnl  Note that both solaris "as"s only care about ",0x90" if they actually
1100dnl  have to use it to fill something, hence the .byte in the test.  It's
1101dnl  the second .align which provokes the error or warning.
1102dnl
1103dnl  The warning from solaris 2.8 is supressed to stop anyone worrying that
1104dnl  something might be wrong.
1105
1106AC_DEFUN(GMP_ASM_ALIGN_FILL_0x90,
1107[AC_REQUIRE([GMP_ASM_TEXT])
1108AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
1109               gmp_cv_asm_align_fill_0x90,
1110[GMP_TRY_ASSEMBLE(
1111[       $gmp_cv_asm_text
1112        .align  4, 0x90
1113        .byte   0
1114        .align  4, 0x90],
1115[if grep "Warning: Fill parameter ignored for executable section" conftest.out >/dev/null; then
1116  echo "Supressing this warning by omitting 0x90" 1>&AC_FD_CC
1117  gmp_cv_asm_align_fill_0x90=no
1118else
1119  gmp_cv_asm_align_fill_0x90=yes
1120fi],
1121[gmp_cv_asm_align_fill_0x90=no])])
1122
1123GMP_DEFINE_RAW(["define(<ALIGN_FILL_0x90>,<$gmp_cv_asm_align_fill_0x90>)"])
1124])
1125
1126
1127dnl  GMP_ASM_TEXT
1128dnl  ------------
1129
1130AC_DEFUN(GMP_ASM_TEXT,
1131[AC_CACHE_CHECK([how to switch to text section],
1132                gmp_cv_asm_text,
1133[case $host in
1134  *-*-aix*)  gmp_cv_asm_text=[".csect .text[PR]"] ;;
1135  *-*-hpux*) gmp_cv_asm_text=".code" ;;
1136  *)         gmp_cv_asm_text=".text" ;;
1137esac
1138])
1139echo ["define(<TEXT>, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
1140])
1141
1142
1143dnl  GMP_ASM_DATA
1144dnl  ------------
1145dnl  Can we say `.data'?
1146
1147AC_DEFUN(GMP_ASM_DATA,
1148[AC_CACHE_CHECK([how to switch to data section],
1149                gmp_cv_asm_data,
1150[case $host in
1151  *-*-aix*) gmp_cv_asm_data=[".csect .data[RW]"] ;;
1152  *)        gmp_cv_asm_data=".data" ;;
1153esac
1154])
1155echo ["define(<DATA>, <$gmp_cv_asm_data>)"] >> $gmp_tmpconfigm4
1156])
1157
1158
1159dnl  GMP_ASM_RODATA
1160dnl  --------------
1161dnl  Find out how to switch to the read-only data section.
1162dnl
1163dnl  The compiler output is grepped for the right directive.  It's not
1164dnl  considered wise to just probe for ".section .rodata" or whatever works,
1165dnl  since arbitrary section names might be accepted, but not necessarily do
1166dnl  the right thing when they get to the linker.
1167dnl
1168dnl  Only a few asm files use RODATA, so this code is perhaps a bit
1169dnl  excessive right now, but should find more uses in the future.
1170dnl
1171dnl  FIXME: gcc on aix generates something like ".csect _foo.ro_c[RO],3"
1172dnl  where foo is the object file.  Might need to check for that if we use
1173dnl  RODATA there.
1174
1175AC_DEFUN(GMP_ASM_RODATA,
1176[AC_REQUIRE([GMP_ASM_TEXT])
1177AC_REQUIRE([GMP_ASM_DATA])
1178AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1179AC_REQUIRE([GMP_ASM_UNDERSCORE])
1180AC_CACHE_CHECK([how to switch to read-only data section],
1181               gmp_cv_asm_rodata,
1182[
1183dnl Default to DATA on CPUs with split code/data caching, and TEXT
1184dnl elsewhere.  i386 means generic x86, so use DATA on it.
1185case $host in
1186X86_PATTERN) gmp_cv_asm_rodata="$gmp_cv_asm_data" ;;
1187*)           gmp_cv_asm_rodata="$gmp_cv_asm_text" ;;
1188esac
1189
1190cat >conftest.c <<EOF
1191const int foo = 123;
1192EOF
1193echo "Test program:" >&AC_FD_CC
1194cat conftest.c >&AC_FD_CC
1195gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
1196if AC_TRY_EVAL(gmp_compile); then
1197  echo "Compiler output:" >&AC_FD_CC
1198  cat conftest.s >&AC_FD_CC
1199  if test $gmp_cv_asm_underscore = yes; then
1200    tmp_gsym_prefix=_
1201  else
1202    tmp_gsym_prefix=
1203  fi
1204  # must see our label
1205  if grep "^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" conftest.s >/dev/null 2>&AC_FD_CC; then
1206    # take the last directive before our label (hence skipping segments
1207    # getting debugging info etc)
1208    tmp_match=`sed -n ["/^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix/q
1209                        /^[.    ]*data/p
1210                        /^[.    ]*rdata/p
1211                        /^[.    ]*text/p
1212                        /^[.    ]*section/p
1213                        /^[.    ]*csect/p
1214                        /^[.    ]*CSECT/p"] conftest.s | sed -n '$p'`
1215    echo "Match: $tmp_match" >&AC_FD_CC
1216    if test -n "$tmp_match"; then
1217      gmp_cv_asm_rodata=$tmp_match
1218    fi
1219  else
1220    echo "Couldn't find label: ^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" >&AC_FD_CC
1221  fi
1222fi
1223])
1224echo ["define(<RODATA>, <$gmp_cv_asm_rodata>)"] >> $gmp_tmpconfigm4
1225])
1226
1227
1228dnl  GMP_ASM_GLOBL
1229dnl  -------------
1230dnl  Can we say `.global'?
1231
1232AC_DEFUN(GMP_ASM_GLOBL,
1233[AC_CACHE_CHECK([how to export a symbol],
1234                gmp_cv_asm_globl,
1235[case $host in
1236  *-*-hpux*) gmp_cv_asm_globl=".export" ;;
1237  *)         gmp_cv_asm_globl=".globl" ;;
1238esac
1239])
1240echo ["define(<GLOBL>, <$gmp_cv_asm_globl>)"] >> $gmp_tmpconfigm4
1241])
1242
1243
1244dnl  GMP_ASM_GLOBL_ATTR
1245dnl  ------------------
1246dnl  Do we need something after `.global symbol'?
1247
1248AC_DEFUN(GMP_ASM_GLOBL_ATTR,
1249[AC_CACHE_CHECK([if the export directive needs an attribute],
1250                gmp_cv_asm_globl_attr,
1251[case $host in
1252  *-*-hpux*) gmp_cv_asm_globl_attr=",entry" ;;
1253  *)         gmp_cv_asm_globl_attr="" ;;
1254esac
1255])
1256echo ["define(<GLOBL_ATTR>, <$gmp_cv_asm_globl_attr>)"] >> $gmp_tmpconfigm4
1257])
1258
1259
1260dnl  GMP_ASM_TYPE
1261dnl  ------------
1262dnl  Can we say ".type", and how?
1263dnl
1264dnl  For i386 GNU/Linux ELF systems, and very likely other ELF systems,
1265dnl  .type and .size are important on functions in shared libraries.  If
1266dnl  .type is omitted and the mainline program references that function then
1267dnl  the code will be copied down to the mainline at load time like a piece
1268dnl  of data.  If .size is wrong or missing (it defaults to 4 bytes or some
1269dnl  such) then incorrect bytes will be copied and a segv is the most likely
1270dnl  result.  In any case such copying is not what's wanted, a .type
1271dnl  directive will ensure a PLT entry is used.
1272dnl
1273dnl  In GMP the assembler functions are normally only used from within the
1274dnl  library (since most programs are not interested in the low level
1275dnl  routines), and in those circumstances a missing .type isn't fatal,
1276dnl  letting the problem go unnoticed.  tests/mpn/t-asmtype.c aims to check
1277dnl  for it.
1278
1279AC_DEFUN(GMP_ASM_TYPE,
1280[AC_CACHE_CHECK([for assembler .type directive],
1281                gmp_cv_asm_type,
1282[gmp_cv_asm_type=
1283for gmp_tmp_prefix in @ \# %; do
1284  GMP_TRY_ASSEMBLE([    .type   sym,${gmp_tmp_prefix}function],
1285    [if grep "\.type pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
1286    else
1287      gmp_cv_asm_type=".type    \$][1,${gmp_tmp_prefix}\$][2"
1288      break
1289    fi])
1290done
1291rm -f conftest*
1292])
1293echo ["define(<TYPE>, <$gmp_cv_asm_type>)"] >> $gmp_tmpconfigm4
1294])
1295
1296
1297dnl  GMP_ASM_SIZE
1298dnl  ------------
1299dnl  Can we say `.size'?
1300
1301AC_DEFUN(GMP_ASM_SIZE,
1302[AC_CACHE_CHECK([for assembler .size directive],
1303                gmp_cv_asm_size,
1304[gmp_cv_asm_size=
1305GMP_TRY_ASSEMBLE([      .size   sym,1],
1306  [if grep "\.size pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
1307  else
1308    gmp_cv_asm_size=".size      \$][1,\$][2"
1309  fi])
1310])
1311echo ["define(<SIZE>, <$gmp_cv_asm_size>)"] >> $gmp_tmpconfigm4
1312])
1313
1314
1315dnl  GMP_ASM_LSYM_PREFIX
1316dnl  -------------------
1317dnl  What is the prefix for a local label?
1318dnl
1319dnl  The prefixes tested are,
1320dnl
1321dnl      L  - usual for underscore systems
1322dnl      .L - usual for non-underscore systems
1323dnl      $  - alpha (gas and OSF system assembler)
1324dnl      L$ - hppa (gas and HP-UX system assembler)
1325dnl
1326dnl  The default is "L" if the tests fail for any reason.  There's a good
1327dnl  chance this will be adequate, since on most systems labels are local
1328dnl  anyway unless given a ".globl", and an "L" will avoid clashes with
1329dnl  other identifers.
1330dnl
1331dnl  For gas, ".L" is normally purely local to the assembler, it doesn't get
1332dnl  put into the object file at all.  This style is preferred, to keep the
1333dnl  object files nice and clean.
1334dnl
1335dnl  BSD format nm produces a line like the following.  The lower case "t"
1336dnl  indicates a local text segment label.  On OSF with "nm -B", an "N" is
1337dnl  printed instead.
1338dnl
1339dnl      00000000 t Lgurkmacka
1340dnl
1341dnl  HP-UX nm prints an error message (though seems to give a 0 exit) if
1342dnl  there's no symbols at all in an object file, hence the use of "dummy".
1343
1344AC_DEFUN(GMP_ASM_LSYM_PREFIX,
1345[AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1346AC_REQUIRE([GMP_PROG_NM])
1347AC_CACHE_CHECK([what prefix to use for a local label],
1348               gmp_cv_asm_lsym_prefix,
1349[for gmp_tmp_pre in L .L $ L$; do
1350  echo "Trying $gmp_tmp_pre" >&AC_FD_CC
1351  GMP_TRY_ASSEMBLE(
1352[dummy${gmp_cv_asm_label_suffix}
1353${gmp_tmp_pre}gurkmacka${gmp_cv_asm_label_suffix}],
1354  [if $NM conftest.$OBJEXT >conftest.nm 2>&AC_FD_CC; then : ; else
1355    cat conftest.nm >&AC_FD_CC
1356    AC_MSG_WARN(["$NM" failure])
1357    break
1358  fi
1359  cat conftest.nm >&AC_FD_CC
1360  if grep gurkmacka conftest.nm >/dev/null; then : ; else
1361    # no mention of the symbol, this is good
1362    gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
1363    break
1364  fi
1365  if grep [' [Nt] .*gurkmacka'] conftest.nm >/dev/null; then
1366    # symbol mentioned as a local, use this if nothing better
1367    if test -z "$gmp_cv_asm_lsym_prefix"; then
1368      gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
1369    fi
1370  fi
1371  ])
1372done
1373rm -f conftest*
1374if test -z "$gmp_cv_asm_lsym_prefix"; then
1375  gmp_cv_asm_lsym_prefix=L
1376  AC_MSG_WARN([cannot determine local label, using default $gmp_cv_asm_lsym_prefix])
1377fi
1378])
1379echo ["define(<LSYM_PREFIX>, <${gmp_cv_asm_lsym_prefix}>)"] >> $gmp_tmpconfigm4
1380AC_DEFINE_UNQUOTED(LSYM_PREFIX, "$gmp_cv_asm_lsym_prefix",
1381                   [Assembler local label prefix])
1382])
1383
1384
1385dnl  GMP_ASM_W32
1386dnl  -----------
1387dnl  How to define a 32-bit word.
1388
1389AC_DEFUN(GMP_ASM_W32,
1390[AC_REQUIRE([GMP_ASM_DATA])
1391AC_REQUIRE([GMP_ASM_GLOBL])
1392AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
1393AC_REQUIRE([GMP_PROG_NM])
1394AC_CACHE_CHECK([how to define a 32-bit word],
1395               gmp_cv_asm_w32,
1396[case $host in
1397  *-*-hpux*)
1398    # FIXME: HPUX puts first symbol at 0x40000000, breaking our assumption
1399    # that it's at 0x0.  We'll have to declare another symbol before the
1400    # .long/.word and look at the distance between the two symbols.  The
1401    # only problem is that the sed expression(s) barfs (on Solaris, for
1402    # example) for the symbol with value 0.  For now, HPUX uses .word.
1403    gmp_cv_asm_w32=".word"
1404    ;;
1405  *-*-*)
1406    gmp_tmp_val=
1407    for gmp_tmp_op in .long .word; do
1408      GMP_TRY_ASSEMBLE(
1409[       $gmp_cv_asm_data
1410        $gmp_cv_asm_globl       foo
1411        $gmp_tmp_op     0
1412foo$gmp_cv_asm_label_suffix
1413        .byte   0],
1414        [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
1415          sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
1416        if test "$gmp_tmp_val" = 4; then
1417          gmp_cv_asm_w32="$gmp_tmp_op"
1418          break
1419        fi])
1420    done
1421    rm -f conftest*
1422    ;;
1423esac
1424if test -z "$gmp_cv_asm_w32"; then
1425  AC_MSG_ERROR([cannot determine how to define a 32-bit word])
1426fi
1427])
1428echo ["define(<W32>, <$gmp_cv_asm_w32>)"] >> $gmp_tmpconfigm4
1429])
1430
1431
1432dnl  GMP_ASM_X86_MMX([ACTION-IF-YES][,ACTION-IF-NO])
1433dnl  -----------------------------------------------
1434dnl  Determine whether the assembler supports MMX instructions.
1435dnl
1436dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
1437dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
1438dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
1439dnl  needed at all, at least for just checking instruction syntax.
1440dnl
1441dnl  "movq %mm0, %mm1" should assemble to "0f 6f c8", but Solaris 2.6 and
1442dnl  2.7 wrongly assemble it to "0f 6f c1" (that being the reverse "movq
1443dnl  %mm1, %mm0").  It seems more trouble than it's worth to work around
1444dnl  this in the code, so just detect and reject.
1445
1446AC_DEFUN(GMP_ASM_X86_MMX,
1447[AC_CACHE_CHECK([if the assembler knows about MMX instructions],
1448                gmp_cv_asm_x86_mmx,
1449[GMP_TRY_ASSEMBLE(
1450[       .text
1451        movq    %mm0, %mm1],
1452[gmp_cv_asm_x86_mmx=yes
1453case $host in
1454*-*-solaris*)
1455  if (dis conftest.$OBJEXT >conftest.out) 2>/dev/null; then
1456    if grep "0f 6f c1" conftest.out >/dev/null; then
1457      gmp_cv_asm_x86_mmx=movq-bug
1458    fi
1459  else
1460    AC_MSG_WARN(["dis" not available to check for "as" movq bug])
1461  fi
1462esac],
1463[gmp_cv_asm_x86_mmx=no])])
1464
1465case $gmp_cv_asm_x86_mmx in
1466movq-bug)
1467  AC_MSG_WARN([+----------------------------------------------------------])
1468  AC_MSG_WARN([| WARNING WARNING WARNING])
1469  AC_MSG_WARN([| Host CPU has MMX code, but the assembler])
1470  AC_MSG_WARN([|     $CCAS $CFLAGS])
1471  AC_MSG_WARN([| has the Solaris 2.6 and 2.7 bug where register to register])
1472  AC_MSG_WARN([| movq operands are reversed.])
1473  AC_MSG_WARN([| Non-MMX replacements will be used.])
1474  AC_MSG_WARN([| This will be an inferior build.])
1475  AC_MSG_WARN([+----------------------------------------------------------])
1476  ;;
1477no)
1478  AC_MSG_WARN([+----------------------------------------------------------])
1479  AC_MSG_WARN([| WARNING WARNING WARNING])
1480  AC_MSG_WARN([| Host CPU has MMX code, but it can't be assembled by])
1481  AC_MSG_WARN([|     $CCAS $CFLAGS])
1482  AC_MSG_WARN([| Non-MMX replacements will be used.])
1483  AC_MSG_WARN([| This will be an inferior build.])
1484  AC_MSG_WARN([+----------------------------------------------------------])
1485  ;;
1486esac
1487if test "$gmp_cv_asm_x86_mmx" = yes; then
1488  ifelse([$1],,:,[$1])
1489else
1490  ifelse([$2],,:,[$2])
1491fi
1492])
1493
1494
1495dnl  GMP_ASM_X86_SHLDL_CL
1496dnl  --------------------
1497
1498AC_DEFUN(GMP_ASM_X86_SHLDL_CL,
1499[AC_REQUIRE([GMP_ASM_TEXT])
1500AC_CACHE_CHECK([if the assembler takes cl with shldl],
1501                gmp_cv_asm_x86_shldl_cl,
1502[GMP_TRY_ASSEMBLE(
1503[       $gmp_cv_asm_text
1504        shldl   %cl, %eax, %ebx],
1505  gmp_cv_asm_x86_shldl_cl=yes,
1506  gmp_cv_asm_x86_shldl_cl=no)
1507])
1508if test "$gmp_cv_asm_x86_shldl_cl" = "yes"; then
1509  GMP_DEFINE(WANT_SHLDL_CL,1)
1510else
1511  GMP_DEFINE(WANT_SHLDL_CL,0)
1512fi
1513])
1514
1515
1516dnl  GMP_ASM_X86_SSE2([ACTION-IF-YES][,ACTION-IF-NO])
1517dnl  ------------------------------------------------
1518dnl  Determine whether the assembler supports SSE2 instructions.
1519dnl
1520dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
1521dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
1522dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
1523dnl  needed at all, at least for just checking instruction syntax.
1524
1525AC_DEFUN(GMP_ASM_X86_SSE2,
1526[AC_CACHE_CHECK([if the assembler knows about SSE2 instructions],
1527                gmp_cv_asm_x86_sse2,
1528[GMP_TRY_ASSEMBLE(
1529[       .text
1530        paddq   %mm0, %mm1],
1531  [gmp_cv_asm_x86_sse2=yes],
1532  [gmp_cv_asm_x86_sse2=no])
1533])
1534case $gmp_cv_asm_x86_sse2 in
1535yes)
1536  ifelse([$1],,:,[$1])
1537  ;;
1538*)
1539  AC_MSG_WARN([+----------------------------------------------------------])
1540  AC_MSG_WARN([| WARNING WARNING WARNING])
1541  AC_MSG_WARN([| Host CPU has SSE2 code, but it can't be assembled by])
1542  AC_MSG_WARN([|     $CCAS $CFLAGS])
1543  AC_MSG_WARN([| Non-SSE2 replacements will be used.])
1544  AC_MSG_WARN([| This will be an inferior build.])
1545  AC_MSG_WARN([+----------------------------------------------------------])
1546  ifelse([$2],,:,[$2])
1547  ;;
1548esac
1549])
1550
1551
1552dnl  GMP_ASM_X86_MCOUNT
1553dnl  ------------------
1554dnl  Find out how to call mcount for profiling on an x86 system.
1555dnl
1556dnl  A dummy function is compiled and the ".s" output examined.  The pattern
1557dnl  matching might be a bit fragile, but should work at least with gcc on
1558dnl  sensible systems.  Certainly it's better than hard coding a table of
1559dnl  conventions.
1560dnl
1561dnl  For non-PIC, any ".data" is taken to mean a counter might be passed.
1562dnl  It's assumed a movl will set it up, and the right register is taken
1563dnl  from that movl.  Any movl involving %esp is ignored (a frame pointer
1564dnl  setup normally).
1565dnl
1566dnl  For PIC, any ".data" is similarly interpreted, but a GOTOFF identifies
1567dnl  the line setting up the right register.
1568dnl
1569dnl  In both cases a line with "mcount" identifies the call and that line is
1570dnl  used literally.
1571dnl
1572dnl  On some systems (eg. FreeBSD 3.5) gcc emits ".data" but doesn't use it,
1573dnl  so it's not an error to have .data but then not find a register.
1574dnl
1575dnl  Variations in mcount conventions on different x86 systems can be found
1576dnl  in gcc config/i386.  mcount can have a "_" prefix or be .mcount or
1577dnl  _mcount_ptr, and for PIC it can be called through a GOT entry, or via
1578dnl  the PLT.  If a pointer to a counter is required it's passed in %eax or
1579dnl  %edx.
1580dnl
1581dnl  Flags to specify PIC are taken from $lt_prog_compiler_pic set by
1582dnl  AC_PROG_LIBTOOL.
1583dnl
1584dnl  Enhancement: Cache the values determined here. But what's the right way
1585dnl  to get two variables (mcount_nonpic_reg and mcount_nonpic_call say) set
1586dnl  from one block of commands?
1587
1588AC_DEFUN(GMP_ASM_X86_MCOUNT,
1589[AC_REQUIRE([AC_ENABLE_SHARED])
1590AC_REQUIRE([AC_PROG_LIBTOOL])
1591AC_MSG_CHECKING([how to call x86 mcount])
1592cat >conftest.c <<EOF
1593foo(){bar();}
1594EOF
1595
1596if test "$enable_static" = yes; then
1597  gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c 1>&AC_FD_CC"
1598  if AC_TRY_EVAL(gmp_asmout_compile); then
1599    if grep '\.data' conftest.s >/dev/null; then
1600      mcount_nonpic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
1601    else
1602      mcount_nonpic_reg=
1603    fi
1604    mcount_nonpic_call=`grep 'call.*mcount' conftest.s`
1605    if test -z "$mcount_nonpic_call"; then
1606      AC_MSG_ERROR([Cannot find mcount call for non-PIC])
1607    fi
1608  else
1609    AC_MSG_ERROR([Cannot compile test program for non-PIC])
1610  fi
1611fi
1612
1613if test "$enable_shared" = yes; then
1614  gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic -S conftest.c 1>&AC_FD_CC"
1615  if AC_TRY_EVAL(gmp_asmout_compile); then
1616    if grep '\.data' conftest.s >/dev/null; then
1617      case $lt_prog_compiler_pic in
1618        *-DDLL_EXPORT*)
1619          # Windows DLLs have non-PIC style mcount
1620          mcount_pic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
1621          ;;
1622        *)
1623          mcount_pic_reg=`sed -n ['s/.*GOTOFF.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
1624          ;;
1625      esac
1626    else
1627      mcount_pic_reg=
1628    fi
1629    mcount_pic_call=`grep 'call.*mcount' conftest.s`
1630    if test -z "$mcount_pic_call"; then
1631      AC_MSG_ERROR([Cannot find mcount call for PIC])
1632    fi
1633  else
1634    AC_MSG_ERROR([Cannot compile test program for PIC])
1635  fi
1636fi
1637
1638GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_REG>, <\`$mcount_nonpic_reg'>)"])
1639GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_CALL>,<\`$mcount_nonpic_call'>)"])
1640GMP_DEFINE_RAW(["define(<MCOUNT_PIC_REG>,    <\`$mcount_pic_reg'>)"])
1641GMP_DEFINE_RAW(["define(<MCOUNT_PIC_CALL>,   <\`$mcount_pic_call'>)"])
1642
1643rm -f conftest.*
1644AC_MSG_RESULT([determined])
1645])
1646
1647
1648dnl  GMP_ASM_M68K_INSTRUCTION
1649dnl  ------------------------
1650dnl  Not sure if ".l" and "%" are independent settings, but it doesn't hurt
1651dnl  to try all four possibilities.  Note that the % ones must be first, so
1652dnl  "d0" won't be interpreted as a label.
1653dnl
1654dnl  gas 1.92.3 on NetBSD 1.4 needs to be tested with a two operand
1655dnl  instruction.  It takes registers without "%", but a single operand
1656dnl  "clrl %d0" only gives a warning, not an error.
1657
1658AC_DEFUN(GMP_ASM_M68K_INSTRUCTION,
1659[AC_REQUIRE([GMP_ASM_TEXT])
1660AC_CACHE_CHECK([assembler instruction and register style],
1661                gmp_cv_asm_m68k_instruction,
1662[gmp_cv_asm_m68k_instruction=unknown
1663for i in "addl %d0,%d1" "add.l %d0,%d1" "addl d0,d1" "add.l d0,d1"; do
1664  GMP_TRY_ASSEMBLE(
1665    [   $gmp_cv_asm_text
1666        $i],
1667    [gmp_cv_asm_m68k_instruction=$i
1668    rm -f conftest*
1669    break])
1670done
1671])
1672case $gmp_cv_asm_m68k_instruction in
1673"addl d0,d1")    want_dot_size=no;  want_register_percent=no  ;;
1674"addl %d0,%d1")  want_dot_size=no;  want_register_percent=yes ;;
1675"add.l d0,d1")   want_dot_size=yes; want_register_percent=no  ;;
1676"add.l %d0,%d1") want_dot_size=yes; want_register_percent=yes ;;
1677*) AC_MSG_ERROR([cannot determine assembler instruction and register style]) ;;
1678esac
1679GMP_DEFINE_RAW(["define(<WANT_REGISTER_PERCENT>, <\`$want_register_percent'>)"])
1680GMP_DEFINE_RAW(["define(<WANT_DOT_SIZE>, <\`$want_dot_size'>)"])
1681])
1682
1683
1684dnl  GMP_ASM_M68K_ADDRESSING
1685dnl  -----------------------
1686
1687AC_DEFUN(GMP_ASM_M68K_ADDRESSING,
1688[AC_REQUIRE([GMP_ASM_TEXT])
1689AC_REQUIRE([GMP_ASM_M68K_INSTRUCTION])
1690AC_CACHE_CHECK([assembler addressing style],
1691                gmp_cv_asm_m68k_addressing,
1692[case $gmp_cv_asm_m68k_instruction in
1693addl*)  movel=movel ;;
1694add.l*) movel=move.l ;;
1695*) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
1696esac
1697case $gmp_cv_asm_m68k_instruction in
1698*"%d0,%d1") dreg=%d0; areg=%a0 ;;
1699*"d0,d1")   dreg=d0;  areg=a0  ;;
1700*) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
1701esac
1702GMP_TRY_ASSEMBLE(
1703[       $gmp_cv_asm_text
1704        $movel  $dreg, $areg@-],
1705  [gmp_cv_asm_m68k_addressing=mit],
1706[GMP_TRY_ASSEMBLE(
1707[       $gmp_cv_asm_text
1708        $movel  $dreg, -($areg)],
1709  [gmp_cv_asm_m68k_addressing=motorola],
1710[AC_MSG_ERROR([cannot determine assembler addressing style])])])
1711])
1712GMP_DEFINE_RAW(["define(<WANT_ADDRESSING>, <\`$gmp_cv_asm_m68k_addressing'>)"])
1713])
1714
1715
1716dnl  GMP_ASM_M68K_BRANCHES
1717dnl  ---------------------
1718dnl  "bra" is the standard branch instruction.  "jra" or "jbra" are
1719dnl  preferred where available, since on gas for instance they give a
1720dnl  displacement only as big as it needs to be, whereas "bra" is always
1721dnl  16-bits.  This applies to the conditional branches "bcc" etc too.
1722dnl  However "dbcc" etc on gas are already only as big as they need to be.
1723
1724AC_DEFUN(GMP_ASM_M68K_BRANCHES,
1725[AC_REQUIRE([GMP_ASM_TEXT])
1726AC_CACHE_CHECK([assembler shortest branches],
1727                gmp_cv_asm_m68k_branches,
1728[gmp_cv_asm_m68k_branches=unknown
1729for i in jra jbra bra; do
1730  GMP_TRY_ASSEMBLE(
1731[       $gmp_cv_asm_text
1732foo$gmp_cv_asm_label_suffix
1733        $i      foo],
1734  [gmp_cv_asm_m68k_branches=$i
1735  rm -f conftest*
1736  break])
1737done
1738])
1739if test "$gmp_cv_asm_m68k_branches" = unknown; then
1740  AC_MSG_ERROR([cannot determine assembler branching style])
1741fi
1742GMP_DEFINE_RAW(["define(<WANT_BRANCHES>, <\`$gmp_cv_asm_m68k_branches'>)"])
1743])
1744
1745
1746dnl  GMP_ASM_POWERPC_R_REGISTERS
1747dnl  ---------------------------
1748dnl  Determine whether the assembler takes powerpc registers with an "r" as
1749dnl  in "r6", or as plain "6".  The latter is standard, but NeXT, Rhapsody,
1750dnl  and MacOS-X require the "r" forms.
1751dnl
1752dnl  See also mpn/powerpc32/powerpc-defs.m4 which uses the result of this
1753dnl  test.
1754
1755AC_DEFUN(GMP_ASM_POWERPC_R_REGISTERS,
1756[AC_REQUIRE([GMP_ASM_TEXT])
1757AC_CACHE_CHECK([if the assembler needs r on registers],
1758               gmp_cv_asm_powerpc_r_registers,
1759[GMP_TRY_ASSEMBLE(
1760[       $gmp_cv_asm_text
1761        mtctr   6],
1762[gmp_cv_asm_powerpc_r_registers=no],
1763[GMP_TRY_ASSEMBLE(
1764[       $gmp_cv_asm_text
1765        mtctr   r6],
1766[gmp_cv_asm_powerpc_r_registers=yes],
1767[AC_MSG_ERROR([neither "mtctr 6" nor "mtctr r6" works])])])])
1768
1769GMP_DEFINE_RAW(["define(<WANT_R_REGISTERS>,<$gmp_cv_asm_powerpc_r_registers>)"])
1770])
1771
1772
1773dnl  GMP_ASM_SPARC_REGISTER
1774dnl  ----------------------
1775dnl  Determine whether the assembler accepts the ".register" directive.
1776dnl  Old versions of solaris "as" don't.
1777dnl
1778dnl  See also mpn/sparc32/sparc-defs.m4 which uses the result of this test.
1779
1780AC_DEFUN(GMP_ASM_SPARC_REGISTER,
1781[AC_REQUIRE([GMP_ASM_TEXT])
1782AC_CACHE_CHECK([if the assembler accepts ".register"],
1783               gmp_cv_asm_sparc_register,
1784[GMP_TRY_ASSEMBLE(
1785[       $gmp_cv_asm_text
1786        .register       %g2,#scratch
1787],
1788[gmp_cv_asm_sparc_register=yes],
1789[gmp_cv_asm_sparc_register=no])])
1790
1791GMP_DEFINE_RAW(["define(<HAVE_REGISTER>,<$gmp_cv_asm_sparc_register>)"])
1792])
1793
1794
1795dnl  GMP_C_ATTRIBUTE_CONST
1796dnl  ---------------------
1797
1798AC_DEFUN(GMP_C_ATTRIBUTE_CONST,
1799[AC_CACHE_CHECK([whether gcc __attribute__ ((const)) works],
1800                gmp_cv_c_attribute_const,
1801[AC_TRY_COMPILE([int foo (int x) __attribute__ ((const));], ,
1802  gmp_cv_c_attribute_const=yes, gmp_cv_c_attribute_const=no)
1803])
1804if test $gmp_cv_c_attribute_const = yes; then
1805  AC_DEFINE(HAVE_ATTRIBUTE_CONST, 1,
1806  [Define if the compiler accepts gcc style __attribute__ ((const))])
1807fi
1808])
1809
1810
1811dnl  GMP_C_ATTRIBUTE_MALLOC
1812dnl  ----------------------
1813dnl  gcc 2.95.x accepts __attribute__ ((malloc)) but with a warning that
1814dnl  it's ignored.  Pretend it doesn't exist in this case, to avoid that
1815dnl  warning.
1816
1817AC_DEFUN(GMP_C_ATTRIBUTE_MALLOC,
1818[AC_CACHE_CHECK([whether gcc __attribute__ ((malloc)) works],
1819                gmp_cv_c_attribute_malloc,
1820[cat >conftest.c <<EOF
1821void *foo (int x) __attribute__ ((malloc));
1822EOF
1823gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.out 2>&1"
1824if AC_TRY_EVAL(gmp_compile); then
1825  if grep "attribute directive ignored" conftest.out >/dev/null; then
1826    gmp_cv_c_attribute_malloc=no
1827  else
1828    gmp_cv_c_attribute_malloc=yes
1829  fi
1830else
1831  gmp_cv_c_attribute_malloc=no
1832fi
1833cat conftest.out >&AC_FD_CC
1834rm -f conftest*
1835])
1836if test $gmp_cv_c_attribute_malloc = yes; then
1837  AC_DEFINE(HAVE_ATTRIBUTE_MALLOC, 1,
1838  [Define if the compiler accepts gcc style __attribute__ ((malloc))])
1839fi
1840])
1841
1842
1843dnl  GMP_C_ATTRIBUTE_MODE
1844dnl  --------------------
1845dnl  Introduced in gcc 2.2, but perhaps not in all Apple derived versions.
1846
1847AC_DEFUN(GMP_C_ATTRIBUTE_MODE,
1848[AC_CACHE_CHECK([whether gcc __attribute__ ((mode (XX))) works],
1849                gmp_cv_c_attribute_mode,
1850[AC_TRY_COMPILE([typedef int SItype __attribute__ ((mode (SI)));], ,
1851  gmp_cv_c_attribute_mode=yes, gmp_cv_c_attribute_mode=no)
1852])
1853if test $gmp_cv_c_attribute_mode = yes; then
1854  AC_DEFINE(HAVE_ATTRIBUTE_MODE, 1,
1855  [Define if the compiler accepts gcc style __attribute__ ((mode (XX)))])
1856fi
1857])
1858
1859
1860dnl  GMP_C_ATTRIBUTE_NORETURN
1861dnl  ------------------------
1862
1863AC_DEFUN(GMP_C_ATTRIBUTE_NORETURN,
1864[AC_CACHE_CHECK([whether gcc __attribute__ ((noreturn)) works],
1865                gmp_cv_c_attribute_noreturn,
1866[AC_TRY_COMPILE([void foo (int x) __attribute__ ((noreturn));], ,
1867  gmp_cv_c_attribute_noreturn=yes, gmp_cv_c_attribute_noreturn=no)
1868])
1869if test $gmp_cv_c_attribute_noreturn = yes; then
1870  AC_DEFINE(HAVE_ATTRIBUTE_NORETURN, 1,
1871  [Define if the compiler accepts gcc style __attribute__ ((noreturn))])
1872fi
1873])
1874
1875
1876dnl  GMP_C_DOUBLE_FORMAT
1877dnl  -------------------
1878dnl  Determine the floating point format.
1879dnl
1880dnl  The object file is grepped, in order to work when cross compiling.  A
1881dnl  start and end sequence is included to avoid false matches, and
1882dnl  allowance is made for the desired data crossing an "od -b" line
1883dnl  boundary.  The test number is a small integer so it should appear
1884dnl  exactly, no rounding or truncation etc.
1885dnl
1886dnl  "od -b", incidentally, is supported even by Unix V7, and the awk script
1887dnl  used doesn't have functions or anything, so even an "old" awk should
1888dnl  suffice.
1889
1890AC_DEFUN(GMP_C_DOUBLE_FORMAT,
1891[AC_REQUIRE([AC_PROG_CC])
1892AC_REQUIRE([AC_PROG_AWK])
1893AC_CACHE_CHECK([format of `double' floating point],
1894                gmp_cv_c_double_format,
1895[gmp_cv_c_double_format=unknown
1896cat >conftest.c <<\EOF
1897[struct {
1898  char    before[8];
1899  double  x;
1900  char    after[8];
1901} foo = {
1902  { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
1903  -123456789.0,
1904  { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
1905};]
1906EOF
1907gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC 2>&1"
1908if AC_TRY_EVAL(gmp_compile); then
1909cat >conftest.awk <<\EOF
1910[
1911BEGIN {
1912  found = 0
1913}
1914
1915{
1916  for (f = 2; f <= NF; f++)
1917    {
1918      for (i = 0; i < 23; i++)
1919        got[i] = got[i+1];
1920      got[23] = $f;
1921
1922      # match the special begin and end sequences
1923      if (got[0] != "001") continue
1924      if (got[1] != "043") continue
1925      if (got[2] != "105") continue
1926      if (got[3] != "147") continue
1927      if (got[4] != "211") continue
1928      if (got[5] != "253") continue
1929      if (got[6] != "315") continue
1930      if (got[7] != "357") continue
1931      if (got[16] != "376") continue
1932      if (got[17] != "334") continue
1933      if (got[18] != "272") continue
1934      if (got[19] != "230") continue
1935      if (got[20] != "166") continue
1936      if (got[21] != "124") continue
1937      if (got[22] != "062") continue
1938      if (got[23] != "020") continue
1939
1940      saw = " (" got[8] " " got[9] " " got[10] " " got[11] " " got[12] " " got[13] " " got[14] " " got[15] ")"
1941
1942      if (got[8]  == "000" &&  \
1943          got[9]  == "000" &&  \
1944          got[10] == "000" &&  \
1945          got[11] == "124" &&  \
1946          got[12] == "064" &&  \
1947          got[13] == "157" &&  \
1948          got[14] == "235" &&  \
1949          got[15] == "301")
1950        {
1951          print "IEEE little endian"
1952          found = 1
1953          exit
1954        }
1955
1956      # ARM style little endian but with the two 4-byte halves swapped
1957      if (got[8]  == "064" &&  \
1958          got[9]  == "157" &&  \
1959          got[10] == "235" &&  \
1960          got[11] == "301" &&  \
1961          got[12] == "000" &&  \
1962          got[13] == "000" &&  \
1963          got[14] == "000" &&  \
1964          got[15] == "124")
1965        {
1966          print "IEEE little endian, swapped halves"
1967          found = 1
1968          exit
1969        }
1970
1971      if (got[8]  == "301" &&  \
1972          got[9]  == "235" &&  \
1973          got[10] == "157" &&  \
1974          got[11] == "064" &&  \
1975          got[12] == "124" &&  \
1976          got[13] == "000" &&  \
1977          got[14] == "000" &&  \
1978          got[15] == "000")
1979        {
1980          print "IEEE big endian"
1981          found = 1
1982          exit
1983        }
1984
1985      if (got[8]  == "353" &&  \
1986          got[9]  == "315" &&  \
1987          got[10] == "242" &&  \
1988          got[11] == "171" &&  \
1989          got[12] == "000" &&  \
1990          got[13] == "240" &&  \
1991          got[14] == "000" &&  \
1992          got[15] == "000")
1993        {
1994          print "VAX D"
1995          found = 1
1996          exit
1997        }
1998
1999      if (got[8]  == "275" &&  \
2000          got[9]  == "301" &&  \
2001          got[10] == "064" &&  \
2002          got[11] == "157" &&  \
2003          got[12] == "000" &&  \
2004          got[13] == "124" &&  \
2005          got[14] == "000" &&  \
2006          got[15] == "000")
2007        {
2008          print "VAX G"
2009          found = 1
2010          exit
2011        }
2012
2013      if (got[8]  == "300" &&  \
2014          got[9]  == "033" &&  \
2015          got[10] == "353" &&  \
2016          got[11] == "171" &&  \
2017          got[12] == "242" &&  \
2018          got[13] == "240" &&  \
2019          got[14] == "000" &&  \
2020          got[15] == "000")
2021        {
2022          print "Cray CFP"
2023          found = 1
2024          exit
2025        }
2026    }
2027}
2028
2029END {
2030  if (! found)
2031    print "unknown", saw
2032}
2033]
2034EOF
2035  gmp_cv_c_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
2036  case $gmp_cv_c_double_format in
2037  unknown*)
2038    echo "cannot match anything, conftest.$OBJEXT contains" >&AC_FD_CC
2039    od -b conftest.$OBJEXT >&AC_FD_CC
2040    ;;
2041  esac
2042else
2043  AC_MSG_WARN([oops, cannot compile test program])
2044fi
2045])
2046
2047AH_VERBATIM([HAVE_DOUBLE],
2048[/* Define one (and only one) of the following for the format of a `double'.
2049   If your format is not among these choices, or you don't know what it is,
2050   then leave all of them undefined.
2051   "IEEE_LITTLE_SWAPPED" means little endian, but with the two 4-byte halves
2052   swapped, as used by ARM CPUs in little endian mode.  */
2053#undef HAVE_DOUBLE_IEEE_BIG_ENDIAN
2054#undef HAVE_DOUBLE_IEEE_LITTLE_ENDIAN
2055#undef HAVE_DOUBLE_IEEE_LITTLE_SWAPPED
2056#undef HAVE_DOUBLE_VAX_D
2057#undef HAVE_DOUBLE_VAX_G
2058#undef HAVE_DOUBLE_CRAY_CFP])
2059
2060case $gmp_cv_c_double_format in
2061  "IEEE big endian")
2062    AC_DEFINE(HAVE_DOUBLE_IEEE_BIG_ENDIAN, 1) ;;
2063  "IEEE little endian")
2064    AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_ENDIAN, 1) ;;
2065  "IEEE little endian, swapped halves")
2066    AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_SWAPPED, 1) ;;
2067  "VAX D")
2068    AC_DEFINE(HAVE_DOUBLE_VAX_D, 1) ;;
2069  "VAX G")
2070    AC_DEFINE(HAVE_DOUBLE_VAX_G, 1) ;;
2071  "Cray CFP")
2072    AC_DEFINE(HAVE_DOUBLE_CRAY_CFP, 1) ;;
2073  unknown*)
2074    ;;
2075  *)
2076    AC_MSG_WARN([oops, unrecognised float format: $gmp_cv_c_double_format])
2077    ;;
2078esac
2079])
2080
2081
2082dnl  GMP_C_INLINE
2083dnl  ------------
2084dnl  Establish an "inline" keyword, if possible.
2085dnl
2086dnl  This is the same as AC_C_INLINE, but introduing a typedef into the test
2087dnl  program.  Some versions of HP C succeed when the return value is a
2088dnl  plain builtin type like "int", but fail when it's a typedef.
2089dnl
2090dnl  FIXME: Hopefully autoconf will do this extra itself one day.
2091
2092AC_DEFUN(GMP_C_INLINE,
2093[AC_CACHE_CHECK([for inline], gmp_cv_c_inline,
2094[gmp_cv_c_inline=no
2095for i in inline __inline__ __inline; do
2096  AC_TRY_COMPILE(
2097[#ifndef __cplusplus
2098typedef int foo_t;
2099$i foo_t func1 () { return 0; }
2100static $i foo_t func2 () { return 0; }
2101#endif], ,
2102    [gmp_cv_c_inline=$i
2103    break])
2104done
2105if test $gmp_cv_c_inline = inline; then
2106  gmp_cv_c_inline=yes
2107fi
2108])
2109case $gmp_cv_c_inline in
2110  inline | yes) ;;
2111  no) AC_DEFINE(inline,,
2112                [Define as `__inline' if that's what the C compiler calls it,
2113                 or to nothing if it is not supported.]) ;;
2114  *)  AC_DEFINE_UNQUOTED(inline, $gmp_cv_c_inline) ;;
2115esac
2116])
2117
2118
2119dnl  GMP_C_RESTRICT
2120dnl  --------------
2121dnl  Establish a "restrict" keyword, if possible, like AC_C_INLINE.
2122dnl
2123dnl  If restrict works already, then do nothing.  Otherwise AC_DEFINE it to
2124dnl  __restrict__ or __restrict if they work, or to empty otherwise.
2125dnl
2126dnl  "restrict" is in C99.  GCC 2.95 and up has it in c99 mode, and also as
2127dnl  __restrict__ and __restrict in all modes.
2128dnl
2129dnl  "yes" is used in the cache variable if plain "restrict" works, to make
2130dnl  the configure message look nicer.
2131
2132AC_DEFUN(GMP_C_RESTRICT,
2133[AC_CACHE_CHECK([for restrict], gmp_cv_c_restrict,
2134[gmp_cv_c_restrict=no
2135for r in restrict __restrict__ __restrict; do
2136  AC_TRY_COMPILE(, [char * $r foo;],
2137    [gmp_cv_c_restrict=$r
2138    break])
2139done
2140if test $gmp_cv_c_restrict = restrict; then
2141  gmp_cv_c_restrict=yes
2142fi
2143])
2144case $gmp_cv_c_restrict in
2145  restrict | yes) ;;
2146  no) AC_DEFINE(restrict,,
2147                [Define as `__restrict' if that's what the C compiler calls it,
2148                 or to nothing if it is not supported.]) ;;
2149  *)  AC_DEFINE_UNQUOTED(restrict, $gmp_cv_c_restrict) ;;
2150esac
2151])
2152
2153
2154dnl  GMP_C_SIZES
2155dnl  -----------
2156dnl  Determine some sizes, if not alredy provided by gmp-mparam.h.
2157dnl  $gmp_mparam_source is the selected gmp-mparam.h.
2158dnl
2159dnl  BITS_PER_MP_LIMB, BYTES_PER_MP_LIMB and BITS_PER_ULONG are needed at
2160dnl  preprocessing time when building the library, for use in #if
2161dnl  conditionals.
2162dnl
2163dnl  BITS_PER_MP_LIMB is also wanted as a plain constant for some macros in
2164dnl  the generated gmp.h, and is instantiated as BITS_PER_MP_LIMB.
2165dnl
2166dnl  If some assembler code depends on a particular type size it's probably
2167dnl  best to put explicit #defines for these in gmp-mparam.h.  That way if
2168dnl  strange compiler options change the size then a mismatch will be
2169dnl  detected by t-constants.c rather than only by the code crashing or
2170dnl  giving wrong results.
2171dnl
2172dnl  None of the assembler code depends on BITS_PER_ULONG currently, so it's
2173dnl  just as easy to let configure find its size as to put explicit values.
2174dnl
2175dnl  The tests here assume bits=8*sizeof, but that might not be universally
2176dnl  true.  It'd be better to probe for how many bits seem to work, like
2177dnl  t-constants does.  But all currently supported systems have limbs and
2178dnl  ulongs with bits=8*sizeof, so it's academic.  Strange systems can
2179dnl  always have the right values put in gmp-mparam.h explicitly.
2180
2181AC_DEFUN(GMP_C_SIZES,
2182[BITS_PER_MP_LIMB=[`sed -n 's/^#define BITS_PER_MP_LIMB[        ][      ]*\([0-9]*\).*$/\1/p' $gmp_mparam_source`]
2183if test -n "$BITS_PER_MP_LIMB" \
2184   && grep "^#define BYTES_PER_MP_LIMB" $gmp_mparam_source >/dev/null; then : ;
2185else
2186  AC_CHECK_SIZEOF(mp_limb_t,,
2187[#include <stdio.h>]
2188GMP_INCLUDE_GMP_H)
2189  if test "$ac_cv_sizeof_mp_limb_t" = 0; then
2190    AC_MSG_ERROR([some sort of compiler problem, mp_limb_t doesn't seem to work])
2191  fi
2192  if test -z "$BITS_PER_MP_LIMB"; then
2193    BITS_PER_MP_LIMB="(8*$ac_cv_sizeof_mp_limb_t)"
2194  fi
2195  if grep "^#define BYTES_PER_MP_LIMB" $gmp_mparam_source >/dev/null; then : ;
2196  else
2197    AC_DEFINE_UNQUOTED(BYTES_PER_MP_LIMB, $ac_cv_sizeof_mp_limb_t,
2198                       [bytes per mp_limb_t, if not in gmp-mparam.h])
2199  fi
2200fi
2201AC_SUBST(BITS_PER_MP_LIMB)
2202define([GMP_INCLUDE_GMP_H_BITS_PER_MP_LIMB],
2203[[#define __GMP_BITS_PER_MP_LIMB $BITS_PER_MP_LIMB
2204#define GMP_LIMB_BITS $BITS_PER_MP_LIMB]])
2205
2206if grep "^#define BITS_PER_ULONG" $gmp_mparam_source >/dev/null; then : ;
2207else
2208  case $limb_chosen in
2209  longlong)
2210    AC_CHECK_SIZEOF(unsigned long)
2211    AC_DEFINE_UNQUOTED(BITS_PER_ULONG, (8 * $ac_cv_sizeof_unsigned_long),
2212                       [bits per unsigned long, if not in gmp-mparam.h])
2213    ;;
2214  *)
2215    # Copy the limb size when a limb is a ulong
2216    AC_DEFINE(BITS_PER_ULONG, BITS_PER_MP_LIMB)
2217    ;;
2218  esac
2219fi
2220])
2221
2222
2223dnl  GMP_C_STDARG
2224dnl  ------------
2225dnl  Test whether to use <stdarg.h> or <varargs.h>.
2226dnl
2227dnl  Notice the AC_DEFINE here is HAVE_STDARG to avoid clashing with
2228dnl  HAVE_STDARG_H which could arise from AC_CHECK_HEADERS.
2229dnl
2230dnl  This test might be slight overkill, after all there's really only going
2231dnl  to be ANSI or K&R and the two can be differentiated by AC_PROG_CC_STDC
2232dnl  or very likely by the setups for _PROTO in gmp.h.  On the other hand
2233dnl  this test is nice and direct, being what we're going to actually use.
2234
2235AC_DEFUN(GMP_C_STDARG,
2236[AC_CACHE_CHECK([whether <stdarg.h> exists and works],
2237                gmp_cv_c_stdarg,
2238[AC_TRY_COMPILE(
2239[#include <stdarg.h>
2240int foo (int x, ...)
2241{
2242  va_list  ap;
2243  int      y;
2244  va_start (ap, x);
2245  y = va_arg (ap, int);
2246  va_end (ap);
2247  return y;
2248}],,
2249gmp_cv_c_stdarg=yes, gmp_cv_c_stdarg=no)
2250])
2251if test $gmp_cv_c_stdarg = yes; then
2252  AC_DEFINE(HAVE_STDARG, 1, [Define if <stdarg.h> exists and works])
2253fi
2254])
2255
2256
2257dnl  GMP_FUNC_ALLOCA
2258dnl  ---------------
2259dnl  Determine whether "alloca" is available.  This is AC_FUNC_ALLOCA from
2260dnl  autoconf, but changed so it doesn't use alloca.c if alloca() isn't
2261dnl  available, and also to use gmp-impl.h for the conditionals detecting
2262dnl  compiler builtin alloca's.
2263
2264AC_DEFUN(GMP_FUNC_ALLOCA,
2265[AC_REQUIRE([GMP_HEADER_ALLOCA])
2266AC_CACHE_CHECK([for alloca (via gmp-impl.h)],
2267               gmp_cv_func_alloca,
2268[AC_TRY_LINK(
2269GMP_INCLUDE_GMP_H
2270[#include "$srcdir/gmp-impl.h"
2271],
2272  [char *p = (char *) alloca (1);],
2273  gmp_cv_func_alloca=yes,
2274  gmp_cv_func_alloca=no)])
2275if test $gmp_cv_func_alloca = yes; then
2276  AC_DEFINE(HAVE_ALLOCA, 1,
2277    [Define if alloca() works (via gmp-impl.h).])
2278fi
2279])
2280
2281AC_DEFUN(GMP_HEADER_ALLOCA,
2282[# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
2283# for constant arguments.  Useless!
2284AC_CACHE_CHECK([for working alloca.h],
2285               gmp_cv_header_alloca,
2286[AC_TRY_LINK([#include <alloca.h>],
2287  [char *p = (char *) alloca (2 * sizeof (int));],
2288  gmp_cv_header_alloca=yes,
2289  gmp_cv_header_alloca=no)])
2290if test $gmp_cv_header_alloca = yes; then
2291  AC_DEFINE(HAVE_ALLOCA_H, 1,
2292    [Define if you have <alloca.h> and it should be used (not on Ultrix).])
2293fi
2294])
2295
2296
2297dnl  GMP_OPTION_ALLOCA
2298dnl  -----------------
2299dnl  Decide what to do about --enable-alloca from the user.
2300dnl  This is a macro so it can require GMP_FUNC_ALLOCA.
2301
2302AC_DEFUN(GMP_OPTION_ALLOCA,
2303[AC_REQUIRE([GMP_FUNC_ALLOCA])
2304AC_CACHE_CHECK([how to allocate temporary memory],
2305               gmp_cv_option_alloca,
2306[case $enable_alloca in
2307  yes)
2308    gmp_cv_option_alloca=alloca
2309    ;;
2310  no)
2311    gmp_cv_option_alloca=malloc-reentrant
2312    ;;
2313  reentrant | notreentrant)
2314    case $gmp_cv_func_alloca in
2315    yes)  gmp_cv_option_alloca=alloca ;;
2316    *)    gmp_cv_option_alloca=malloc-$enable_alloca ;;
2317    esac
2318    ;;
2319  *)
2320    gmp_cv_option_alloca=$enable_alloca
2321    ;;
2322esac
2323])
2324case $gmp_cv_option_alloca in
2325  alloca)
2326    if test $gmp_cv_func_alloca = no; then
2327      AC_MSG_ERROR([--enable-alloca=alloca specified, but alloca not available])
2328    fi
2329    AC_DEFINE(WANT_TMP_ALLOCA, 1, [--enable-alloca=yes])
2330    ;;
2331  malloc-reentrant)
2332    AC_DEFINE(WANT_TMP_REENTRANT, 1, [--enable-alloca=malloc-reentrant])
2333    TAL_OBJECT=tal-reent$U.lo
2334    ;;
2335  malloc-notreentrant)
2336    AC_DEFINE(WANT_TMP_NOTREENTRANT, 1, [--enable-alloca=malloc-notreentrant])
2337    TAL_OBJECT=tal-notreent$U.lo
2338    ;;
2339  debug)
2340    AC_DEFINE(WANT_TMP_DEBUG, 1, [--enable-alloca=debug])
2341    TAL_OBJECT=tal-debug$U.lo
2342    ;;
2343  *)
2344    # checks at the start of configure.in should protect us
2345    AC_MSG_ERROR([unrecognised --enable-alloca=$gmp_cv_option_alloca])
2346    ;;
2347esac
2348AC_SUBST(TAL_OBJECT)
2349])
2350
2351
2352dnl  GMP_FUNC_SSCANF_WRITABLE_INPUT
2353dnl  ------------------------------
2354dnl  Determine whether sscanf requires a writable input string.
2355dnl
2356dnl  FIXME: Run a program to try this, when doing a native build.
2357
2358AC_DEFUN(GMP_FUNC_SSCANF_WRITABLE_INPUT,
2359[AC_CACHE_CHECK([whether sscanf needs writable input],
2360                 gmp_cv_func_sscanf_writable_input,
2361[case $host in
2362  *-*-hpux9 | *-*-hpux9.*)
2363     gmp_cv_func_sscanf_writable_input=yes ;;
2364  *) gmp_cv_func_sscanf_writable_input=no  ;;
2365esac
2366])
2367case $gmp_cv_func_sscanf_writable_input in
2368  yes) AC_DEFINE(SSCANF_WRITABLE_INPUT, 1,
2369                 [Define if sscanf requires writable inputs]) ;;
2370  no)  ;;
2371  *)   AC_MSG_ERROR([unrecognised \$gmp_cv_func_sscanf_writable_input]) ;;
2372esac
2373])
2374
2375
2376dnl  GMP_FUNC_VSNPRINTF
2377dnl  ------------------
2378dnl  Check whether vsnprintf exists, and works properly.
2379dnl
2380dnl  Sparc Solaris 2.7 in 64-bit mode doesn't always truncate, making
2381dnl  vsnprintf like vsprintf, and hence completely useless.  On one system a
2382dnl  literal string is enough to provoke the problem, on another a "%n" was
2383dnl  needed.  There seems to be something weird going on with the optimizer
2384dnl  or something, since on the first system adding a second check with
2385dnl  "%n", or even just an initialized local variable, makes it work.  In
2386dnl  any case, without bothering to get to the bottom of this, the two
2387dnl  program runs in the code below end up successfully detecting the
2388dnl  problem.
2389dnl
2390dnl  glibc 2.0.x returns either -1 or bufsize-1 for an overflow (both seen,
2391dnl  not sure which 2.0.x does which), but still puts the correct null
2392dnl  terminated result into the buffer.
2393
2394AC_DEFUN(GMP_FUNC_VSNPRINTF,
2395[AC_REQUIRE([GMP_C_STDARG])
2396AC_CHECK_FUNC(vsnprintf,
2397              [gmp_vsnprintf_exists=yes],
2398              [gmp_vsnprintf_exists=no])
2399if test "$gmp_vsnprintf_exists" = no; then
2400  gmp_cv_func_vsnprintf=no
2401else
2402  AC_CACHE_CHECK([whether vsnprintf works],
2403                 gmp_cv_func_vsnprintf,
2404  [gmp_cv_func_vsnprintf=yes
2405   for i in 'check ("hello world");' 'int n; check ("%nhello world", &n);'; do
2406     AC_TRY_RUN([
2407#include <string.h>  /* for strcmp */
2408#include <stdio.h>   /* for vsnprintf */
2409
2410#if HAVE_STDARG
2411#include <stdarg.h>
2412#else
2413#include <varargs.h>
2414#endif
2415
2416int
2417#if HAVE_STDARG
2418check (const char *fmt, ...)
2419#else
2420check (va_alist)
2421     va_dcl
2422#endif
2423{
2424  static char  buf[128];
2425  va_list  ap;
2426  int      ret;
2427
2428#if HAVE_STDARG
2429  va_start (ap, fmt);
2430#else
2431  char *fmt;
2432  va_start (ap);
2433  fmt = va_arg (ap, char *);
2434#endif
2435
2436  ret = vsnprintf (buf, 4, fmt, ap);
2437
2438  if (strcmp (buf, "hel") != 0)
2439    exit (1);
2440
2441  /* allowed return values */
2442  if (ret != -1 && ret != 3 && ret != 11)
2443    exit (2);
2444
2445  return 0;
2446}
2447
2448int
2449main ()
2450{
2451$i
2452  exit (0);
2453}
2454],
2455      [:],
2456      [gmp_cv_func_vsnprintf=no; break],
2457      [gmp_cv_func_vsnprintf=probably; break])
2458  done
2459  ])
2460  if test "$gmp_cv_func_vsnprintf" = probably; then
2461    AC_MSG_WARN([cannot check for properly working vsnprintf when cross compiling, will assume it's ok])
2462  fi
2463  if test "$gmp_cv_func_vsnprintf" != no; then
2464    AC_DEFINE(HAVE_VSNPRINTF,1,
2465              [Define if you have vsnprintf and it works properly.])
2466  fi
2467fi
2468])
2469
2470
2471dnl  GMP_H_ANSI
2472dnl  ----------
2473dnl  Check whether gmp.h recognises the compiler as ANSI capable.
2474
2475AC_DEFUN(GMP_H_ANSI,
2476[AC_REQUIRE([AC_PROG_CC_STDC])
2477case $ac_cv_prog_cc_stdc in
2478  no)
2479    ;;
2480  *)
2481    AC_TRY_COMPILE(
2482GMP_INCLUDE_GMP_H
2483[#if ! __GMP_HAVE_PROTOTYPES
2484die die die
2485#endif
2486],,,
2487    [AC_MSG_WARN([gmp.h doesnt recognise compiler as ANSI, prototypes and "const" will be unavailable])])
2488    ;;
2489esac
2490])
2491
2492
2493dnl  GMP_H_EXTERN_INLINE
2494dnl  -------------------
2495dnl  If the compiler has an "inline" of some sort, check whether the
2496dnl  #ifdef's in gmp.h recognise it.
2497
2498AC_DEFUN(GMP_H_EXTERN_INLINE,
2499[AC_REQUIRE([GMP_C_INLINE])
2500case $gmp_cv_c_inline in
2501no) ;;
2502*)
2503  AC_TRY_COMPILE(
2504[#define __GMP_WITHIN_CONFIGURE_INLINE 1
2505]GMP_INCLUDE_GMP_H[
2506#ifndef __GMP_EXTERN_INLINE
2507die die die
2508#endif
2509],,,
2510  [case $gmp_cv_c_inline in
2511  yes) tmp_inline=inline ;;
2512  *)   tmp_inline=$gmp_cv_c_inline ;;
2513  esac   
2514  AC_MSG_WARN([gmp.h doesnt recognise compiler "$tmp_inline", inlines will be unavailable])])
2515  ;;
2516esac
2517])
2518
2519
2520dnl  GMP_H_HAVE_FILE
2521dnl  ---------------
2522dnl  Check whether the #ifdef's in gmp.h recognise when stdio.h has been
2523dnl  included to get FILE.
2524
2525AC_DEFUN(GMP_H_HAVE_FILE,
2526[AC_TRY_COMPILE(
2527[#include <stdio.h>]
2528GMP_INCLUDE_GMP_H
2529[#if ! _GMP_H_HAVE_FILE
2530die die die
2531#endif
2532],,,
2533  [AC_MSG_WARN([gmp.h doesnt recognise <stdio.h>, FILE prototypes will be unavailable])])
2534])
2535
2536
2537dnl  GMP_IMPL_H_IEEE_FLOATS
2538dnl  ----------------------
2539dnl  Check whether the #ifdef's in gmp-impl.h recognise IEEE format and
2540dnl  endianness.
2541
2542AC_DEFUN(GMP_IMPL_H_IEEE_FLOATS,
2543[case $host in
2544  vax*-*-*)
2545    # not IEEE (neither D nor G formats are IEEE)
2546    ;;
2547  none-*-*)
2548    # don't worry about this when CPU "none"
2549    ;;
2550  *)
2551    case $path in
2552      *cray/cfp*)
2553        # not IEEE
2554        ;;
2555      *)
2556        AC_TRY_COMPILE(
2557[#include <stdio.h>]
2558GMP_INCLUDE_GMP_H
2559[#include "$srcdir/gmp-impl.h"
2560#ifndef _GMP_IEEE_FLOATS
2561die die die
2562#endif
2563],,,[
2564          AC_MSG_WARN([gmp-impl.h doesnt recognise "double" as IEEE.])
2565          AC_MSG_WARN([If your CPU floats are in fact IEEE then you])
2566          AC_MSG_WARN([might like to augment the tests there.])
2567        ])
2568        ;;
2569    esac
2570    ;;
2571esac
2572])
Note: See TracBrowser for help on using the repository browser.