resetting manifest requested domain to floor
[platform/upstream/gmp.git] / configure.ac
1 dnl  Process this file with autoconf to produce a configure script.
2
3
4 define(GMP_COPYRIGHT,[[
5
6 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
7 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
8
9 This file is part of the GNU MP Library.
10
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published
13 by the Free Software Foundation; either version 3 of the License, or (at
14 your option) any later version.
15
16 The GNU MP Library is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
19 License for more details.
20
21 You should have received a copy of the GNU Lesser General Public License
22 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.
23 ]])
24
25 AC_COPYRIGHT(GMP_COPYRIGHT)
26 AH_TOP(/*GMP_COPYRIGHT*/)
27
28 AC_REVISION($Revision$)
29 AC_PREREQ(2.59)
30 AC_INIT(GNU MP, GMP_VERSION, [gmp-bugs@gmplib.org, see http://gmplib.org/manual/Reporting-Bugs.html], gmp)
31 AC_CONFIG_SRCDIR(gmp-impl.h)
32 m4_pattern_forbid([^[ \t]*GMP_])
33 m4_pattern_allow(GMP_LDFLAGS)
34 m4_pattern_allow(GMP_LIMB_BITS)
35 m4_pattern_allow(GMP_MPARAM_H_SUGGEST)
36 m4_pattern_allow(GMP_NAIL_BITS)
37 m4_pattern_allow(GMP_NUMB_BITS)
38 m4_pattern_allow(GMP_NONSTD_ABI)
39
40 # If --target is not used then $target_alias is empty, but if say
41 # "./configure athlon-pc-freebsd3.5" is used, then all three of
42 # $build_alias, $host_alias and $target_alias are set to
43 # "athlon-pc-freebsd3.5".
44 #
45 if test -n "$target_alias" && test "$target_alias" != "$host_alias"; then
46   AC_MSG_ERROR([--target is not appropriate for GMP
47 Use --build=CPU-VENDOR-OS if you need to specify your CPU and/or system
48 explicitly.  Use --host if cross-compiling (see "Installing GMP" in the
49 manual for more on this).])
50 fi
51
52 GMP_INIT(config.m4)
53
54 AC_CANONICAL_HOST
55
56 dnl  Automake "no-dependencies" is used because include file dependencies
57 dnl  are not useful to us.  Pretty much everything depends just on gmp.h,
58 dnl  gmp-impl.h and longlong.h, and yet only rarely does everything need to
59 dnl  be rebuilt for changes to those files.
60 dnl
61 dnl  "no-dependencies" also helps with the way we're setup to run
62 dnl  AC_PROG_CXX only conditionally.  If dependencies are used then recent
63 dnl  automake (eg 1.7.2) appends an AM_CONDITIONAL to AC_PROG_CXX, and then
64 dnl  gets upset if it's not actually executed.
65 dnl
66 dnl  Note that there's a copy of these options in the top-level Makefile.am,
67 dnl  so update there too if changing anything.
68 dnl
69 AM_INIT_AUTOMAKE([1.8 gnu no-dependencies])
70 AC_CONFIG_HEADERS(config.h:config.in)
71 AM_MAINTAINER_MODE
72
73
74 AC_ARG_ENABLE(assert,
75 AC_HELP_STRING([--enable-assert],[enable ASSERT checking [[default=no]]]),
76 [case $enableval in
77 yes|no) ;;
78 *) AC_MSG_ERROR([bad value $enableval for --enable-assert, need yes or no]) ;;
79 esac],
80 [enable_assert=no])
81
82 if test "$enable_assert" = "yes"; then
83   AC_DEFINE(WANT_ASSERT,1,
84   [Define to 1 to enable ASSERT checking, per --enable-assert])
85   want_assert_01=1
86 else
87   want_assert_01=0
88 fi
89 GMP_DEFINE_RAW(["define(<WANT_ASSERT>,$want_assert_01)"])
90
91
92 AC_ARG_ENABLE(alloca,
93 AC_HELP_STRING([--enable-alloca],[how to get temp memory [[default=reentrant]]]),
94 [case $enableval in
95 alloca|malloc-reentrant|malloc-notreentrant) ;;
96 yes|no|reentrant|notreentrant) ;;
97 debug) ;;
98 *)
99   AC_MSG_ERROR([bad value $enableval for --enable-alloca, need one of:
100 yes no reentrant notreentrant alloca malloc-reentrant malloc-notreentrant debug]) ;;
101 esac],
102 [enable_alloca=reentrant])
103
104
105 # IMPROVE ME: The default for C++ is disabled.  The tests currently
106 # performed below for a working C++ compiler are not particularly strong,
107 # and in general can't be expected to get the right setup on their own.  The
108 # most significant problem is getting the ABI the same.  Defaulting CXXFLAGS
109 # to CFLAGS takes only a small step towards this.  It's also probably worth
110 # worrying whether the C and C++ runtimes from say gcc and a vendor C++ can
111 # work together.  Some rather broken C++ installations were encountered
112 # during testing, and though such things clearly aren't GMP's problem, if
113 # --enable-cxx=detect were to be the default then some careful checks of
114 # which, if any, C++ compiler on the system is up to scratch would be
115 # wanted.
116 #
117 AC_ARG_ENABLE(cxx,
118 AC_HELP_STRING([--enable-cxx],[enable C++ support [[default=no]]]),
119 [case $enableval in
120 yes|no|detect) ;;
121 *) AC_MSG_ERROR([bad value $enableval for --enable-cxx, need yes/no/detect]) ;;
122 esac],
123 [enable_cxx=no])
124
125
126 AC_ARG_ENABLE(assembly,
127 AC_HELP_STRING([--enable-assembly],[enable the use of assembly loops [[default=yes]]]),
128 [case $enableval in
129 yes|no) ;;
130 *) AC_MSG_ERROR([bad value $enableval for --enable-assembly, need yes or no]) ;;
131 esac],
132 [enable_assembly=yes])
133
134 if test "$enable_assembly" = "yes"; then
135   AC_DEFINE(WANT_ASSEMBLY,1,
136   [Defined to 1 as per --enable-assembly])
137 fi
138
139
140 AC_ARG_ENABLE(fft,
141 AC_HELP_STRING([--enable-fft],[enable FFTs for multiplication [[default=yes]]]),
142 [case $enableval in
143 yes|no) ;;
144 *) AC_MSG_ERROR([bad value $enableval for --enable-fft, need yes or no]) ;;
145 esac],
146 [enable_fft=yes])
147
148 if test "$enable_fft" = "yes"; then
149   AC_DEFINE(WANT_FFT,1,
150   [Define to 1 to enable FFTs for multiplication, per --enable-fft])
151 fi
152
153
154 AC_ARG_ENABLE(old-fft-full,
155 AC_HELP_STRING([--enable-old-fft-full],[enable old mpn_mul_fft_full for multiplication [[default=no]]]),
156 [case $enableval in
157 yes|no) ;;
158 *) AC_MSG_ERROR([bad value $enableval for --enable-old-fft-full, need yes or no]) ;;
159 esac],
160 [enable_old_fft_full=no])
161
162 if test "$enable_old_fft_full" = "yes"; then
163   AC_DEFINE(WANT_OLD_FFT_FULL,1,
164   [Define to 1 to enable old mpn_mul_fft_full for multiplication, per --enable-old-fft-full])
165 fi
166
167
168 AC_ARG_ENABLE(nails,
169 AC_HELP_STRING([--enable-nails],[use nails on limbs [[default=no]]]),
170 [case $enableval in
171 [yes|no|[02468]|[0-9][02468]]) ;;
172 [*[13579]])
173   AC_MSG_ERROR([bad value $enableval for --enable-nails, only even nail sizes supported]) ;;
174 *)
175   AC_MSG_ERROR([bad value $enableval for --enable-nails, need yes/no/number]) ;;
176 esac],
177 [enable_nails=no])
178
179 case $enable_nails in
180 yes) GMP_NAIL_BITS=2 ;;
181 no)  GMP_NAIL_BITS=0 ;;
182 *)   GMP_NAIL_BITS=$enable_nails ;;
183 esac
184 AC_SUBST(GMP_NAIL_BITS)
185
186
187 AC_ARG_ENABLE(profiling,
188 AC_HELP_STRING([--enable-profiling],
189                [build with profiler support [[default=no]]]),
190 [case $enableval in
191 no|prof|gprof|instrument) ;;
192 *) AC_MSG_ERROR([bad value $enableval for --enable-profiling, need no/prof/gprof/instrument]) ;;
193 esac],
194 [enable_profiling=no])
195
196 case $enable_profiling in
197   prof)
198     AC_DEFINE(WANT_PROFILING_PROF, 1,
199               [Define to 1 if --enable-profiling=prof])
200     ;;
201   gprof)
202     AC_DEFINE(WANT_PROFILING_GPROF, 1,
203               [Define to 1 if --enable-profiling=gprof])
204     ;;
205   instrument)
206     AC_DEFINE(WANT_PROFILING_INSTRUMENT, 1,
207               [Define to 1 if --enable-profiling=instrument])
208     ;;
209 esac
210
211 GMP_DEFINE_RAW(["define(<WANT_PROFILING>,<\`$enable_profiling'>)"])
212
213 # -fomit-frame-pointer is incompatible with -pg on some chips
214 if test "$enable_profiling" = gprof; then
215   fomit_frame_pointer=
216 else
217   fomit_frame_pointer="-fomit-frame-pointer"
218 fi
219
220
221 AC_ARG_WITH(readline,
222 AC_HELP_STRING([--with-readline],
223                [readline support in calc demo program [[default=detect]]]),
224 [case $withval in
225 yes|no|detect) ;;
226 *) AC_MSG_ERROR([bad value $withval for --with-readline, need yes/no/detect]) ;;
227 esac],
228 [with_readline=detect])
229
230
231 AC_ARG_ENABLE(fat,
232 AC_HELP_STRING([--enable-fat],
233                [build a fat binary on systems that support it [[default=no]]]),
234 [case $enableval in
235 yes|no) ;;
236 *) AC_MSG_ERROR([bad value $enableval for --enable-fat, need yes or no]) ;;
237 esac],
238 [enable_fat=no])
239
240
241 AC_ARG_ENABLE(minithres,
242 AC_HELP_STRING([--enable-minithres],
243                [choose minimal thresholds for testing [[default=no]]]),
244 [case $enableval in
245 yes|no) ;;
246 *) AC_MSG_ERROR([bad value $enableval for --enable-minithres, need yes or no]) ;;
247 esac],
248 [enable_minithres=no])
249
250
251 if test $enable_fat = yes && test $enable_assembly = no ; then
252   AC_MSG_ERROR([when doing a fat build, disabling assembly will not work])
253 fi
254
255
256 tmp_host=`echo $host_cpu | sed 's/\./_/'`
257 AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_$tmp_host)
258 GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_HOST_CPU_$tmp_host')", POST)
259
260 dnl  The HAVE_HOST_CPU_ list here only needs to have entries for those which
261 dnl  are going to be tested, not everything that can possibly be selected.
262 dnl
263 dnl  The HAVE_HOST_CPU_FAMILY_ list similarly, and note that the AC_DEFINEs
264 dnl  for these are under the cpu specific setups below.
265
266 AH_VERBATIM([HAVE_HOST_CPU_1],
267 [/* Define one of these to 1 for the host CPU family.
268    If your CPU is not in any of these families, leave all undefined.
269    For an AMD64 chip, define "x86" in ABI=32, but not in ABI=64. */
270 #undef HAVE_HOST_CPU_FAMILY_alpha
271 #undef HAVE_HOST_CPU_FAMILY_m68k
272 #undef HAVE_HOST_CPU_FAMILY_power
273 #undef HAVE_HOST_CPU_FAMILY_powerpc
274 #undef HAVE_HOST_CPU_FAMILY_x86
275 #undef HAVE_HOST_CPU_FAMILY_x86_64
276
277 /* Define one of the following to 1 for the host CPU, as per the output of
278    ./config.guess.  If your CPU is not listed here, leave all undefined.  */
279 #undef HAVE_HOST_CPU_alphaev67
280 #undef HAVE_HOST_CPU_alphaev68
281 #undef HAVE_HOST_CPU_alphaev7
282 #undef HAVE_HOST_CPU_m68020
283 #undef HAVE_HOST_CPU_m68030
284 #undef HAVE_HOST_CPU_m68040
285 #undef HAVE_HOST_CPU_m68060
286 #undef HAVE_HOST_CPU_m68360
287 #undef HAVE_HOST_CPU_powerpc604
288 #undef HAVE_HOST_CPU_powerpc604e
289 #undef HAVE_HOST_CPU_powerpc750
290 #undef HAVE_HOST_CPU_powerpc7400
291 #undef HAVE_HOST_CPU_supersparc
292 #undef HAVE_HOST_CPU_i386
293 #undef HAVE_HOST_CPU_i586
294 #undef HAVE_HOST_CPU_i686
295 #undef HAVE_HOST_CPU_pentium
296 #undef HAVE_HOST_CPU_pentiummmx
297 #undef HAVE_HOST_CPU_pentiumpro
298 #undef HAVE_HOST_CPU_pentium2
299 #undef HAVE_HOST_CPU_pentium3
300 #undef HAVE_HOST_CPU_s390_z900
301 #undef HAVE_HOST_CPU_s390_z990
302 #undef HAVE_HOST_CPU_s390_z9
303 #undef HAVE_HOST_CPU_s390_z10
304 #undef HAVE_HOST_CPU_s390_z196
305
306 /* Define to 1 iff we have a s390 with 64-bit registers.  */
307 #undef HAVE_HOST_CPU_s390_zarch])
308
309
310 # Table of compilers, options, and mpn paths.  This code has various related
311 # purposes
312 #
313 #   - better default CC/CFLAGS selections than autoconf otherwise gives
314 #   - default CC/CFLAGS selections for extra CPU types specific to GMP
315 #   - a few tests for known bad compilers
316 #   - choice of ABIs on suitable systems
317 #   - selection of corresponding mpn search path
318 #
319 # After GMP specific searches and tests, the standard autoconf AC_PROG_CC is
320 # called.  User selections of CC etc are respected.
321 #
322 # Care is taken not to use macros like AC_TRY_COMPILE during the GMP
323 # pre-testing, since they of course depend on AC_PROG_CC, and also some of
324 # them cache their results, which is not wanted.
325 #
326 # The ABI selection mechanism is unique to GMP.  All that reaches autoconf
327 # is a different selection of CC/CFLAGS according to the best ABI the system
328 # supports, and/or what the user selects.  Naturally the mpn assembler code
329 # selected is very dependent on the ABI.
330 #
331 # The closest the standard tools come to a notion of ABI is something like
332 # "sparc64" which encodes a CPU and an ABI together.  This doesn't seem to
333 # scale well for GMP, where exact CPU types like "ultrasparc2" are wanted,
334 # separate from the ABI used on them.
335 #
336 #
337 # The variables set here are
338 #
339 #   cclist              the compiler choices
340 #   xx_cflags           flags for compiler xx
341 #   xx_cflags_maybe     flags for compiler xx, if they work
342 #   xx_cppflags         cpp flags for compiler xx
343 #   xx_cflags_optlist   list of sets of optional flags
344 #   xx_cflags_yyy       set yyy of optional flags for compiler xx
345 #   xx_ldflags          -Wc,-foo flags for libtool linking with compiler xx
346 #   ar_flags            extra flags for $AR
347 #   nm_flags            extra flags for $NM
348 #   limb                limb size, can be "longlong"
349 #   path                mpn search path
350 #   extra_functions     extra mpn functions
351 #   fat_path            fat binary mpn search path [if fat binary desired]
352 #   fat_functions       fat functions
353 #   fat_thresholds      fat thresholds
354 #
355 # Suppose xx_cflags_optlist="arch", then flags from $xx_cflags_arch are
356 # tried, and the first flag that works will be used.  An optlist like "arch
357 # cpu optimize" can be used to get multiple independent sets of flags tried.
358 # The first that works from each will be used.  If no flag in a set works
359 # then nothing from that set is added.
360 #
361 # For multiple ABIs, the scheme extends as follows.
362 #
363 #   abilist               set of ABI choices
364 #   cclist_aa             compiler choices in ABI aa
365 #   xx_aa_cflags          flags for xx in ABI aa
366 #   xx_aa_cflags_maybe    flags for xx in ABI aa, if they work
367 #   xx_aa_cppflags        cpp flags for xx in ABI aa
368 #   xx_aa_cflags_optlist  list of sets of optional flags in ABI aa
369 #   xx_aa_cflags_yyy      set yyy of optional flags for compiler xx in ABI aa
370 #   xx_aa_ldflags         -Wc,-foo flags for libtool linking
371 #   ar_aa_flags           extra flags for $AR in ABI aa
372 #   nm_aa_flags           extra flags for $NM in ABI aa
373 #   limb_aa               limb size in ABI aa, can be "longlong"
374 #   path_aa               mpn search path in ABI aa
375 #   extra_functions_aa    extra mpn functions in ABI aa
376 #
377 # As a convenience, the unadorned xx_cflags (etc) are used for the last ABI
378 # in ablist, if an xx_aa_cflags for that ABI isn't given.  For example if
379 # abilist="64 32" then $cc_64_cflags will be used for the 64-bit ABI, but
380 # for the 32-bit either $cc_32_cflags or $cc_cflags is used, whichever is
381 # defined.  This makes it easy to add some 64-bit compilers and flags to an
382 # unadorned 32-bit set.
383 #
384 # limb=longlong (or limb_aa=longlong) applies to all compilers within that
385 # ABI.  It won't work to have some needing long long and some not, since a
386 # single instantiated gmp.h will be used by both.
387 #
388 # SPEED_CYCLECOUNTER, cyclecounter_size and CALLING_CONVENTIONS_OBJS are
389 # also set here, with an ABI suffix.
390 #
391 #
392 #
393 # A table-driven approach like this to mapping cpu type to good compiler
394 # options is a bit of a maintenance burden, but there's not much uniformity
395 # between options specifications on different compilers.  Some sort of
396 # separately updatable tool might be cute.
397 #
398 # The use of lots of variables like this, direct and indirect, tends to
399 # obscure when and how various things are done, but unfortunately it's
400 # pretty much the only way.  If shell subroutines were portable then actual
401 # code like "if this .. do that" could be written, but attempting the same
402 # with full copies of GMP_PROG_CC_WORKS etc expanded at every point would
403 # hugely bloat the output.
404
405
406 AC_ARG_VAR(ABI, [desired ABI (for processors supporting more than one ABI)])
407
408 # abilist needs to be non-empty, "standard" is just a generic name here
409 abilist="standard"
410
411 # FIXME: We'd like to prefer an ANSI compiler, perhaps by preferring
412 # c89 over cc here.  But note that on HP-UX c89 provides a castrated
413 # environment, and would want to be excluded somehow.  Maybe
414 # AC_PROG_CC_STDC already does enough to stick cc into ANSI mode and
415 # we don't need to worry.
416 #
417 cclist="gcc cc"
418
419 gcc_cflags="-O2 -pedantic"
420 gcc_64_cflags="-O2 -pedantic"
421 cc_cflags="-O"
422 cc_64_cflags="-O"
423
424 SPEED_CYCLECOUNTER_OBJ=
425 cyclecounter_size=2
426
427 AC_SUBST(HAVE_HOST_CPU_FAMILY_power,  0)
428 AC_SUBST(HAVE_HOST_CPU_FAMILY_powerpc,0)
429
430 case $host in
431
432   a29k*-*-*)
433     path="a29k"
434     ;;
435
436
437   alpha*-*-*)
438     AC_DEFINE(HAVE_HOST_CPU_FAMILY_alpha)
439     case $host_cpu in
440       alphaev5* | alphapca5*)
441         path="alpha/ev5 alpha" ;;
442       alphaev67 | alphaev68 | alphaev7*)
443         path="alpha/ev67 alpha/ev6 alpha" ;;
444       alphaev6)
445         path="alpha/ev6 alpha" ;;
446       *)
447         path="alpha" ;;
448     esac
449     extra_functions="cntlz"
450     gcc_cflags_optlist="asm cpu oldas" # need asm ahead of cpu, see below
451     gcc_cflags_oldas="-Wa,-oldas"     # see GMP_GCC_WA_OLDAS.
452
453     # gcc 2.7.2.3 doesn't know any -mcpu= for alpha, apparently.
454     # gcc 2.95 knows -mcpu= ev4, ev5, ev56, pca56, ev6.
455     # gcc 3.0 adds nothing.
456     # gcc 3.1 adds ev45, ev67 (but ev45 is the same as ev4).
457     # gcc 3.2 adds nothing.
458     #
459     # gcc version "2.9-gnupro-99r1" under "-O2 -mcpu=ev6" strikes internal
460     # compiler errors too easily and is rejected by GMP_PROG_CC_WORKS.  Each
461     # -mcpu=ev6 below has a fallback to -mcpu=ev56 for this reason.
462     #
463     case $host_cpu in
464       alpha)        gcc_cflags_cpu="-mcpu=ev4" ;;
465       alphaev5)     gcc_cflags_cpu="-mcpu=ev5" ;;
466       alphaev56)    gcc_cflags_cpu="-mcpu=ev56" ;;
467       alphapca56 | alphapca57)
468                     gcc_cflags_cpu="-mcpu=pca56" ;;
469       alphaev6)     gcc_cflags_cpu="-mcpu=ev6 -mcpu=ev56" ;;
470       alphaev67 | alphaev68 | alphaev7*)
471                     gcc_cflags_cpu="-mcpu=ev67 -mcpu=ev6 -mcpu=ev56" ;;
472     esac
473
474     # gcc version "2.9-gnupro-99r1" on alphaev68-dec-osf5.1 has been seen
475     # accepting -mcpu=ev6, but not putting the assembler in the right mode
476     # for what it produces.  We need to do this for it, and need to do it
477     # before testing the -mcpu options.
478     #
479     # On old versions of gcc, which don't know -mcpu=, we believe an
480     # explicit -Wa,-mev5 etc will be necessary to put the assembler in
481     # the right mode for our .asm files and longlong.h asm blocks.
482     #
483     # On newer versions of gcc, when -mcpu= is known, we must give a -Wa
484     # which is at least as high as the code gcc will generate.  gcc
485     # establishes what it needs with a ".arch" directive, our command line
486     # option seems to override that.
487     #
488     # gas prior to 2.14 doesn't accept -mev67, but -mev6 seems enough for
489     # ctlz and cttz (in 2.10.0 at least).
490     #
491     # OSF `as' accepts ev68 but stupidly treats it as ev4.  -arch only seems
492     # to affect insns like ldbu which are expanded as macros when necessary.
493     # Insns like ctlz which were never available as macros are always
494     # accepted and always generate their plain code.
495     #
496     case $host_cpu in
497       alpha)        gcc_cflags_asm="-Wa,-arch,ev4 -Wa,-mev4" ;;
498       alphaev5)     gcc_cflags_asm="-Wa,-arch,ev5 -Wa,-mev5" ;;
499       alphaev56)    gcc_cflags_asm="-Wa,-arch,ev56 -Wa,-mev56" ;;
500       alphapca56 | alphapca57)
501                     gcc_cflags_asm="-Wa,-arch,pca56 -Wa,-mpca56" ;;
502       alphaev6)     gcc_cflags_asm="-Wa,-arch,ev6 -Wa,-mev6" ;;
503       alphaev67 | alphaev68 | alphaev7*)
504                     gcc_cflags_asm="-Wa,-arch,ev67 -Wa,-mev67 -Wa,-arch,ev6 -Wa,-mev6" ;;
505     esac
506
507     # It might be better to ask "cc" whether it's Cray C or DEC C,
508     # instead of relying on the OS part of $host.  But it's hard to
509     # imagine either of those compilers anywhere except their native
510     # systems.
511     #
512     GMP_INCLUDE_MPN(alpha/alpha-defs.m4)
513     case $host in
514       *-cray-unicos*)
515         cc_cflags="-O"          # no -g, it silently disables all optimizations
516         GMP_INCLUDE_MPN(alpha/unicos.m4)
517         # Don't perform any assembly syntax tests on this beast.
518         gmp_asm_syntax_testing=no
519         ;;
520       *-*-osf*)
521         GMP_INCLUDE_MPN(alpha/default.m4)
522         cc_cflags=""
523         cc_cflags_optlist="opt cpu"
524
525         # not sure if -fast works on old versions, so make it optional
526         cc_cflags_opt="-fast -O2"
527
528         # DEC C V5.9-005 knows ev4, ev5, ev56, pca56, ev6.
529         # Compaq C V6.3-029 adds ev67.
530         #
531         case $host_cpu in
532           alpha)       cc_cflags_cpu="-arch~ev4~-tune~ev4" ;;
533           alphaev5)    cc_cflags_cpu="-arch~ev5~-tune~ev5" ;;
534           alphaev56)   cc_cflags_cpu="-arch~ev56~-tune~ev56" ;;
535           alphapca56 | alphapca57)
536             cc_cflags_cpu="-arch~pca56~-tune~pca56" ;;
537           alphaev6)    cc_cflags_cpu="-arch~ev6~-tune~ev6" ;;
538           alphaev67 | alphaev68 | alphaev7*)
539             cc_cflags_cpu="-arch~ev67~-tune~ev67 -arch~ev6~-tune~ev6" ;;
540         esac
541         ;;
542       *)
543         GMP_INCLUDE_MPN(alpha/default.m4)
544         ;;
545     esac
546
547     case $host in
548       *-*-unicos*)
549         # tune/alpha.asm assumes int==4bytes but unicos uses int==8bytes
550         ;;
551       *)
552         SPEED_CYCLECOUNTER_OBJ=alpha.lo
553         cyclecounter_size=1 ;;
554     esac
555     ;;
556
557
558   # Cray vector machines.
559   # This must come after alpha* so that we can recognize present and future
560   # vector processors with a wildcard.
561   *-cray-unicos*)
562     gmp_asm_syntax_testing=no
563     cclist="cc"
564     # We used to have -hscalar0 here as a workaround for miscompilation of
565     # mpz/import.c, but let's hope Cray fixes their bugs instead, since
566     # -hscalar0 causes disastrously poor code to be generated.
567     cc_cflags="-O3 -hnofastmd -htask0 -Wa,-B"
568     path="cray"
569     ;;
570
571
572   arm*-*-*)
573     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
574     gcc_cflags_optlist="arch tune"
575     gcc_cflags_maybe="-marm"
576     gcc_testlist="gcc-arm-umodsi"
577     GMP_INCLUDE_MPN(arm/arm-defs.m4)
578     CALLING_CONVENTIONS_OBJS='arm32call.lo arm32check.lo'
579
580     case $host_cpu in
581       armsa1 | armv4*)
582         path="arm"
583         gcc_cflags_arch="-march=armv4"
584         ;;
585       armxscale | arm926 | arm946 | arm966 | arm1026 | armv5*)
586         path="arm/v5 arm"
587         gcc_cflags_arch="-march=armv5"
588         ;;
589       arm11mpcore | arm1136 | arm1176 | armv6*)
590         path="arm/v6 arm/v5 arm"
591         gcc_cflags_arch="-march=armv6"
592         ;;
593       arm1156)
594         path="arm/v6t2 arm/v6 arm/v5 arm"
595         gcc_cflags_arch="-march=armv6t2"
596         ;;
597       armcortexa9)
598         path="arm/v7a/cora9 arm/v6t2 arm/v6 arm/v5 arm"
599         gcc_cflags_arch="-march=armv7-a"
600         gcc_cflags_tune="-mtune=cortex-a9"
601         ;;
602       armcortexa15)
603         path="arm/v7a/cora15 arm/v6t2 arm/v6 arm/v5 arm"
604         gcc_cflags_arch="-march=armv7-a"
605         gcc_cflags_tune="-mtune=cortex-a15 -mtune=cortex-a9"
606         ;;
607       armcortexa5 | armcortexa8 | armv7a*)
608         path="arm/v6t2 arm/v6 arm/v5 arm"
609         gcc_cflags_arch="-march=armv7-a"
610         ;;
611       *)
612         path="arm"
613         ;;
614     esac
615     ;;
616
617
618   clipper*-*-*)
619     path="clipper"
620     ;;
621
622
623   # Fujitsu
624   [f30[01]-fujitsu-sysv*])
625     cclist="gcc vcc"
626     # FIXME: flags for vcc?
627     vcc_cflags="-g"
628     path="fujitsu"
629     ;;
630
631
632   hppa*-*-*)
633     # HP cc (the one sold separately) is K&R by default, but AM_C_PROTOTYPES
634     # will add "-Ae", or "-Aa -D_HPUX_SOURCE", to put it into ansi mode, if
635     # possible.
636     #
637     # gcc for hppa 2.0 can be built either for 2.0n (32-bit) or 2.0w
638     # (64-bit), but not both, so there's no option to choose the desired
639     # mode, we must instead detect which of the two it is.  This is done by
640     # checking sizeof(long), either 4 or 8 bytes respectively.  Do this in
641     # ABI=1.0 too, in case someone tries to build that with a 2.0w gcc.
642     #
643     gcc_cflags_optlist="arch"
644     gcc_testlist="sizeof-long-4"
645     SPEED_CYCLECOUNTER_OBJ=hppa.lo
646     cyclecounter_size=1
647
648     # FIXME: For hppa2.0*, path should be "pa32/hppa2_0 pa32/hppa1_1 pa32".
649     # (Can't remember why this isn't done already, have to check what .asm
650     # files are available in each and how they run on a typical 2.0 cpu.)
651     #
652     case $host_cpu in
653       hppa1.0*)    path="pa32" ;;
654       hppa7000*)   path="pa32/hppa1_1 pa32" ;;
655       hppa2.0* | hppa64)
656                    path="pa32/hppa2_0 pa32/hppa1_1/pa7100 pa32/hppa1_1 pa32" ;;
657       *)           # default to 7100
658                    path="pa32/hppa1_1/pa7100 pa32/hppa1_1 pa32" ;;
659     esac
660
661     # gcc 2.7.2.3 knows -mpa-risc-1-0 and -mpa-risc-1-1
662     # gcc 2.95 adds -mpa-risc-2-0, plus synonyms -march=1.0, 1.1 and 2.0
663     #
664     # We don't use -mpa-risc-2-0 in ABI=1.0 because 64-bit registers may not
665     # be saved by the kernel on an old system.  Actually gcc (as of 3.2)
666     # only adds a few float instructions with -mpa-risc-2-0, so it would
667     # probably be safe, but let's not take the chance.  In any case, a
668     # configuration like --host=hppa2.0 ABI=1.0 is far from optimal.
669     #
670     case $host_cpu in
671       hppa1.0*)           gcc_cflags_arch="-mpa-risc-1-0" ;;
672       *)                  # default to 7100
673                           gcc_cflags_arch="-mpa-risc-1-1" ;;
674     esac
675
676     case $host_cpu in
677       hppa1.0*)    cc_cflags="+O2" ;;
678       *)           # default to 7100
679                    cc_cflags="+DA1.1 +O2" ;;
680     esac
681
682     case $host in
683       hppa2.0*-*-* | hppa64-*-*)
684         cclist_20n="gcc cc"
685         abilist="2.0n 1.0"
686         path_20n="pa64"
687         limb_20n=longlong
688         any_20n_testlist="sizeof-long-4"
689         SPEED_CYCLECOUNTER_OBJ_20n=hppa2.lo
690         cyclecounter_size_20n=2
691
692         # -mpa-risc-2-0 is only an optional flag, in case an old gcc is
693         # used.  Assembler support for 2.0 is essential though, for our asm
694         # files.
695         gcc_20n_cflags="$gcc_cflags"
696         gcc_20n_cflags_optlist="arch"
697         gcc_20n_cflags_arch="-mpa-risc-2-0 -mpa-risc-1-1"
698         gcc_20n_testlist="sizeof-long-4 hppa-level-2.0"
699
700         cc_20n_cflags="+DA2.0 +e +O2 -Wl,+vnocompatwarnings"
701         cc_20n_testlist="hpc-hppa-2-0"
702
703         # ABI=2.0w is available for hppa2.0w and hppa2.0, but not for
704         # hppa2.0n, on the assumption that that the latter indicates a
705         # desire for ABI=2.0n.
706         case $host in
707         hppa2.0n-*-*) ;;
708         *)
709           # HPUX 10 and earlier cannot run 2.0w.  Not sure about other
710           # systems (GNU/Linux for instance), but lets assume they're ok.
711           case $host in
712             [*-*-hpux[1-9] | *-*-hpux[1-9].* | *-*-hpux10 | *-*-hpux10.*]) ;;
713             [*-*-linux*])  abilist="1.0" ;; # due to linux permanent kernel bug
714             *)    abilist="2.0w $abilist" ;;
715           esac
716
717           cclist_20w="gcc cc"
718           gcc_20w_cflags="$gcc_cflags -mpa-risc-2-0"
719           cc_20w_cflags="+DD64 +O2"
720           cc_20w_testlist="hpc-hppa-2-0"
721           path_20w="pa64"
722           any_20w_testlist="sizeof-long-8"
723           SPEED_CYCLECOUNTER_OBJ_20w=hppa2w.lo
724           cyclecounter_size_20w=2
725           ;;
726         esac
727         ;;
728     esac
729     ;;
730
731
732   i960*-*-*)
733     path="i960"
734     ;;
735
736
737   IA64_PATTERN)
738     abilist="64"
739     GMP_INCLUDE_MPN(ia64/ia64-defs.m4)
740     SPEED_CYCLECOUNTER_OBJ=ia64.lo
741     any_32_testlist="sizeof-long-4"
742
743     case $host_cpu in
744       itanium)   path="ia64/itanium  ia64" ;;
745       itanium2)  path="ia64/itanium2 ia64" ;;
746       *)         path="ia64" ;;
747     esac
748
749     gcc_64_cflags_optlist="tune"
750     gcc_32_cflags_optlist=$gcc_64_cflags_optlist
751
752     # gcc pre-release 3.4 adds -mtune itanium and itanium2
753     case $host_cpu in
754       itanium)   gcc_cflags_tune="-mtune=itanium" ;;
755       itanium2)  gcc_cflags_tune="-mtune=itanium2" ;;
756     esac
757
758     case $host in
759       *-*-linux*)
760         cclist="gcc icc"
761         icc_cflags="-no-gcc"
762         icc_cflags_optlist="opt"
763         # Don't use -O3, it is for "large data sets" and also miscompiles GMP.
764         # But icc miscompiles GMP at any optimization level, at higher levels
765         # it miscompiles more files...
766         icc_cflags_opt="-O2 -O1"
767         ;;
768
769       *-*-hpux*)
770         # HP cc sometimes gets internal errors if the optimization level is
771         # too high.  GMP_PROG_CC_WORKS detects this, the "_opt" fallbacks
772         # let us use whatever seems to work.
773         #
774         abilist="32 64"
775         any_64_testlist="sizeof-long-8"
776
777         cclist_32="gcc cc"
778         path_32="ia64"
779         cc_32_cflags=""
780         cc_32_cflags_optlist="opt"
781         cc_32_cflags_opt="+O3 +O2 +O1"
782         gcc_32_cflags="$gcc_cflags -milp32"
783         limb_32=longlong
784         SPEED_CYCLECOUNTER_OBJ_32=ia64.lo
785         cyclecounter_size_32=2
786
787         # Must have +DD64 in CPPFLAGS to get the right __LP64__ for headers,
788         # but also need it in CFLAGS for linking programs, since automake
789         # only uses CFLAGS when linking, not CPPFLAGS.
790         # FIXME: Maybe should use cc_64_ldflags for this, but that would
791         # need GMP_LDFLAGS used consistently by all the programs.
792         #
793         cc_64_cflags="+DD64"
794         cc_64_cppflags="+DD64"
795         cc_64_cflags_optlist="opt"
796         cc_64_cflags_opt="+O3 +O2 +O1"
797         gcc_64_cflags="$gcc_cflags -mlp64"
798         ;;
799     esac
800     ;;
801
802
803   # Motorola 68k
804   #
805   M68K_PATTERN)
806     AC_DEFINE(HAVE_HOST_CPU_FAMILY_m68k)
807     GMP_INCLUDE_MPN(m68k/m68k-defs.m4)
808     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
809     gcc_cflags_optlist="arch"
810
811     # gcc 2.7.2 knows -m68000, -m68020, -m68030, -m68040.
812     # gcc 2.95 adds -mcpu32, -m68060.
813     # FIXME: Maybe "-m68020 -mnobitfield" would suit cpu32 on 2.7.2.
814     #
815     case $host_cpu in
816     m68020)  gcc_cflags_arch="-m68020" ;;
817     m68030)  gcc_cflags_arch="-m68030" ;;
818     m68040)  gcc_cflags_arch="-m68040" ;;
819     m68060)  gcc_cflags_arch="-m68060 -m68000" ;;
820     m68360)  gcc_cflags_arch="-mcpu32 -m68000" ;;
821     *)       gcc_cflags_arch="-m68000" ;;
822     esac
823
824     # FIXME: m68k/mc68020 looks like it's ok for cpu32, but this wants to be
825     # tested.  Will need to introduce an m68k/cpu32 if m68k/mc68020 ever uses
826     # the bitfield instructions.
827     case $host_cpu in
828     [m680[234]0 | m68360])  path="m68k/mc68020 m68k" ;;
829     *)                      path="m68k" ;;
830     esac
831     ;;
832
833
834   # Motorola 88k
835   m88k*-*-*)
836     path="m88k"
837     ;;
838   m88110*-*-*)
839     gcc_cflags="$gcc_cflags -m88110"
840     path="m88k/mc88110 m88k"
841     ;;
842
843
844   # National Semiconductor 32k
845   ns32k*-*-*)
846     path="ns32k"
847     ;;
848
849
850   # IRIX 5 and earlier can only run 32-bit o32.
851   #
852   # IRIX 6 and up always has a 64-bit mips CPU can run n32 or 64.  n32 is
853   # preferred over 64, but only because that's been the default in past
854   # versions of GMP.  The two are equally efficient.
855   #
856   # Linux kernel 2.2.13 arch/mips/kernel/irixelf.c has a comment about not
857   # supporting n32 or 64.
858   #
859   # For reference, libtool (eg. 1.5.6) recognises the n32 ABI and knows the
860   # right options to use when linking (both cc and gcc), so no need for
861   # anything special from us.
862   #
863   mips*-*-*)
864     abilist="o32"
865     gcc_cflags_optlist="abi"
866     gcc_cflags_abi="-mabi=32"
867     gcc_testlist="gcc-mips-o32"
868     path="mips32"
869     cc_cflags="-O2 -o32"   # no -g, it disables all optimizations
870     # this suits both mips32 and mips64
871     GMP_INCLUDE_MPN(mips32/mips-defs.m4)
872
873     case $host in
874       [mips64*-*-* | mips*-*-irix[6789]*])
875         abilist="n32 64 o32"
876
877         cclist_n32="gcc cc"
878         gcc_n32_cflags="$gcc_cflags -mabi=n32"
879         cc_n32_cflags="-O2 -n32"        # no -g, it disables all optimizations
880         limb_n32=longlong
881         path_n32="mips64"
882
883         cclist_64="gcc cc"
884         gcc_64_cflags="$gcc_cflags -mabi=64"
885         gcc_64_ldflags="-Wc,-mabi=64"
886         cc_64_cflags="-O2 -64"          # no -g, it disables all optimizations
887         cc_64_ldflags="-Wc,-64"
888         path_64="mips64"
889         ;;
890     esac
891     ;;
892
893
894   # Darwin (powerpc-apple-darwin1.3) has it's hacked gcc installed as cc.
895   # Our usual "gcc in disguise" detection means gcc_cflags etc here gets
896   # used.
897   #
898   # The darwin pre-compiling preprocessor is disabled with -no-cpp-precomp
899   # since it doesn't like "__attribute__ ((mode (SI)))" etc in gmp-impl.h,
900   # and so always ends up running the plain preprocessor anyway.  This could
901   # be done in CPPFLAGS rather than CFLAGS, but there's not many places
902   # preprocessing is done separately, and this is only a speedup, the normal
903   # preprocessor gets run if there's any problems.
904   #
905   # We used to use -Wa,-mppc with gcc, but can't remember exactly why.
906   # Presumably it was for old versions of gcc where -mpowerpc doesn't put
907   # the assembler in the right mode.  In any case -Wa,-mppc is not good, for
908   # instance -mcpu=604 makes recent gcc use -m604 to get access to the
909   # "fsel" instruction, but a -Wa,-mppc overrides that, making code that
910   # comes out with fsel fail.
911   #
912   # (Note also that the darwin assembler doesn't accept "-mppc", so any
913   # -Wa,-mppc was used only if it worked.  The right flag on darwin would be
914   # "-arch ppc" or some such, but that's already the default.)
915   #
916   [powerpc*-*-* | power[3-9]-*-*])
917     AC_DEFINE(HAVE_HOST_CPU_FAMILY_powerpc)
918     HAVE_HOST_CPU_FAMILY_powerpc=1
919     abilist="32"
920     cclist="gcc cc"
921     cc_cflags="-O2"
922     gcc_32_cflags="$gcc_cflags -mpowerpc"
923     gcc_cflags_optlist="precomp subtype asm cpu"
924     gcc_cflags_precomp="-no-cpp-precomp"
925     gcc_cflags_subtype="-force_cpusubtype_ALL"  # for vmx on darwin
926     gcc_cflags_asm=""
927     gcc_cflags_cpu=""
928     vmx_path=""
929
930     # grab this object, though it's not a true cycle counter routine
931     SPEED_CYCLECOUNTER_OBJ=powerpc.lo
932     cyclecounter_size=0
933
934     case $host_cpu in
935       powerpc740 | powerpc750)
936         path="powerpc32/750 powerpc32" ;;
937       powerpc7400 | powerpc7410)
938         path="powerpc32/vmx powerpc32/750 powerpc32" ;;
939       [powerpc74[45]?])
940         path="powerpc32/vmx powerpc32" ;;
941       *)
942         path="powerpc32" ;;
943     esac
944
945     case $host_cpu in
946       powerpc401)   gcc_cflags_cpu="-mcpu=401" ;;
947       powerpc403)   gcc_cflags_cpu="-mcpu=403"
948                     xlc_cflags_arch="-qarch=403 -qarch=ppc" ;;
949       powerpc405)   gcc_cflags_cpu="-mcpu=405" ;;
950       powerpc505)   gcc_cflags_cpu="-mcpu=505" ;;
951       powerpc601)   gcc_cflags_cpu="-mcpu=601"
952                     xlc_cflags_arch="-qarch=601 -qarch=ppc" ;;
953       powerpc602)   gcc_cflags_cpu="-mcpu=602"
954                     xlc_cflags_arch="-qarch=602 -qarch=ppc" ;;
955       powerpc603)   gcc_cflags_cpu="-mcpu=603"
956                     xlc_cflags_arch="-qarch=603 -qarch=ppc" ;;
957       powerpc603e)  gcc_cflags_cpu="-mcpu=603e -mcpu=603"
958                     xlc_cflags_arch="-qarch=603 -qarch=ppc" ;;
959       powerpc604)   gcc_cflags_cpu="-mcpu=604"
960                     xlc_cflags_arch="-qarch=604 -qarch=ppc" ;;
961       powerpc604e)  gcc_cflags_cpu="-mcpu=604e -mcpu=604"
962                     xlc_cflags_arch="-qarch=604 -qarch=ppc" ;;
963       powerpc620)   gcc_cflags_cpu="-mcpu=620" ;;
964       powerpc630)   gcc_cflags_cpu="-mcpu=630"
965                     xlc_cflags_arch="-qarch=pwr3"
966                     cpu_path="p3 p3-p7" ;;
967       powerpc740)   gcc_cflags_cpu="-mcpu=740" ;;
968       powerpc7400 | powerpc7410)
969                     gcc_cflags_asm="-Wa,-maltivec"
970                     gcc_cflags_cpu="-mcpu=7400 -mcpu=750" ;;
971       [powerpc74[45]?])
972                     gcc_cflags_asm="-Wa,-maltivec"
973                     gcc_cflags_cpu="-mcpu=7450" ;;
974       powerpc750)   gcc_cflags_cpu="-mcpu=750" ;;
975       powerpc801)   gcc_cflags_cpu="-mcpu=801" ;;
976       powerpc821)   gcc_cflags_cpu="-mcpu=821" ;;
977       powerpc823)   gcc_cflags_cpu="-mcpu=823" ;;
978       powerpc860)   gcc_cflags_cpu="-mcpu=860" ;;
979       powerpc970)   gcc_cflags_cpu="-mtune=970"
980                     xlc_cflags_arch="-qarch=970 -qarch=pwr3"
981                     vmx_path="powerpc64/vmx"
982                     cpu_path="p4 p3-p7" ;;
983       power4)       gcc_cflags_cpu="-mtune=power4"
984                     xlc_cflags_arch="-qarch=pwr4"
985                     cpu_path="p4 p3-p7" ;;
986       power5)       gcc_cflags_cpu="-mtune=power5 -mtune=power4"
987                     xlc_cflags_arch="-qarch=pwr5"
988                     cpu_path="p5 p4 p3-p7" ;;
989       power6)       gcc_cflags_cpu="-mtune=power6"
990                     xlc_cflags_arch="-qarch=pwr6"
991                     cpu_path="p6 p3-p7" ;;
992       power7)       gcc_cflags_cpu="-mtune=power7 -mtune=power5"
993                     xlc_cflags_arch="-qarch=pwr7 -qarch=pwr5"
994                     cpu_path="p7 p5 p4 p3-p7" ;;
995     esac
996
997     case $host in
998       *-*-aix*)
999         cclist="gcc xlc cc"
1000         gcc_32_cflags_maybe="-maix32"
1001         xlc_cflags="-O2 -qmaxmem=20000"
1002         xlc_cflags_optlist="arch"
1003         xlc_32_cflags_maybe="-q32"
1004         ar_32_flags="-X32"
1005         nm_32_flags="-X32"
1006     esac
1007
1008     case $host in
1009       POWERPC64_PATTERN)
1010         case $host in
1011           *-*-aix*)
1012             # On AIX a true 64-bit ABI is available.
1013             # Need -Wc to pass object type flags through to the linker.
1014             abilist="mode64 $abilist"
1015             cclist_mode64="gcc xlc"
1016             gcc_mode64_cflags="$gcc_cflags -maix64 -mpowerpc64"
1017             gcc_mode64_cflags_optlist="cpu"
1018             gcc_mode64_ldflags="-Wc,-maix64"
1019             xlc_mode64_cflags="-O2 -q64 -qmaxmem=20000"
1020             xlc_mode64_cflags_optlist="arch"
1021             xlc_mode64_ldflags="-Wc,-q64"
1022             # Must indicate object type to ar and nm
1023             ar_mode64_flags="-X64"
1024             nm_mode64_flags="-X64"
1025             path_mode64=""
1026             p=""
1027             for i in $cpu_path
1028               do path_mode64="${path_mode64}powerpc64/mode64/$i "
1029                  path_mode64="${path_mode64}powerpc64/$i "
1030                  p="${p} powerpc32/$i "
1031               done
1032             path_mode64="${path_mode64}powerpc64/mode64 $vmx_path powerpc64"
1033             path="$p $path"
1034             # grab this object, though it's not a true cycle counter routine
1035             SPEED_CYCLECOUNTER_OBJ_mode64=powerpc64.lo
1036             cyclecounter_size_mode64=0
1037             ;;
1038           *-*-darwin*)
1039             # On Darwin we can use 64-bit instructions with a longlong limb,
1040             # but the chip still in 32-bit mode.
1041             # In theory this can be used on any OS which knows how to save
1042             # 64-bit registers in a context switch.
1043             #
1044             # Note that we must use -mpowerpc64 with gcc, since the
1045             # longlong.h macros expect limb operands in a single 64-bit
1046             # register, not two 32-bit registers as would be given for a
1047             # long long without -mpowerpc64.  In theory we could detect and
1048             # accommodate both styles, but the proper 64-bit registers will
1049             # be fastest and are what we really want to use.
1050             #
1051             # One would think -mpowerpc64 would set the assembler in the right
1052             # mode to handle 64-bit instructions.  But for that, also
1053             # -force_cpusubtype_ALL is needed.
1054             #
1055             # Do not use -fast for Darwin, it actually adds options
1056             # incompatible with a shared library.
1057             #
1058             abilist="mode64 mode32 $abilist"
1059             gcc_32_cflags_maybe="-m32"
1060             gcc_cflags_opt="-O3 -O2 -O1"        # will this become used?
1061             cclist_mode32="gcc"
1062             gcc_mode32_cflags_maybe="-m32"
1063             gcc_mode32_cflags="-mpowerpc64"
1064             gcc_mode32_cflags_optlist="subtype cpu opt"
1065             gcc_mode32_cflags_subtype="-force_cpusubtype_ALL"
1066             gcc_mode32_cflags_opt="-O3 -O2 -O1"
1067             limb_mode32=longlong
1068             cclist_mode64="gcc"
1069             gcc_mode64_cflags="-m64"
1070             gcc_mode64_cflags_optlist="cpu opt"
1071             gcc_mode64_cflags_opt="-O3 -O2 -O1"
1072             path_mode64=""
1073             path_mode32=""
1074             p=""
1075             for i in $cpu_path
1076               do path_mode64="${path_mode64}powerpc64/mode64/$i "
1077                  path_mode64="${path_mode64}powerpc64/$i "
1078                  path_mode32="${path_mode32}powerpc64/mode32/$i "
1079                  path_mode32="${path_mode32}powerpc64/$i "
1080                  p="${p} powerpc32/$i "
1081               done
1082             path_mode64="${path_mode64}powerpc64/mode64 $vmx_path powerpc64"
1083             path_mode32="${path_mode32}powerpc64/mode32 $vmx_path powerpc64"
1084             path="$p $path"
1085             SPEED_CYCLECOUNTER_OBJ_mode64=powerpc64.lo
1086             cyclecounter_size_mode64=0
1087             any_mode64_testlist="sizeof-long-8"
1088             ;;
1089           *-*-linux* | *-*-*bsd*)
1090             # On GNU/Linux, assume the processor is in 64-bit mode.  Some
1091             # environments have a gcc that is always in 64-bit mode, while
1092             # others require -m64, hence the use of cflags_maybe.  The
1093             # sizeof-long-8 test checks the mode is right (for the no option
1094             # case).
1095             #
1096             # -mpowerpc64 is not used, since it should be the default in
1097             # 64-bit mode.  (We need its effect for the various longlong.h
1098             # asm macros to be right of course.)
1099             #
1100             # gcc64 was an early port of gcc to 64-bit mode, but should be
1101             # obsolete before too long.  We prefer plain gcc when it knows
1102             # 64-bits.
1103             #
1104             abilist="mode64 mode32 $abilist"
1105             gcc_32_cflags_maybe="-m32"
1106             cclist_mode32="gcc"
1107             gcc_mode32_cflags_maybe="-m32"
1108             gcc_mode32_cflags="-mpowerpc64"
1109             gcc_mode32_cflags_optlist="cpu opt"
1110             gcc_mode32_cflags_opt="-O3 -O2 -O1"
1111             limb_mode32=longlong
1112             cclist_mode64="gcc gcc64"
1113             gcc_mode64_cflags_maybe="-m64"
1114             gcc_mode64_cflags_optlist="cpu opt"
1115             gcc_mode64_cflags_opt="-O3 -O2 -O1"
1116             path_mode64=""
1117             path_mode32=""
1118             p=""
1119             for i in $cpu_path
1120               do path_mode64="${path_mode64}powerpc64/mode64/$i "
1121                  path_mode64="${path_mode64}powerpc64/$i "
1122                  path_mode32="${path_mode32}powerpc64/mode32/$i "
1123                  path_mode32="${path_mode32}powerpc64/$i "
1124                  p="${p} powerpc32/$i "
1125               done
1126             path_mode64="${path_mode64}powerpc64/mode64 $vmx_path powerpc64"
1127             path_mode32="${path_mode32}powerpc64/mode32 $vmx_path powerpc64"
1128             path="$p $path"
1129             SPEED_CYCLECOUNTER_OBJ_mode64=powerpc64.lo
1130             cyclecounter_size_mode64=0
1131             any_mode64_testlist="sizeof-long-8"
1132             ;;
1133         esac
1134         ;;
1135     esac
1136     ;;
1137
1138
1139   # POWER 32-bit
1140   [power-*-* | power[12]-*-* | power2sc-*-*])
1141     AC_DEFINE(HAVE_HOST_CPU_FAMILY_power)
1142     HAVE_HOST_CPU_FAMILY_power=1
1143     cclist="gcc"
1144     extra_functions="udiv_w_sdiv"
1145     path="power"
1146
1147     # gcc 2.7.2 knows rios1, rios2, rsc
1148     #
1149     # -mcpu=rios2 can tickle an AIX assembler bug (see GMP_PROG_CC_WORKS) so
1150     # there needs to be a fallback to just -mpower.
1151     #
1152     gcc_cflags_optlist="cpu"
1153     case $host in
1154       power-*-*)    gcc_cflags_cpu="-mcpu=power -mpower" ;;
1155       power1-*-*)   gcc_cflags_cpu="-mcpu=rios1 -mpower" ;;
1156       power2-*-*)   gcc_cflags_cpu="-mcpu=rios2 -mpower" ;;
1157       power2sc-*-*) gcc_cflags_cpu="-mcpu=rsc   -mpower" ;;
1158     esac
1159     case $host in
1160     *-*-aix*)
1161       cclist="gcc xlc"
1162       xlc_cflags="-O2 -qarch=pwr -qmaxmem=20000"
1163       ;;
1164     esac
1165     ;;
1166
1167
1168   pyramid-*-*)
1169     path="pyr"
1170     ;;
1171
1172
1173   # IBM System/390 and z/Architecture
1174   S390_PATTERN | S390X_PATTERN)
1175     abilist="32"
1176     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
1177     gcc_cflags_optlist="arch"
1178     path="s390_32"
1179     extra_functions="udiv_w_sdiv"
1180     gcc_32_cflags_maybe="-m31"
1181
1182     case $host_cpu in
1183       s390)
1184         ;;
1185       z900 | z900esa)
1186         cpu="z900"
1187         gccarch="$cpu"
1188         path="s390_32/esame/$cpu s390_32/esame s390_32"
1189         gcc_cflags_arch="-march=$gccarch"
1190         AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
1191         AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
1192         extra_functions=""
1193         ;;
1194       z990 | z990esa)
1195         cpu="z990"
1196         gccarch="$cpu"
1197         path="s390_32/esame/$cpu s390_32/esame s390_32"
1198         gcc_cflags_arch="-march=$gccarch"
1199         AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
1200         AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
1201         extra_functions=""
1202         ;;
1203       z9 | z9esa)
1204         cpu="z9"
1205         gccarch="z9-109"
1206         path="s390_32/esame/$cpu s390_32/esame s390_32"
1207         gcc_cflags_arch="-march=$gccarch"
1208         AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
1209         AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
1210         extra_functions=""
1211         ;;
1212       z10 | z10esa)
1213         cpu="z10"
1214         gccarch="z10"
1215         path="s390_32/esame/$cpu s390_32/esame s390_32"
1216         gcc_cflags_arch="-march=$gccarch"
1217         AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
1218         AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
1219         extra_functions=""
1220         ;;
1221       z196 | z196esa)
1222         cpu="z196"
1223         gccarch="z196"
1224         path="s390_32/esame/$cpu s390_32/esame s390_32"
1225         gcc_cflags_arch="-march=$gccarch"
1226         AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
1227         AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
1228         extra_functions=""
1229         ;;
1230       esac
1231
1232     case $host in
1233       S390X_PATTERN)
1234         abilist="64 32"
1235         cclist_64="gcc"
1236         gcc_64_cflags_optlist="arch"
1237         gcc_64_cflags="$gcc_cflags -m64"
1238         path_64="s390_64/$host_cpu s390_64"
1239         extra_functions=""
1240         ;;
1241       esac
1242     ;;
1243
1244
1245   sh-*-*)   path="sh" ;;
1246   [sh[2-4]-*-*])  path="sh/sh2 sh" ;;
1247
1248
1249   *sparc*-*-*)
1250     # sizeof(long)==4 or 8 is tested, to ensure we get the right ABI.  We've
1251     # had various bug reports where users have set CFLAGS for their desired
1252     # mode, but not set our ABI.  For some reason it's sparc where this
1253     # keeps coming up, presumably users there are accustomed to driving the
1254     # compiler mode that way.  The effect of our testlist setting is to
1255     # reject ABI=64 in favour of ABI=32 if the user has forced the flags to
1256     # 32-bit mode.
1257     #
1258     abilist="32"
1259     cclist="gcc acc cc"
1260     any_testlist="sizeof-long-4"
1261     GMP_INCLUDE_MPN(sparc32/sparc-defs.m4)
1262
1263     case $host_cpu in
1264       sparcv8 | microsparc | turbosparc)
1265         path="sparc32/v8 sparc32" ;;
1266       supersparc)
1267         path="sparc32/v8/supersparc sparc32/v8 sparc32" ;;
1268       [sparc64 | sparcv9* | ultrasparc | ultrasparc[234]*])
1269         path="sparc32/v9 sparc32/v8 sparc32" ;;
1270       [ultrasparct[12345]])
1271         path="sparc32/ultrasparct1 sparc32/v8 sparc32" ;;
1272       *)
1273         path="sparc32" ;;
1274     esac
1275
1276     # gcc 2.7.2 doesn't know about v9 and doesn't pass -xarch=v8plus to the
1277     # assembler.  Add it explicitly since the solaris assembler won't accept
1278     # our sparc32/v9 asm code without it.  gas accepts -xarch=v8plus too, so
1279     # it can be in the cflags unconditionally (though gas doesn't need it).
1280     #
1281     # gcc -m32 is needed to force 32-bit mode on a dual-ABI system, but past
1282     # gcc doesn't know that flag, hence cflags_maybe.  Note that -m32 cannot
1283     # be done through the optlist since the plain cflags would be run first
1284     # and we don't want to require the default mode (whatever it is) works.
1285     #
1286     # Note it's gcc_32_cflags_maybe and not gcc_cflags_maybe because the
1287     # latter would be used in the 64-bit ABI on systems like "*bsd" where
1288     # abilist="64" only.
1289     #
1290     case $host_cpu in
1291       [ultrasparct[345]])
1292         gcc_32_cflags="$gcc_cflags -Wa,-xarch=v8plusd" ;;
1293       sparc64 | sparcv9* | ultrasparc*)
1294         gcc_32_cflags="$gcc_cflags -Wa,-xarch=v8plus" ;;
1295     esac
1296     gcc_32_cflags_maybe="-m32"
1297     gcc_cflags_optlist="cpu"
1298
1299     # gcc 2.7.2 knows -mcypress, -msupersparc, -mv8, -msparclite.
1300     # gcc 2.95 knows -mcpu= v7, hypersparc, sparclite86x, f930, f934,
1301     #   sparclet, tsc701, v9, ultrasparc.  A warning is given that the
1302     #   plain -m forms will disappear.
1303     # gcc 3.0 adds nothing.
1304     # gcc 3.1 adds nothing.
1305     # gcc 3.2 adds nothing.
1306     # gcc 3.3 adds ultrasparc3.
1307     #
1308     case $host_cpu in
1309       supersparc)           gcc_cflags_cpu="-mcpu=supersparc -msupersparc" ;;
1310       sparcv8 | microsparc | turbosparc)
1311                             gcc_cflags_cpu="-mcpu=v8 -mv8" ;;
1312       sparc64 | sparcv9*)   gcc_cflags_cpu="-mcpu=v9 -mv8" ;;
1313       ultrasparc3)          gcc_cflags_cpu="-mcpu=ultrasparc3 -mcpu=ultrasparc -mv8" ;;
1314       ultrasparc*)          gcc_cflags_cpu="-mcpu=ultrasparc -mv8" ;;
1315       *)                    gcc_cflags_cpu="-mcpu=v7 -mcypress" ;;
1316     esac
1317
1318     # SunPRO cc and acc, and SunOS bundled cc
1319     case $host in
1320       *-*-solaris* | *-*-sunos*)
1321         # Note no -g, it disables all optimizations.
1322         cc_cflags=
1323         cc_cflags_optlist="opt arch cpu"
1324
1325         # SunOS cc doesn't know -xO4, fallback to -O2.
1326         cc_cflags_opt="-xO4 -O2"
1327
1328         # SunOS cc doesn't know -xarch, apparently always generating v7
1329         # code, so make this optional
1330         case $host_cpu in
1331           sparcv8 | microsparc | supersparc | turbosparc)
1332                                               cc_cflags_arch="-xarch=v8" ;;
1333           [ultrasparct[345]])                 cc_cflags_arch="-xarch=v8plusd" ;;
1334           sparc64 | sparcv9* | ultrasparc*)   cc_cflags_arch="-xarch=v8plus" ;;
1335           *)                                  cc_cflags_arch="-xarch=v7" ;;
1336         esac
1337
1338         # SunOS cc doesn't know -xchip and doesn't seem to have an equivalent.
1339         # SunPRO cc 5 recognises -xchip=generic, old, super, super2, micro,
1340         #   micro2, hyper, hyper2, powerup, ultra, ultra2, ultra2i.
1341         # SunPRO cc 6 adds -xchip=ultra2e, ultra3cu.
1342         #
1343         # FIXME: Which of ultra, ultra2 or ultra2i is the best fallback for
1344         # ultrasparc3?
1345         #
1346         case $host_cpu in
1347           supersparc)   cc_cflags_cpu="-xchip=super" ;;
1348           microsparc)   cc_cflags_cpu="-xchip=micro" ;;
1349           turbosparc)   cc_cflags_cpu="-xchip=micro2" ;;
1350           ultrasparc)   cc_cflags_cpu="-xchip=ultra" ;;
1351           ultrasparc2)  cc_cflags_cpu="-xchip=ultra2" ;;
1352           ultrasparc2i) cc_cflags_cpu="-xchip=ultra2i" ;;
1353           ultrasparc3)  cc_cflags_cpu="-xchip=ultra3 -xchip=ultra" ;;
1354           *)            cc_cflags_cpu="-xchip=generic" ;;
1355         esac
1356     esac
1357
1358     case $host_cpu in
1359       sparc64 | sparcv9* | ultrasparc*)
1360         case $host in
1361           # Solaris 6 and earlier cannot run ABI=64 since it doesn't save
1362           # registers properly, so ABI=32 is left as the only choice.
1363           #
1364           [*-*-solaris2.[0-6] | *-*-solaris2.[0-6].*]) ;;
1365
1366           # BSD sparc64 ports are 64-bit-only systems, so ABI=64 is the only
1367           # choice.  In fact they need no special compiler flags, gcc -m64
1368           # is the default, but it doesn't hurt to add it.  v9 CPUs always
1369           # use the sparc64 port, since the plain 32-bit sparc ports don't
1370           # run on a v9.
1371           #
1372           *-*-*bsd*) abilist="64" ;;
1373
1374           # For all other systems, we try both 64 and 32.
1375           #
1376           # GNU/Linux sparc64 has only recently gained a 64-bit user mode.
1377           # In the past sparc64 meant a v9 cpu, but there were no 64-bit
1378           # operations in user mode.  We assume that if "gcc -m64" works
1379           # then the system is suitable.  Hopefully even if someone attempts
1380           # to put a new gcc and/or glibc on an old system it won't run.
1381           #
1382           *) abilist="64 32" ;;
1383         esac
1384
1385         case $host_cpu in
1386           ultrasparc | ultrasparc2 | ultrasparc2i)
1387             path_64="sparc64/ultrasparc1234 sparc64" ;;
1388           [ultrasparc[34]])
1389             path_64="sparc64/ultrasparc34 sparc64/ultrasparc1234 sparc64" ;;
1390           [ultrasparct[12345]])
1391             path_64="sparc64/ultrasparct1 sparc64" ;;
1392           *)
1393             path_64="sparc64"
1394         esac
1395
1396         cclist_64="gcc"
1397         any_64_testlist="sizeof-long-8"
1398
1399         # gcc -mptr64 is probably implied by -m64, but we're not sure if
1400         # this was always so.  On Solaris in the past we always used both
1401         # "-m64 -mptr64".
1402         #
1403         # gcc -Wa,-xarch=v9 is thought to be necessary in some cases on
1404         # solaris, but it would seem likely that if gcc is going to generate
1405         # 64-bit code it will have to add that option itself where needed.
1406         # An extra copy of this option should be harmless though, but leave
1407         # it until we're sure.  (Might want -xarch=v9a or -xarch=v9b for the
1408         # higher cpu types instead.)
1409         #
1410         gcc_64_cflags="$gcc_cflags -m64 -mptr64"
1411         gcc_64_ldflags="-Wc,-m64"
1412         gcc_64_cflags_optlist="cpu"
1413
1414         case $host in
1415           *-*-solaris*)
1416             # Sun cc.
1417             #
1418             # We used to have -fast and some fixup options here, but it
1419             # recurrently caused problems with miscompilation.  Of course,
1420             # -fast is documented as miscompiling things for the sake of speed.
1421             #
1422             cclist_64="$cclist_64 cc"
1423             cc_64_cflags="-xO3 -xarch=v9"
1424             cc_64_cflags_optlist="cpu"
1425             ;;
1426         esac
1427
1428         # using the v9 %tick register
1429         SPEED_CYCLECOUNTER_OBJ_32=sparcv9.lo
1430         SPEED_CYCLECOUNTER_OBJ_64=sparcv9.lo
1431         cyclecounter_size_32=2
1432         cyclecounter_size_64=2
1433         ;;
1434     esac
1435     ;;
1436
1437
1438   # VAX
1439   vax*-*-*elf*)
1440     # Use elf conventions (i.e., '%' register prefix, no global prefix)
1441     #
1442     GMP_INCLUDE_MPN(vax/elf.m4)
1443     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
1444     path="vax"
1445     extra_functions="udiv_w_sdiv"
1446     ;;
1447   vax*-*-*)
1448     # Default to aout conventions (i.e., no register prefix, '_' global prefix)
1449     #
1450     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
1451     path="vax"
1452     extra_functions="udiv_w_sdiv"
1453     ;;
1454
1455
1456   # AMD and Intel x86 configurations, including AMD64
1457   #
1458   # Rumour has it gcc -O2 used to give worse register allocation than just
1459   # -O, but lets assume that's no longer true.
1460   #
1461   # -m32 forces 32-bit mode on a bi-arch 32/64 amd64 build of gcc.  -m64 is
1462   # the default in such a build (we think), so -m32 is essential for ABI=32.
1463   # This is, of course, done for any $host_cpu, not just x86_64, so we can
1464   # get such a gcc into the right mode to cross-compile to say i486-*-*.
1465   #
1466   # -m32 is not available in gcc 2.95 and earlier, hence cflags_maybe to use
1467   # it when it works.  We check sizeof(long)==4 to ensure we get the right
1468   # mode, in case -m32 has failed not because it's an old gcc, but because
1469   # it's a dual 32/64-bit gcc without a 32-bit libc, or whatever.
1470   #
1471   X86_PATTERN | X86_64_PATTERN)
1472     abilist="32"
1473     cclist="gcc icc cc"
1474     gcc_cflags="$gcc_cflags $fomit_frame_pointer"
1475     gcc_32_cflags_maybe="-m32"
1476     icc_cflags="-no-gcc"
1477     icc_cflags_optlist="opt"
1478     icc_cflags_opt="-O3 -O2 -O1"
1479     any_32_testlist="sizeof-long-4"
1480     CALLING_CONVENTIONS_OBJS='x86call.lo x86check$U.lo'
1481
1482     # Availability of rdtsc is checked at run-time.
1483     SPEED_CYCLECOUNTER_OBJ=pentium.lo
1484
1485     # gcc 2.7.2 only knows i386 and i486, using -m386 or -m486.  These
1486     #     represent -mcpu= since -m486 doesn't generate 486 specific insns.
1487     # gcc 2.95 adds k6, pentium and pentiumpro, and takes -march= and -mcpu=.
1488     # gcc 3.0 adds athlon.
1489     # gcc 3.1 adds k6-2, k6-3, pentium-mmx, pentium2, pentium3, pentium4,
1490     #     athlon-tbird, athlon-4, athlon-xp, athlon-mp.
1491     # gcc 3.2 adds winchip2.
1492     # gcc 3.3 adds winchip-c6.
1493     # gcc 3.3.1 from mandrake adds k8 and knows -mtune.
1494     # gcc 3.4 adds c3, c3-2, k8, and deprecates -mcpu in favour of -mtune.
1495     #
1496     # In gcc 2.95.[0123], -march=pentiumpro provoked a stack slot bug in an
1497     # old version of mpz/powm.c.  Seems to be fine with the current code, so
1498     # no need for any restrictions on that option.
1499     #
1500     # -march=pentiumpro can fail if the assembler doesn't know "cmov"
1501     # (eg. solaris 2.8 native "as"), so always have -march=pentium after
1502     # that as a fallback.
1503     #
1504     # -march=pentium4 and -march=k8 enable SSE2 instructions, which may or
1505     # may not be supported by the assembler and/or the OS, and is bad in gcc
1506     # prior to 3.3.  The tests will reject these if no good, so fallbacks
1507     # like "-march=pentium4 -mno-sse2" are given to try also without SSE2.
1508     # Note the relevant -march types are listed in the optflags handling
1509     # below, be sure to update there if adding new types emitting SSE2.
1510     #
1511     # -mtune is used at the start of each cpu option list to give something
1512     # gcc 3.4 will use, thereby avoiding warnings from -mcpu.  -mcpu forms
1513     # are retained for use by prior gcc.  For example pentium has
1514     # "-mtune=pentium -mcpu=pentium ...", the -mtune is for 3.4 and the
1515     # -mcpu for prior.  If there's a brand new choice in 3.4 for a chip,
1516     # like k8 for x86_64, then it can be the -mtune at the start, no need to
1517     # duplicate anything.
1518     #
1519     gcc_cflags_optlist="cpu arch"
1520     case $host_cpu in
1521       i386*)
1522         gcc_cflags_cpu="-mtune=i386 -mcpu=i386 -m386"
1523         gcc_cflags_arch="-march=i386"
1524         path="x86"
1525         ;;
1526       i486*)
1527         gcc_cflags_cpu="-mtune=i486 -mcpu=i486 -m486"
1528         gcc_cflags_arch="-march=i486"
1529         path="x86/i486 x86"
1530         ;;
1531       i586 | pentium)
1532         gcc_cflags_cpu="-mtune=pentium -mcpu=pentium -m486"
1533         gcc_cflags_arch="-march=pentium"
1534         path="x86/pentium x86"
1535         ;;
1536       pentiummmx)
1537         gcc_cflags_cpu="-mtune=pentium-mmx -mcpu=pentium-mmx -mcpu=pentium -m486"
1538         gcc_cflags_arch="-march=pentium-mmx -march=pentium"
1539         path="x86/pentium/mmx x86/pentium x86"
1540         ;;
1541       i686 | pentiumpro)
1542         gcc_cflags_cpu="-mtune=pentiumpro -mcpu=pentiumpro -mcpu=i486 -m486"
1543         gcc_cflags_arch="-march=pentiumpro -march=pentium"
1544         path="x86/p6 x86"
1545         ;;
1546       pentium2)
1547         gcc_cflags_cpu="-mtune=pentium2 -mcpu=pentium2 -mcpu=pentiumpro -mcpu=i486 -m486"
1548         gcc_cflags_arch="-march=pentium2 -march=pentiumpro -march=pentium"
1549         path="x86/p6/mmx x86/p6 x86"
1550         ;;
1551       pentium3)
1552         gcc_cflags_cpu="-mtune=pentium3 -mcpu=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1553         gcc_cflags_arch="-march=pentium3 -march=pentiumpro -march=pentium"
1554         path="x86/p6/p3mmx x86/p6/mmx x86/p6 x86"
1555         ;;
1556       pentiumm)
1557         gcc_cflags_cpu="-mtune=pentium3 -mcpu=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1558         gcc_cflags_arch="-march=pentium3 -march=pentiumpro -march=pentium"
1559         path="x86/p6/sse2 x86/p6/p3mmx x86/p6/mmx x86/p6 x86"
1560         ;;
1561       k6)
1562         gcc_cflags_cpu="-mtune=k6 -mcpu=k6 -mcpu=i486 -m486"
1563         gcc_cflags_arch="-march=k6"
1564         path="x86/k6/mmx x86/k6 x86"
1565         ;;
1566       k62)
1567         gcc_cflags_cpu="-mtune=k6-2 -mcpu=k6-2 -mcpu=k6 -mcpu=i486 -m486"
1568         gcc_cflags_arch="-march=k6-2 -march=k6"
1569         path="x86/k6/k62mmx x86/k6/mmx x86/k6 x86"
1570         ;;
1571       k63)
1572         gcc_cflags_cpu="-mtune=k6-3 -mcpu=k6-3 -mcpu=k6 -mcpu=i486 -m486"
1573         gcc_cflags_arch="-march=k6-3 -march=k6"
1574         path="x86/k6/k62mmx x86/k6/mmx x86/k6 x86"
1575         ;;
1576       geode)
1577         gcc_cflags_cpu="-mtune=k6-3 -mcpu=k6-3 -mcpu=k6 -mcpu=i486 -m486"
1578         gcc_cflags_arch="-march=k6-3 -march=k6"
1579         path="x86/geode x86/k6/k62mmx x86/k6/mmx x86/k6 x86"
1580         ;;
1581       athlon)
1582         # Athlon instruction costs are close to P6 (3 cycle load latency,
1583         # 4-6 cycle mul, 40 cycle div, pairable adc, etc) so if gcc doesn't
1584         # know athlon (eg. 2.95.2 doesn't) then fall back on pentiumpro.
1585         gcc_cflags_cpu="-mtune=athlon -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1586         gcc_cflags_arch="-march=athlon -march=pentiumpro -march=pentium"
1587         path="x86/k7/mmx x86/k7 x86"
1588         ;;
1589       i786 | pentium4)
1590         # pentiumpro is the primary fallback when gcc doesn't know pentium4.
1591         # This gets us cmov to eliminate branches.  Maybe "athlon" would be
1592         # a possibility on gcc 3.0.
1593         #
1594         gcc_cflags_cpu="-mtune=pentium4 -mcpu=pentium4 -mcpu=pentiumpro -mcpu=i486 -m486"
1595         gcc_cflags_arch="-march=pentium4 -march=pentium4~-mno-sse2 -march=pentiumpro -march=pentium"
1596         gcc_64_cflags_cpu="-mtune=nocona"
1597         path="x86/pentium4/sse2 x86/pentium4/mmx x86/pentium4 x86"
1598         path_64="x86_64/pentium4 x86_64"
1599         ;;
1600       viac32)
1601         # Not sure of the best fallbacks here for -mcpu.
1602         # c3-2 has sse and mmx, so pentium3 is good for -march.
1603         gcc_cflags_cpu="-mtune=c3-2 -mcpu=c3-2 -mcpu=i486 -m486"
1604         gcc_cflags_arch="-march=c3-2 -march=pentium3 -march=pentiumpro -march=pentium"
1605         path="x86/p6/p3mmx x86/p6/mmx x86/p6 x86"
1606         ;;
1607       viac3*)
1608         # Not sure of the best fallbacks here.
1609         gcc_cflags_cpu="-mtune=c3 -mcpu=c3 -mcpu=i486 -m486"
1610         gcc_cflags_arch="-march=c3 -march=pentium-mmx -march=pentium"
1611         path="x86/pentium/mmx x86/pentium x86"
1612         ;;
1613       athlon64 | k8 | x86_64)
1614         gcc_cflags_cpu="-mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1615         gcc_cflags_arch="-march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1616         path="x86/k8 x86/k7/mmx x86/k7 x86"
1617         path_64="x86_64/k8 x86_64"
1618         ;;
1619       k10)
1620         gcc_cflags_cpu="-mtune=amdfam10 -mtune=k8"
1621         gcc_cflags_arch="-march=amdfam10 -march=k8 -march=k8~-mno-sse2"
1622         path="x86/k10 x86/k8 x86/k7/mmx x86/k7 x86"
1623         path_64="x86_64/k10 x86_64/k8 x86_64"
1624         ;;
1625       bobcat)
1626         gcc_cflags_cpu="-mtune=btver1 -mtune=amdfam10 -mtune=k8"
1627         gcc_cflags_arch="-march=btver1 -march=amdfam10 -march=k8 -march=k8~-mno-sse2"
1628         path="x86/bobcat x86/k7/mmx x86/k7 x86"
1629         path_64="x86_64/bobcat x86_64/k10 x86_64/k8 x86_64"
1630         ;;
1631       bulldozer | bd1)
1632         gcc_cflags_cpu="-mtune=bdver1 -mtune=amdfam10 -mtune=k8"
1633         gcc_cflags_arch="-march=bdver1 -march=amdfam10 -march=k8 -march=k8~-mno-sse2"
1634         path="x86/bd1 x86/k7/mmx x86/k7 x86"
1635         path_64="x86_64/bd1 x86_64/k10 x86_64/k8 x86_64"
1636         ;;
1637       core2)
1638         gcc_cflags_cpu="-mtune=core2 -mtune=k8"
1639         gcc_cflags_arch="-march=core2 -march=core2~-mno-sse2 -march=k8 -march=k8~-mno-sse2"
1640         path="x86/core2 x86/p6/sse2 x86/p6/p3mmx x86/p6/mmx x86/p6 x86"
1641         path_64="x86_64/core2 x86_64"
1642        ;;
1643       corei | coreinhm | coreiwsm)
1644         gcc_cflags_cpu="-mtune=corei7 -mtune=core2 -mtune=k8"
1645         gcc_cflags_arch="-march=corei7 -march=core2 -march=core2~-mno-sse2 -march=k8 -march=k8~-mno-sse2"
1646         path="x86/coreinhm x86/p6/sse2 x86/p6/p3mmx x86/p6/mmx x86/p6 x86"
1647         path_64="x86_64/coreinhm x86_64/core2 x86_64"
1648         ;;
1649       coreisbr | coreihwl | coreibwl)
1650         gcc_cflags_cpu="-mtune=corei7 -mtune=core2 -mtune=k8"
1651         gcc_cflags_arch="-march=corei7 -march=core2 -march=core2~-mno-sse2 -march=k8 -march=k8~-mno-sse2"
1652         path="x86/coreisbr x86/p6/sse2 x86/p6/p3mmx x86/p6/mmx x86/p6 x86"
1653         path_64="x86_64/coreisbr x86_64/coreinhm x86_64/core2 x86_64"
1654         ;;
1655       atom)
1656         gcc_cflags_cpu="-mtune=atom -mtune=pentium3"
1657         gcc_cflags_arch="-march=atom -march=pentium3"
1658         path="x86/atom/sse2 x86/atom/mmx x86/atom x86"
1659         path_64="x86_64/atom x86_64"
1660         ;;
1661       nano)
1662         gcc_cflags_cpu="-mtune=nano"
1663         gcc_cflags_arch="-march=nano"
1664         path="x86/nano x86"
1665         path_64="x86_64/nano x86_64"
1666         ;;
1667       *)
1668         gcc_cflags_cpu="-mtune=i486 -mcpu=i486 -m486"
1669         gcc_cflags_arch="-march=i486"
1670         path="x86"
1671         path_64="x86_64"
1672         ;;
1673     esac
1674
1675     case $host in
1676       X86_64_PATTERN)
1677         cclist_64="gcc"
1678         gcc_64_cflags="$gcc_cflags -m64"
1679         gcc_64_cflags_optlist="cpu arch"
1680         CALLING_CONVENTIONS_OBJS_64='amd64call.lo amd64check$U.lo'
1681         SPEED_CYCLECOUNTER_OBJ_64=x86_64.lo
1682         cyclecounter_size_64=2
1683
1684         cclist_x32="gcc"
1685         gcc_x32_cflags="$gcc_cflags -mx32"
1686         gcc_x32_cflags_optlist="$gcc_64_cflags_optlist"
1687         CALLING_CONVENTIONS_OBJS_x32="$CALLING_CONVENTIONS_OBJS_64"
1688         SPEED_CYCLECOUNTER_OBJ_x32="$SPEED_CYCLECOUNTER_OBJ_64"
1689         cyclecounter_size_x32="$cyclecounter_size_64"
1690         path_x32="$path_64"
1691         limb_x32=longlong
1692         any_x32_testlist="sizeof-long-4"
1693
1694         abilist="64 x32 32"
1695         if test "$enable_assembly" = "yes" ; then
1696             extra_functions_64="invert_limb_table"
1697             extra_functions_x32=$extra_functions_64
1698         fi
1699
1700         case $host in
1701           *-*-solaris*)
1702             # Sun cc.
1703             cclist_64="$cclist_64 cc"
1704             cc_64_cflags="-xO3 -m64"
1705             ;;
1706           *-*-mingw* | *-*-cygwin)
1707             limb_64=longlong
1708             CALLING_CONVENTIONS_OBJS_64=""
1709             AC_DEFINE(HOST_DOS64,1,[Define to 1 for Windos/64])
1710             GMP_NONSTD_ABI_64=DOS64
1711             ;;
1712         esac
1713         ;;
1714     esac
1715     ;;
1716
1717
1718   # FIXME: z8kx won't get through config.sub.  Could make 16 versus 32 bit
1719   # limb an ABI option perhaps.
1720   z8kx*-*-*)
1721     path="z8000x"
1722     extra_functions="udiv_w_sdiv"
1723     ;;
1724   z8k*-*-*)
1725     path="z8000"
1726     extra_functions="udiv_w_sdiv"
1727     ;;
1728
1729
1730   # Special CPU "none" used to select generic C, now this is obsolete.
1731   none-*-*)
1732     enable_assembly=no
1733     AC_MSG_WARN([the \"none\" host is obsolete, use --disable-assembly])
1734     ;;
1735
1736 esac
1737
1738 # mingw can be built by the cygwin gcc if -mno-cygwin is added.  For
1739 # convenience add this automatically if it works.  Actual mingw gcc accepts
1740 # -mno-cygwin too, but of course is the default.  mingw only runs on the
1741 # x86s, but allow any CPU here so as to catch "none" too.
1742 #
1743 case $host in
1744   *-*-mingw*)
1745     gcc_cflags_optlist="$gcc_cflags_optlist nocygwin"
1746     gcc_cflags_nocygwin="-mno-cygwin"
1747     ;;
1748 esac
1749
1750
1751 CFLAGS_or_unset=${CFLAGS-'(unset)'}
1752 CPPFLAGS_or_unset=${CPPFLAGS-'(unset)'}
1753
1754 cat >&AC_FD_CC <<EOF
1755 User:
1756 ABI=$ABI
1757 CC=$CC
1758 CFLAGS=$CFLAGS_or_unset
1759 CPPFLAGS=$CPPFLAGS_or_unset
1760 MPN_PATH=$MPN_PATH
1761 GMP:
1762 abilist=$abilist
1763 cclist=$cclist
1764 EOF
1765
1766
1767 test_CFLAGS=${CFLAGS+set}
1768 test_CPPFLAGS=${CPPFLAGS+set}
1769
1770 for abi in $abilist; do
1771   abi_last="$abi"
1772 done
1773
1774 # If the user specifies an ABI then it must be in $abilist, after that
1775 # $abilist is restricted to just that choice.
1776 #
1777 if test -n "$ABI"; then
1778   found=no
1779   for abi in $abilist; do
1780     if test $abi = "$ABI"; then found=yes; break; fi
1781   done
1782   if test $found = no; then
1783     AC_MSG_ERROR([ABI=$ABI is not among the following valid choices: $abilist])
1784   fi
1785   abilist="$ABI"
1786 fi
1787
1788 found_compiler=no
1789
1790 for abi in $abilist; do
1791
1792   echo "checking ABI=$abi"
1793
1794   # Suppose abilist="64 32", then for abi=64, will have abi1="_64" and
1795   # abi2="_64".  For abi=32, will have abi1="_32" and abi2="".  This is how
1796   # $gcc_cflags becomes a fallback for $gcc_32_cflags (the last in the
1797   # abilist), but there's no fallback for $gcc_64_cflags.
1798   #
1799   abi1=[`echo _$abi | sed 's/[.]//g'`]
1800   if test $abi = $abi_last; then abi2=; else abi2="$abi1"; fi
1801
1802   # Compiler choices under this ABI
1803                               eval cclist_chosen=\"\$cclist$abi1\"
1804   test -n "$cclist_chosen" || eval cclist_chosen=\"\$cclist$abi2\"
1805
1806   # If there's a user specified $CC then don't use a list for
1807   # $cclist_chosen, just a single value for $ccbase.
1808   #
1809   if test -n "$CC"; then
1810
1811     # The first word of $CC, stripped of any directory.  For instance
1812     # CC="/usr/local/bin/gcc -pipe" will give "gcc".
1813     #
1814     for ccbase in $CC; do break; done
1815     ccbase=`echo $ccbase | sed 's:.*/::'`
1816
1817     # If this $ccbase is in $cclist_chosen then it's a compiler we know and
1818     # we can do flags defaulting with it.  If not, then $cclist_chosen is
1819     # set to "unrecognised" so no default flags are used.
1820     #
1821     # "unrecognised" is used to avoid bad effects with eval if $ccbase has
1822     # non-symbol characters.  For instance ccbase=my+cc would end up with
1823     # something like cflags="$my+cc_cflags" which would give
1824     # cflags="+cc_cflags" rather than the intended empty string for an
1825     # unknown compiler.
1826     #
1827     found=unrecognised
1828     for i in $cclist_chosen; do
1829       if test "$ccbase" = $i; then
1830         found=$ccbase
1831         break
1832       fi
1833     done
1834     cclist_chosen=$found
1835   fi
1836
1837   for ccbase in $cclist_chosen; do
1838
1839     # When cross compiling, look for a compiler with the $host_alias as a
1840     # prefix, the same way that AC_CHECK_TOOL does.  But don't do this to a
1841     # user-selected $CC.
1842     #
1843     # $cross_compiling will be yes/no/maybe at this point.  Do the host
1844     # prefixing for "maybe" as well as "yes".
1845     #
1846     if test "$cross_compiling" != no && test -z "$CC"; then
1847       cross_compiling_prefix="${host_alias}-"
1848     fi
1849
1850     for ccprefix in $cross_compiling_prefix ""; do
1851
1852       cc="$CC"
1853       test -n "$cc" || cc="$ccprefix$ccbase"
1854
1855       # If the compiler is gcc but installed under another name, then change
1856       # $ccbase so as to use the flags we know for gcc.  This helps for
1857       # instance when specifying CC=gcc272 on Debian GNU/Linux, or the
1858       # native cc which is really gcc on NeXT or MacOS-X.
1859       #
1860       # FIXME: There's a slight misfeature here.  If cc is actually gcc but
1861       # gcc is not a known compiler under this $abi then we'll end up
1862       # testing it with no flags and it'll work, but chances are it won't be
1863       # in the right mode for the ABI we desire.  Let's quietly hope this
1864       # doesn't happen.
1865       #
1866       if test $ccbase != gcc; then
1867         GMP_PROG_CC_IS_GNU($cc,ccbase=gcc)
1868       fi
1869
1870       # Similarly if the compiler is IBM xlc but invoked as cc or whatever
1871       # then change $ccbase and make the default xlc flags available.
1872       if test $ccbase != xlc; then
1873         GMP_PROG_CC_IS_XLC($cc,ccbase=xlc)
1874       fi
1875
1876       # acc was Sun's first unbundled compiler back in the SunOS days, or
1877       # something like that, but today its man page says it's not meant to
1878       # be used directly (instead via /usr/ucb/cc).  The options are pretty
1879       # much the same as the main SunPRO cc, so share those configs.
1880       #
1881       case $host in
1882         *sparc*-*-solaris* | *sparc*-*-sunos*)
1883           if test "$ccbase" = acc; then ccbase=cc; fi ;;
1884       esac
1885
1886       for tmp_cflags_maybe in yes no; do
1887                              eval cflags=\"\$${ccbase}${abi1}_cflags\"
1888         test -n "$cflags" || eval cflags=\"\$${ccbase}${abi2}_cflags\"
1889
1890         if test "$tmp_cflags_maybe" = yes; then
1891           # don't try cflags_maybe when the user set CFLAGS
1892           if test "$test_CFLAGS" = set; then continue; fi
1893                                      eval cflags_maybe=\"\$${ccbase}${abi1}_cflags_maybe\"
1894           test -n "$cflags_maybe" || eval cflags_maybe=\"\$${ccbase}${abi2}_cflags_maybe\"
1895           # don't try cflags_maybe if there's nothing set
1896           if test -z "$cflags_maybe"; then continue; fi
1897           cflags="$cflags_maybe $cflags"
1898         fi
1899
1900         # Any user CFLAGS, even an empty string, takes precedence
1901         if test "$test_CFLAGS" = set; then cflags=$CFLAGS; fi
1902
1903         # Any user CPPFLAGS, even an empty string, takes precedence
1904                                eval cppflags=\"\$${ccbase}${abi1}_cppflags\"
1905         test -n "$cppflags" || eval cppflags=\"\$${ccbase}${abi2}_cppflags\"
1906         if test "$test_CPPFLAGS" = set; then cppflags=$CPPFLAGS; fi
1907
1908         # --enable-profiling adds -p/-pg even to user-specified CFLAGS.
1909         # This is convenient, but it's perhaps a bit naughty to modify user
1910         # CFLAGS.
1911         case "$enable_profiling" in
1912           prof)       cflags="$cflags -p" ;;
1913           gprof)      cflags="$cflags -pg" ;;
1914           instrument) cflags="$cflags -finstrument-functions" ;;
1915         esac
1916
1917         GMP_PROG_CC_WORKS($cc $cflags $cppflags,,continue)
1918
1919         # If we're supposed to be using a "long long" for a limb, check that
1920         # it works.
1921                                   eval limb_chosen=\"\$limb$abi1\"
1922         test -n "$limb_chosen" || eval limb_chosen=\"\$limb$abi2\"
1923         if test "$limb_chosen" = longlong; then
1924           GMP_PROG_CC_WORKS_LONGLONG($cc $cflags $cppflags,,continue)
1925         fi
1926
1927         # The tests to perform on this $cc, if any
1928                                eval testlist=\"\$${ccbase}${abi1}_testlist\"
1929         test -n "$testlist" || eval testlist=\"\$${ccbase}${abi2}_testlist\"
1930         test -n "$testlist" || eval testlist=\"\$any${abi1}_testlist\"
1931         test -n "$testlist" || eval testlist=\"\$any${abi2}_testlist\"
1932
1933         testlist_pass=yes
1934         for tst in $testlist; do
1935           case $tst in
1936           hpc-hppa-2-0)   GMP_HPC_HPPA_2_0($cc,,testlist_pass=no) ;;
1937           gcc-arm-umodsi) GMP_GCC_ARM_UMODSI($cc,,testlist_pass=no) ;;
1938           gcc-mips-o32)   GMP_GCC_MIPS_O32($cc,,testlist_pass=no) ;;
1939           hppa-level-2.0) GMP_HPPA_LEVEL_20($cc $cflags,,testlist_pass=no) ;;
1940           sizeof*)       GMP_C_TEST_SIZEOF($cc $cflags,$tst,,testlist_pass=no) ;;
1941           esac
1942           if test $testlist_pass = no; then break; fi
1943         done
1944
1945         if test $testlist_pass = yes; then
1946           found_compiler=yes
1947           break
1948         fi
1949       done
1950
1951       if test $found_compiler = yes; then break; fi
1952     done
1953
1954     if test $found_compiler = yes; then break; fi
1955   done
1956
1957   if test $found_compiler = yes; then break; fi
1958 done
1959
1960
1961 # If we recognised the CPU, as indicated by $path being set, then insist
1962 # that we have a working compiler, either from our $cclist choices or from
1963 # $CC.  We can't let AC_PROG_CC look around for a compiler because it might
1964 # find one that we've rejected (for not supporting the modes our asm code
1965 # demands, etc).
1966 #
1967 # If we didn't recognise the CPU (and this includes host_cpu=none), then
1968 # fall through and let AC_PROG_CC look around for a compiler too.  This is
1969 # mostly in the interests of following a standard autoconf setup, after all
1970 # we've already tested cc and gcc adequately (hopefully).  As of autoconf
1971 # 2.50 the only thing AC_PROG_CC really adds is a check for "cl" (Microsoft
1972 # C on MS-DOS systems).
1973 #
1974 if test $found_compiler = no && test -n "$path"; then
1975   AC_MSG_ERROR([could not find a working compiler, see config.log for details])
1976 fi
1977
1978 case $host in
1979   X86_PATTERN | X86_64_PATTERN)
1980     # If the user asked for a fat build, override the path and flags set above
1981     if test $enable_fat = yes; then
1982       gcc_cflags_cpu=""
1983       gcc_cflags_arch=""
1984
1985       fat_functions="add_n addmul_1 bdiv_dbm1c com copyd copyi dive_1 divrem_1
1986                      gcd_1 lshift lshiftc mod_1 mod_1_1 mod_1_1_cps mod_1_2
1987                      mod_1_2_cps mod_1_4 mod_1_4_cps mod_34lsub1 mode1o mul_1
1988                      mul_basecase mullo_basecase pre_divrem_1 pre_mod_1 redc_1
1989                      redc_2 rshift sqr_basecase sub_n submul_1"
1990
1991       if test "$abi" = 32; then
1992         extra_functions="$extra_functions fat fat_entry"
1993         path="x86/fat x86"
1994         fat_path="x86 x86/fat x86/i486
1995                   x86/k6 x86/k6/mmx x86/k6/k62mmx
1996                   x86/k7 x86/k7/mmx
1997                   x86/k8 x86/k10 x86/bobcat
1998                   x86/pentium x86/pentium/mmx
1999                   x86/p6 x86/p6/mmx x86/p6/p3mmx x86/p6/sse2
2000                   x86/pentium4 x86/pentium4/mmx x86/pentium4/sse2
2001                   x86/core2 x86/coreinhm x86/coreisbr
2002                   x86/atom x86/atom/mmx x86/atom/sse2 x86/nano"
2003       fi
2004
2005       if test "$abi" = 64; then
2006         gcc_64_cflags=""
2007         extra_functions_64="$extra_functions_64 fat fat_entry"
2008         path_64="x86_64/fat x86_64"
2009         fat_path="x86_64 x86_64/fat
2010                   x86_64/k8 x86_64/k10 x86_64/bd1 x86_64/bobcat
2011                   x86_64/pentium4 x86_64/core2 x86_64/coreinhm x86_64/coreisbr
2012                   x86_64/atom x86_64/nano"
2013         fat_functions="$fat_functions addmul_2 addlsh1_n addlsh2_n sublsh1_n"
2014       fi
2015
2016       fat_thresholds="MUL_TOOM22_THRESHOLD MUL_TOOM33_THRESHOLD
2017                       SQR_TOOM2_THRESHOLD SQR_TOOM3_THRESHOLD
2018                       BMOD_1_TO_MOD_1_THRESHOLD"
2019     fi
2020     ;;
2021 esac
2022
2023
2024 if test $found_compiler = yes; then
2025
2026   # If we're creating CFLAGS, then look for optional additions.  If the user
2027   # set CFLAGS then leave it alone.
2028   #
2029   if test "$test_CFLAGS" != set; then
2030                           eval optlist=\"\$${ccbase}${abi1}_cflags_optlist\"
2031     test -n "$optlist" || eval optlist=\"\$${ccbase}${abi2}_cflags_optlist\"
2032
2033     for opt in $optlist; do
2034                              eval optflags=\"\$${ccbase}${abi1}_cflags_${opt}\"
2035       test -n "$optflags" || eval optflags=\"\$${ccbase}${abi2}_cflags_${opt}\"
2036       test -n "$optflags" || eval optflags=\"\$${ccbase}_cflags_${opt}\"
2037
2038       for flag in $optflags; do
2039
2040         # ~ represents a space in an option spec
2041         flag=`echo "$flag" | tr '~' ' '`
2042
2043         case $flag in
2044           -march=pentium4 | -march=k8)
2045             # For -march settings which enable SSE2 we exclude certain bad
2046             # gcc versions and we need an OS knowing how to save xmm regs.
2047             #
2048             # This is only for ABI=32, any 64-bit gcc is good and any OS
2049             # knowing x86_64 will know xmm.
2050             #
2051             # -march=k8 was only introduced in gcc 3.3, so we shouldn't need
2052             # the GMP_GCC_PENTIUM4_SSE2 check (for gcc 3.2 and prior).  But
2053             # it doesn't hurt to run it anyway, sharing code with the
2054             # pentium4 case.
2055             #
2056             if test "$abi" = 32; then
2057               GMP_GCC_PENTIUM4_SSE2($cc $cflags $cppflags,, continue)
2058               GMP_OS_X86_XMM($cc $cflags $cppflags,, continue)
2059             fi
2060             ;;
2061           -no-cpp-precomp)
2062             # special check, avoiding a warning
2063             GMP_GCC_NO_CPP_PRECOMP($ccbase,$cc,$cflags,
2064                                    [cflags="$cflags $flag"
2065                                    break],
2066                                    [continue])
2067             ;;
2068           -Wa,-m*)
2069             case $host in
2070               alpha*-*-*)
2071                 GMP_GCC_WA_MCPU($cc $cflags, $flag, , [continue])
2072               ;;
2073             esac
2074             ;;
2075           -Wa,-oldas)
2076             GMP_GCC_WA_OLDAS($cc $cflags $cppflags,
2077                              [cflags="$cflags $flag"
2078                              break],
2079                              [continue])
2080             ;;
2081         esac
2082
2083         GMP_PROG_CC_WORKS($cc $cflags $cppflags $flag,
2084           [cflags="$cflags $flag"
2085           break])
2086       done
2087     done
2088   fi
2089
2090   ABI="$abi"
2091   CC="$cc"
2092   CFLAGS="$cflags"
2093   CPPFLAGS="$cppflags"
2094   eval GMP_NONSTD_ABI=\"\$GMP_NONSTD_ABI_$ABI\"
2095
2096   # Could easily have this in config.h too, if desired.
2097   ABI_nodots=`echo $ABI | sed 's/\./_/'`
2098   GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_ABI_$ABI_nodots')", POST)
2099
2100
2101   # GMP_LDFLAGS substitution, selected according to ABI.
2102   # These are needed on libgmp.la and libmp.la, but currently not on
2103   # convenience libraries like tune/libspeed.la or mpz/libmpz.la.
2104   #
2105                             eval GMP_LDFLAGS=\"\$${ccbase}${abi1}_ldflags\"
2106   test -n "$GMP_LDFLAGS" || eval GMP_LDFLAGS=\"\$${ccbase}${abi1}_ldflags\"
2107   AC_SUBST(GMP_LDFLAGS)
2108   AC_SUBST(LIBGMP_LDFLAGS)
2109   AC_SUBST(LIBGMPXX_LDFLAGS)
2110
2111   # extra_functions, selected according to ABI
2112                     eval tmp=\"\$extra_functions$abi1\"
2113   test -n "$tmp" || eval tmp=\"\$extra_functions$abi2\"
2114   extra_functions="$tmp"
2115
2116
2117   # Cycle counter, selected according to ABI.
2118   #
2119                     eval tmp=\"\$SPEED_CYCLECOUNTER_OBJ$abi1\"
2120   test -n "$tmp" || eval tmp=\"\$SPEED_CYCLECOUNTER_OBJ$abi2\"
2121   SPEED_CYCLECOUNTER_OBJ="$tmp"
2122                     eval tmp=\"\$cyclecounter_size$abi1\"
2123   test -n "$tmp" || eval tmp=\"\$cyclecounter_size$abi2\"
2124   cyclecounter_size="$tmp"
2125
2126   if test -n "$SPEED_CYCLECOUNTER_OBJ"; then
2127     AC_DEFINE_UNQUOTED(HAVE_SPEED_CYCLECOUNTER, $cyclecounter_size,
2128     [Tune directory speed_cyclecounter, undef=none, 1=32bits, 2=64bits)])
2129   fi
2130   AC_SUBST(SPEED_CYCLECOUNTER_OBJ)
2131
2132
2133   # Calling conventions checking, selected according to ABI.
2134   #
2135                     eval tmp=\"\$CALLING_CONVENTIONS_OBJS$abi1\"
2136   test -n "$tmp" || eval tmp=\"\$CALLING_CONVENTIONS_OBJS$abi2\"
2137   if test "$enable_assembly" = "yes"; then
2138      CALLING_CONVENTIONS_OBJS="$tmp"
2139   else
2140      CALLING_CONVENTIONS_OBJS=""
2141   fi
2142
2143   if test -n "$CALLING_CONVENTIONS_OBJS"; then
2144     AC_DEFINE(HAVE_CALLING_CONVENTIONS,1,
2145     [Define to 1 if tests/libtests has calling conventions checking for the CPU])
2146   fi
2147   AC_SUBST(CALLING_CONVENTIONS_OBJS)
2148
2149 fi
2150
2151
2152 # If the user gave an MPN_PATH, use that verbatim, otherwise choose
2153 # according to the ABI and add "generic".
2154 #
2155 if test -n "$MPN_PATH"; then
2156   path="$MPN_PATH"
2157 else
2158                     eval tmp=\"\$path$abi1\"
2159   test -n "$tmp" || eval tmp=\"\$path$abi2\"
2160   path="$tmp generic"
2161 fi
2162
2163
2164 # Long long limb setup for gmp.h.
2165 case $limb_chosen in
2166 longlong) DEFN_LONG_LONG_LIMB="#define _LONG_LONG_LIMB 1"    ;;
2167 *)        DEFN_LONG_LONG_LIMB="/* #undef _LONG_LONG_LIMB */" ;;
2168 esac
2169 AC_SUBST(DEFN_LONG_LONG_LIMB)
2170
2171
2172 # The C compiler and preprocessor, put into ANSI mode if possible.
2173 AC_PROG_CC
2174 AC_PROG_CC_STDC
2175 AC_PROG_CPP
2176
2177
2178 # The C compiler on the build system, and associated tests.
2179 GMP_PROG_CC_FOR_BUILD
2180 GMP_PROG_CPP_FOR_BUILD
2181 GMP_PROG_EXEEXT_FOR_BUILD
2182 GMP_C_FOR_BUILD_ANSI
2183 GMP_CHECK_LIBM_FOR_BUILD
2184
2185
2186 # How to assemble, used with CFLAGS etc, see mpn/Makeasm.am.
2187 # Using the compiler is a lot easier than figuring out how to invoke the
2188 # assembler directly.
2189 #
2190 test -n "$CCAS" || CCAS="$CC -c"
2191 AC_SUBST(CCAS)
2192
2193
2194 # The C++ compiler, if desired.
2195 want_cxx=no
2196 if test $enable_cxx != no; then
2197   test_CXXFLAGS=${CXXFLAGS+set}
2198   AC_PROG_CXX
2199
2200   echo "CXXFLAGS chosen by autoconf: $CXXFLAGS" >&AC_FD_CC
2201   cxxflags_ac_prog_cxx=$CXXFLAGS
2202   cxxflags_list=ac_prog_cxx
2203
2204   # If the user didn't specify $CXXFLAGS, then try $CFLAGS, with -g removed
2205   # if AC_PROG_CXX thinks that doesn't work.  $CFLAGS stands a good chance
2206   # of working, eg. on a GNU system where CC=gcc and CXX=g++.
2207   #
2208   if test "$test_CXXFLAGS" != set; then
2209     cxxflags_cflags=$CFLAGS
2210     cxxflags_list="cflags $cxxflags_list"
2211     if test "$ac_prog_cxx_g" = no; then
2212       cxxflags_cflags=`echo "$cxxflags_cflags" | sed -e 's/ -g //' -e 's/^-g //' -e 's/ -g$//'`
2213     fi
2214   fi
2215
2216   # See if the C++ compiler works.  If the user specified CXXFLAGS then all
2217   # we're doing is checking whether AC_PROG_CXX succeeded, since it doesn't
2218   # give a fatal error, just leaves CXX set to a default g++.  If on the
2219   # other hand the user didn't specify CXXFLAGS then we get to try here our
2220   # $cxxflags_list alternatives.
2221   #
2222   # Automake includes $CPPFLAGS in a C++ compile, so we do the same here.
2223   #
2224   for cxxflags_choice in $cxxflags_list; do
2225     eval CXXFLAGS=\"\$cxxflags_$cxxflags_choice\"
2226     GMP_PROG_CXX_WORKS($CXX $CPPFLAGS $CXXFLAGS,
2227       [want_cxx=yes
2228       break])
2229   done
2230
2231   # If --enable-cxx=yes but a C++ compiler can't be found, then abort.
2232   if test $want_cxx = no && test $enable_cxx = yes; then
2233     AC_MSG_ERROR([C++ compiler not available, see config.log for details])
2234   fi
2235 fi
2236
2237 AM_CONDITIONAL(WANT_CXX, test $want_cxx = yes)
2238
2239 # FIXME: We're not interested in CXXCPP for ourselves, but if we don't do it
2240 # here then AC_PROG_LIBTOOL will AC_REQUIRE it (via _LT_AC_TAGCONFIG) and
2241 # hence execute it unconditionally, and that will fail if there's no C++
2242 # compiler (and no generic /lib/cpp).
2243 #
2244 if test $want_cxx = yes; then
2245   AC_PROG_CXXCPP
2246 fi
2247
2248
2249 # Path setups for Cray, according to IEEE or CFP.  These must come after
2250 # deciding the compiler.
2251 #
2252 GMP_CRAY_OPTIONS(
2253   [add_path="cray/ieee"],
2254   [add_path="cray/cfp"; extra_functions="mulwwc90"],
2255   [add_path="cray/cfp"; extra_functions="mulwwj90"])
2256
2257
2258 if test -z "$MPN_PATH"; then
2259   path="$add_path $path"
2260 fi
2261
2262 # For a nail build, also look in "nails" subdirectories.
2263 #
2264 if test $GMP_NAIL_BITS != 0 && test -z "$MPN_PATH"; then
2265   new_path=
2266   for i in $path; do
2267     case $i in
2268     generic) new_path="$new_path $i" ;;
2269     *)       new_path="$new_path $i/nails $i" ;;
2270     esac
2271   done
2272   path=$new_path
2273 fi
2274
2275
2276 # Put all directories into CPUVEC_list so as to get a full set of
2277 # CPUVEC_SETUP_$tmp_suffix defines into config.h, even if some of them are
2278 # empty because mmx and/or sse2 had to be dropped.
2279 #
2280 for i in $fat_path; do
2281   GMP_FAT_SUFFIX(tmp_suffix, $i)
2282   CPUVEC_list="$CPUVEC_list CPUVEC_SETUP_$tmp_suffix"
2283 done
2284
2285
2286 # If there's any sse2 or mmx in the path, check whether the assembler
2287 # supports it, and remove if not.
2288 #
2289 # We only need this in ABI=32, for ABI=64 on x86_64 we can assume a new
2290 # enough assembler.
2291 #
2292 case $host in
2293   X86_PATTERN | X86_64_PATTERN)
2294     if test "$ABI" = 32; then
2295       case "$path $fat_path" in
2296         *mmx*)   GMP_ASM_X86_MMX( , [GMP_STRIP_PATH(*mmx*)]) ;;
2297       esac
2298       case "$path $fat_path" in
2299         *sse2*)  GMP_ASM_X86_SSE2( , [GMP_STRIP_PATH(sse2)]) ;;
2300       esac
2301     fi
2302     ;;
2303 esac
2304
2305
2306 if test "$enable_assembly" = "no"; then
2307   path="generic"
2308   CFLAGS="$CFLAGS -DNO_ASM"
2309 #  for abi in $abilist; do
2310 #    eval unset "path_\$abi"
2311 #    eval gcc_${abi}_cflags=\"\$gcc_${abi}_cflags -DNO_ASM\"
2312 #  done
2313 fi
2314
2315
2316 cat >&AC_FD_CC <<EOF
2317 Decided:
2318 ABI=$ABI
2319 CC=$CC
2320 CFLAGS=$CFLAGS
2321 CPPFLAGS=$CPPFLAGS
2322 GMP_LDFLAGS=$GMP_LDFLAGS
2323 CXX=$CXX
2324 CXXFLAGS=$CXXFLAGS
2325 path=$path
2326 EOF
2327 echo "using ABI=\"$ABI\""
2328 echo "      CC=\"$CC\""
2329 echo "      CFLAGS=\"$CFLAGS\""
2330 echo "      CPPFLAGS=\"$CPPFLAGS\""
2331 if test $want_cxx = yes; then
2332   echo "      CXX=\"$CXX\""
2333   echo "      CXXFLAGS=\"$CXXFLAGS\""
2334 fi
2335 echo "      MPN_PATH=\"$path\""
2336
2337
2338 CL_AS_NOEXECSTACK
2339
2340 GMP_PROG_AR
2341 GMP_PROG_NM
2342
2343 case $host in
2344   # FIXME: On AIX 3 and 4, $libname.a is included in libtool
2345   # $library_names_spec, so libgmp.a becomes a symlink to libgmp.so, making
2346   # it impossible to build shared and static libraries simultaneously.
2347   # Disable shared libraries by default, but let the user override with
2348   # --enable-shared --disable-static.
2349   #
2350   # FIXME: This $libname.a problem looks like it might apply to *-*-amigaos*
2351   # and *-*-os2* too, but wait for someone to test this before worrying
2352   # about it.  If there is a problem then of course libtool is the right
2353   # place to fix it.
2354   #
2355   [*-*-aix[34]*])
2356     if test -z "$enable_shared"; then enable_shared=no; fi ;;
2357 esac
2358
2359
2360 # Configs for Windows DLLs.
2361
2362 AC_LIBTOOL_WIN32_DLL
2363
2364 AC_SUBST(LIBGMP_DLL,0)
2365 case $host in
2366   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2*)
2367     # By default, build only static.
2368     if test -z "$enable_shared"; then
2369       enable_shared=no
2370     fi
2371     # Don't allow both static and DLL.
2372     if test "$enable_shared" != no && test "$enable_static" != no; then
2373       AC_MSG_ERROR([cannot build both static and DLL, since gmp.h is different for each.
2374 Use "--disable-static --enable-shared" to build just a DLL.])
2375     fi
2376
2377     # "-no-undefined" is required when building a DLL, see documentation on
2378     # AC_LIBTOOL_WIN32_DLL.
2379     #
2380     # "-Wl,--export-all-symbols" is a bit of a hack, it gets all libgmp and
2381     # libgmpxx functions and variables exported.  This is what libtool did
2382     # in the past, and it's convenient for us in the test programs.
2383     #
2384     # Maybe it'd be prudent to check for --export-all-symbols before using
2385     # it, but it seems to have been in ld since at least 2000, and there's
2386     # not really any alternative we want to take up at the moment.
2387     #
2388     # "-Wl,output-def" is used to get a .def file for use by MS lib to make
2389     # a .lib import library, described in the manual.  libgmp-3.dll.def
2390     # corresponds to the libmp-3.dll.def generated by libtool (as a result
2391     # of -export-symbols on that library).
2392     #
2393     # Incidentally, libtool does generate an import library libgmp.dll.a,
2394     # but it's "ar" format and cannot be used by the MS linker.  There
2395     # doesn't seem to be any GNU tool for generating or converting to .lib.
2396     #
2397     # FIXME: The .def files produced by -Wl,output-def include isascii,
2398     # iscsym, iscsymf and toascii, apparently because mingw ctype.h doesn't
2399     # inline isascii (used in gmp).  It gives an extern inline for
2400     # __isascii, but for some reason not the plain isascii.
2401     #
2402     if test "$enable_shared" = yes; then
2403       GMP_LDFLAGS="$GMP_LDFLAGS -no-undefined -Wl,--export-all-symbols"
2404       LIBGMP_LDFLAGS="$LIBGMP_LDFLAGS -Wl,--output-def,.libs/libgmp-3.dll.def"
2405       LIBGMPXX_LDFLAGS="$LIBGMP_LDFLAGS -Wl,--output-def,.libs/libgmpxx-3.dll.def"
2406       LIBGMP_DLL=1
2407     fi
2408     ;;
2409 esac
2410
2411
2412 # Ensure that $CONFIG_SHELL is available for AC_LIBTOOL_SYS_MAX_CMD_LEN.
2413 # It's often set already by _LT_AC_PROG_ECHO_BACKSLASH or
2414 # _AS_LINENO_PREPARE, but not always.
2415 #
2416 # The symptom of CONFIG_SHELL unset is some "expr" errors during the test,
2417 # and an empty result.  This only happens when invoked as "sh configure",
2418 # ie. no path, and can be seen for instance on ia64-*-hpux*.
2419 #
2420 # FIXME: Newer libtool should have it's own fix for this.
2421 #
2422 if test -z "$CONFIG_SHELL"; then
2423   CONFIG_SHELL=$SHELL
2424 fi
2425
2426 # Enable CXX in libtool only if we want it, and never enable GCJ, nor RC on
2427 # mingw and cygwin.  Under --disable-cxx this avoids some error messages
2428 # from libtool arising from the fact we didn't actually run AC_PROG_CXX.
2429 # Notice that any user-supplied --with-tags setting takes precedence.
2430 #
2431 # FIXME: Is this the right way to get this effect?  Very possibly not, but
2432 # the current _LT_AC_TAGCONFIG doesn't really suggest an alternative.
2433 #
2434 if test "${with_tags+set}" != set; then
2435   if test $want_cxx = yes; then
2436     with_tags=CXX
2437   else
2438     with_tags=
2439   fi
2440 fi
2441
2442 # The dead hand of AC_REQUIRE makes AC_PROG_LIBTOOL expand and execute
2443 # AC_PROG_F77, even when F77 is not in the selected with_tags.  This is
2444 # probably harmless, but it's unsightly and bloats our configure, so pretend
2445 # AC_PROG_F77 has been expanded already.
2446 #
2447 # FIXME: Rumour has it libtool will one day provide a way for a configure.in
2448 # to say what it wants from among supported languages etc.
2449 #
2450 AC_PROVIDE([AC_PROG_F77])
2451
2452 AC_PROG_LIBTOOL
2453
2454 # Generate an error here if attempting to build both shared and static when
2455 # $libname.a is in $library_names_spec (as mentioned above), rather than
2456 # wait for ar or ld to fail.
2457 #
2458 if test "$enable_shared" = yes && test "$enable_static" = yes; then
2459   case $library_names_spec in
2460     *libname.a*)
2461       AC_MSG_ERROR([cannot create both shared and static libraries on this system, --disable one of the two])
2462       ;;
2463   esac
2464 fi
2465
2466 AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
2467
2468
2469 # Many of these library and header checks are for the benefit of
2470 # supplementary programs.  libgmp doesn't use anything too weird.
2471
2472 AC_HEADER_STDC
2473 AC_HEADER_TIME
2474
2475 # Reasons for testing:
2476 #   float.h - not in SunOS bundled cc
2477 #   invent.h - IRIX specific
2478 #   langinfo.h - X/Open standard only, not in djgpp for instance
2479 #   locale.h - old systems won't have this
2480 #   nl_types.h - X/Open standard only, not in djgpp for instance
2481 #       (usually langinfo.h gives nl_item etc, but not on netbsd 1.4.1)
2482 #   sys/attributes.h - IRIX specific
2483 #   sys/iograph.h - IRIX specific
2484 #   sys/mman.h - not in Cray Unicos
2485 #   sys/param.h - not in mingw
2486 #   sys/processor.h - solaris specific, though also present in macos
2487 #   sys/pstat.h - HPUX specific
2488 #   sys/resource.h - not in mingw
2489 #   sys/sysctl.h - not in mingw
2490 #   sys/sysinfo.h - OSF specific
2491 #   sys/syssgi.h - IRIX specific
2492 #   sys/systemcfg.h - AIX specific
2493 #   sys/time.h - autoconf suggests testing, don't know anywhere without it
2494 #   sys/times.h - not in mingw
2495 #   machine/hal_sysinfo.h - OSF specific
2496 #
2497 # inttypes.h, stdint.h, unistd.h and sys/types.h are already in the autoconf
2498 # default tests
2499 #
2500 AC_CHECK_HEADERS(fcntl.h float.h invent.h langinfo.h locale.h nl_types.h sys/attributes.h sys/iograph.h sys/mman.h sys/param.h sys/processor.h sys/pstat.h sys/sysinfo.h sys/syssgi.h sys/systemcfg.h sys/time.h sys/times.h)
2501
2502 # On SunOS, sys/resource.h needs sys/time.h (for struct timeval)
2503 AC_CHECK_HEADERS(sys/resource.h,,,
2504 [#if TIME_WITH_SYS_TIME
2505 # include <sys/time.h>
2506 # include <time.h>
2507 #else
2508 # if HAVE_SYS_TIME_H
2509 #  include <sys/time.h>
2510 # else
2511 #  include <time.h>
2512 # endif
2513 #endif])
2514
2515 # On NetBSD and OpenBSD, sys/sysctl.h needs sys/param.h for various constants
2516 AC_CHECK_HEADERS(sys/sysctl.h,,,
2517 [#if HAVE_SYS_PARAM_H
2518 # include <sys/param.h>
2519 #endif])
2520
2521 # On OSF 4.0, <machine/hal_sysinfo.h> must have <sys/sysinfo.h> for ulong_t
2522 AC_CHECK_HEADERS(machine/hal_sysinfo.h,,,
2523 [#if HAVE_SYS_SYSINFO_H
2524 # include <sys/sysinfo.h>
2525 #endif])
2526
2527 # Reasons for testing:
2528 #   optarg - not declared in mingw
2529 #   fgetc, fscanf, ungetc, vfprintf - not declared in SunOS 4
2530 #   sys_errlist, sys_nerr - not declared in SunOS 4
2531 #
2532 # optarg should be in unistd.h and the rest in stdio.h, both of which are
2533 # in the autoconf default includes.
2534 #
2535 # sys_errlist and sys_nerr are supposed to be in <errno.h> on SunOS according
2536 # to the man page (but aren't), in glibc they're in stdio.h.
2537 #
2538 AC_CHECK_DECLS([fgetc, fscanf, optarg, ungetc, vfprintf])
2539 AC_CHECK_DECLS([sys_errlist, sys_nerr], , ,
2540 [#include <stdio.h>
2541 #include <errno.h>])
2542
2543 AC_TYPE_SIGNAL
2544
2545 # Reasons for testing:
2546 #   intmax_t       - C99
2547 #   long double    - not in the HP bundled K&R cc
2548 #   long long      - only in reasonably recent compilers
2549 #   ptrdiff_t      - seems to be everywhere, maybe don't need to check this
2550 #   quad_t         - BSD specific
2551 #   uint_least32_t - C99
2552 #
2553 # the default includes are sufficient for all these types
2554 #
2555 AC_CHECK_TYPES([intmax_t, long double, long long, ptrdiff_t, quad_t,
2556                 uint_least32_t, intptr_t])
2557
2558 AC_C_STRINGIZE
2559
2560 # FIXME: Really want #ifndef __cplusplus around the #define volatile
2561 # replacement autoconf gives, since volatile is always available in C++.
2562 # But we don't use it in C++ currently.
2563 AC_C_VOLATILE
2564
2565 AC_C_RESTRICT
2566
2567 GMP_C_STDARG
2568 GMP_C_ATTRIBUTE_CONST
2569 GMP_C_ATTRIBUTE_MALLOC
2570 GMP_C_ATTRIBUTE_MODE
2571 GMP_C_ATTRIBUTE_NORETURN
2572
2573 GMP_H_EXTERN_INLINE
2574
2575 # from libtool
2576 AC_CHECK_LIBM
2577 AC_SUBST(LIBM)
2578
2579 GMP_FUNC_ALLOCA
2580 GMP_OPTION_ALLOCA
2581
2582 GMP_H_HAVE_FILE
2583
2584 AC_C_BIGENDIAN(
2585   [AC_DEFINE(HAVE_LIMB_BIG_ENDIAN, 1)
2586    GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_LIMB_BIG_ENDIAN')", POST)],
2587   [AC_DEFINE(HAVE_LIMB_LITTLE_ENDIAN, 1)
2588    GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_LIMB_LITTLE_ENDIAN')", POST)
2589   ], [:])
2590 AH_VERBATIM([HAVE_LIMB],
2591 [/* Define one of these to 1 for the endianness of `mp_limb_t'.
2592    If the endianness is not a simple big or little, or you don't know what
2593    it is, then leave both undefined. */
2594 #undef HAVE_LIMB_BIG_ENDIAN
2595 #undef HAVE_LIMB_LITTLE_ENDIAN])
2596
2597 GMP_C_DOUBLE_FORMAT
2598
2599
2600 # Reasons for testing:
2601 #   alarm - not in mingw
2602 #   attr_get - IRIX specific
2603 #   clock_gettime - not in glibc 2.2.4, only very recent systems
2604 #   cputime - not in glibc
2605 #   getsysinfo - OSF specific
2606 #   getrusage - not in mingw
2607 #   gettimeofday - not in mingw
2608 #   mmap - not in mingw, djgpp
2609 #   nl_langinfo - X/Open standard only, not in djgpp for instance
2610 #   obstack_vprintf - glibc specific
2611 #   processor_info - solaris specific
2612 #   pstat_getprocessor - HPUX specific (10.x and up)
2613 #   raise - an ANSI-ism, though probably almost universal by now
2614 #   read_real_time - AIX specific
2615 #   sigaction - not in mingw
2616 #   sigaltstack - not in mingw, or old AIX (reputedly)
2617 #   sigstack - not in mingw
2618 #   strerror - not in SunOS
2619 #   strnlen - glibc extension (some other systems too)
2620 #   syssgi - IRIX specific
2621 #   times - not in mingw
2622 #
2623 # AC_FUNC_STRNLEN is not used because we don't want the AC_LIBOBJ
2624 # replacement setups it gives.  It detects a faulty strnlen on AIX, but
2625 # missing out on that test is ok since our only use of strnlen is in
2626 # __gmp_replacement_vsnprintf which is not required on AIX since it has a
2627 # vsnprintf.
2628 #
2629 AC_CHECK_FUNCS(alarm attr_get clock cputime getpagesize getrusage gettimeofday getsysinfo localeconv memset mmap mprotect nl_langinfo obstack_vprintf popen processor_info pstat_getprocessor raise read_real_time sigaction sigaltstack sigstack syssgi strchr strerror strnlen strtol strtoul sysconf sysctl sysctlbyname times)
2630
2631 # clock_gettime is in librt on *-*-osf5.1 and on glibc, so att -lrt to
2632 # TUNE_LIBS if needed. On linux (tested on x86_32, 2.6.26),
2633 # clock_getres reports ns accuracy, while in a quick test on osf
2634 # clock_getres said only 1 millisecond.
2635
2636 old_LIBS="$LIBS"
2637 AC_SEARCH_LIBS(clock_gettime, rt, [
2638   AC_DEFINE([HAVE_CLOCK_GETTIME],1,[Define to 1 if you have the `clock_gettime' function])])
2639 TUNE_LIBS="$LIBS"
2640 LIBS="$old_LIBS"
2641
2642 AC_SUBST(TUNE_LIBS)
2643
2644 GMP_FUNC_VSNPRINTF
2645 GMP_FUNC_SSCANF_WRITABLE_INPUT
2646
2647 # Reasons for checking:
2648 #   pst_processor psp_iticksperclktick - not in hpux 9
2649 #
2650 AC_CHECK_MEMBER(struct pst_processor.psp_iticksperclktick,
2651                 [AC_DEFINE(HAVE_PSP_ITICKSPERCLKTICK, 1,
2652 [Define to 1 if <sys/pstat.h> `struct pst_processor' exists
2653 and contains `psp_iticksperclktick'.])],,
2654                 [#include <sys/pstat.h>])
2655
2656 # C++ tests, when required
2657 #
2658 if test $enable_cxx = yes; then
2659   AC_LANG_PUSH(C++)
2660
2661   # Reasons for testing:
2662   #   <sstream> - not in g++ 2.95.2
2663   #   std::locale - not in g++ 2.95.4
2664   #
2665   AC_CHECK_HEADERS([sstream])
2666   AC_CHECK_TYPES([std::locale],,,[#include <locale>])
2667
2668   AC_LANG_POP(C++)
2669 fi
2670
2671
2672 # Pick the correct source files in $path and link them to mpn/.
2673 # $gmp_mpn_functions lists all functions we need.
2674 #
2675 # The rule is to find a file with the function name and a .asm, .S,
2676 # .s, or .c extension.  Certain multi-function files with special names
2677 # can provide some functions too.  (mpn/Makefile.am passes
2678 # -DOPERATION_<func> to get them to generate the right code.)
2679
2680 # Note: $gmp_mpn_functions must have mod_1 before pre_mod_1 so the former
2681 #       can optionally provide the latter as an extra entrypoint.  Likewise
2682 #       divrem_1 and pre_divrem_1.
2683
2684 gmp_mpn_functions_optional="umul udiv                                   \
2685   invert_limb sqr_diagonal sqr_diag_addlsh1                             \
2686   mul_2 mul_3 mul_4 mul_5 mul_6                                         \
2687   addmul_2 addmul_3 addmul_4 addmul_5 addmul_6 addmul_7 addmul_8        \
2688   addlsh1_n sublsh1_n rsblsh1_n rsh1add_n rsh1sub_n                     \
2689   addlsh2_n sublsh2_n rsblsh2_n                                         \
2690   addlsh_n sublsh_n rsblsh_n                                            \
2691   add_n_sub_n addaddmul_1msb0"
2692
2693 gmp_mpn_functions="$extra_functions                                        \
2694   add add_1 add_n sub sub_1 sub_n addcnd_n subcnd_n neg com                \
2695   mul_1 addmul_1 submul_1                                                  \
2696   add_err1_n add_err2_n add_err3_n sub_err1_n sub_err2_n sub_err3_n        \
2697   lshift rshift dive_1 diveby3 divis divrem divrem_1 divrem_2              \
2698   fib2_ui mod_1 mod_34lsub1 mode1o pre_divrem_1 pre_mod_1 dump             \
2699   mod_1_1 mod_1_2 mod_1_3 mod_1_4 lshiftc                                  \
2700   mul mul_fft mul_n sqr mul_basecase sqr_basecase nussbaumer_mul           \
2701   mulmid_basecase toom42_mulmid mulmid_n mulmid                            \
2702   random random2 pow_1                                                     \
2703   rootrem sqrtrem get_str set_str scan0 scan1 popcount hamdist cmp         \
2704   perfsqr perfpow                                                          \
2705   gcd_1 gcd gcdext_1 gcdext gcd_subdiv_step                                \
2706   gcdext_lehmer                                                            \
2707   div_q tdiv_qr jacbase jacobi_2 jacobi get_d                              \
2708   matrix22_mul matrix22_mul1_inverse_vector                                \
2709   hgcd_matrix hgcd2 hgcd_step hgcd_reduce hgcd hgcd_appr                   \
2710   hgcd2_jacobi hgcd_jacobi                                                 \
2711   mullo_n mullo_basecase                                                   \
2712   toom22_mul toom32_mul toom42_mul toom52_mul toom62_mul                   \
2713   toom33_mul toom43_mul toom53_mul toom54_mul toom63_mul                   \
2714   toom44_mul                                                               \
2715   toom6h_mul toom6_sqr toom8h_mul toom8_sqr                                \
2716   toom_couple_handling                                                     \
2717   toom2_sqr toom3_sqr toom4_sqr                                            \
2718   toom_eval_dgr3_pm1 toom_eval_dgr3_pm2                                    \
2719   toom_eval_pm1 toom_eval_pm2 toom_eval_pm2exp toom_eval_pm2rexp           \
2720   toom_interpolate_5pts toom_interpolate_6pts toom_interpolate_7pts        \
2721   toom_interpolate_8pts toom_interpolate_12pts toom_interpolate_16pts      \
2722   invertappr invert binvert mulmod_bnm1 sqrmod_bnm1                        \
2723   div_qr_2 div_qr_2n_pi1 div_qr_2u_pi1                                     \
2724   sbpi1_div_q sbpi1_div_qr sbpi1_divappr_q                                 \
2725   dcpi1_div_q dcpi1_div_qr dcpi1_divappr_q                                 \
2726   mu_div_qr mu_divappr_q mu_div_q                                          \
2727   bdiv_q_1                                                                 \
2728   sbpi1_bdiv_q sbpi1_bdiv_qr                                               \
2729   dcpi1_bdiv_q dcpi1_bdiv_qr                                               \
2730   mu_bdiv_q mu_bdiv_qr                                                     \
2731   bdiv_q bdiv_qr broot brootinv bsqrt bsqrtinv                             \
2732   divexact bdiv_dbm1c redc_1 redc_2 redc_n powm powlo powm_sec             \
2733   sb_div_qr_sec sb_div_r_sec sbpi1_div_qr_sec sbpi1_div_r_sec              \
2734   trialdiv remove                                                          \
2735   and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n                     \
2736   copyi copyd zero tabselect                                               \
2737   comb_tables                                                              \
2738   $gmp_mpn_functions_optional"
2739
2740 define(GMP_MULFUNC_CHOICES,
2741 [# functions that can be provided by multi-function files
2742 tmp_mulfunc=
2743 case $tmp_fn in
2744   add_n|sub_n)       tmp_mulfunc="aors_n"    ;;
2745   add_err1_n|sub_err1_n)
2746                      tmp_mulfunc="aors_err1_n" ;;
2747   add_err2_n|sub_err2_n)
2748                      tmp_mulfunc="aors_err2_n" ;;
2749   add_err3_n|sub_err3_n)
2750                      tmp_mulfunc="aors_err3_n" ;;
2751   addcnd_n|subcnd_n) tmp_mulfunc="aorscnd_n"   ;;
2752   addmul_1|submul_1) tmp_mulfunc="aorsmul_1" ;;
2753   popcount|hamdist)  tmp_mulfunc="popham"    ;;
2754   and_n|andn_n|nand_n | ior_n|iorn_n|nior_n | xor_n|xnor_n)
2755                      tmp_mulfunc="logops_n"  ;;
2756   lshift|rshift)     tmp_mulfunc="lorrshift";;
2757   addlsh1_n)
2758                      tmp_mulfunc="aorslsh1_n aorrlsh1_n";;
2759   sublsh1_n)
2760                      tmp_mulfunc="aorslsh1_n sorrlsh1_n";;
2761   rsblsh1_n)
2762                      tmp_mulfunc="aorrlsh1_n sorrlsh1_n";;
2763   addlsh2_n)
2764                      tmp_mulfunc="aorslsh2_n aorrlsh2_n";;
2765   sublsh2_n)
2766                      tmp_mulfunc="aorslsh2_n sorrlsh2_n";;
2767   rsblsh2_n)
2768                      tmp_mulfunc="aorrlsh2_n sorrlsh2_n";;
2769   addlsh_n)
2770                      tmp_mulfunc="aorslsh_n aorrlsh_n";;
2771   sublsh_n)
2772                      tmp_mulfunc="aorslsh_n sorrlsh_n";;
2773   rsblsh_n)
2774                      tmp_mulfunc="aorrlsh_n sorrlsh_n";;
2775   rsh1add_n|rsh1sub_n)
2776                      tmp_mulfunc="rsh1aors_n";;
2777   sb_div_qr_sec|sb_div_r_sec)
2778                      tmp_mulfunc="sb_div_sec";;
2779   sbpi1_div_qr_sec|sbpi1_div_r_sec)
2780                      tmp_mulfunc="sbpi1_div_sec";;
2781 esac
2782 ])
2783
2784 # the list of all object files used by mpn/Makefile.in and the
2785 # top-level Makefile.in, respectively
2786 mpn_objects=
2787 mpn_objs_in_libgmp=
2788
2789 # links from the sources, to be removed by "make distclean"
2790 gmp_srclinks=
2791
2792
2793 # mpn_relative_top_srcdir is $top_srcdir, but for use from within the mpn
2794 # build directory.  If $srcdir is relative then we use a relative path too,
2795 # so the two trees can be moved together.
2796 case $srcdir in
2797   [[\\/]* | ?:[\\/]*])  # absolute, as per autoconf
2798     mpn_relative_top_srcdir=$srcdir ;;
2799   *)                    # relative
2800     mpn_relative_top_srcdir=../$srcdir ;;
2801 esac
2802
2803
2804 define(MPN_SUFFIXES,[asm S s c])
2805
2806 dnl  Usage: GMP_FILE_TO_FUNCTION_BASE(func,file)
2807 dnl
2808 dnl  Set $func to the function base name for $file, eg. dive_1 gives
2809 dnl  divexact_1.
2810 dnl
2811 define(GMP_FILE_TO_FUNCTION,
2812 [case $$2 in
2813   dive_1)       $1=divexact_1 ;;
2814   diveby3)      $1=divexact_by3c ;;
2815   pre_divrem_1) $1=preinv_divrem_1 ;;
2816   mode1o)       $1=modexact_1c_odd ;;
2817   pre_mod_1)    $1=preinv_mod_1 ;;
2818   mod_1_1)      $1=mod_1_1p ;;
2819   mod_1_1_cps)  $1=mod_1_1p_cps ;;
2820   mod_1_2)      $1=mod_1s_2p ;;
2821   mod_1_2_cps)  $1=mod_1s_2p_cps ;;
2822   mod_1_3)      $1=mod_1s_3p ;;
2823   mod_1_3_cps)  $1=mod_1s_3p_cps ;;
2824   mod_1_4)      $1=mod_1s_4p ;;
2825   mod_1_4_cps)  $1=mod_1s_4p_cps ;;
2826   *)            $1=$$2 ;;
2827 esac
2828 ])
2829
2830 # Fat binary setups.
2831 #
2832 # We proceed through each $fat_path directory, and look for $fat_function
2833 # routines there.  Those found are incorporated in the build by generating a
2834 # little mpn/<foo>.asm or mpn/<foo>.c file in the build directory, with
2835 # suitable function renaming, and adding that to $mpn_objects (the same as a
2836 # normal mpn file).
2837 #
2838 # fat.h is generated with macros to let internal calls to each $fat_function
2839 # go directly through __gmpn_cpuvec, plus macros and declarations helping to
2840 # setup that structure, on a per-directory basis ready for
2841 # mpn/<cpu>/fat/fat.c.
2842 #
2843 # fat.h includes thresholds listed in $fat_thresholds, extracted from
2844 # gmp-mparam.h in each directory.  An overall maximum for each threshold is
2845 # established, for use in making fixed size arrays of temporary space.
2846 # (Eg. MUL_TOOM33_THRESHOLD_LIMIT used by mpn/generic/mul.c.)
2847 #
2848 # It'd be possible to do some of this manually, but when there's more than a
2849 # few functions and a few directories it becomes very tedious, and very
2850 # prone to having some routine accidentally omitted.  On that basis it seems
2851 # best to automate as much as possible, even if the code to do so is a bit
2852 # ugly.
2853 #
2854
2855 if test -n "$fat_path"; then
2856   # Usually the mpn build directory is created with mpn/Makefile
2857   # instantiation, but we want to write to it sooner.
2858   mkdir mpn 2>/dev/null
2859
2860   echo "/* fat.h - setups for fat binaries." >fat.h
2861   echo "   Generated by configure - DO NOT EDIT.  */" >>fat.h
2862
2863   AC_DEFINE(WANT_FAT_BINARY, 1, [Define to 1 when building a fat binary.])
2864   GMP_DEFINE(WANT_FAT_BINARY, yes)
2865
2866   # Don't want normal copies of fat functions
2867   for tmp_fn in $fat_functions; do
2868     GMP_REMOVE_FROM_LIST(gmp_mpn_functions, $tmp_fn)
2869     GMP_REMOVE_FROM_LIST(gmp_mpn_functions_optional, $tmp_fn)
2870   done
2871
2872   for tmp_fn in $fat_functions; do
2873     GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2874     echo "
2875 #ifndef OPERATION_$tmp_fn
2876 #undef  mpn_$tmp_fbase
2877 #define mpn_$tmp_fbase  (*__gmpn_cpuvec.$tmp_fbase)
2878 #endif
2879 DECL_$tmp_fbase (__MPN(${tmp_fbase}_init));" >>fat.h
2880     # encourage various macros to use fat functions
2881     AC_DEFINE_UNQUOTED(HAVE_NATIVE_mpn_$tmp_fbase)
2882   done
2883
2884   echo "" >>fat.h
2885   echo "/* variable thresholds */" >>fat.h
2886   for tmp_tn in $fat_thresholds; do
2887     echo "#undef  $tmp_tn" >>fat.h
2888     echo "#define $tmp_tn  CPUVEC_THRESHOLD (`echo $tmp_tn | tr [A-Z] [a-z]`)" >>fat.h
2889   done
2890
2891   echo "
2892 /* Copy all fields into __gmpn_cpuvec.
2893    memcpy is not used because it might operate byte-wise (depending on its
2894    implementation), and we need the function pointer writes to be atomic.
2895    "volatile" discourages the compiler from trying to optimize this.  */
2896 #define CPUVEC_INSTALL(vec) \\
2897   do { \\
2898     volatile struct cpuvec_t *p = &__gmpn_cpuvec; \\" >>fat.h
2899   for tmp_fn in $fat_functions; do
2900     GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2901     echo "    p->$tmp_fbase = vec.$tmp_fbase; \\" >>fat.h
2902   done
2903   for tmp_tn in $fat_thresholds; do
2904     tmp_field_name=`echo $tmp_tn | tr [[A-Z]] [[a-z]]`
2905     echo "    p->$tmp_field_name = vec.$tmp_field_name; \\" >>fat.h
2906   done
2907   echo "  } while (0)" >>fat.h
2908
2909   echo "
2910 /* A helper to check all fields are filled. */
2911 #define ASSERT_CPUVEC(vec) \\
2912   do { \\" >>fat.h
2913   for tmp_fn in $fat_functions; do
2914     GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2915     echo "    ASSERT (vec.$tmp_fbase != NULL); \\" >>fat.h
2916   done
2917   for tmp_tn in $fat_thresholds; do
2918     tmp_field_name=`echo $tmp_tn | tr [[A-Z]] [[a-z]]`
2919     echo "    ASSERT (vec.$tmp_field_name != 0); \\" >>fat.h
2920   done
2921   echo "  } while (0)" >>fat.h
2922
2923   echo "
2924 /* Call ITERATE(field) for each fat threshold field. */
2925 #define ITERATE_FAT_THRESHOLDS() \\
2926   do { \\" >>fat.h
2927   for tmp_tn in $fat_thresholds; do
2928     tmp_field_name=`echo $tmp_tn | tr [[A-Z]] [[a-z]]`
2929     echo "    ITERATE ($tmp_tn, $tmp_field_name); \\" >>fat.h
2930   done
2931   echo "  } while (0)" >>fat.h
2932
2933   for tmp_dir in $fat_path; do
2934     CPUVEC_SETUP=
2935     THRESH_ASM_SETUP=
2936     echo "" >>fat.h
2937     GMP_FAT_SUFFIX(tmp_suffix, $tmp_dir)
2938
2939     # In order to keep names unique on a DOS 8.3 filesystem, use a prefix
2940     # (rather than a suffix) for the generated file names, and abbreviate.
2941     case $tmp_suffix in
2942       pentium)       tmp_prefix=p   ;;
2943       pentium_mmx)   tmp_prefix=pm  ;;
2944       p6_mmx)        tmp_prefix=p2  ;;
2945       p6_p3mmx)      tmp_prefix=p3  ;;
2946       pentium4)      tmp_prefix=p4  ;;
2947       pentium4_mmx)  tmp_prefix=p4m ;;
2948       pentium4_sse2) tmp_prefix=p4s ;;
2949       k6_mmx)        tmp_prefix=k6m ;;
2950       k6_k62mmx)     tmp_prefix=k62 ;;
2951       k7_mmx)        tmp_prefix=k7m ;;
2952       *)             tmp_prefix=$tmp_suffix ;;
2953     esac
2954
2955     # Extract desired thresholds from gmp-mparam.h file in this directory,
2956     # if present.
2957     tmp_mparam=$srcdir/mpn/$tmp_dir/gmp-mparam.h
2958     if test -f $tmp_mparam; then
2959       for tmp_tn in $fat_thresholds; do
2960         tmp_thresh=`sed -n "s/^#define $tmp_tn[         ]*\\([0-9][0-9]*\\).*$/\\1/p" $tmp_mparam`
2961         if test -n "$tmp_thresh"; then
2962           THRESH_ASM_SETUP=["${THRESH_ASM_SETUP}define($tmp_tn,$tmp_thresh)
2963 "]
2964           CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.`echo $tmp_tn | tr [[A-Z]] [[a-z]]` = $tmp_thresh; \\
2965 "
2966           eval tmp_limit=\$${tmp_tn}_LIMIT
2967           if test -z "$tmp_limit"; then
2968             tmp_limit=0
2969           fi
2970           if test $tmp_thresh -gt $tmp_limit; then
2971             eval ${tmp_tn}_LIMIT=$tmp_thresh
2972           fi
2973         fi
2974       done
2975     fi
2976
2977     for tmp_fn in $fat_functions; do
2978       GMP_MULFUNC_CHOICES
2979
2980       for tmp_base in $tmp_fn $tmp_mulfunc; do
2981         for tmp_ext in MPN_SUFFIXES; do
2982           tmp_file=$srcdir/mpn/$tmp_dir/$tmp_base.$tmp_ext
2983           if test -f $tmp_file; then
2984
2985             # If the host uses a non-standard ABI, check if tmp_file supports it
2986             #
2987             if test -n "$GMP_NONSTD_ABI" && test $tmp_ext != "c"; then
2988               abi=[`sed -n 's/^[        ]*ABI_SUPPORT(\(.*\))/\1/p' $tmp_file `]
2989               if echo "$abi" | grep -q "\\b${GMP_NONSTD_ABI}\\b"; then
2990                 true
2991               else
2992                 continue
2993               fi
2994             fi
2995
2996             mpn_objects="$mpn_objects ${tmp_prefix}_$tmp_fn.lo"
2997             mpn_objs_in_libgmp="$mpn_objs_in_libgmp mpn/${tmp_prefix}_$tmp_fn.lo"
2998
2999             GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
3000
3001             # carry-in variant, eg. divrem_1c or modexact_1c_odd
3002             case $tmp_fbase in
3003               *_1*) tmp_fbasec=`echo $tmp_fbase | sed 's/_1/_1c/'` ;;
3004               *)    tmp_fbasec=${tmp_fbase}c ;;
3005             esac
3006
3007             # Create a little file doing an include from srcdir.  The
3008             # OPERATION and renamings aren't all needed all the time, but
3009             # they don't hurt if unused.
3010             #
3011             # FIXME: Should generate these via config.status commands.
3012             # Would need them all in one AC_CONFIG_COMMANDS though, since
3013             # that macro doesn't accept a set of separate commands generated
3014             # by shell code.
3015             #
3016             case $tmp_ext in
3017               asm)
3018                 # hide the d-n-l from autoconf's error checking
3019                 tmp_d_n_l=d""nl
3020                 echo ["$tmp_d_n_l  mpn_$tmp_fbase - from $tmp_dir directory for fat binary.
3021 $tmp_d_n_l  Generated by configure - DO NOT EDIT.
3022
3023 define(OPERATION_$tmp_fn)
3024 define(__gmpn_$tmp_fbase, __gmpn_${tmp_fbase}_$tmp_suffix)
3025 define(__gmpn_$tmp_fbasec,__gmpn_${tmp_fbasec}_${tmp_suffix})
3026 define(__gmpn_preinv_${tmp_fbase},__gmpn_preinv_${tmp_fbase}_${tmp_suffix})
3027 define(__gmpn_${tmp_fbase}_cps,__gmpn_${tmp_fbase}_cps_${tmp_suffix})
3028
3029 $tmp_d_n_l  For k6 and k7 gcd_1 calling their corresponding mpn_modexact_1_odd
3030 ifdef(\`__gmpn_modexact_1_odd',,
3031 \`define(__gmpn_modexact_1_odd,__gmpn_modexact_1_odd_${tmp_suffix})')
3032
3033 $THRESH_ASM_SETUP
3034 include][($mpn_relative_top_srcdir/mpn/$tmp_dir/$tmp_base.asm)
3035 "] >mpn/${tmp_prefix}_$tmp_fn.asm
3036                 ;;
3037               c)
3038                 echo ["/* mpn_$tmp_fbase - from $tmp_dir directory for fat binary.
3039    Generated by configure - DO NOT EDIT. */
3040
3041 #define OPERATION_$tmp_fn 1
3042 #define __gmpn_$tmp_fbase           __gmpn_${tmp_fbase}_$tmp_suffix
3043 #define __gmpn_$tmp_fbasec          __gmpn_${tmp_fbasec}_${tmp_suffix}
3044 #define __gmpn_preinv_${tmp_fbase}  __gmpn_preinv_${tmp_fbase}_${tmp_suffix}
3045 #define __gmpn_${tmp_fbase}_cps     __gmpn_${tmp_fbase}_cps_${tmp_suffix}
3046
3047 #include \"$mpn_relative_top_srcdir/mpn/$tmp_dir/$tmp_base.c\"
3048 "] >mpn/${tmp_prefix}_$tmp_fn.c
3049                 ;;
3050             esac
3051
3052             # Prototype, and append to CPUVEC_SETUP for this directory.
3053             echo "DECL_$tmp_fbase (__gmpn_${tmp_fbase}_$tmp_suffix);" >>fat.h
3054             CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.$tmp_fbase = __gmpn_${tmp_fbase}_${tmp_suffix}; \\
3055 "
3056             # Ditto for any preinv variant (preinv_divrem_1, preinv_mod_1).
3057             if grep "^PROLOGUE(mpn_preinv_$tmp_fn)" $tmp_file >/dev/null; then
3058               echo "DECL_preinv_$tmp_fbase (__gmpn_preinv_${tmp_fbase}_$tmp_suffix);" >>fat.h
3059               CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.preinv_$tmp_fbase = __gmpn_preinv_${tmp_fbase}_${tmp_suffix}; \\
3060 "
3061             fi
3062
3063             # Ditto for any mod_1...cps variant
3064             if grep "^PROLOGUE(mpn_${tmp_fbase}_cps)" $tmp_file >/dev/null; then
3065               echo "DECL_${tmp_fbase}_cps (__gmpn_${tmp_fbase}_cps_$tmp_suffix);" >>fat.h
3066               CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.${tmp_fbase}_cps = __gmpn_${tmp_fbase}_cps_${tmp_suffix}; \\
3067 "
3068             fi
3069           fi
3070         done
3071       done
3072     done
3073
3074     # Emit CPUVEC_SETUP for this directory
3075     echo "" >>fat.h
3076     echo "#define CPUVEC_SETUP_$tmp_suffix \\" >>fat.h
3077     echo "  do { \\" >>fat.h
3078     echo "$CPUVEC_SETUP  } while (0)" >>fat.h
3079   done
3080
3081   # Emit threshold limits
3082   echo "" >>fat.h
3083   for tmp_tn in $fat_thresholds; do
3084     eval tmp_limit=\$${tmp_tn}_LIMIT
3085     echo "#define ${tmp_tn}_LIMIT  $tmp_limit" >>fat.h
3086   done
3087 fi
3088
3089
3090 # Normal binary setups.
3091 #
3092
3093 for tmp_ext in MPN_SUFFIXES; do
3094   eval found_$tmp_ext=no
3095 done
3096
3097 for tmp_fn in $gmp_mpn_functions; do
3098   for tmp_ext in MPN_SUFFIXES; do
3099     test "$no_create" = yes || rm -f mpn/$tmp_fn.$tmp_ext
3100   done
3101
3102   # mpn_preinv_divrem_1 might have been provided by divrem_1.asm, likewise
3103   # mpn_preinv_mod_1 by mod_1.asm.
3104   case $tmp_fn in
3105   pre_divrem_1)
3106     if test "$HAVE_NATIVE_mpn_preinv_divrem_1" = yes; then continue; fi ;;
3107   pre_mod_1)
3108     if test "$HAVE_NATIVE_mpn_preinv_mod_1" = yes; then continue; fi ;;
3109   esac
3110
3111   GMP_MULFUNC_CHOICES
3112
3113   found=no
3114   for tmp_dir in $path; do
3115     for tmp_base in $tmp_fn $tmp_mulfunc; do
3116       for tmp_ext in MPN_SUFFIXES; do
3117         tmp_file=$srcdir/mpn/$tmp_dir/$tmp_base.$tmp_ext
3118         if test -f $tmp_file; then
3119
3120           # For a nails build, check if the file supports our nail bits.
3121           # Generic code always supports all nails.
3122           #
3123           # FIXME: When a multi-function file is selected to provide one of
3124           # the nails-neutral routines, like logops_n for and_n, the
3125           # PROLOGUE grepping will create HAVE_NATIVE_mpn_<foo> defines for
3126           # all functions in that file, even if they haven't all been
3127           # nailified.  Not sure what to do about this, it's only really a
3128           # problem for logops_n, and it's not too terrible to insist those
3129           # get nailified always.
3130           #
3131           if test $GMP_NAIL_BITS != 0 && test $tmp_dir != generic; then
3132             case $tmp_fn in
3133               and_n | ior_n | xor_n | andn_n | \
3134               copyi | copyd | \
3135               popcount | hamdist | \
3136               udiv | udiv_w_sdiv | umul | \
3137               cntlz | invert_limb)
3138                 # these operations are either unaffected by nails or defined
3139                 # to operate on full limbs
3140                 ;;
3141               *)
3142                 nails=[`sed -n 's/^[    ]*NAILS_SUPPORT(\(.*\))/\1/p' $tmp_file `]
3143                 for n in $nails; do
3144                   case $n in
3145                   *-*)
3146                     n_start=`echo "$n" | sed -n 's/\(.*\)-.*/\1/p'`
3147                     n_end=`echo "$n" | sed -n 's/.*-\(.*\)/\1/p'`
3148                     ;;
3149                   *)
3150                     n_start=$n
3151                     n_end=$n
3152                     ;;
3153                   esac
3154                   if test $GMP_NAIL_BITS -ge $n_start && test $GMP_NAIL_BITS -le $n_end; then
3155                     found=yes
3156                     break
3157                   fi
3158                 done
3159                 if test $found != yes; then
3160                   continue
3161                 fi
3162                 ;;
3163             esac
3164           fi
3165
3166           # If the host uses a non-standard ABI, check if tmp_file supports it
3167           #
3168           if test -n "$GMP_NONSTD_ABI" && test $tmp_ext != "c"; then
3169             abi=[`sed -n 's/^[  ]*ABI_SUPPORT(\(.*\))/\1/p' $tmp_file `]
3170             if echo "$abi" | grep -q "\\b${GMP_NONSTD_ABI}\\b"; then
3171               true
3172             else
3173               continue
3174             fi
3175           fi
3176
3177           found=yes
3178           eval found_$tmp_ext=yes
3179
3180           if test $tmp_ext = c; then
3181             tmp_u='$U'
3182           else
3183             tmp_u=
3184           fi
3185
3186           mpn_objects="$mpn_objects $tmp_fn$tmp_u.lo"
3187           mpn_objs_in_libgmp="$mpn_objs_in_libgmp mpn/$tmp_fn$tmp_u.lo"
3188           AC_CONFIG_LINKS(mpn/$tmp_fn.$tmp_ext:mpn/$tmp_dir/$tmp_base.$tmp_ext)
3189           gmp_srclinks="$gmp_srclinks mpn/$tmp_fn.$tmp_ext"
3190
3191           # Duplicate AC_DEFINEs are harmless, so it doesn't matter
3192           # that multi-function files get grepped here repeatedly.
3193           # The PROLOGUE pattern excludes the optional second parameter.
3194           gmp_ep=[`
3195             sed -n 's/^[        ]*MULFUNC_PROLOGUE(\(.*\))/\1/p' $tmp_file ;
3196             sed -n 's/^[        ]*PROLOGUE(\([^,]*\).*)/\1/p' $tmp_file
3197           `]
3198           for gmp_tmp in $gmp_ep; do
3199             AC_DEFINE_UNQUOTED(HAVE_NATIVE_$gmp_tmp)
3200             eval HAVE_NATIVE_$gmp_tmp=yes
3201           done
3202
3203           case $tmp_fn in
3204           sqr_basecase) sqr_basecase_source=$tmp_file ;;
3205           esac
3206
3207           break
3208         fi
3209       done
3210       if test $found = yes; then break ; fi
3211     done
3212     if test $found = yes; then break ; fi
3213   done
3214
3215   if test $found = no; then
3216     for tmp_optional in $gmp_mpn_functions_optional; do
3217       if test $tmp_optional = $tmp_fn; then
3218         found=yes
3219       fi
3220     done
3221     if test $found = no; then
3222       AC_MSG_ERROR([no version of $tmp_fn found in path: $path])
3223     fi
3224   fi
3225 done
3226
3227 # All cycle counters are .asm files currently
3228 if test -n "$SPEED_CYCLECOUNTER_OBJ"; then
3229   found_asm=yes
3230 fi
3231
3232 dnl  The following list only needs to have templates for those defines which
3233 dnl  are going to be tested by the code, there's no need to have every
3234 dnl  possible mpn routine.
3235
3236 AH_VERBATIM([HAVE_NATIVE],
3237 [/* Define to 1 each of the following for which a native (ie. CPU specific)
3238     implementation of the corresponding routine exists.  */
3239 #undef HAVE_NATIVE_mpn_add_n
3240 #undef HAVE_NATIVE_mpn_add_n_sub_n
3241 #undef HAVE_NATIVE_mpn_add_nc
3242 #undef HAVE_NATIVE_mpn_addaddmul_1msb0
3243 #undef HAVE_NATIVE_mpn_addcnd_n
3244 #undef HAVE_NATIVE_mpn_addlsh1_n
3245 #undef HAVE_NATIVE_mpn_addlsh2_n
3246 #undef HAVE_NATIVE_mpn_addlsh_n
3247 #undef HAVE_NATIVE_mpn_addlsh1_nc
3248 #undef HAVE_NATIVE_mpn_addlsh2_nc
3249 #undef HAVE_NATIVE_mpn_addlsh_nc
3250 #undef HAVE_NATIVE_mpn_addlsh1_n_ip1
3251 #undef HAVE_NATIVE_mpn_addlsh2_n_ip1
3252 #undef HAVE_NATIVE_mpn_addlsh_n_ip1
3253 #undef HAVE_NATIVE_mpn_addlsh1_nc_ip1
3254 #undef HAVE_NATIVE_mpn_addlsh2_nc_ip1
3255 #undef HAVE_NATIVE_mpn_addlsh_nc_ip1
3256 #undef HAVE_NATIVE_mpn_addlsh1_n_ip2
3257 #undef HAVE_NATIVE_mpn_addlsh2_n_ip2
3258 #undef HAVE_NATIVE_mpn_addlsh_n_ip2
3259 #undef HAVE_NATIVE_mpn_addlsh1_nc_ip2
3260 #undef HAVE_NATIVE_mpn_addlsh2_nc_ip2
3261 #undef HAVE_NATIVE_mpn_addlsh_nc_ip2
3262 #undef HAVE_NATIVE_mpn_addmul_1c
3263 #undef HAVE_NATIVE_mpn_addmul_2
3264 #undef HAVE_NATIVE_mpn_addmul_3
3265 #undef HAVE_NATIVE_mpn_addmul_4
3266 #undef HAVE_NATIVE_mpn_addmul_5
3267 #undef HAVE_NATIVE_mpn_addmul_6
3268 #undef HAVE_NATIVE_mpn_addmul_7
3269 #undef HAVE_NATIVE_mpn_addmul_8
3270 #undef HAVE_NATIVE_mpn_addmul_2s
3271 #undef HAVE_NATIVE_mpn_and_n
3272 #undef HAVE_NATIVE_mpn_andn_n
3273 #undef HAVE_NATIVE_mpn_bdiv_dbm1c
3274 #undef HAVE_NATIVE_mpn_bdiv_q_1
3275 #undef HAVE_NATIVE_mpn_pi1_bdiv_q_1
3276 #undef HAVE_NATIVE_mpn_com
3277 #undef HAVE_NATIVE_mpn_copyd
3278 #undef HAVE_NATIVE_mpn_copyi
3279 #undef HAVE_NATIVE_mpn_div_qr_2
3280 #undef HAVE_NATIVE_mpn_divexact_1
3281 #undef HAVE_NATIVE_mpn_divexact_by3c
3282 #undef HAVE_NATIVE_mpn_divrem_1
3283 #undef HAVE_NATIVE_mpn_divrem_1c
3284 #undef HAVE_NATIVE_mpn_divrem_2
3285 #undef HAVE_NATIVE_mpn_gcd_1
3286 #undef HAVE_NATIVE_mpn_hamdist
3287 #undef HAVE_NATIVE_mpn_invert_limb
3288 #undef HAVE_NATIVE_mpn_ior_n
3289 #undef HAVE_NATIVE_mpn_iorn_n
3290 #undef HAVE_NATIVE_mpn_lshift
3291 #undef HAVE_NATIVE_mpn_lshiftc
3292 #undef HAVE_NATIVE_mpn_lshsub_n
3293 #undef HAVE_NATIVE_mpn_mod_1
3294 #undef HAVE_NATIVE_mpn_mod_1_1p
3295 #undef HAVE_NATIVE_mpn_mod_1c
3296 #undef HAVE_NATIVE_mpn_mod_1s_2p
3297 #undef HAVE_NATIVE_mpn_mod_1s_4p
3298 #undef HAVE_NATIVE_mpn_mod_34lsub1
3299 #undef HAVE_NATIVE_mpn_modexact_1_odd
3300 #undef HAVE_NATIVE_mpn_modexact_1c_odd
3301 #undef HAVE_NATIVE_mpn_mul_1
3302 #undef HAVE_NATIVE_mpn_mul_1c
3303 #undef HAVE_NATIVE_mpn_mul_2
3304 #undef HAVE_NATIVE_mpn_mul_3
3305 #undef HAVE_NATIVE_mpn_mul_4
3306 #undef HAVE_NATIVE_mpn_mul_5
3307 #undef HAVE_NATIVE_mpn_mul_6
3308 #undef HAVE_NATIVE_mpn_mul_basecase
3309 #undef HAVE_NATIVE_mpn_nand_n
3310 #undef HAVE_NATIVE_mpn_nior_n
3311 #undef HAVE_NATIVE_mpn_popcount
3312 #undef HAVE_NATIVE_mpn_preinv_divrem_1
3313 #undef HAVE_NATIVE_mpn_preinv_mod_1
3314 #undef HAVE_NATIVE_mpn_redc_1
3315 #undef HAVE_NATIVE_mpn_redc_2
3316 #undef HAVE_NATIVE_mpn_rsblsh1_n
3317 #undef HAVE_NATIVE_mpn_rsblsh2_n
3318 #undef HAVE_NATIVE_mpn_rsblsh_n
3319 #undef HAVE_NATIVE_mpn_rsblsh1_nc
3320 #undef HAVE_NATIVE_mpn_rsblsh2_nc
3321 #undef HAVE_NATIVE_mpn_rsblsh_nc
3322 #undef HAVE_NATIVE_mpn_rsh1add_n
3323 #undef HAVE_NATIVE_mpn_rsh1add_nc
3324 #undef HAVE_NATIVE_mpn_rsh1sub_n
3325 #undef HAVE_NATIVE_mpn_rsh1sub_nc
3326 #undef HAVE_NATIVE_mpn_rshift
3327 #undef HAVE_NATIVE_mpn_sqr_basecase
3328 #undef HAVE_NATIVE_mpn_sqr_diagonal
3329 #undef HAVE_NATIVE_mpn_sqr_diag_addlsh1
3330 #undef HAVE_NATIVE_mpn_sub_n
3331 #undef HAVE_NATIVE_mpn_sub_nc
3332 #undef HAVE_NATIVE_mpn_subcnd_n
3333 #undef HAVE_NATIVE_mpn_sublsh1_n
3334 #undef HAVE_NATIVE_mpn_sublsh2_n
3335 #undef HAVE_NATIVE_mpn_sublsh_n
3336 #undef HAVE_NATIVE_mpn_sublsh1_nc
3337 #undef HAVE_NATIVE_mpn_sublsh2_nc
3338 #undef HAVE_NATIVE_mpn_sublsh_nc
3339 #undef HAVE_NATIVE_mpn_sublsh1_n_ip1
3340 #undef HAVE_NATIVE_mpn_sublsh2_n_ip1
3341 #undef HAVE_NATIVE_mpn_sublsh_n_ip1
3342 #undef HAVE_NATIVE_mpn_sublsh1_nc_ip1
3343 #undef HAVE_NATIVE_mpn_sublsh2_nc_ip1
3344 #undef HAVE_NATIVE_mpn_sublsh_nc_ip1
3345 #undef HAVE_NATIVE_mpn_submul_1c
3346 #undef HAVE_NATIVE_mpn_tabselect
3347 #undef HAVE_NATIVE_mpn_udiv_qrnnd
3348 #undef HAVE_NATIVE_mpn_udiv_qrnnd_r
3349 #undef HAVE_NATIVE_mpn_umul_ppmm
3350 #undef HAVE_NATIVE_mpn_umul_ppmm_r
3351 #undef HAVE_NATIVE_mpn_xor_n
3352 #undef HAVE_NATIVE_mpn_xnor_n])
3353
3354
3355 # Don't demand an m4 unless it's actually needed.
3356 if test $found_asm = yes; then
3357   GMP_PROG_M4
3358   GMP_M4_M4WRAP_SPURIOUS
3359 # else
3360 # It's unclear why this m4-not-needed stuff was ever done.
3361 #  if test -z "$M4" ; then
3362 #    M4=m4-not-needed
3363 #  fi
3364 fi
3365
3366 # Only do the GMP_ASM checks if there's a .S or .asm wanting them.
3367 if test $found_asm = no && test $found_S = no; then
3368   gmp_asm_syntax_testing=no
3369 fi
3370
3371 if test "$gmp_asm_syntax_testing" != no; then
3372   GMP_ASM_TEXT
3373   GMP_ASM_DATA
3374   GMP_ASM_LABEL_SUFFIX
3375   GMP_ASM_GLOBL
3376   GMP_ASM_GLOBL_ATTR
3377   GMP_ASM_UNDERSCORE
3378   GMP_ASM_RODATA
3379   GMP_ASM_TYPE
3380   GMP_ASM_SIZE
3381   GMP_ASM_LSYM_PREFIX
3382   GMP_ASM_W32
3383   GMP_ASM_ALIGN_LOG
3384
3385   case $host in
3386     hppa*-*-*)
3387       # for both pa32 and pa64
3388       GMP_INCLUDE_MPN(pa32/pa-defs.m4)
3389       ;;
3390     IA64_PATTERN)
3391       GMP_ASM_IA64_ALIGN_OK
3392       ;;
3393     M68K_PATTERN)
3394       GMP_ASM_M68K_INSTRUCTION
3395       GMP_ASM_M68K_ADDRESSING
3396       GMP_ASM_M68K_BRANCHES
3397       ;;
3398     [powerpc*-*-* | power[3-9]-*-*])
3399       GMP_ASM_POWERPC_PIC_ALWAYS
3400       GMP_ASM_POWERPC_R_REGISTERS
3401       GMP_INCLUDE_MPN(powerpc32/powerpc-defs.m4)
3402       case $host in
3403         *-*-aix*)
3404           case $ABI in
3405             mode64)      GMP_INCLUDE_MPN(powerpc64/aix.m4) ;;
3406             *)           GMP_INCLUDE_MPN(powerpc32/aix.m4) ;;
3407           esac
3408           ;;
3409         *-*-linux* | *-*-*bsd*)
3410           case $ABI in
3411             mode64)      GMP_INCLUDE_MPN(powerpc64/elf.m4) ;;
3412             mode32 | 32) GMP_INCLUDE_MPN(powerpc32/elf.m4) ;;
3413           esac
3414           ;;
3415         *-*-darwin*)
3416           case $ABI in
3417             mode64)      GMP_INCLUDE_MPN(powerpc64/darwin.m4) ;;
3418             mode32 | 32) GMP_INCLUDE_MPN(powerpc32/darwin.m4) ;;
3419           esac
3420           ;;
3421         *)
3422           # Assume unrecognized operating system is the powerpc eABI
3423           GMP_INCLUDE_MPN(powerpc32/eabi.m4)
3424           ;;
3425       esac
3426       ;;
3427     power*-*-aix*)
3428       GMP_INCLUDE_MPN(powerpc32/aix.m4)
3429       ;;
3430     *sparc*-*-*)
3431       case $ABI in
3432         64)
3433           GMP_ASM_SPARC_REGISTER
3434           ;;
3435       esac
3436       ;;
3437     X86_PATTERN | X86_64_PATTERN)
3438       GMP_ASM_ALIGN_FILL_0x90
3439       case $ABI in
3440         32)
3441           GMP_INCLUDE_MPN(x86/x86-defs.m4)
3442           AC_DEFINE(HAVE_HOST_CPU_FAMILY_x86)
3443           GMP_ASM_COFF_TYPE
3444           GMP_ASM_X86_GOT_UNDERSCORE
3445           GMP_ASM_X86_SHLDL_CL
3446           case $enable_profiling in
3447             prof | gprof)  GMP_ASM_X86_MCOUNT ;;
3448           esac
3449           case $host in
3450             *-*-darwin*)
3451               GMP_INCLUDE_MPN(x86/darwin.m4) ;;
3452           esac
3453           ;;
3454         64|x32)
3455           GMP_INCLUDE_MPN(x86_64/x86_64-defs.m4)
3456           AC_DEFINE(HAVE_HOST_CPU_FAMILY_x86_64)
3457           case $host in
3458             *-*-darwin*)
3459               GMP_INCLUDE_MPN(x86_64/darwin.m4) ;;
3460             *-*-mingw* | *-*-cygwin)
3461               GMP_INCLUDE_MPN(x86_64/dos64.m4) ;;
3462           esac
3463           ;;
3464       esac
3465       ;;
3466   esac
3467 fi
3468
3469 # For --enable-minithres, prepend "minithres" to path so that its special
3470 # gmp-mparam.h will be used.
3471 if test $enable_minithres = yes; then
3472   path="minithres $path"
3473 fi
3474
3475 # Create link for gmp-mparam.h.
3476 gmp_mparam_source=
3477 for gmp_mparam_dir in $path; do
3478   test "$no_create" = yes || rm -f gmp-mparam.h
3479   tmp_file=$srcdir/mpn/$gmp_mparam_dir/gmp-mparam.h
3480   if test -f $tmp_file; then
3481     AC_CONFIG_LINKS(gmp-mparam.h:mpn/$gmp_mparam_dir/gmp-mparam.h)
3482     gmp_srclinks="$gmp_srclinks gmp-mparam.h"
3483     gmp_mparam_source=$tmp_file
3484     break
3485   fi
3486 done
3487 if test -z "$gmp_mparam_source"; then
3488   AC_MSG_ERROR([no version of gmp-mparam.h found in path: $path])
3489 fi
3490
3491 # For a helpful message from tune/tuneup.c
3492 gmp_mparam_suggest=$gmp_mparam_source
3493 if test "$gmp_mparam_dir" = generic; then
3494   for i in $path; do break; done
3495   if test "$i" != generic; then
3496     gmp_mparam_suggest="new file $srcdir/mpn/$i/gmp-mparam.h"
3497   fi
3498 fi
3499 AC_DEFINE_UNQUOTED(GMP_MPARAM_H_SUGGEST, "$gmp_mparam_source",
3500 [The gmp-mparam.h file (a string) the tune program should suggest updating.])
3501
3502
3503 # Copy relevant parameters from gmp-mparam.h to config.m4.
3504 # We only do this for parameters that are used by some assembly files.
3505 # Fat binaries do this on a per-file basis, so skip in that case.
3506 #
3507 if test -z "$fat_path"; then
3508   for i in SQR_TOOM2_THRESHOLD BMOD_1_TO_MOD_1_THRESHOLD SHLD_SLOW SHRD_SLOW; do
3509     value=`sed -n 's/^#define '$i'[     ]*\([0-9][0-9]*\).*$/\1/p' $gmp_mparam_source`
3510     if test -n "$value"; then
3511       GMP_DEFINE_RAW(["define(<$i>,<$value>)"])
3512     fi
3513   done
3514 fi
3515
3516
3517 # Sizes of some types, needed at preprocessing time.
3518 #
3519 # FIXME: The assumption that GMP_LIMB_BITS is 8*sizeof(mp_limb_t) might
3520 # be slightly rash, but it's true everywhere we know of and ought to be true
3521 # of any sensible system.  In a generic C build, grepping LONG_BIT out of
3522 # <limits.h> might be an alternative, for maximum portability.
3523 #
3524 AC_CHECK_SIZEOF(void *)
3525 AC_CHECK_SIZEOF(unsigned short)
3526 AC_CHECK_SIZEOF(unsigned)
3527 AC_CHECK_SIZEOF(unsigned long)
3528 AC_CHECK_SIZEOF(mp_limb_t, , GMP_INCLUDE_GMP_H)
3529 if test "$ac_cv_sizeof_mp_limb_t" = 0; then
3530   AC_MSG_ERROR([Oops, mp_limb_t doesn't seem to work])
3531 fi
3532 AC_SUBST(GMP_LIMB_BITS, `expr 8 \* $ac_cv_sizeof_mp_limb_t`)
3533 GMP_DEFINE_RAW(["define(<SIZEOF_UNSIGNED>,<$ac_cv_sizeof_unsigned>)"])
3534
3535 # Check compiler limb size matches gmp-mparam.h
3536 #
3537 # FIXME: Some of the cycle counter objects in the tune directory depend on
3538 # the size of ulong, it'd be possible to check that here, though a mismatch
3539 # probably wouldn't want to be fatal, none of the libgmp assembler code
3540 # depends on ulong.
3541 #
3542 mparam_bits=[`sed -n 's/^#define GMP_LIMB_BITS[         ][      ]*\([0-9]*\).*$/\1/p' $gmp_mparam_source`]
3543 if test -n "$mparam_bits" && test "$mparam_bits" -ne $GMP_LIMB_BITS; then
3544   if test "$test_CFLAGS" = set; then
3545     AC_MSG_ERROR([Oops, mp_limb_t is $GMP_LIMB_BITS bits, but the assembler code
3546 in this configuration expects $mparam_bits bits.
3547 You appear to have set \$CFLAGS, perhaps you also need to tell GMP the
3548 intended ABI, see "ABI and ISA" in the manual.])
3549   else
3550     AC_MSG_ERROR([Oops, mp_limb_t is $GMP_LIMB_BITS bits, but the assembler code
3551 in this configuration expects $mparam_bits bits.])
3552   fi
3553 fi
3554
3555 GMP_DEFINE_RAW(["define(<GMP_LIMB_BITS>,$GMP_LIMB_BITS)"])
3556 GMP_DEFINE_RAW(["define(<GMP_NAIL_BITS>,$GMP_NAIL_BITS)"])
3557 GMP_DEFINE_RAW(["define(<GMP_NUMB_BITS>,eval(GMP_LIMB_BITS-GMP_NAIL_BITS))"])
3558
3559
3560 AC_SUBST(mpn_objects)
3561 AC_SUBST(mpn_objs_in_libgmp)
3562 AC_SUBST(gmp_srclinks)
3563
3564
3565 # A recompiled sqr_basecase for use in the tune program, if necessary.
3566 TUNE_SQR_OBJ=
3567 test -d tune || mkdir tune
3568 case $sqr_basecase_source in
3569   *.asm)
3570     sqr_max=[`sed -n 's/^def...(SQR_TOOM2_THRESHOLD_MAX, *\([0-9]*\))/\1/p' $sqr_basecase_source`]
3571     if test -n "$sqr_max"; then
3572       TUNE_SQR_OBJ=sqr_asm.o
3573       AC_DEFINE_UNQUOTED(TUNE_SQR_TOOM2_MAX,$sqr_max,
3574       [Maximum size the tune program can test for SQR_TOOM2_THRESHOLD])
3575     fi
3576     cat >tune/sqr_basecase.c <<EOF
3577 /* not sure that an empty file can compile, so put in a dummy */
3578 int sqr_basecase_dummy;
3579 EOF
3580     ;;
3581   *.c)
3582     TUNE_SQR_OBJ=
3583     AC_DEFINE(TUNE_SQR_TOOM2_MAX,SQR_TOOM2_MAX_GENERIC)
3584     cat >tune/sqr_basecase.c <<EOF
3585 #define TUNE_PROGRAM_BUILD 1
3586 #define TUNE_PROGRAM_BUILD_SQR 1
3587 #include "mpn/sqr_basecase.c"
3588 EOF
3589     ;;
3590 esac
3591 AC_SUBST(TUNE_SQR_OBJ)
3592
3593
3594 # Configs for demos/pexpr.c.
3595 #
3596 AC_CONFIG_FILES(demos/pexpr-config.h:demos/pexpr-config-h.in)
3597 GMP_SUBST_CHECK_FUNCS(clock, cputime, getrusage, gettimeofday, sigaction, sigaltstack, sigstack)
3598 GMP_SUBST_CHECK_HEADERS(sys/resource.h)
3599 AC_CHECK_TYPES([stack_t], HAVE_STACK_T_01=1, HAVE_STACK_T_01=0,
3600                [#include <signal.h>])
3601 AC_SUBST(HAVE_STACK_T_01)
3602
3603 # Configs for demos/calc directory
3604 #
3605 # AC_SUBST+AC_CONFIG_FILES is used for calc-config.h, rather than AC_DEFINE+
3606 # AC_CONFIG_HEADERS, since with the latter automake (1.8) will then put the
3607 # directory (ie. demos/calc) into $(DEFAULT_INCLUDES) for every Makefile.in,
3608 # which would look very strange.
3609 #
3610 # -lcurses is required by libreadline.  On a typical SVR4 style system this
3611 # normally doesn't have to be given explicitly, since libreadline.so will
3612 # have a NEEDED record for it.  But if someone for some reason is using only
3613 # a static libreadline.a then we must give -lcurses.  Readline (as of
3614 # version 4.3) doesn't use libtool, so we can't rely on a .la to cover
3615 # necessary dependencies.
3616 #
3617 # On a couple of systems we've seen libreadline available, but the headers
3618 # not in the default include path, so check for readline/readline.h.  We've
3619 # also seen readline/history.h missing, not sure if that's just a broken
3620 # install or a very old version, but check that too.
3621 #
3622 AC_CONFIG_FILES(demos/calc/calc-config.h:demos/calc/calc-config-h.in)
3623 LIBCURSES=
3624 if test $with_readline != no; then
3625   AC_CHECK_LIB(ncurses, tputs, [LIBCURSES=-lncurses],
3626     [AC_CHECK_LIB(curses, tputs, [LIBCURSES=-lcurses])])
3627 fi
3628 AC_SUBST(LIBCURSES)
3629 use_readline=$with_readline
3630 if test $with_readline = detect; then
3631   use_readline=no
3632   AC_CHECK_LIB(readline, readline,
3633     [AC_CHECK_HEADER(readline/readline.h,
3634       [AC_CHECK_HEADER(readline/history.h, use_readline=yes)])],
3635     , $LIBCURSES)
3636   AC_MSG_CHECKING(readline detected)
3637   AC_MSG_RESULT($use_readline)
3638 fi
3639 if test $use_readline = yes; then
3640   AC_SUBST(WITH_READLINE_01, 1)
3641   AC_SUBST(LIBREADLINE, -lreadline)
3642 else
3643   WITH_READLINE_01=0
3644 fi
3645 AC_PROG_YACC
3646 AM_PROG_LEX
3647
3648 # Configs for demos/expr directory
3649 #
3650 # Libtool already runs an AC_CHECK_TOOL for ranlib, but we give
3651 # AC_PROG_RANLIB anyway since automake is supposed to complain if it's not
3652 # called.  (Automake 1.8.4 doesn't, at least not when the only library is in
3653 # an EXTRA_LIBRARIES.)
3654 #
3655 AC_PROG_RANLIB
3656
3657
3658 # Create config.m4.
3659 GMP_FINISH
3660
3661 # Create Makefiles
3662 # FIXME: Upcoming version of autoconf/automake may not like broken lines.
3663 #        Right now automake isn't accepting the new AC_CONFIG_FILES scheme.
3664
3665 AC_OUTPUT(Makefile                                                      \
3666   mpf/Makefile mpn/Makefile mpq/Makefile                                \
3667   mpz/Makefile printf/Makefile scanf/Makefile rand/Makefile cxx/Makefile \
3668   tests/Makefile tests/devel/Makefile                                   \
3669   tests/mpf/Makefile tests/mpn/Makefile tests/mpq/Makefile              \
3670   tests/mpz/Makefile tests/rand/Makefile tests/misc/Makefile            \
3671   tests/cxx/Makefile                                                    \
3672   doc/Makefile tune/Makefile                                            \
3673   demos/Makefile demos/calc/Makefile demos/expr/Makefile                \
3674   gmp.h:gmp-h.in)
3675
3676 AC_MSG_NOTICE([summary of build options:
3677
3678   Version:           ${PACKAGE_STRING}
3679   Host type:         ${host}
3680   ABI:               ${ABI}
3681   Install prefix:    ${prefix}
3682   Compiler:          ${CC}
3683   Static libraries:  ${enable_static}
3684   Shared libraries:  ${enable_shared}
3685 ])
3686
3687 if test x$cross_compiling = xyes ; then
3688    case "$host" in
3689      *-*-mingw* | *-*-cygwin)
3690      if test x$ABI = x64 ; then
3691         AC_MSG_NOTICE([If wine64 is installed, use make check TESTS_ENVIRONMENT=wine64.])
3692      else
3693         AC_MSG_NOTICE([If wine is installed, use make check TESTS_ENVIRONMENT=wine.])
3694      fi
3695      ;;
3696    esac
3697 fi