Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  acinclude.m4   Sprache: Shell

 
dnl  GMP specific autoconf macros


dnl  Copyright 2000-2006, 2009, 2011, 2013-2018 Free Software Foundation, Inc.
dnl
dnl  This file is part of the GNU MP Library.
dnl
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
dnl  it under the terms of either:
dnl
dnl    * the GNU Lesser General Public License as published by the Free
dnl      Software Foundation; either version 3 of the License, or (at your
dnl      option) any later version.
dnl
dnl  or
dnl
dnl    * the GNU General Public License as published by the Free Software
dnl      Foundation; either version 2 of the License, or (at your option) any
dnl      later version.
dnl
dnl  or both in parallel, as here.
dnl
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dnl  for more details.
dnl
dnl  You should have received copies of the GNU General Public License and the
dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
dnl  see https://www.gnu.org/licenses/.


dnl  Some tests use, or must delete, the default compiler output.  The
dnl  possible filenames are based on what autoconf looks for, namely
dnl
dnl    a.out - normal unix style
dnl    b.out - i960 systems, including gcc there
dnl    a.exe - djgpp
dnl    a_out.exe - OpenVMS DEC C called via GNV wrapper (gnv.sourceforge.net)
dnl    conftest.exe - various DOS compilers


define(IA64_PATTERN,
[[ia64*-*-* | itanium-*-* | itanium2-*-*]])

dnl  Need to be careful not to match m6811, m6812, m68hc11 and m68hc12, all
dnl  of which config.sub accepts.  (Though none of which are likely to work
dnl  with GMP.)
dnl
define(M68K_PATTERN,
[[m68k-*-* | m68[0-9][0-9][0-9]-*-*]])

define(POWERPC64_PATTERN,
[[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-* | powerpc970-*-* | power[3-9]-*-* | power1[0-9]-*-*]])

define(S390_PATTERN,
[[s390-*-* | z900esa-*-* | z990esa-*-* | z9esa-*-* | z1[0-6]esa-*-* | z196esa-*-*]])

define(S390X_PATTERN,
[[s390x-*-* | z900-*-* | z990-*-* | z9-*-* | z1[0-6]-*-* | z196-*-*]])

define(X86_PATTERN,
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])

define(X86_64_PATTERN,
[[athlon64-*-* | k8-*-* | k10-*-* | bobcat-*-* | jaguar*-*-* | bulldozer*-*-* | piledriver*-*-* | steamroller*-*-* | excavator*-*-* | zen*-*-* | pentium4-*-* | atom-*-* | silvermont-*-* | goldmont-*-* | tremont-*-* | core2-*-* | corei*-*-* | x86_64-*-* | nano-*-* | nehalem*-*-* | westmere*-*-* | sandybridge*-*-* | ivybridge*-*-* | haswell*-*-* | broadwell*-*-* | skylake*-*-* | kabylake*-*-* | icelake*-*-* | tigerlake*-*-* | rocketlake*-*-* | alderlake*-*-* | raptorlake*-*-*]])

dnl  GMP_FAT_SUFFIX(DSTVAR, DIRECTORY)
dnl  ---------------------------------
dnl  Emit code to set shell variable DSTVAR to the suffix for a fat binary
dnl  routine from DIRECTORY.  DIRECTORY can be a shell expression like $foo
dnl  etc.
dnl
dnl  The suffix is directory separators / or \ changed to underscores, and
dnl  if there's more than one directory part, then the first is dropped.
dnl
dnl  For instance,
dnl
dnl      x86         ->  x86
dnl      x86/k6      ->  k6
dnl      x86/k6/mmx  ->  k6_mmx

define(GMP_FAT_SUFFIX,
[[$1=`echo $2 | sed -e '/\//s:^[^/]*/::' -e 's:[\\/]:_:g'`]])


dnl  GMP_REMOVE_FROM_LIST(listvar,item)
dnl  ----------------------------------
dnl  Emit code to remove any occurrence of ITEM from $LISTVAR.  ITEM can be a
dnl  shell expression like $foo if desired.

define(GMP_REMOVE_FROM_LIST,
[remove_from_list_tmp=
for remove_from_list_i in $[][$1]; do
  if test $remove_from_list_i = [$2]; then :;
  else
     remove_from_list_tmp="$remove_from_list_tmp $remove_from_list_i"
  fi
done
[$1]=$remove_from_list_tmp
])


dnl  GMP_STRIP_PATH(subdir)
dnl  ----------------------
dnl  Strip entries */subdir from $path and $fat_path.

define(GMP_STRIP_PATH,
[GMP_STRIP_PATH_VAR(path, [$1])
GMP_STRIP_PATH_VAR(fat_path, [$1])
])

define(GMP_STRIP_PATH_VAR,
[tmp_path=
for i in $[][$1]; do
  case $i in
    */[$2]) ;;
    *) tmp_path="$tmp_path $i" ;;
  esac
done
[$1]="$tmp_path"
])


dnl  GMP_INCLUDE_GMP_H
dnl  -----------------
dnl  Expand to the right way to #include gmp-h.in.  This must be used
dnl  instead of gmp.h, since that file isn't generated until the end of the
dnl  configure.
dnl
dnl  Dummy value for GMP_LIMB_BITS is enough
dnl  for all current configure-time uses of gmp.h.

define(GMP_INCLUDE_GMP_H,
[[#define __GMP_WITHIN_CONFIGURE 1   /* ignore template stuff */
#define GMP_NAIL_BITS $GMP_NAIL_BITS
#define GMP_LIMB_BITS 123
$DEFN_LONG_LONG_LIMB
#include "$srcdir/gmp-h.in"]
])


dnl  GMP_HEADER_GETVAL(NAME,FILE)
dnl  ----------------------------
dnl  Expand at autoconf time to the value of a "#define NAME" from the given
dnl  FILE.  The regexps here aren't very rugged, but are enough for gmp.
dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.

define(GMP_HEADER_GETVAL,
[patsubst(patsubst(
esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
[^.*$1[  ]+],[]),
[[
  ]*$],[])])


dnl  GMP_VERSION
dnl  -----------
dnl  The gmp version number, extracted from the #defines in gmp-h.in at
dnl  autoconf time.  Two digits like 3.0 if patchlevel <= 0, or three digits
dnl  like 3.0.1 if patchlevel > 0.

define(GMP_VERSION,
[GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl
.GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl
.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])


dnl  GMP_SUBST_CHECK_FUNCS(func,...)
dnl  ------------------------------
dnl  Setup an AC_SUBST of HAVE_FUNC_01 for each argument.

AC_DEFUN([GMP_SUBST_CHECK_FUNCS],
[m4_if([$1],,,
[_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01)
GMP_SUBST_CHECK_FUNCS(m4_shift($@))])])

dnl  Called: _GMP_SUBST_CHECK_FUNCS(cachevar,substvar)
AC_DEFUN([_GMP_SUBST_CHECK_FUNCS],
[case $[$1] in
yes) AC_SUBST([$2],1) ;;
no)  [$2]=0 ;;
esac
])


dnl  GMP_SUBST_CHECK_HEADERS(foo.h,...)
dnl  ----------------------------------
dnl  Setup an AC_SUBST of HAVE_FOO_H_01 for each argument.

AC_DEFUN([GMP_SUBST_CHECK_HEADERS],
[m4_if([$1],,,
[_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]),
HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01)
GMP_SUBST_CHECK_HEADERS(m4_shift($@))])])

dnl  Called: _GMP_SUBST_CHECK_HEADERS(cachevar,substvar)
AC_DEFUN([_GMP_SUBST_CHECK_HEADERS],
[case $[$1] in
yes) AC_SUBST([$2],1) ;;
no)  [$2]=0 ;;
esac
])


dnl  GMP_COMPARE_GE(A1,B1, A2,B2, ...)
dnl  ---------------------------------
dnl  Compare two version numbers A1.A2.etc and B1.B2.etc.  Set
dnl  $gmp_compare_ge to yes or no according to the result.  The A parts
dnl  should be variables, the B parts fixed numbers.  As many parts as
dnl  desired can be included.  An empty string in an A part is taken to be
dnl  zero, the B parts should be non-empty and non-zero.
dnl
dnl  For example,
dnl
dnl      GMP_COMPARE($major,10, $minor,3, $subminor,1)
dnl
dnl  would test whether $major.$minor.$subminor is greater than or equal to
dnl  10.3.1.

AC_DEFUN([GMP_COMPARE_GE],
[gmp_compare_ge=no
GMP_COMPARE_GE_INTERNAL($@)
])

AC_DEFUN([GMP_COMPARE_GE_INTERNAL],
[ifelse(len([$3]),0,
[if test -n "$1" && test "$1" -ge $2; then
  gmp_compare_ge=yes
fi],
[if test -n "$1"then
  if test "$1" -gt $2; then
    gmp_compare_ge=yes
  else
    if test "$1" -eq $2; then
      GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@)))
    fi
  fi
fi])
])


