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