Blame acinclude.m4

Packit 5c3484
dnl  GMP specific autoconf macros
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  Copyright 2000-2006, 2009, 2011, 2013-2015 Free Software Foundation, Inc.
Packit 5c3484
dnl
Packit 5c3484
dnl  This file is part of the GNU MP Library.
Packit 5c3484
dnl
Packit 5c3484
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
Packit 5c3484
dnl  it under the terms of either:
Packit 5c3484
dnl
Packit 5c3484
dnl    * the GNU Lesser General Public License as published by the Free
Packit 5c3484
dnl      Software Foundation; either version 3 of the License, or (at your
Packit 5c3484
dnl      option) any later version.
Packit 5c3484
dnl
Packit 5c3484
dnl  or
Packit 5c3484
dnl
Packit 5c3484
dnl    * the GNU General Public License as published by the Free Software
Packit 5c3484
dnl      Foundation; either version 2 of the License, or (at your option) any
Packit 5c3484
dnl      later version.
Packit 5c3484
dnl
Packit 5c3484
dnl  or both in parallel, as here.
Packit 5c3484
dnl
Packit 5c3484
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
Packit 5c3484
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit 5c3484
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit 5c3484
dnl  for more details.
Packit 5c3484
dnl
Packit 5c3484
dnl  You should have received copies of the GNU General Public License and the
Packit 5c3484
dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
Packit 5c3484
dnl  see https://www.gnu.org/licenses/.
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  Some tests use, or must delete, the default compiler output.  The
Packit 5c3484
dnl  possible filenames are based on what autoconf looks for, namely
Packit 5c3484
dnl
Packit 5c3484
dnl    a.out - normal unix style
Packit 5c3484
dnl    b.out - i960 systems, including gcc there
Packit 5c3484
dnl    a.exe - djgpp
Packit 5c3484
dnl    a_out.exe - OpenVMS DEC C called via GNV wrapper (gnv.sourceforge.net)
Packit 5c3484
dnl    conftest.exe - various DOS compilers
Packit 5c3484
Packit 5c3484
Packit 5c3484
define(IA64_PATTERN,
Packit 5c3484
[[ia64*-*-* | itanium-*-* | itanium2-*-*]])
Packit 5c3484
Packit 5c3484
dnl  Need to be careful not to match m6811, m6812, m68hc11 and m68hc12, all
Packit 5c3484
dnl  of which config.sub accepts.  (Though none of which are likely to work
Packit 5c3484
dnl  with GMP.)
Packit 5c3484
dnl
Packit 5c3484
define(M68K_PATTERN,
Packit 5c3484
[[m68k-*-* | m68[0-9][0-9][0-9]-*-*]])
Packit 5c3484
Packit 5c3484
define(POWERPC64_PATTERN,
Packit 5c3484
[[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-* | powerpc970-*-* | power[3-9]-*-*]])
Packit 5c3484
Packit 5c3484
define(S390_PATTERN,
Packit 5c3484
[[s390-*-* | z900esa-*-* | z990esa-*-* | z9esa-*-* | z10esa-*-* | z196esa-*-*]])
Packit 5c3484
Packit 5c3484
define(S390X_PATTERN,
Packit 5c3484
[[s390x-*-* | z900-*-* | z990-*-* | z9-*-* | z10-*-* | z196-*-*]])
Packit 5c3484
Packit 5c3484
define(X86_PATTERN,
Packit 5c3484
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])
Packit 5c3484
Packit 5c3484
define(X86_64_PATTERN,
Packit 5c3484
[[athlon64-*-* | k8-*-* | k10-*-* | bobcat-*-* | jaguar*-*-* | bulldozer*-*-* | piledriver*-*-* | steamroller*-*-* | excavator*-*-* | pentium4-*-* | atom-*-* | silvermont-*-* | goldmont-*-* | core2-*-* | corei*-*-* | x86_64-*-* | nano-*-* | nehalem*-*-* | westmere*-*-* | sandybridge*-*-* | ivybridge*-*-* | haswell*-*-* | broadwell*-*-* | skylake*-*-* | kabylake*-*-*]])
Packit 5c3484
Packit 5c3484
dnl  GMP_FAT_SUFFIX(DSTVAR, DIRECTORY)
Packit 5c3484
dnl  ---------------------------------
Packit 5c3484
dnl  Emit code to set shell variable DSTVAR to the suffix for a fat binary
Packit 5c3484
dnl  routine from DIRECTORY.  DIRECTORY can be a shell expression like $foo
Packit 5c3484
dnl  etc.
Packit 5c3484
dnl
Packit 5c3484
dnl  The suffix is directory separators / or \ changed to underscores, and
Packit 5c3484
dnl  if there's more than one directory part, then the first is dropped.
Packit 5c3484
dnl
Packit 5c3484
dnl  For instance,
Packit 5c3484
dnl
Packit 5c3484
dnl      x86         ->  x86
Packit 5c3484
dnl      x86/k6      ->  k6
Packit 5c3484
dnl      x86/k6/mmx  ->  k6_mmx
Packit 5c3484
Packit 5c3484
define(GMP_FAT_SUFFIX,
Packit 5c3484
[[$1=`echo $2 | sed -e '/\//s:^[^/]*/::' -e 's:[\\/]:_:g'`]])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_REMOVE_FROM_LIST(listvar,item)
Packit 5c3484
dnl  ----------------------------------
Packit 5c3484
dnl  Emit code to remove any occurrence of ITEM from $LISTVAR.  ITEM can be a
Packit 5c3484
dnl  shell expression like $foo if desired.
Packit 5c3484
Packit 5c3484
define(GMP_REMOVE_FROM_LIST,
Packit 5c3484
[remove_from_list_tmp=
Packit 5c3484
for remove_from_list_i in $[][$1]; do
Packit 5c3484
  if test $remove_from_list_i = [$2]; then :;
Packit 5c3484
  else
Packit 5c3484
     remove_from_list_tmp="$remove_from_list_tmp $remove_from_list_i"
Packit 5c3484
  fi
Packit 5c3484
done
Packit 5c3484
[$1]=$remove_from_list_tmp
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_STRIP_PATH(subdir)
Packit 5c3484
dnl  ----------------------
Packit 5c3484
dnl  Strip entries */subdir from $path and $fat_path.
Packit 5c3484
Packit 5c3484
define(GMP_STRIP_PATH,
Packit 5c3484
[GMP_STRIP_PATH_VAR(path, [$1])
Packit 5c3484
GMP_STRIP_PATH_VAR(fat_path, [$1])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
define(GMP_STRIP_PATH_VAR,
Packit 5c3484
[tmp_path=
Packit 5c3484
for i in $[][$1]; do
Packit 5c3484
  case $i in
Packit 5c3484
    */[$2]) ;;
Packit 5c3484
    *) tmp_path="$tmp_path $i" ;;
Packit 5c3484
  esac
Packit 5c3484
done
Packit 5c3484
[$1]="$tmp_path"
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_INCLUDE_GMP_H
Packit 5c3484
dnl  -----------------
Packit 5c3484
dnl  Expand to the right way to #include gmp-h.in.  This must be used
Packit 5c3484
dnl  instead of gmp.h, since that file isn't generated until the end of the
Packit 5c3484
dnl  configure.
Packit 5c3484
dnl
Packit 5c3484
dnl  Dummy value for GMP_LIMB_BITS is enough
Packit 5c3484
dnl  for all current configure-time uses of gmp.h.
Packit 5c3484
Packit 5c3484
define(GMP_INCLUDE_GMP_H,
Packit 5c3484
[[#define __GMP_WITHIN_CONFIGURE 1   /* ignore template stuff */
Packit 5c3484
#define GMP_NAIL_BITS $GMP_NAIL_BITS
Packit 5c3484
#define GMP_LIMB_BITS 123
Packit 5c3484
$DEFN_LONG_LONG_LIMB
Packit 5c3484
#include "$srcdir/gmp-h.in"]
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_HEADER_GETVAL(NAME,FILE)
Packit 5c3484
dnl  ----------------------------
Packit 5c3484
dnl  Expand at autoconf time to the value of a "#define NAME" from the given
Packit 5c3484
dnl  FILE.  The regexps here aren't very rugged, but are enough for gmp.
Packit 5c3484
dnl  /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
Packit 5c3484
Packit 5c3484
define(GMP_HEADER_GETVAL,
Packit 5c3484
[patsubst(patsubst(
Packit 5c3484
esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
Packit 5c3484
[^.*$1[ 	]+],[]),
Packit 5c3484
[[
Packit 5c3484
 	]*$],[])])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_VERSION
Packit 5c3484
dnl  -----------
Packit 5c3484
dnl  The gmp version number, extracted from the #defines in gmp-h.in at
Packit 5c3484
dnl  autoconf time.  Two digits like 3.0 if patchlevel <= 0, or three digits
Packit 5c3484
dnl  like 3.0.1 if patchlevel > 0.
Packit 5c3484
Packit 5c3484
define(GMP_VERSION,
Packit 5c3484
[GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl
Packit 5c3484
.GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl
Packit 5c3484
.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_SUBST_CHECK_FUNCS(func,...)
Packit 5c3484
dnl  ------------------------------
Packit 5c3484
dnl  Setup an AC_SUBST of HAVE_FUNC_01 for each argument.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_SUBST_CHECK_FUNCS],
Packit 5c3484
[m4_if([$1],,,
Packit 5c3484
[_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01)
Packit 5c3484
GMP_SUBST_CHECK_FUNCS(m4_shift($@))])])
Packit 5c3484
Packit 5c3484
dnl  Called: _GMP_SUBST_CHECK_FUNCS(cachevar,substvar)
Packit 5c3484
AC_DEFUN([_GMP_SUBST_CHECK_FUNCS],
Packit 5c3484
[case $[$1] in
Packit 5c3484
yes) AC_SUBST([$2],1) ;;
Packit 5c3484
no)  [$2]=0 ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_SUBST_CHECK_HEADERS(foo.h,...)
Packit 5c3484
dnl  ----------------------------------
Packit 5c3484
dnl  Setup an AC_SUBST of HAVE_FOO_H_01 for each argument.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_SUBST_CHECK_HEADERS],
Packit 5c3484
[m4_if([$1],,,
Packit 5c3484
[_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]),
Packit 5c3484
HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01)
Packit 5c3484
GMP_SUBST_CHECK_HEADERS(m4_shift($@))])])
Packit 5c3484
Packit 5c3484
dnl  Called: _GMP_SUBST_CHECK_HEADERS(cachevar,substvar)
Packit 5c3484
AC_DEFUN([_GMP_SUBST_CHECK_HEADERS],
Packit 5c3484
[case $[$1] in
Packit 5c3484
yes) AC_SUBST([$2],1) ;;
Packit 5c3484
no)  [$2]=0 ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_COMPARE_GE(A1,B1, A2,B2, ...)
Packit 5c3484
dnl  ---------------------------------
Packit 5c3484
dnl  Compare two version numbers A1.A2.etc and B1.B2.etc.  Set
Packit 5c3484
dnl  $gmp_compare_ge to yes or no according to the result.  The A parts
Packit 5c3484
dnl  should be variables, the B parts fixed numbers.  As many parts as
Packit 5c3484
dnl  desired can be included.  An empty string in an A part is taken to be
Packit 5c3484
dnl  zero, the B parts should be non-empty and non-zero.
Packit 5c3484
dnl
Packit 5c3484
dnl  For example,
Packit 5c3484
dnl
Packit 5c3484
dnl      GMP_COMPARE($major,10, $minor,3, $subminor,1)
Packit 5c3484
dnl
Packit 5c3484
dnl  would test whether $major.$minor.$subminor is greater than or equal to
Packit 5c3484
dnl  10.3.1.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_COMPARE_GE],
Packit 5c3484
[gmp_compare_ge=no
Packit 5c3484
GMP_COMPARE_GE_INTERNAL($@)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_COMPARE_GE_INTERNAL],
Packit 5c3484
[ifelse(len([$3]),0,
Packit 5c3484
[if test -n "$1" && test "$1" -ge $2; then
Packit 5c3484
  gmp_compare_ge=yes
Packit 5c3484
fi],
Packit 5c3484
[if test -n "$1"; then
Packit 5c3484
  if test "$1" -gt $2; then
Packit 5c3484
    gmp_compare_ge=yes
Packit 5c3484
  else
Packit 5c3484
    if test "$1" -eq $2; then
Packit 5c3484
      GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@)))
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
fi])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_AR
Packit 5c3484
dnl  -----------
Packit 5c3484
dnl  GMP additions to $AR.
Packit 5c3484
dnl
Packit 5c3484
dnl  A cross-"ar" may be necessary when cross-compiling since the build
Packit 5c3484
dnl  system "ar" might try to interpret the object files to build a symbol
Packit 5c3484
dnl  table index, hence the use of AC_CHECK_TOOL.
Packit 5c3484
dnl
Packit 5c3484
dnl  A user-selected $AR is always left unchanged.  AC_CHECK_TOOL is still
Packit 5c3484
dnl  run to get the "checking" message printed though.
Packit 5c3484
dnl
Packit 5c3484
dnl  If extra flags are added to AR, then ac_cv_prog_AR and
Packit 5c3484
dnl  ac_cv_prog_ac_ct_AR are set too, since libtool (cvs 2003-03-31 at
Packit 5c3484
dnl  least) will do an AC_CHECK_TOOL and that will AR from one of those two
Packit 5c3484
dnl  cached variables.  (ac_cv_prog_AR is used if there's an ac_tool_prefix,
Packit 5c3484
dnl  or ac_cv_prog_ac_ct_AR is used otherwise.)  FIXME: This is highly
Packit 5c3484
dnl  dependent on autoconf internals, perhaps it'd work to put our extra
Packit 5c3484
dnl  flags into AR_FLAGS instead.
Packit 5c3484
dnl
Packit 5c3484
dnl  $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru".  The
Packit 5c3484
dnl  latter fails when libtool goes into piecewise mode and is unlucky
Packit 5c3484
dnl  enough to have two same-named objects in separate pieces, as happens
Packit 5c3484
dnl  for instance to random.o (and others) on vax-dec-ultrix4.5.  Naturally
Packit 5c3484
dnl  a user-selected $AR_FLAGS is left unchanged.
Packit 5c3484
dnl
Packit 5c3484
dnl  For reference, $ARFLAGS is used by automake (1.8) for its ".a" archive
Packit 5c3484
dnl  file rules.  This doesn't get used by the piecewise linking, so we
Packit 5c3484
dnl  leave it at the default "cru".
Packit 5c3484
dnl
Packit 5c3484
dnl  FIXME: Libtool 1.5.2 has its own arrangements for "cq", but that version
Packit 5c3484
dnl  is broken in other ways.  When we can upgrade, remove the forcible
Packit 5c3484
dnl  AR_FLAGS=cq.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_AR],
Packit 5c3484
[dnl  Want to establish $AR before libtool initialization.
Packit 5c3484
AC_BEFORE([$0],[AC_PROG_LIBTOOL])
Packit 5c3484
gmp_user_AR=$AR
Packit 5c3484
AC_CHECK_TOOL(AR, ar, ar)
Packit 5c3484
if test -z "$gmp_user_AR"; then
Packit 5c3484
                        eval arflags=\"\$ar${abi1}_flags\"
Packit 5c3484
  test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\"
Packit 5c3484
  if test -n "$arflags"; then
Packit 5c3484
    AC_MSG_CHECKING([for extra ar flags])
Packit 5c3484
    AR="$AR $arflags"
Packit 5c3484
    ac_cv_prog_AR="$AR $arflags"
Packit 5c3484
    ac_cv_prog_ac_ct_AR="$AR $arflags"
Packit 5c3484
    AC_MSG_RESULT([$arflags])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
if test -z "$AR_FLAGS"; then
Packit 5c3484
  AR_FLAGS=cq
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_M4
Packit 5c3484
dnl  -----------
Packit 5c3484
dnl  Find a working m4, either in $PATH or likely locations, and setup $M4
Packit 5c3484
dnl  and an AC_SUBST accordingly.  If $M4 is already set then it's a user
Packit 5c3484
dnl  choice and is accepted with no checks.  GMP_PROG_M4 is like
Packit 5c3484
dnl  AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
Packit 5c3484
dnl  good enough.
Packit 5c3484
dnl
Packit 5c3484
dnl  See mpn/asm-defs.m4 for details on the known bad m4s.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_M4],
Packit 5c3484
[AC_ARG_VAR(M4,[m4 macro processor])
Packit 5c3484
AC_CACHE_CHECK([for suitable m4],
Packit 5c3484
                gmp_cv_prog_m4,
Packit 5c3484
[if test -n "$M4"; then
Packit 5c3484
  gmp_cv_prog_m4="$M4"
Packit 5c3484
else
Packit 5c3484
  cat >conftest.m4 <<\EOF
Packit 5c3484
dnl  Must protect this against being expanded during autoconf m4!
Packit 5c3484
dnl  Dont put "dnl"s in this as autoconf will flag an error for unexpanded
Packit 5c3484
dnl  macros.
Packit 5c3484
[define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
Packit 5c3484
``bad: $][# not supported (SunOS /usr/bin/m4)
Packit 5c3484
'')ifelse(eval(89),89,`define(t2,Y)',
Packit 5c3484
`bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
Packit 5c3484
')ifelse(eval(9,9),10,`define(t3,Y)',
Packit 5c3484
`bad: eval() doesnt support radix in eval (FreeBSD 8.x,9.0,9.1,9.2 m4)
Packit 5c3484
')ifelse(t1`'t2`'t3,YYY,`good
Packit 5c3484
')]
Packit 5c3484
EOF
Packit 5c3484
dnl ' <- balance the quotes for emacs sh-mode
Packit 5c3484
  echo "trying m4" >&AC_FD_CC
Packit 5c3484
  gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
Packit 5c3484
  echo "$gmp_tmp_val" >&AC_FD_CC
Packit 5c3484
  if test "$gmp_tmp_val" = good; then
Packit 5c3484
    gmp_cv_prog_m4="m4"
Packit 5c3484
  else
Packit 5c3484
    IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
Packit 5c3484
dnl $ac_dummy forces splitting on constant user-supplied paths.
Packit 5c3484
dnl POSIX.2 word splitting is done only on the output of word expansions,
Packit 5c3484
dnl not every word.  This closes a longstanding sh security hole.
Packit 5c3484
    ac_dummy="$PATH:/usr/5bin"
Packit 5c3484
    for ac_dir in $ac_dummy; do
Packit 5c3484
      test -z "$ac_dir" && ac_dir=.
Packit 5c3484
      echo "trying $ac_dir/m4" >&AC_FD_CC
Packit 5c3484
      gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
Packit 5c3484
      echo "$gmp_tmp_val" >&AC_FD_CC
Packit 5c3484
      if test "$gmp_tmp_val" = good; then
Packit 5c3484
        gmp_cv_prog_m4="$ac_dir/m4"
Packit 5c3484
        break
Packit 5c3484
      fi
Packit 5c3484
    done
Packit 5c3484
    IFS="$ac_save_ifs"
Packit 5c3484
    if test -z "$gmp_cv_prog_m4"; then
Packit 5c3484
      AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
  rm -f conftest.m4
Packit 5c3484
fi])
Packit 5c3484
M4="$gmp_cv_prog_m4"
Packit 5c3484
AC_SUBST(M4)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_M4_M4WRAP_SPURIOUS
Packit 5c3484
dnl  ----------------------
Packit 5c3484
dnl  Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4.
Packit 5c3484
dnl
Packit 5c3484
dnl  The following systems have been seen with the problem.
Packit 5c3484
dnl
Packit 5c3484
dnl  - Unicos alpha, but its assembler doesn't seem to mind.
Packit 5c3484
dnl  - MacOS X Darwin, its assembler fails.
Packit 5c3484
dnl  - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores
Packit 5c3484
dnl    the bad last line since it doesn't have a newline.
Packit 5c3484
dnl  - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind.
Packit 5c3484
dnl  - HP-UX ia64.
Packit 5c3484
dnl
Packit 5c3484
dnl  Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer
Packit 5c3484
dnl  an m4 with a working m4wrap, if it can be found.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_M4_M4WRAP_SPURIOUS],
Packit 5c3484
[AC_REQUIRE([GMP_PROG_M4])
Packit 5c3484
AC_CACHE_CHECK([if m4wrap produces spurious output],
Packit 5c3484
               gmp_cv_m4_m4wrap_spurious,
Packit 5c3484
[# hide the d-n-l from autoconf's error checking
Packit 5c3484
tmp_d_n_l=d""nl
Packit 5c3484
cat >conftest.m4 <
Packit 5c3484
[changequote({,})define(x,)m4wrap({x})$tmp_d_n_l]
Packit 5c3484
EOF
Packit 5c3484
echo test input is >&AC_FD_CC
Packit 5c3484
cat conftest.m4 >&AC_FD_CC
Packit 5c3484
tmp_chars=`$M4 conftest.m4 | wc -c`
Packit 5c3484
echo produces $tmp_chars chars output >&AC_FD_CC
Packit 5c3484
rm -f conftest.m4
Packit 5c3484
if test $tmp_chars = 0; then
Packit 5c3484
  gmp_cv_m4_m4wrap_spurious=no
Packit 5c3484
else
Packit 5c3484
  gmp_cv_m4_m4wrap_spurious=yes
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
GMP_DEFINE_RAW(["define(<M4WRAP_SPURIOUS>,<$gmp_cv_m4_m4wrap_spurious>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_NM
Packit 5c3484
dnl  -----------
Packit 5c3484
dnl  GMP additions to libtool AC_PROG_NM.
Packit 5c3484
dnl
Packit 5c3484
dnl  Note that if AC_PROG_NM can't find a working nm it still leaves
Packit 5c3484
dnl  $NM set to "nm", so $NM can't be assumed to actually work.
Packit 5c3484
dnl
Packit 5c3484
dnl  A user-selected $NM is always left unchanged.  AC_PROG_NM is still run
Packit 5c3484
dnl  to get the "checking" message printed though.
Packit 5c3484
dnl
Packit 5c3484
dnl  Perhaps it'd be worthwhile checking that nm works, by running it on an
Packit 5c3484
dnl  actual object file.  For instance on sparcv9 solaris old versions of
Packit 5c3484
dnl  GNU nm don't recognise 64-bit objects.  Checking would give a better
Packit 5c3484
dnl  error message than just a failure in later tests like GMP_ASM_W32 etc.
Packit 5c3484
dnl
Packit 5c3484
dnl  On the other hand it's not really normal autoconf practice to take too
Packit 5c3484
dnl  much trouble over detecting a broken set of tools.  And libtool doesn't
Packit 5c3484
dnl  do anything at all for say ranlib or strip.  So for now we're inclined
Packit 5c3484
dnl  to just demand that the user provides a coherent environment.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_NM],
Packit 5c3484
[dnl  Make sure we're the first to call AC_PROG_NM, so our extra flags are
Packit 5c3484
dnl   used by everyone.
Packit 5c3484
AC_BEFORE([$0],[AC_PROG_NM])
Packit 5c3484
gmp_user_NM=$NM
Packit 5c3484
AC_PROG_NM
Packit 5c3484
Packit 5c3484
# FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool
Packit 5c3484
# defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found.  In this
Packit 5c3484
# case run it again to try the native "nm", firstly so that likely locations
Packit 5c3484
# are searched, secondly so that -B or -p are added if necessary for BSD
Packit 5c3484
# format.  This is necessary for instance on OSF with "./configure
Packit 5c3484
# --build=alphaev5-dec-osf --host=alphaev6-dec-osf".
Packit 5c3484
#
Packit 5c3484
if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then
Packit 5c3484
  $as_unset lt_cv_path_NM
Packit 5c3484
  gmp_save_ac_tool_prefix=$ac_tool_prefix
Packit 5c3484
  ac_tool_prefix=
Packit 5c3484
  NM=
Packit 5c3484
  AC_PROG_NM
Packit 5c3484
  ac_tool_prefix=$gmp_save_ac_tool_prefix
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
if test -z "$gmp_user_NM"; then
Packit 5c3484
                        eval nmflags=\"\$nm${abi1}_flags\"
Packit 5c3484
  test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\"
Packit 5c3484
  if test -n "$nmflags"; then
Packit 5c3484
    AC_MSG_CHECKING([for extra nm flags])
Packit 5c3484
    NM="$NM $nmflags"
Packit 5c3484
    AC_MSG_RESULT([$nmflags])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS])
Packit 5c3484
dnl  --------------------------------------------------------------------
Packit 5c3484
dnl  Check if cc+cflags can compile and link.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is designed to be run repeatedly with different cc+cflags
Packit 5c3484
dnl  selections, so the result is not cached.
Packit 5c3484
dnl
Packit 5c3484
dnl  For a native build, meaning $cross_compiling == no, we require that the
Packit 5c3484
dnl  generated program will run.  This is the same as AC_PROG_CC does in
Packit 5c3484
dnl  _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass
Packit 5c3484
dnl  a CC/CFLAGS combination that it rejects.
Packit 5c3484
dnl
Packit 5c3484
dnl  sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel
Packit 5c3484
dnl  was booted in 32-bit mode.  The effect of requiring the compiler output
Packit 5c3484
dnl  will run is that a plain native "./configure" falls back on ABI=32, but
Packit 5c3484
dnl  ABI=64 is still available as a cross-compile.
Packit 5c3484
dnl
Packit 5c3484
dnl  The various specific problems we try to detect are done in separate
Packit 5c3484
dnl  compiles.  Although this is probably a bit slower than one test
Packit 5c3484
dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
Packit 5c3484
dnl  hence giving the user a clue about why we rejected the compiler.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_WORKS],
Packit 5c3484
[AC_MSG_CHECKING([compiler $1])
Packit 5c3484
gmp_prog_cc_works=yes
Packit 5c3484
Packit 5c3484
# first see a simple "main()" works, then go on to other checks
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [function pointer return],
Packit 5c3484
[/* The following provokes an internal error from gcc 2.95.2 -mpowerpc64
Packit 5c3484
   (without -maix64), hence detecting an unusable compiler */
Packit 5c3484
void *g() { return (void *) 0; }
Packit 5c3484
void *f() { return g(); }
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [cmov instruction],
Packit 5c3484
[/* The following provokes an invalid instruction syntax from i386 gcc
Packit 5c3484
   -march=pentiumpro on Solaris 2.8.  The native sun assembler
Packit 5c3484
   requires a non-standard syntax for cmov which gcc (as of 2.95.2 at
Packit 5c3484
   least) doesn't know.  */
Packit 5c3484
int n;
Packit 5c3484
int cmov () { return (n >= 0 ? n : 0); }
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [double -> ulong conversion],
Packit 5c3484
[/* The following provokes a linker invocation problem with gcc 3.0.3
Packit 5c3484
   on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630".  The -mcpu=630
Packit 5c3484
   option causes gcc to incorrectly select the 32-bit libgcc.a, not
Packit 5c3484
   the 64-bit one, and consequently it misses out on the __fixunsdfdi
Packit 5c3484
   helper (double -> uint64 conversion).  */
Packit 5c3484
double d;
Packit 5c3484
unsigned long gcc303 () { return (unsigned long) d; }
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [double negation],
Packit 5c3484
[/* The following provokes an error from hppa gcc 2.95 under -mpa-risc-2-0 if
Packit 5c3484
   the assembler doesn't know hppa 2.0 instructions.  fneg is a 2.0
Packit 5c3484
   instruction, and a negation like this comes out using it.  */
Packit 5c3484
double fneg_data;
Packit 5c3484
unsigned long fneg () { return -fneg_data; }
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [double -> float conversion],
Packit 5c3484
[/* The following makes gcc 3.3 -march=pentium4 generate an SSE2 xmm insn
Packit 5c3484
   (cvtsd2ss) which will provoke an error if the assembler doesn't recognise
Packit 5c3484
   those instructions.  Not sure how much of the gmp code will come out
Packit 5c3484
   wanting sse2, but it's easiest to reject an option we know is bad.  */
Packit 5c3484
double ftod_data;
Packit 5c3484
float ftod () { return (float) ftod_data; }
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [gnupro alpha ev6 char spilling],
Packit 5c3484
[/* The following provokes an internal compiler error from gcc version
Packit 5c3484
   "2.9-gnupro-99r1" under "-O2 -mcpu=ev6", apparently relating to char
Packit 5c3484
   values being spilled into floating point registers.  The problem doesn't
Packit 5c3484
   show up all the time, but has occurred enough in GMP for us to reject
Packit 5c3484
   this compiler+flags.  */
Packit 5c3484
#include <string.h>  /* for memcpy */
Packit 5c3484
struct try_t
Packit 5c3484
{
Packit 5c3484
 char dst[2];
Packit 5c3484
 char size;
Packit 5c3484
 long d0, d1, d2, d3, d4, d5, d6;
Packit 5c3484
 char overlap;
Packit 5c3484
};
Packit 5c3484
struct try_t param[6];
Packit 5c3484
int
Packit 5c3484
param_init ()
Packit 5c3484
{
Packit 5c3484
 struct try_t *p;
Packit 5c3484
 memcpy (p, &param[ 2 ], sizeof (*p));
Packit 5c3484
 memcpy (p, &param[ 2 ], sizeof (*p));
Packit 5c3484
 p->size = 2;
Packit 5c3484
 memcpy (p, &param[ 1 ], sizeof (*p));
Packit 5c3484
 p->dst[0] = 1;
Packit 5c3484
 p->overlap = 2;
Packit 5c3484
 memcpy (p, &param[ 3 ], sizeof (*p));
Packit 5c3484
 p->dst[0] = 1;
Packit 5c3484
 p->overlap = 8;
Packit 5c3484
 memcpy (p, &param[ 4 ], sizeof (*p));
Packit 5c3484
 memcpy (p, &param[ 4 ], sizeof (*p));
Packit 5c3484
 p->overlap = 8;
Packit 5c3484
 memcpy (p, &param[ 5 ], sizeof (*p));
Packit 5c3484
 memcpy (p, &param[ 5 ], sizeof (*p));
Packit 5c3484
 memcpy (p, &param[ 5 ], sizeof (*p));
Packit 5c3484
 return 0;
Packit 5c3484
}
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
# __builtin_alloca is not available everywhere, check it exists before
Packit 5c3484
# seeing that it works
Packit 5c3484
GMP_PROG_CC_WORKS_PART_TEST([$1],[__builtin_alloca availability],
Packit 5c3484
[int k; int foo () { __builtin_alloca (k); }],
Packit 5c3484
  [GMP_PROG_CC_WORKS_PART([$1], [alloca array],
Packit 5c3484
[/* The following provokes an internal compiler error from Itanium HP-UX cc
Packit 5c3484
    under +O2 or higher.  We use this sort of code in mpn/generic/mul_fft.c. */
Packit 5c3484
int k;
Packit 5c3484
int foo ()
Packit 5c3484
{
Packit 5c3484
  int i, **a;
Packit 5c3484
  a = __builtin_alloca (k);
Packit 5c3484
  for (i = 0; i <= k; i++)
Packit 5c3484
    a[i] = __builtin_alloca (1 << i);
Packit 5c3484
}
Packit 5c3484
])])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [abs int -> double conversion],
Packit 5c3484
[/* The following provokes an internal error from the assembler on
Packit 5c3484
   power2-ibm-aix4.3.1.0.  gcc -mrios2 compiles to nabs+fcirz, and this
Packit 5c3484
   results in "Internal error related to the source program domain".
Packit 5c3484
Packit 5c3484
   For reference it seems to be the combination of nabs+fcirz which is bad,
Packit 5c3484
   not either alone.  This sort of thing occurs in mpz/get_str.c with the
Packit 5c3484
   way double chars_per_bit_exactly is applied in MPN_SIZEINBASE.  Perhaps
Packit 5c3484
   if that code changes to a scaled-integer style then we won't need this
Packit 5c3484
   test.  */
Packit 5c3484
Packit 5c3484
double fp[1];
Packit 5c3484
int x;
Packit 5c3484
int f ()
Packit 5c3484
{
Packit 5c3484
  int a;
Packit 5c3484
  a = (x >= 0 ? x : -x);
Packit 5c3484
  return a * fp[0];
Packit 5c3484
}
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 1],
Packit 5c3484
[/* The following provokes a segfault in the compiler on powerpc-apple-darwin.
Packit 5c3484
   Extracted from tests/mpn/t-iord_u.c.  Causes Apple's gcc 3.3 build 1640 and
Packit 5c3484
   1666 to segfault with e.g., -O2 -mpowerpc64.  */
Packit 5c3484
Packit 5c3484
#if defined (__GNUC__) && ! defined (__cplusplus)
Packit 5c3484
typedef unsigned long long t1;typedef t1*t2;
Packit 5c3484
void g(){}
Packit 5c3484
void h(){}
Packit 5c3484
static __inline__ t1 e(t2 rp,t2 up,int n,t1 v0)
Packit 5c3484
{t1 c,x,r;int i;if(v0){c=1;for(i=1;i
Packit 5c3484
void f(){static const struct{t1 n;t1 src[9];t1 want[9];}d[]={{1,{0},{1}},};t1 got[9];int i;
Packit 5c3484
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();}}
Packit 5c3484
#else
Packit 5c3484
int dummy;
Packit 5c3484
#endif
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 2],
Packit 5c3484
[/* The following provokes an internal compiler error on powerpc-apple-darwin.
Packit 5c3484
   Extracted from mpz/cfdiv_q_2exp.c.  Causes Apple's gcc 3.3 build 1640 and
Packit 5c3484
   1666 to get an ICE with -O1 -mpowerpc64.  */
Packit 5c3484
Packit 5c3484
#if defined (__GNUC__) && ! defined (__cplusplus)
Packit 5c3484
int g();
Packit 5c3484
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();}
Packit 5c3484
int g(){return 0;}
Packit 5c3484
#else
Packit 5c3484
int dummy;
Packit 5c3484
#endif
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART([$1], [freebsd hacked gcc],
Packit 5c3484
[/* Provokes an ICE on i386-freebsd with the FreeBSD-hacked gcc, under
Packit 5c3484
   -O2 -march=amdfam10.  We call helper functions here "open" and "close" in
Packit 5c3484
   order for linking to succeed.  */
Packit 5c3484
Packit 5c3484
#if defined (__GNUC__) && ! defined (__cplusplus)
Packit 5c3484
int open(int*,int*,int);void*close(int);void g(int*rp,int*up,int un){
Packit 5c3484
__builtin_expect(un<=0x7f00,1)?__builtin_alloca(un):close(un);if(__builtin_clzl
Packit 5c3484
(up[un])){open(rp,up,un);while(1){if(rp[un-1]!=0)break;un--;}}}
Packit 5c3484
#else
Packit 5c3484
int dummy;
Packit 5c3484
#endif
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization],
Packit 5c3484
[/* The following is mis-compiled by HP ia-64 cc version
Packit 5c3484
        cc: HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]
Packit 5c3484
   under "cc +O3", both in +DD32 and +DD64 modes.  The mpn_lshift_com gets
Packit 5c3484
   inlined and its return value somehow botched to be 0 instead of 1.  This
Packit 5c3484
   arises in the real mpn_lshift_com in mul_fft.c.  A lower optimization
Packit 5c3484
   level, like +O2 seems ok.  This code needs to be run to show the problem,
Packit 5c3484
   but that's fine, the offending cc is a native-only compiler so we don't
Packit 5c3484
   have to worry about cross compiling.  */
Packit 5c3484
Packit 5c3484
#if ! defined (__cplusplus)
Packit 5c3484
unsigned long
Packit 5c3484
lshift_com (rp, up, n, cnt)
Packit 5c3484
  unsigned long *rp;
Packit 5c3484
  unsigned long *up;
Packit 5c3484
  long n;
Packit 5c3484
  unsigned cnt;
Packit 5c3484
{
Packit 5c3484
  unsigned long retval, high_limb, low_limb;
Packit 5c3484
  unsigned tnc;
Packit 5c3484
  long i;
Packit 5c3484
  tnc = 8 * sizeof (unsigned long) - cnt;
Packit 5c3484
  low_limb = *up++;
Packit 5c3484
  retval = low_limb >> tnc;
Packit 5c3484
  high_limb = low_limb << cnt;
Packit 5c3484
  for (i = n - 1; i != 0; i--)
Packit 5c3484
    {
Packit 5c3484
      low_limb = *up++;
Packit 5c3484
      *rp++ = ~(high_limb | (low_limb >> tnc));
Packit 5c3484
      high_limb = low_limb << cnt;
Packit 5c3484
    }
Packit 5c3484
  return retval;
Packit 5c3484
}
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  unsigned long cy, rp[2], up[2];
Packit 5c3484
  up[0] = ~ 0L;
Packit 5c3484
  up[1] = 0;
Packit 5c3484
  cy = lshift_com (rp, up, 2L, 1);
Packit 5c3484
  if (cy != 1L)
Packit 5c3484
    return 1;
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
#else
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
#endif
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization 2],
Packit 5c3484
[/* The following is mis-compiled by Intel ia-64 icc version 1.8 under
Packit 5c3484
    "icc -O3",  After several calls, the function writes partial garbage to
Packit 5c3484
    the result vector.  Perhaps relates to the chk.a.nc insn.  This code needs
Packit 5c3484
    to be run to show the problem, but that's fine, the offending cc is a
Packit 5c3484
    native-only compiler so we don't have to worry about cross compiling.  */
Packit 5c3484
Packit 5c3484
#if ! defined (__cplusplus)
Packit 5c3484
#include <stdlib.h>
Packit 5c3484
void
Packit 5c3484
lshift_com (rp, up, n, cnt)
Packit 5c3484
  unsigned long *rp;
Packit 5c3484
  unsigned long *up;
Packit 5c3484
  long n;
Packit 5c3484
  unsigned cnt;
Packit 5c3484
{
Packit 5c3484
  unsigned long high_limb, low_limb;
Packit 5c3484
  unsigned tnc;
Packit 5c3484
  long i;
Packit 5c3484
  up += n;
Packit 5c3484
  rp += n;
Packit 5c3484
  tnc = 8 * sizeof (unsigned long) - cnt;
Packit 5c3484
  low_limb = *--up;
Packit 5c3484
  high_limb = low_limb << cnt;
Packit 5c3484
  for (i = n - 1; i != 0; i--)
Packit 5c3484
    {
Packit 5c3484
      low_limb = *--up;
Packit 5c3484
      *--rp = ~(high_limb | (low_limb >> tnc));
Packit 5c3484
      high_limb = low_limb << cnt;
Packit 5c3484
    }
Packit 5c3484
  *--rp = ~high_limb;
Packit 5c3484
}
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  unsigned long *r, *r2;
Packit 5c3484
  unsigned long a[88 + 1];
Packit 5c3484
  long i;
Packit 5c3484
  for (i = 0; i < 88 + 1; i++)
Packit 5c3484
    a[i] = ~0L;
Packit 5c3484
  r = malloc (10000 * sizeof (unsigned long));
Packit 5c3484
  r2 = r;
Packit 5c3484
  for (i = 0; i < 528; i += 23)
Packit 5c3484
    {
Packit 5c3484
      lshift_com (r2, a,
Packit 5c3484
		  i / (8 * sizeof (unsigned long)) + 1,
Packit 5c3484
		  i % (8 * sizeof (unsigned long)));
Packit 5c3484
      r2 += 88 + 1;
Packit 5c3484
    }
Packit 5c3484
  if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
Packit 5c3484
      r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
Packit 5c3484
    abort ();
Packit 5c3484
  free (r);
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
#else
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
#endif
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
# A certain _GLOBAL_OFFSET_TABLE_ problem in past versions of gas, tickled
Packit 5c3484
# by recent versions of gcc.
Packit 5c3484
#
Packit 5c3484
if test "$gmp_prog_cc_works" = yes; then
Packit 5c3484
  case $host in
Packit 5c3484
    X86_PATTERN)
Packit 5c3484
      # this problem only arises in PIC code, so don't need to test when
Packit 5c3484
      # --disable-shared.  We don't necessarily have $enable_shared set to
Packit 5c3484
      # yes at this point, it will still be unset for the default (which is
Packit 5c3484
      # yes); hence the use of "!= no".
Packit 5c3484
      if test "$enable_shared" != no; then
Packit 5c3484
        GMP_PROG_CC_X86_GOT_EAX_EMITTED([$1],
Packit 5c3484
          [GMP_ASM_X86_GOT_EAX_OK([$1],,
Packit 5c3484
            [gmp_prog_cc_works="no, bad gas GOT with eax"])])
Packit 5c3484
      fi
Packit 5c3484
      ;;
Packit 5c3484
  esac
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
AC_MSG_RESULT($gmp_prog_cc_works)
Packit 5c3484
case $gmp_prog_cc_works in
Packit 5c3484
  yes)
Packit 5c3484
    [$2]
Packit 5c3484
    ;;
Packit 5c3484
  *)
Packit 5c3484
    [$3]
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
dnl  Called: GMP_PROG_CC_WORKS_PART(CC+CFLAGS,FAIL-MESSAGE [,CODE])
Packit 5c3484
dnl  A dummy main() is appended to the CODE given.
Packit 5c3484
dnl
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_WORKS_PART],
Packit 5c3484
[GMP_PROG_CC_WORKS_PART_MAIN([$1],[$2],
Packit 5c3484
[$3]
Packit 5c3484
[int main () { return 0; }])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
dnl  Called: GMP_PROG_CC_WORKS_PART_MAIN(CC+CFLAGS,FAIL-MESSAGE,CODE)
Packit 5c3484
dnl  CODE must include a main().
Packit 5c3484
dnl
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_WORKS_PART_MAIN],
Packit 5c3484
[GMP_PROG_CC_WORKS_PART_TEST([$1],[$2],[$3],
Packit 5c3484
  [],
Packit 5c3484
  gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2]",
Packit 5c3484
  gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2][[, program does not run]]")
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
dnl  Called: GMP_PROG_CC_WORKS_PART_TEST(CC+CFLAGS,TITLE,[CODE],
Packit 5c3484
dnl            [ACTION-GOOD],[ACTION-BAD][ACTION-NORUN])
Packit 5c3484
dnl
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_WORKS_PART_TEST],
Packit 5c3484
[if test "$gmp_prog_cc_works" = yes; then
Packit 5c3484
  # remove anything that might look like compiler output to our "||" expression
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
  cat >conftest.c <
Packit 5c3484
[$3]
Packit 5c3484
EOF
Packit 5c3484
  echo "Test compile: [$2]" >&AC_FD_CC
Packit 5c3484
  gmp_compile="$1 conftest.c >&AC_FD_CC"
Packit 5c3484
  if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
    cc_works_part=yes
Packit 5c3484
    if test "$cross_compiling" = no; then
Packit 5c3484
      if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
Packit 5c3484
      else
Packit 5c3484
        cc_works_part=norun
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    cc_works_part=no
Packit 5c3484
  fi
Packit 5c3484
  if test "$cc_works_part" != yes; then
Packit 5c3484
    echo "failed program was:" >&AC_FD_CC
Packit 5c3484
    cat conftest.c >&AC_FD_CC
Packit 5c3484
  fi
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
  case $cc_works_part in
Packit 5c3484
    yes)
Packit 5c3484
      $4
Packit 5c3484
      ;;
Packit 5c3484
    no)
Packit 5c3484
      $5
Packit 5c3484
      ;;
Packit 5c3484
    norun)
Packit 5c3484
      $6
Packit 5c3484
      ;;
Packit 5c3484
  esac
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_WORKS_LONGLONG(cc+cflags,[ACTION-YES][,ACTION-NO])
Packit 5c3484
dnl  --------------------------------------------------------------
Packit 5c3484
dnl  Check that cc+cflags accepts "long long".
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is designed to be run repeatedly with different cc+cflags
Packit 5c3484
dnl  selections, so the result is not cached.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_WORKS_LONGLONG],
Packit 5c3484
[AC_MSG_CHECKING([compiler $1 has long long])
Packit 5c3484
cat >conftest.c <
Packit 5c3484
long long  foo;
Packit 5c3484
long long  bar () { return foo; }
Packit 5c3484
int main () { return 0; }
Packit 5c3484
EOF
Packit 5c3484
gmp_prog_cc_works=no
Packit 5c3484
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  gmp_prog_cc_works=yes
Packit 5c3484
else
Packit 5c3484
  echo "failed program was:" >&AC_FD_CC
Packit 5c3484
  cat conftest.c >&AC_FD_CC
Packit 5c3484
fi
Packit 5c3484
rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
AC_MSG_RESULT($gmp_prog_cc_works)
Packit 5c3484
if test $gmp_prog_cc_works = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_TEST_SIZEOF(cc/cflags,test,[ACTION-GOOD][,ACTION-BAD])
Packit 5c3484
dnl  ------------------------------------------------------------
Packit 5c3484
dnl  The given cc/cflags compiler is run to check the size of a type
Packit 5c3484
dnl  specified by the "test" argument.  "test" can either be a string, or a
Packit 5c3484
dnl  variable like $foo.  The value should be for instance "sizeof-long-4",
Packit 5c3484
dnl  to test that sizeof(long)==4.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is designed to be run for different compiler and/or flags
Packit 5c3484
dnl  combinations, so the result is not cached.
Packit 5c3484
dnl
Packit 5c3484
dnl  The idea for making an array that has a negative size if the desired
Packit 5c3484
dnl  condition test is false comes from autoconf AC_CHECK_SIZEOF.  The cast
Packit 5c3484
dnl  to "long" in the array dimension also follows autoconf, apparently it's
Packit 5c3484
dnl  a workaround for a HP compiler bug.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_TEST_SIZEOF],
Packit 5c3484
[echo "configure: testlist $2" >&AC_FD_CC
Packit 5c3484
[gmp_sizeof_type=`echo "$2" | sed 's/sizeof-\([a-z]*\).*/\1/'`]
Packit 5c3484
[gmp_sizeof_want=`echo "$2" | sed 's/sizeof-[a-z]*-\([0-9]*\).*/\1/'`]
Packit 5c3484
AC_MSG_CHECKING([compiler $1 has sizeof($gmp_sizeof_type)==$gmp_sizeof_want])
Packit 5c3484
cat >conftest.c <
Packit 5c3484
[int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  static int test_array [1 - 2 * (long) (sizeof ($gmp_sizeof_type) != $gmp_sizeof_want)];
Packit 5c3484
  test_array[0] = 0;
Packit 5c3484
  return 0;
Packit 5c3484
}]
Packit 5c3484
EOF
Packit 5c3484
gmp_c_testlist_sizeof=no
Packit 5c3484
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  gmp_c_testlist_sizeof=yes
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
AC_MSG_RESULT($gmp_c_testlist_sizeof)
Packit 5c3484
if test $gmp_c_testlist_sizeof = yes; then
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
else
Packit 5c3484
  ifelse([$4],,:,[$4])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
Packit 5c3484
dnl  -------------------------------------------------------
Packit 5c3484
dnl  Determine whether the given compiler is GNU C.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't
Packit 5c3484
dnl  cache the result.  The same "ifndef" style test is used, to avoid
Packit 5c3484
dnl  problems with syntax checking cpp's used on NeXT and Apple systems.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_IS_GNU],
Packit 5c3484
[cat >conftest.c <
Packit 5c3484
#if ! defined (__GNUC__) || defined (__INTEL_COMPILER)
Packit 5c3484
  choke me
Packit 5c3484
#endif
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  rm -f conftest*
Packit 5c3484
  AC_MSG_CHECKING([whether $1 is gcc])
Packit 5c3484
  AC_MSG_RESULT(yes)
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  rm -f conftest*
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_IS_XLC(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
Packit 5c3484
dnl  -------------------------------------------------------
Packit 5c3484
dnl  Determine whether the given compiler is IBM xlc (on AIX).
Packit 5c3484
dnl
Packit 5c3484
dnl  There doesn't seem to be a preprocessor symbol to test for this, or if
Packit 5c3484
dnl  there is one then it's well hidden in xlc 3.1 on AIX 4.3, so just grep
Packit 5c3484
dnl  the man page printed when xlc is invoked with no arguments.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_IS_XLC],
Packit 5c3484
[gmp_command="$1 2>&1 | grep xlc >/dev/null"
Packit 5c3484
if AC_TRY_EVAL(gmp_command); then
Packit 5c3484
  AC_MSG_CHECKING([whether $1 is xlc])
Packit 5c3484
  AC_MSG_RESULT(yes)
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_X86_GOT_EAX_EMITTED(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
Packit 5c3484
dnl  ----------------------------------------------------------------------
Packit 5c3484
dnl  Determine whether CC+CFLAGS emits instructions using %eax with
Packit 5c3484
dnl  _GLOBAL_OFFSET_TABLE_.  This test is for use on x86 systems.
Packit 5c3484
dnl
Packit 5c3484
dnl  Recent versions of gcc will use %eax for the GOT in leaf functions, for
Packit 5c3484
dnl  instance gcc 3.3.3 with -O3.  This avoids having to save and restore
Packit 5c3484
dnl  %ebx which otherwise usually holds the GOT, and is what gcc used in the
Packit 5c3484
dnl  past.
Packit 5c3484
dnl
Packit 5c3484
dnl  %ecx and %edx are also candidates for this sort of optimization, and
Packit 5c3484
dnl  are used under lesser optimization levels, like -O2 in 3.3.3.  FIXME:
Packit 5c3484
dnl  It's not quite clear what the conditions for using %eax are, we might
Packit 5c3484
dnl  need more test code to provoke it.
Packit 5c3484
dnl
Packit 5c3484
dnl  The motivation for this test is that past versions of gas have bugs
Packit 5c3484
dnl  affecting this usage, see GMP_ASM_X86_GOT_EAX_OK.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is not specific to gcc, other compilers might emit %eax GOT
Packit 5c3484
dnl  insns like this, though we've not investigated that.
Packit 5c3484
dnl
Packit 5c3484
dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so we doesn't
Packit 5c3484
dnl  cache the result.
Packit 5c3484
dnl
Packit 5c3484
dnl  -fPIC is hard coded here, because this test is for use before libtool
Packit 5c3484
dnl  has established the pic options.  It's right for gcc, but perhaps not
Packit 5c3484
dnl  other compilers.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_X86_GOT_EAX_EMITTED],
Packit 5c3484
[echo "Testing gcc GOT with eax emitted" >&AC_FD_CC
Packit 5c3484
cat >conftest.c <<\EOF
Packit 5c3484
[int foo;
Packit 5c3484
int bar () { return foo; }
Packit 5c3484
]EOF
Packit 5c3484
tmp_got_emitted=no
Packit 5c3484
gmp_compile="$1 -fPIC -S conftest.c >&AC_FD_CC 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  if grep "addl.*_GLOBAL_OFFSET_TABLE_.*eax" conftest.s >/dev/null; then
Packit 5c3484
    tmp_got_emitted=yes
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
rm -f conftest.*
Packit 5c3484
echo "Result: $tmp_got_emitted" >&AC_FD_CC
Packit 5c3484
if test "$tmp_got_emitted" = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_HPC_HPPA_2_0(cc,[ACTION-IF-GOOD][,ACTION-IF-BAD])
Packit 5c3484
dnl  ---------------------------------------------------------
Packit 5c3484
dnl  Find out whether a HP compiler is good enough to generate hppa 2.0.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test might be repeated for different compilers, so the result is
Packit 5c3484
dnl  not cached.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_HPC_HPPA_2_0],
Packit 5c3484
[AC_MSG_CHECKING([whether HP compiler $1 is good for 64-bits])
Packit 5c3484
# Bad compiler output:
Packit 5c3484
#   ccom: HP92453-01 G.10.32.05 HP C Compiler
Packit 5c3484
# Good compiler output:
Packit 5c3484
#   ccom: HP92453-01 A.10.32.30 HP C Compiler
Packit 5c3484
# Let A.10.32.30 or higher be ok.
Packit 5c3484
echo >conftest.c
Packit 5c3484
gmp_tmp_vs=`$1 $2 -V -c -o conftest.$OBJEXT conftest.c 2>&1 | grep "^ccom:"`
Packit 5c3484
echo "Version string: $gmp_tmp_vs" >&AC_FD_CC
Packit 5c3484
rm conftest*
Packit 5c3484
gmp_tmp_v1=`echo $gmp_tmp_vs | sed 's/.* .\.\([[0-9]]*\).*/\1/'`
Packit 5c3484
gmp_tmp_v2=`echo $gmp_tmp_vs | sed 's/.* .\..*\.\(.*\)\..* HP C.*/\1/'`
Packit 5c3484
gmp_tmp_v3=`echo $gmp_tmp_vs | sed 's/.* .\..*\..*\.\(.*\) HP C.*/\1/'`
Packit 5c3484
echo "Version number: $gmp_tmp_v1.$gmp_tmp_v2.$gmp_tmp_v3" >&AC_FD_CC
Packit 5c3484
if test -z "$gmp_tmp_v1"; then
Packit 5c3484
  gmp_hpc_64bit=not-applicable
Packit 5c3484
else
Packit 5c3484
  GMP_COMPARE_GE($gmp_tmp_v1, 10, $gmp_tmp_v2, 32, $gmp_tmp_v3, 30)
Packit 5c3484
  gmp_hpc_64bit=$gmp_compare_ge
Packit 5c3484
fi
Packit 5c3484
AC_MSG_RESULT($gmp_hpc_64bit)
Packit 5c3484
if test $gmp_hpc_64bit = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_GCC_ARM_UMODSI(CC,[ACTIONS-IF-GOOD][,ACTIONS-IF-BAD])
Packit 5c3484
dnl  ---------------------------------------------------------
Packit 5c3484
dnl  gcc 2.95.3 and earlier on arm has a bug in the libgcc __umodsi routine
Packit 5c3484
dnl  making "%" give wrong results for some operands, eg. "0x90000000 % 3".
Packit 5c3484
dnl  We're hoping it'll be fixed in 2.95.4, and we know it'll be fixed in
Packit 5c3484
dnl  gcc 3.
Packit 5c3484
dnl
Packit 5c3484
dnl  There's only a couple of places gmp cares about this, one is the
Packit 5c3484
dnl  size==1 case in mpn/generic/mode1o.c, and this shows up in
Packit 5c3484
dnl  tests/mpz/t-jac.c as a wrong result from mpz_kronecker_ui.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_GCC_ARM_UMODSI],
Packit 5c3484
[AC_MSG_CHECKING([whether ARM gcc unsigned division works])
Packit 5c3484
tmp_version=`$1 --version`
Packit 5c3484
echo "$tmp_version" >&AC_FD_CC
Packit 5c3484
case $tmp_version in
Packit 5c3484
  [2.95 | 2.95.[123]])
Packit 5c3484
    ifelse([$3],,:,[$3])
Packit 5c3484
    gmp_gcc_arm_umodsi_result=["no, gcc 2.95.[0123]"] ;;
Packit 5c3484
  *)
Packit 5c3484
    ifelse([$2],,:,[$2])
Packit 5c3484
    gmp_gcc_arm_umodsi_result=yes ;;
Packit 5c3484
esac
Packit 5c3484
AC_MSG_RESULT([$gmp_gcc_arm_umodsi_result])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_GCC_MIPS_O32(gcc,[actions-yes][,[actions-no]])
Packit 5c3484
dnl  -------------------------------------------------
Packit 5c3484
dnl  Test whether gcc supports o32.
Packit 5c3484
dnl
Packit 5c3484
dnl  gcc 2.7.2.2 only does o32, and doesn't accept -mabi=32.
Packit 5c3484
dnl
Packit 5c3484
dnl  gcc 2.95 accepts -mabi=32 but it only works on irix5, on irix6 it gives
Packit 5c3484
dnl  "cc1: The -mabi=32 support does not work yet".
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_GCC_MIPS_O32],
Packit 5c3484
[AC_MSG_CHECKING([whether gcc supports o32])
Packit 5c3484
echo 'int x;' >conftest.c
Packit 5c3484
echo "$1 -mabi=32 -c conftest.c" >&AC_FD_CC
Packit 5c3484
if $1 -mabi=32 -c conftest.c >conftest.out 2>&1; then
Packit 5c3484
  result=yes
Packit 5c3484
else
Packit 5c3484
  cat conftest.out >&AC_FD_CC
Packit 5c3484
  if grep "cc1: Invalid option \`abi=32'" conftest.out >/dev/null; then
Packit 5c3484
    result=yes
Packit 5c3484
  else
Packit 5c3484
    result=no
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
rm -f conftest.*
Packit 5c3484
AC_MSG_RESULT($result)
Packit 5c3484
if test $result = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_GCC_NO_CPP_PRECOMP(CCBASE,CC,CFLAGS,[ACTIONS-YES][,ACTIONS-NO])
Packit 5c3484
dnl  -------------------------------------------------------------------
Packit 5c3484
dnl  Check whether -no-cpp-precomp should be used on this compiler, and
Packit 5c3484
dnl  execute the corresponding ACTIONS-YES or ACTIONS-NO.
Packit 5c3484
dnl
Packit 5c3484
dnl  -no-cpp-precomp is only meant for Apple's hacked version of gcc found
Packit 5c3484
dnl  on powerpc*-*-darwin*, but we can give it a try on any gcc.  Normal gcc
Packit 5c3484
dnl  (as of 3.0 at least) only gives a warning, not an actual error, and we
Packit 5c3484
dnl  watch for that and decide against the option in that case, to avoid
Packit 5c3484
dnl  confusing the user.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_GCC_NO_CPP_PRECOMP],
Packit 5c3484
[if test "$ccbase" = gcc; then
Packit 5c3484
  AC_MSG_CHECKING([compiler $2 $3 -no-cpp-precomp])
Packit 5c3484
  result=no
Packit 5c3484
  cat >conftest.c <
Packit 5c3484
int main () { return 0; }
Packit 5c3484
EOF
Packit 5c3484
  gmp_compile="$2 $3 -no-cpp-precomp conftest.c >conftest.out 2>&1"
Packit 5c3484
  if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
    if grep "unrecognized option.*-no-cpp-precomp" conftest.out >/dev/null; then : ;
Packit 5c3484
    else
Packit 5c3484
      result=yes
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
  cat conftest.out >&AC_FD_CC
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
  AC_MSG_RESULT($result)
Packit 5c3484
  if test "$result" = yes; then
Packit 5c3484
      ifelse([$4],,:,[$4])
Packit 5c3484
  else
Packit 5c3484
      ifelse([$5],,:,[$5])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_GCC_PENTIUM4_SSE2(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
Packit 5c3484
dnl  ---------------------------------------------------------------
Packit 5c3484
dnl  Determine whether gcc CC+CFLAGS is a good enough version for
Packit 5c3484
dnl  -march=pentium4 with sse2.
Packit 5c3484
dnl
Packit 5c3484
dnl  Gcc 3.2.1 was seen generating incorrect code for raw double -> int
Packit 5c3484
dnl  conversions through a union.  We believe the problem is in all 3.1 and
Packit 5c3484
dnl  3.2 versions, but that it's fixed in 3.3.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_GCC_PENTIUM4_SSE2],
Packit 5c3484
[AC_MSG_CHECKING([whether gcc is good for sse2])
Packit 5c3484
case `$1 -dumpversion` in
Packit 5c3484
  [3.[012] | 3.[012].*]) result=no ;;
Packit 5c3484
  *)                     result=yes ;;
Packit 5c3484
esac
Packit 5c3484
AC_MSG_RESULT($result)
Packit 5c3484
if test "$result" = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_GCC_WA_MCPU(CC+CFLAGS, NEWFLAG [,ACTION-YES [,ACTION-NO]])
Packit 5c3484
dnl  --------------------------------------------------------------
Packit 5c3484
dnl  Check whether gcc (or gas rather) accepts a flag like "-Wa,-mev67".
Packit 5c3484
dnl
Packit 5c3484
dnl  Gas doesn't give an error for an unknown cpu, it only prints a warning
Packit 5c3484
dnl  like "Warning: Unknown CPU identifier `ev78'".
Packit 5c3484
dnl
Packit 5c3484
dnl  This is intended for use on alpha, since only recent versions of gas
Packit 5c3484
dnl  accept -mev67, but there's nothing here that's alpha specific.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_GCC_WA_MCPU],
Packit 5c3484
[AC_MSG_CHECKING([assembler $1 $2])
Packit 5c3484
result=no
Packit 5c3484
cat >conftest.c <
Packit 5c3484
int main () {}
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$1 $2 -c conftest.c >conftest.out 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  if grep "Unknown CPU identifier" conftest.out >/dev/null; then : ;
Packit 5c3484
  else
Packit 5c3484
    result=yes
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
cat conftest.out >&AC_FD_CC
Packit 5c3484
rm -f conftest*
Packit 5c3484
AC_MSG_RESULT($result)
Packit 5c3484
if test "$result" = yes; then
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
else
Packit 5c3484
  ifelse([$4],,:,[$4])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_GCC_WA_OLDAS(CC+CFLAGS [,ACTION-YES [,ACTION-NO]])
Packit 5c3484
dnl  ------------------------------------------------------
Packit 5c3484
dnl  Check whether gcc should be run with "-Wa,-oldas".
Packit 5c3484
dnl
Packit 5c3484
dnl  On systems alpha*-*-osf* (or maybe just osf5), apparently there's a
Packit 5c3484
dnl  newish Compaq "as" which doesn't work with the gcc mips-tfile.
Packit 5c3484
dnl  Compiling an empty file with "gcc -c foo.c" produces for instance
Packit 5c3484
dnl
Packit 5c3484
dnl      mips-tfile, /tmp/ccaqUNnF.s:7 Segmentation fault
Packit 5c3484
dnl
Packit 5c3484
dnl  The fix is to pass "-oldas" to that assembler, as noted by
Packit 5c3484
dnl
Packit 5c3484
dnl      http://gcc.gnu.org/install/specific.html#alpha*-dec-osf*
Packit 5c3484
dnl
Packit 5c3484
dnl  The test here tries to compile an empty file, and if that fails but
Packit 5c3484
dnl  adding -Wa,-oldas makes it succeed, then that flag is considered
Packit 5c3484
dnl  necessary.
Packit 5c3484
dnl
Packit 5c3484
dnl  We look for the failing case specifically, since it may not be a good
Packit 5c3484
dnl  idea to use -Wa,-oldas in other circumstances.  For instance gas takes
Packit 5c3484
dnl  "-oldas" to mean the "-o" option and will write a file called "ldas" as
Packit 5c3484
dnl  its output.  Normally gcc puts its own "-o" after any -Wa options, so
Packit 5c3484
dnl  -oldas ends up being harmless, but clearly that's only through good
Packit 5c3484
dnl  luck.
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro is designed for use while probing for a good compiler, and
Packit 5c3484
dnl  so doesn't cache it's result.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_GCC_WA_OLDAS],
Packit 5c3484
[AC_MSG_CHECKING([for $1 -Wa,-oldas])
Packit 5c3484
result=no
Packit 5c3484
cat >conftest.c <
Packit 5c3484
EOF
Packit 5c3484
echo "with empty conftest.c" >&AC_FD_CC
Packit 5c3484
gmp_compile="$1 -c conftest.c >&AC_FD_CC 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then : ;
Packit 5c3484
else
Packit 5c3484
  # empty fails
Packit 5c3484
  gmp_compile="$1 -Wa,-oldas -c conftest.c >&AC_FD_CC 2>&1"
Packit 5c3484
  if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
    # but with -Wa,-oldas it works
Packit 5c3484
    result=yes
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
AC_MSG_RESULT($result)
Packit 5c3484
if test "$result" = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_OS_X86_XMM(CC+CFLAGS,[ACTION-IF-YES][,ACTION-IF-NO])
Packit 5c3484
dnl  --------------------------------------------------------
Packit 5c3484
dnl  Determine whether the operating system supports XMM registers.
Packit 5c3484
dnl
Packit 5c3484
dnl  If build==host then a test program is run, executing an SSE2
Packit 5c3484
dnl  instruction using an XMM register.  This will give a SIGILL if the
Packit 5c3484
dnl  system hasn't set the OSFXSR bit in CR4 to say it knows it must use
Packit 5c3484
dnl  fxsave/fxrestor in a context switch (to save xmm registers).
Packit 5c3484
dnl
Packit 5c3484
dnl  If build!=host, we can fallback on:
Packit 5c3484
dnl
Packit 5c3484
dnl      - FreeBSD version 4 is the first supporting xmm.
Packit 5c3484
dnl
Packit 5c3484
dnl      - Linux kernel 2.4 might be the first stable series supporting xmm
Packit 5c3484
dnl        (not sure).  But there's no version number in the GNU/Linux
Packit 5c3484
dnl        config tuple to test anyway.
Packit 5c3484
dnl
Packit 5c3484
dnl  The default is to allow xmm.  This might seem rash, but it's likely
Packit 5c3484
dnl  most systems know xmm by now, so this will normally be what's wanted.
Packit 5c3484
dnl  And cross compiling is a bit hairy anyway, so hopefully anyone doing it
Packit 5c3484
dnl  will be smart enough to know what to do.
Packit 5c3484
dnl
Packit 5c3484
dnl  In the test program, .text and .globl are hard coded because this macro
Packit 5c3484
dnl  is wanted before GMP_ASM_TEXT and GMP_ASM_GLOBL are run.  A .byte
Packit 5c3484
dnl  sequence is used (for xorps %xmm0, %xmm0) to make us independent of
Packit 5c3484
dnl  tests for whether the assembler supports sse2/xmm.  Obviously we need
Packit 5c3484
dnl  both assembler and OS support, but this means we don't force the order
Packit 5c3484
dnl  in which we test.
Packit 5c3484
dnl
Packit 5c3484
dnl  FIXME: Maybe we should use $CCAS to assemble, if it's set.  (Would
Packit 5c3484
dnl  still want $CC/$CFLAGS for the link.)  But this test is used before
Packit 5c3484
dnl  AC_PROG_CC sets $OBJEXT, so we'd need to check for various object file
Packit 5c3484
dnl  suffixes ourselves.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_OS_X86_XMM],
Packit 5c3484
[AC_CACHE_CHECK([whether the operating system supports XMM registers],
Packit 5c3484
		gmp_cv_os_x86_xmm,
Packit 5c3484
[if test "$build" = "$host"; then
Packit 5c3484
  # remove anything that might look like compiler output to our "||" expression
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
  cat >conftest.s <
Packit 5c3484
	.text
Packit 5c3484
main:
Packit 5c3484
_main:
Packit 5c3484
	.globl	main
Packit 5c3484
	.globl	_main
Packit 5c3484
	.byte	0x0f, 0x57, 0xc0
Packit 5c3484
	xorl	%eax, %eax
Packit 5c3484
	ret
Packit 5c3484
EOF
Packit 5c3484
  gmp_compile="$1 conftest.s -o conftest >&AC_FD_CC"
Packit 5c3484
  if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
    if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then
Packit 5c3484
      gmp_cv_os_x86_xmm=yes
Packit 5c3484
    else
Packit 5c3484
      gmp_cv_os_x86_xmm=no
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    AC_MSG_WARN([Oops, cannot compile test program])
Packit 5c3484
  fi
Packit 5c3484
  rm -f conftest*
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
if test -z "$gmp_cv_os_x86_xmm"; then
Packit 5c3484
  case $host_os in
Packit 5c3484
    [freebsd[123] | freebsd[123].*])
Packit 5c3484
      gmp_cv_os_x86_xmm=no ;;
Packit 5c3484
    freebsd*)
Packit 5c3484
      gmp_cv_os_x86_xmm=yes ;;
Packit 5c3484
    *)
Packit 5c3484
      gmp_cv_os_x86_xmm=probably ;;
Packit 5c3484
  esac
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
if test "$gmp_cv_os_x86_xmm" = probably; then
Packit 5c3484
  AC_MSG_WARN([Not certain of OS support for xmm when cross compiling.])
Packit 5c3484
  AC_MSG_WARN([Will assume it's ok, expect a SIGILL if this is wrong.])
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
case $gmp_cv_os_x86_xmm in
Packit 5c3484
no)
Packit 5c3484
  $3
Packit 5c3484
  ;;
Packit 5c3484
*)
Packit 5c3484
  $2
Packit 5c3484
  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_CRAY_HOST_TYPES(C90/T90-IEEE, C90/T90-CFP, J90/SV1)
Packit 5c3484
dnl  -------------------------------------------------------
Packit 5c3484
dnl  Execute the actions in the arguments on the respective Cray vector
Packit 5c3484
dnl  systems.  For other hosts, do nothing.
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro should be used after the C compiler has been chosen, since
Packit 5c3484
dnl  on c90 and t90 we ask the compiler whether we're in IEEE or CFP float
Packit 5c3484
dnl  mode.
Packit 5c3484
dnl
Packit 5c3484
dnl  This code is in a macro so that any AC_REQUIRE pre-requisites of
Packit 5c3484
dnl  AC_EGREP_CPP will be expanded at the top-level, ie. for all hosts not
Packit 5c3484
dnl  merely c90 and t90.  In autoconf 2.57 for instance this means
Packit 5c3484
dnl  AC_PROG_EGREP, which is needed by various other macros.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_CRAY_OPTIONS],
Packit 5c3484
[case $host_cpu in
Packit 5c3484
  c90 | t90)
Packit 5c3484
    AC_EGREP_CPP(yes,
Packit 5c3484
[#ifdef _CRAYIEEE
Packit 5c3484
yes
Packit 5c3484
#endif],
Packit 5c3484
    [$1],
Packit 5c3484
    [$2])
Packit 5c3484
    ;;
Packit 5c3484
  j90 | sv1)
Packit 5c3484
    [$3]
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_HPPA_LEVEL_20(cc/cflags [, ACTION-GOOD [,ACTION-BAD]])
Packit 5c3484
dnl  ----------------------------------------------------------
Packit 5c3484
dnl  Check that the given cc/cflags accepts HPPA 2.0n assembler code.
Packit 5c3484
dnl
Packit 5c3484
dnl  Old versions of gas don't know 2.0 instructions.  It rejects ".level
Packit 5c3484
dnl  2.0" for a start, so just test that.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is designed to be run for various different compiler and
Packit 5c3484
dnl  flags combinations, and hence doesn't cache its result.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_HPPA_LEVEL_20],
Packit 5c3484
[AC_MSG_CHECKING([$1 assembler knows hppa 2.0])
Packit 5c3484
result=no
Packit 5c3484
cat >conftest.s <
Packit 5c3484
	.level 2.0
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$1 -c conftest.s >&AC_FD_CC 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  result=yes
Packit 5c3484
else
Packit 5c3484
  echo "failed program was" >&AC_FD_CC
Packit 5c3484
  cat conftest.s >&AC_FD_CC
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
AC_MSG_RESULT($result)
Packit 5c3484
if test "$result" = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CXX_WORKS(cxx/cxxflags [, ACTION-YES [,ACTION-NO]])
Packit 5c3484
dnl  ------------------------------------------------------------
Packit 5c3484
dnl  Check whether cxx/cxxflags can compile and link.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is designed to be run repeatedly with different cxx/cxxflags
Packit 5c3484
dnl  selections, so the result is not cached.
Packit 5c3484
dnl
Packit 5c3484
dnl  For a native build, we insist on being able to run the program, so as
Packit 5c3484
dnl  to detect any problems with the standard C++ library.  During
Packit 5c3484
dnl  development various systems with broken or incomplete C++ installations
Packit 5c3484
dnl  were seen.
Packit 5c3484
dnl
Packit 5c3484
dnl  The various features and problems we try to detect are done in separate
Packit 5c3484
dnl  compiles.  Although this is probably a bit slower than one test
Packit 5c3484
dnl  program, it makes it easy to indicate the problem in AC_MSG_RESULT,
Packit 5c3484
dnl  hence giving the user a clue about why we rejected the compiler.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CXX_WORKS],
Packit 5c3484
[AC_MSG_CHECKING([C++ compiler $1])
Packit 5c3484
gmp_prog_cxx_works=yes
Packit 5c3484
Packit 5c3484
# start with a plain "main()", then go on to further checks
Packit 5c3484
GMP_PROG_CXX_WORKS_PART([$1], [])
Packit 5c3484
Packit 5c3484
GMP_PROG_CXX_WORKS_PART([$1], [namespace],
Packit 5c3484
[namespace foo { }
Packit 5c3484
using namespace foo;
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
# GMP requires the standard C++ iostream classes
Packit 5c3484
GMP_PROG_CXX_WORKS_PART([$1], [std iostream],
Packit 5c3484
[/* This test rejects g++ 2.7.2 which doesn't have <iostream>, only a
Packit 5c3484
    pre-standard iostream.h. */
Packit 5c3484
#include <iostream>
Packit 5c3484
Packit 5c3484
/* This test rejects OSF 5.1 Compaq C++ in its default pre-standard iostream
Packit 5c3484
   mode, since that mode puts cout in the global namespace, not "std".  */
Packit 5c3484
void someoutput (void) { std::cout << 123; }
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
AC_MSG_RESULT($gmp_prog_cxx_works)
Packit 5c3484
case $gmp_prog_cxx_works in
Packit 5c3484
  yes)
Packit 5c3484
    [$2]
Packit 5c3484
    ;;
Packit 5c3484
  *)
Packit 5c3484
    [$3]
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
dnl  Called: GMP_PROG_CXX_WORKS_PART(CXX+CXXFLAGS, FAIL-MESSAGE [,CODE])
Packit 5c3484
dnl
Packit 5c3484
AC_DEFUN([GMP_PROG_CXX_WORKS_PART],
Packit 5c3484
[if test "$gmp_prog_cxx_works" = yes; then
Packit 5c3484
  # remove anything that might look like compiler output to our "||" expression
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
  cat >conftest.cc <
Packit 5c3484
[$3]
Packit 5c3484
int main (void) { return 0; }
Packit 5c3484
EOF
Packit 5c3484
  echo "Test compile: [$2]" >&AC_FD_CC
Packit 5c3484
  gmp_cxxcompile="$1 conftest.cc >&AC_FD_CC"
Packit 5c3484
  if AC_TRY_EVAL(gmp_cxxcompile); then
Packit 5c3484
    if test "$cross_compiling" = no; then
Packit 5c3484
      if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
Packit 5c3484
      else
Packit 5c3484
        gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2], program does not run"
Packit 5c3484
      fi
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    gmp_prog_cxx_works="no[]m4_if([$2],,,[, ])[$2]"
Packit 5c3484
  fi
Packit 5c3484
  case $gmp_prog_cxx_works in
Packit 5c3484
    no*)
Packit 5c3484
      echo "failed program was:" >&AC_FD_CC
Packit 5c3484
      cat conftest.cc >&AC_FD_CC
Packit 5c3484
      ;;
Packit 5c3484
  esac
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_INIT([M4-DEF-FILE])
Packit 5c3484
dnl  -----------------------
Packit 5c3484
dnl  Initializations for GMP config.m4 generation.
Packit 5c3484
dnl
Packit 5c3484
dnl  FIXME: The generated config.m4 doesn't get recreated by config.status.
Packit 5c3484
dnl  Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_INIT],
Packit 5c3484
[ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
Packit 5c3484
gmp_tmpconfigm4=cnfm4.tmp
Packit 5c3484
gmp_tmpconfigm4i=cnfm4i.tmp
Packit 5c3484
gmp_tmpconfigm4p=cnfm4p.tmp
Packit 5c3484
rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p
Packit 5c3484
Packit 5c3484
# CONFIG_TOP_SRCDIR is a path from the mpn builddir to the top srcdir.
Packit 5c3484
# The pattern here tests for an absolute path the same way as
Packit 5c3484
# _AC_OUTPUT_FILES in autoconf acgeneral.m4.
Packit 5c3484
case $srcdir in
Packit 5c3484
[[\\/]]* | ?:[[\\/]]* )  tmp="$srcdir"    ;;
Packit 5c3484
*)                       tmp="../$srcdir" ;;
Packit 5c3484
esac
Packit 5c3484
echo ["define(<CONFIG_TOP_SRCDIR>,<\`$tmp'>)"] >>$gmp_tmpconfigm4
Packit 5c3484
Packit 5c3484
# All CPUs use asm-defs.m4
Packit 5c3484
echo ["include][(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"] >>$gmp_tmpconfigm4i
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_FINISH
Packit 5c3484
dnl  ----------
Packit 5c3484
dnl  Create config.m4 from its accumulated parts.
Packit 5c3484
dnl
Packit 5c3484
dnl  __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
Packit 5c3484
dnl  of config.m4 is harmless.
Packit 5c3484
dnl
Packit 5c3484
dnl  A separate ifdef on the angle bracket quoted part ensures the quoting
Packit 5c3484
dnl  style there is respected.  The basic defines from gmp_tmpconfigm4 are
Packit 5c3484
dnl  fully quoted but are still put under an ifdef in case any have been
Packit 5c3484
dnl  redefined by one of the m4 include files.
Packit 5c3484
dnl
Packit 5c3484
dnl  Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
Packit 5c3484
dnl  work, since it'd interpret parentheses and quotes in dnl comments, and
Packit 5c3484
dnl  having a whole file as a macro argument would overflow the string space
Packit 5c3484
dnl  on BSD m4.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_FINISH],
Packit 5c3484
[AC_REQUIRE([GMP_INIT])
Packit 5c3484
echo "creating $gmp_configm4"
Packit 5c3484
echo ["d""nl $gmp_configm4.  Generated automatically by configure."] > $gmp_configm4
Packit 5c3484
if test -f $gmp_tmpconfigm4; then
Packit 5c3484
  echo ["changequote(<,>)"] >> $gmp_configm4
Packit 5c3484
  echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
Packit 5c3484
  cat $gmp_tmpconfigm4 >> $gmp_configm4
Packit 5c3484
  echo [">)"] >> $gmp_configm4
Packit 5c3484
  echo ["changequote(\`,')"] >> $gmp_configm4
Packit 5c3484
  rm $gmp_tmpconfigm4
Packit 5c3484
fi
Packit 5c3484
echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
Packit 5c3484
if test -f $gmp_tmpconfigm4i; then
Packit 5c3484
  cat $gmp_tmpconfigm4i >> $gmp_configm4
Packit 5c3484
  rm $gmp_tmpconfigm4i
Packit 5c3484
fi
Packit 5c3484
if test -f $gmp_tmpconfigm4p; then
Packit 5c3484
  cat $gmp_tmpconfigm4p >> $gmp_configm4
Packit 5c3484
  rm $gmp_tmpconfigm4p
Packit 5c3484
fi
Packit 5c3484
echo ["')"] >> $gmp_configm4
Packit 5c3484
echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_INCLUDE_MPN(FILE)
Packit 5c3484
dnl  ---------------------
Packit 5c3484
dnl  Add an include_mpn(`FILE') to config.m4.  FILE should be a path
Packit 5c3484
dnl  relative to the mpn source directory, for example
Packit 5c3484
dnl
Packit 5c3484
dnl      GMP_INCLUDE_MPN(`x86/x86-defs.m4')
Packit 5c3484
dnl
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_INCLUDE_MPN],
Packit 5c3484
[AC_REQUIRE([GMP_INIT])
Packit 5c3484
echo ["include_mpn(\`$1')"] >> $gmp_tmpconfigm4i
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_DEFINE(MACRO, DEFINITION [, LOCATION])
Packit 5c3484
dnl  ------------------------------------------
Packit 5c3484
dnl  Define M4 macro MACRO as DEFINITION in temporary file.
Packit 5c3484
dnl
Packit 5c3484
dnl  If LOCATION is `POST', the definition will appear after any include()
Packit 5c3484
dnl  directives inserted by GMP_INCLUDE.  Mind the quoting!  No shell
Packit 5c3484
dnl  variables will get expanded.  Don't forget to invoke GMP_FINISH to
Packit 5c3484
dnl  create file config.m4.  config.m4 uses `<' and '>' as quote characters
Packit 5c3484
dnl  for all defines.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_DEFINE],
Packit 5c3484
[AC_REQUIRE([GMP_INIT])
Packit 5c3484
echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
Packit 5c3484
                              $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_DEFINE_RAW(STRING [, LOCATION])
Packit 5c3484
dnl  ------------------------------------
Packit 5c3484
dnl  Put STRING into config.m4 file.
Packit 5c3484
dnl
Packit 5c3484
dnl  If LOCATION is `POST', the definition will appear after any include()
Packit 5c3484
dnl  directives inserted by GMP_INCLUDE.  Don't forget to invoke GMP_FINISH
Packit 5c3484
dnl  to create file config.m4.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_DEFINE_RAW],
Packit 5c3484
[AC_REQUIRE([GMP_INIT])
Packit 5c3484
echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
Packit 5c3484
dnl  ----------------------------------------------------------
Packit 5c3484
dnl  Attempt to assemble the given code.
Packit 5c3484
dnl  Do "action-success" if this succeeds, "action-fail" if not.
Packit 5c3484
dnl
Packit 5c3484
dnl  conftest.o and conftest.out are available for inspection in
Packit 5c3484
dnl  "action-success".  If either action does a "break" out of a loop then
Packit 5c3484
dnl  an explicit "rm -f conftest*" will be necessary.
Packit 5c3484
dnl
Packit 5c3484
dnl  This is not unlike AC_TRY_COMPILE, but there's no default includes or
Packit 5c3484
dnl  anything in "asm-code", everything wanted must be given explicitly.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_TRY_ASSEMBLE],
Packit 5c3484
[cat >conftest.s <
Packit 5c3484
[$1]
Packit 5c3484
EOF
Packit 5c3484
gmp_assemble="$CCAS $CFLAGS $CPPFLAGS conftest.s >conftest.out 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_assemble); then
Packit 5c3484
  cat conftest.out >&AC_FD_CC
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  cat conftest.out >&AC_FD_CC
Packit 5c3484
  echo "configure: failed program was:" >&AC_FD_CC
Packit 5c3484
  cat conftest.s >&AC_FD_CC
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl Checks whether the stack can be marked nonexecutable by passing an option
Packit 5c3484
dnl to the C-compiler when acting on .s files. Appends that option to ASMFLAGS.
Packit 5c3484
dnl This macro is adapted from one found in GLIBC-2.3.5.
Packit 5c3484
dnl FIXME: This test looks broken. It tests that a file with .note.GNU-stack...
Packit 5c3484
dnl can be compiled/assembled with -Wa,--noexecstack.  It does not determine
Packit 5c3484
dnl if that command-line option has any effect on general asm code.
Packit 5c3484
AC_DEFUN([CL_AS_NOEXECSTACK],[
Packit 5c3484
dnl AC_REQUIRE([AC_PROG_CC]) GMP uses something else
Packit 5c3484
AC_CACHE_CHECK([whether assembler supports --noexecstack option],
Packit 5c3484
cl_cv_as_noexecstack, [dnl
Packit 5c3484
  cat > conftest.c <
Packit 5c3484
void foo() {}
Packit 5c3484
EOF
Packit 5c3484
  if AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS
Packit 5c3484
                     -S -o conftest.s conftest.c >/dev/null]) \
Packit 5c3484
     && grep .note.GNU-stack conftest.s >/dev/null \
Packit 5c3484
     && AC_TRY_COMMAND([${CC} $CFLAGS $CPPFLAGS -Wa,--noexecstack
Packit 5c3484
                       -c -o conftest.o conftest.s >/dev/null])
Packit 5c3484
  then
Packit 5c3484
    cl_cv_as_noexecstack=yes
Packit 5c3484
  else
Packit 5c3484
    cl_cv_as_noexecstack=no
Packit 5c3484
  fi
Packit 5c3484
  rm -f conftest*])
Packit 5c3484
  if test "$cl_cv_as_noexecstack" = yes; then
Packit 5c3484
    ASMFLAGS="$ASMFLAGS -Wa,--noexecstack"
Packit 5c3484
  fi
Packit 5c3484
  AC_SUBST(ASMFLAGS)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_LABEL_SUFFIX
Packit 5c3484
dnl  --------------------
Packit 5c3484
dnl  : - is usual.
Packit 5c3484
dnl  empty - hppa on HP-UX doesn't use a :, just the label name
Packit 5c3484
dnl
Packit 5c3484
dnl  Note that it's necessary to test the empty case first, since HP "as"
Packit 5c3484
dnl  will accept "somelabel:", and take it to mean a label with a name that
Packit 5c3484
dnl  happens to end in a colon.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_LABEL_SUFFIX],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([for assembler label suffix],
Packit 5c3484
                gmp_cv_asm_label_suffix,
Packit 5c3484
[gmp_cv_asm_label_suffix=unknown
Packit 5c3484
for i in "" ":"; do
Packit 5c3484
  echo "trying $i" >&AC_FD_CC
Packit 5c3484
  GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
somelabel$i],
Packit 5c3484
    [gmp_cv_asm_label_suffix=$i
Packit 5c3484
     rm -f conftest*
Packit 5c3484
     break],
Packit 5c3484
    [cat conftest.out >&AC_FD_CC])
Packit 5c3484
done
Packit 5c3484
if test "$gmp_cv_asm_label_suffix" = "unknown"; then
Packit 5c3484
  AC_MSG_ERROR([Cannot determine label suffix])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
echo ["define(<LABEL_SUFFIX>, <$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_UNDERSCORE
Packit 5c3484
dnl  ------------------
Packit 5c3484
dnl  Determine whether global symbols need to be prefixed with an underscore.
Packit 5c3484
dnl  The output from "nm" is grepped to see what a typical symbol looks like.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test used to grep the .o file directly, but that failed with greps
Packit 5c3484
dnl  that don't like binary files (eg. SunOS 4).
Packit 5c3484
dnl
Packit 5c3484
dnl  This test also used to construct an assembler file with and without an
Packit 5c3484
dnl  underscore and try to link that to a C file, to see which worked.
Packit 5c3484
dnl  Although that's what will happen in the real build we don't really want
Packit 5c3484
dnl  to depend on creating asm files within configure for every possible CPU
Packit 5c3484
dnl  (or at least we don't want to do that more than we have to).
Packit 5c3484
dnl
Packit 5c3484
dnl  The fallback on no underscore is based on the assumption that the world
Packit 5c3484
dnl  is moving towards non-underscore systems.  There should actually be no
Packit 5c3484
dnl  good reason for nm to fail though.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_UNDERSCORE],
Packit 5c3484
[AC_REQUIRE([GMP_PROG_NM])
Packit 5c3484
AC_CACHE_CHECK([if globals are prefixed by underscore],
Packit 5c3484
               gmp_cv_asm_underscore,
Packit 5c3484
[gmp_cv_asm_underscore="unknown"
Packit 5c3484
cat >conftest.c <
Packit 5c3484
int gurkmacka;
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  $NM conftest.$OBJEXT >conftest.out
Packit 5c3484
  if grep "[[ 	]]_gurkmacka" conftest.out >/dev/null; then
Packit 5c3484
    gmp_cv_asm_underscore=yes
Packit 5c3484
  elif grep "[[ 	]]gurkmacka" conftest.out >/dev/null; then
Packit 5c3484
    gmp_cv_asm_underscore=no
Packit 5c3484
  else
Packit 5c3484
    echo "configure: $NM doesn't have gurkmacka:" >&AC_FD_CC
Packit 5c3484
    cat conftest.out >&AC_FD_CC
Packit 5c3484
  fi
Packit 5c3484
else
Packit 5c3484
  echo "configure: failed program was:" >&AC_FD_CC
Packit 5c3484
  cat conftest.c >&AC_FD_CC
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_asm_underscore in
Packit 5c3484
  yes)
Packit 5c3484
    GMP_DEFINE(GSYM_PREFIX, [_]) ;;
Packit 5c3484
  no)
Packit 5c3484
    GMP_DEFINE(GSYM_PREFIX, []) ;;
Packit 5c3484
  *)
Packit 5c3484
    AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
    AC_MSG_WARN([| Cannot determine global symbol prefix.])
Packit 5c3484
    AC_MSG_WARN([| $NM output doesn't contain a global data symbol.])
Packit 5c3484
    AC_MSG_WARN([| Will proceed with no underscore.])
Packit 5c3484
    AC_MSG_WARN([| If this is wrong then you'll get link errors referring])
Packit 5c3484
    AC_MSG_WARN([| to ___gmpn_add_n (note three underscores).])
Packit 5c3484
    AC_MSG_WARN([| In this case do a fresh build with an override,])
Packit 5c3484
    AC_MSG_WARN([|     ./configure gmp_cv_asm_underscore=yes])
Packit 5c3484
    AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
    GMP_DEFINE(GSYM_PREFIX, [])
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_ALIGN_LOG
Packit 5c3484
dnl  -----------------
Packit 5c3484
dnl  Is parameter to `.align' logarithmic?
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_ALIGN_LOG],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_GLOBL])
Packit 5c3484
AC_REQUIRE([GMP_ASM_BYTE])
Packit 5c3484
AC_REQUIRE([GMP_ASM_DATA])
Packit 5c3484
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_REQUIRE([GMP_PROG_NM])
Packit 5c3484
AC_CACHE_CHECK([if .align assembly directive is logarithmic],
Packit 5c3484
               gmp_cv_asm_align_log,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[      	$gmp_cv_asm_data
Packit 5c3484
      	.align  4
Packit 5c3484
	$gmp_cv_asm_globl	foo
Packit 5c3484
	$gmp_cv_asm_byte	1
Packit 5c3484
	.align	4
Packit 5c3484
foo$gmp_cv_asm_label_suffix
Packit 5c3484
	$gmp_cv_asm_byte	2],
Packit 5c3484
  [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
Packit 5c3484
     sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
Packit 5c3484
  if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"; then
Packit 5c3484
    gmp_cv_asm_align_log=yes
Packit 5c3484
  else
Packit 5c3484
    gmp_cv_asm_align_log=no
Packit 5c3484
  fi],
Packit 5c3484
  [AC_MSG_ERROR([cannot assemble alignment test])])])
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<ALIGN_LOGARITHMIC>,<$gmp_cv_asm_align_log>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_ALIGN_FILL_0x90
Packit 5c3484
dnl  -----------------------
Packit 5c3484
dnl  Determine whether a ",0x90" suffix works on a .align directive.
Packit 5c3484
dnl  This is only meant for use on x86, 0x90 being a "nop".
Packit 5c3484
dnl
Packit 5c3484
dnl  Old gas, eg. 1.92.3
Packit 5c3484
dnl       Needs ",0x90" or else the fill is 0x00, which can't be executed
Packit 5c3484
dnl       across.
Packit 5c3484
dnl
Packit 5c3484
dnl  New gas, eg. 2.91
Packit 5c3484
dnl       Generates multi-byte nop fills even when ",0x90" is given.
Packit 5c3484
dnl
Packit 5c3484
dnl  Solaris 2.6 as
Packit 5c3484
dnl       ",0x90" is not allowed, causes a fatal error.
Packit 5c3484
dnl
Packit 5c3484
dnl  Solaris 2.8 as
Packit 5c3484
dnl       ",0x90" does nothing, generates a warning that it's being ignored.
Packit 5c3484
dnl
Packit 5c3484
dnl  SCO OpenServer 5 as
Packit 5c3484
dnl       Second parameter is max bytes to fill, not a fill pattern.
Packit 5c3484
dnl       ",0x90" is an error due to being bigger than the first parameter.
Packit 5c3484
dnl       Multi-byte nop fills are generated in text segments.
Packit 5c3484
dnl
Packit 5c3484
dnl  Note that both solaris "as"s only care about ",0x90" if they actually
Packit 5c3484
dnl  have to use it to fill something, hence the .byte in the test.  It's
Packit 5c3484
dnl  the second .align which provokes the error or warning.
Packit 5c3484
dnl
Packit 5c3484
dnl  The warning from solaris 2.8 is suppressed to stop anyone worrying that
Packit 5c3484
dnl  something might be wrong.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_ALIGN_FILL_0x90],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
Packit 5c3484
               gmp_cv_asm_align_fill_0x90,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[      	$gmp_cv_asm_text
Packit 5c3484
      	.align  4, 0x90
Packit 5c3484
	.byte   0
Packit 5c3484
      	.align  4, 0x90],