dnl  GMP_PROG_AR
dnl  -----------
dnl  GMP additions to $AR.
dnl
dnl  A cross-"ar" may be necessary when cross-compiling since the build
dnl  system "ar" might try to interpret the object files to build a symbol
dnl  table index, hence the use of AC_CHECK_TOOL.
dnl
dnl  A user-selected $AR is always left unchanged.  AC_CHECK_TOOL is still
dnl  run to get the "checking" message printed though.
dnl
dnl  If extra flags are added to AR, then ac_cv_prog_AR and
dnl  ac_cv_prog_ac_ct_AR are set too, since libtool (cvs 2003-03-31 at
dnl  least) will do an AC_CHECK_TOOL and that will AR from one of those two
dnl  cached variables.  (ac_cv_prog_AR is used if there's an ac_tool_prefix,
dnl  or ac_cv_prog_ac_ct_AR is used otherwise.)  FIXME: This is highly
dnl  dependent on autoconf internals, perhaps it'd work to put our extra
dnl  flags into AR_FLAGS instead.
dnl
dnl  $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru".  The
dnl  latter fails when libtool goes into piecewise mode and is unlucky
dnl  enough to have two same-named objects in separate pieces, as happens
dnl  for instance to random.o (and others) on vax-dec-ultrix4.5.  Naturally
dnl  a user-selected $AR_FLAGS is left unchanged.
dnl
dnl  For reference, $ARFLAGS is used by automake (1.8) for its ".a" archive
dnl  file rules.  This doesn't get used by the piecewise linking, so we
dnl  leave it at the default "cru".
dnl
dnl  FIXME: Libtool 1.5.2 has its own arrangements for "cq", but that version
dnl  is broken in other ways.  When we can upgrade, remove the forcible
dnl  AR_FLAGS=cq.

AC_DEFUN([GMP_PROG_AR],
[dnl  Want to establish $AR before libtool initialization.
AC_BEFORE([$0],[AC_PROG_LIBTOOL])
gmp_user_AR=$AR
AC_CHECK_TOOL(AR, ar, ar)
if test -z "$gmp_user_AR"then
                        eval arflags=\"\$ar${abi1}_flags\"
  test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\"
  if test -n "$arflags"then
    AC_MSG_CHECKING([for extra ar flags])
    AR="$AR $arflags"
    ac_cv_prog_AR="$AR $arflags"
    ac_cv_prog_ac_ct_AR="$AR $arflags"
    AC_MSG_RESULT([$arflags])
  fi
fi
if test -z "$AR_FLAGS"then
  AR_FLAGS=cq
fi
])


dnl  GMP_PROG_M4
dnl  -----------
dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
dnl  AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
dnl  good enough.
dnl
dnl  See mpn/asm-defs.m4 for details on the known bad m4s.

