1dnl  Process this file with autoconf to produce a configure script.
2
3define(GMP_COPYRIGHT,[[
4
5Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6Free Software Foundation, Inc.
7
8Copyright 2008 William Hart.
9
10This file is part of the MPIR Library.
11
12The MPIR Library is free software; you can redistribute it and/or modify
13it under the terms of the GNU Lesser General Public License as published
14by the Free Software Foundation; either version 2.1 of the License, or (at
15your option) any later version.
16
17The MPIR Library is distributed in the hope that it will be useful, but
18WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20License for more details.
21
22You should have received a copy of the GNU Lesser General Public License
23along with the MPIR Library; see the file COPYING.LIB.  If not, write to
24the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25MA 02110-1301, USA.
26]])
27
28AC_COPYRIGHT(GMP_COPYRIGHT)
29AH_TOP(/*GMP_COPYRIGHT*/)
30
31AC_REVISION($Revision: 1.11 $)
32AC_PREREQ(2.68)
33AC_INIT(MPIR, MPIR_VERSION, http://groups.google.co.uk/group/mpir-devel/, mpir)
34AC_CONFIG_SRCDIR(gmp-impl.h)
35m4_pattern_forbid([^[ \t]*GMP_])
36m4_pattern_allow(GMP_LDFLAGS)
37m4_pattern_allow(GMP_LIMB_BITS)
38m4_pattern_allow(GMP_MPARAM_H_SUGGEST)
39m4_pattern_allow(GMP_NAIL_BITS)
40m4_pattern_allow(GMP_NUMB_BITS)
41m4_pattern_allow(WANT_GMP_CC)
42
43# If --target is not used then $target_alias is empty, but if say
44# "./configure athlon-pc-freebsd3.5" is used, then all three of
45# $build_alias, $host_alias and $target_alias are set to
46# "athlon-pc-freebsd3.5".
47#
48if test -n "$target_alias" && test "$target_alias" != "$host_alias"; then
49  AC_MSG_ERROR([--target is not appropriate for GMP
50Use --build=CPU-VENDOR-OS if you need to specify your CPU and/or system
51explicitly.  Use --host if cross-compiling (see "Installing GMP" in the
52manual for more on this).])
53fi
54
55GMP_INIT(config.m4)
56
57AC_CANONICAL_HOST
58
59dnl  Automake "no-dependencies" is used because include file dependencies
60dnl  are not useful to us.  Pretty much everything depends just on mpir.h,
61dnl  gmp-impl.h and longlong.h, and yet only rarely does everything need to
62dnl  be rebuilt for changes to those files.
63dnl
64dnl  Note that there's a copy of these options in the top-level Makefile.am,
65dnl  so update there too if changing anything.
66dnl
67AM_INIT_AUTOMAKE([1.11 gnu subdir-objects no-dependencies parallel-tests no-dist-gzip dist-bzip2 dist-zip dist-lzip])
68AC_CONFIG_HEADERS(config.h:config.in)
69AM_MAINTAINER_MODE
70
71dnl  Yasm configuration
72AC_ARG_WITH([yasm],
73[AC_HELP_STRING([--with-yasm],[use a custom Yasm])],
74[],
75[]
76)
77
78AC_ARG_ENABLE(assert,
79AC_HELP_STRING([--enable-assert],[enable ASSERT checking [[default=no]]]),
80[case $enableval in
81yes|no) ;;
82*) AC_MSG_ERROR([bad value $enableval for --enable-assert, need yes or no]) ;;
83esac],
84[enable_assert=no])
85
86if test "$enable_assert" = "yes"; then
87  AC_DEFINE(WANT_ASSERT,1,
88  [Define to 1 to enable ASSERT checking, per --enable-assert])
89  want_assert_01=1
90else
91  want_assert_01=0
92fi
93GMP_DEFINE_RAW(["define(<WANT_ASSERT>,$want_assert_01)"])
94
95
96AC_ARG_ENABLE(alloca,
97AC_HELP_STRING([--enable-alloca],[how to get temp memory [[default=reentrant]]]),
98[case $enableval in
99alloca|malloc-reentrant|malloc-notreentrant) ;;
100yes|no|reentrant|notreentrant) ;;
101debug) ;;
102*)
103  AC_MSG_ERROR([bad value $enableval for --enable-alloca, need one of:
104yes no reentrant notreentrant alloca malloc-reentrant malloc-notreentrant debug]) ;;
105esac],
106[enable_alloca=reentrant])
107
108
109# IMPROVE ME: The default for C++ is disabled.  The tests currently
110# performed below for a working C++ compiler are not particularly strong,
111# and in general can't be expected to get the right setup on their own.  The
112# most significant problem is getting the ABI the same.  Defaulting CXXFLAGS
113# to CFLAGS takes only a small step towards this.  It's also probably worth
114# worrying whether the C and C++ runtimes from say gcc and a vendor C++ can
115# work together.  Some rather broken C++ installations were encountered
116# during testing, and though such things clearly aren't GMP's problem, if
117# --enable-cxx=detect were to be the default then some careful checks of
118# which, if any, C++ compiler on the system is up to scratch would be
119# wanted.
120#
121AC_ARG_ENABLE(cxx,
122AC_HELP_STRING([--enable-cxx],[enable C++ support [[default=no]]]),
123[case $enableval in
124yes|no|detect) ;;
125*) AC_MSG_ERROR([bad value $enableval for --enable-cxx, need yes/no/detect]) ;;
126esac],
127[enable_cxx=no])
128
129
130AC_ARG_ENABLE(fft,
131AC_HELP_STRING([--enable-fft],[enable FFTs for multiplication [[default=yes]]]),
132[case $enableval in
133yes|no) ;;
134*) AC_MSG_ERROR([bad value $enableval for --enable-fft, need yes or no]) ;;
135esac],
136[enable_fft=yes])
137
138if test "$enable_fft" = "yes"; then
139  AC_DEFINE(WANT_FFT,1,
140  [Define to 1 to enable FFTs for multiplication, per --enable-fft])
141fi
142
143AC_ARG_ENABLE(gmpcompat,
144AC_HELP_STRING([--enable-gmpcompat],
145               [create library and header files named gmp as well as mpir [[default=no]]]),
146[case $enableval in
147yes|no) ;;
148*) AC_MSG_ERROR([bad value $enableval for --enable-gmpcompat, need yes or no]) ;;
149esac],
150[enable_gmpcompat=no])
151AM_CONDITIONAL(WANT_GMPCOMPAT, test "$enable_gmpcompat" = "yes")
152
153AC_ARG_ENABLE(nails,
154AC_HELP_STRING([--enable-nails],[use nails on limbs [[default=no]]]),
155[case $enableval in
156[no|[0]]) ;;
157*) AC_MSG_ERROR([bad value $enableval for --enable-nails, Sorry nails not available in this build]) ;;
158esac],
159[enable_nails=no])
160
161case $enable_nails in
162yes) GMP_NAIL_BITS=2 ;;
163no)  GMP_NAIL_BITS=0 ;;
164*)   GMP_NAIL_BITS=$enable_nails ;;
165esac
166AC_SUBST(GMP_NAIL_BITS)
167
168
169AC_ARG_ENABLE(profiling,
170AC_HELP_STRING([--enable-profiling],
171               [build with profiler support [[default=no]]]),
172[case $enableval in
173no|prof|gprof|instrument) ;;
174*) AC_MSG_ERROR([bad value $enableval for --enable-profiling, need no/prof/gprof/instrument]) ;;
175esac],
176[enable_profiling=no])
177
178case $enable_profiling in
179  prof)
180    AC_DEFINE(WANT_PROFILING_PROF, 1,
181              [Define to 1 if --enable-profiling=prof])
182    ;;
183  gprof)
184    AC_DEFINE(WANT_PROFILING_GPROF, 1,
185              [Define to 1 if --enable-profiling=gprof])
186    ;;
187  instrument)
188    AC_DEFINE(WANT_PROFILING_INSTRUMENT, 1,
189              [Define to 1 if --enable-profiling=instrument])
190    ;;
191esac
192
193GMP_DEFINE_RAW(["define(<WANT_PROFILING>,<\`$enable_profiling'>)"])
194
195# -fomit-frame-pointer is incompatible with -pg on some chips
196if test "$enable_profiling" = gprof; then
197  fomit_frame_pointer=
198else
199  fomit_frame_pointer="-fomit-frame-pointer"
200fi
201
202AC_ARG_ENABLE(fat,
203AC_HELP_STRING([--enable-fat],
204               [build a fat binary on systems that support it [[default=no]]]),
205[case $enableval in
206yes|no) ;;
207*) AC_MSG_ERROR([bad value $enableval for --enable-fat, need yes or no]) ;;
208esac],
209[enable_fat=no])
210
211# Table of compilers, options, and mpn paths.  This code has various related
212# purposes
213#
214#   - better default CC/CFLAGS selections than autoconf otherwise gives
215#   - default CC/CFLAGS selections for extra CPU types specific to GMP
216#   - a few tests for known bad compilers
217#   - choice of ABIs on suitable systems
218#   - selection of corresponding mpn search path
219#
220# After GMP specific searches and tests, the standard autoconf AC_PROG_CC is
221# called.  User selections of CC etc are respected.
222#
223# Care is taken not to use macros like AC_TRY_COMPILE during the GMP
224# pre-testing, since they of course depend on AC_PROG_CC, and also some of
225# them cache their results, which is not wanted.
226#
227# The ABI selection mechanism is unique to GMP.  All that reaches autoconf
228# is a different selection of CC/CFLAGS according to the best ABI the system
229# supports, and/or what the user selects.  Naturally the mpn assembler code
230# selected is very dependent on the ABI.
231#
232# The closest the standard tools come to a notion of ABI is something like
233# "sparc64" which encodes a CPU and an ABI together.  This doesn't seem to
234# scale well for GMP, where exact CPU types like "ultrasparc2" are wanted,
235# separate from the ABI used on them.
236#
237#
238# The variables set here are
239#
240#   cclist              the compiler choices
241#   xx_cflags           flags for compiler xx
242#   xx_cflags_maybe     flags for compiler xx, if they work
243#   xx_cppflags         cpp flags for compiler xx
244#   xx_cflags_optlist   list of sets of optional flags
245#   xx_cflags_yyy       set yyy of optional flags for compiler xx
246#   xx_ldflags          -Wc,-foo flags for libtool linking with compiler xx
247#   ar_flags            extra flags for $AR
248#   nm_flags            extra flags for $NM
249#   limb                limb size, can be "longlong"
250#   path                mpn search path
251#   extra_functions     extra mpn functions
252#   fat_path            fat binary mpn search path [if fat binary desired]
253#   fat_functions       fat functions
254#   fat_thresholds      fat thresholds
255#
256# Suppose xx_cflags_optlist="arch", then flags from $xx_cflags_arch are
257# tried, and the first flag that works will be used.  An optlist like "arch
258# cpu optimize" can be used to get multiple independent sets of flags tried.
259# The first that works from each will be used.  If no flag in a set works
260# then nothing from that set is added.
261#
262# For multiple ABIs, the scheme extends as follows.
263#
264#   abilist               set of ABI choices
265#   cclist_aa             compiler choices in ABI aa
266#   xx_aa_cflags          flags for xx in ABI aa
267#   xx_aa_cflags_maybe    flags for xx in ABI aa, if they work
268#   xx_aa_cppflags        cpp flags for xx in ABI aa
269#   xx_aa_cflags_optlist  list of sets of optional flags in ABI aa
270#   xx_aa_cflags_yyy      set yyy of optional flags for compiler xx in ABI aa
271#   xx_aa_ldflags         -Wc,-foo flags for libtool linking
272#   ar_aa_flags           extra flags for $AR in ABI aa
273#   nm_aa_flags           extra flags for $NM in ABI aa
274#   limb_aa               limb size in ABI aa, can be "longlong"
275#   path_aa               mpn search path in ABI aa
276#   extra_functions_aa    extra mpn functions in ABI aa
277#
278# As a convenience, the unadorned xx_cflags (etc) are used for the last ABI
279# in ablist, if an xx_aa_cflags for that ABI isn't given.  For example if
280# abilist="64 32" then $cc_64_cflags will be used for the 64-bit ABI, but
281# for the 32-bit either $cc_32_cflags or $cc_cflags is used, whichever is
282# defined.  This makes it easy to add some 64-bit compilers and flags to an
283# unadorned 32-bit set.
284#
285# limb=longlong (or limb_aa=longlong) applies to all compilers within that
286# ABI.  It won't work to have some needing long long and some not, since a
287# single instantiated mpir.h will be used by both.
288#
289# SPEED_CYCLECOUNTER, cyclecounter_size and CALLING_CONVENTIONS_OBJS are
290# also set here, with an ABI suffix.
291#
292#
293#
294# A table-driven approach like this to mapping cpu type to good compiler
295# options is a bit of a maintenance burden, but there's not much uniformity
296# between options specifications on different compilers.  Some sort of
297# separately updatable tool might be cute.
298#
299# The use of lots of variables like this, direct and indirect, tends to
300# obscure when and how various things are done, but unfortunately it's
301# pretty much the only way.  If shell subroutines were portable then actual
302# code like "if this .. do that" could be written, but attempting the same
303# with full copies of GMP_PROG_CC_WORKS etc expanded at every point would
304# hugely bloat the output.
305
306
307AC_ARG_VAR(ABI, [desired ABI (for processors supporting more than one ABI)])
308
309# abilist needs to be non-empty, "standard" is just a generic name here
310abilist="standard"
311
312# FIXME: We'd like to prefer an ANSI compiler, perhaps by preferring
313# c89 over cc here.  But note that on HP-UX c89 provides a castrated
314# environment, and would want to be excluded somehow.  Maybe
315# AC_PROG_CC_STDC already does enough to stick cc into ANSI mode and
316# we don't need to worry.
317#
318cclist="gcc cc"
319
320gcc_cflags="-O2"
321gcc_64_cflags="-O2"
322cc_cflags="-O"
323cc_64_cflags="-O"
324
325SPEED_CYCLECOUNTER_OBJ=
326cyclecounter_size=2
327
328case $host in
329
330  alpha*-*-*)
331    case $host_cpu in
332      alphaev5* | alphapca5*) path="alpha/ev5 alpha" ;;
333      alphaev67 | alphaev68 | alphaev7*)
334        path="alpha/ev67 alpha/ev6 alpha/ev5 alpha" ;;
335      alphaev6* | alphaev7*)  path="alpha/ev6 alpha/ev5 alpha" ;;
336      *)                      path="alpha" ;;
337    esac
338    extra_functions="cntlz"
339    gcc_cflags_optlist="asm cpu" # need asm ahead of cpu, see below
340
341    # gcc 2.7.2.3 doesn't know any -mcpu= for alpha, apparently.
342    # gcc 2.95 knows -mcpu= ev4, ev5, ev56, pca56, ev6.
343    # gcc 3.0 adds nothing.
344    # gcc 3.1 adds ev45, ev67 (but ev45 is the same as ev4).
345    # gcc 3.2 adds nothing.
346    #
347    # gcc version "2.9-gnupro-99r1" under "-O2 -mcpu=ev6" strikes internal
348    # compiler errors too easily and is rejected by GMP_PROG_CC_WORKS.  Each
349    # -mcpu=ev6 below has a fallback to -mcpu=ev56 for this reason.
350    #
351    case $host_cpu in
352      alpha)        gcc_cflags_cpu="-mcpu=ev4" ;;
353      alphaev5)     gcc_cflags_cpu="-mcpu=ev5" ;;
354      alphaev56)    gcc_cflags_cpu="-mcpu=ev56" ;;
355      alphapca56 | alphapca57)
356                    gcc_cflags_cpu="-mcpu=pca56" ;;
357      alphaev6)     gcc_cflags_cpu="-mcpu=ev6 -mcpu=ev56" ;;
358      alphaev67 | alphaev68 | alphaev7*)
359                    gcc_cflags_cpu="-mcpu=ev67 -mcpu=ev6 -mcpu=ev56" ;;
360    esac
361
362    # On old versions of gcc, which don't know -mcpu=, we believe an
363    # explicit -Wa,-mev5 etc will be necessary to put the assembler in
364    # the right mode for our .asm files and longlong.h asm blocks.
365    #
366    # On newer versions of gcc, when -mcpu= is known, we must give a -Wa
367    # which is at least as high as the code gcc will generate.  gcc
368    # establishes what it needs with a ".arch" directive, our command line
369    # option seems to override that.
370    #
371    # gas prior to 2.14 doesn't accept -mev67, but -mev6 seems enough for
372    # ctlz and cttz (in 2.10.0 at least).
373    #
374    case $host_cpu in
375      alpha)        gcc_cflags_asm="-Wa,-arch,ev4 -Wa,-mev4" ;;
376      alphaev5)     gcc_cflags_asm="-Wa,-arch,ev5 -Wa,-mev5" ;;
377      alphaev56)    gcc_cflags_asm="-Wa,-arch,ev56 -Wa,-mev56" ;;
378      alphapca56 | alphapca57)
379                    gcc_cflags_asm="-Wa,-arch,pca56 -Wa,-mpca56" ;;
380      alphaev6)     gcc_cflags_asm="-Wa,-arch,ev6 -Wa,-mev6" ;;
381      alphaev67 | alphaev68 | alphaev7*)
382                    gcc_cflags_asm="-Wa,-arch,ev67 -Wa,-mev67 -Wa,-arch,ev6 -Wa,-mev6" ;;
383    esac
384
385    # It might be better to ask "cc" whether it's Cray C or DEC C,
386    # instead of relying on the OS part of $host.  But it's hard to
387    # imagine either of those compilers anywhere except their native
388    # systems.
389    #
390    GMP_INCLUDE_MPN(alpha/alpha-defs.m4)
391    GMP_INCLUDE_MPN(alpha/default.m4)
392    SPEED_CYCLECOUNTER_OBJ=alpha.lo
393    cyclecounter_size=1
394    ;;
395
396  arm*-*-*)
397    path="arm"
398    gcc_cflags="$gcc_cflags $fomit_frame_pointer"
399    gcc_testlist="gcc-arm-umodsi"
400    GMP_INCLUDE_MPN(arm/arm-defs.m4)
401    ;;
402
403  IA64_PATTERN)
404    abilist="64"
405    GMP_INCLUDE_MPN(ia64/ia64-defs.m4)
406    SPEED_CYCLECOUNTER_OBJ=ia64.lo
407    gcc_64_cflags="-O2"
408
409    case $host_cpu in
410      itanium)   path="ia64/itanium  ia64" ;;
411      itanium2)  path="ia64/itanium2 ia64" ;;
412      *)         path="ia64" ;;
413    esac
414
415    gcc_64_cflags_optlist="tune"
416    gcc_32_cflags_optlist=$gcc_64_cflags_optlist
417
418    # gcc pre-release 3.4 adds -mtune itanium and itanium2
419    case $host_cpu in
420      itanium)   gcc_cflags_tune="-mtune=itanium" ;;
421      itanium2)  gcc_cflags_tune="-mtune=itanium2" ;;
422    esac
423
424    case $host in
425      *-*-linux*)
426	cclist="gcc icc"
427	icc_cflags="-no-gcc -fpic"
428	icc_cflags_optlist="opt"
429	# FIXME: Check if -O3 is really right.  The manual warns it is for
430	# large data sets, for which GMP uses assembly loops.
431	icc_cflags_opt="-O3 -O2 -O1"
432	;;
433
434      *-*-hpux*)
435        # HP cc sometimes gets internal errors if the optimization level is
436        # too high.  GMP_PROG_CC_WORKS detects this, the "_opt" fallbacks
437        # let us use whatever seems to work.
438        #
439        abilist="32 64"
440
441        cclist_32="gcc cc"
442        path_32="ia64"
443        cc_32_cflags=""
444        cc_32_cflags_optlist="opt"
445        cc_32_cflags_opt="+O3 +O2 +O1"
446        gcc_32_cflags="-milp32 -O2"
447        limb_32=longlong
448        SPEED_CYCLECOUNTER_OBJ_32=ia64.lo
449        cyclecounter_size_32=2
450
451        # Must have +DD64 in CPPFLAGS to get the right __LP64__ for headers,
452        # but also need it in CFLAGS for linking programs, since automake
453        # only uses CFLAGS when linking, not CPPFLAGS.
454        # FIXME: Maybe should use cc_64_ldflags for this, but that would
455        # need GMP_LDFLAGS used consistently by all the programs.
456        #
457        cc_64_cflags="+DD64"
458        cc_64_cppflags="+DD64"
459        cc_64_cflags_optlist="opt"
460        cc_64_cflags_opt="+O3 +O2 +O1"
461        gcc_64_cflags="-mlp64 -O2"
462        ;;
463    esac
464    ;;
465
466  # Irix  5 and earlier can only run 32-bit o32.
467  #
468  # IRIX 6 and up always has a 64-bit mips CPU can run n32 or 64.  n32 is
469  # preferred over 64, but only because that's been the default in past
470  # versions of GMP.  The two are equally efficient.
471  #
472  # Linux kernel 2.2.13 arch/mips/kernel/irixelf.c has a comment about not
473  # supporting n32 or 64.
474  #
475  # For reference, libtool (eg. 1.5.6) recognises the n32 ABI and knows the
476  # right options to use when linking (both cc and gcc), so no need for
477  # anything special from us.
478  #
479  mips*-*-*)
480    abilist="o32"
481    gcc_cflags_optlist="abi"
482    gcc_cflags_abi="-mabi=32"
483    gcc_testlist="gcc-mips-o32"
484    path="mips32"
485    cc_cflags="-O2 -o32"   # no -g, it disables all optimizations
486    # this suits both mips32 and mips64
487    GMP_INCLUDE_MPN(mips32/mips-defs.m4)
488
489    case $host in
490      [mips64*-*-*])
491        abilist="64 n32 o32"
492
493        cclist_n32="gcc cc"
494	gcc_n32_cflags="-O2 -mabi=n32"
495        cc_n32_cflags="-O2 -n32"	# no -g, it disables all optimizations
496        limb_n32=longlong
497        path_n32="mips64"
498
499        cclist_64="pathcc gcc cc"
500        gcc_64_cflags="-O2 -mabi=64"
501        gcc_64_ldflags="-Wc,-mabi=64"
502        cc_64_cflags="-O2 -64"		# no -g, it disables all optimizations
503        cc_64_ldflags="-Wc,-64"
504        pathcc_64_cflags="-O0 -mabi=64"
505        pathcc_64_ldflags="-Wc,-mabi=64"
506        path_64="mips64"
507        ;;
508    esac
509    ;;
510
511
512  # Darwin (powerpc-apple-darwin1.3) has it's hacked gcc installed as cc.
513  # Our usual "gcc in disguise" detection means gcc_cflags etc here gets
514  # used.
515  #
516  # The darwin pre-compiling preprocessor is disabled with -no-cpp-precomp
517  # since it doesn't like "__attribute__ ((mode (SI)))" etc in gmp-impl.h,
518  # and so always ends up running the plain preprocessor anyway.  This could
519  # be done in CPPFLAGS rather than CFLAGS, but there's not many places
520  # preprocessing is done separately, and this is only a speedup, the normal
521  # preprocessor gets run if there's any problems.
522  #
523  # We used to use -Wa,-mppc with gcc, but can't remember exactly why.
524  # Presumably it was for old versions of gcc where -mpowerpc doesn't put
525  # the assembler in the right mode.  In any case -Wa,-mppc is not good, for
526  # instance -mcpu=604 makes recent gcc use -m604 to get access to the
527  # "fsel" instruction, but a -Wa,-mppc overrides that, making code that
528  # comes out with fsel fail.
529  #
530  # (Note also that the darwin assembler doesn't accept "-mppc", so any
531  # -Wa,-mppc was used only if it worked.  The right flag on darwin would be
532  # "-arch ppc" or some such, but that's already the default.)
533  #
534  [powerpc*-*-* | power[3-9]-*-*])
535    abilist="32"
536    cclist="gcc cc"
537    cc_cflags="-O2"
538    gcc_cflags="-O2 -mpowerpc"
539    gcc_cflags_optlist="precomp subtype asm cpu"
540    gcc_cflags_precomp="-no-cpp-precomp"
541    gcc_cflags_subtype="-force_cpusubtype_ALL"	# for vmx on darwin
542    gcc_cflags_asm=""
543    gcc_cflags_cpu=""
544
545    # grab this object, though it's not a true cycle counter routine
546    SPEED_CYCLECOUNTER_OBJ=powerpc.lo
547    cyclecounter_size=0
548
549    case $host_cpu in
550      powerpc740 | powerpc750)
551        path="powerpc32/750 powerpc32" ;;
552      powerpc7400)
553        path="powerpc32/vmx powerpc32/750 powerpc32" ;;
554      [powerpc74[45]?])
555        path="powerpc32/vmx powerpc32 powerpc32" ;;
556      *)
557        path="powerpc32" ;;
558    esac
559
560    # gcc 2.7.2 knows -mcpu=403, 601, 603, 604.
561    # gcc 2.95 adds 401, 505, 602, 603e, ec603e, 604e, 620, 740, 750,
562    #   801, 821, 823, 860.
563    # gcc 3.0 adds 630, rs64a.
564    # gcc 3.1 adds 405, 7400, 7450.
565    # gcc 3.2 adds nothing.
566    # gcc 3.3 adds power3, power4, 8540.  power3 seems to be a synonym for 630.
567    # gcc pre-release 3.4 adds 405fp, 440, 440fp, 970.
568    #
569    # FIXME: The way 603e falls back to 603 for gcc 2.7.2 should be
570    # done for all the others too.  But what would be the correct
571    # arrangements?
572    #
573    case $host_cpu in
574      powerpc401)   gcc_cflags_cpu="-mcpu=401" ;;
575      powerpc403)   gcc_cflags_cpu="-mcpu=403" ;;
576      powerpc405)   gcc_cflags_cpu="-mcpu=405" ;;
577      powerpc505)   gcc_cflags_cpu="-mcpu=505" ;;
578      powerpc601)   gcc_cflags_cpu="-mcpu=601" ;;
579      powerpc602)   gcc_cflags_cpu="-mcpu=602" ;;
580      powerpc603)   gcc_cflags_cpu="-mcpu=603" ;;
581      powerpc603e)  gcc_cflags_cpu="-mcpu=603e -mcpu=603" ;;
582      powerpc604)   gcc_cflags_cpu="-mcpu=604" ;;
583      powerpc604e)  gcc_cflags_cpu="-mcpu=604e -mcpu=604" ;;
584      powerpc620)   gcc_cflags_cpu="-mcpu=620" ;;
585      powerpc630)   gcc_cflags_cpu="-mcpu=630" ;;
586      powerpc740)   gcc_cflags_cpu="-mcpu=740" ;;
587      powerpc7400 | powerpc7410)
588		    gcc_cflags_asm="-Wa,-maltivec"
589  		    gcc_cflags_cpu="-mcpu=7400 -mcpu=750" ;;
590      powerpc74[45]?)
591            gcc_cflags_asm="-Wa,-maltivec"
592  		    gcc_cflags_cpu="-mcpu=7450" ;;
593      powerpc750)   gcc_cflags_cpu="-mcpu=750" ;;
594      powerpc801)   gcc_cflags_cpu="-mcpu=801" ;;
595      powerpc821)   gcc_cflags_cpu="-mcpu=821" ;;
596      powerpc823)   gcc_cflags_cpu="-mcpu=823" ;;
597      powerpc860)   gcc_cflags_cpu="-mcpu=860" ;;
598      powerpc970)   gcc_cflags_cpu="-mcpu=970" ;;
599    esac
600
601    case $host in
602      *-*-aix*)
603        cclist="gcc xlc cc"
604        xlc_cflags="-O2 -qmaxmem=20000"
605        xlc_cflags_optlist="arch"
606
607        # xlc (what version?) knows -qarch=ppc, ppcgr, 601, 602, 603, 604,
608        # 403, rs64a
609        # -qarch=ppc is needed, so ensure everything falls back to that.
610        # FIXME: Perhaps newer versions know more flavours.
611        #
612    	case $host_cpu in
613	  powerpc403)   xlc_cflags_arch="-qarch=403 -qarch=ppc" ;;
614	  powerpc601)   xlc_cflags_arch="-qarch=601 -qarch=ppc" ;;
615	  powerpc602)   xlc_cflags_arch="-qarch=602 -qarch=ppc" ;;
616	  powerpc603)   xlc_cflags_arch="-qarch=603 -qarch=ppc" ;;
617	  powerpc603e)  xlc_cflags_arch="-qarch=603 -qarch=ppc" ;;
618	  powerpc604)   xlc_cflags_arch="-qarch=604 -qarch=ppc" ;;
619	  powerpc604e)  xlc_cflags_arch="-qarch=604 -qarch=ppc" ;;
620	  *)            xlc_cflags_arch="-qarch=ppc" ;;
621        esac
622        ;;
623    esac
624
625    case $host in
626      POWERPC64_PATTERN)
627        case $host_cpu in
628	  powerpc970)		vmx_path="powerpc64/vmx" ;;
629	  *)			vmx_path="" ;;
630	esac
631        case $host in
632          *-*-aix*)
633            # On AIX a true 64-bit ABI is available.
634            # Need -Wc to pass object type flags through to the linker.
635            abilist="aix64 $abilist"
636            cclist_aix64="gcc xlc"
637            gcc_aix64_cflags="-O2 -maix64 -mpowerpc64"
638            gcc_aix64_cflags_optlist="cpu"
639	    gcc_aix64_ldflags="-Wc,-maix64"
640            xlc_aix64_cflags="-O2 -q64 -qtune=pwr3 -qmaxmem=20000"
641	    xlc_aix64_ldflags="-Wc,-q64"
642            # Must indicate object type to ar and nm
643	    ar_aix64_flags="-X64"
644	    nm_aix64_flags="-X64"
645            path_aix64="powerpc64/mode64 $vmx_path powerpc64"
646            # grab this object, though it's not a true cycle counter routine
647            SPEED_CYCLECOUNTER_OBJ_aix64=powerpc64.lo
648            cyclecounter_size_aix64=0
649            ;;
650          *-*-darwin*)
651            # On Darwin we can use 64-bit instructions with a longlong limb,
652            # but the chip still in 32-bit mode.
653            # In theory this can be used on any OS which knows how to save
654            # 64-bit registers in a context switch.
655            #
656            # Note that we must use -mpowerpc64 with gcc, since the
657            # longlong.h macros expect limb operands in a single 64-bit
658            # register, not two 32-bit registers as would be given for a
659            # long long without -mpowerpc64.  In theory we could detect and
660            # accomodate both styles, but the proper 64-bit registers will
661            # be fastest and are what we really want to use.
662            #
663	    # One would think -mpowerpc64 would set the assembler in the right
664	    # mode to handle 64-bit instructions.  But for that, also
665	    # -force_cpusubtype_ALL is needed.
666	    #
667	    # Do not use -fast for Darwin, it actually adds options
668	    # incompatible with a shared library.
669	    #
670	    abilist="mode64 mode32 $abilist"
671	    gcc_cflags_opt="-O3 -O2 -O1"	# will this become used?
672	    cclist_mode32="gcc"
673	    gcc_mode32_cflags="-mpowerpc64"
674	    gcc_mode32_cflags_optlist="subtype cpu opt"
675	    gcc_mode32_cflags_subtype="-force_cpusubtype_ALL"
676	    gcc_mode32_cflags_opt="-O3 -O2 -O1"
677	    path_mode32="powerpc64/mode32 $vmx_path powerpc64"
678	    limb_mode32=longlong
679	    cclist_mode64="gcc"
680	    gcc_mode64_cflags="-m64"
681	    gcc_mode64_cflags_optlist="cpu opt"
682	    gcc_mode64_cflags_opt="-O3 -O2 -O1"
683	    path_mode64="powerpc64/mode64 $vmx_path powerpc64"
684            SPEED_CYCLECOUNTER_OBJ_mode64=powerpc64.lo
685            cyclecounter_size_mode64=0
686	    any_mode64_testlist="sizeof-long-8"
687	    ;;
688	  *-*-linux* | *-*-*bsd*)
689	    # On GNU/Linux, assume the processor is in 64-bit mode.  Some
690	    # environments have a gcc that is always in 64-bit mode, while
691	    # others require -m64, hence the use of cflags_maybe.  The
692	    # sizeof-long-8 test checks the mode is right (for the no option
693	    # case).
694            #
695            # -mpowerpc64 is not used, since it should be the default in
696            # 64-bit mode.  (We need its effect for the various longlong.h
697            # asm macros to be right of course.)
698            #
699            # gcc64 was an early port of gcc to 64-bit mode, but should be
700            # obsolete before too long.  We prefer plain gcc when it knows
701            # 64-bits.
702	    #
703	    abilist="mode64 mode32 $abilist"
704	    cclist_mode32="gcc"
705	    gcc_mode32_cflags="-mpowerpc64 -Wa,-mppc64"
706	    gcc_mode32_cflags_optlist="cpu opt"
707	    gcc_mode32_cflags_opt="-O3 -O2 -O1"
708	    path_mode32="powerpc64/mode32 $vmx_path powerpc64"
709	    limb_mode32=longlong
710	    cclist_mode64="gcc gcc64"
711	    gcc_mode64_cflags_maybe="-m64"
712	    gcc_mode64_cflags_optlist="cpu opt"
713	    gcc_mode64_cflags_opt="-O3 -O2 -O1"
714	    path_mode64="powerpc64/mode64 $vmx_path powerpc64"
715            SPEED_CYCLECOUNTER_OBJ_mode64=powerpc64.lo
716            cyclecounter_size_mode64=0
717	    any_mode64_testlist="sizeof-long-8"
718	    ;;
719        esac
720        ;;
721    esac
722    ;;
723
724  *sparc*-*-*)
725    # sizeof(long)==4 or 8 is tested, to ensure we get the right ABI.  We've
726    # had various bug reports where users have set CFLAGS for their desired
727    # mode, but not set our ABI.  For some reason it's sparc where this
728    # keeps coming up, presumably users there are accustomed to driving the
729    # compiler mode that way.  The effect of our testlist setting is to
730    # reject ABI=64 in favour of ABI=32 if the user has forced the flags to
731    # 32-bit mode.
732    #
733    abilist="32"
734    cclist="gcc acc cc"
735    any_testlist="sizeof-long-4"
736    GMP_INCLUDE_MPN(sparc32/sparc-defs.m4)
737
738    case $host_cpu in
739      sparcv8 | microsparc | turbosparc)
740        path="sparc32" ;;
741      supersparc)
742        path="sparc32" ;;
743      sparc64 | sparcv9* | ultrasparc*)
744        path="sparc32/v9 sparc32" ;;
745      *)
746        path="sparc32" ;;
747    esac
748
749    # gcc 2.7.2 doesn't know about v9 and doesn't pass -xarch=v8plus to the
750    # assembler.  Add it explicitly since the solaris assembler won't accept
751    # our sparc32/v9 asm code without it.  gas accepts -xarch=v8plus too, so
752    # it can be in the cflags unconditionally (though gas doesn't need it).
753    #
754    # gcc -m32 is needed to force 32-bit mode on a dual-ABI system, but past
755    # gcc doesn't know that flag, hence cflags_maybe.  Note that -m32 cannot
756    # be done through the optlist since the plain cflags would be run first
757    # and we don't want to require the default mode (whatever it is) works.
758    #
759    # Note it's gcc_32_cflags_maybe and not gcc_cflags_maybe because the
760    # latter would be used in the 64-bit ABI on systems like "*bsd" where
761    # abilist="64" only.
762    #
763    case $host_cpu in
764      sparc64 | sparcv9* | ultrasparc*)
765        gcc_cflags="-O2 -Wa,-xarch=v8plus" ;;
766      *)
767        gcc_cflags="-O2" ;;
768    esac
769    gcc_32_cflags_maybe="-m32"
770    gcc_cflags_optlist="cpu"
771
772    # gcc 2.7.2 knows -mcypress, -msupersparc, -mv8, -msparclite.
773    # gcc 2.95 knows -mcpu= v7, hypersparc, sparclite86x, f930, f934,
774    #   sparclet, tsc701, v9, ultrasparc.  A warning is given that the
775    #   plain -m forms will disappear.
776    # gcc 3.0 adds nothing.
777    # gcc 3.1 adds nothing.
778    # gcc 3.2 adds nothing.
779    # gcc 3.3 adds ultrasparc3.
780    #
781    case $host_cpu in
782      supersparc)           gcc_cflags_cpu="-mcpu=supersparc -msupersparc" ;;
783      sparcv8 | microsparc | turbosparc)
784			    gcc_cflags_cpu="-mcpu=v8 -mv8" ;;
785      sparc64 | sparcv9*)   gcc_cflags_cpu="-mcpu=v9 -mv8" ;;
786      ultrasparc3)          gcc_cflags_cpu="-mcpu=ultrasparc3 -mcpu=ultrasparc -mv8" ;;
787      ultrasparc*)          gcc_cflags_cpu="-mcpu=ultrasparc -mv8" ;;
788      *)                    gcc_cflags_cpu="-mcpu=v7 -mcypress" ;;
789    esac
790
791    # SunPRO cc and acc, and SunOS bundled cc
792    case $host in
793      *-*-solaris* | *-*-sunos*)
794    	# Note no -g, it disables all optimizations.
795    	cc_cflags=
796    	cc_cflags_optlist="opt arch cpu"
797
798        # SunOS cc doesn't know -xO4, fallback to -O2.
799    	cc_cflags_opt="-xO4 -O2"
800
801        # SunOS cc doesn't know -xarch, apparently always generating v7
802        # code, so make this optional
803    	case $host_cpu in
804    	  sparcv8 | microsparc | supersparc | turbosparc)
805					      cc_cflags_arch="-xarch=v8" ;;
806    	  sparc64 | sparcv9* | ultrasparc*)   cc_cflags_arch="-xarch=v8plus" ;;
807    	  *)                                  cc_cflags_arch="-xarch=v7" ;;
808    	esac
809
810        # SunOS cc doesn't know -xchip and doesn't seem to have an equivalent.
811    	# SunPRO cc 5 recognises -xchip=generic, old, super, super2, micro,
812    	#   micro2, hyper, hyper2, powerup, ultra, ultra2, ultra2i.
813    	# SunPRO cc 6 adds -xchip=ultra2e, ultra3cu.
814        #
815    	# FIXME: Which of ultra, ultra2 or ultra2i is the best fallback for
816    	# ultrasparc3?
817    	#
818    	case $host_cpu in
819    	  supersparc)   cc_cflags_cpu="-xchip=super" ;;
820    	  microsparc)   cc_cflags_cpu="-xchip=micro" ;;
821    	  turbosparc)   cc_cflags_cpu="-xchip=micro2" ;;
822    	  ultrasparc)   cc_cflags_cpu="-xchip=ultra" ;;
823    	  ultrasparc2)  cc_cflags_cpu="-xchip=ultra2" ;;
824    	  ultrasparc2i) cc_cflags_cpu="-xchip=ultra2i" ;;
825    	  ultrasparc3)  cc_cflags_cpu="-xchip=ultra3 -xchip=ultra" ;;
826    	  *)            cc_cflags_cpu="-xchip=generic" ;;
827    	esac
828    esac
829
830    case $host_cpu in
831      sparc64 | sparcv9* | ultrasparc*)
832        case $host in
833          # Solaris 6 and earlier cannot run ABI=64 since it doesn't save
834          # registers properly, so ABI=32 is left as the only choice.
835          #
836          [*-*-solaris2.[0-6] | *-*-solaris2.[0-6].*]) ;;
837
838          # BSD sparc64 ports are 64-bit-only systems, so ABI=64 is the only
839          # choice.  In fact they need no special compiler flags, gcc -m64
840          # is the default, but it doesn't hurt to add it.  v9 CPUs always
841          # use the sparc64 port, since the plain 32-bit sparc ports don't
842          # run on a v9.
843          #
844          *-*-*bsd*) abilist="64" ;;
845
846          # For all other systems, we try both 64 and 32.
847          #
848          # GNU/Linux sparc64 has only recently gained a 64-bit user mode.
849          # In the past sparc64 meant a v9 cpu, but there were no 64-bit
850          # operations in user mode.  We assume that if "gcc -m64" works
851          # then the system is suitable.  Hopefully even if someone attempts
852          # to put a new gcc and/or glibc on an old system it won't run.
853          #
854          *) abilist="64 32" ;;
855        esac
856
857        path_64="sparc64"
858        cclist_64="gcc"
859        any_64_testlist="sizeof-long-8"
860
861        # gcc -mptr64 is probably implied by -m64, but we're not sure if
862        # this was always so.  On Solaris in the past we always used both
863        # "-m64 -mptr64".
864        #
865        # gcc -Wa,-xarch=v9 is thought to be necessary in some cases on
866        # solaris, but it would seem likely that if gcc is going to generate
867        # 64-bit code it will have to add that option itself where needed.
868        # An extra copy of this option should be harmless though, but leave
869        # it until we're sure.  (Might want -xarch=v9a or -xarch=v9b for the
870        # higher cpu types instead.)
871        #
872        gcc_64_cflags="-O2 -m64 -mptr64"
873        gcc_64_ldflags="-Wc,-m64"
874        gcc_64_cflags_optlist="cpu"
875
876        case $host in
877          *-*-solaris*)
878            # Sun cc.
879            #
880            # -fast enables different optimizations depending on compiler
881            # version.  Unfortunately it does things according to the native
882            # system, which may not be optimal when cross compiling (to a
883            # different sparc).  -xchip from cc_cflags_cpu will override at
884            # least that part of its selections.
885            #
886             # -fns=no and -fsimple=1 disable some transformations that
887            # conflict with IEEE 754, which some compiler versions perform
888            # under -fast.
889            #
890            # In any case -fast can result in incorrect optimisations and so
891            # has been removed (see
892            # http://swox.com/list-archives/gmp-bugs/2008-April/000987.html)
893            #
894           cclist_64="$cclist_64 cc"
895            cc_64_cflags="-xarch=v9"
896            cc_64_cflags_optlist="cpu"
897            ;;
898        esac
899
900        # using the v9 %tick register
901        SPEED_CYCLECOUNTER_OBJ_32=sparcv9.lo
902        SPEED_CYCLECOUNTER_OBJ_64=sparcv9.lo
903        cyclecounter_size_32=2
904        cyclecounter_size_64=2
905        ;;
906    esac
907    ;;
908
909  # AMD and Intel x86 configurations, including AMD64
910  #
911  # Rumour has it gcc -O2 used to give worse register allocation than just
912  # -O, but lets assume that's no longer true.
913  #
914  # -m32 forces 32-bit mode on a bi-arch 32/64 amd64 build of gcc.  -m64 is
915  # the default in such a build (we think), so -m32 is essential for ABI=32.
916  # This is, of course, done for any $host_cpu, not just x86_64, so we can
917  # get such a gcc into the right mode to cross-compile to say i486-*-*.
918  #
919  # -m32 is not available in gcc 2.95 and earlier, hence cflags_maybe to use
920  # it when it works.  We check sizeof(long)==4 to ensure we get the right
921  # mode, in case -m32 has failed not because it's an old gcc, but because
922  # it's a dual 32/64-bit gcc without a 32-bit libc, or whatever.
923  #
924  X86_PATTERN | X86_64_PATTERN)
925    abilist="32"
926    cclist="gcc icc cc"
927    gcc_cflags="-O2 $fomit_frame_pointer"
928	case $host in
929	*-*-linux-gnu)
930	    gcc_32_ldflags="-Wl,-z,noexecstack" ;;
931	esac
932    gcc_32_cflags_maybe="-m32"
933    icc_cflags="-no-gcc"
934    icc_cflags_optlist="opt"
935    icc_cflags_opt="-O3 -O2 -O1"
936    any_32_testlist="sizeof-long-4"
937    CALLING_CONVENTIONS_OBJS='x86call.lo x86check$U.lo'
938
939    # Availability of rdtsc is checked at run-time.
940    SPEED_CYCLECOUNTER_OBJ=pentium.lo
941
942    case $host in
943      *-*-solaris* | *-*-sunos*)
944    	# Note no -g, it disables all optimizations.
945    	cc_cflags=
946    	cc_cflags_optlist="opt arch cpu"
947
948        # SunOS cc doesn't know -xO4, fallback to -O2.
949    	cc_cflags_opt="-xO4 -O2" ;;
950    esac
951
952    # gcc 2.7.2 only knows i386 and i486, using -m386 or -m486.  These
953    #     represent -mcpu= since -m486 doesn't generate 486 specific insns.
954    # gcc 2.95 adds k6, pentium and pentiumpro, and takes -march= and -mcpu=.
955    # gcc 3.0 adds athlon.
956    # gcc 3.1 adds k6-2, k6-3, pentium-mmx, pentium2, pentium3, pentium4,
957    #     athlon-tbird, athlon-4, athlon-xp, athlon-mp.
958    # gcc 3.2 adds winchip2.
959    # gcc 3.3 adds winchip-c6.
960    # gcc 3.3.1 from mandrake adds k8 and knows -mtune.
961    # gcc 3.4 adds c3, c3-2, k8, and deprecates -mcpu in favour of -mtune.
962    #
963    # In gcc 2.95.[0123], -march=pentiumpro provoked a stack slot bug in an
964    # old version of mpz/powm.c.  Seems to be fine with the current code, so
965    # no need for any restrictions on that option.
966    #
967    # -march=pentiumpro can fail if the assembler doesn't know "cmov"
968    # (eg. solaris 2.8 native "as"), so always have -march=pentium after
969    # that as a fallback.
970    #
971    # -march=pentium4 and -march=k8 enable SSE2 instructions, which may or
972    # may not be supported by the assembler and/or the OS, and is bad in gcc
973    # prior to 3.3.  The tests will reject these if no good, so fallbacks
974    # like "-march=pentium4 -mno-sse2" are given to try also without SSE2.
975    # Note the relevant -march types are listed in the optflags handling
976    # below, be sure to update there if adding new types emitting SSE2.
977    #
978    # -mtune is used at the start of each cpu option list to give something
979    # gcc 3.4 will use, thereby avoiding warnings from -mcpu.  -mcpu forms
980    # are retained for use by prior gcc.  For example pentium has
981    # "-mtune=pentium -mcpu=pentium ...", the -mtune is for 3.4 and the
982    # -mcpu for prior.  If there's a brand new choice in 3.4 for a chip,
983    # like k8 for x86_64, then it can be the -mtune at the start, no need to
984    # duplicate anything.
985    #
986    gcc_cflags_optlist="cpu arch"
987    case $host_cpu in
988      i386*)
989        gcc_cflags_cpu="-mtune=i386 -mcpu=i386 -m386"
990        gcc_cflags_arch="-march=i386"
991        ;;
992      i486*)
993        gcc_cflags_cpu="-mtune=i486 -mcpu=i486 -m486"
994        gcc_cflags_arch="-march=i486"
995        ;;
996      i586 | pentium)
997        gcc_cflags_cpu="-mtune=pentium -mcpu=pentium -m486"
998        gcc_cflags_arch="-march=pentium"
999        ;;
1000      pentiummmx)
1001        gcc_cflags_cpu="-mtune=pentium-mmx -mcpu=pentium-mmx -mcpu=pentium -m486"
1002        gcc_cflags_arch="-march=pentium-mmx -march=pentium"
1003        ;;
1004      i686 | pentiumpro)
1005        gcc_cflags_cpu="-mtune=pentiumpro -mcpu=pentiumpro -mcpu=i486 -m486"
1006        gcc_cflags_arch="-march=pentiumpro -march=pentium"
1007        ;;
1008      pentium2)
1009        gcc_cflags_cpu="-mtune=pentium2 -mcpu=pentium2 -mcpu=pentiumpro -mcpu=i486 -m486"
1010        gcc_cflags_arch="-march=pentium2 -march=pentiumpro -march=pentium"
1011        ;;
1012      pentium3)
1013        gcc_cflags_cpu="-mtune=pentium3 -mcpu=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1014        gcc_cflags_arch="-march=pentium3 -march=pentiumpro -march=pentium"
1015        ;;
1016      core)
1017        gcc_cflags_cpu="-mtune=pentium-m -mtune=pentium3m -mtune=pentium3 -mcpu=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1018        gcc_cflags_arch="-march=pentium-m -march=pentium3m -march=pentium3 -march=pentiumpro -march=pentium"
1019        ;;
1020      k6)
1021        gcc_cflags_cpu="-mtune=k6 -mcpu=k6 -mcpu=i486 -m486"
1022        gcc_cflags_arch="-march=k6"
1023        ;;
1024      k62)
1025        gcc_cflags_cpu="-mtune=k6-2 -mcpu=k6-2 -mcpu=k6 -mcpu=i486 -m486"
1026        gcc_cflags_arch="-march=k6-2 -march=k6"
1027        ;;
1028      k63)
1029        gcc_cflags_cpu="-mtune=k6-3 -mcpu=k6-3 -mcpu=k6 -mcpu=i486 -m486"
1030        gcc_cflags_arch="-march=k6-3 -march=k6"
1031        ;;
1032      k7 | athlon)
1033        # Athlon instruction costs are close to P6 (3 cycle load latency,
1034        # 4-6 cycle mul, 40 cycle div, pairable adc, etc) so if gcc doesn't
1035        # know athlon (eg. 2.95.2 doesn't) then fall back on pentiumpro.
1036        gcc_cflags_cpu="-mtune=athlon -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1037        gcc_cflags_arch="-march=athlon -march=pentiumpro -march=pentium"
1038        ;;
1039      i786 | pentium4)
1040        # pentiumpro is the primary fallback when gcc doens't know pentium4.
1041        # This gets us cmov to eliminate branches.  Maybe "athlon" would be
1042        # a possibility on gcc 3.0.
1043        #
1044        gcc_cflags_cpu="-mtune=pentium4 -mcpu=pentium4 -mcpu=pentiumpro -mcpu=i486 -m486"
1045        gcc_cflags_arch="-march=pentium4 -march=pentium4~-mno-sse2 -march=pentiumpro -march=pentium"
1046        ;;
1047      prescott)
1048        # prescott is defined for our purposes as 32 bit pentium4 with SSE3
1049        gcc_cflags_cpu="-mtune=prescott -mtune=pentium4 -mcpu=pentium4 -mcpu=pentiumpro -mcpu=i486 -m486"
1050        gcc_cflags_arch="-march=prescott -march=pentium4~-mno-sse2 -march=pentiumpro -march=pentium"
1051        ;;
1052      netburst | netburstlahf)
1053        # prescott is defined for our purposes as 32 bit pentium4 with SSE3
1054        gcc_cflags_cpu="-mtune=nocona -mtune=pentium4 -mcpu=pentium4 -mcpu=pentiumpro -mcpu=i486 -m486"
1055        gcc_cflags_arch="-march=nocona -march=pentium4~-mno-sse2 -march=pentiumpro -march=pentium"
1056        ;;
1057      nano | viac32)
1058        # Not sure of the best fallbacks here for -mcpu.
1059        # c3-2 has sse and mmx, so pentium3 is good for -march.
1060        gcc_cflags_cpu="-mtune=c3-2 -mcpu=c3-2 -mcpu=i486 -m486"
1061        gcc_cflags_arch="-march=c3-2 -march=pentium3 -march=pentiumpro -march=pentium"
1062        ;;
1063      viac3*)
1064        # Not sure of the best fallbacks here.
1065        gcc_cflags_cpu="-mtune=c3 -mcpu=c3 -mcpu=i486 -m486"
1066        gcc_cflags_arch="-march=c3 -march=pentium-mmx -march=pentium"
1067        ;;
1068      x86_64 | k8)
1069        gcc_cflags_cpu="-mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1070        gcc_cflags_arch="-march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1071        ;;
1072      k10 | k102 | k103)
1073        gcc_cflags_cpu="-mtune=amdfam10 -mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1074        gcc_cflags_arch="-march=amdfam10 -march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1075        ;;
1076      bulldozer)
1077        gcc_cflags_cpu="-mtune=bdver1 -mtune=amdfam10 -mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1078        gcc_cflags_arch="-march=bdver1 -march=amdfam10 -march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1079        ;;
1080      piledriver)
1081        gcc_cflags_cpu="-mtune=bdver2 -mtune=amdfam10 -mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1082        gcc_cflags_arch="-march=bdver2 -march=amdfam10 -march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1083        ;;
1084      bobcat)
1085        gcc_cflags_cpu="-mtune=btver1 -mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1086        gcc_cflags_arch="-march=btver1 -march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1087        ;;
1088      atom)
1089        gcc_cflags_cpu="-mtune=atom -mtune=k8 -mcpu=athlon -mcpu=pentiumpro -mcpu=i486 -m486"
1090        gcc_cflags_arch="-march=atom -march=k8 -march=k8~-mno-sse2 -march=athlon -march=pentiumpro -march=pentium"
1091        ;;
1092      core2 | penryn)
1093        gcc_cflags_cpu="-mtune=core2 -mtune=nocona -mtune=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1094        gcc_cflags_arch="-march=core2 -march=nocona -march=pentium3 -march=pentiumpro -march=pentium"
1095        ;;
1096      nehalem | westmere)
1097        gcc_cflags_cpu="-mtune=corei7 -mtune=core2 -mtune=nocona -mtune=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1098        gcc_cflags_arch="-march=corei7 -march=core2 -march=nocona -march=pentium3 -march=pentiumpro -march=pentium"
1099        ;;
1100      sandybridge | ivybridge | haswell)
1101        gcc_cflags_cpu="-mtune=corei7-avx -mtune=corei7 -mtune=core2 -mtune=nocona -mtune=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1102        gcc_cflags_arch="-march=corei7-avx -march=corei7 -march=core2 -march=nocona -march=pentium3 -march=pentiumpro -march=pentium"
1103        ;;
1104      skylake)
1105        gcc_cflags_cpu="-mtune=corei7 -mtune=core2 -mtune=nocona -mtune=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1106        gcc_cflags_arch="-march=corei7 -march=core2 -march=nocona -march=pentium3 -march=pentiumpro -march=pentium"
1107        ;;
1108      skylakeavx)
1109        gcc_cflags_cpu="-mtune=skylake -mtune=corei7-avx -mtune=corei7 -mtune=core2 -mtune=nocona -mtune=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1110        gcc_cflags_arch="-march=skylake -march=corei7-avx -march=corei7 -march=core2 -march=nocona -march=pentium3 -march=pentiumpro -march=pentium"
1111        ;;
1112      broadwell)
1113        gcc_cflags_cpu="-mtune=broadwell -mtune=corei7-avx -mtune=corei7 -mtune=core2 -mtune=nocona -mtune=pentium3 -mcpu=pentiumpro -mcpu=i486 -m486"
1114        gcc_cflags_arch="-march=broadwell -march=corei7-avx -march=corei7 -march=core2 -march=nocona -march=pentium3 -march=pentiumpro -march=pentium"
1115        ;;
1116      *)
1117        gcc_cflags_cpu="-mtune=i486 -mcpu=i486 -m486"
1118        gcc_cflags_arch="-march=i486"
1119        ;;
1120    esac
1121
1122    case $host_cpu in
1123      i386*)                   path="x86/i386 x86" ;;
1124      i486*)                   path="x86/i486 x86" ;;
1125      i586 | pentium)          path="x86/pentium x86" ;;
1126      pentiummmx)              path="x86/pentium/mmx x86/pentium x86" ;;
1127      i686 | pentiumpro)       path="x86/p6 x86" ;;
1128      pentium2)                path="x86/p6/mmx x86/p6 x86" ;;
1129      pentium3)                path="x86/p6/p3mmx x86/p6/mmx x86/p6 x86";;
1130      core)                    path="x86/p6/p3mmx x86/p6/mmx x86/p6 x86";;
1131      [k6[23]])                path="x86/k6/k62mmx x86/k6/mmx x86/k6 x86" ;;
1132      k6)                      path="x86/k6/mmx x86/k6 x86" ;;
1133      athlon | k7 | x86_64 | atom)   path="x86/k7/mmx x86/k7 x86" ;;
1134      k102 | k103 | bulldozer | piledriver)       path="x86/k7/mmx/k8/k10/k102  x86/k7/mmx/k8/k10 x86/k7/mmx/k8 x86/k7/mmx x86/k7 x86" ;;
1135      k10)			path="x86/k7/mmx/k8/k10 x86/k7/mmx/k8 x86/k7/mmx x86/k7 x86" ;;
1136      k8 | bobcat)		path="x86/k7/mmx/k8 x86/k7/mmx x86/k7 x86" ;;
1137      core2 | penryn)		path="x86/core2 x86" ;;
1138      i786 | pentium4)		path="x86/pentium4/sse2 x86/pentium4/mmx x86/pentium4 x86" ;;
1139      nehalem | westmere | sandybridge | ivybridge | haswell | skylake | skylakeavx | broadwell)	path="x86/nehalem x86" ;;
1140      prescott | netburst | netburstlahf)       path="x86/pentium4/sse2 x86/pentium4/mmx x86/pentium4 x86" ;;
1141      # VIA/Centaur processors, sold as CyrixIII and C3.
1142      nano | viac32)           path="x86/p6/p3mmx x86/p6/mmx x86/p6 x86";;
1143      viac3*)                  path="x86/pentium/mmx x86/pentium x86";;
1144      *)                       path="x86" ;;
1145    esac
1146
1147    # 32bit apple darwin doesn't like our PIC format asm code
1148    case $host in
1149	i[34567]86-apple-darwin* | pentium*-apple-darwin* | prescott-apple-darwin* | core-apple-darwin* )	path="x86/applenopic" ;;
1150	# assume Core2 or later
1151	*-apple-darwin* )	path="x86/applenopic/core2 x86/applenopic" ;;
1152	*)			;;
1153    esac
1154
1155    # If the user asked for a fat build, override the path set above
1156    if test $enable_fat = yes; then
1157      gcc_cflags_cpu=""
1158      gcc_cflags_arch=""
1159      extra_functions="$extra_functions fat fat_entry"
1160      path="x86 x86/fat"
1161      fat_path="x86 x86/fat x86/i486
1162		x86/k6 x86/k6/mmx x86/k6/k62mmx
1163		x86/k7 x86/k7/mmx x86/k7/mmx/k8 x86/k7/mmx/k8/k10 x86/k7/mmx/k8/k10/k102
1164		x86/pentium x86/pentium/mmx
1165		x86/p6 x86/p6/mmx x86/p6/p3mmx
1166		x86/pentium4 x86/pentium4/mmx x86/pentium4/sse2
1167		x86/core2 x86/nehalem"
1168      fat_functions="add_n addmul_1 add_err1_n add_err2_n copyd copyi
1169		     divexact_1 divexact_by3c divexact_byfobm1 divrem_1 divrem_2
1170			 divrem_euclidean_qr_1
1171			divrem_euclidean_qr_2 gcd_1 lshift
1172		     mod_1 mod_34lsub1 modexact_1c_odd mul_1 mul_basecase
1173		     mulmid_basecase preinv_divrem_1 preinv_mod_1 redc_1 rshift
1174		     sqr_basecase sub_n submul_1 sumdiff_n sub_err1_n sub_err2_n"
1175      fat_exclude=""
1176      fat_thresholds="MUL_KARATSUBA_THRESHOLD MUL_TOOM3_THRESHOLD
1177		      SQR_KARATSUBA_THRESHOLD SQR_TOOM3_THRESHOLD"
1178    fi
1179
1180    case $host in
1181      X86_64_PATTERN)
1182        abilist="64 32"
1183        cclist_64="gcc cc"
1184        gcc_64_cflags="-m64"
1185	gcc_cflags_opt="-O2 -O1"
1186	case $host in
1187	*-*-linux-gnu)
1188	    gcc_64_ldflags="-Wl,-z,noexecstack" ;;
1189	esac
1190        gcc_64_cflags_optlist="opt arch cpu"
1191        SPEED_CYCLECOUNTER_OBJ_64=x86_64.lo
1192        CALLING_CONVENTIONS_OBJS_64='x86_64call.lo x86_64check$U.lo'
1193        cyclecounter_size_64=2
1194        case $host in
1195           *-*-solaris* | *-*-sunos*)
1196           # Note no -g, it disables all optimizations.
1197           cc_64_cflags="-m64"
1198           cc_64_cflags_optlist="opt arch cpu"
1199
1200           # SunOS cc doesn't know -xO4, fallback to -O2.
1201           cc_64_cflags_opt="-xO4 -O2" ;;
1202        esac
1203
1204        case $host in
1205          # NOTE x86_64w and x86_64 paths MUST be the same , for the fat structure
1206          x86_64-pc-msys|x86_64-w64-mingw*|x86_64-*-cygwin*)
1207            path_64="x86_64w" ;;
1208          netburst-pc-msys|netburst-w64-mingw*|netburst-*-cygwin*)
1209            path_64="x86_64w/netburst x86_64w" ;;
1210          netburstlahf-pc-msys|netburstlahf-w64-mingw*|netburstlahf-*-cygwin*)
1211            path_64="x86_64w/netburst x86_64w" ;;
1212          k8-pc-msys|k8-w64-mingw*|k8-*-cygwin*)
1213            path_64="x86_64w/k8/k8only x86_64w/k8 x86_64w" ;;
1214          k10-pc-msys|k10-w64-mingw*|k10-*-cygwin*)
1215            path_64="x86_64w/k8/k10 x86_64w/k8 x86_64w" ;;
1216          k102-pc-msys|k102-w64-mingw*|k102-*-cygwin*)
1217            path_64="x86_64w/k8/k10/k102 x86_64w/k8/k10 x86_64w/k8 x86_64w" ;;
1218          k103-pc-msys|k103-w64-mingw*|k103-*-cygwin*)
1219            path_64="x86_64w/k8/k10/k102 x86_64w/k8/k10 x86_64w/k8 x86_64w" ;;
1220          bulldozer-pc-msys|bulldozer-w64-mingw*|bulldozer-*-cygwin*)
1221            path_64="x86_64w/bulldozer x86_64w/k8/k10/k102 x86_64w/k8/k10 x86_64w/k8 x86_64w" ;;
1222          piledriver-pc-msys|piledriver-w64-mingw*|piledriver-*-cygwin*)
1223            path_64="x86_64w/bulldozer/piledriver x86_64w/bulldozer x86_64w/k8/k10/k102 x86_64w/k8/k10 x86_64w/k8 x86_64w" ;;
1224          bobcat-pc-msys|bobcat-w64-mingw*|bobcat-*-cygwin*)
1225            path_64="x86_64w/bobcat x86_64w" ;;
1226          core2-pc-msys|core2-w64-mingw*|core2-*-cygwin*)
1227            path_64="x86_64w/core2 x86_64w" ;;
1228          penryn-pc-msys|penryn-w64-mingw*|penryn-*-cygwin*)
1229            path_64="x86_64w/core2/penryn x86_64w/core2 x86_64w" ;;
1230          nehalem-pc-msys|nehalem-w64-mingw*|nehalem-*-cygwin*)
1231            path_64="x86_64w/nehalem x86_64w" ;;
1232          westmere-pc-msys|westmere-w64-mingw*|westmere-*-cygwin*)
1233            path_64="x86_64w/nehalem/westmere x86_64w/nehalem x86_64w" ;;
1234          sandybridge-pc-msys|sandybridge-w64-mingw*|sandybridge-*-cygwin*)
1235            path_64="x86_64w/sandybridge x86_64w" ;;
1236          ivybridge-pc-msys|ivybridge-w64-mingw*|ivybridge-*-cygwin*)
1237            path_64="x86_64w/sandybridge/ivybridge x86_64w/sandybridge x86_64w" ;;
1238          haswell-pc-msys|haswell-w64-mingw*|haswell-*-cygwin*)
1239            path_64="x86_64w/haswell x86_64w/sandybridge x86_64w" ;;
1240          skylake-pc-msys|skylake-w64-mingw*|skylake-*-cygwin*)
1241            path_64="x86_64w/skylake x86_64w/sandybridge x86_64w" ;;
1242          skylakeavx-pc-msys|skylakeavx-w64-mingw*|skylakeavx-*-cygwin*)
1243            path_64="x86_64w/skylakeavx x86_64w/skylake x86_64w/haswell x86_64w/sandybridge x86_64w" ;;
1244          broadwell-pc-msys|broadwell-w64-mingw*|broadwell-*-cygwin*)
1245            path_64="x86_64w/haswell/broadwell x86_64w/haswell/avx x86_64w/haswell x86_64w/sandybridge x86_64w" ;;
1246          atom-pc-msys|atom-w64-mingw*|atom-*-cygwin*)
1247            path_64="x86_64w/atom x86_64w" ;;
1248          nano-pc-msys|nano-w64-mingw*|nano-*-cygwin*)
1249            path_64="x86_64w/k8/k8only x86_64w/k8 x86_64w" ;;
1250
1251          x86_64-*-*)
1252            path_64="x86_64" ;;
1253          netburst-*-*)
1254            path_64="x86_64/netburst x86_64" ;;
1255          netburstlahf-*-*)
1256            path_64="x86_64/netburst x86_64" ;;
1257          k8-*-*)
1258            path_64="x86_64/k8/k8only x86_64/k8 x86_64" ;;
1259          k10-*-*)
1260            path_64="x86_64/k8/k10 x86_64/k8 x86_64" ;;
1261          k102-*-*)
1262            path_64="x86_64/k8/k10/k102 x86_64/k8/k10 x86_64/k8 x86_64" ;;
1263          k103-*-*)
1264            path_64="x86_64/k8/k10/k102 x86_64/k8/k10 x86_64/k8 x86_64" ;;
1265          bulldozer-*-*)
1266            path_64="x86_64/bulldozer x86_64/k8/k10/k102 x86_64/k8/k10 x86_64/k8 x86_64" ;;
1267          piledriver-*-*)
1268            path_64="x86_64/bulldozer/piledriver x86_64/bulldozer x86_64/k8/k10/k102 x86_64/k8/k10 x86_64/k8 x86_64" ;;
1269          bobcat-*-*)
1270            path_64="x86_64/bobcat x86_64" ;;
1271          core2-*-*)
1272            path_64="x86_64/core2 x86_64" ;;
1273          penryn-*-*)
1274            path_64="x86_64/core2/penryn x86_64/core2 x86_64" ;;
1275          nehalem-*-*)
1276            path_64="x86_64/nehalem x86_64/core2 x86_64" ;;
1277          westmere-*-*)
1278            path_64="x86_64/nehalem/westmere x86_64/nehalem x86_64/core2 x86_64" ;;
1279          sandybridge-*-*)
1280            path_64="x86_64/sandybridge x86_64/nehalem x86_64/core2 x86_64" ;;
1281          ivybridge-*-*)
1282            path_64="x86_64/sandybridge/ivybridge x86_64/sandybridge x86_64/nehalem x86_64/core2 x86_64" ;;
1283          haswell-*-*)
1284            path_64="x86_64/haswell/avx x86_64/haswell x86_64/sandybridge x86_64" ;;
1285          broadwell-*-*)
1286            path_64="x86_64/haswell/broadwell x86_64/haswell/avx x86_64/haswell x86_64/sandybridge x86_64" ;;
1287          skylake-*-*)
1288            path_64="x86_64/skylake x86_64/sandybridge x86_64" ;;
1289          skylakeavx-*-*)
1290            path_64="x86_64/skylake/avx x86_64/haswell/avx x86_64/skylake x86_64/haswell x86_64/sandybridge x86_64" ;;
1291          atom-*-*)
1292            path_64="x86_64/atom x86_64" ;;
1293          nano-*-*)
1294            path_64="x86_64/k8/k8only x86_64/k8 x86_64" ;;
1295        esac
1296
1297        # If the user asked for a fat build, override the path set above
1298        if test $enable_fat = yes; then
1299          gcc_64_cflags_cpu=""
1300          gcc_64_cflags_arch=""
1301          extra_functions_64="$extra_functions_64 fat fat_entry"
1302          case $host in
1303            *-pc-msys|*-w64-mingw*|*-*-cygwin*)
1304              path_64="x86_64w x86_64w/fat"
1305              fat_path_64="x86_64w x86_64w/fat x86_64w/netburst x86_64w/k8 x86_64w/k8/k8only x86_64w/k8/k10 x86_64w/k8/k10/k102  x86_64w/core2 x86_64w/core2/penryn x86_64w/nehalem x86_64w/nehalem/westmere x86_64w/atom x86_64w/bobcat x86_64w/sandybridge x86_64w/haswell x86_64w/haswell/avx x86_64w/haswell/broadwell x86_64w/skylake x86_64w/skylake/avx" ;;
1306            *-*-*)
1307              path_64="x86_64 x86_64/fat"
1308              fat_path_64="x86_64 x86_64/fat x86_64/netburst x86_64/k8 x86_64/k8/k8only x86_64/k8/k10 x86_64/k8/k10/k102  x86_64/core2 x86_64/core2/penryn x86_64/nehalem x86_64/nehalem/westmere x86_64/atom x86_64/bobcat x86_64/bulldozer x86_64/bulldozer/piledriver x86_64/sandybridge x86_64/sandybridge/ivybridge x86_64/haswell x86_64/haswell/avx x86_64/haswell/broadwell x86_64/skylake x86_64/skylake/avx" ;;
1309          esac
1310        fi
1311        ;;
1312
1313      esac
1314      ;;
1315
1316
1317  # Special CPU "none" selects generic C.
1318  #
1319  none-*-*)
1320    abilist="long longlong"
1321    cclist_long=$cclist
1322    gcc_long_cflags=$gcc_cflags
1323    cc_long_cflags=$cc_cflags
1324    cclist_longlong=$cclist
1325    gcc_longlong_cflags=$gcc_cflags
1326    cc_longlong_cflags=$cc_cflags
1327    limb_longlong=longlong
1328    ;;
1329
1330esac
1331
1332# mingw can be built by the cygwin gcc if -mno-cygwin is added.  For
1333# convenience add this automatically if it works.  Actual mingw gcc accepts
1334# -mno-cygwin too, but of course is the default.  mingw only runs on the
1335# x86s, but allow any CPU here so as to catch "none" too.
1336#
1337case $host in
1338  *-pc-msys|*-*-mingw*)
1339    gcc_cflags_optlist="$gcc_cflags_optlist nocygwin"
1340    gcc_cflags_nocygwin="-mno-cygwin"
1341    ;;
1342esac
1343
1344CFLAGS_or_unset=${CFLAGS-'(unset)'}
1345CPPFLAGS_or_unset=${CPPFLAGS-'(unset)'}
1346
1347cat >&AC_FD_CC <<EOF
1348User:
1349ABI=$ABI
1350CC=$CC
1351CFLAGS=$CFLAGS_or_unset
1352CPPFLAGS=$CPPFLAGS_or_unset
1353MPN_PATH=$MPN_PATH
1354GMP:
1355abilist=$abilist
1356cclist=$cclist
1357EOF
1358
1359
1360test_CFLAGS=${CFLAGS+set}
1361test_CPPFLAGS=${CPPFLAGS+set}
1362
1363for abi in $abilist; do
1364  abi_last="$abi"
1365done
1366
1367# If the user specifies an ABI then it must be in $abilist, after that
1368# $abilist is restricted to just that choice.
1369#
1370if test -n "$ABI"; then
1371  found=no
1372  for abi in $abilist; do
1373    if test $abi = "$ABI"; then found=yes; break; fi
1374  done
1375  if test $found = no; then
1376    AC_MSG_ERROR([ABI=$ABI is not among the following valid choices: $abilist])
1377  fi
1378  abilist="$ABI"
1379fi
1380
1381found_compiler=no
1382
1383for abi in $abilist; do
1384
1385  echo "checking ABI=$abi"
1386
1387  # Suppose abilist="64 32", then for abi=64, will have abi1="_64" and
1388  # abi2="_64".  For abi=32, will have abi1="_32" and abi2="".  This is how
1389  # $gcc_cflags becomes a fallback for $gcc_32_cflags (the last in the
1390  # abilist), but there's no fallback for $gcc_64_cflags.
1391  #
1392  abi1=[`echo _$abi | sed 's/[.]//g'`]
1393  if test $abi = $abi_last; then abi2=; else abi2="$abi1"; fi
1394
1395  # Compiler choices under this ABI
1396                              eval cclist_chosen=\"\$cclist$abi1\"
1397  test -n "$cclist_chosen" || eval cclist_chosen=\"\$cclist$abi2\"
1398
1399  # If there's a user specified $CC then don't use a list for
1400  # $cclist_chosen, just a single value for $ccbase.
1401  #
1402  if test -n "$CC"; then
1403
1404    # The first word of $CC, stripped of any directory.  For instance
1405    # CC="/usr/local/bin/gcc -pipe" will give "gcc".
1406    #
1407    for ccbase in $CC; do break; done
1408    ccbase=`echo $ccbase | sed 's:.*/::'`
1409
1410    # If this $ccbase is in $cclist_chosen then it's a compiler we know and
1411    # we can do flags defaulting with it.  If not, then $cclist_chosen is
1412    # set to "unrecognised" so no default flags are used.
1413    #
1414    # "unrecognised" is used to avoid bad effects with eval if $ccbase has
1415    # non-symbol characters.  For instance ccbase=my+cc would end up with
1416    # something like cflags="$my+cc_cflags" which would give
1417    # cflags="+cc_cflags" rather than the intended empty string for an
1418    # unknown compiler.
1419    #
1420    found=unrecognised
1421    for i in $cclist_chosen; do
1422      if test "$ccbase" = $i; then
1423        found=$ccbase
1424        break
1425      fi
1426    done
1427    cclist_chosen=$found
1428  fi
1429
1430  for ccbase in $cclist_chosen; do
1431
1432    # When cross compiling, look for a compiler with the $host_alias as a
1433    # prefix, the same way that AC_CHECK_TOOL does.  But don't do this to a
1434    # user-selected $CC.
1435    #
1436    # $cross_compiling will be yes/no/maybe at this point.  Do the host
1437    # prefixing for "maybe" as well as "yes".
1438    #
1439    if test "$cross_compiling" != no && test -z "$CC"; then
1440      cross_compiling_prefix="${host_alias}-"
1441    fi
1442
1443    for ccprefix in $cross_compiling_prefix ""; do
1444
1445      cc="$CC"
1446      test -n "$cc" || cc="$ccprefix$ccbase"
1447
1448      # If the compiler is gcc but installed under another name, then change
1449      # $ccbase so as to use the flags we know for gcc.  This helps for
1450      # instance when specifying CC=gcc272 on Debian GNU/Linux, or the
1451      # native cc which is really gcc on NeXT or MacOS-X.
1452      #
1453      # FIXME: There's a slight misfeature here.  If cc is actually gcc but
1454      # gcc is not a known compiler under this $abi then we'll end up
1455      # testing it with no flags and it'll work, but chances are it won't be
1456      # in the right mode for the ABI we desire.  Let's quietly hope this
1457      # doesn't happen.
1458      #
1459      if test $ccbase != gcc; then
1460        GMP_PROG_CC_IS_GNU($cc,ccbase=gcc)
1461      fi
1462
1463      # Similarly if the compiler is IBM xlc but invoked as cc or whatever
1464      # then change $ccbase and make the default xlc flags available.
1465      if test $ccbase != xlc; then
1466        GMP_PROG_CC_IS_XLC($cc,ccbase=xlc)
1467      fi
1468
1469      # acc was Sun's first unbundled compiler back in the SunOS days, or
1470      # something like that, but today its man page says it's not meant to
1471      # be used directly (instead via /usr/ucb/cc).  The options are pretty
1472      # much the same as the main SunPRO cc, so share those configs.
1473      #
1474      case $host in
1475        *sparc*-*-solaris* | *sparc*-*-sunos*)
1476          if test "$ccbase" = acc; then ccbase=cc; fi ;;
1477      esac
1478
1479      for tmp_cflags_maybe in yes no; do
1480                             eval cflags=\"\$${ccbase}${abi1}_cflags\"
1481        test -n "$cflags" || eval cflags=\"\$${ccbase}${abi2}_cflags\"
1482
1483	if test "$tmp_cflags_maybe" = yes; then
1484          # don't try cflags_maybe when the user set CFLAGS
1485          if test "$test_CFLAGS" = set; then continue; fi
1486                                     eval cflags_maybe=\"\$${ccbase}${abi1}_cflags_maybe\"
1487          test -n "$cflags_maybe" || eval cflags_maybe=\"\$${ccbase}${abi2}_cflags_maybe\"
1488          # don't try cflags_maybe if there's nothing set
1489          if test -z "$cflags_maybe"; then continue; fi
1490          cflags="$cflags_maybe $cflags"
1491        fi
1492
1493        # Any user CFLAGS, even an empty string, takes precendence
1494        if test "$test_CFLAGS" = set; then cflags=$CFLAGS; fi
1495
1496        # Any user CPPFLAGS, even an empty string, takes precendence
1497                               eval cppflags=\"\$${ccbase}${abi1}_cppflags\"
1498        test -n "$cppflags" || eval cppflags=\"\$${ccbase}${abi2}_cppflags\"
1499        if test "$test_CPPFLAGS" = set; then cppflags=$CPPFLAGS; fi
1500
1501        # --enable-profiling adds -p/-pg even to user-specified CFLAGS.
1502        # This is convenient, but it's perhaps a bit naughty to modify user
1503        # CFLAGS.
1504        case "$enable_profiling" in
1505          prof)       cflags="$cflags -p" ;;
1506          gprof)      cflags="$cflags -pg" ;;
1507          instrument) cflags="$cflags -finstrument-functions" ;;
1508        esac
1509
1510        GMP_PROG_CC_WORKS($cc $cflags $cppflags,,continue)
1511
1512        # If we're supposed to be using a "long long" for a limb, check that
1513        # it works.
1514                                  eval limb_chosen=\"\$limb$abi1\"
1515        test -n "$limb_chosen" || eval limb_chosen=\"\$limb$abi2\"
1516        if test "$limb_chosen" = longlong; then
1517          GMP_PROG_CC_WORKS_LONGLONG($cc $cflags $cppflags,,continue)
1518        fi
1519
1520        # The tests to perform on this $cc, if any
1521                               eval testlist=\"\$${ccbase}${abi1}_testlist\"
1522        test -n "$testlist" || eval testlist=\"\$${ccbase}${abi2}_testlist\"
1523        test -n "$testlist" || eval testlist=\"\$any${abi1}_testlist\"
1524        test -n "$testlist" || eval testlist=\"\$any${abi2}_testlist\"
1525
1526        testlist_pass=yes
1527        for tst in $testlist; do
1528          case $tst in
1529          gcc-arm-umodsi) GMP_GCC_ARM_UMODSI($cc,,testlist_pass=no) ;;
1530          gcc-mips-o32)   GMP_GCC_MIPS_O32($cc,,testlist_pass=no) ;;
1531          sizeof*)       GMP_C_TEST_SIZEOF($cc $cflags,$tst,,testlist_pass=no) ;;
1532          esac
1533          if test $testlist_pass = no; then break; fi
1534        done
1535
1536        if test $testlist_pass = yes; then
1537          found_compiler=yes
1538          break
1539        fi
1540      done
1541
1542      if test $found_compiler = yes; then break; fi
1543    done
1544
1545    if test $found_compiler = yes; then break; fi
1546  done
1547
1548  if test $found_compiler = yes; then break; fi
1549done
1550
1551
1552# If we recognised the CPU, as indicated by $path being set, then insist
1553# that we have a working compiler, either from our $cclist choices or from
1554# $CC.  We can't let AC_PROG_CC look around for a compiler because it might
1555# find one that we've rejected (for not supporting the modes our asm code
1556# demands, etc).
1557#
1558# If we didn't recognise the CPU (and this includes host_cpu=none), then
1559# fall through and let AC_PROG_CC look around for a compiler too.  This is
1560# mostly in the interests of following a standard autoconf setup, after all
1561# we've already tested cc and gcc adequately (hopefully).  As of autoconf
1562# 2.50 the only thing AC_PROG_CC really adds is a check for "cl" (Microsoft
1563# C on MS-DOS systems).
1564#
1565if test $found_compiler = no && test -n "$path"; then
1566  AC_MSG_ERROR([could not find a working compiler, see config.log for details])
1567fi
1568
1569
1570if test $found_compiler = yes; then
1571
1572  # If we're creating CFLAGS, then look for optional additions.  If the user
1573  # set CFLAGS then leave it alone.
1574  #
1575  if test "$test_CFLAGS" != set; then
1576                          eval optlist=\"\$${ccbase}${abi1}_cflags_optlist\"
1577    test -n "$optlist" || eval optlist=\"\$${ccbase}${abi2}_cflags_optlist\"
1578
1579    for opt in $optlist; do
1580                             eval optflags=\"\$${ccbase}${abi1}_cflags_${opt}\"
1581      test -n "$optflags" || eval optflags=\"\$${ccbase}${abi2}_cflags_${opt}\"
1582      test -n "$optflags" || eval optflags=\"\$${ccbase}_cflags_${opt}\"
1583
1584      for flag in $optflags; do
1585
1586	# ~ respresents a space in an option spec
1587        flag=`echo "$flag" | tr '~' ' '`
1588
1589        case $flag in
1590          -march=pentium4 | -march=k8)
1591            # For -march settings which enable SSE2 we exclude certain bad
1592            # gcc versions and we need an OS knowing how to save xmm regs.
1593            #
1594            # This is only for ABI=32, any 64-bit gcc is good and any OS
1595            # knowing x86_64 will know xmm.
1596            #
1597            # -march=k8 was only introduced in gcc 3.3, so we shouldn't need
1598            # the GMP_GCC_PENTIUM4_SSE2 check (for gcc 3.2 and prior).  But
1599            # it doesn't hurt to run it anyway, sharing code with the
1600            # pentium4 case.
1601            #
1602            if test "$abi" = 32; then
1603              GMP_GCC_PENTIUM4_SSE2($cc $cflags $cppflags,, continue)
1604              GMP_OS_X86_XMM($cc $cflags $cppflags,, continue)
1605            fi
1606            ;;
1607          -no-cpp-precomp)
1608            # special check, avoiding a warning
1609            GMP_GCC_NO_CPP_PRECOMP($ccbase,$cc,$cflags,
1610                                   [cflags="$cflags $flag"
1611                                   break],
1612                                   [continue])
1613            ;;
1614          -Wa,-m*)
1615            ;;
1616        esac
1617
1618        GMP_PROG_CC_WORKS($cc $cflags $cppflags $flag,
1619          [cflags="$cflags $flag"
1620          break])
1621      done
1622    done
1623  fi
1624
1625  ABI="$abi"
1626  CC="$cc"
1627  CFLAGS="$cflags"
1628  CPPFLAGS="$cppflags"
1629  if test $enable_gmpcompat = yes; then
1630    GMP_CC="#define __GMP_CC __MPIR_CC"
1631    GMP_CFLAGS="#define __GMP_CFLAGS __MPIR_CFLAGS"
1632  else
1633    GMP_CC="/* No __GMP_CC here as --enable-gmpcompat option not selected */"
1634    GMP_CFLAGS=""
1635  fi
1636
1637   AC_SUBST(GMP_CC)
1638   AC_SUBST(GMP_CFLAGS)
1639
1640  # Could easily have this in config.h too, if desired.
1641  ABI_nodots=`echo $ABI | sed 's/\./_/'`
1642  GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_ABI_$ABI_nodots')", POST)
1643
1644
1645  # GMP_LDFLAGS substitution, selected according to ABI.
1646  # These are needed on libmpir.la and libmp.la, but currently not on
1647  # convenience libraries like tune/libspeed.la or mpz/libmpz.la.
1648  #
1649                            eval GMP_LDFLAGS=\"\$${ccbase}${abi1}_ldflags\"
1650  test -n "$GMP_LDFLAGS" || eval GMP_LDFLAGS=\"\$${ccbase}${abi1}_ldflags\"
1651  AC_SUBST(GMP_LDFLAGS)
1652  AC_SUBST(LIBGMP_LDFLAGS)
1653  AC_SUBST(LIBGMPXX_LDFLAGS)
1654
1655  # extra_functions, selected according to ABI
1656                    eval tmp=\"\$extra_functions$abi1\"
1657  test -n "$tmp" || eval tmp=\"\$extra_functions$abi2\"
1658  extra_functions="$tmp"
1659
1660
1661  # Cycle counter, selected according to ABI.
1662  #
1663                    eval tmp=\"\$SPEED_CYCLECOUNTER_OBJ$abi1\"
1664  test -n "$tmp" || eval tmp=\"\$SPEED_CYCLECOUNTER_OBJ$abi2\"
1665  SPEED_CYCLECOUNTER_OBJ="$tmp"
1666                    eval tmp=\"\$cyclecounter_size$abi1\"
1667  test -n "$tmp" || eval tmp=\"\$cyclecounter_size$abi2\"
1668  cyclecounter_size="$tmp"
1669
1670  if test -n "$SPEED_CYCLECOUNTER_OBJ"; then
1671    AC_DEFINE_UNQUOTED(HAVE_SPEED_CYCLECOUNTER, $cyclecounter_size,
1672    [Tune directory speed_cyclecounter, undef=none, 1=32bits, 2=64bits)])
1673  fi
1674  AC_SUBST(SPEED_CYCLECOUNTER_OBJ)
1675
1676
1677  # Calling conventions checking, selected according to ABI.
1678  #
1679                    eval tmp=\"\$CALLING_CONVENTIONS_OBJS$abi1\"
1680  test -n "$tmp" || eval tmp=\"\$CALLING_CONVENTIONS_OBJS$abi2\"
1681  CALLING_CONVENTIONS_OBJS="$tmp"
1682
1683  if test -n "$CALLING_CONVENTIONS_OBJS"; then
1684    AC_DEFINE(HAVE_CALLING_CONVENTIONS,1,
1685    [Define to 1 if tests/libtests has calling conventions checking for the CPU])
1686  fi
1687  AC_SUBST(CALLING_CONVENTIONS_OBJS)
1688
1689fi
1690
1691
1692# If the user gave an MPN_PATH, use that verbatim, otherwise choose
1693# according to the ABI and add "generic".
1694#
1695if test -n "$MPN_PATH"; then
1696  path="$MPN_PATH"
1697else
1698                    eval tmp=\"\$path$abi1\"
1699  test -n "$tmp" || eval tmp=\"\$path$abi2\"
1700  path="$tmp generic"
1701fi
1702
1703
1704# Long long limb setup for mpir.h.
1705case $limb_chosen in
1706longlong) DEFN_LONG_LONG_LIMB="#define _LONG_LONG_LIMB 1"    ;;
1707*)        DEFN_LONG_LONG_LIMB="/* #undef _LONG_LONG_LIMB */" ;;
1708esac
1709AC_SUBST(DEFN_LONG_LONG_LIMB)
1710
1711AC_GNU_SOURCE
1712
1713# The C compiler and preprocessor, put into ANSI mode if possible.
1714AC_PROG_CC
1715AC_PROG_CC_STDC
1716AC_PROG_CPP
1717GMP_H_ANSI
1718
1719
1720# The C compiler on the build system, and associated tests.
1721GMP_PROG_CC_FOR_BUILD
1722GMP_PROG_CPP_FOR_BUILD
1723GMP_PROG_EXEEXT_FOR_BUILD
1724GMP_C_FOR_BUILD_ANSI
1725GMP_CHECK_LIBM_FOR_BUILD
1726
1727# How to assemble, used with CFLAGS etc, see mpn/Makeasm.am.
1728# Using the compiler is a lot easier than figuring out how to invoke the
1729# assembler directly.
1730#
1731test -n "$CCAS" || CCAS="$CC -c"
1732AC_SUBST(CCAS)
1733
1734# If the user provided its Yasm, check it seems functional
1735MPIR_AS=""
1736if test -z "$with_yasm"; then
1737  echo "Looking for a system-wide yasm..."
1738  MPIR_AS=`which yasm`
1739  if test $? -ne 0; then
1740    AC_MSG_ERROR([no system-wide yasm found])
1741  fi
1742else
1743  MPIR_AS="$with_yasm"
1744fi
1745echo "Checking yasm..."
1746if ! test -f "$MPIR_AS" || ! test -x "$MPIR_AS"; then
1747  AC_MSG_ERROR([$MPIR_AS does not seem functional])
1748fi
1749AC_SUBST(MPIR_AS)
1750
1751# The C++ compiler, if desired.
1752
1753test_CXXFLAGS=${CXXFLAGS+set}
1754
1755AC_PROG_CXX
1756
1757# Now actually check that the C++ compiler works if it is needed.
1758want_cxx=no
1759if test $enable_cxx != no; then
1760
1761  echo "CXXFLAGS chosen by autoconf: $CXXFLAGS" >&AC_FD_CC
1762  cxxflags_ac_prog_cxx=$CXXFLAGS
1763  cxxflags_list=ac_prog_cxx
1764
1765  # If the user didn't specify $CXXFLAGS, then try $CFLAGS, with -g removed
1766  # if AC_PROG_CXX thinks that doesn't work.  $CFLAGS stands a good chance
1767  # of working, eg. on a GNU system where CC=gcc and CXX=g++.
1768  #
1769  if test "$test_CXXFLAGS" != set; then
1770    cxxflags_cflags=$CFLAGS
1771    cxxflags_list="cflags $cxxflags_list"
1772    if test "$ac_prog_cxx_g" = no; then
1773      cxxflags_cflags=`echo "$cxxflags_cflags" | sed -e 's/ -g //' -e 's/^-g //' -e 's/ -g$//'`
1774    fi
1775  fi
1776
1777  # See if the C++ compiler works.  If the user specified CXXFLAGS then all
1778  # we're doing is checking whether AC_PROG_CXX succeeded, since it doesn't
1779  # give a fatal error, just leaves CXX set to a default g++.  If on the
1780  # other hand the user didn't specify CXXFLAGS then we get to try here our
1781  # $cxxflags_list alternatives.
1782  #
1783  # Automake includes $CPPFLAGS in a C++ compile, so we do the same here.
1784  #
1785  for cxxflags_choice in $cxxflags_list; do
1786    eval CXXFLAGS=\"\$cxxflags_$cxxflags_choice\"
1787    GMP_PROG_CXX_WORKS($CXX $CPPFLAGS $CXXFLAGS,
1788      [want_cxx=yes
1789      break])
1790  done
1791
1792  # If --enable-cxx=yes but a C++ compiler can't be found, then abort.
1793  if test $want_cxx = no && test $enable_cxx = yes; then
1794    AC_MSG_ERROR([C++ compiler not available, see config.log for details])
1795  fi
1796fi
1797
1798AM_CONDITIONAL(WANT_CXX, test $want_cxx = yes)
1799
1800if test -z "$MPN_PATH"; then
1801  path="$add_path $path"
1802fi
1803
1804# For a nail build, also look in "nails" subdirectories.
1805#
1806if test $GMP_NAIL_BITS != 0 && test -z "$MPN_PATH"; then
1807  new_path=
1808  for i in $path; do
1809    case $i in
1810    generic) new_path="$new_path $i" ;;
1811    *)       new_path="$new_path $i/nails $i" ;;
1812    esac
1813  done
1814  path=$new_path
1815fi
1816
1817
1818# Put all directories into CPUVEC_list so as to get a full set of
1819# CPUVEC_SETUP_$tmp_suffix defines into config.h, even if some of them are
1820# empty because mmx and/or sse2 had to be dropped.
1821# For MINGW64 we have have to hack this so as x86_64w gets turned into x86_64
1822for i in $fat_path; do
1823  GMP_FAT_SUFFIX(tmp_suffix, $i)
1824  CPUVEC_list="$CPUVEC_list CPUVEC_SETUP_$tmp_suffix"
1825done
1826
1827
1828# If there's any sse2 or mmx in the path, check whether the assembler
1829# supports it, and remove if not.
1830#
1831# We only need this in ABI=32, for ABI=64 on x86_64 we can assume a new
1832# enough assembler.
1833#
1834case $host in
1835  X86_PATTERN | X86_64_PATTERN)
1836    if test "$ABI" = 32; then
1837      case "$path $fat_path" in
1838        *mmx*)   GMP_ASM_X86_MMX( , [GMP_STRIP_PATH(*mmx*)]) ;;
1839      esac
1840      case "$path $fat_path" in
1841        *sse2*)  GMP_ASM_X86_SSE2( , [GMP_STRIP_PATH(sse2)]) ;;
1842      esac
1843    fi
1844    ;;
1845esac
1846
1847
1848cat >&AC_FD_CC <<EOF
1849Decided:
1850ABI=$ABI
1851CC=$CC
1852CFLAGS=$CFLAGS
1853CPPFLAGS=$CPPFLAGS
1854GMP_LDFLAGS=$GMP_LDFLAGS
1855CXX=$CXX
1856CXXFLAGS=$CXXFLAGS
1857path=$path
1858EOF
1859echo "using ABI=\"$ABI\""
1860echo "      CC=\"$CC\""
1861echo "      CFLAGS=\"$CFLAGS\""
1862echo "      CPPFLAGS=\"$CPPFLAGS\""
1863if test $want_cxx = yes; then
1864  echo "      CXX=\"$CXX\""
1865  echo "      CXXFLAGS=\"$CXXFLAGS\""
1866fi
1867echo "      MPN_PATH=\"$path\""
1868
1869
1870GMP_PROG_AR
1871GMP_PROG_NM
1872
1873case $host in
1874  # FIXME: On AIX 3 and 4, $libname.a is included in libtool
1875  # $library_names_spec, so libmpir.a becomes a symlink to libmpir.so, making
1876  # it impossible to build shared and static libraries simultaneously.
1877  # Disable shared libraries by default, but let the user override with
1878  # --enable-shared --disable-static.
1879  #
1880  # FIXME: This $libname.a problem looks like it might apply to *-*-amigaos*
1881  # and *-*-os2* too, but wait for someone to test this before worrying
1882  # about it.  If there is a problem then of course libtool is the right
1883  # place to fix it.
1884  #
1885  [*-*-aix[34]*])
1886    if test -z "$enable_shared"; then enable_shared=no; fi ;;
1887esac
1888
1889
1890# Enable various configuration flags and DLL on Windows
1891LT_INIT([win32-dll])
1892
1893# Configs for Windows DLLs.
1894
1895AC_SUBST(LIBGMP_DLL,0)
1896case $host in
1897  *-pc-msys|*-*-cygwin* | *-*-mingw*)
1898    # By default, build only static.
1899    if test -z "$enable_shared"; then
1900      enable_shared=no
1901    fi
1902    # Don't allow both static and DLL.
1903    if test "$enable_shared" != no && test "$enable_static" != no; then
1904      AC_MSG_ERROR([cannot build both static and DLL, since mpir.h is different for each.
1905Use "--disable-static --enable-shared" to build just a DLL.])
1906    fi
1907
1908    # "-no-undefined" is required when building a DLL, see documentation on
1909    # AC_LIBTOOL_WIN32_DLL.
1910    #
1911    # "-Wl,--export-all-symbols" is a bit of a hack, it gets all libmpir and
1912    # libmpirxx functions and variables exported.  This is what libtool did
1913    # in the past, and it's convenient for us in the test programs.
1914    #
1915    # Maybe it'd be prudent to check for --export-all-symbols before using
1916    # it, but it seems to have been in ld since at least 2000, and there's
1917    # not really any alternative we want to take up at the moment.
1918    #
1919    # "-Wl,output-def" is used to get a .def file for use by MS lib to make
1920    # a .lib import library, described in the manual.  libmpir-3.dll.def
1921    # corresponds to the libmp-3.dll.def generated by libtool (as a result
1922    # of -export-symbols on that library).
1923    #
1924    # Incidentally, libtool does generate an import library libmpir.dll.a,
1925    # but it's "ar" format and cannot be used by the MS linker.  There
1926    # doesn't seem to be any GNU tool for generating or converting to .lib.
1927    #
1928    # FIXME: The .def files produced by -Wl,output-def include isascii,
1929    # iscsym, iscsymf and toascii, apparently because mingw ctype.h doesn't
1930    # inline isascii (used in gmp).  It gives an extern inline for
1931    # __isascii, but for some reason not the plain isascii.
1932    #
1933    # LDFLAGS="$LDFLAGS -Wl,--enable-auto-import"  this is too general
1934    if test "$enable_shared" = yes; then
1935      GMP_LDFLAGS="$GMP_LDFLAGS -no-undefined -Wl,--export-all-symbols"
1936      LIBGMP_LDFLAGS="$LIBGMP_LDFLAGS -Wl,--output-def,.libs/libmpir-3.dll.def"
1937      LIBGMPXX_LDFLAGS="$LIBGMP_LDFLAGS -Wl,--output-def,.libs/libmpirxx-3.dll.def"
1938      LIBGMP_DLL=1
1939    fi
1940    ;;
1941esac
1942
1943# Generate an error here if attempting to build both shared and static when
1944# $libname.a is in $library_names_spec (as mentioned above), rather than
1945# wait for ar or ld to fail.
1946#
1947if test "$enable_shared" = yes && test "$enable_static" = yes; then
1948  case $library_names_spec in
1949    *libname.a*)
1950      AC_MSG_ERROR([cannot create both shared and static libraries on this system, --disable one of the two])
1951      ;;
1952  esac
1953fi
1954
1955AM_CONDITIONAL(ENABLE_STATIC, test "$enable_static" = yes)
1956AM_CONDITIONAL(ENABLE_SHARED, test "$enable_shared" = yes)
1957
1958
1959# Many of these library and header checks are for the benefit of
1960# supplementary programs.  libmpir doesn't use anything too weird.
1961
1962AC_HEADER_STDC
1963AC_HEADER_TIME
1964
1965# Reasons for testing:
1966#   float.h - not in SunOS bundled cc
1967#   langinfo.h - X/Open standard only, not in djgpp for instance
1968#   locale.h - old systems won't have this
1969#   nl_types.h - X/Open standard only, not in djgpp for instance
1970#       (usually langinfo.h gives nl_item etc, but not on netbsd 1.4.1)
1971#   sys/mman.h - not in Cray Unicos
1972#   sys/param.h - not in mingw
1973#   sys/processor.h - solaris specific, though also present in macos
1974#   sys/pstat.h - HPUX specific
1975#   sys/resource.h - not in mingw
1976#   sys/sysctl.h - not in mingw
1977#   sys/sysinfo.h - OSF specific
1978#   sys/systemcfg.h - AIX specific
1979#   sys/time.h - autoconf suggests testing, don't know anywhere without it
1980#   sys/times.h - not in mingw
1981#
1982# inttypes.h, stdint.h, unistd.h and sys/types.h are already in the autoconf
1983# default tests
1984#
1985AC_CHECK_HEADERS(fenv.h fcntl.h float.h langinfo.h locale.h nl_types.h sys/mman.h sys/param.h sys/processor.h sys/pstat.h sys/sysinfo.h sys/systemcfg.h sys/time.h sys/times.h)
1986
1987# On SunOS, sys/resource.h needs sys/time.h (for struct timeval)
1988AC_CHECK_HEADERS(sys/resource.h,,,
1989[#if TIME_WITH_SYS_TIME
1990# include <sys/time.h>
1991# include <time.h>
1992#else
1993# if HAVE_SYS_TIME_H
1994#  include <sys/time.h>
1995# else
1996#  include <time.h>
1997# endif
1998#endif])
1999
2000# On NetBSD and OpenBSD, sys/sysctl.h needs sys/param.h for various constants
2001AC_CHECK_HEADERS(sys/sysctl.h,,,
2002[#if HAVE_SYS_PARAM_H
2003# include <sys/param.h>
2004#endif])
2005
2006# Reasons for testing:
2007#   optarg - not declared in mingw
2008#   fgetc, fscanf, ungetc, vfprintf - not declared in SunOS 4
2009#   sys_errlist, sys_nerr - not declared in SunOS 4
2010#
2011# optarg should be in unistd.h and the rest in stdio.h, both of which are
2012# in the autoconf default includes.
2013#
2014# sys_errlist and sys_nerr are supposed to be in <errno.h> on SunOS according
2015# to the man page (but aren't), in glibc they're in stdio.h.
2016#
2017AC_CHECK_DECLS([fgetc, fscanf, optarg, ungetc, vfprintf])
2018AC_CHECK_DECLS([sys_errlist, sys_nerr], , ,
2019[#include <stdio.h>
2020#include <errno.h>])
2021
2022AC_TYPE_SIGNAL
2023
2024# Reasons for testing:
2025#   intmax_t       - C99
2026#   long double    - not in the HP bundled K&R cc
2027#   long long      - only in reasonably recent compilers
2028#   ptrdiff_t      - seems to be everywhere, maybe don't need to check this
2029#   quad_t         - BSD specific
2030#   uint_least32_t - C99
2031#
2032# the default includes are sufficient for all these types
2033#
2034AC_CHECK_TYPES([intmax_t, uintmax_t, long double, long long, ptrdiff_t, quad_t, uint_least32_t])
2035
2036AC_C_STRINGIZE
2037
2038# FIXME: Really want #ifndef __cplusplus around the #define volatile
2039# replacement autoconf gives, since volatile is always available in C++.
2040# But we don't use it in C++ currently.
2041AC_C_VOLATILE
2042
2043# AC_C_RESTRICT
2044
2045GMP_C_STDARG
2046GMP_C_ATTRIBUTE_CONST
2047GMP_C_ATTRIBUTE_MALLOC
2048GMP_C_ATTRIBUTE_MODE
2049GMP_C_ATTRIBUTE_NORETURN
2050
2051GMP_H_EXTERN_INLINE
2052
2053# from libtool
2054LT_LIB_M
2055AC_SUBST(LIBM)
2056
2057GMP_FUNC_ALLOCA
2058GMP_OPTION_ALLOCA
2059
2060GMP_H_HAVE_FILE
2061
2062AC_C_BIGENDIAN(
2063  [AC_DEFINE(HAVE_LIMB_BIG_ENDIAN, 1)
2064   GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_LIMB_BIG_ENDIAN')", POST)],
2065  [AC_DEFINE(HAVE_LIMB_LITTLE_ENDIAN, 1)
2066   GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_LIMB_LITTLE_ENDIAN')", POST)
2067  ], [:])
2068AH_VERBATIM([HAVE_LIMB],
2069[/* Define one of these to 1 for the endianness of `mp_limb_t'.
2070   If the endianness is not a simple big or little, or you don't know what
2071   it is, then leave both undefined. */
2072#undef HAVE_LIMB_BIG_ENDIAN
2073#undef HAVE_LIMB_LITTLE_ENDIAN])
2074
2075GMP_C_DOUBLE_FORMAT
2076
2077
2078# Reasons for testing:
2079#   alarm - not in mingw
2080#   attr_get - IRIX specific
2081#   clock_gettime - not in glibc 2.2.4, only very recent systems
2082#   cputime - not in glibc
2083#   getsysinfo - OSF specific
2084#   getrusage - not in mingw
2085#   gettimeofday - not in mingw
2086#   mmap - not in mingw, djgpp
2087#   nl_langinfo - X/Open standard only, not in djgpp for instance
2088#   obstack_vprintf - glibc specific
2089#   processor_info - solaris specific
2090#   pstat_getprocessor - HPUX specific (10.x and up)
2091#   raise - an ANSI-ism, though probably almost universal by now
2092#   read_real_time - AIX specific
2093#   strerror - not in SunOS
2094#   strnlen - glibc extension (some other systems too)
2095#   syssgi - IRIX specific
2096#   times - not in mingw
2097#
2098# clock_gettime is in librt on *-*-osf5.1.  We could look for it
2099# there, but that's not worth bothering with unless it has a decent
2100# resolution (in a quick test clock_getres said only 1 millisecond).
2101#
2102# AC_FUNC_STRNLEN is not used because we don't want the AC_LIBOBJ
2103# replacement setups it gives.  It detects a faulty strnlen on AIX, but
2104# missing out on that test is ok since our only use of strnlen is in
2105# __gmp_replacement_vsnprintf which is not required on AIX since it has a
2106# vsnprintf.
2107#
2108AC_CHECK_FUNCS(alarm attr_get clock clock_gettime cputime getpagesize getrusage gettimeofday getsysinfo localeconv memset mmap nl_langinfo obstack_vprintf popen processor_info pstat_getprocessor raise read_real_time syssgi strchr strerror strnlen strtol strtoul sysconf sysctl sysctlbyname times)
2109
2110# mingw returns OK on mprotect , but it's broken
2111#
2112case $host in
2113  *-pc-msys|*-*-mingw*)
2114    ;;
2115  *)
2116    AC_CHECK_FUNCS(mprotect)
2117esac
2118
2119GMP_FUNC_VSNPRINTF
2120GMP_FUNC_SSCANF_WRITABLE_INPUT
2121
2122# Reasons for checking:
2123#   pst_processor psp_iticksperclktick - not in hpux 9
2124#
2125AC_CHECK_MEMBER(struct pst_processor.psp_iticksperclktick,
2126                [AC_DEFINE(HAVE_PSP_ITICKSPERCLKTICK, 1,
2127[Define to 1 if <sys/pstat.h> `struct pst_processor' exists
2128and contains `psp_iticksperclktick'.])],,
2129                [#include <sys/pstat.h>])
2130
2131# C++ tests, when required
2132#
2133if test $enable_cxx = yes; then
2134  AC_LANG_PUSH(C++)
2135
2136  # Reasons for testing:
2137  #   <sstream> - not in g++ 2.95.2
2138  #   std::locale - not in g++ 2.95.4
2139  #
2140  AC_CHECK_HEADERS([sstream])
2141  AC_CHECK_TYPES([std::locale],,,[#include <locale>])
2142
2143  AC_LANG_POP(C++)
2144fi
2145
2146
2147# Pick the correct source files in $path and link them to mpn/.
2148# $gmp_mpn_functions lists all functions we need.
2149#
2150# The rule is to find a file with the function name and a .asm, .S,
2151# .s, or .c extension.  Certain multi-function files with special names
2152# can provide some functions too.  (mpn/Makefile.am passes
2153# -DOPERATION_<func> to get them to generate the right code.)
2154
2155# Note: $gmp_mpn_functions must have mod_1 before preinv_mod_1 so the former
2156#       can optionally provide the latter as an extra entrypoint.  Likewise
2157#       divrem_1 and preinv_divrem_1.
2158
2159gmp_mpn_functions_optional="umul udiv copyi copyd com_n neg_n
2160  and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n			\
2161  invert_limb sqr_diagonal lshift1 rshift1 lshift2 rshift2	\
2162  mul_2 mul_3 mul_4 store not karaadd karasub half double		\
2163  addmul_2 addmul_3 addmul_4 addmul_5 addmul_6 addmul_7 addmul_8	\
2164  addlsh1_n sublsh1_n rsh1add_n rsh1sub_n sumdiff_n lshiftc		\
2165  addlsh_n sublsh_n inclsh_n declsh_n nsumdiff_n"
2166
2167gmp_mpn_functions="$extra_functions					   \
2168  add add_1 add_n sub sub_1 sub_n mul_1 addmul_1 submul_1 lshift rshift    \
2169  addadd_n addsub_n subadd_n		\
2170  comb_tables divexact_1 divexact_by3c divexact_byff divexact_byfobm1 divisible_p divrem divrem_1 divrem_2       \
2171  divrem_euclidean_qr_1 divrem_euclidean_qr_2 divrem_euclidean_r_1	\
2172  divrem_hensel_qr_1 divrem_hensel_qr_1_1 divrem_hensel_qr_1_2		\
2173  divrem_hensel_r_1 divrem_hensel_rsh_qr_1 rsh_divrem_hensel_qr_1	\
2174  rsh_divrem_hensel_qr_1_1 rsh_divrem_hensel_qr_1_2			\
2175  add_err1_n add_err2_n sub_err1_n sub_err2_n				   \
2176  fib2_ui mod_1 mod_34lsub1 modexact_1c_odd preinv_divrem_1 preinv_mod_1 dump		   \
2177  gcd_subdiv_step gcdext_lehmer gcdext_1 hgcd matrix22_mul hgcd2            \
2178  hgcd2_jacobi hgcd_appr hgcd_jacobi hgcd_matrix hgcd_reduce hgcd_step \
2179  matrix22_mul1_inverse_vector \
2180  mod_1_1 mod_1_2 mod_1_3 tdiv_q mp_bases fib_table			\
2181  mulmid_basecase mulmid mulmid_n toom42_mulmid	mulmod_bexpp1 mulmod_2expm1 \
2182  mulmod_2expp1_basecase mul_fft \
2183  mul mul_n mul_basecase sqr_basecase random random2 	   \
2184  pow_1 powlo powm binvert \
2185  urandomb urandomm randomb rrandom invert \
2186  rootrem sizeinbase sqrtrem get_str set_str scan0 scan1 popcount hamdist cmp perfect_square_p \
2187  bdivmod gcd gcd_1 gcdext tdiv_qr jacobi_base jacobi jacobi_2 get_d  \
2188  mullow_n mulhigh_n mullow_n_basecase mullow_basecase \
2189  redc_1 redc_2 redc_n \
2190  sb_divappr_q toom3_mul toom3_mul_n toom4_mul toom4_mul_n \
2191  dc_div_q dc_divappr_q sb_div_q sb_div_qr dc_div_qr dc_div_qr_n inv_divappr_q_n \
2192  inv_divappr_q inv_div_q inv_div_qr inv_div_qr_n rootrem_basecase \
2193  toom_eval_dgr3_pm1 toom_eval_dgr3_pm2 toom_eval_pm1 toom_eval_pm2 \
2194  toom_eval_pm2exp toom_eval_pm2rexp toom_interpolate_16pts \
2195  toom8_sqr_n toom8h_mul toom_couple_handling sb_bdiv_q sb_bdiv_qr \
2196  dc_bdiv_q_n dc_bdiv_q dc_bdiv_qr dc_bdiv_qr_n divexact zero $gmp_mpn_functions_optional"
2197
2198# should be able to remove the mulfunc below
2199define(GMP_MULFUNC_CHOICES,
2200[# functions that can be provided by multi-function files
2201tmp_mulfunc=
2202case $tmp_fn in
2203  and_n|andn_n|nand_n | ior_n|iorn_n|nior_n | xor_n|xnor_n)
2204                     tmp_mulfunc="logops_n"  ;;
2205esac
2206])
2207
2208# the list of all object files used by mpn/Makefile.in and the
2209# top-level Makefile.in, respectively
2210mpn_objects=
2211mpn_objs_in_libgmp=
2212
2213# links from the sources, to be removed by "make distclean"
2214gmp_srclinks=
2215
2216
2217# mpn_relative_top_srcdir is $top_srcdir, but for use from within the mpn
2218# build directory.  If $srcdir is relative then we use a relative path too,
2219# so the two trees can be moved together.
2220case $srcdir in
2221  [[\\/]* | ?:[\\/]*])  # absolute, as per autoconf
2222    mpn_relative_top_srcdir=$srcdir ;;
2223  *)                    # relative
2224    mpn_relative_top_srcdir=../$srcdir ;;
2225esac
2226
2227
2228define(MPN_SUFFIXES,[as asm S s c])
2229
2230
2231dnl  Usage: GMP_FILE_TO_FUNCTION_BASE(func,file)
2232dnl
2233dnl  Set $func to the function base name for $file, eg. dive_1 gives
2234dnl  divexact_1.
2235dnl
2236define(GMP_FILE_TO_FUNCTION,
2237[case $$2 in
2238  *)         	$1=$$2 ;;
2239esac
2240])
2241
2242# Fat binary setups.
2243#
2244# We proceed through each $fat_path directory, and look for $fat_function
2245# routines there.  Those found are incorporated in the build by generating a
2246# little mpn/<foo>.asm or mpn/<foo>.c file in the build directory, with
2247# suitable function renaming, and adding that to $mpn_objects (the same as a
2248# normal mpn file).
2249#
2250# fat.h is generated with macros to let internal calls to each $fat_function
2251# go directly through __gmpn_cpuvec, plus macros and declarations helping to
2252# setup that structure, on a per-directory basis ready for
2253# mpn/<cpu>/fat/fat.c.
2254#
2255# fat.h includes thesholds listed in $fat_thresholds, extracted from
2256# gmp-mparam.h in each directory.  An overall maximum for each threshold is
2257# established, for use in making fixed size arrays of temporary space.
2258# (Eg. MUL_TOOM3_THRESHOLD_LIMIT used by mpn/generic/mul.c.)
2259#
2260# It'd be possible to do some of this manually, but when there's more than a
2261# few functions and a few directories it becomes very tedious, and very
2262# prone to having some routine accidentally omitted.  On that basis it seems
2263# best to automate as much as possible, even if the code to do so is a bit
2264# ugly.
2265#
2266
2267
2268if test -n "$fat_path"; then
2269  if test "$ABI" = 64; then
2270    fat_path="$fat_path_64"
2271  fi
2272
2273  # Usually the mpn build directory is created with mpn/Makefile
2274  # instantiation, but we want to write to it sooner.
2275  mkdir mpn 2>/dev/null
2276
2277  echo "/* fat.h - setups for fat binaries." >fat.h
2278  echo "   Generated by configure - DO NOT EDIT.  */" >>fat.h
2279
2280  AC_DEFINE(WANT_FAT_BINARY, 1, [Define to 1 when building a fat binary.])
2281  GMP_DEFINE(WANT_FAT_BINARY, yes)
2282
2283  # Don't want normal copies of fat functions
2284  for tmp_fn in $fat_functions; do
2285    GMP_REMOVE_FROM_LIST(gmp_mpn_functions, $tmp_fn)
2286    GMP_REMOVE_FROM_LIST(gmp_mpn_functions_optional, $tmp_fn)
2287  done
2288
2289  for tmp_fn in $fat_functions; do
2290    GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2291    echo "
2292#ifndef OPERATION_$tmp_fn
2293#undef  mpn_$tmp_fbase
2294#define mpn_$tmp_fbase  (*__gmpn_cpuvec.$tmp_fbase)
2295#endif
2296DECL_$tmp_fbase (__MPN(${tmp_fbase}_init));" >>fat.h
2297    # encourage various macros to use fat functions
2298    AC_DEFINE_UNQUOTED(HAVE_NATIVE_$tmp_fbase)
2299  done
2300
2301  echo "" >>fat.h
2302  echo "/* variable thresholds */" >>fat.h
2303  for tmp_tn in $fat_thresholds; do
2304    echo "#undef  $tmp_tn" >>fat.h
2305    echo "#define $tmp_tn  CPUVEC_THRESHOLD (`echo $tmp_tn | tr '[A-Z]' '[a-z]'`)" >>fat.h
2306  done
2307
2308  echo "
2309/* Copy all fields into __gmpn_cpuvec.
2310   memcpy is not used because it might operate byte-wise (depending on its
2311   implemenation), and we need the function pointer writes to be atomic.
2312   "volatile" discourages the compiler from trying to optimize this.  */
2313#define CPUVEC_INSTALL(vec) \\
2314  do { \\
2315    volatile struct cpuvec_t *p = &__gmpn_cpuvec; \\" >>fat.h
2316  for tmp_fn in $fat_functions; do
2317    GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2318    echo "    p->$tmp_fbase = vec.$tmp_fbase; \\" >>fat.h
2319  done
2320  for tmp_tn in $fat_thresholds; do
2321    tmp_field_name=`echo $tmp_tn | tr '[[A-Z]]' '[[a-z]]'`
2322    echo "    p->$tmp_field_name = vec.$tmp_field_name; \\" >>fat.h
2323  done
2324  echo "  } while (0)" >>fat.h
2325
2326  echo "
2327/* A helper to check all fields are filled. */
2328#define ASSERT_CPUVEC(vec) \\
2329  do { \\" >>fat.h
2330  for tmp_fn in $fat_functions; do
2331    GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2332    echo "    ASSERT (vec.$tmp_fbase != NULL); \\" >>fat.h
2333  done
2334  for tmp_tn in $fat_thresholds; do
2335    tmp_field_name=`echo $tmp_tn | tr '[[A-Z]]' '[[a-z]]'`
2336    echo "    ASSERT (vec.$tmp_field_name != 0); \\" >>fat.h
2337  done
2338  echo "  } while (0)" >>fat.h
2339
2340  echo "
2341/* Call ITERATE(field) for each fat threshold field. */
2342#define ITERATE_FAT_THRESHOLDS() \\
2343  do { \\" >>fat.h
2344  for tmp_tn in $fat_thresholds; do
2345    tmp_field_name=`echo $tmp_tn | tr '[[A-Z]]' '[[a-z]]'`
2346    echo "    ITERATE ($tmp_tn, $tmp_field_name); \\" >>fat.h
2347  done
2348  echo "  } while (0)" >>fat.h
2349
2350  for tmp_dir in $fat_path; do
2351    CPUVEC_SETUP=
2352    THRESH_ASM_SETUP=
2353    echo "" >>fat.h
2354    GMP_FAT_SUFFIX(tmp_suffix, $tmp_dir)
2355
2356    # In order to keep names unique on a DOS 8.3 filesystem, use a prefix
2357    # (rather than a suffix) for the generated file names, and abbreviate.
2358    case $tmp_suffix in
2359      pentium)       tmp_prefix=p   ;;
2360      pentium_mmx)   tmp_prefix=pm  ;;
2361      p6_mmx)        tmp_prefix=p2  ;;
2362      p6_p3mmx)      tmp_prefix=p3  ;;
2363      pentium4)      tmp_prefix=p4  ;;
2364      pentium4_mmx)  tmp_prefix=p4m ;;
2365      pentium4_sse2) tmp_prefix=p4s ;;
2366      k6_mmx)        tmp_prefix=k6m ;;
2367      k6_k62mmx)     tmp_prefix=k62 ;;
2368      k7_mmx)        tmp_prefix=k7m ;;
2369      *)             tmp_prefix=$tmp_suffix ;;
2370    esac
2371
2372    # Extract desired thresholds from gmp-mparam.h file in this directory,
2373    # if prsent.
2374    tmp_mparam=$srcdir/mpn/$tmp_dir/gmp-mparam.h
2375    if test -f $tmp_mparam; then
2376      for tmp_tn in $fat_thresholds; do
2377        tmp_thresh=`sed -n "s/^#define $tmp_tn[ 	]*\\([0-9][0-9]*\\).*$/\\1/p" $tmp_mparam`
2378        if test -n "$tmp_thresh"; then
2379          THRESH_ASM_SETUP=["${THRESH_ASM_SETUP}define($tmp_tn,$tmp_thresh)
2380"]
2381          CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.`echo $tmp_tn | tr '[[A-Z]]' '[[a-z]]'` = $tmp_thresh; \\
2382"
2383          eval tmp_limit=\$${tmp_tn}_LIMIT
2384          if test -z "$tmp_limit"; then
2385            tmp_limit=0
2386          fi
2387          if test $tmp_thresh -gt $tmp_limit; then
2388            eval ${tmp_tn}_LIMIT=$tmp_thresh
2389          fi
2390        fi
2391      done
2392    fi
2393
2394    for tmp_fn in $fat_functions; do
2395      GMP_MULFUNC_CHOICES
2396
2397      for tmp_base in $tmp_fn $tmp_mulfunc; do
2398        for tmp_ext in MPN_SUFFIXES; do
2399          tmp_file=$srcdir/mpn/$tmp_dir/$tmp_base.$tmp_ext
2400          if test -f $tmp_file; then
2401
2402            mpn_objects="$mpn_objects ${tmp_prefix}_$tmp_fn.lo"
2403            mpn_objs_in_libgmp="$mpn_objs_in_libgmp mpn/${tmp_prefix}_$tmp_fn.lo"
2404
2405            GMP_FILE_TO_FUNCTION(tmp_fbase,tmp_fn)
2406
2407            # carry-in variant, eg. divrem_1c or modexact_1c_odd
2408            case $tmp_fbase in
2409              *_1*) tmp_fbasec=`echo $tmp_fbase | sed 's/_1/_1c/'` ;;
2410              *)    tmp_fbasec=${tmp_fbase}c ;;
2411            esac
2412
2413            # Create a little file doing an include from srcdir.  The
2414            # OPERATION and renamings aren't all needed all the time, but
2415            # they don't hurt if unused.
2416            #
2417            # FIXME: Should generate these via config.status commands.
2418            # Would need them all in one AC_CONFIG_COMMANDS though, since
2419            # that macro doesn't accept a set of separate commands generated
2420            # by shell code.
2421            #
2422	    gmp_srclinks="$gmp_srclinks mpn/${tmp_prefix}_$tmp_fn.$tmp_ext"
2423            case $tmp_ext in
2424              as)
2425                echo [";  mpn_$tmp_fbase - from $tmp_dir directory for fat binary.
2426;  Generated by configure - DO NOT EDIT.
2427
2428%define OPERATION_$tmp_fn
2429%define suffix $tmp_suffix
2430
2431%include \"$mpn_relative_top_srcdir/mpn/$tmp_dir/$tmp_base.as\"
2432"] >mpn/${tmp_prefix}_$tmp_fn.as
2433                ;;
2434              asm)
2435                # hide the d-n-l from autoconf's error checking
2436                tmp_d_n_l=d""nl
2437                echo ["$tmp_d_n_l  mpn_$tmp_fbase - from $tmp_dir directory for fat binary.
2438$tmp_d_n_l  Generated by configure - DO NOT EDIT.
2439$tmp_d_n_l  This line is to help MINGW64
2440
2441define(OPERATION_$tmp_fn)
2442define(__gmpn_$tmp_fbase, __gmpn_${tmp_fbase}_$tmp_suffix)
2443define(__gmpn_$tmp_fbasec,__gmpn_${tmp_fbasec}_${tmp_suffix})
2444define(__gmpn_preinv_${tmp_fbase},__gmpn_preinv_${tmp_fbase}_${tmp_suffix})
2445
2446$tmp_d_n_l  For k6 and k7 gcd_1 calling their corresponding mpn_modexact_1_odd
2447ifdef(\`__gmpn_modexact_1_odd',,
2448\`define(__gmpn_modexact_1_odd,__gmpn_modexact_1_odd_${tmp_suffix})')
2449
2450$THRESH_ASM_SETUP
2451include][($mpn_relative_top_srcdir/mpn/$tmp_dir/$tmp_base.asm)
2452"] >mpn/${tmp_prefix}_$tmp_fn.asm
2453                ;;
2454              c)
2455
2456                echo ["/* mpn_$tmp_fbase - from $tmp_dir directory for fat binary.
2457   Generated by configure - DO NOT EDIT. */
2458
2459#define OPERATION_$tmp_fn 1
2460#define __gmpn_$tmp_fbase           __gmpn_${tmp_fbase}_$tmp_suffix
2461#define __gmpn_$tmp_fbasec          __gmpn_${tmp_fbasec}_${tmp_suffix}
2462#define __gmpn_preinv_${tmp_fbase}  __gmpn_preinv_${tmp_fbase}_${tmp_suffix}
2463
2464#include \"$mpn_relative_top_srcdir/mpn/$tmp_dir/$tmp_base.c\"
2465"] >mpn/${tmp_prefix}_$tmp_fn.c
2466                ;;
2467            esac
2468
2469            # Prototype, and append to CPUVEC_SETUP for this directory.
2470            echo "DECL_$tmp_fbase (__gmpn_${tmp_fbase}_$tmp_suffix);" >>fat.h
2471            CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.$tmp_fbase = __gmpn_${tmp_fbase}_${tmp_suffix}; \\
2472"
2473            # Ditto for any preinv variant (preinv_divrem_1, preinv_mod_1).
2474            if grep "^PROLOGUE(mpn_preinv_$tmp_fn)\|GLOBAL_FUNC mpn_preinv_$tmp_fn" $tmp_file >/dev/null; then
2475              echo "DECL_preinv_$tmp_fbase (__gmpn_preinv_${tmp_fbase}_$tmp_suffix);" >>fat.h
2476              CPUVEC_SETUP="$CPUVEC_SETUP    decided_cpuvec.preinv_$tmp_fbase = __gmpn_preinv_${tmp_fbase}_${tmp_suffix}; \\
2477"
2478            fi
2479          fi
2480        done
2481      done
2482    done
2483
2484    # Emit CPUVEC_SETUP for this directory
2485    echo "" >>fat.h
2486    echo "#define CPUVEC_SETUP_$tmp_suffix \\" >>fat.h
2487    echo "  do { \\" >>fat.h
2488    echo "$CPUVEC_SETUP  } while (0)" >>fat.h
2489  done
2490
2491  # Emit threshold limits
2492  echo "" >>fat.h
2493  for tmp_tn in $fat_thresholds; do
2494    eval tmp_limit=\$${tmp_tn}_LIMIT
2495    echo "#define ${tmp_tn}_LIMIT  $tmp_limit" >>fat.h
2496  done
2497fi
2498
2499
2500# Normal binary setups.
2501#
2502
2503for tmp_ext in MPN_SUFFIXES; do
2504  eval found_$tmp_ext=no
2505done
2506
2507for tmp_fn in $gmp_mpn_functions; do
2508  for tmp_ext in MPN_SUFFIXES; do
2509    test "$no_create" = yes || rm -f mpn/$tmp_fn.$tmp_ext
2510  done
2511
2512  # mpn_preinv_divrem_1 might have been provided by divrem_1.asm, likewise
2513  # mpn_preinv_mod_1 by mod_1.asm.
2514  case $tmp_fn in
2515  preinv_divrem_1)
2516    if test "$HAVE_NATIVE_mpn_preinv_divrem_1" = yes; then continue; fi ;;
2517  preinv_mod_1)
2518    if test "$HAVE_NATIVE_mpn_preinv_mod_1" = yes; then continue; fi ;;
2519  esac
2520
2521  GMP_MULFUNC_CHOICES
2522
2523  found=no
2524  for tmp_dir in $path; do
2525    for tmp_base in $tmp_fn $tmp_mulfunc; do
2526      for tmp_ext in MPN_SUFFIXES; do
2527        tmp_file=$srcdir/mpn/$tmp_dir/$tmp_base.$tmp_ext
2528        if test -f $tmp_file; then
2529
2530          # For a nails build, check if the file supports our nail bits.
2531          # Generic code always supports all nails.
2532          #
2533          # FIXME: When a multi-function file is selected to provide one of
2534          # the nails-neutral routines, like logops_n for and_n, the
2535          # PROLOGUE grepping will create HAVE_NATIVE_mpn_<foo> defines for
2536          # all functions in that file, even if they haven't all been
2537          # nailified.  Not sure what to do about this, it's only really a
2538          # problem for logops_n, and it's not too terrible to insist those
2539          # get nailified always.
2540          #
2541          if test $GMP_NAIL_BITS != 0 && test $tmp_dir != generic; then
2542            case $tmp_fn in
2543              and_n | ior_n | xor_n | andn_n | \
2544              copyi | copyd | \
2545              popcount | hamdist | \
2546              udiv | udiv_w_sdiv | umul | \
2547              cntlz | invert_limb)
2548                # these operations are either unaffected by nails or defined
2549                # to operate on full limbs
2550                ;;
2551              *)
2552                nails=[`sed -n 's/^[ 	]*NAILS_SUPPORT(\(.*\))/\1/p' $tmp_file `]
2553                for n in $nails; do
2554                  case $n in
2555                  *-*)
2556                    n_start=`echo "$n" | sed -n 's/\(.*\)-.*/\1/p'`
2557                    n_end=`echo "$n" | sed -n 's/.*-\(.*\)/\1/p'`
2558                    ;;
2559                  *)
2560                    n_start=$n
2561                    n_end=$n
2562                    ;;
2563                  esac
2564                  if test $GMP_NAIL_BITS -ge $n_start && test $GMP_NAIL_BITS -le $n_end; then
2565                    found=yes
2566                    break
2567                  fi
2568                done
2569                if test $found != yes; then
2570                  continue
2571                fi
2572                ;;
2573            esac
2574          fi
2575
2576          found=yes
2577          eval found_$tmp_ext=yes
2578
2579          if test $tmp_ext = c; then
2580            tmp_u='$U'
2581          else
2582            tmp_u=
2583          fi
2584
2585	  mpn_objects="$mpn_objects $tmp_fn$tmp_u.lo"
2586          mpn_objs_in_libgmp="$mpn_objs_in_libgmp mpn/$tmp_fn$tmp_u.lo"
2587          AC_CONFIG_LINKS(mpn/$tmp_fn.$tmp_ext:mpn/$tmp_dir/$tmp_base.$tmp_ext)
2588          gmp_srclinks="$gmp_srclinks mpn/$tmp_fn.$tmp_ext"
2589
2590          # Duplicate AC_DEFINEs are harmless, so it doesn't matter
2591          # that multi-function files get grepped here repeatedly.
2592          # The PROLOGUE pattern excludes the optional second parameter.
2593          gmp_ep=[`
2594            sed -n 's/^[ 	]*MULFUNC_PROLOGUE(\(.*\))/\1/p' $tmp_file ;
2595            sed -n 's/^[ 	]*PROLOGUE(\([^,]*\).*)/\1/p' $tmp_file ;
2596            sed -n 's/^;[ 	]*PROLOGUE(\([^,]*\).*)/\1/p' $tmp_file ;
2597            sed -n 's/[^G]*GLOBAL_FUNC[[:space:]]*\(.*\)/\1/p' $tmp_file ;
2598          `]
2599          for gmp_tmp in $gmp_ep; do
2600            AC_DEFINE_UNQUOTED(HAVE_NATIVE_$gmp_tmp)
2601            eval HAVE_NATIVE_$gmp_tmp=yes
2602          done
2603
2604          case $tmp_fn in
2605          sqr_basecase) sqr_basecase_source=$tmp_file ;;
2606          esac
2607
2608          break
2609        fi
2610      done
2611      if test $found = yes; then break ; fi
2612    done
2613    if test $found = yes; then break ; fi
2614  done
2615
2616  if test $found = no; then
2617    for tmp_optional in $gmp_mpn_functions_optional; do
2618      if test $tmp_optional = $tmp_fn; then
2619        found=yes
2620      fi
2621    done
2622    if test $found = no; then
2623      AC_MSG_ERROR([no version of $tmp_fn found in path: $path])
2624    fi
2625  fi
2626done
2627
2628# For mingw64 rename all *.asm files to *.as files so we then will use yasm
2629# cant move them yet as the mpn directory is not created until the end.
2630# Apart from defining old_gmp_srclinks (and we could do without it...),
2631# what follows is not strictly needed and just make gmp_srclinks more
2632# consistent.
2633case $host in
2634  *-pc-msys|*-w64-mingw*|*-*-cygwin*)
2635    if test "$ABI" = "64"; then
2636      old_gmp_srclinks=$gmp_srclinks
2637      gmp_srclinks=
2638      for jay in $old_gmp_srclinks; do
2639        jayext=`echo "$jay" | awk -F . '{print $NF}'`
2640        #jayext=`/bin/echo "${jay#*.}"`
2641        #jayext=`echo "$jay" | sed -n 's/.*\.//'`
2642        base=`echo "${jay%.*}"`
2643        name=`basename $base`
2644        if test "$jayext" = "asm" && test "$name" != "fat_entry"; then
2645          gmp_srclinks="$gmp_srclinks $base.as"
2646        else
2647          gmp_srclinks="$gmp_srclinks $jay"
2648        fi
2649      done
2650    fi
2651  ;;
2652esac
2653
2654# All cycle counters are .asm files currently
2655if test -n "$SPEED_CYCLECOUNTER_OBJ"; then
2656  found_asm=yes
2657fi
2658
2659dnl  The following list only needs to have templates for those defines which
2660dnl  are going to be tested by the code, there's no need to have every
2661dnl  possible mpn routine.
2662
2663AH_VERBATIM([HAVE_NATIVE],
2664[/* Define to 1 each of the following for which a native (ie. CPU specific)
2665    implementation of the corresponding routine exists.  */
2666#undef HAVE_NATIVE_mpn_add_n
2667#undef HAVE_NATIVE_mpn_add_nc
2668#undef HAVE_NATIVE_mpn_addadd_n
2669#undef HAVE_NATIVE_mpn_addlsh1_n
2670#undef HAVE_NATIVE_mpn_addlsh_n
2671#undef HAVE_NATIVE_mpn_addlsh_nc
2672#undef HAVE_NATIVE_mpn_addmul_1c
2673#undef HAVE_NATIVE_mpn_addmul_2
2674#undef HAVE_NATIVE_mpn_addmul_3
2675#undef HAVE_NATIVE_mpn_addmul_4
2676#undef HAVE_NATIVE_mpn_addmul_5
2677#undef HAVE_NATIVE_mpn_addmul_6
2678#undef HAVE_NATIVE_mpn_addmul_7
2679#undef HAVE_NATIVE_mpn_addmul_8
2680#undef HAVE_NATIVE_mpn_addsub_n
2681#undef HAVE_NATIVE_mpn_sumdiff_n
2682#undef HAVE_NATIVE_mpn_nsumdiff_n
2683#undef HAVE_NATIVE_mpn_and_n
2684#undef HAVE_NATIVE_mpn_andn_n
2685#undef HAVE_NATIVE_mpn_com_n
2686#undef HAVE_NATIVE_mpn_not
2687#undef HAVE_NATIVE_mpn_copyd
2688#undef HAVE_NATIVE_mpn_copyi
2689#undef HAVE_NATIVE_mpn_declsh_n
2690#undef HAVE_NATIVE_mpn_divexact_1
2691#undef HAVE_NATIVE_mpn_divrem_euclidean_qr_1
2692#undef HAVE_NATIVE_mpn_divrem_hensel_qr_1
2693#undef HAVE_NATIVE_mpn_divrem_hensel_qr_1_1
2694#undef HAVE_NATIVE_mpn_divrem_hensel_qr_1_2
2695#undef HAVE_NATIVE_mpn_divrem_hensel_r_1
2696#undef HAVE_NATIVE_mpn_divrem_hensel_rsh_qr_1
2697#undef HAVE_NATIVE_mpn_rsh_divrem_hensel_qr_1
2698#undef HAVE_NATIVE_mpn_rsh_divrem_hensel_qr_1_1
2699#undef HAVE_NATIVE_mpn_rsh_divrem_hensel_qr_1_2
2700#undef HAVE_NATIVE_mpn_divrem_euclidean_qr_2
2701#undef HAVE_NATIVE_mpn_divrem_euclidean_r_1
2702#undef HAVE_NATIVE_mpn_divrem_1
2703#undef HAVE_NATIVE_mpn_divrem_1c
2704#undef HAVE_NATIVE_mpn_divrem_2
2705#undef HAVE_NATIVE_mpn_double
2706#undef HAVE_NATIVE_mpn_gcd_1
2707#undef HAVE_NATIVE_mpn_half
2708#undef HAVE_NATIVE_mpn_inclsh_n
2709#undef HAVE_NATIVE_mpn_invert_limb
2710#undef HAVE_NATIVE_mpn_ior_n
2711#undef HAVE_NATIVE_mpn_iorn_n
2712#undef HAVE_NATIVE_mpn_karaadd
2713#undef HAVE_NATIVE_mpn_karasub
2714#undef HAVE_NATIVE_mpn_lshift1
2715#undef HAVE_NATIVE_mpn_lshift2
2716#undef HAVE_NATIVE_mpn_lshiftc
2717#undef HAVE_NATIVE_mpn_mod_1
2718#undef HAVE_NATIVE_mpn_mod_1_1
2719#undef HAVE_NATIVE_mpn_mod_1_2
2720#undef HAVE_NATIVE_mpn_mod_1_3
2721#undef HAVE_NATIVE_mpn_mod_1c
2722#undef HAVE_NATIVE_mpn_modexact_1_odd
2723#undef HAVE_NATIVE_mpn_modexact_1c_odd
2724#undef HAVE_NATIVE_mpn_mul_1c
2725#undef HAVE_NATIVE_mpn_mul_2
2726#undef HAVE_NATIVE_mpn_mul_3
2727#undef HAVE_NATIVE_mpn_mul_4
2728#undef HAVE_NATIVE_mpn_mul_basecase
2729#undef HAVE_NATIVE_mpn_nand_n
2730#undef HAVE_NATIVE_mpn_neg_n
2731#undef HAVE_NATIVE_mpn_nior_n
2732#undef HAVE_NATIVE_mpn_preinv_divrem_1
2733#undef HAVE_NATIVE_mpn_preinv_mod_1
2734#undef HAVE_NATIVE_mpn_redc_1
2735#undef HAVE_NATIVE_mpn_redc_2
2736#undef HAVE_NATIVE_mpn_rsh1add_n
2737#undef HAVE_NATIVE_mpn_rsh1sub_n
2738#undef HAVE_NATIVE_mpn_rshift1
2739#undef HAVE_NATIVE_mpn_rshift2
2740#undef HAVE_NATIVE_mpn_sqr_basecase
2741#undef HAVE_NATIVE_mpn_sqr_diagonal
2742#undef HAVE_NATIVE_mpn_store
2743#undef HAVE_NATIVE_mpn_sub_n
2744#undef HAVE_NATIVE_mpn_sub_nc
2745#undef HAVE_NATIVE_mpn_subadd_n
2746#undef HAVE_NATIVE_mpn_sublsh1_n
2747#undef HAVE_NATIVE_mpn_sublsh_n
2748#undef HAVE_NATIVE_mpn_sublsh_nc
2749#undef HAVE_NATIVE_mpn_submul_1c
2750#undef HAVE_NATIVE_mpn_umul_ppmm
2751#undef HAVE_NATIVE_mpn_umul_ppmm_r
2752#undef HAVE_NATIVE_mpn_udiv_qrnnd
2753#undef HAVE_NATIVE_mpn_udiv_qrnnd_r
2754#undef HAVE_NATIVE_mpn_xor_n
2755#undef HAVE_NATIVE_mpn_xnor_n])
2756
2757
2758# Don't demand an m4 unless it's actually needed.
2759if test $found_asm = yes; then
2760  GMP_PROG_M4
2761  GMP_M4_M4WRAP_SPURIOUS
2762else
2763  M4=m4-not-needed
2764fi
2765
2766# Only do the GMP_ASM checks if there's a .S or .asm wanting them.
2767if test $found_asm = no && test $found_S = no; then
2768  gmp_asm_syntax_testing=no
2769fi
2770
2771if test "$gmp_asm_syntax_testing" != no; then
2772  GMP_ASM_TEXT
2773  GMP_ASM_DATA
2774  GMP_ASM_LABEL_SUFFIX
2775  GMP_ASM_GLOBL
2776  GMP_ASM_GLOBL_ATTR
2777  GMP_ASM_UNDERSCORE
2778  GMP_ASM_RODATA
2779  GMP_ASM_TYPE
2780  GMP_ASM_SIZE
2781  GMP_ASM_LSYM_PREFIX
2782  GMP_ASM_W32
2783  GMP_ASM_ALIGN_LOG
2784  case $host in
2785    IA64_PATTERN)
2786      GMP_ASM_IA64_ALIGN_OK
2787      ;;
2788    [powerpc*-*-* | power[3-9]-*-*])
2789      GMP_ASM_POWERPC_PIC_ALWAYS
2790      GMP_ASM_POWERPC_R_REGISTERS
2791      GMP_INCLUDE_MPN(powerpc32/powerpc-defs.m4)
2792      case $host in
2793        *-*-aix*)
2794	  case $ABI in
2795	    64 | aix64)  GMP_INCLUDE_MPN(powerpc64/aix.m4) ;;
2796            *)           GMP_INCLUDE_MPN(powerpc32/aix.m4) ;;
2797          esac
2798          ;;
2799        *-*-linux* | *-*-*bsd*)
2800	  case $ABI in
2801	    mode64)      GMP_INCLUDE_MPN(powerpc64/elf.m4) ;;
2802	    mode32 | 32) GMP_INCLUDE_MPN(powerpc32/elf.m4) ;;
2803          esac
2804          ;;
2805        *-*-darwin*)
2806	  case $ABI in
2807	    mode64)      GMP_INCLUDE_MPN(powerpc64/darwin.m4) ;;
2808	    mode32 | 32) GMP_INCLUDE_MPN(powerpc32/darwin.m4) ;;
2809          esac
2810          ;;
2811        *)
2812	  # Assume unrecognized operating system is the powerpc eABI
2813          GMP_INCLUDE_MPN(powerpc32/eabi.m4)
2814	  ;;
2815      esac
2816      ;;
2817    power*-*-aix*)
2818      GMP_INCLUDE_MPN(powerpc32/aix.m4)
2819      ;;
2820    sparcv9*-*-* | ultrasparc*-*-* | sparc64-*-*)
2821      case $ABI in
2822        64)
2823          GMP_ASM_SPARC_REGISTER
2824          ;;
2825      esac
2826      ;;
2827    X86_PATTERN | X86_64_PATTERN)
2828      GMP_ASM_ALIGN_FILL_0x90
2829      case $ABI in
2830        32)
2831          GMP_INCLUDE_MPN(x86/x86-defs.m4)
2832          GMP_ASM_COFF_TYPE
2833          GMP_ASM_X86_GOT_UNDERSCORE
2834          GMP_ASM_X86_SHLDL_CL
2835      	  case $enable_profiling in
2836      	    prof | gprof)  GMP_ASM_X86_MCOUNT ;;
2837      	  esac
2838          case $host in
2839            *-*-darwin*)
2840              OBJECT_FORMAT="-f macho32" ;;
2841            *)
2842              OBJECT_FORMAT="-f elf32" ;;
2843           esac
2844          ;;
2845
2846        64)
2847          case $host in
2848            *-*-darwin*)
2849              # Defined in mpn/x86_64/x86_64-defs.m4, but there currently
2850              # hardcoded just for ELF, so redefine it here for Mach-O:
2851              GMP_DEFINE_RAW(["define(\`JUMPTABSECT',\`    .section    __DATA,__const')"],POST)
2852              OBJECT_FORMAT="-f macho64" ;;
2853            *-pc-msys|*-w64-mingw*|*-*-cygwin*)
2854              OBJECT_FORMAT="-f x64"  ;;
2855            *)
2856              OBJECT_FORMAT="-f elf64" ;;
2857          esac
2858          GMP_INCLUDE_MPN(x86_64/x86_64-defs.m4)
2859          ;;
2860      esac
2861      AC_SUBST(OBJECT_FORMAT)
2862      ;;
2863  esac
2864fi
2865
2866# Create link for gmp-mparam.h.
2867gmp_mparam_source=
2868for gmp_mparam_dir in $path; do
2869  test "$no_create" = yes || rm -f gmp-mparam.h
2870  tmp_file=$srcdir/mpn/$gmp_mparam_dir/gmp-mparam.h
2871  if test -f $tmp_file; then
2872    AC_CONFIG_LINKS(gmp-mparam.h:mpn/$gmp_mparam_dir/gmp-mparam.h)
2873    gmp_srclinks="$gmp_srclinks gmp-mparam.h"
2874    gmp_mparam_source=$tmp_file
2875    break
2876  fi
2877done
2878if test -z "$gmp_mparam_source"; then
2879  AC_MSG_ERROR([no version of gmp-mparam.h found in path: $path])
2880fi
2881
2882# Create longlong.h from the path
2883longlong_source=
2884for longlong_dir in $path; do
2885  test "$no_create" = yes || rm -f longlong.h
2886  tmp_file=$srcdir/mpn/$longlong_dir/longlong_inc.h
2887  if test -f $tmp_file; then
2888    AC_CONFIG_FILES(longlong.h:longlong_pre.h:mpn/$longlong_dir/longlong_inc.h:longlong_post.h)
2889    gmp_srclinks="$gmp_srclinks longlong.h"
2890    longlong_source=$tmp_file
2891    break
2892  fi
2893done
2894if test -z "$longlong_source"; then
2895  AC_MSG_ERROR([no version of longlong_inc.h found in path: $path])
2896fi
2897
2898# For a helpful message from tune/tuneup.c
2899gmp_mparam_suggest=$gmp_mparam_source
2900if test "$gmp_mparam_dir" = generic; then
2901  for i in $path; do break; done
2902  if test "$i" != generic; then
2903    gmp_mparam_suggest="new file $srcdir/mpn/$i/gmp-mparam.h"
2904  fi
2905fi
2906AC_DEFINE_UNQUOTED(GMP_MPARAM_H_SUGGEST, "$gmp_mparam_source",
2907[The gmp-mparam.h file (a string) the tune program should suggest updating.])
2908
2909
2910# Copy any SQR_KARATSUBA_THRESHOLD from gmp-mparam.h to config.m4.
2911# Some versions of sqr_basecase.asm use this.
2912# Fat binaries do this on a per-file basis, so skip in that case.
2913#
2914if test -z "$fat_path"; then
2915  tmp_gmp_karatsuba_sqr_threshold=`sed -n 's/^#define SQR_KARATSUBA_THRESHOLD[ 	]*\([0-9][0-9]*\).*$/\1/p' $gmp_mparam_source`
2916  if test -n "$tmp_gmp_karatsuba_sqr_threshold"; then
2917    GMP_DEFINE_RAW(["define(<SQR_KARATSUBA_THRESHOLD>,<$tmp_gmp_karatsuba_sqr_threshold>)"])
2918  fi
2919fi
2920
2921
2922# Sizes of some types, needed at preprocessing time.
2923#
2924# FIXME: The assumption that BITS_PER_MP_LIMB is 8*sizeof(mp_limb_t) might
2925# be slightly rash, but it's true everwhere we know of and ought to be true
2926# of any sensible system.  In a generic C build, grepping LONG_BIT out of
2927# <limits.h> might be an alternative, for maximum portability.
2928#
2929AC_CHECK_SIZEOF(unsigned short)
2930AC_CHECK_SIZEOF(unsigned)
2931AC_CHECK_SIZEOF(unsigned long)
2932AC_CHECK_SIZEOF(uintmax_t)
2933AC_CHECK_SIZEOF(mp_limb_t, , GMP_INCLUDE_GMP_H)
2934if test "$ac_cv_sizeof_mp_limb_t" = 0; then
2935  AC_MSG_ERROR([Oops, mp_limb_t doesn't seem to work])
2936fi
2937AC_SUBST(BITS_PER_MP_LIMB, `expr 8 \* $ac_cv_sizeof_mp_limb_t`)
2938GMP_DEFINE_RAW(["define(<SIZEOF_UNSIGNED>,<$ac_cv_sizeof_unsigned>)"])
2939
2940# Check compiler limb size matches gmp-mparam.h
2941#
2942# FIXME: Some of the cycle counter objects in the tune directory depend on
2943# the size of ulong, it'd be possible to check that here, though a mismatch
2944# probably wouldn't want to be fatal, none of the libmpir assembler code
2945# depends on ulong.
2946#
2947mparam_bits=[`sed -n 's/^#define BITS_PER_MP_LIMB[ 	][ 	]*\([0-9]*\).*$/\1/p' $gmp_mparam_source`]
2948if test -n "$mparam_bits" && test "$mparam_bits" -ne $BITS_PER_MP_LIMB; then
2949  if test "$test_CFLAGS" = set; then
2950    AC_MSG_ERROR([Oops, mp_limb_t is $BITS_PER_MP_LIMB bits, but the assembler code
2951in this configuration expects $mparam_bits bits.
2952You appear to have set \$CFLAGS, perhaps you also need to tell GMP the
2953intended ABI, see "ABI and ISA" in the manual.])
2954  else
2955    AC_MSG_ERROR([Oops, mp_limb_t is $BITS_PER_MP_LIMB bits, but the assembler code
2956in this configuration expects $mparam_bits bits.])
2957  fi
2958fi
2959
2960GMP_DEFINE_RAW(["define(<GMP_LIMB_BITS>,$BITS_PER_MP_LIMB)"])
2961GMP_DEFINE_RAW(["define(<GMP_NAIL_BITS>,$GMP_NAIL_BITS)"])
2962GMP_DEFINE_RAW(["define(<GMP_NUMB_BITS>,eval(GMP_LIMB_BITS-GMP_NAIL_BITS))"])
2963
2964AC_SUBST(mpn_objects)
2965AC_SUBST(mpn_objs_in_libgmp)
2966
2967
2968
2969AC_SUBST(gmp_srclinks)
2970
2971
2972# A recompiled sqr_basecase for use in the tune program, if necessary.
2973TUNE_SQR_OBJ=
2974test -d tune || mkdir tune
2975case $sqr_basecase_source in
2976  *.asm | *.as)
2977    sqr_max=[`sed -n 's/^def...(SQR_KARATSUBA_THRESHOLD_MAX, *\([0-9]*\))/\1/p' $sqr_basecase_source`]
2978    if test -n "$sqr_max"; then
2979      TUNE_SQR_OBJ=sqr_asm.o
2980      AC_DEFINE_UNQUOTED(TUNE_SQR_KARATSUBA_MAX,$sqr_max,
2981      [Maximum size the tune program can test for SQR_KARATSUBA_THRESHOLD])
2982    fi
2983    cat >tune/sqr_basecase.c <<EOF
2984/* not sure that an empty file can compile, so put in a dummy */
2985int sqr_basecase_dummy;
2986EOF
2987    ;;
2988  *.c)
2989    TUNE_SQR_OBJ=
2990    AC_DEFINE(TUNE_SQR_KARATSUBA_MAX,SQR_KARATSUBA_MAX_GENERIC)
2991    cat >tune/sqr_basecase.c <<EOF
2992#define TUNE_PROGRAM_BUILD 1
2993#define TUNE_PROGRAM_BUILD_SQR 1
2994#include "mpn/sqr_basecase.c"
2995EOF
2996    ;;
2997esac
2998AC_SUBST(TUNE_SQR_OBJ)
2999
3000# Create config.m4.
3001GMP_FINISH
3002
3003case $host in
3004  *-pc-msys|*-w64-mingw*|*-*-cygwin*)
3005    if test "$ABI" = "64"; then
3006      if test $enable_fat = yes; then
3007        YASM_MAC_INC=yasm_macwin.inc.fat
3008      else
3009        YASM_MAC_INC=yasm_macwin.inc.nofat
3010      fi
3011    else
3012      if test $enable_fat = yes; then
3013        YASM_MAC_INC=yasm_mac.inc.fat
3014      else
3015        YASM_MAC_INC=yasm_mac.inc.nofat
3016      fi
3017    fi
3018  ;;
3019  *-*-*)
3020    if test $enable_fat = yes; then
3021      YASM_MAC_INC=yasm_mac.inc.fat
3022    else
3023      YASM_MAC_INC=yasm_mac.inc.nofat
3024    fi
3025  ;;
3026esac
3027AC_CONFIG_LINKS(yasm_mac.inc:$YASM_MAC_INC)
3028
3029# Create Makefiles
3030# FIXME: Upcoming version of autoconf/automake don't like broken lines.
3031#        Right now automake isn't accepting the new AC_CONFIG_FILES scheme.
3032
3033AC_CONFIG_FILES(Makefile mpf/Makefile mpn/Makefile fft/Makefile mpq/Makefile mpz/Makefile printf/Makefile scanf/Makefile cxx/Makefile tests/Makefile tests/devel/Makefile tests/mpf/Makefile tests/mpn/Makefile tests/fft/Makefile tests/mpq/Makefile tests/mpz/Makefile tests/rand/Makefile tests/misc/Makefile tests/cxx/Makefile doc/Makefile tune/Makefile)
3034AC_CONFIG_FILES(mpir.h:gmp-h.in)
3035if test $enable_gmpcompat = yes; then
3036  AC_CONFIG_FILES(gmp.h:gmp-h.in)
3037  if test $enable_cxx = yes ; then
3038    AC_CONFIG_FILES(gmpxx.h:mpirxx.h)
3039  fi
3040fi
3041
3042AC_OUTPUT
3043
3044# now we have created and populated the mpn directory we can rename the files
3045# and post process the "m4 macros" into "yasm macros"
3046case $host in
3047  *-pc-msys|*-w64-mingw*|*-*-cygwin*)
3048    if test "$ABI" = "64"; then
3049      echo "Renaming assembly files on Win64..."
3050      for jay in $old_gmp_srclinks; do
3051        jayext=`echo "$jay" | awk -F . '{print $NF}'`
3052        #jayext=`/bin/echo "${jay#*.}"`
3053        #jayext=`echo "$jay" | sed -n 's/.*\.//'`
3054        base=`echo "${jay%.*}"`
3055        name=`basename $base`
3056        if test "$jayext" = "asm" && test "$name" != "fat_entry" ; then
3057          got=`grep -ce "d""nl  This line is to help MINGW64" $jay`
3058          if test "$got" = "1" ; then
3059            cat $jay | sed s/"include(\(.*\))"/"%include \"\1\""/ | sed s/"d""efine(\(.*\),\(.*\))"/"%d""efine \1 \2"/ | sed s/"d""efine(\(.*\))"/"%d""efine \1"/ | sed s/"d""nl\(.*\)"/"; \1"/ | sed s/ifdef.*// | sed s/"\`.*"// > $base.as
3060            rm -f $jay
3061          else
3062            mv $jay $base.as
3063          fi
3064        fi
3065      done
3066# the file x86_64_divrem_euclidean_qr_1.as should detect the defined macro EXCLUDE_PREINV , but for some reason it doesnt, so we hack it
3067      if test $enable_fat = yes; then
3068        echo "%d""efine EXCLUDE_PREINV 1" > mpn/x86_64_divrem_euclidean_qr_1.tmp
3069        cat mpn/x86_64_divrem_euclidean_qr_1.as >> mpn/x86_64_divrem_euclidean_qr_1.tmp
3070        mv mpn/x86_64_divrem_euclidean_qr_1.tmp mpn/x86_64_divrem_euclidean_qr_1.as
3071      fi
3072    fi
3073  ;;
3074esac
3075