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