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