Packit 5c3484
[if grep "Warning: Fill parameter ignored for executable section" conftest.out >/dev/null; then
Packit 5c3484
  echo "Suppressing this warning by omitting 0x90" 1>&AC_FD_CC
Packit 5c3484
  gmp_cv_asm_align_fill_0x90=no
Packit 5c3484
else
Packit 5c3484
  gmp_cv_asm_align_fill_0x90=yes
Packit 5c3484
fi],
Packit 5c3484
[gmp_cv_asm_align_fill_0x90=no])])
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<ALIGN_FILL_0x90>,<$gmp_cv_asm_align_fill_0x90>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_BYTE
Packit 5c3484
dnl  ------------
Packit 5c3484
dnl  .byte - is usual.
Packit 5c3484
dnl  data1 - required by ia64 (on hpux at least).
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro is just to support other configure tests, not any actual asm
Packit 5c3484
dnl  code.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_BYTE],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_CACHE_CHECK([for assembler byte directive],
Packit 5c3484
                gmp_cv_asm_byte,
Packit 5c3484
[for i in .byte data1; do
Packit 5c3484
  echo "trying $i" >&AC_FD_CC
Packit 5c3484
  GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_data
Packit 5c3484
	$i	0
Packit 5c3484
],
Packit 5c3484
    [gmp_cv_asm_byte=$i
Packit 5c3484
     rm -f conftest*
Packit 5c3484
     break],
Packit 5c3484
    [cat conftest.out >&AC_FD_CC])