AC_DEFUN([GMP_PROG_M4],
[AC_ARG_VAR(M4,[m4 macro processor])
AC_CACHE_CHECK([for suitable m4],
                gmp_cv_prog_m4,
[if test -n "$M4"then
  gmp_cv_prog_m4="$M4"
else
  cat >conftest.m4 <<\EOF
dnl  Must protect this against being expanded during autoconf m4!
dnl  Dont put "dnl"s in this as autoconf will flag an error for unexpanded
dnl  macros.
[define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
``bad: $][# not supported (SunOS /usr/bin/m4)
'')ifelse(eval(89),89,`define(t2,Y)',
`bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
')ifelse(eval(9,9),10,`define(t3,Y)',
`bad: eval() doesnt support radix in eval (FreeBSD 8.x,9.0,9.1,9.2 m4)
')ifelse(t1`'t2`'t3,YYY,`good
')]
EOF
dnl ' <- balance the quotes for emacs sh-mode
  echo "trying m4" >&AC_FD_CC
  gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
  echo "$gmp_tmp_val" >&AC_FD_CC
  if test "$gmp_tmp_val" = good; then
    gmp_cv_prog_m4="m4"
  else
    IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
dnl $ac_dummy forces splitting on constant user-supplied paths.
dnl POSIX.2 word splitting is done only on the output of word expansions,
dnl not every word.  This closes a longstanding sh security hole.
    ac_dummy="$PATH:/usr/5bin"
    for ac_dir in $ac_dummy; do
      test -z "$ac_dir" && ac_dir=.
      echo "trying $ac_dir/m4" >&AC_FD_CC
      gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
      echo "$gmp_tmp_val" >&AC_FD_CC
      if test "$gmp_tmp_val" = good; then
        gmp_cv_prog_m4="$ac_dir/m4"
        break
      fi
    done
    IFS="$ac_save_ifs"
    if test -z "$gmp_cv_prog_m4"then
      AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
    fi
  fi
  rm -f conftest.m4
fi])
M4="$gmp_cv_prog_m4"
AC_SUBST(M4)
])


dnl  GMP_M4_M4WRAP_SPURIOUS
dnl  ----------------------
dnl  Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4.
dnl
dnl  The following systems have been seen with the problem.
dnl
dnl  - Unicos alpha, but its assembler doesn't seem to mind.
dnl  - MacOS X Darwin, its assembler fails.
dnl  - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores
dnl    the bad last line since it doesn't have a newline.
dnl  - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind.
dnl  - HP-UX ia64.
dnl
dnl  Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer
dnl  an m4 with a working m4wrap, if it can be found.

AC_DEFUN([GMP_M4_M4WRAP_SPURIOUS],
[AC_REQUIRE([GMP_PROG_M4])
AC_CACHE_CHECK([if m4wrap produces spurious output],
               gmp_cv_m4_m4wrap_spurious,
[# hide the d-n-l from autoconf's error checking
tmp_d_n_l=d""nl
cat >conftest.m4 <<EOF
[changequote({,})define(x,)m4wrap({x})$tmp_d_n_l]
EOF
echo test input is >&AC_FD_CC
cat conftest.m4 >&AC_FD_CC
tmp_chars=`$M4 conftest.m4 | wc -c`
echo produces $tmp_chars chars output >&AC_FD_CC
rm -f conftest.m4
if test $tmp_chars = 0; then
  gmp_cv_m4_m4wrap_spurious=no
else
  gmp_cv_m4_m4wrap_spurious=yes
fi
])
GMP_DEFINE_RAW(["define(,<$gmp_cv_m4_m4wrap_spurious>)"])
])


dnl  GMP_PROG_NM
dnl  -----------
dnl  GMP additions to libtool AC_PROG_NM.
dnl
dnl  Note that if AC_PROG_NM can't find a working nm it still leaves
dnl  $NM set to "nm", so $NM can't be assumed to actually work.
dnl
dnl  A user-selected $NM is always left unchanged.  AC_PROG_NM is still run
dnl  to get the "checking" message printed though.
dnl
dnl  Perhaps it'd be worthwhile checking that nm works, by running it on an
dnl  actual object file.  For instance on sparcv9 solaris old versions of
dnl  GNU nm don't recognise 64-bit objects. Checking would give a better
dnl  error message than just a failure in later tests like GMP_ASM_W32 etc.
dnl
dnl  On the other hand it's not really normal autoconf practice to take too
dnl  much trouble over detecting a broken set of tools.  And libtool doesn't
dnl  do anything at all for say ranlib or strip.  So for now we're inclined
dnl  to just demand that the user provides a coherent environment.

AC_DEFUN([GMP_PROG_NM],
[dnl  Make sure we're the first to call AC_PROG_NM, so our extra flags are
dnl   used by everyone.
AC_BEFORE([$0],[AC_PROG_NM])
gmp_user_NM=$NM
AC_PROG_NM

# FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool
# defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found.  In this
# case run it again to try the native "nm", firstly so that likely locations
# are searched, secondly so that -B or -p are added if necessary for BSD
# format.  This is necessary for instance on OSF with "./configure
# --build=alphaev5-dec-osf --host=alphaev6-dec-osf".
#
if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then
  $as_unset lt_cv_path_NM
  gmp_save_ac_tool_prefix=$ac_tool_prefix
  ac_tool_prefix=
  NM=
  AC_PROG_NM
  ac_tool_prefix=$gmp_save_ac_tool_prefix
fi

if test -z "$gmp_user_NM"then
                        eval nmflags=\"\$nm${abi1}_flags\"
  test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\"
  if test -n "$nmflags"then
    AC_MSG_CHECKING([for extra nm flags])
    NM="$NM $nmflags"
    AC_MSG_RESULT([$nmflags])
  fi
fi
])


dnl  GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS])
dnl  --------------------------------------------------------------------
dnl  Check if cc+cflags can compile and link.
dnl
dnl  This test is designed to be run repeatedly with different cc+cflags
dnl  selections, so the result is not cached.
dnl
dnl  For a native build, meaning $cross_compiling == no, we require that the
dnl  generated program will run.  This is the same as AC_PROG_CC does in
dnl  _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass
dnl  a CC/CFLAGS combination that it rejects.
dnl
dnl  sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel
dnl  was booted in 32-bit mode.  The effect of requiring the compiler output
dnl  will run is that a plain native "./configure" falls back on ABI=32, but
dnl  ABI=64 is still available as a cross-compile.
dnl
dnl  The various specific problems we try to detect are done in separate
dnl  compiles.  Although this is probably a bit slower than one test
dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
dnl  hence giving the user a clue about why we rejected the compiler.

AC_DEFUN([GMP_PROG_CC_WORKS],
[AC_MSG_CHECKING([compiler $1])
gmp_prog_cc_works=yes

# first see a simple "main()" works, then go on to other checks
GMP_PROG_CC_WORKS_PART([$1], [])

GMP_PROG_CC_WORKS_PART([$1], [function pointer return],
[/* The following provokes an internal error from gcc 2.95.2 -mpowerpc64
   (without -maix64), hence detecting an unusable compiler */
void *g() { return (void *) 0; }
void *f() { return g(); }
])

GMP_PROG_CC_WORKS_PART([$1], [cmov instruction],
[/* The following provokes an invalid instruction syntax from i386 gcc
   -march=pentiumpro on Solaris 2.8.  The native sun assembler
   requires a non-standard syntax for cmov which gcc (as of 2.95.2 at
   least) doesn't know. */
int n;
int cmov () { return (n >= 0 ? n : 0); }
])

GMP_PROG_CC_WORKS_PART([$1], [double -> ulong conversion],
[/* The following provokes a linker invocation problem with gcc 3.0.3
   on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630".  The -mcpu=630
   option causes gcc to incorrectly select the 32-bit libgcc.a, not
   the 64-bit one, and consequently it misses out on the __fixunsdfdi
   helper (double -> uint64 conversion).  */
double d;
unsigned long gcc303 () { return (unsigned long) d; }
])

GMP_PROG_CC_WORKS_PART([$1], [double negation],
[/* The following provokes an error from hppa gcc 2.95 under -mpa-risc-2-0 if
   the assembler doesn't know hppa 2.0 instructions. fneg is a 2.0
   instruction, and a negation like this comes out using it.  */
double fneg_data;
unsigned long fneg () { return -fneg_data; }
])

GMP_PROG_CC_WORKS_PART([$1], [double -> float conversion],
[/* The following makes gcc 3.3 -march=pentium4 generate an SSE2 xmm insn
   (cvtsd2ss) which will provoke an error if the assembler doesn't recognise
   those instructions.  Not sure how much of the gmp code will come out
   wanting sse2, but it's easiest to reject an option we know is bad. */
double ftod_data;
float ftod () { return (float) ftod_data; }
])

GMP_PROG_CC_WORKS_PART([$1], [gnupro alpha ev6 char spilling],
[/* The following provokes an internal compiler error from gcc version
   "2.9-gnupro-99r1" under "-O2 -mcpu=ev6", apparently relating to char
   values being spilled into floating point registers.  The problem doesn't
   show up all the time, but has occurred enough in GMP for us to reject
   this compiler+flags.  */
#include <string.h>  /* for memcpy */
struct try_t
{
 char dst[2];
 char size;
 long d0, d1, d2, d3, d4, d5, d6;
 char overlap;
};
struct try_t param[6];
int
param_init ()
{
 struct try_t *p;
 memcpy (p, ¶m[ 2 ], sizeof (*p));
 memcpy (p, ¶m[ 2 ], sizeof (*p));
 p->size = 2;
 memcpy (p, ¶m[ 1 ], sizeof (*p));
 p->dst[0] = 1;
 p->overlap = 2;
 memcpy (p, ¶m[ 3 ], sizeof (*p));
 p->dst[0] = 1;
 p->overlap = 8;
 memcpy (p, ¶m[ 4 ], sizeof (*p));
 memcpy (p, ¶m[ 4 ], sizeof (*p));
 p->overlap = 8;
 memcpy (p, ¶m[ 5 ], sizeof (*p));
 memcpy (p, ¶m[ 5 ], sizeof (*p));
 memcpy (p, ¶m[ 5 ], sizeof (*p));
 return 0;
}
])

# __builtin_alloca is not available everywhere, check it exists before
# seeing that it works
GMP_PROG_CC_WORKS_PART_TEST([$1],[__builtin_alloca availability],
[int k; int foo () { __builtin_alloca (k); }],
  [GMP_PROG_CC_WORKS_PART([$1], [alloca array],
[/* The following provokes an internal compiler error from Itanium HP-UX cc
    under +O2 or higher.  We use this sort of code in mpn/generic/mul_fft.c. */
int k;
int foo ()
{
  int i, **a;
  a = __builtin_alloca (k);
  for (i = 0; i <= k; i++)
    a[i] = __builtin_alloca (1 << i);
}
])])

GMP_PROG_CC_WORKS_PART([$1], [abs int -> double conversion],
[/* The following provokes an internal error from the assembler on
   power2-ibm-aix4.3.1.0.  gcc -mrios2 compiles to nabs+fcirz, and this
   results in "Internal error related to the source program domain".

   For reference it seems to be the combination of nabs+fcirz which is bad,
   not either alone.  This sort of thing occurs in mpz/get_str.c with the
   way double chars_per_bit_exactly is applied in MPN_SIZEINBASE.  Perhaps
   if that code changes to a scaled-integer style then we won't need this
   test.  */

double fp[1];
int x;
int f ()
{
  int a;
  a = (x >= 0 ? x : -x);
  return a * fp[0];
}
])

GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 1],
[/* The following provokes a segfault in the compiler on powerpc-apple-darwin.
   Extracted from tests/mpn/t-iord_u.c.  Causes Apple's gcc 3.3 build 1640 and
   1666 to segfault with e.g., -O2 -mpowerpc64.  */

#if defined (__GNUC__) && ! defined (__cplusplus)
typedef unsigned long long t1;typedef t1*t2;
void g(){}
void h(){}
static __inline__ t1 e(t2 rp,t2 up,int n,t1 v0)
{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;}
void f(){static const struct{t1 n;t1 src[9];t1 want[9];}d[]={{1,{0},{1}},};t1 got[9];int i;
for(i=0;i<1;i++){if(e(got,got,9,d[i].n)==0)h();g(i,d[i].src,d[i].n,got,d[i].want,9);if(d[i].n)h();}}
#else
int dummy;
#endif
])

GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 2],
[/* The following provokes an internal compiler error on powerpc-apple-darwin.
   Extracted from mpz/cfdiv_q_2exp.c.  Causes Apple's gcc 3.3 build 1640 and
   1666 to get an ICE with -O1 -mpowerpc64.  */

#if defined (__GNUC__) && ! defined (__cplusplus)
int g();
void f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
int g(){return 0;}
#else
int dummy;
#endif
])

GMP_PROG_CC_WORKS_PART([$1], [freebsd hacked gcc],
[/* Provokes an ICE on i386-freebsd with the FreeBSD-hacked gcc, under
   -O2 -march=amdfam10.  We call helper functions here "open" and "close" in
   order for linking to succeed.  */

#if defined (__GNUC__) && ! defined (__cplusplus)
int open(int*,int*,int);void*close(int);void g(int*rp,int*up,int un){
__builtin_expect(un<=0x7f00,1)?__builtin_alloca(un):close(un);if(__builtin_clzl
(up[un])){open(rp,up,un);while(1){if(rp[un-1]!=0)break;un--;}}}
#else
int dummy;
#endif
])

GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization],
[/* The following is mis-compiled by HP ia-64 cc version
        cc: HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]
   under "cc +O3", both in +DD32 and +DD64 modes.  The mpn_lshift_com gets
   inlined and its return value somehow botched to be 0 instead of 1.  This
   arises in the real mpn_lshift_com in mul_fft.c.  A lower optimization
   level, like +O2 seems ok.  This code needs to be run to show the problem,
   but that's fine, the offending cc is a native-only compiler so we don't
   have to worry about cross compiling.  */

#if ! defined (__cplusplus)
unsigned long
lshift_com (rp, up, n, cnt)
  unsigned long *rp;
  unsigned long *up;
  long n;
  unsigned cnt;
{
  unsigned long retval, high_limb, low_limb;
  unsigned tnc;
  long i;
  tnc = 8 * sizeof (unsigned long) - cnt;
  low_limb = *up++;
  retval = low_limb >> tnc;
  high_limb = low_limb << cnt;
  for (i = n - 1; i != 0; i--)
    {
      low_limb = *up++;
      *rp++ = ~(high_limb | (low_limb >> tnc));
      high_limb = low_limb << cnt;
    }
  return retval;
}
int
main ()
{
  unsigned long cy, rp[2], up[2];
  up[0] = ~ 0L;
  up[1] = 0;
  cy = lshift_com (rp, up, 2L, 1);
  if (cy != 1L)
    return 1;
  return 0;
}
#else
int
main ()
{
  return 0;
}
#endif
])

GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization 2],
[/* The following is mis-compiled by Intel ia-64 icc version 1.8 under
    "icc -O3",  After several calls, the function writes partial garbage to
    the result vector.  Perhaps relates to the chk.a.nc insn.  This code needs
    to be run to show the problem, but that's fine, the offending cc is a
    native-only compiler so we don't have to worry about cross compiling. */

#if ! defined (__cplusplus)
#include <stdlib.h>
void
lshift_com (rp, up, n, cnt)
  unsigned long *rp;
  unsigned long *up;
  long n;
  unsigned cnt;
{
  unsigned long high_limb, low_limb;
  unsigned tnc;
  long i;
  up += n;
  rp += n;
  tnc = 8 * sizeof (unsigned long) - cnt;
  low_limb = *--up;
  high_limb = low_limb << cnt;
  for (i = n - 1; i != 0; i--)
    {
      low_limb = *--up;
      *--rp = ~(high_limb | (low_limb >> tnc));
      high_limb = low_limb << cnt;
    }
  *--rp = ~high_limb;
}
int
main ()
{
  unsigned long *r, *r2;
  unsigned long a[88 + 1];
  long i;
  for (i = 0; i < 88 + 1; i++)
    a[i] = ~0L;
  r = calloc (10000, sizeof (unsigned long));
  r2 = r;
  for (i = 0; i < 528; i += 23)
    {
      lshift_com (r2, a,
    i / (8 * sizeof (unsigned long)) + 1,
    i % (8 * sizeof (unsigned long)));
      r2 += 88 + 1;
    }
  if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
      r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
    abort ();
  free (r);
  return 0;
}
#else
int
main ()
{
  return 0;
}
#endif
])


# A certain _GLOBAL_OFFSET_TABLE_ problem in past versions of gas, tickled
# by recent versions of gcc.
#
if test "$gmp_prog_cc_works" = yes; then
  case $host in
    X86_PATTERN)
      # this problem only arises in PIC code, so don't need to test when
      # --disable-shared.  We don't necessarily have $enable_shared set to
      # yes at this point, it will still be unset for the default (which is
      # yes); hence the use of "!= no".
      if test "$enable_shared" != no; then
        GMP_PROG_CC_X86_GOT_EAX_EMITTED([$1],
          [GMP_ASM_X86_GOT_EAX_OK([$1],,
            [gmp_prog_cc_works="no, bad gas GOT with eax"])])
      fi
      ;;
  esac
fi

AC_MSG_RESULT($gmp_prog_cc_works)
case $gmp_prog_cc_works in
  yes)
    [$2]
    ;;
  *)
    [$3]
    ;;
esac
])

dnl  Called: GMP_PROG_CC_WORKS_PART(CC+CFLAGS,FAIL-MESSAGE [,CODE])
dnl  A dummy main() is appended to the CODE given.
dnl
AC_DEFUN([GMP_PROG_CC_WORKS_PART],
[GMP_PROG_CC_WORKS_PART_MAIN([$1],[$2],
[$3]
[int main () { return 0; }])
])

dnl  Called: GMP_PROG_CC_WORKS_PART_MAIN(CC+CFLAGS,FAIL-MESSAGE,CODE)
dnl  CODE must include a main().
dnl
AC_DEFUN([GMP_PROG_CC_WORKS_PART_MAIN],
[GMP_PROG_CC_WORKS_PART_TEST([$1],[$2],[$3],
  [],
  gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2]",
  gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2][[, program does not run]]")
])

dnl  Called: GMP_PROG_CC_WORKS_PART_TEST(CC+CFLAGS,TITLE,[CODE],
dnl            [ACTION-GOOD],[ACTION-BAD][ACTION-NORUN])
dnl
AC_DEFUN([GMP_PROG_CC_WORKS_PART_TEST],
[if test "$gmp_prog_cc_works" = yes; then
  # remove anything that might look like compiler output to our "||" expression
  rm -f conftest* a.out b.out a.exe a_out.exe
  cat >conftest.c <<EOF
[$3]
EOF
  echo "Test compile: [$2]" >&AC_FD_CC
  gmp_compile="$1 conftest.c >&AC_FD_CC"
  if AC_TRY_EVAL(gmp_compile); then
    cc_works_part=yes
    if test "$cross_compiling" = no; then
      if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
      else
        cc_works_part=norun
      fi
    fi
  else
    cc_works_part=no
  fi
  if test "$cc_works_part" != yes; then
    echo "failed program was:" >&AC_FD_CC
    cat conftest.c >&AC_FD_CC
  fi
  rm -f conftest* a.out b.out a.exe a_out.exe
  case $cc_works_part in
    yes)
      $4
      ;;
    no)
      $5
      ;;
    norun)
      $6
      ;;
  esac
fi
])


dnl  GMP_PROG_CC_WORKS_LONGLONG(cc+cflags,[ACTION-YES][,ACTION-NO])
dnl  --------------------------------------------------------------
dnl  Check that cc+cflags accepts "long long".
dnl
dnl  This test is designed to be run repeatedly with different cc+cflags
dnl  selections, so the result is not cached.

AC_DEFUN([GMP_PROG_CC_WORKS_LONGLONG],
[AC_MSG_CHECKING([compiler $1 has long long])
cat >conftest.c <<EOF
long long  foo;
long long  bar () { return foo; }
int main () { return 0; }
EOF
gmp_prog_cc_works=no
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
  gmp_prog_cc_works=yes
else
  echo "failed program was:" >&AC_FD_CC
  cat conftest.c >&AC_FD_CC
fi
rm -f conftest* a.out b.out a.exe a_out.exe
AC_MSG_RESULT($gmp_prog_cc_works)
if test $gmp_prog_cc_works = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_C_TEST_SIZEOF(cc/cflags,test,[ACTION-GOOD][,ACTION-BAD])
dnl  ------------------------------------------------------------
dnl  The given cc/cflags compiler is run to check the size of a type
dnl  specified by the "test" argument.  "test" can either be a string, or a
dnl  variable like $foo.  The value should be for instance "sizeof-long-4",
dnl  to test that sizeof(long)==4.
dnl
dnl  This test is designed to be run for different compiler and/or flags
dnl  combinations, so the result is not cached.
dnl
dnl  The idea for making an array that has a negative size if the desired
dnl  condition test is false comes from autoconf AC_CHECK_SIZEOF.  The cast
dnl  to "long" in the array dimension also follows autoconf, apparently it's
dnl  a workaround for a HP compiler bug.

AC_DEFUN([GMP_C_TEST_SIZEOF],
[echo "configure: testlist $2" >&AC_FD_CC
[gmp_sizeof_type=`echo "$2" | sed 's/sizeof-\([a-z\*]*\).*/\1/'`]
[gmp_sizeof_want=`echo "$2" | sed 's/sizeof-[a-z\*]*-\([0-9]*\).*/\1/'`]
AC_MSG_CHECKING([compiler $1 has sizeof($gmp_sizeof_type)==$gmp_sizeof_want])
cat >conftest.c <<EOF
[int
main ()
{
  static int test_array [1 - 2 * (long) (sizeof ($gmp_sizeof_type) != $gmp_sizeof_want)];
  test_array[0] = 0;
  return 0;
}]
EOF
gmp_c_testlist_sizeof=no
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
  gmp_c_testlist_sizeof=yes
fi
rm -f conftest*
AC_MSG_RESULT($gmp_c_testlist_sizeof)
if test $gmp_c_testlist_sizeof = yes; then
  ifelse([$3],,:,[$3])
else
  ifelse([$4],,:,[$4])
fi
])


dnl  GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
dnl  -------------------------------------------------------
dnl  Determine whether the given compiler is GNU C.
dnl
dnl  This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't
dnl  cache the result.  The same "ifndef" style test is used, to avoid
dnl  problems with syntax checking cpp's used on NeXT and Apple systems.

AC_DEFUN([GMP_PROG_CC_IS_GNU],
[cat >conftest.c <<EOF
#if ! defined (__GNUC__) || defined (__INTEL_COMPILER)
  choke me
#endif
EOF
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
  rm -f conftest*
  AC_MSG_CHECKING([whether $1 is gcc])
  AC_MSG_RESULT(yes)
  ifelse([$2],,:,[$2])
else
  rm -f conftest*
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_PROG_CC_IS_XLC(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
dnl  -------------------------------------------------------
dnl  Determine whether the given compiler is IBM xlc (on AIX).
dnl
dnl  There doesn't seem to be a preprocessor symbol to test for this, or if
dnl  there is one then it's well hidden in xlc 3.1 on AIX 4.3, so just grep
dnl  the man page printed when xlc is invoked with no arguments.

AC_DEFUN([GMP_PROG_CC_IS_XLC],
[gmp_command="$1 2>&1 | grep xlc >/dev/null"
if AC_TRY_EVAL(gmp_command); then
  AC_MSG_CHECKING([whether $1 is xlc])
  AC_MSG_RESULT(yes)
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_PROG_CC_X86_GOT_EAX_EMITTED(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
dnl  ----------------------------------------------------------------------
dnl  Determine whether CC+CFLAGS emits instructions using %eax with
dnl  _GLOBAL_OFFSET_TABLE_.  This test is for use on x86 systems.
dnl
dnl  Recent versions of gcc will use %eax for the GOT in leaf functions, for
dnl  instance gcc 3.3.3 with -O3.  This avoids having to save and restore
dnl  %ebx which otherwise usually holds the GOT, and is what gcc used in the
dnl  past.
dnl
dnl  %ecx and %edx are also candidates for this sort of optimization, and
dnl  are used under lesser optimization levels, like -O2 in 3.3.3.  FIXME:
dnl  It's not quite clear what the conditions for using %eax are, we might
dnl  need more test code to provoke it.
dnl
dnl  The motivation for this test is that past versions of gas have bugs
dnl  affecting this usage, see GMP_ASM_X86_GOT_EAX_OK.
dnl
dnl  This test is not specific to gcc, other compilers might emit %eax GOT
dnl  insns like this, though we've not investigated that.
dnl
dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so we doesn't
dnl  cache the result.
dnl
dnl  -fPIC is hard coded here, because this test is for use before libtool
dnl  has established the pic options.  It's right for gcc, but perhaps not
dnl  other compilers.

AC_DEFUN([GMP_PROG_CC_X86_GOT_EAX_EMITTED],
[echo "Testing gcc GOT with eax emitted" >&AC_FD_CC
cat >conftest.c <<\EOF
[int foo;
int bar () { return foo; }
]EOF
tmp_got_emitted=no
gmp_compile="$1 -fPIC -S conftest.c >&AC_FD_CC 2>&1"
if AC_TRY_EVAL(gmp_compile); then
  if grep "addl.*_GLOBAL_OFFSET_TABLE_.*eax" conftest.s >/dev/null; then
    tmp_got_emitted=yes
  fi
fi
rm -f conftest.*
echo "Result: $tmp_got_emitted" >&AC_FD_CC
if test "$tmp_got_emitted" = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_HPC_HPPA_2_0(cc,[ACTION-IF-GOOD][,ACTION-IF-BAD])
dnl  ---------------------------------------------------------
dnl  Find out whether a HP compiler is good enough to generate hppa 2.0.
dnl
dnl  This test might be repeated for different compilers, so the result is
dnl  not cached.

AC_DEFUN([GMP_HPC_HPPA_2_0],
[AC_MSG_CHECKING([whether HP compiler $1 is good for 64-bits])
# Bad compiler output:
#   ccom: HP92453-01 G.10.32.05 HP C Compiler
# Good compiler output:
#   ccom: HP92453-01 A.10.32.30 HP C Compiler
# Let A.10.32.30 or higher be ok.
echo >conftest.c
gmp_tmp_vs=`$1 $2 -V -c -o conftest.$OBJEXT conftest.c 2>&1 | grep "^ccom:"`
echo "Version string: $gmp_tmp_vs" >&AC_FD_CC
rm conftest*
gmp_tmp_v1=`echo $gmp_tmp_vs | sed 's/.* .\.\([[0-9]]*\).*/\1/'`
gmp_tmp_v2=`echo $gmp_tmp_vs | sed 's/.* .\..*\.\(.*\)\..* HP C.*/\1/'`
gmp_tmp_v3=`echo $gmp_tmp_vs | sed 's/.* .\..*\..*\.\(.*\) HP C.*/\1/'`
echo "Version number: $gmp_tmp_v1.$gmp_tmp_v2.$gmp_tmp_v3" >&AC_FD_CC
if test -z "$gmp_tmp_v1"then
  gmp_hpc_64bit=not-applicable
else
  GMP_COMPARE_GE($gmp_tmp_v1, 10, $gmp_tmp_v2, 32, $gmp_tmp_v3, 30)
  gmp_hpc_64bit=$gmp_compare_ge
fi
AC_MSG_RESULT($gmp_hpc_64bit)
if test $gmp_hpc_64bit = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_GCC_ARM_UMODSI(CC,[ACTIONS-IF-GOOD][,ACTIONS-IF-BAD])
dnl  ---------------------------------------------------------
dnl  gcc 2.95.3 and earlier on arm has a bug in the libgcc __umodsi routine
dnl  making "%" give wrong results for some operands, eg. "0x90000000 % 3".
dnl  We're hoping it'll be fixed in 2.95.4, and we know it'll be fixed in
dnl  gcc 3.
dnl
dnl  There's only a couple of places gmp cares about this, one is the
dnl  size==1 case in mpn/generic/mode1o.c, and this shows up in
dnl  tests/mpz/t-jac.c as a wrong result from mpz_kronecker_ui.

AC_DEFUN([GMP_GCC_ARM_UMODSI],
[AC_MSG_CHECKING([whether ARM gcc unsigned division works])
tmp_version=`$1 --version`
echo "$tmp_version" >&AC_FD_CC
case $tmp_version in
  [2.95 | 2.95.[123]])
    ifelse([$3],,:,[$3])
    gmp_gcc_arm_umodsi_result=["no, gcc 2.95.[0123]"] ;;
  *)
    ifelse([$2],,:,[$2])
    gmp_gcc_arm_umodsi_result=yes ;;
esac
AC_MSG_RESULT([$gmp_gcc_arm_umodsi_result])
])


dnl  GMP_GCC_MIPS_O32(gcc,[actions-yes][,[actions-no]])
dnl  -------------------------------------------------
dnl  Test whether gcc supports o32.
dnl
dnl  gcc 2.7.2.2 only does o32, and doesn't accept -mabi=32.
dnl
dnl  gcc 2.95 accepts -mabi=32 but it only works on irix5, on irix6 it gives
dnl  "cc1: The -mabi=32 support does not work yet".

AC_DEFUN([GMP_GCC_MIPS_O32],
[AC_MSG_CHECKING([whether gcc supports o32])
echo 'int x;' >conftest.c
echo "$1 -mabi=32 -c conftest.c" >&AC_FD_CC
if $1 -mabi=32 -c conftest.c >conftest.out 2>&1; then
  result=yes
else
  cat conftest.out >&AC_FD_CC
  if grep "cc1: Invalid option \`abi=32'" conftest.out >/dev/null; then
    result=yes
  else
    result=no
  fi
fi
rm -f conftest.*
AC_MSG_RESULT($result)
if test $result = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_GCC_NO_CPP_PRECOMP(CCBASE,CC,CFLAGS,[ACTIONS-YES][,ACTIONS-NO])
dnl  -------------------------------------------------------------------
dnl  Check whether -no-cpp-precomp should be used on this compiler, and
dnl  execute the corresponding ACTIONS-YES or ACTIONS-NO.
dnl
dnl  -no-cpp-precomp is only meant for Apple's hacked version of gcc found
dnl  on powerpc*-*-darwin*, but we can give it a try on any gcc.  Normal gcc
dnl  (as of 3.0 at least) only gives a warning, not an actual error, and we
dnl  watch for that and decide against the option in that case, to avoid
dnl  confusing the user.

AC_DEFUN([GMP_GCC_NO_CPP_PRECOMP],
[if test "$ccbase" = gcc; then
  AC_MSG_CHECKING([compiler $2 $3 -no-cpp-precomp])
  result=no
  cat >conftest.c <<EOF
int main () { return 0; }
EOF
  gmp_compile="$2 $3 -no-cpp-precomp conftest.c >conftest.out 2>&1"
  if AC_TRY_EVAL(gmp_compile); then
    if grep "unrecognized option.*-no-cpp-precomp" conftest.out >/dev/null; then : ;
    else
      result=yes
    fi
  fi
  cat conftest.out >&AC_FD_CC
  rm -f conftest* a.out b.out a.exe a_out.exe
  AC_MSG_RESULT($result)
  if test "$result" = yes; then
      ifelse([$4],,:,[$4])
  else
      ifelse([$5],,:,[$5])
  fi
fi
])


dnl  GMP_GCC_PENTIUM4_SSE2(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
dnl  ---------------------------------------------------------------
dnl  Determine whether gcc CC+CFLAGS is a good enough version for
dnl  -march=pentium4 with sse2.
dnl
dnl  Gcc 3.2.1 was seen generating incorrect code for raw double -> int
dnl  conversions through a union.  We believe the problem is in all 3.1 and
dnl  3.2 versions, but that it's fixed in 3.3.

AC_DEFUN([GMP_GCC_PENTIUM4_SSE2],
[AC_MSG_CHECKING([whether gcc is good for sse2])
case `$1 -dumpversion` in
  [3.[012] | 3.[012].*]) result=no ;;
  *)                     result=yes ;;
esac
AC_MSG_RESULT($result)
if test "$result" = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_GCC_WA_MCPU(CC+CFLAGS, NEWFLAG [,ACTION-YES [,ACTION-NO]])
dnl  --------------------------------------------------------------
dnl  Check whether gcc (or gas rather) accepts a flag like "-Wa,-mev67".
dnl
dnl  Gas doesn't give an error for an unknown cpu, it only prints a warning
dnl  like "Warning: Unknown CPU identifier `ev78'".
dnl
dnl  This is intended for use on alpha, since only recent versions of gas
dnl  accept -mev67, but there's nothing here that's alpha specific.

AC_DEFUN([GMP_GCC_WA_MCPU],
[AC_MSG_CHECKING([assembler $1 $2])
result=no
cat >conftest.c <<EOF
int main () {}
EOF
gmp_compile="$1 $2 -c conftest.c >conftest.out 2>&1"
if AC_TRY_EVAL(gmp_compile); then
  if grep "Unknown CPU identifier" conftest.out >/dev/null; then : ;
  else
    result=yes
  fi
fi
cat conftest.out >&AC_FD_CC
rm -f conftest*
AC_MSG_RESULT($result)
if test "$result" = yes; then
  ifelse([$3],,:,[$3])
else
  ifelse([$4],,:,[$4])
fi
])


dnl  GMP_GCC_WA_OLDAS(CC+CFLAGS [,ACTION-YES [,ACTION-NO]])
dnl  ------------------------------------------------------
dnl  Check whether gcc should be run with "-Wa,-oldas".
dnl
dnl  On systems alpha*-*-osf* (or maybe just osf5), apparently there's a
dnl  newish Compaq "as" which doesn't work with the gcc mips-tfile.
dnl  Compiling an empty file with "gcc -c foo.c" produces for instance
dnl
dnl      mips-tfile, /tmp/ccaqUNnF.s:7 Segmentation fault
dnl
dnl  The fix is to pass "-oldas" to that assembler, as noted by
dnl
dnl      http://gcc.gnu.org/install/specific.html#alpha*-dec-osf*
dnl
dnl  The test here tries to compile an empty file, and if that fails but
dnl  adding -Wa,-oldas makes it succeed, then that flag is considered
dnl  necessary.
dnl
dnl  We look for the failing case specifically, since it may not be a good
dnl  idea to use -Wa,-oldas in other circumstances.  For instance gas takes
dnl  "-oldas" to mean the "-o" option and will write a file called "ldas" as
dnl  its output.  Normally gcc puts its own "-o" after any -Wa options, so
dnl  -oldas ends up being harmless, but clearly that's only through good
dnl  luck.
dnl
dnl  This macro is designed for use while probing for a good compiler, and
dnl  so doesn't cache it's result.

AC_DEFUN([GMP_GCC_WA_OLDAS],
[AC_MSG_CHECKING([for $1 -Wa,-oldas])
result=no
cat >conftest.c <<EOF
EOF
echo "with empty conftest.c" >&AC_FD_CC
gmp_compile="$1 -c conftest.c >&AC_FD_CC 2>&1"
if AC_TRY_EVAL(gmp_compile); then : ;
else
  # empty fails
  gmp_compile="$1 -Wa,-oldas -c conftest.c >&AC_FD_CC 2>&1"
  if AC_TRY_EVAL(gmp_compile); then
    # but with -Wa,-oldas it works
    result=yes
  fi
fi
rm -f conftest*
AC_MSG_RESULT($result)
if test "$result" = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_OS_X86_XMM(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
dnl  --------------------------------------------------------
dnl  Determine whether the operating system supports XMM registers.
dnl
dnl  If build==host then a test program is run, executing an SSE2
dnl  instruction using an XMM register.  This will give a SIGILL if the
dnl  system hasn't set the OSFXSR bit in CR4 to say it knows it must use
dnl  fxsave/fxrestor in a context switch (to save xmm registers).
dnl
dnl  If build!=host, we can fallback on:
dnl
dnl      - FreeBSD version 4 is the first supporting xmm.
dnl
dnl      - Linux kernel 2.4 might be the first stable series supporting xmm
dnl        (not sure).  But there's no version number in the GNU/Linux
dnl        config tuple to test anyway.
dnl
dnl  The default is to allow xmm.  This might seem rash, but it's likely
dnl  most systems know xmm by now, so this will normally be what's wanted.
dnl  And cross compiling is a bit hairy anyway, so hopefully anyone doing it
dnl  will be smart enough to know what to do.
dnl
dnl  In the test program, .text and .globl are hard coded because this macro
dnl  is wanted before GMP_ASM_TEXT and GMP_ASM_GLOBL are run.  A .byte
dnl  sequence is used (for xorps %xmm0, %xmm0) to make us independent of
dnl  tests for whether the assembler supports sse2/xmm.  Obviously we need
dnl  both assembler and OS support, but this means we don't force the order
dnl  in which we test.
dnl
dnl  FIXME: Maybe we should use $CCAS to assemble, if it's set. (Would
dnl  still want $CC/$CFLAGS for the link.)  But this test is used before
dnl  AC_PROG_CC sets $OBJEXT, so we'd need to check for various object file
dnl  suffixes ourselves.

AC_DEFUN([GMP_OS_X86_XMM],
[AC_CACHE_CHECK([whether the operating system supports XMM registers],
  gmp_cv_os_x86_xmm,
[if test "$build" = "$host"then
  # remove anything that might look like compiler output to our "||" expression
  rm -f conftest* a.out b.out a.exe a_out.exe
  cat >conftest.s <<EOF
 .text
main:
_main:
 .globl main
 .globl _main
 .byte 0x0f, 0x57, 0xc0
 xorl %eax, %eax
 ret
EOF
  gmp_compile="$1 conftest.s -o conftest >&AC_FD_CC"
  if AC_TRY_EVAL(gmp_compile); then
    if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then
      gmp_cv_os_x86_xmm=yes
    else
      gmp_cv_os_x86_xmm=no
    fi
  else
    AC_MSG_WARN([Oops, cannot compile test program])
  fi
  rm -f conftest*
fi

if test -z "$gmp_cv_os_x86_xmm"then
  case $host_os in
    [freebsd[123] | freebsd[123].*])
      gmp_cv_os_x86_xmm=no ;;
    freebsd*)
      gmp_cv_os_x86_xmm=yes ;;
    *)
      gmp_cv_os_x86_xmm=probably ;;
  esac
fi
])

if test "$gmp_cv_os_x86_xmm" = probably; then
  AC_MSG_WARN([Not certain of OS support for xmm when cross compiling.])
  AC_MSG_WARN([Will assume it's ok, expect a SIGILL if this is wrong.])
fi

case $gmp_cv_os_x86_xmm in
no)
  $3
  ;;
*)
  $2
  ;;
esac
])


dnl  GMP_CRAY_HOST_TYPES(C90/T90-IEEE, C90/T90-CFP, J90/SV1)
dnl  -------------------------------------------------------
dnl  Execute the actions in the arguments on the respective Cray vector
dnl  systems.  For other hosts, do nothing.
dnl
dnl  This macro should be used after the C compiler has been chosen, since
dnl  on c90 and t90 we ask the compiler whether we're in IEEE or CFP float
dnl  mode.
dnl
dnl  This code is in a macro so that any AC_REQUIRE pre-requisites of
dnl  AC_EGREP_CPP will be expanded at the top-level, ie. for all hosts not
dnl  merely c90 and t90.  In autoconf 2.57 for instance this means
dnl  AC_PROG_EGREP, which is needed by various other macros.

AC_DEFUN([GMP_CRAY_OPTIONS],
[case $host_cpu in
  c90 | t90)
    AC_EGREP_CPP(yes,
[#ifdef _CRAYIEEE
yes
#endif],
    [$1],
    [$2])
    ;;
  j90 | sv1)
    [$3]
    ;;
esac
])


dnl  GMP_HPPA_LEVEL_20(cc/cflags [, ACTION-GOOD [,ACTION-BAD]])
dnl  ----------------------------------------------------------
dnl  Check that the given cc/cflags accepts HPPA 2.0n assembler code.
dnl
dnl  Old versions of gas don't know 2.0 instructions. It rejects ".level
dnl  2.0" for a start, so just test that.
dnl
dnl  This test is designed to be run for various different compiler and
dnl  flags combinations, and hence doesn't cache its result.

AC_DEFUN([GMP_HPPA_LEVEL_20],
[AC_MSG_CHECKING([$1 assembler knows hppa 2.0])
result=no
cat >conftest.s <<EOF
 .level 2.0
EOF
gmp_compile="$1 -c conftest.s >&AC_FD_CC 2>&1"
if AC_TRY_EVAL(gmp_compile); then
  result=yes
else
  echo "failed program was" >&AC_FD_CC
  cat conftest.s >&AC_FD_CC
fi
rm -f conftest*
AC_MSG_RESULT($result)
if test "$result" = yes; then
  ifelse([$2],,:,[$2])
else
  ifelse([$3],,:,[$3])
fi
])


dnl  GMP_PROG_CXX_WORKS(cxx/cxxflags [, ACTION-YES [,ACTION-NO]])
dnl  ------------------------------------------------------------
dnl  Check whether cxx/cxxflags can compile and link.
dnl
dnl  This test is designed to be run repeatedly with different cxx/cxxflags
dnl  selections, so the result is not cached.
dnl
dnl  For a native build, we insist on being able to run the program, so as
dnl  to detect any problems with the standard C++ library.  During
dnl  development various systems with broken or incomplete C++ installations
dnl  were seen.
dnl
dnl  The various features and problems we try to detect are done in separate
dnl  compiles.  Although this is probably a bit slower than one test
dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
dnl  hence giving the user a clue about why we rejected the compiler.

AC_DEFUN([GMP_PROG_CXX_WORKS],
[AC_MSG_CHECKING([C++ compiler $1])
gmp_prog_cxx_works=yes

# start with a plain "main()", then go on to further checks
GMP_PROG_CXX_WORKS_PART([$1], [])

GMP_PROG_CXX_WORKS_PART([$1], [namespace],
[namespace foo { }
using namespace foo;
])

# GMP requires the standard C++ iostream classes
GMP_PROG_CXX_WORKS_PART([$1], [std iostream],
[/* This test rejects g++ 2.7.2 which doesn't have , only a
    pre-standard iostream.h. */
#include <iostream>

/* This test rejects OSF 5.1 Compaq C++ in its default pre-standard iostream
   mode, since that mode puts cout in the global namespace, not "std".  */
void someoutput (void) { std::cout << 123; }
])

AC_MSG_RESULT($gmp_prog_cxx_works)
case $gmp_prog_cxx_works in
  yes)
    [$2]
    ;;
  *)
    [$3]
    ;;
esac
])

dnl  Called: GMP_PROG_CXX_WORKS_PART(CXX+CXXFLAGS, FAIL-MESSAGE [,CODE])
dnl
AC_DEFUN([GMP_PROG_CXX_WORKS_PART],
[if test "$gmp_prog_cxx_works" = yes; then
  # remove anything that might look like compiler output to our "||" expression
  rm -f conftest* a.out b.out a.exe a_out.exe
  cat >conftest.cc <<EOF
[$3]
int main (void) { return 0; }
EOF
  echo "Test compile: [$2]" >&AC_FD_CC
  gmp_cxxcompile="$1 conftest.cc >&AC_FD_CC"
  if AC_TRY_EVAL(gmp_cxxcompile); then
    if test "$cross_compiling" = no; then
      if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
      else
        gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2], program does not run"
      fi
    fi
  else
    gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2]"
  fi
  case $gmp_prog_cxx_works in
    no*)
      echo "failed program was:" >&AC_FD_CC
      cat conftest.cc >&AC_FD_CC
      ;;
  esac
  rm -f conftest* a.out b.out a.exe a_out.exe
