github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/acinclude.m4 (about)

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