Packit 5c3484
done
Packit 5c3484
if test -z "$gmp_cv_asm_byte"; then
Packit 5c3484
  AC_MSG_ERROR([Cannot determine how to emit a data byte])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_TEXT
Packit 5c3484
dnl  ------------
Packit 5c3484
dnl  .text - is usual.
Packit 5c3484
dnl  .code - is needed by the hppa on HP-UX (but ia64 HP-UX uses .text)
Packit 5c3484
dnl  .csect .text[PR] - is for AIX.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_TEXT],
Packit 5c3484
[AC_CACHE_CHECK([how to switch to text section],
Packit 5c3484
                gmp_cv_asm_text,
Packit 5c3484
[for i in ".text" ".code" [".csect .text[PR]"]; do
Packit 5c3484
  echo "trying $i" >&AC_FD_CC
Packit 5c3484
  GMP_TRY_ASSEMBLE([	$i],
Packit 5c3484
    [gmp_cv_asm_text=$i
Packit 5c3484
     rm -f conftest*
Packit 5c3484
     break])
Packit 5c3484
done
Packit 5c3484
if test -z "$gmp_cv_asm_text"; then
Packit 5c3484
  AC_MSG_ERROR([Cannot determine text section directive])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
echo ["define(<TEXT>, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_DATA
Packit 5c3484
dnl  ------------
Packit 5c3484
dnl  Can we say `.data'?
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_DATA],
Packit 5c3484
[AC_CACHE_CHECK([how to switch to data section],
Packit 5c3484
                gmp_cv_asm_data,
Packit 5c3484
[case $host in
Packit 5c3484
  *-*-aix*) gmp_cv_asm_data=[".csect .data[RW]"] ;;
Packit 5c3484
  *)        gmp_cv_asm_data=".data" ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
echo ["define(<DATA>, <$gmp_cv_asm_data>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_RODATA
Packit 5c3484
dnl  --------------
Packit 5c3484
dnl  Find out how to switch to the read-only data section.
Packit 5c3484
dnl
Packit 5c3484
dnl  The compiler output is grepped for the right directive.  It's not
Packit 5c3484
dnl  considered wise to just probe for ".section .rodata" or whatever works,
Packit 5c3484
dnl  since arbitrary section names might be accepted, but not necessarily do
Packit 5c3484
dnl  the right thing when they get to the linker.
Packit 5c3484
dnl
Packit 5c3484
dnl  Only a few asm files use RODATA, so this code is perhaps a bit
Packit 5c3484
dnl  excessive right now, but should find more uses in the future.
Packit 5c3484
dnl
Packit 5c3484
dnl  FIXME: gcc on aix generates something like ".csect _foo.ro_c[RO],3"
Packit 5c3484
dnl  where foo is the object file.  Might need to check for that if we use
Packit 5c3484
dnl  RODATA there.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_RODATA],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_REQUIRE([GMP_ASM_DATA])
Packit 5c3484
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_REQUIRE([GMP_ASM_UNDERSCORE])
Packit 5c3484
AC_CACHE_CHECK([how to switch to read-only data section],
Packit 5c3484
               gmp_cv_asm_rodata,
Packit 5c3484
[
Packit 5c3484
dnl Default to DATA on CPUs with split code/data caching, and TEXT
Packit 5c3484
dnl elsewhere.  i386 means generic x86, so use DATA on it.
Packit 5c3484
case $host in
Packit 5c3484
X86_PATTERN | x86_64-*-*)
Packit 5c3484
  gmp_cv_asm_rodata="$gmp_cv_asm_data" ;;
Packit 5c3484
*)
Packit 5c3484
  gmp_cv_asm_rodata="$gmp_cv_asm_text" ;;
Packit 5c3484
esac
Packit 5c3484
Packit 5c3484
cat >conftest.c <
Packit 5c3484
extern const int foo[[]];		/* Suppresses C++'s suppression of foo */
Packit 5c3484
const int foo[[]] = {1,2,3};
Packit 5c3484
EOF
Packit 5c3484
echo "Test program:" >&AC_FD_CC
Packit 5c3484
cat conftest.c >&AC_FD_CC
Packit 5c3484
gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  echo "Compiler output:" >&AC_FD_CC
Packit 5c3484
  cat conftest.s >&AC_FD_CC
Packit 5c3484
  if test $gmp_cv_asm_underscore = yes; then
Packit 5c3484
    tmp_gsym_prefix=_
Packit 5c3484
  else
Packit 5c3484
    tmp_gsym_prefix=
Packit 5c3484
  fi
Packit 5c3484
  # must see our label
Packit 5c3484
  if grep "^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" conftest.s >/dev/null 2>&AC_FD_CC; then
Packit 5c3484
    # take the last directive before our label (hence skipping segments
Packit 5c3484
    # getting debugging info etc)
Packit 5c3484
    tmp_match=`sed -n ["/^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix/q
Packit 5c3484
                        /^[. 	]*data/p
Packit 5c3484
                        /^[. 	]*rdata/p
Packit 5c3484
                        /^[. 	]*text/p
Packit 5c3484
                        /^[. 	]*section/p
Packit 5c3484
                        /^[. 	]*csect/p
Packit 5c3484
                        /^[. 	]*CSECT/p"] conftest.s | sed -n '$p'`
Packit 5c3484
    echo "Match: $tmp_match" >&AC_FD_CC
Packit 5c3484
    if test -n "$tmp_match"; then
Packit 5c3484
      gmp_cv_asm_rodata=$tmp_match
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    echo "Couldn't find label: ^${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix" >&AC_FD_CC
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
echo ["define(<RODATA>, <$gmp_cv_asm_rodata>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_GLOBL
Packit 5c3484
dnl  -------------
Packit 5c3484
dnl  The assembler directive to mark a label as a global symbol.
Packit 5c3484
dnl
Packit 5c3484
dnl  ia64 - .global is standard, according to the Intel documentation.
Packit 5c3484
dnl
Packit 5c3484
dnl  hppa - ".export foo,entry" is demanded by HP hppa "as".  ".global" is a
Packit 5c3484
dnl      kind of import.
Packit 5c3484
dnl
Packit 5c3484
dnl  other - .globl is usual.
Packit 5c3484
dnl
Packit 5c3484
dnl  "gas" tends to accept .globl everywhere, in addition to .export or
Packit 5c3484
dnl  .global or whatever the system assembler demands.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_GLOBL],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([for assembler global directive],
Packit 5c3484
                gmp_cv_asm_globl,
Packit 5c3484
[case $host in
Packit 5c3484
  hppa*-*-*)     gmp_cv_asm_globl=.export ;;
Packit 5c3484
  IA64_PATTERN)  gmp_cv_asm_globl=.global ;;
Packit 5c3484
  *)             gmp_cv_asm_globl=.globl  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
echo ["define(<GLOBL>, <$gmp_cv_asm_globl>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_GLOBL_ATTR
Packit 5c3484
dnl  ------------------
Packit 5c3484
dnl  Do we need something after `GLOBL symbol'?
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_GLOBL_ATTR],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_GLOBL])
Packit 5c3484
AC_CACHE_CHECK([for assembler global directive attribute],
Packit 5c3484
                gmp_cv_asm_globl_attr,
Packit 5c3484
[case $gmp_cv_asm_globl in
Packit 5c3484
  .export) gmp_cv_asm_globl_attr=",entry" ;;
Packit 5c3484
  *)       gmp_cv_asm_globl_attr="" ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
echo ["define(<GLOBL_ATTR>, <$gmp_cv_asm_globl_attr>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_TYPE
Packit 5c3484
dnl  ------------
Packit 5c3484
dnl  Can we say ".type", and how?
Packit 5c3484
dnl
Packit 5c3484
dnl  For i386 GNU/Linux ELF systems, and very likely other ELF systems,
Packit 5c3484
dnl  .type and .size are important on functions in shared libraries.  If
Packit 5c3484
dnl  .type is omitted and the mainline program references that function then
Packit 5c3484
dnl  the code will be copied down to the mainline at load time like a piece
Packit 5c3484
dnl  of data.  If .size is wrong or missing (it defaults to 4 bytes or some
Packit 5c3484
dnl  such) then incorrect bytes will be copied and a segv is the most likely
Packit 5c3484
dnl  result.  In any case such copying is not what's wanted, a .type
Packit 5c3484
dnl  directive will ensure a PLT entry is used.
Packit 5c3484
dnl
Packit 5c3484
dnl  In GMP the assembler functions are normally only used from within the
Packit 5c3484
dnl  library (since most programs are not interested in the low level
Packit 5c3484
dnl  routines), and in those circumstances a missing .type isn't fatal,
Packit 5c3484
dnl  letting the problem go unnoticed.  tests/mpn/t-asmtype.c aims to check
Packit 5c3484
dnl  for it.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_TYPE],
Packit 5c3484
[AC_CACHE_CHECK([for assembler .type directive],
Packit 5c3484
                gmp_cv_asm_type,
Packit 5c3484
[gmp_cv_asm_type=
Packit 5c3484
for gmp_tmp_prefix in @ \# %; do
Packit 5c3484
  GMP_TRY_ASSEMBLE([	.type	sym,${gmp_tmp_prefix}function],
Packit 5c3484
    [if grep "\.type pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
Packit 5c3484
    else
Packit 5c3484
      gmp_cv_asm_type=".type	\$][1,${gmp_tmp_prefix}\$][2"
Packit 5c3484
      break
Packit 5c3484
    fi])
Packit 5c3484
done
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
echo ["define(<TYPE>, <$gmp_cv_asm_type>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_SIZE
Packit 5c3484
dnl  ------------
Packit 5c3484
dnl  Can we say `.size'?
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_SIZE],
Packit 5c3484
[AC_CACHE_CHECK([for assembler .size directive],
Packit 5c3484
                gmp_cv_asm_size,
Packit 5c3484
[gmp_cv_asm_size=
Packit 5c3484
GMP_TRY_ASSEMBLE([	.size	sym,1],
Packit 5c3484
  [if grep "\.size pseudo-op used outside of \.def/\.endef ignored" conftest.out >/dev/null; then : ;
Packit 5c3484
  else
Packit 5c3484
    gmp_cv_asm_size=".size	\$][1,\$][2"
Packit 5c3484
  fi])
Packit 5c3484
])
Packit 5c3484
echo ["define(<SIZE>, <$gmp_cv_asm_size>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_COFF_TYPE
Packit 5c3484
dnl  -----------------
Packit 5c3484
dnl  Determine whether the assembler supports COFF type information.
Packit 5c3484
dnl
Packit 5c3484
dnl  Currently this is only needed for mingw (and cygwin perhaps) and so is
Packit 5c3484
dnl  run only on the x86s, but it ought to work anywhere.
Packit 5c3484
dnl
Packit 5c3484
dnl  On MINGW, recent versions of the linker have an automatic import scheme
Packit 5c3484
dnl  for data in a DLL which is referenced by a mainline but without
Packit 5c3484
dnl  __declspec (__dllimport__) on the prototype.  It seems functions
Packit 5c3484
dnl  without type information are treated as data, or something, and calls
Packit 5c3484
dnl  to them from the mainline will crash.  gcc puts type information on the
Packit 5c3484
dnl  C functions it generates, we need to do the same for assembler
Packit 5c3484
dnl  functions.
Packit 5c3484
dnl
Packit 5c3484
dnl  This applies only to functions without __declspec(__dllimport__),
Packit 5c3484
dnl  ie. without __GMP_DECLSPEC in the case of libgmp, so it also works just
Packit 5c3484
dnl  to ensure all assembler functions used from outside libgmp have
Packit 5c3484
dnl  __GMP_DECLSPEC on their prototypes.  But this isn't an ideal situation,
Packit 5c3484
dnl  since we don't want perfectly valid calls going wrong just because
Packit 5c3484
dnl  there wasn't a prototype in scope.
Packit 5c3484
dnl
Packit 5c3484
dnl  When an auto-import takes place, the following warning is given by the
Packit 5c3484
dnl  linker.  This shouldn't be seen for any functions.
Packit 5c3484
dnl
Packit 5c3484
dnl      Info: resolving _foo by linking to __imp__foo (auto-import)
Packit 5c3484
dnl
Packit 5c3484
dnl
Packit 5c3484
dnl  COFF type directives look like the following
Packit 5c3484
dnl
Packit 5c3484
dnl      .def    _foo
Packit 5c3484
dnl      .scl    2
Packit 5c3484
dnl      .type   32
Packit 5c3484
dnl      .endef
Packit 5c3484
dnl
Packit 5c3484
dnl  _foo is the symbol with GSYM_PREFIX (_).  .scl is the storage class, 2
Packit 5c3484
dnl  for external, 3 for static.  .type is the object type, 32 for a
Packit 5c3484
dnl  function.
Packit 5c3484
dnl
Packit 5c3484
dnl  On an ELF system, this is (correctly) rejected due to .def, .endef and
Packit 5c3484
dnl  .scl being invalid, and .type not having enough arguments.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_COFF_TYPE],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_REQUIRE([GMP_ASM_GLOBL])
Packit 5c3484
AC_REQUIRE([GMP_ASM_GLOBL_ATTR])
Packit 5c3484
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_REQUIRE([GMP_ASM_UNDERSCORE])
Packit 5c3484
AC_CACHE_CHECK([for assembler COFF type directives],
Packit 5c3484
		gmp_cv_asm_x86_coff_type,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	$gmp_cv_asm_globl ${tmp_gsym_prefix}foo$gmp_cv_asm_globl_attr
Packit 5c3484
	.def	${tmp_gsym_prefix}foo
Packit 5c3484
	.scl	2
Packit 5c3484
	.type	32
Packit 5c3484
	.endef
Packit 5c3484
${tmp_gsym_prefix}foo$gmp_cv_asm_label_suffix
Packit 5c3484
],
Packit 5c3484
  [gmp_cv_asm_x86_coff_type=yes],
Packit 5c3484
  [gmp_cv_asm_x86_coff_type=no])
Packit 5c3484
])
Packit 5c3484
echo ["define(<HAVE_COFF_TYPE>, <$gmp_cv_asm_x86_coff_type>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_LSYM_PREFIX
Packit 5c3484
dnl  -------------------
Packit 5c3484
dnl  What is the prefix for a local label?
Packit 5c3484
dnl
Packit 5c3484
dnl  The prefixes tested are,
Packit 5c3484
dnl
Packit 5c3484
dnl      L  - usual for underscore systems
Packit 5c3484
dnl      .L - usual for non-underscore systems
Packit 5c3484
dnl      $  - alpha (gas and OSF system assembler)
Packit 5c3484
dnl      L$ - hppa (gas and HP-UX system assembler)
Packit 5c3484
dnl
Packit 5c3484
dnl  The default is "L" if the tests fail for any reason.  There's a good
Packit 5c3484
dnl  chance this will be adequate, since on most systems labels are local
Packit 5c3484
dnl  anyway unless given a ".globl", and an "L" will avoid clashes with
Packit 5c3484
dnl  other identifers.
Packit 5c3484
dnl
Packit 5c3484
dnl  For gas, ".L" is normally purely local to the assembler, it doesn't get
Packit 5c3484
dnl  put into the object file at all.  This style is preferred, to keep the
Packit 5c3484
dnl  object files nice and clean.
Packit 5c3484
dnl
Packit 5c3484
dnl  BSD format nm produces a line like
Packit 5c3484
dnl
Packit 5c3484
dnl      00000000 t Lgurkmacka
Packit 5c3484
dnl
Packit 5c3484
dnl  The symbol code is normally "t" for text, but any lower case letter
Packit 5c3484
dnl  indicates a local definition.
Packit 5c3484
dnl
Packit 5c3484
dnl  Code "n" is for a debugging symbol, OSF "nm -B" gives that as an upper
Packit 5c3484
dnl  case "N" for a local.
Packit 5c3484
dnl
Packit 5c3484
dnl  HP-UX nm prints an error message (though seems to give a 0 exit) if
Packit 5c3484
dnl  there's no symbols at all in an object file, hence the use of "dummy".
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_LSYM_PREFIX],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_REQUIRE([GMP_PROG_NM])
Packit 5c3484
AC_CACHE_CHECK([for assembler local label prefix],
Packit 5c3484
               gmp_cv_asm_lsym_prefix,
Packit 5c3484
[gmp_tmp_pre_appears=yes
Packit 5c3484
for gmp_tmp_pre in L .L $L $ L$; do
Packit 5c3484
  echo "Trying $gmp_tmp_pre" >&AC_FD_CC
Packit 5c3484
  GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
dummy${gmp_cv_asm_label_suffix}
Packit 5c3484
${gmp_tmp_pre}gurkmacka${gmp_cv_asm_label_suffix}],
Packit 5c3484
  [if $NM conftest.$OBJEXT >conftest.nm 2>&AC_FD_CC; then : ; else
Packit 5c3484
    cat conftest.nm >&AC_FD_CC
Packit 5c3484
    AC_MSG_WARN(["$NM" failure])
Packit 5c3484
    break
Packit 5c3484
  fi
Packit 5c3484
  cat conftest.nm >&AC_FD_CC
Packit 5c3484
  if grep gurkmacka conftest.nm >/dev/null; then : ; else
Packit 5c3484
    # no mention of the symbol, this is good
Packit 5c3484
    echo "$gmp_tmp_pre label doesn't appear in object file at all (good)" >&AC_FD_CC
Packit 5c3484
    gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
Packit 5c3484
    gmp_tmp_pre_appears=no
Packit 5c3484
    break
Packit 5c3484
  fi
Packit 5c3484
  if grep [' [a-zN] .*gurkmacka'] conftest.nm >/dev/null; then
Packit 5c3484
    # symbol mentioned as a local, use this if nothing better
Packit 5c3484
    echo "$gmp_tmp_pre label is local but still in object file" >&AC_FD_CC
Packit 5c3484
    if test -z "$gmp_cv_asm_lsym_prefix"; then
Packit 5c3484
      gmp_cv_asm_lsym_prefix="$gmp_tmp_pre"
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    echo "$gmp_tmp_pre label is something unknown" >&AC_FD_CC
Packit 5c3484
  fi
Packit 5c3484
  ])
Packit 5c3484
done
Packit 5c3484
rm -f conftest*
Packit 5c3484
if test -z "$gmp_cv_asm_lsym_prefix"; then
Packit 5c3484
  gmp_cv_asm_lsym_prefix=L
Packit 5c3484
  AC_MSG_WARN([cannot determine local label, using default $gmp_cv_asm_lsym_prefix])
Packit 5c3484
fi
Packit 5c3484
# for development purposes, note whether we got a purely temporary local label
Packit 5c3484
echo "Local label appears in object files: $gmp_tmp_pre_appears" >&AC_FD_CC
Packit 5c3484
])
Packit 5c3484
echo ["define(<LSYM_PREFIX>, <${gmp_cv_asm_lsym_prefix}>)"] >> $gmp_tmpconfigm4
Packit 5c3484
AC_DEFINE_UNQUOTED(LSYM_PREFIX, "$gmp_cv_asm_lsym_prefix",
Packit 5c3484
                   [Assembler local label prefix])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_W32