fi
])


dnl  GMP_INIT([M4-DEF-FILE])
dnl  -----------------------
dnl  Initializations for GMP config.m4 generation.
dnl
dnl  FIXME: The generated config.m4 doesn't get recreated by config.status.
dnl  Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.

AC_DEFUN([GMP_INIT],
[ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
gmp_tmpconfigm4=cnfm4.tmp
gmp_tmpconfigm4i=cnfm4i.tmp
gmp_tmpconfigm4p=cnfm4p.tmp
rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p

# CONFIG_TOP_SRCDIR is a path from the mpn builddir to the top srcdir.
# The pattern here tests for an absolute path the same way as
# _AC_OUTPUT_FILES in autoconf acgeneral.m4.
case $srcdir in
[[\\/]]* | ?:[[\\/]]* )  tmp="$srcdir"    ;;
*)                       tmp="../$srcdir" ;;
esac
echo ["define(,<\`$tmp'>)"] >>$gmp_tmpconfigm4

# All CPUs use asm-defs.m4
echo ["include][(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"] >>$gmp_tmpconfigm4i
])


dnl  GMP_FINISH
dnl  ----------
dnl  Create config.m4 from its accumulated parts.
dnl
dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
dnl  of config.m4 is harmless.
dnl
dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
dnl  fully quoted but are still put under an ifdef in case any have been
dnl  redefined by one of the m4 include files.
dnl
dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
dnl  having a whole file as a macro argument would overflow the string space
dnl  on BSD m4.

