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