Packit 5c3484
dnl  -----------
Packit 5c3484
dnl  How to define a 32-bit word.
Packit 5c3484
dnl
Packit 5c3484
dnl  FIXME: This test is not right for ia64-*-hpux*.  The directive should
Packit 5c3484
dnl  be "data4", but the W32 macro is not currently used by the mpn/ia64 asm
Packit 5c3484
dnl  files.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_W32],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_DATA])
Packit 5c3484
AC_REQUIRE([GMP_ASM_BYTE])
Packit 5c3484
AC_REQUIRE([GMP_ASM_GLOBL])
Packit 5c3484
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_REQUIRE([GMP_PROG_NM])
Packit 5c3484
AC_CACHE_CHECK([how to define a 32-bit word],
Packit 5c3484
	       gmp_cv_asm_w32,
Packit 5c3484
[case $host in
Packit 5c3484
  *-*-hpux*)
Packit 5c3484
    # FIXME: HPUX puts first symbol at 0x40000000, breaking our assumption
Packit 5c3484
    # that it's at 0x0.  We'll have to declare another symbol before the
Packit 5c3484
    # .long/.word and look at the distance between the two symbols.  The
Packit 5c3484
    # only problem is that the sed expression(s) barfs (on Solaris, for
Packit 5c3484
    # example) for the symbol with value 0.  For now, HPUX uses .word.
Packit 5c3484
    gmp_cv_asm_w32=".word"
Packit 5c3484
    ;;
Packit 5c3484
  *-*-*)