AC_DEFUN([GMP_FINISH],
[AC_REQUIRE([GMP_INIT])
echo "creating $gmp_configm4"
echo ["d""nl $gmp_configm4. Generated automatically by configure."] > $gmp_configm4
if test -f $gmp_tmpconfigm4; then
  echo ["changequote(<,>)"] >> $gmp_configm4
  echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
  cat $gmp_tmpconfigm4 >> $gmp_configm4
  echo [">)"] >> $gmp_configm4
  echo ["changequote(\`,')"] >> $gmp_configm4
  rm $gmp_tmpconfigm4
fi
echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
if test -f $gmp_tmpconfigm4i; then
  cat $gmp_tmpconfigm4i >> $gmp_configm4
  rm $gmp_tmpconfigm4i
fi
if test -f $gmp_tmpconfigm4p; then
  cat $gmp_tmpconfigm4p >> $gmp_configm4
  rm $gmp_tmpconfigm4p
fi
echo ["')"] >> $gmp_configm4
echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
])


dnl  GMP_INCLUDE_MPN(FILE)
dnl  ---------------------
dnl  Add an include_mpn(`FILE') to config.m4. FILE should be a path
dnl  relative to the mpn source directory, for example
dnl
dnl      GMP_INCLUDE_MPN(`x86/x86-defs.m4')
dnl

AC_DEFUN([GMP_INCLUDE_MPN],
[AC_REQUIRE([GMP_INIT])
echo ["include_mpn(\`$1')"] >> $gmp_tmpconfigm4i
])


dnl  GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
dnl  ------------------------------------------
dnl  Define M4 macro MACRO as DEFINITION in temporary file.
dnl
dnl  If LOCATION is `POST', the definition will appear after any include()
dnl  directives inserted by GMP_INCLUDE.  Mind the quoting!  No shell
dnl  variables will get expanded.  Don't forget to invoke GMP_FINISH to
dnl  create file config.m4.  config.m4 uses `<' and '>' as quote characters
dnl  for all defines.

AC_DEFUN([GMP_DEFINE],
[AC_REQUIRE([GMP_INIT])
echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
                              $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
])


dnl  GMP_DEFINE_RAW(STRING [, LOCATION])
dnl  ------------------------------------
dnl  Put STRING into config.m4 file.
dnl
dnl  If LOCATION is `POST', the definition will appear after any include()
dnl  directives inserted by GMP_INCLUDE.  Don't forget to invoke GMP_FINISH
dnl  to create file config.m4.

AC_DEFUN([GMP_DEFINE_RAW],
[AC_REQUIRE([GMP_INIT])
echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
])


dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
dnl  ----------------------------------------------------------
dnl  Attempt to assemble the given code.
dnl  Do "action-success" if this succeeds, "action-fail" if not.
dnl
dnl  conftest.o and conftest.out are available for inspection in
dnl  "action-success".  If either action does a "break" out of a loop then
dnl  an explicit "rm -f conftest*" will be necessary.
dnl
dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
dnl  anything in "asm-code", everything wanted must be given explicitly.

AC_DEFUN([GMP_TRY_ASSEMBLE],
[cat >conftest.s <<EOF
[$1]
EOF
gmp_assemble="$CCAS $CFLAGS $CPPFLAGS conftest.s >conftest.out 2>&1"
if AC_TRY_EVAL(gmp_assemble); then
  cat conftest.out >&AC_FD_CC
  ifelse([$2],,:,[$2])
else
  cat conftest.out >&AC_FD_CC
  echo "configure: failed program was:" >&AC_FD_CC
  cat conftest.s >&AC_FD_CC
  ifelse([$3],,:,[$3])
fi
rm -f conftest*
])


dnl Checks whether the stack can be marked nonexecutable by passing an option
dnl to the C-compiler when acting on .s files. Appends that option to ASMFLAGS.
dnl This macro is adapted from one found in GLIBC-2.3.5.
dnl FIXME: This test looks broken. It tests that a file with .note.GNU-stack...
dnl can be compiled/assembled with -Wa,--noexecstack.  It does not determine
dnl if that command-line option has any effect on general asm code.
AC_DEFUN([CL_AS_NOEXECSTACK],[
dnl AC_REQUIRE([AC_PROG_CC]) GMP uses something else
AC_CACHE_CHECK([whether assembler supports --noexecstack option],
cl_cv_as_noexecstack, [dnl
  cat > conftest.c <<EOF
void foo() {}
EOF
  if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
                     -S -o conftest.s conftest.c >/dev/null]) \
     && grep .note.GNU-stack conftest.s >/dev/null \
     && AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wa,--noexecstack
                       -c -o conftest.o conftest.s >/dev/null])
  then
    cl_cv_as_noexecstack=yes
  else
    cl_cv_as_noexecstack=no
  fi
  rm -f conftest*])
  if test "$cl_cv_as_noexecstack" = yes; then
    ASMFLAGS="$ASMFLAGS -Wa,--noexecstack"
  fi
  AC_SUBST(ASMFLAGS)
])


dnl  GMP_ASM_LABEL_SUFFIX
dnl  --------------------
dnl  : - is usual.
dnl  empty - hppa on HP-UX doesn't use a :, just the label name
dnl
dnl  Note that it's necessary to test the empty case first, since HP "as"
dnl  will accept "somelabel:", and take it to mean a label with a name that
dnl  happens to end in a colon.

AC_DEFUN([GMP_ASM_LABEL_SUFFIX],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_CACHE_CHECK([for assembler label suffix],
                gmp_cv_asm_label_suffix,
[gmp_cv_asm_label_suffix=unknown
for i in "" ":"do
  echo "trying $i" >&AC_FD_CC
  GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_text
somelabel$i],
    [gmp_cv_asm_label_suffix=$i
     rm -f conftest*
     break],
    [cat conftest.out >&AC_FD_CC])
done
if test "$gmp_cv_asm_label_suffix" = "unknown"then
  AC_MSG_ERROR([Cannot determine label suffix])
fi
])
echo ["define(, <$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_UNDERSCORE
dnl  ------------------
dnl  Determine whether global symbols need to be prefixed with an underscore.
dnl  The output from "nm" is grepped to see what a typical symbol looks like.
dnl
dnl  This test used to grep the .o file directly, but that failed with greps
dnl  that don't like binary files (eg. SunOS 4).
dnl
dnl  This test also used to construct an assembler file with and without an
dnl  underscore and try to link that to a C file, to see which worked.
dnl  Although that's what will happen in the real build we don't really want
dnl  to depend on creating asm files within configure for every possible CPU
dnl  (or at least we don't want to do that more than we have to).
dnl
dnl  The fallback on no underscore is based on the assumption that the world
dnl  is moving towards non-underscore systems.  There should actually be no
dnl  good reason for nm to fail though.

AC_DEFUN([GMP_ASM_UNDERSCORE],
[AC_REQUIRE([GMP_PROG_NM])
AC_CACHE_CHECK([if globals are prefixed by underscore],
               gmp_cv_asm_underscore,
[gmp_cv_asm_underscore="unknown"
cat >conftest.c <<EOF
int gurkmacka;
EOF
gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
  $NM conftest.$OBJEXT >conftest.out
  if grep "[[ ]]_gurkmacka" conftest.out >/dev/null; then
    gmp_cv_asm_underscore=yes
  elif grep "[[ ]]gurkmacka" conftest.out >/dev/null; then
    gmp_cv_asm_underscore=no
  else
    echo "configure: $NM doesn't have gurkmacka:" >&AC_FD_CC
    cat conftest.out >&AC_FD_CC
  fi
else
  echo "configure: failed program was:" >&AC_FD_CC
  cat conftest.c >&AC_FD_CC
fi
rm -f conftest*
])
case $gmp_cv_asm_underscore in
  yes)
    GMP_DEFINE(GSYM_PREFIX, [_]) ;;
  no)
    GMP_DEFINE(GSYM_PREFIX, []) ;;
  *)
    AC_MSG_WARN([+----------------------------------------------------------])
    AC_MSG_WARN([| Cannot determine global symbol prefix.])
    AC_MSG_WARN([| $NM output doesn't contain a global data symbol.])
    AC_MSG_WARN([| Will proceed with no underscore.])
    AC_MSG_WARN([| If this is wrong then you'll get link errors referring])
    AC_MSG_WARN([| to ___gmpn_add_n (note three underscores).])
    AC_MSG_WARN([| In this case do a fresh build with an override,])
    AC_MSG_WARN([|     ./configure gmp_cv_asm_underscore=yes])
    AC_MSG_WARN([+----------------------------------------------------------])
    GMP_DEFINE(GSYM_PREFIX, [])
    ;;
esac
])


dnl  GMP_ASM_ALIGN_LOG
dnl  -----------------
dnl  Is parameter to `.align' logarithmic?

AC_DEFUN([GMP_ASM_ALIGN_LOG],
[AC_REQUIRE([GMP_ASM_GLOBL])
AC_REQUIRE([GMP_ASM_BYTE])
AC_REQUIRE([GMP_ASM_DATA])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_REQUIRE([GMP_PROG_NM])
AC_CACHE_CHECK([if .align assembly directive is logarithmic],
               gmp_cv_asm_align_log,
[GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_data
 .align  4
 $gmp_cv_asm_globl foo
 $gmp_cv_asm_byte 1
 .align 4
foo$gmp_cv_asm_label_suffix
 $gmp_cv_asm_byte 2],
  [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
     sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
  if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"then
    gmp_cv_asm_align_log=yes
  else
    gmp_cv_asm_align_log=no
  fi],
  [AC_MSG_ERROR([cannot assemble alignment test])])])

GMP_DEFINE_RAW(["define(,<$gmp_cv_asm_align_log>)"])
])