Packit 5c3484
    gmp_tmp_val=
Packit 5c3484
    for gmp_tmp_op in .long .word data4; do
Packit 5c3484
      GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_data
Packit 5c3484
	$gmp_cv_asm_globl	foo
Packit 5c3484
	$gmp_tmp_op	0
Packit 5c3484
foo$gmp_cv_asm_label_suffix
Packit 5c3484
	$gmp_cv_asm_byte	0],
Packit 5c3484
        [gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
Packit 5c3484
          sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
Packit 5c3484
        if test "$gmp_tmp_val" = 4; then
Packit 5c3484
          gmp_cv_asm_w32="$gmp_tmp_op"
Packit 5c3484
          break
Packit 5c3484
        fi])
Packit 5c3484
    done
Packit 5c3484
    rm -f conftest*
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
if test -z "$gmp_cv_asm_w32"; then
Packit 5c3484
  AC_MSG_ERROR([cannot determine how to define a 32-bit word])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
echo ["define(<W32>, <$gmp_cv_asm_w32>)"] >> $gmp_tmpconfigm4
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_X86_ASM_GOT_UNDERSCORE
Packit 5c3484
dnl  --------------------------
Packit 5c3484
dnl  Determine whether i386 _GLOBAL_OFFSET_TABLE_ needs an additional
Packit 5c3484
dnl  underscore prefix.
Packit 5c3484
dnl
Packit 5c3484
dnl    SVR4      - the standard is _GLOBAL_OFFSET_TABLE_
Packit 5c3484
dnl    GNU/Linux - follows SVR4
Packit 5c3484
dnl    OpenBSD   - an a.out underscore system, uses __GLOBAL_OFFSET_TABLE_
Packit 5c3484
dnl    NetBSD    - also an a.out underscore system, but _GLOBAL_OFFSET_TABLE_
Packit 5c3484
dnl
Packit 5c3484
dnl  The test attempts to link a program using _GLOBAL_OFFSET_TABLE_ or
Packit 5c3484
dnl  __GLOBAL_OFFSET_TABLE_ to see which works.
Packit 5c3484
dnl
Packit 5c3484
dnl  $lt_prog_compiler_pic is included in the compile because old versions
Packit 5c3484
dnl  of gas wouldn't accept PIC idioms without the right option (-K).  This
Packit 5c3484
dnl  is the same as what libtool and mpn/Makeasm.am will do.
Packit 5c3484
dnl
Packit 5c3484
dnl  $lt_prog_compiler_pic is also included in the link because OpenBSD ld
Packit 5c3484
dnl  won't accept an R_386_GOTPC relocation without the right options.  This
Packit 5c3484
dnl  is not what's done by the Makefiles when building executables, but
Packit 5c3484
dnl  let's hope it's ok (it works fine with gcc).
Packit 5c3484
dnl
Packit 5c3484
dnl  The fallback is no additional underscore, on the basis that this will
Packit 5c3484
dnl  suit SVR4/ELF style systems, which should be much more common than
Packit 5c3484
dnl  a.out systems with shared libraries.
Packit 5c3484
dnl
Packit 5c3484
dnl  Note that it's not an error for the tests to fail, since for instance
Packit 5c3484
dnl  cygwin, mingw and djgpp don't have a _GLOBAL_OFFSET_TABLE_ scheme at
Packit 5c3484
dnl  all.
Packit 5c3484
dnl
Packit 5c3484
dnl  Perhaps $CCAS could be asked to do the linking as well as the
Packit 5c3484
dnl  assembling, but in the Makefiles it's only used for assembling, so lets
Packit 5c3484
dnl  keep it that way.
Packit 5c3484
dnl
Packit 5c3484
dnl  The test here is run even under --disable-shared, so that PIC objects
Packit 5c3484
dnl  can be built and tested by the tune/many.pl development scheme.  The
Packit 5c3484
dnl  tests will be reasonably quick and won't give a fatal error, so this
Packit 5c3484
dnl  arrangement is ok.  AC_LIBTOOL_PROG_COMPILER_PIC does its
Packit 5c3484
dnl  $lt_prog_compiler_pic setups even for --disable-shared too.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_GOT_UNDERSCORE],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_REQUIRE([GMP_ASM_GLOBL])
Packit 5c3484
AC_REQUIRE([GMP_ASM_GLOBL_ATTR])
Packit 5c3484
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
Packit 5c3484
AC_REQUIRE([GMP_ASM_UNDERSCORE])
Packit 5c3484
AC_REQUIRE([AC_LIBTOOL_PROG_COMPILER_PIC])
Packit 5c3484
AC_CACHE_CHECK([if _GLOBAL_OFFSET_TABLE_ is prefixed by underscore],
Packit 5c3484
               gmp_cv_asm_x86_got_underscore,
Packit 5c3484
[gmp_cv_asm_x86_got_underscore="not applicable"
Packit 5c3484
if test $gmp_cv_asm_underscore = yes; then
Packit 5c3484
  tmp_gsym_prefix=_
Packit 5c3484
else
Packit 5c3484
  tmp_gsym_prefix=
Packit 5c3484
fi
Packit 5c3484
for tmp_underscore in "" "_"; do
Packit 5c3484
  cat >conftest.s <
Packit 5c3484
	$gmp_cv_asm_text
Packit 5c3484
	$gmp_cv_asm_globl ${tmp_gsym_prefix}main$gmp_cv_asm_globl_attr
Packit 5c3484
${tmp_gsym_prefix}main$gmp_cv_asm_label_suffix
Packit 5c3484
	addl	$ ${tmp_underscore}_GLOBAL_OFFSET_TABLE_, %ebx
Packit 5c3484
EOF
Packit 5c3484
  gmp_compile="$CCAS $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.s >&AC_FD_CC && $CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic conftest.$OBJEXT >&AC_FD_CC"
Packit 5c3484
  if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
    if test "$tmp_underscore" = "_"; then
Packit 5c3484
      gmp_cv_asm_x86_got_underscore=yes
Packit 5c3484
    else
Packit 5c3484
      gmp_cv_asm_x86_got_underscore=no
Packit 5c3484
    fi
Packit 5c3484
    break
Packit 5c3484
  fi
Packit 5c3484
done
Packit 5c3484
rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
])
Packit 5c3484
if test "$gmp_cv_asm_x86_got_underscore" = "yes"; then
Packit 5c3484
  GMP_DEFINE(GOT_GSYM_PREFIX, [_])
Packit 5c3484
else
Packit 5c3484
  GMP_DEFINE(GOT_GSYM_PREFIX, [])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_GOT_EAX_OK(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
Packit 5c3484
dnl  -------------------------------------------------------------
Packit 5c3484
dnl  Determine whether _GLOBAL_OFFSET_TABLE_ used with %eax is ok.
Packit 5c3484
dnl
Packit 5c3484
dnl  An instruction
Packit 5c3484
dnl
Packit 5c3484
dnl          addl  $_GLOBAL_OFFSET_TABLE_, %eax
Packit 5c3484
dnl
Packit 5c3484
dnl  is incorrectly assembled by gas 2.12 (or thereabouts) and earlier.  It
Packit 5c3484
dnl  puts an addend 2 into the R_386_GOTPC relocation, but it should be 1
Packit 5c3484
dnl  for this %eax form being a 1 byte opcode (with other registers it's 2
Packit 5c3484
dnl  opcode bytes).  See note about this in mpn/x86/README too.
Packit 5c3484
dnl
Packit 5c3484
dnl  We assemble this, surrounded by some unlikely byte sequences as
Packit 5c3484
dnl  delimiters, and check for the bad output.
Packit 5c3484
dnl
Packit 5c3484
dnl  This is for use by compiler probing in GMP_PROG_CC_WORKS, so the result
Packit 5c3484
dnl  is not cached.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is not specific to gas, but old gas is the only assembler we
Packit 5c3484
dnl  know of with this problem.  The Solaris has been seen coming out ok.
Packit 5c3484
dnl
Packit 5c3484
dnl  ".text" is hard coded because this macro is wanted before GMP_ASM_TEXT.
Packit 5c3484
dnl  This should be fine, ".text" is normal on x86 systems, and certainly
Packit 5c3484
dnl  will be fine with the offending gas.
Packit 5c3484
dnl
Packit 5c3484
dnl  If an error occurs when assembling, we consider the assembler ok, since
Packit 5c3484
dnl  the bad output does not occur.  This happens for instance on mingw,
Packit 5c3484
dnl  where _GLOBAL_OFFSET_TABLE_ results in a bfd error, since there's no
Packit 5c3484
dnl  GOT etc in PE object files.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test is used before the object file extension has been determined,
Packit 5c3484
dnl  so we force output to conftest.o.  Using -o with -c is not portable,
Packit 5c3484
dnl  but we think all x86 compilers will accept -o with -c, certainly gcc
Packit 5c3484
dnl  does.
Packit 5c3484
dnl
Packit 5c3484
dnl  -fPIC is hard coded here, because this test is for use before libtool
Packit 5c3484
dnl  has established the pic options.  It's right for gcc, but perhaps not
Packit 5c3484
dnl  other compilers.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_GOT_EAX_OK],
Packit 5c3484
[echo "Testing gas GOT with eax good" >&AC_FD_CC
Packit 5c3484
cat >conftest.awk <<\EOF
Packit 5c3484
[BEGIN {
Packit 5c3484
  want[0]  = "001"
Packit 5c3484
  want[1]  = "043"
Packit 5c3484
  want[2]  = "105"
Packit 5c3484
  want[3]  = "147"
Packit 5c3484
  want[4]  = "211"
Packit 5c3484
  want[5]  = "253"
Packit 5c3484
  want[6]  = "315"
Packit 5c3484
  want[7]  = "357"
Packit 5c3484
Packit 5c3484
  want[8]  = "005"
Packit 5c3484
  want[9]  = "002"
Packit 5c3484
  want[10] = "000"
Packit 5c3484
  want[11] = "000"
Packit 5c3484
  want[12] = "000"
Packit 5c3484
Packit 5c3484
  want[13] = "376"
Packit 5c3484
  want[14] = "334"
Packit 5c3484
  want[15] = "272"
Packit 5c3484
  want[16] = "230"
Packit 5c3484
  want[17] = "166"
Packit 5c3484
  want[18] = "124"
Packit 5c3484
  want[19] = "062"
Packit 5c3484
  want[20] = "020"
Packit 5c3484
Packit 5c3484
  result = "yes"
Packit 5c3484
}
Packit 5c3484
{
Packit 5c3484
  for (f = 2; f <= NF; f++)
Packit 5c3484
    {
Packit 5c3484
      for (i = 0; i < 20; i++)
Packit 5c3484
        got[i] = got[i+1];
Packit 5c3484
      got[20] = $f;
Packit 5c3484
Packit 5c3484
      found = 1
Packit 5c3484
      for (i = 0; i < 21; i++)
Packit 5c3484
        if (got[i] != want[i])
Packit 5c3484
          {
Packit 5c3484
            found = 0
Packit 5c3484
            break
Packit 5c3484
          }
Packit 5c3484
      if (found)
Packit 5c3484
        {
Packit 5c3484
          result = "no"
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
    }
Packit 5c3484
}
Packit 5c3484
END {
Packit 5c3484
  print result
Packit 5c3484
}
Packit 5c3484
]EOF
Packit 5c3484
cat >conftest.s <<\EOF
Packit 5c3484
[	.text
Packit 5c3484
	.byte	1, 35, 69, 103, 137, 171, 205, 239
Packit 5c3484
	addl	$_GLOBAL_OFFSET_TABLE_, %eax
Packit 5c3484
	.byte	254, 220, 186, 152, 118, 84, 50, 16
Packit 5c3484
]EOF
Packit 5c3484
tmp_got_good=yes
Packit 5c3484
gmp_compile="$1 -fPIC -o conftest.o -c conftest.s >&AC_FD_CC 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  tmp_got_good=`od -b conftest.o | $AWK -f conftest.awk`
Packit 5c3484
fi
Packit 5c3484
rm -f conftest.*
Packit 5c3484
echo "Result: $tmp_got_good" >&AC_FD_CC
Packit 5c3484
if test "$tmp_got_good" = no; then
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
else
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_MMX([ACTION-IF-YES][,ACTION-IF-NO])
Packit 5c3484
dnl  -----------------------------------------------
Packit 5c3484
dnl  Determine whether the assembler supports MMX instructions.
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
Packit 5c3484
dnl  here.  ".text" is believed to be correct on all x86 systems.  Actually
Packit 5c3484
dnl  ".text" probably isn't needed at all, at least for just checking
Packit 5c3484
dnl  instruction syntax.
Packit 5c3484
dnl
Packit 5c3484
dnl  "movq %mm0, %mm1" should assemble to "0f 6f c8", but Solaris 2.6 and
Packit 5c3484
dnl  2.7 wrongly assemble it to "0f 6f c1" (that being the reverse "movq
Packit 5c3484
dnl  %mm1, %mm0").  It seems more trouble than it's worth to work around
Packit 5c3484
dnl  this in the code, so just detect and reject.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_MMX],
Packit 5c3484
[AC_CACHE_CHECK([if the assembler knows about MMX instructions],
Packit 5c3484
		gmp_cv_asm_x86_mmx,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	.text
Packit 5c3484
	movq	%mm0, %mm1],
Packit 5c3484
[gmp_cv_asm_x86_mmx=yes
Packit 5c3484
case $host in
Packit 5c3484
*-*-solaris*)
Packit 5c3484
  if (dis conftest.$OBJEXT >conftest.out) 2>/dev/null; then
Packit 5c3484
    if grep "0f 6f c1" conftest.out >/dev/null; then
Packit 5c3484
      gmp_cv_asm_x86_mmx=movq-bug
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    AC_MSG_WARN(["dis" not available to check for "as" movq bug])
Packit 5c3484
  fi
Packit 5c3484
esac],
Packit 5c3484
[gmp_cv_asm_x86_mmx=no])])
Packit 5c3484
Packit 5c3484
case $gmp_cv_asm_x86_mmx in
Packit 5c3484
movq-bug)
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  AC_MSG_WARN([| WARNING WARNING WARNING])
Packit 5c3484
  AC_MSG_WARN([| Host CPU has MMX code, but the assembler])