dnl  GMP_ASM_ALIGN_FILL_0x90
dnl  -----------------------
dnl  Determine whether a ",0x90" suffix works on a .align directive.
dnl  This is only meant for use on x86, 0x90 being a "nop".
dnl
dnl  Old gas, eg. 1.92.3
dnl       Needs ",0x90" or else the fill is 0x00, which can't be executed
dnl       across.
dnl
dnl  New gas, eg. 2.91
dnl       Generates multi-byte nop fills even when ",0x90" is given.
dnl
dnl  Solaris 2.6 as
dnl       ",0x90" is not allowed, causes a fatal error.
dnl
dnl  Solaris 2.8 as
dnl       ",0x90" does nothing, generates a warning that it's being ignored.
dnl
dnl  SCO OpenServer 5 as
dnl       Second parameter is max bytes to fill, not a fill pattern.
dnl       ",0x90" is an error due to being bigger than the first parameter.
dnl       Multi-byte nop fills are generated in text segments.
dnl
dnl  Note that both solaris "as"s only care about ",0x90" if they actually
dnl  have to use it to fill something, hence the .byte in the test.  It's
dnl  the second .align which provokes the error or warning.
dnl
dnl  The warning from solaris 2.8 is suppressed to stop anyone worrying that
dnl  something might be wrong.