Packit 5c3484
  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
Packit 5c3484
  AC_MSG_WARN([| has the Solaris 2.6 and 2.7 bug where register to register])
Packit 5c3484
  AC_MSG_WARN([| movq operands are reversed.])
Packit 5c3484
  AC_MSG_WARN([| Non-MMX replacements will be used.])
Packit 5c3484
  AC_MSG_WARN([| This will be an inferior build.])
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  ;;
Packit 5c3484
no)
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  AC_MSG_WARN([| WARNING WARNING WARNING])
Packit 5c3484
  AC_MSG_WARN([| Host CPU has MMX code, but it can't be assembled by])
Packit 5c3484
  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
Packit 5c3484
  AC_MSG_WARN([| Non-MMX replacements will be used.])
Packit 5c3484
  AC_MSG_WARN([| This will be an inferior build.])
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  ;;
Packit 5c3484
esac
Packit 5c3484
if test "$gmp_cv_asm_x86_mmx" = yes; then
Packit 5c3484
  ifelse([$1],,:,[$1])
Packit 5c3484
else
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_SHLDL_CL
Packit 5c3484
dnl  --------------------
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_SHLDL_CL],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([if the assembler takes cl with shldl],
Packit 5c3484
		gmp_cv_asm_x86_shldl_cl,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	shldl	%cl, %eax, %ebx],
Packit 5c3484
  gmp_cv_asm_x86_shldl_cl=yes,
Packit 5c3484
  gmp_cv_asm_x86_shldl_cl=no)
Packit 5c3484
])
Packit 5c3484
if test "$gmp_cv_asm_x86_shldl_cl" = "yes"; then
Packit 5c3484
  GMP_DEFINE(WANT_SHLDL_CL,1)
Packit 5c3484
else
Packit 5c3484
  GMP_DEFINE(WANT_SHLDL_CL,0)
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_SSE2([ACTION-IF-YES][,ACTION-IF-NO])
Packit 5c3484
dnl  ------------------------------------------------
Packit 5c3484
dnl  Determine whether the assembler supports SSE2 instructions.
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
Packit 5c3484
dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
Packit 5c3484
dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
Packit 5c3484
dnl  needed at all, at least for just checking instruction syntax.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_SSE2],
Packit 5c3484
[AC_CACHE_CHECK([if the assembler knows about SSE2 instructions],
Packit 5c3484
		gmp_cv_asm_x86_sse2,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	.text
Packit 5c3484
	paddq	%mm0, %mm1],
Packit 5c3484
  [gmp_cv_asm_x86_sse2=yes],
Packit 5c3484
  [gmp_cv_asm_x86_sse2=no])
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_asm_x86_sse2 in
Packit 5c3484
yes)
Packit 5c3484
  ifelse([$1],,:,[$1])
Packit 5c3484
  ;;
Packit 5c3484
*)
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  AC_MSG_WARN([| WARNING WARNING WARNING])
Packit 5c3484
  AC_MSG_WARN([| Host CPU has SSE2 code, but it can't be assembled by])
Packit 5c3484
  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
Packit 5c3484
  AC_MSG_WARN([| Non-SSE2 replacements will be used.])
Packit 5c3484
  AC_MSG_WARN([| This will be an inferior build.])
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_MULX([ACTION-IF-YES][,ACTION-IF-NO])
Packit 5c3484
dnl  ------------------------------------------------
Packit 5c3484
dnl  Determine whether the assembler supports the mulx instruction which debut
Packit 5c3484
dnl  with Haswell.
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
Packit 5c3484
dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
Packit 5c3484
dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
Packit 5c3484
dnl  needed at all, at least for just checking instruction syntax.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_MULX],
Packit 5c3484
[AC_CACHE_CHECK([if the assembler knows about the mulx instruction],
Packit 5c3484
		gmp_cv_asm_x86_mulx,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	.text
Packit 5c3484
	mulx	%r8, %r9, %r10],
Packit 5c3484
  [gmp_cv_asm_x86_mulx=yes],
Packit 5c3484
  [gmp_cv_asm_x86_mulx=no])
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_asm_x86_mulx in
Packit 5c3484
yes)
Packit 5c3484
  ifelse([$1],,:,[$1])
Packit 5c3484
  ;;
Packit 5c3484
*)
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  AC_MSG_WARN([| WARNING WARNING WARNING])
Packit 5c3484
  AC_MSG_WARN([| Host CPU has the mulx instruction, but it can't be])
Packit 5c3484
  AC_MSG_WARN([| assembled by])
Packit 5c3484
  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
Packit 5c3484
  AC_MSG_WARN([| Older x86 instructions will be used.])
Packit 5c3484
  AC_MSG_WARN([| This will be an inferior build.])
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_ADX([ACTION-IF-YES][,ACTION-IF-NO])
Packit 5c3484
dnl  ------------------------------------------------
Packit 5c3484
dnl  Determine whether the assembler supports the adcx and adox instructions
Packit 5c3484
dnl  which debut with the Haswell shrink Broadwell.
Packit 5c3484
dnl
Packit 5c3484
dnl  This macro is wanted before GMP_ASM_TEXT, so ".text" is hard coded
Packit 5c3484
dnl  here.  ".text" is believed to be correct on all x86 systems, certainly
Packit 5c3484
dnl  it's all GMP_ASM_TEXT gives currently.  Actually ".text" probably isn't
Packit 5c3484
dnl  needed at all, at least for just checking instruction syntax.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_ADX],
Packit 5c3484
[AC_CACHE_CHECK([if the assembler knows about the adox instruction],
Packit 5c3484
		gmp_cv_asm_x86_adx,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	.text
Packit 5c3484
	adox	%r8, %r9
Packit 5c3484
	adcx	%r8, %r9],
Packit 5c3484
  [gmp_cv_asm_x86_adx=yes],
Packit 5c3484
  [gmp_cv_asm_x86_adx=no])
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_asm_x86_adx in
Packit 5c3484
yes)
Packit 5c3484
  ifelse([$1],,:,[$1])
Packit 5c3484
  ;;
Packit 5c3484
*)
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  AC_MSG_WARN([| WARNING WARNING WARNING])
Packit 5c3484
  AC_MSG_WARN([| Host CPU has the adcx and adox instructions, but they])
Packit 5c3484
  AC_MSG_WARN([| can't be assembled by])
Packit 5c3484
  AC_MSG_WARN([|     $CCAS $CFLAGS $CPPFLAGS])
Packit 5c3484
  AC_MSG_WARN([| Older x86 instructions will be used.])
Packit 5c3484
  AC_MSG_WARN([| This will be an inferior build.])
Packit 5c3484
  AC_MSG_WARN([+----------------------------------------------------------])
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_X86_MCOUNT
Packit 5c3484
dnl  ------------------
Packit 5c3484
dnl  Find out how to call mcount for profiling on an x86 system.
Packit 5c3484
dnl
Packit 5c3484
dnl  A dummy function is compiled and the ".s" output examined.  The pattern
Packit 5c3484
dnl  matching might be a bit fragile, but should work at least with gcc on
Packit 5c3484
dnl  sensible systems.  Certainly it's better than hard coding a table of
Packit 5c3484
dnl  conventions.
Packit 5c3484
dnl
Packit 5c3484
dnl  For non-PIC, any ".data" is taken to mean a counter might be passed.
Packit 5c3484
dnl  It's assumed a movl will set it up, and the right register is taken
Packit 5c3484
dnl  from that movl.  Any movl involving %esp is ignored (a frame pointer
Packit 5c3484
dnl  setup normally).
Packit 5c3484
dnl
Packit 5c3484
dnl  For PIC, any ".data" is similarly interpreted, but a GOTOFF identifies
Packit 5c3484
dnl  the line setting up the right register.
Packit 5c3484
dnl
Packit 5c3484
dnl  In both cases a line with "mcount" identifies the call and that line is
Packit 5c3484
dnl  used literally.
Packit 5c3484
dnl
Packit 5c3484
dnl  On some systems (eg. FreeBSD 3.5) gcc emits ".data" but doesn't use it,
Packit 5c3484
dnl  so it's not an error to have .data but then not find a register.
Packit 5c3484
dnl
Packit 5c3484
dnl  Variations in mcount conventions on different x86 systems can be found
Packit 5c3484
dnl  in gcc config/i386.  mcount can have a "_" prefix or be .mcount or
Packit 5c3484
dnl  _mcount_ptr, and for PIC it can be called through a GOT entry, or via
Packit 5c3484
dnl  the PLT.  If a pointer to a counter is required it's passed in %eax or
Packit 5c3484
dnl  %edx.
Packit 5c3484
dnl
Packit 5c3484
dnl  Flags to specify PIC are taken from $lt_prog_compiler_pic set by
Packit 5c3484
dnl  AC_PROG_LIBTOOL.
Packit 5c3484
dnl
Packit 5c3484
dnl  Enhancement: Cache the values determined here. But what's the right way
Packit 5c3484
dnl  to get two variables (mcount_nonpic_reg and mcount_nonpic_call say) set
Packit 5c3484
dnl  from one block of commands?
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_X86_MCOUNT],
Packit 5c3484
[AC_REQUIRE([AC_ENABLE_SHARED])
Packit 5c3484
AC_REQUIRE([AC_PROG_LIBTOOL])
Packit 5c3484
AC_MSG_CHECKING([how to call x86 mcount])
Packit 5c3484
cat >conftest.c <
Packit 5c3484
foo(){bar();}
Packit 5c3484
EOF
Packit 5c3484
Packit 5c3484
if test "$enable_static" = yes; then
Packit 5c3484
  gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c 1>&AC_FD_CC"
Packit 5c3484
  if AC_TRY_EVAL(gmp_asmout_compile); then
Packit 5c3484
    if grep '\.data' conftest.s >/dev/null; then
Packit 5c3484
      mcount_nonpic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
Packit 5c3484
    else
Packit 5c3484
      mcount_nonpic_reg=
Packit 5c3484
    fi
Packit 5c3484
    mcount_nonpic_call=`grep 'call.*mcount' conftest.s`
Packit 5c3484
    if test -z "$mcount_nonpic_call"; then
Packit 5c3484
      AC_MSG_ERROR([Cannot find mcount call for non-PIC])
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    AC_MSG_ERROR([Cannot compile test program for non-PIC])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
if test "$enable_shared" = yes; then
Packit 5c3484
  gmp_asmout_compile="$CC $CFLAGS $CPPFLAGS $lt_prog_compiler_pic -S conftest.c 1>&AC_FD_CC"
Packit 5c3484
  if AC_TRY_EVAL(gmp_asmout_compile); then
Packit 5c3484
    if grep '\.data' conftest.s >/dev/null; then
Packit 5c3484
      case $lt_prog_compiler_pic in
Packit 5c3484
        *-DDLL_EXPORT*)
Packit 5c3484
          # Windows DLLs have non-PIC style mcount
Packit 5c3484
          mcount_pic_reg=`sed -n ['/esp/!s/.*movl.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
Packit 5c3484
          ;;
Packit 5c3484
        *)
Packit 5c3484
          mcount_pic_reg=`sed -n ['s/.*GOTOFF.*,\(%[a-z]*\).*$/\1/p'] conftest.s`
Packit 5c3484
          ;;
Packit 5c3484
      esac
Packit 5c3484
    else
Packit 5c3484
      mcount_pic_reg=
Packit 5c3484
    fi
Packit 5c3484
    mcount_pic_call=`grep 'call.*mcount' conftest.s`
Packit 5c3484
    if test -z "$mcount_pic_call"; then
Packit 5c3484
      AC_MSG_ERROR([Cannot find mcount call for PIC])
Packit 5c3484
    fi
Packit 5c3484
  else
Packit 5c3484
    AC_MSG_ERROR([Cannot compile test program for PIC])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_REG>, <\`$mcount_nonpic_reg'>)"])
Packit 5c3484
GMP_DEFINE_RAW(["define(<MCOUNT_NONPIC_CALL>,<\`$mcount_nonpic_call'>)"])
Packit 5c3484
GMP_DEFINE_RAW(["define(<MCOUNT_PIC_REG>,    <\`$mcount_pic_reg'>)"])
Packit 5c3484
GMP_DEFINE_RAW(["define(<MCOUNT_PIC_CALL>,   <\`$mcount_pic_call'>)"])
Packit 5c3484
Packit 5c3484
rm -f conftest.*
Packit 5c3484
AC_MSG_RESULT([determined])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_IA64_ALIGN_OK
Packit 5c3484
dnl  ---------------------
Packit 5c3484
dnl  Determine whether .align correctly pads with nop instructions in a text
Packit 5c3484
dnl  segment.
Packit 5c3484
dnl
Packit 5c3484
dnl  gas 2.14 and earlier byte swaps its padding bundle on big endian
Packit 5c3484
dnl  systems, which is incorrect (endianness only changes data).  What
Packit 5c3484
dnl  should be "nop.m / nop.f / nop.i" comes out as "break" instructions.
Packit 5c3484
dnl
Packit 5c3484
dnl  The test here detects the bad case, and assumes anything else is ok
Packit 5c3484
dnl  (there are many sensible nop bundles, so it'd be impractical to try to
Packit 5c3484
dnl  match everything good).
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_IA64_ALIGN_OK],
Packit 5c3484
[AC_CACHE_CHECK([whether assembler .align padding is good],
Packit 5c3484
		gmp_cv_asm_ia64_align_ok,
Packit 5c3484
[cat >conftest.awk <<\EOF
Packit 5c3484
[BEGIN {
Packit 5c3484
  want[0]  = "011"
Packit 5c3484
  want[1]  = "160"
Packit 5c3484
  want[2]  = "074"
Packit 5c3484
  want[3]  = "040"
Packit 5c3484
  want[4]  = "000"
Packit 5c3484
  want[5]  = "040"
Packit 5c3484
  want[6]  = "020"
Packit 5c3484
  want[7]  = "221"
Packit 5c3484
  want[8]  = "114"
Packit 5c3484
  want[9]  = "000"
Packit 5c3484
  want[10] = "100"
Packit 5c3484
  want[11] = "200"
Packit 5c3484
  want[12] = "122"
Packit 5c3484
  want[13] = "261"
Packit 5c3484
  want[14] = "000"
Packit 5c3484
  want[15] = "200"
Packit 5c3484
Packit 5c3484
  want[16] = "000"
Packit 5c3484
  want[17] = "004"
Packit 5c3484
  want[18] = "000"
Packit 5c3484
  want[19] = "000"
Packit 5c3484
  want[20] = "000"
Packit 5c3484
  want[21] = "000"
Packit 5c3484
  want[22] = "002"
Packit 5c3484
  want[23] = "000"
Packit 5c3484
  want[24] = "000"
Packit 5c3484
  want[25] = "000"
Packit 5c3484
  want[26] = "000"
Packit 5c3484
  want[27] = "001"
Packit 5c3484
  want[28] = "000"
Packit 5c3484
  want[29] = "000"
Packit 5c3484
  want[30] = "000"
Packit 5c3484
  want[31] = "014"
Packit 5c3484
Packit 5c3484
  want[32] = "011"
Packit 5c3484
  want[33] = "270"
Packit 5c3484
  want[34] = "140"
Packit 5c3484
  want[35] = "062"
Packit 5c3484
  want[36] = "000"
Packit 5c3484
  want[37] = "040"
Packit 5c3484
  want[38] = "240"
Packit 5c3484
  want[39] = "331"
Packit 5c3484
  want[40] = "160"
Packit 5c3484
  want[41] = "000"
Packit 5c3484
  want[42] = "100"
Packit 5c3484
  want[43] = "240"
Packit 5c3484
  want[44] = "343"
Packit 5c3484
  want[45] = "371"
Packit 5c3484
  want[46] = "000"
Packit 5c3484
  want[47] = "200"
Packit 5c3484
Packit 5c3484
  result = "yes"
Packit 5c3484
}
Packit 5c3484
{
Packit 5c3484
  for (f = 2; f <= NF; f++)
Packit 5c3484
    {
Packit 5c3484
      for (i = 0; i < 47; i++)
Packit 5c3484
        got[i] = got[i+1];
Packit 5c3484
      got[47] = $f;
Packit 5c3484
Packit 5c3484
      found = 1
Packit 5c3484
      for (i = 0; i < 48; i++)
Packit 5c3484
        if (got[i] != want[i])
Packit 5c3484
          {
Packit 5c3484
            found = 0
Packit 5c3484
            break
Packit 5c3484
          }
Packit 5c3484
      if (found)
Packit 5c3484
        {
Packit 5c3484
          result = "no"
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
    }
Packit 5c3484
}
Packit 5c3484
END {
Packit 5c3484
  print result
Packit 5c3484
}
Packit 5c3484
]EOF
Packit 5c3484
GMP_TRY_ASSEMBLE(
Packit 5c3484
[	.text
Packit 5c3484
	.align	32
Packit 5c3484
{ .mmi;	add	r14 = r15, r16
Packit 5c3484
	add	r17 = r18, r19
Packit 5c3484
	add	r20 = r21, r22 ;; }
Packit 5c3484
	.align	32
Packit 5c3484
{ .mmi;	add	r23 = r24, r25
Packit 5c3484
	add	r26 = r27, r28
Packit 5c3484
	add	r29 = r30, r31 ;; }
Packit 5c3484
],
Packit 5c3484
  [gmp_cv_asm_ia64_align_ok=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`],
Packit 5c3484
  [AC_MSG_WARN([oops, cannot compile test program])
Packit 5c3484
   gmp_cv_asm_ia64_align_ok=yes])
Packit 5c3484
])
Packit 5c3484
GMP_DEFINE_RAW(["define(<IA64_ALIGN_OK>, <\`$gmp_cv_asm_ia64_align_ok'>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_M68K_INSTRUCTION
Packit 5c3484
dnl  ------------------------
Packit 5c3484
dnl  Not sure if ".l" and "%" are independent settings, but it doesn't hurt
Packit 5c3484
dnl  to try all four possibilities.  Note that the % ones must be first, so
Packit 5c3484
dnl  "d0" won't be interpreted as a label.
Packit 5c3484
dnl
Packit 5c3484
dnl  gas 1.92.3 on NetBSD 1.4 needs to be tested with a two operand
Packit 5c3484
dnl  instruction.  It takes registers without "%", but a single operand
Packit 5c3484
dnl  "clrl %d0" only gives a warning, not an error.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_M68K_INSTRUCTION],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([assembler instruction and register style],
Packit 5c3484
		gmp_cv_asm_m68k_instruction,
Packit 5c3484
[for i in "addl %d0,%d1" "add.l %d0,%d1" "addl d0,d1" "add.l d0,d1"; do
Packit 5c3484
  GMP_TRY_ASSEMBLE(
Packit 5c3484
    [	$gmp_cv_asm_text
Packit 5c3484
	$i],
Packit 5c3484
    [gmp_cv_asm_m68k_instruction=$i
Packit 5c3484
    rm -f conftest*
Packit 5c3484
    break])
Packit 5c3484
done
Packit 5c3484
if test -z "$gmp_cv_asm_m68k_instruction"; then
Packit 5c3484
  AC_MSG_ERROR([cannot determine assembler instruction and register style])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_asm_m68k_instruction in
Packit 5c3484
"addl d0,d1")    want_dot_size=no;  want_register_percent=no  ;;
Packit 5c3484
"addl %d0,%d1")  want_dot_size=no;  want_register_percent=yes ;;
Packit 5c3484
"add.l d0,d1")   want_dot_size=yes; want_register_percent=no  ;;
Packit 5c3484
"add.l %d0,%d1") want_dot_size=yes; want_register_percent=yes ;;
Packit 5c3484
*) AC_MSG_ERROR([oops, unrecognised instruction and register style]) ;;
Packit 5c3484
esac
Packit 5c3484
GMP_DEFINE_RAW(["define(<WANT_REGISTER_PERCENT>, <\`$want_register_percent'>)"])
Packit 5c3484
GMP_DEFINE_RAW(["define(<WANT_DOT_SIZE>, <\`$want_dot_size'>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_M68K_ADDRESSING
Packit 5c3484
dnl  -----------------------
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_M68K_ADDRESSING],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_REQUIRE([GMP_ASM_M68K_INSTRUCTION])
Packit 5c3484
AC_CACHE_CHECK([assembler addressing style],
Packit 5c3484
		gmp_cv_asm_m68k_addressing,
Packit 5c3484
[case $gmp_cv_asm_m68k_instruction in
Packit 5c3484
addl*)  movel=movel ;;
Packit 5c3484
add.l*) movel=move.l ;;
Packit 5c3484
*) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
Packit 5c3484
esac
Packit 5c3484
case $gmp_cv_asm_m68k_instruction in
Packit 5c3484
*"%d0,%d1") dreg=%d0; areg=%a0 ;;
Packit 5c3484
*"d0,d1")   dreg=d0;  areg=a0  ;;
Packit 5c3484
*) AC_MSG_ERROR([oops, unrecognised gmp_cv_asm_m68k_instruction]) ;;
Packit 5c3484
esac
Packit 5c3484
GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	$movel	$dreg, $areg@-],
Packit 5c3484
  [gmp_cv_asm_m68k_addressing=mit],
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	$movel	$dreg, -($areg)],
Packit 5c3484
  [gmp_cv_asm_m68k_addressing=motorola],
Packit 5c3484
[AC_MSG_ERROR([cannot determine assembler addressing style])])])
Packit 5c3484
])
Packit 5c3484
GMP_DEFINE_RAW(["define(<WANT_ADDRESSING>, <\`$gmp_cv_asm_m68k_addressing'>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_M68K_BRANCHES
Packit 5c3484
dnl  ---------------------
Packit 5c3484
dnl  "bra" is the standard branch instruction.  "jra" or "jbra" are
Packit 5c3484
dnl  preferred where available, since on gas for instance they give a
Packit 5c3484
dnl  displacement only as big as it needs to be, whereas "bra" is always
Packit 5c3484
dnl  16-bits.  This applies to the conditional branches "bcc" etc too.
Packit 5c3484
dnl  However "dbcc" etc on gas are already only as big as they need to be.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_M68K_BRANCHES],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([assembler shortest branches],
Packit 5c3484
		gmp_cv_asm_m68k_branches,
Packit 5c3484
[for i in jra jbra bra; do
Packit 5c3484
  GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
foo$gmp_cv_asm_label_suffix
Packit 5c3484
	$i	foo],
Packit 5c3484
  [gmp_cv_asm_m68k_branches=$i
Packit 5c3484
  rm -f conftest*
Packit 5c3484
  break])
Packit 5c3484
done
Packit 5c3484
if test -z "$gmp_cv_asm_m68k_branches"; then
Packit 5c3484
  AC_MSG_ERROR([cannot determine assembler branching style])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
GMP_DEFINE_RAW(["define(<WANT_BRANCHES>, <\`$gmp_cv_asm_m68k_branches'>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_POWERPC_PIC_ALWAYS
Packit 5c3484
dnl  --------------------------
Packit 5c3484
dnl  Determine whether PIC is the default compiler output.
Packit 5c3484
dnl
Packit 5c3484
dnl  SVR4 style "foo@ha" addressing is interpreted as non-PIC, and anything
Packit 5c3484
dnl  else is assumed to require PIC always (Darwin or AIX).  SVR4 is the
Packit 5c3484
dnl  only non-PIC addressing syntax the asm files have at the moment anyway.
Packit 5c3484
dnl
Packit 5c3484
dnl  Libtool does this by taking "*-*-aix* | *-*-darwin* | *-*-rhapsody*" to
Packit 5c3484
dnl  mean PIC always, but it seems more reliable to grep the compiler
Packit 5c3484
dnl  output.
Packit 5c3484
dnl
Packit 5c3484
dnl The next paragraph is untrue for Tiger.  Was it ever true?  For tiger,
Packit 5c3484
dnl "cc -fast" makes non-PIC the default (and the binaries do run).
Packit 5c3484
dnl  On Darwin "cc -static" is non-PIC with syntax "ha16(_foo)", but that's
Packit 5c3484
dnl  apparently only for use in the kernel, which we're not attempting to
Packit 5c3484
dnl  target at the moment, so don't look for that.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_POWERPC_PIC_ALWAYS],
Packit 5c3484
[AC_REQUIRE([AC_PROG_CC])
Packit 5c3484
AC_CACHE_CHECK([whether compiler output is PIC by default],
Packit 5c3484
               gmp_cv_asm_powerpc_pic,
Packit 5c3484
[gmp_cv_asm_powerpc_pic=yes
Packit 5c3484
cat >conftest.c <
Packit 5c3484
int foo;
Packit 5c3484
int *bar() { return &foo; }
Packit 5c3484
EOF
Packit 5c3484
echo "Test program:" >&AC_FD_CC
Packit 5c3484
cat conftest.c >&AC_FD_CC
Packit 5c3484
gmp_compile="$CC $CFLAGS $CPPFLAGS -S conftest.c >&AC_FD_CC"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  echo "Compiler output:" >&AC_FD_CC
Packit 5c3484
  cat conftest.s >&AC_FD_CC
Packit 5c3484
  if grep 'foo@ha' conftest.s >/dev/null 2>&AC_FD_CC; then
Packit 5c3484
    gmp_cv_asm_powerpc_pic=no
Packit 5c3484
  fi
Packit 5c3484
  if grep 'ha16(_foo)' conftest.s >/dev/null 2>&AC_FD_CC; then
Packit 5c3484
    gmp_cv_asm_powerpc_pic=no
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
GMP_DEFINE_RAW(["define(<PIC_ALWAYS>,<$gmp_cv_asm_powerpc_pic>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_POWERPC_R_REGISTERS
Packit 5c3484
dnl  ---------------------------
Packit 5c3484
dnl  Determine whether the assembler takes powerpc registers with an "r" as
Packit 5c3484
dnl  in "r6", or as plain "6".  The latter is standard, but NeXT, Rhapsody,
Packit 5c3484
dnl  and MacOS-X require the "r" forms.
Packit 5c3484
dnl
Packit 5c3484
dnl  See also mpn/powerpc32/powerpc-defs.m4 which uses the result of this
Packit 5c3484
dnl  test.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_POWERPC_R_REGISTERS],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([if the assembler needs r on registers],
Packit 5c3484
               gmp_cv_asm_powerpc_r_registers,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	mtctr	6],
Packit 5c3484
[gmp_cv_asm_powerpc_r_registers=no],
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	mtctr	r6],
Packit 5c3484
[gmp_cv_asm_powerpc_r_registers=yes],
Packit 5c3484
[AC_MSG_ERROR([neither "mtctr 6" nor "mtctr r6" works])])])])
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<WANT_R_REGISTERS>,<$gmp_cv_asm_powerpc_r_registers>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_SPARC_REGISTER
Packit 5c3484
dnl  ----------------------
Packit 5c3484
dnl  Determine whether the assembler accepts the ".register" directive.
Packit 5c3484
dnl  Old versions of solaris "as" don't.
Packit 5c3484
dnl
Packit 5c3484
dnl  See also mpn/sparc32/sparc-defs.m4 which uses the result of this test.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_SPARC_REGISTER],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([if the assembler accepts ".register"],
Packit 5c3484
               gmp_cv_asm_sparc_register,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	.register	%g2,#scratch
Packit 5c3484
],
Packit 5c3484
[gmp_cv_asm_sparc_register=yes],
Packit 5c3484
[gmp_cv_asm_sparc_register=no])])
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<HAVE_REGISTER>,<$gmp_cv_asm_sparc_register>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_SPARC_GOTDATA
Packit 5c3484
dnl  ----------------------
Packit 5c3484
dnl  Determine whether the assembler accepts gotdata relocations.
Packit 5c3484
dnl
Packit 5c3484
dnl  See also mpn/sparc32/sparc-defs.m4 which uses the result of this test.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_SPARC_GOTDATA],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([if the assembler accepts gotdata relocations],
Packit 5c3484
               gmp_cv_asm_sparc_gotdata,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	.text
Packit 5c3484
	sethi	%gdop_hix22(symbol), %g1
Packit 5c3484
	or	%g1, %gdop_lox10(symbol), %g1
Packit 5c3484
],
Packit 5c3484
[gmp_cv_asm_sparc_gotdata=yes],
Packit 5c3484
[gmp_cv_asm_sparc_gotdata=no])])
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<HAVE_GOTDATA>,<$gmp_cv_asm_sparc_gotdata>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_ASM_SPARC_SHARED_THUNKS
Packit 5c3484
dnl  ----------------------
Packit 5c3484
dnl  Determine whether the assembler supports all of the features
Packit 5c3484
dnl  necessary in order to emit shared PIC thunks on sparc.
Packit 5c3484
dnl
Packit 5c3484
dnl  See also mpn/sparc32/sparc-defs.m4 which uses the result of this test.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_ASM_SPARC_SHARED_THUNKS],
Packit 5c3484
[AC_REQUIRE([GMP_ASM_TEXT])
Packit 5c3484
AC_CACHE_CHECK([if the assembler can support shared PIC thunks],
Packit 5c3484
               gmp_cv_asm_sparc_shared_thunks,
Packit 5c3484
[GMP_TRY_ASSEMBLE(
Packit 5c3484
[	$gmp_cv_asm_text
Packit 5c3484
	.section	.text.__sparc_get_pc_thunk.l7,"axG",@progbits,__sparc_get_pc_thunk.l7,comdat
Packit 5c3484
	.weak	__sparc_get_pc_thunk.l7
Packit 5c3484
	.hidden	__sparc_get_pc_thunk.l7
Packit 5c3484
	.type	__sparc_get_pc_thunk.l7, #function
Packit 5c3484
__sparc_get_pc_thunk.l7:
Packit 5c3484
	jmp	%o7+8
Packit 5c3484
	 add	%o7, %l7, %l7
Packit 5c3484
],
Packit 5c3484
[gmp_cv_asm_sparc_shared_thunks=yes],
Packit 5c3484
[gmp_cv_asm_sparc_shared_thunks=no])])
Packit 5c3484
Packit 5c3484
GMP_DEFINE_RAW(["define(<HAVE_SHARED_THUNKS>,<$gmp_cv_asm_sparc_shared_thunks>)"])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_ATTRIBUTE_CONST
Packit 5c3484
dnl  ---------------------
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_ATTRIBUTE_CONST],
Packit 5c3484
[AC_CACHE_CHECK([whether gcc __attribute__ ((const)) works],
Packit 5c3484
                gmp_cv_c_attribute_const,
Packit 5c3484
[AC_TRY_COMPILE([int foo (int x) __attribute__ ((const));], ,
Packit 5c3484
  gmp_cv_c_attribute_const=yes, gmp_cv_c_attribute_const=no)
Packit 5c3484
])
Packit 5c3484
if test $gmp_cv_c_attribute_const = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_ATTRIBUTE_CONST, 1,
Packit 5c3484
  [Define to 1 if the compiler accepts gcc style __attribute__ ((const))])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_ATTRIBUTE_MALLOC
Packit 5c3484
dnl  ----------------------
Packit 5c3484
dnl  gcc 2.95.x accepts __attribute__ ((malloc)) but with a warning that
Packit 5c3484
dnl  it's ignored.  Pretend it doesn't exist in this case, to avoid that
Packit 5c3484
dnl  warning.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_ATTRIBUTE_MALLOC],
Packit 5c3484
[AC_CACHE_CHECK([whether gcc __attribute__ ((malloc)) works],
Packit 5c3484
                gmp_cv_c_attribute_malloc,
Packit 5c3484
[cat >conftest.c <
Packit 5c3484
void *foo (int x) __attribute__ ((malloc));
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >conftest.out 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  if grep "attribute directive ignored" conftest.out >/dev/null; then
Packit 5c3484
    gmp_cv_c_attribute_malloc=no
Packit 5c3484
  else
Packit 5c3484
    gmp_cv_c_attribute_malloc=yes
Packit 5c3484
  fi
Packit 5c3484
else
Packit 5c3484
  gmp_cv_c_attribute_malloc=no
Packit 5c3484
fi
Packit 5c3484
cat conftest.out >&AC_FD_CC
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
if test $gmp_cv_c_attribute_malloc = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_ATTRIBUTE_MALLOC, 1,
Packit 5c3484
  [Define to 1 if the compiler accepts gcc style __attribute__ ((malloc))])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_ATTRIBUTE_MODE
Packit 5c3484
dnl  --------------------
Packit 5c3484
dnl  Introduced in gcc 2.2, but perhaps not in all Apple derived versions.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_ATTRIBUTE_MODE],
Packit 5c3484
[AC_CACHE_CHECK([whether gcc __attribute__ ((mode (XX))) works],
Packit 5c3484
                gmp_cv_c_attribute_mode,
Packit 5c3484
[AC_TRY_COMPILE([typedef int SItype __attribute__ ((mode (SI)));], ,
Packit 5c3484
  gmp_cv_c_attribute_mode=yes, gmp_cv_c_attribute_mode=no)
Packit 5c3484
])
Packit 5c3484
if test $gmp_cv_c_attribute_mode = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_ATTRIBUTE_MODE, 1,
Packit 5c3484
  [Define to 1 if the compiler accepts gcc style __attribute__ ((mode (XX)))])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_ATTRIBUTE_NORETURN
Packit 5c3484
dnl  ------------------------
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_ATTRIBUTE_NORETURN],
Packit 5c3484
[AC_CACHE_CHECK([whether gcc __attribute__ ((noreturn)) works],
Packit 5c3484
                gmp_cv_c_attribute_noreturn,
Packit 5c3484
[AC_TRY_COMPILE([void foo (int x) __attribute__ ((noreturn));], ,
Packit 5c3484
  gmp_cv_c_attribute_noreturn=yes, gmp_cv_c_attribute_noreturn=no)
Packit 5c3484
])
Packit 5c3484
if test $gmp_cv_c_attribute_noreturn = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_ATTRIBUTE_NORETURN, 1,
Packit 5c3484
  [Define to 1 if the compiler accepts gcc style __attribute__ ((noreturn))])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
dnl  GMP_C_HIDDEN_ALIAS
Packit 5c3484
dnl  ------------------------
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_HIDDEN_ALIAS],
Packit 5c3484
[AC_CACHE_CHECK([whether gcc hidden aliases work],
Packit 5c3484
                gmp_cv_c_hidden_alias,
Packit 5c3484
[AC_TRY_COMPILE(
Packit 5c3484
[void hid() __attribute__ ((visibility("hidden")));
Packit 5c3484
void hid() {}
Packit 5c3484
void pub() __attribute__ ((alias("hid")));],
Packit 5c3484
, gmp_cv_c_hidden_alias=yes, gmp_cv_c_hidden_alias=no)
Packit 5c3484
])
Packit 5c3484
if test $gmp_cv_c_hidden_alias = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_HIDDEN_ALIAS, 1,
Packit 5c3484
  [Define to 1 if the compiler accepts gcc style __attribute__ ((visibility))
Packit 5c3484
and __attribute__ ((alias))])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
dnl  GMP_C_DOUBLE_FORMAT
Packit 5c3484
dnl  -------------------
Packit 5c3484
dnl  Determine the floating point format.
Packit 5c3484
dnl
Packit 5c3484
dnl  The object file is grepped, in order to work when cross compiling.  A
Packit 5c3484
dnl  start and end sequence is included to avoid false matches, and allowance
Packit 5c3484
dnl  is made for the desired data crossing an "od -b" line boundary.  The test
Packit 5c3484
dnl  number is a small integer so it should appear exactly, no rounding or
Packit 5c3484
dnl  truncation etc.
Packit 5c3484
dnl
Packit 5c3484
dnl  "od -b", incidentally, is supported even by Unix V7, and the awk script
Packit 5c3484
dnl  used doesn't have functions or anything, so even an "old" awk should
Packit 5c3484
dnl  suffice.
Packit 5c3484
dnl
Packit 5c3484
dnl  The C code here declares the variable foo as extern; without that, some
Packit 5c3484
dnl  C++ compilers will not put foo in the object file.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_DOUBLE_FORMAT],
Packit 5c3484
[AC_REQUIRE([AC_PROG_CC])
Packit 5c3484
AC_REQUIRE([AC_PROG_AWK])
Packit 5c3484
AC_CACHE_CHECK([format of `double' floating point],
Packit 5c3484
                gmp_cv_c_double_format,
Packit 5c3484
[gmp_cv_c_double_format=unknown
Packit 5c3484
cat >conftest.c <<\EOF
Packit 5c3484
[struct foo {
Packit 5c3484
  char    before[8];
Packit 5c3484
  double  x;
Packit 5c3484
  char    after[8];
Packit 5c3484
};
Packit 5c3484
extern struct foo foo;
Packit 5c3484
struct foo foo = {
Packit 5c3484
  { '\001', '\043', '\105', '\147', '\211', '\253', '\315', '\357' },
Packit 5c3484
  -123456789.0,
Packit 5c3484
  { '\376', '\334', '\272', '\230', '\166', '\124', '\062', '\020' },
Packit 5c3484
};]
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AC_FD_CC 2>&1"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
cat >conftest.awk <<\EOF
Packit 5c3484
[
Packit 5c3484
BEGIN {
Packit 5c3484
  found = 0
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
{
Packit 5c3484
  for (f = 2; f <= NF; f++)
Packit 5c3484
    {
Packit 5c3484
      for (i = 0; i < 23; i++)
Packit 5c3484
        got[i] = got[i+1];
Packit 5c3484
      got[23] = $f;
Packit 5c3484
Packit 5c3484
      # match the special begin and end sequences
Packit 5c3484
      if (got[0] != "001") continue
Packit 5c3484
      if (got[1] != "043") continue
Packit 5c3484
      if (got[2] != "105") continue
Packit 5c3484
      if (got[3] != "147") continue
Packit 5c3484
      if (got[4] != "211") continue
Packit 5c3484
      if (got[5] != "253") continue
Packit 5c3484
      if (got[6] != "315") continue
Packit 5c3484
      if (got[7] != "357") continue
Packit 5c3484
      if (got[16] != "376") continue
Packit 5c3484
      if (got[17] != "334") continue
Packit 5c3484
      if (got[18] != "272") continue
Packit 5c3484
      if (got[19] != "230") continue
Packit 5c3484
      if (got[20] != "166") continue
Packit 5c3484
      if (got[21] != "124") continue
Packit 5c3484
      if (got[22] != "062") continue
Packit 5c3484
      if (got[23] != "020") continue
Packit 5c3484
Packit 5c3484
      saw = " (" got[8] " " got[9] " " got[10] " " got[11] " " got[12] " " got[13] " " got[14] " " got[15] ")"
Packit 5c3484
Packit 5c3484
      if (got[8]  == "000" &&  \
Packit 5c3484
          got[9]  == "000" &&  \
Packit 5c3484
          got[10] == "000" &&  \
Packit 5c3484
          got[11] == "124" &&  \
Packit 5c3484
          got[12] == "064" &&  \
Packit 5c3484
          got[13] == "157" &&  \
Packit 5c3484
          got[14] == "235" &&  \
Packit 5c3484
          got[15] == "301")
Packit 5c3484
        {
Packit 5c3484
          print "IEEE little endian"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
Packit 5c3484
      # Little endian with the two 4-byte halves swapped, as used by ARM
Packit 5c3484
      # when the chip is in little endian mode.
Packit 5c3484
      #
Packit 5c3484
      if (got[8]  == "064" &&  \
Packit 5c3484
          got[9]  == "157" &&  \
Packit 5c3484
          got[10] == "235" &&  \
Packit 5c3484
          got[11] == "301" &&  \
Packit 5c3484
          got[12] == "000" &&  \
Packit 5c3484
          got[13] == "000" &&  \
Packit 5c3484
          got[14] == "000" &&  \
Packit 5c3484
          got[15] == "124")
Packit 5c3484
        {
Packit 5c3484
          print "IEEE little endian, swapped halves"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
Packit 5c3484
      # gcc 2.95.4 on one GNU/Linux ARM system was seen generating 000 in
Packit 5c3484
      # the last byte, whereas 124 is correct.  Not sure where the bug
Packit 5c3484
      # actually lies, but a running program didn't seem to get a full
Packit 5c3484
      # mantissa worth of working bits.
Packit 5c3484
      #
Packit 5c3484
      # We match this case explicitly so we can give a nice result message,
Packit 5c3484
      # but we deliberately exclude it from the normal IEEE double setups
Packit 5c3484
      # since it's too broken.
Packit 5c3484
      #
Packit 5c3484
      if (got[8]  == "064" &&  \
Packit 5c3484
          got[9]  == "157" &&  \
Packit 5c3484
          got[10] == "235" &&  \
Packit 5c3484
          got[11] == "301" &&  \
Packit 5c3484
          got[12] == "000" &&  \
Packit 5c3484
          got[13] == "000" &&  \
Packit 5c3484
          got[14] == "000" &&  \
Packit 5c3484
          got[15] == "000")
Packit 5c3484
        {
Packit 5c3484
          print "bad ARM software floats"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
Packit 5c3484
      if (got[8]  == "301" &&  \
Packit 5c3484
          got[9]  == "235" &&  \
Packit 5c3484
          got[10] == "157" &&  \
Packit 5c3484
          got[11] == "064" &&  \
Packit 5c3484
          got[12] == "124" &&  \
Packit 5c3484
          got[13] == "000" &&  \
Packit 5c3484
          got[14] == "000" &&  \
Packit 5c3484
	  got[15] == "000")
Packit 5c3484
        {
Packit 5c3484
          print "IEEE big endian"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
Packit 5c3484
      if (got[8]  == "353" &&  \
Packit 5c3484
          got[9]  == "315" &&  \
Packit 5c3484
          got[10] == "242" &&  \
Packit 5c3484
          got[11] == "171" &&  \
Packit 5c3484
          got[12] == "000" &&  \
Packit 5c3484
          got[13] == "240" &&  \
Packit 5c3484
          got[14] == "000" &&  \
Packit 5c3484
          got[15] == "000")
Packit 5c3484
        {
Packit 5c3484
          print "VAX D"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
Packit 5c3484
      if (got[8]  == "275" &&  \
Packit 5c3484
          got[9]  == "301" &&  \
Packit 5c3484
          got[10] == "064" &&  \
Packit 5c3484
          got[11] == "157" &&  \
Packit 5c3484
          got[12] == "000" &&  \
Packit 5c3484
          got[13] == "124" &&  \
Packit 5c3484
          got[14] == "000" &&  \
Packit 5c3484
          got[15] == "000")
Packit 5c3484
        {
Packit 5c3484
          print "VAX G"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
Packit 5c3484
      if (got[8]  == "300" &&  \
Packit 5c3484
          got[9]  == "033" &&  \
Packit 5c3484
          got[10] == "353" &&  \
Packit 5c3484
          got[11] == "171" &&  \
Packit 5c3484
          got[12] == "242" &&  \
Packit 5c3484
          got[13] == "240" &&  \
Packit 5c3484
          got[14] == "000" &&  \
Packit 5c3484
          got[15] == "000")
Packit 5c3484
        {
Packit 5c3484
          print "Cray CFP"
Packit 5c3484
          found = 1
Packit 5c3484
          exit
Packit 5c3484
        }
Packit 5c3484
    }
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
END {
Packit 5c3484
  if (! found)
Packit 5c3484
    print "unknown", saw
Packit 5c3484
}
Packit 5c3484
]
Packit 5c3484
EOF
Packit 5c3484
  gmp_cv_c_double_format=`od -b conftest.$OBJEXT | $AWK -f conftest.awk`
Packit 5c3484
  case $gmp_cv_c_double_format in
Packit 5c3484
  unknown*)
Packit 5c3484
    echo "cannot match anything, conftest.$OBJEXT contains" >&AC_FD_CC
Packit 5c3484
    od -b conftest.$OBJEXT >&AC_FD_CC
Packit 5c3484
    ;;
Packit 5c3484
  esac
Packit 5c3484
else
Packit 5c3484
  AC_MSG_WARN([oops, cannot compile test program])
Packit 5c3484
fi
Packit 5c3484
rm -f conftest*
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
AH_VERBATIM([HAVE_DOUBLE],
Packit 5c3484
[/* Define one of the following to 1 for the format of a `double'.
Packit 5c3484
   If your format is not among these choices, or you don't know what it is,
Packit 5c3484
   then leave all undefined.
Packit 5c3484
   IEEE_LITTLE_SWAPPED means little endian, but with the two 4-byte halves
Packit 5c3484
   swapped, as used by ARM CPUs in little endian mode.  */
Packit 5c3484
#undef HAVE_DOUBLE_IEEE_BIG_ENDIAN
Packit 5c3484
#undef HAVE_DOUBLE_IEEE_LITTLE_ENDIAN
Packit 5c3484
#undef HAVE_DOUBLE_IEEE_LITTLE_SWAPPED
Packit 5c3484
#undef HAVE_DOUBLE_VAX_D
Packit 5c3484
#undef HAVE_DOUBLE_VAX_G
Packit 5c3484
#undef HAVE_DOUBLE_CRAY_CFP])
Packit 5c3484
Packit 5c3484
case $gmp_cv_c_double_format in
Packit 5c3484
  "IEEE big endian")
Packit 5c3484
    AC_DEFINE(HAVE_DOUBLE_IEEE_BIG_ENDIAN, 1)
Packit 5c3484
    GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_DOUBLE_IEEE_BIG_ENDIAN')", POST)
Packit 5c3484
    ;;
Packit 5c3484
  "IEEE little endian")
Packit 5c3484
    AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_ENDIAN, 1)
Packit 5c3484
    GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_DOUBLE_IEEE_LITTLE_ENDIAN')", POST)
Packit 5c3484
    ;;
Packit 5c3484
  "IEEE little endian, swapped halves")
Packit 5c3484
    AC_DEFINE(HAVE_DOUBLE_IEEE_LITTLE_SWAPPED, 1) ;;
Packit 5c3484
  "VAX D")
Packit 5c3484
    AC_DEFINE(HAVE_DOUBLE_VAX_D, 1) ;;
Packit 5c3484
  "VAX G")
Packit 5c3484
    AC_DEFINE(HAVE_DOUBLE_VAX_G, 1) ;;
Packit 5c3484
  "Cray CFP")
Packit 5c3484
    AC_DEFINE(HAVE_DOUBLE_CRAY_CFP, 1) ;;
Packit 5c3484
  "bad ARM software floats")
Packit 5c3484
    ;;
Packit 5c3484
  unknown*)
Packit 5c3484
    AC_MSG_WARN([Could not determine float format.])
Packit 5c3484
    AC_MSG_WARN([Conversions to and from "double" may be slow.])
Packit 5c3484
    ;;
Packit 5c3484
  *)