AC_DEFUN([GMP_ASM_ALIGN_FILL_0x90],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
               gmp_cv_asm_align_fill_0x90,
[GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_text
 .align  4, 0x90
 .byte   0
 .align  4, 0x90],
[if grep "Warning: Fill parameter ignored for executable section" conftest.out >/dev/null; then
  echo "Suppressing this warning by omitting 0x90" 1>&AC_FD_CC
  gmp_cv_asm_align_fill_0x90=no
else
  gmp_cv_asm_align_fill_0x90=yes
fi],
[gmp_cv_asm_align_fill_0x90=no])])

GMP_DEFINE_RAW(["define(,<$gmp_cv_asm_align_fill_0x90>)"])
])


dnl  GMP_ASM_BYTE
dnl  ------------
dnl  .byte - is usual.
dnl  data1 - required by ia64 (on hpux at least).
dnl
dnl  This macro is just to support other configure tests, not any actual asm
dnl  code.

AC_DEFUN([GMP_ASM_BYTE],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_CACHE_CHECK([for assembler byte directive],
                gmp_cv_asm_byte,
[for i in .byte data1; do
  echo "trying $i" >&AC_FD_CC
  GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_data
 $i 0
],
    [gmp_cv_asm_byte=$i
     rm -f conftest*
     break],
    [cat conftest.out >&AC_FD_CC])
done
if test -z "$gmp_cv_asm_byte"then
  AC_MSG_ERROR([Cannot determine how to emit a data byte])
fi
])
])