Packit 5c3484
    AC_MSG_WARN([oops, unrecognised float format: $gmp_cv_c_double_format])
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_STDARG
Packit 5c3484
dnl  ------------
Packit 5c3484
dnl  Test whether to use <stdarg.h>.
Packit 5c3484
dnl
Packit 5c3484
dnl  Notice the AC_DEFINE here is HAVE_STDARG to avoid clashing with
Packit 5c3484
dnl  HAVE_STDARG_H which could arise from AC_CHECK_HEADERS.
Packit 5c3484
dnl
Packit 5c3484
dnl  This test might be slight overkill, after all there's really only going
Packit 5c3484
dnl  to be ANSI or K&R and the two can be differentiated by AC_PROG_CC_STDC
Packit 5c3484
dnl  or very likely by the setups for _PROTO in gmp.h.  On the other hand
Packit 5c3484
dnl  this test is nice and direct, being what we're going to actually use.
Packit 5c3484
Packit 5c3484
dnl  AC_DEFUN([GMP_C_STDARG],
Packit 5c3484
dnl  [AC_CACHE_CHECK([whether <stdarg.h> exists and works],
Packit 5c3484
dnl                  gmp_cv_c_stdarg,
Packit 5c3484
dnl  [AC_TRY_COMPILE(
Packit 5c3484
dnl  [#include <stdarg.h>
Packit 5c3484
dnl  int foo (int x, ...)
Packit 5c3484
dnl  {
Packit 5c3484
dnl    va_list  ap;
Packit 5c3484
dnl    int      y;
Packit 5c3484
dnl    va_start (ap, x);
Packit 5c3484
dnl    y = va_arg (ap, int);
Packit 5c3484
dnl    va_end (ap);
Packit 5c3484
dnl    return y;
Packit 5c3484
dnl  }],,
Packit 5c3484
dnl  gmp_cv_c_stdarg=yes, gmp_cv_c_stdarg=no)
Packit 5c3484
dnl  ])
Packit 5c3484
dnl  if test $gmp_cv_c_stdarg = yes; then
Packit 5c3484
dnl    AC_DEFINE(HAVE_STDARG, 1, [Define to 1 if <stdarg.h> exists and works])
Packit 5c3484
dnl  fi
Packit 5c3484
dnl  ])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_FUNC_ALLOCA
Packit 5c3484
dnl  ---------------
Packit 5c3484
dnl  Determine whether "alloca" is available.  This is AC_FUNC_ALLOCA from
Packit 5c3484
dnl  autoconf, but changed so it doesn't use alloca.c if alloca() isn't
Packit 5c3484
dnl  available, and also to use gmp-impl.h for the conditionals detecting
Packit 5c3484
dnl  compiler builtin alloca's.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_FUNC_ALLOCA],
Packit 5c3484
[AC_REQUIRE([GMP_HEADER_ALLOCA])
Packit 5c3484
AC_CACHE_CHECK([for alloca (via gmp-impl.h)],
Packit 5c3484
               gmp_cv_func_alloca,
Packit 5c3484
[AC_TRY_LINK(
Packit 5c3484
GMP_INCLUDE_GMP_H
Packit 5c3484
[#include "$srcdir/gmp-impl.h"
Packit 5c3484
],
Packit 5c3484
  [char *p = (char *) alloca (1);],
Packit 5c3484
  gmp_cv_func_alloca=yes,
Packit 5c3484
  gmp_cv_func_alloca=no)])
Packit 5c3484
if test $gmp_cv_func_alloca = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_ALLOCA, 1, [Define to 1 if alloca() works (via gmp-impl.h).])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_HEADER_ALLOCA],
Packit 5c3484
[# The Ultrix 4.2 mips builtin alloca declared by alloca.h only works
Packit 5c3484
# for constant arguments.  Useless!
Packit 5c3484
AC_CACHE_CHECK([for working alloca.h],
Packit 5c3484
               gmp_cv_header_alloca,
Packit 5c3484
[AC_TRY_LINK([#include <alloca.h>],
Packit 5c3484
  [char *p = (char *) alloca (2 * sizeof (int));],
Packit 5c3484
  gmp_cv_header_alloca=yes,
Packit 5c3484
  gmp_cv_header_alloca=no)])
Packit 5c3484
if test $gmp_cv_header_alloca = yes; then
Packit 5c3484
  AC_DEFINE(HAVE_ALLOCA_H, 1,
Packit 5c3484
  [Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_OPTION_ALLOCA
Packit 5c3484
dnl  -----------------
Packit 5c3484
dnl  Decide what to do about --enable-alloca from the user.
Packit 5c3484
dnl  This is a macro so it can require GMP_FUNC_ALLOCA.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_OPTION_ALLOCA],
Packit 5c3484
[AC_REQUIRE([GMP_FUNC_ALLOCA])
Packit 5c3484
AC_CACHE_CHECK([how to allocate temporary memory],
Packit 5c3484
               gmp_cv_option_alloca,
Packit 5c3484
[case $enable_alloca in
Packit 5c3484
  yes)
Packit 5c3484
    gmp_cv_option_alloca=alloca
Packit 5c3484
    ;;
Packit 5c3484
  no)
Packit 5c3484
    gmp_cv_option_alloca=malloc-reentrant
Packit 5c3484
    ;;
Packit 5c3484
  reentrant | notreentrant)
Packit 5c3484
    case $gmp_cv_func_alloca in
Packit 5c3484
    yes)  gmp_cv_option_alloca=alloca ;;
Packit 5c3484
    *)    gmp_cv_option_alloca=malloc-$enable_alloca ;;
Packit 5c3484
    esac
Packit 5c3484
    ;;
Packit 5c3484
  *)
Packit 5c3484
    gmp_cv_option_alloca=$enable_alloca
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
AH_VERBATIM([WANT_TMP],
Packit 5c3484
[/* Define one of these to 1 for the desired temporary memory allocation
Packit 5c3484
   method, per --enable-alloca. */
Packit 5c3484
#undef WANT_TMP_ALLOCA
Packit 5c3484
#undef WANT_TMP_REENTRANT
Packit 5c3484
#undef WANT_TMP_NOTREENTRANT
Packit 5c3484
#undef WANT_TMP_DEBUG])
Packit 5c3484
Packit 5c3484
case $gmp_cv_option_alloca in
Packit 5c3484
  alloca)
Packit 5c3484
    if test $gmp_cv_func_alloca = no; then
Packit 5c3484
      AC_MSG_ERROR([--enable-alloca=alloca specified, but alloca not available])
Packit 5c3484
    fi
Packit 5c3484
    AC_DEFINE(WANT_TMP_ALLOCA)
Packit 5c3484
    TAL_OBJECT=tal-reent$U.lo
Packit 5c3484
    ;;
Packit 5c3484
  malloc-reentrant)
Packit 5c3484
    AC_DEFINE(WANT_TMP_REENTRANT)
Packit 5c3484
    TAL_OBJECT=tal-reent$U.lo
Packit 5c3484
    ;;
Packit 5c3484
  malloc-notreentrant)
Packit 5c3484
    AC_DEFINE(WANT_TMP_NOTREENTRANT)
Packit 5c3484
    TAL_OBJECT=tal-notreent$U.lo
Packit 5c3484
    ;;
Packit 5c3484
  debug)
Packit 5c3484
    AC_DEFINE(WANT_TMP_DEBUG)
Packit 5c3484
    TAL_OBJECT=tal-debug$U.lo
Packit 5c3484
    ;;
Packit 5c3484
  *)
Packit 5c3484
    # checks at the start of configure.in should protect us
Packit 5c3484
    AC_MSG_ERROR([unrecognised --enable-alloca=$gmp_cv_option_alloca])
Packit 5c3484
    ;;
Packit 5c3484
esac
Packit 5c3484
AC_SUBST(TAL_OBJECT)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_FUNC_SSCANF_WRITABLE_INPUT
Packit 5c3484
dnl  ------------------------------
Packit 5c3484
dnl  Determine whether sscanf requires a writable input string.
Packit 5c3484
dnl
Packit 5c3484
dnl  It might be nicer to run a program to determine this when doing a
Packit 5c3484
dnl  native build, but the systems afflicted are few and far between these
Packit 5c3484
dnl  days, so it seems good enough just to list them.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_FUNC_SSCANF_WRITABLE_INPUT],
Packit 5c3484
[AC_CACHE_CHECK([whether sscanf needs writable input],
Packit 5c3484
                 gmp_cv_func_sscanf_writable_input,
Packit 5c3484
[case $host in
Packit 5c3484
  *-*-hpux9 | *-*-hpux9.*)
Packit 5c3484
     gmp_cv_func_sscanf_writable_input=yes ;;
Packit 5c3484
  *) gmp_cv_func_sscanf_writable_input=no  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_func_sscanf_writable_input in
Packit 5c3484
  yes) AC_DEFINE(SSCANF_WRITABLE_INPUT, 1,
Packit 5c3484
                 [Define to 1 if sscanf requires writable inputs]) ;;
Packit 5c3484
  no)  ;;
Packit 5c3484
  *)   AC_MSG_ERROR([unrecognised \$gmp_cv_func_sscanf_writable_input]) ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_FUNC_VSNPRINTF
Packit 5c3484
dnl  ------------------
Packit 5c3484
dnl  Check whether vsnprintf exists, and works properly.
Packit 5c3484
dnl
Packit 5c3484
dnl  Systems without vsnprintf include mingw32, OSF 4.
Packit 5c3484
dnl
Packit 5c3484
dnl  Sparc Solaris 2.7 in 64-bit mode doesn't always truncate, making
Packit 5c3484
dnl  vsnprintf like vsprintf, and hence completely useless.  On one system a
Packit 5c3484
dnl  literal string is enough to provoke the problem, on another a "%n" was
Packit 5c3484
dnl  needed.  There seems to be something weird going on with the optimizer
Packit 5c3484
dnl  or something, since on the first system adding a second check with
Packit 5c3484
dnl  "%n", or even just an initialized local variable, makes it work.  In
Packit 5c3484
dnl  any case, without bothering to get to the bottom of this, the two
Packit 5c3484
dnl  program runs in the code below end up successfully detecting the
Packit 5c3484
dnl  problem.
Packit 5c3484
dnl
Packit 5c3484
dnl  glibc 2.0.x returns either -1 or bufsize-1 for an overflow (both seen,
Packit 5c3484
dnl  not sure which 2.0.x does which), but still puts the correct null
Packit 5c3484
dnl  terminated result into the buffer.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_FUNC_VSNPRINTF],
Packit 5c3484
[AC_CHECK_FUNC(vsnprintf,
Packit 5c3484
              [gmp_vsnprintf_exists=yes],
Packit 5c3484
              [gmp_vsnprintf_exists=no])
Packit 5c3484
if test "$gmp_vsnprintf_exists" = no; then
Packit 5c3484
  gmp_cv_func_vsnprintf=no
Packit 5c3484
else
Packit 5c3484
  AC_CACHE_CHECK([whether vsnprintf works],
Packit 5c3484
                 gmp_cv_func_vsnprintf,
Packit 5c3484
  [gmp_cv_func_vsnprintf=yes
Packit 5c3484
   for i in 'return check ("hello world");' 'int n; return check ("%nhello world", &n);'; do
Packit 5c3484
     AC_TRY_RUN([
Packit 5c3484
#include <string.h>  /* for strcmp */
Packit 5c3484
#include <stdio.h>   /* for vsnprintf */
Packit 5c3484
Packit 5c3484
#include <stdarg.h>
Packit 5c3484
Packit 5c3484
int
Packit 5c3484
check (const char *fmt, ...)
Packit 5c3484
{
Packit 5c3484
  static char  buf[128];
Packit 5c3484
  va_list  ap;
Packit 5c3484
  int      ret;
Packit 5c3484
Packit 5c3484
  va_start (ap, fmt);
Packit 5c3484
Packit 5c3484
  ret = vsnprintf (buf, 4, fmt, ap);
Packit 5c3484
Packit 5c3484
  if (strcmp (buf, "hel") != 0)
Packit 5c3484
    return 1;
Packit 5c3484
Packit 5c3484
  /* allowed return values */
Packit 5c3484
  if (ret != -1 && ret != 3 && ret != 11)
Packit 5c3484
    return 2;
Packit 5c3484
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
$i
Packit 5c3484
}
Packit 5c3484
],
Packit 5c3484
      [:],
Packit 5c3484
      [gmp_cv_func_vsnprintf=no; break],
Packit 5c3484
      [gmp_cv_func_vsnprintf=probably; break])
Packit 5c3484
  done
Packit 5c3484
  ])
Packit 5c3484
  if test "$gmp_cv_func_vsnprintf" = probably; then
Packit 5c3484
    AC_MSG_WARN([cannot check for properly working vsnprintf when cross compiling, will assume it's ok])
Packit 5c3484
  fi
Packit 5c3484
  if test "$gmp_cv_func_vsnprintf" != no; then
Packit 5c3484
    AC_DEFINE(HAVE_VSNPRINTF,1,
Packit 5c3484
    [Define to 1 if you have the `vsnprintf' function and it works properly.])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_H_EXTERN_INLINE
Packit 5c3484
dnl  -------------------
Packit 5c3484
dnl  If the compiler has an "inline" of some sort, check whether the
Packit 5c3484
dnl  #ifdef's in gmp.h recognise it.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_H_EXTERN_INLINE],
Packit 5c3484
[AC_REQUIRE([AC_C_INLINE])
Packit 5c3484
case $ac_cv_c_inline in
Packit 5c3484
no) ;;
Packit 5c3484
*)
Packit 5c3484
  AC_TRY_COMPILE(
Packit 5c3484
[#define __GMP_WITHIN_CONFIGURE_INLINE 1
Packit 5c3484
]GMP_INCLUDE_GMP_H[
Packit 5c3484
#ifndef __GMP_EXTERN_INLINE
Packit 5c3484
die die die
Packit 5c3484
#endif
Packit 5c3484
],,,
Packit 5c3484
  [case $ac_cv_c_inline in
Packit 5c3484
  yes) tmp_inline=inline ;;
Packit 5c3484
  *)   tmp_inline=$ac_cv_c_inline ;;
Packit 5c3484
  esac
Packit 5c3484
  AC_MSG_WARN([gmp.h doesnt recognise compiler "$tmp_inline", inlines will be unavailable])])
Packit 5c3484
  ;;
Packit 5c3484
esac
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_H_HAVE_FILE
Packit 5c3484
dnl  ---------------
Packit 5c3484
dnl  Check whether the #ifdef's in gmp.h recognise when stdio.h has been
Packit 5c3484
dnl  included to get FILE.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_H_HAVE_FILE],
Packit 5c3484
[AC_TRY_COMPILE(
Packit 5c3484
[#include <stdio.h>]
Packit 5c3484
GMP_INCLUDE_GMP_H
Packit 5c3484
[#if ! _GMP_H_HAVE_FILE
Packit 5c3484
die die die
Packit 5c3484
#endif
Packit 5c3484
],,,
Packit 5c3484
  [AC_MSG_WARN([gmp.h doesnt recognise <stdio.h>, FILE prototypes will be unavailable])])
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_FOR_BUILD
Packit 5c3484
dnl  ---------------------
Packit 5c3484
dnl  Establish CC_FOR_BUILD, a C compiler for the build system.
Packit 5c3484
dnl
Packit 5c3484
dnl  If CC_FOR_BUILD is set then it's expected to work, likewise the old
Packit 5c3484
dnl  style HOST_CC, otherwise some likely candidates are tried, the same as
Packit 5c3484
dnl  configfsf.guess.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_FOR_BUILD],
Packit 5c3484
[AC_REQUIRE([AC_PROG_CC])
Packit 5c3484
if test -n "$CC_FOR_BUILD"; then
Packit 5c3484
  GMP_PROG_CC_FOR_BUILD_WORKS($CC_FOR_BUILD,,
Packit 5c3484
    [AC_MSG_ERROR([Specified CC_FOR_BUILD doesn't seem to work])])
Packit 5c3484
elif test -n "$HOST_CC"; then
Packit 5c3484
  GMP_PROG_CC_FOR_BUILD_WORKS($HOST_CC,
Packit 5c3484
    [CC_FOR_BUILD=$HOST_CC],
Packit 5c3484
    [AC_MSG_ERROR([Specified HOST_CC doesn't seem to work])])
Packit 5c3484
else
Packit 5c3484
  for i in "$CC" "$CC $CFLAGS $CPPFLAGS" cc gcc c89 c99; do
Packit 5c3484
    GMP_PROG_CC_FOR_BUILD_WORKS($i,
Packit 5c3484
      [CC_FOR_BUILD=$i
Packit 5c3484
       break])
Packit 5c3484
  done
Packit 5c3484
  if test -z "$CC_FOR_BUILD"; then
Packit 5c3484
    AC_MSG_ERROR([Cannot find a build system compiler])
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
Packit 5c3484
AC_ARG_VAR(CC_FOR_BUILD,[build system C compiler])
Packit 5c3484
AC_SUBST(CC_FOR_BUILD)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CC_FOR_BUILD_WORKS(cc/cflags[,[action-if-good][,action-if-bad]])
Packit 5c3484
dnl  -------------------------------------------------------------------------
Packit 5c3484
dnl  See if the given cc/cflags works on the build system.
Packit 5c3484
dnl
Packit 5c3484
dnl  It seems easiest to just use the default compiler output, rather than
Packit 5c3484
dnl  figuring out the .exe or whatever at this stage.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CC_FOR_BUILD_WORKS],
Packit 5c3484
[AC_MSG_CHECKING([build system compiler $1])
Packit 5c3484
# remove anything that might look like compiler output to our "||" expression
Packit 5c3484
rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
cat >conftest.c <
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$1 conftest.c"
Packit 5c3484
cc_for_build_works=no
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  if (./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest) >&AC_FD_CC 2>&1; then
Packit 5c3484
    cc_for_build_works=yes
Packit 5c3484
  fi
Packit 5c3484
fi
Packit 5c3484
rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
AC_MSG_RESULT($cc_for_build_works)
Packit 5c3484
if test "$cc_for_build_works" = yes; then
Packit 5c3484
  ifelse([$2],,:,[$2])
Packit 5c3484
else
Packit 5c3484
  ifelse([$3],,:,[$3])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_CPP_FOR_BUILD
Packit 5c3484
dnl  ---------------------
Packit 5c3484
dnl  Establish CPP_FOR_BUILD, the build system C preprocessor.
Packit 5c3484
dnl  The choices tried here are the same as AC_PROG_CPP, but with
Packit 5c3484
dnl  CC_FOR_BUILD.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_CPP_FOR_BUILD],
Packit 5c3484
[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
Packit 5c3484
AC_MSG_CHECKING([for build system preprocessor])
Packit 5c3484
if test -z "$CPP_FOR_BUILD"; then
Packit 5c3484
  AC_CACHE_VAL(gmp_cv_prog_cpp_for_build,
Packit 5c3484
  [cat >conftest.c <
Packit 5c3484
#define FOO BAR
Packit 5c3484
EOF
Packit 5c3484
  for i in "$CC_FOR_BUILD -E" "$CC_FOR_BUILD -E -traditional-cpp" "/lib/cpp"; do
Packit 5c3484
    gmp_compile="$i conftest.c"
Packit 5c3484
    if AC_TRY_EVAL(gmp_compile) >&AC_FD_CC 2>&1; then
Packit 5c3484
      gmp_cv_prog_cpp_for_build=$i
Packit 5c3484
      break
Packit 5c3484
    fi
Packit 5c3484
  done
Packit 5c3484
  rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
  if test -z "$gmp_cv_prog_cpp_for_build"; then
Packit 5c3484
    AC_MSG_ERROR([Cannot find build system C preprocessor.])
Packit 5c3484
  fi
Packit 5c3484
  ])
Packit 5c3484
  CPP_FOR_BUILD=$gmp_cv_prog_cpp_for_build
Packit 5c3484
fi
Packit 5c3484
AC_MSG_RESULT([$CPP_FOR_BUILD])
Packit 5c3484
Packit 5c3484
AC_ARG_VAR(CPP_FOR_BUILD,[build system C preprocessor])
Packit 5c3484
AC_SUBST(CPP_FOR_BUILD)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_PROG_EXEEXT_FOR_BUILD
Packit 5c3484
dnl  -------------------------
Packit 5c3484
dnl  Determine EXEEXT_FOR_BUILD, the build system executable suffix.
Packit 5c3484
dnl
Packit 5c3484
dnl  The idea is to find what "-o conftest$foo" will make it possible to run
Packit 5c3484
dnl  the program with ./conftest.  On Unix-like systems this is of course
Packit 5c3484
dnl  nothing, for DOS it's ".exe", or for a strange RISC OS foreign file
Packit 5c3484
dnl  system cross compile it can be ",ff8" apparently.  Not sure if the
Packit 5c3484
dnl  latter actually applies to a build-system executable, maybe it doesn't,
Packit 5c3484
dnl  but it won't hurt to try.
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_PROG_EXEEXT_FOR_BUILD],
Packit 5c3484
[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
Packit 5c3484
AC_CACHE_CHECK([for build system executable suffix],
Packit 5c3484
               gmp_cv_prog_exeext_for_build,
Packit 5c3484
[cat >conftest.c <
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
for i in .exe ,ff8 ""; do
Packit 5c3484
  gmp_compile="$CC_FOR_BUILD conftest.c -o conftest$i"
Packit 5c3484
  if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
    if (./conftest) 2>&AC_FD_CC; then
Packit 5c3484
      gmp_cv_prog_exeext_for_build=$i
Packit 5c3484
      break
Packit 5c3484
    fi
Packit 5c3484
  fi
Packit 5c3484
done
Packit 5c3484
rm -f conftest*
Packit 5c3484
if test "${gmp_cv_prog_exeext_for_build+set}" != set; then
Packit 5c3484
  AC_MSG_ERROR([Cannot determine executable suffix])
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
AC_SUBST(EXEEXT_FOR_BUILD,$gmp_cv_prog_exeext_for_build)
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_C_FOR_BUILD_ANSI
Packit 5c3484
dnl  --------------------
Packit 5c3484
dnl  Determine whether CC_FOR_BUILD is ANSI, and establish U_FOR_BUILD
Packit 5c3484
dnl  accordingly.
Packit 5c3484
dnl
Packit 5c3484
dnl  FIXME: Use AC_PROG_CC sets ac_cv_prog_cc_c89 which could be used instead
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_C_FOR_BUILD_ANSI],
Packit 5c3484
[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
Packit 5c3484
AC_CACHE_CHECK([whether build system compiler is ANSI],
Packit 5c3484
               gmp_cv_c_for_build_ansi,
Packit 5c3484
[cat >conftest.c <
Packit 5c3484
int
Packit 5c3484
main (int argc, char **argv)
Packit 5c3484
{
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$CC_FOR_BUILD conftest.c"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  gmp_cv_c_for_build_ansi=yes
Packit 5c3484
else
Packit 5c3484
  gmp_cv_c_for_build_ansi=no
Packit 5c3484
fi
Packit 5c3484
rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
])
Packit 5c3484
if test "$gmp_cv_c_for_build_ansi" = yes; then
Packit 5c3484
  U_FOR_BUILD=
Packit 5c3484
else
Packit 5c3484
  AC_SUBST(U_FOR_BUILD,_)
Packit 5c3484
fi
Packit 5c3484
])
Packit 5c3484
Packit 5c3484
Packit 5c3484
dnl  GMP_CHECK_LIBM_FOR_BUILD
Packit 5c3484
dnl  ------------------------
Packit 5c3484
dnl  Establish LIBM_FOR_BUILD as -lm, if that seems to work.
Packit 5c3484
dnl
Packit 5c3484
dnl  Libtool AC_CHECK_LIBM also uses -lmw on *-ncr-sysv4.3*, if it works.
Packit 5c3484
dnl  Don't know what that does, lets assume it's not needed just for log().
Packit 5c3484
Packit 5c3484
AC_DEFUN([GMP_CHECK_LIBM_FOR_BUILD],
Packit 5c3484
[AC_REQUIRE([GMP_PROG_CC_FOR_BUILD])
Packit 5c3484
AC_CACHE_CHECK([for build system compiler math library],
Packit 5c3484
               gmp_cv_check_libm_for_build,
Packit 5c3484
[cat >conftest.c <
Packit 5c3484
#include <math.h>
Packit 5c3484
int
Packit 5c3484
main ()
Packit 5c3484
{
Packit 5c3484
  return 0;
Packit 5c3484
}
Packit 5c3484
double d;
Packit 5c3484
double
Packit 5c3484
foo ()
Packit 5c3484
{
Packit 5c3484
  return log (d);
Packit 5c3484
}
Packit 5c3484
EOF
Packit 5c3484
gmp_compile="$CC_FOR_BUILD conftest.c -lm"
Packit 5c3484
if AC_TRY_EVAL(gmp_compile); then
Packit 5c3484
  gmp_cv_check_libm_for_build=-lm
Packit 5c3484
else
Packit 5c3484
  gmp_cv_check_libm_for_build=no
Packit 5c3484
fi
Packit 5c3484
rm -f conftest* a.out b.out a.exe a_out.exe
Packit 5c3484
])
Packit 5c3484
case $gmp_cv_check_libm_for_build in
Packit 5c3484
  yes) AC_SUBST(LIBM_FOR_BUILD,-lm) ;;
Packit 5c3484
  no)  LIBM_FOR_BUILD= ;;
Packit 5c3484
  *)   LIBM_FOR_BUILD=$gmp_cv_check_libm_for_build ;;
Packit 5c3484
esac
Packit 5c3484
])