dnl  GMP_ASM_TEXT
dnl  ------------
dnl  .text - is usual.
dnl  .code - is needed by the hppa on HP-UX (but ia64 HP-UX uses .text)
dnl  .csect .text[PR] - is for AIX.

AC_DEFUN([GMP_ASM_TEXT],
[AC_CACHE_CHECK([how to switch to text section],
                gmp_cv_asm_text,
[for i in ".text" ".code" [".csect .text[PR]"]; do
  echo "trying $i" >&AC_FD_CC
  GMP_TRY_ASSEMBLE([ $i],
    [gmp_cv_asm_text=$i
     rm -f conftest*
     break])
done
if test -z "$gmp_cv_asm_text"then
  AC_MSG_ERROR([Cannot determine text section directive])
fi
])
echo ["define(, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_DATA
dnl  ------------
dnl  Can we say `.data'?

AC_DEFUN([GMP_ASM_DATA],
[AC_CACHE_CHECK([how to switch to data section],
                gmp_cv_asm_data,
[case $host in
  *-*-aix*) gmp_cv_asm_data=[".csect .data[RW]"] ;;
  *)        gmp_cv_asm_data=".data" ;;
esac
])
echo ["define(, <$gmp_cv_asm_data>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_RODATA
dnl  --------------
dnl  Find out how to switch to the read-only data section.
dnl
dnl  The compiler output is grepped for the right directive.  It's not
dnl  considered wise to just probe for ".section .rodata" or whatever works,
dnl  since arbitrary section names might be accepted, but not necessarily do
dnl  the right thing when they get to the linker.
dnl
dnl  Only a few asm files use RODATA, so this code is perhaps a bit
dnl  excessive right now, but should find more uses in the future.
dnl
dnl  FIXME: gcc on aix generates something like ".csect _foo.ro_c[RO],3"
dnl  where foo is the object file.  Might need to check for that if we use
dnl  RODATA there.

AC_DEFUN([GMP_ASM_RODATA],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_REQUIRE([GMP_ASM_DATA])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_REQUIRE([GMP_ASM_UNDERSCORE])
AC_CACHE_CHECK([how to switch to read-only data section],
               gmp_cv_asm_rodata,
[
dnl Default to DATA on CPUs with split code/data caching, and TEXT
dnl elsewhere.  i386 means generic x86, so use DATA on it.
case $host in
X86_PATTERN | x86_64-*-*)
  gmp_cv_asm_rodata="$gmp_cv_asm_data" ;;
*)
  gmp_cv_asm_rodata="$gmp_cv_asm_text" ;;
esac

cat >conftest.c <<EOF
extern const int foo[[]];  /* Suppresses C++'s suppression of foo */
const int foo[[]] = {1,2,3};
EOF
echo "Test program:" >&AC_FD_CC
cat conftest.c >&AC_FD_CC
gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
  echo "Compiler output:" >&AC_FD_CC
  cat conftest.s >&AC_FD_CC
  if test $gmp_cv_asm_underscore = yes; then
    tmp_gsym_prefix=_
  else
    tmp_gsym_prefix=
  fi
  # must see our label
  if grep "^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" conftest.s >/dev/null 2>&AC_FD_CC; then
    # take the last directive before our label (hence skipping segments
    # getting debugging info etc)
    tmp_match=`sed -n ["/^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix/q
                        /^[.  ]*data/p
                        /^[.  ]*rdata/p
                        /^[.  ]*text/p
                        /^[.  ]*section/p
                        /^[.  ]*csect/p
                        /^[.  ]*CSECT/p"] conftest.s | sed -n '$p'`
    echo "Match: $tmp_match" >&AC_FD_CC
    if test -n "$tmp_match"then
      gmp_cv_asm_rodata=$tmp_match
    fi
  else
    echo "Couldn't find label: ^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" >&AC_FD_CC
  fi
fi
rm -f conftest*
])
echo ["define(, <$gmp_cv_asm_rodata>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_GLOBL
dnl  -------------
dnl  The assembler directive to mark a label as a global symbol.
dnl
dnl  ia64 - .global is standard, according to the Intel documentation.
dnl
dnl  hppa - ".export foo,entry" is demanded by HP hppa "as".  ".global" is a
dnl      kind of import.
dnl
dnl  other - .globl is usual.
dnl
dnl  "gas" tends to accept .globl everywhere, in addition to .export or
dnl  .global or whatever the system assembler demands.

AC_DEFUN([GMP_ASM_GLOBL],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_CACHE_CHECK([for assembler global directive],
                gmp_cv_asm_globl,
[case $host in
  hppa*-*-*)     gmp_cv_asm_globl=.export ;;
  IA64_PATTERN)  gmp_cv_asm_globl=.global ;;
  *)             gmp_cv_asm_globl=.globl  ;;
esac
])
echo ["define(, <$gmp_cv_asm_globl>)"] >> $gmp_tmpconfigm4
])


dnl  GMP_ASM_GLOBL_ATTR
dnl  ------------------
dnl  Do we need something after `GLOBL symbol'?

AC_DEFUN([GMP_ASM_GLOBL_ATTR],
[AC_REQUIRE([GMP_ASM_GLOBL])
AC_CACHE_CHECK([for assembler global directive attribute],
                gmp_cv_asm_globl_attr,
[case $gmp_cv_asm_globl in
--> --------------------

--> maximum size reached

--> --------------------

89%


¤ Dauer der Verarbeitung: 0.114 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung ist noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge