summaryrefslogtreecommitdiff
path: root/configure.in
blob: 24abf9c23273501a91205c15d999419cbf5438f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
dnl  Process this file with autoconf to produce a configure script.


dnl  Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
dnl
dnl  This file is part of the GNU MP Library.
dnl
dnl  The GNU MP Library is free software; you can redistribute it and/or modify
dnl  it under the terms of the GNU Lesser General Public License as published
dnl  by the Free Software Foundation; either version 2.1 of the License, or (at
dnl  your option) any later version.
dnl
dnl  The GNU MP Library is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
dnl  License for more details.
dnl
dnl  You should have received a copy of the GNU Lesser General Public License
dnl  along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
dnl  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
dnl  MA 02111-1307, USA.


AC_REVISION($Revision$)dnl
AC_PREREQ(2.14)dnl
AC_INIT(gmp-impl.h)

dnl Check system.
AC_CANONICAL_SYSTEM

dnl  Automake
AM_INIT_AUTOMAKE(gmp, GMP_VERSION)
AM_CONFIG_HEADER(config.h:config.in)
AM_MAINTAINER_MODE

dnl  GMP specific
GMP_INIT(config.m4)


AC_ARG_ENABLE(assert,
AC_HELP_STRING([--enable-assert],[enable ASSERT checking [default=no]]),
[case "${enableval}" in
yes|no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-assert, need yes or no]) ;;
esac],
[enable_assert=no])

if test "$enable_assert" = "yes"; then
  AC_DEFINE(WANT_ASSERT,1,
  [./configure --enable-assert option, to enable some ASSERT()s])
fi


AC_ARG_ENABLE(alloca,
AC_HELP_STRING([--enable-alloca],[use alloca for temp space [default=yes]]),
[case "${enableval}" in
yes|no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-alloca, need yes or no]) ;;
esac],
[enable_alloca=yes])

if test "$enable_alloca" = "no"; then
  AC_DEFINE(USE_STACK_ALLOC,1,
  [./configure --disable-alloca option, to use stack-alloc.c, not alloca])
fi


AC_ARG_ENABLE(fft,
AC_HELP_STRING([--enable-fft],[enable FFTs for multiplication [default=no]]),
[case "${enableval}" in
yes|no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-fft, need yes or no]) ;;
esac],
[enable_fft=no])

if test "$enable_fft" = "yes"; then
  AC_DEFINE(WANT_FFT,1,
  [./configure --enable-fft option, to enable FFTs for multiplication])
fi


AC_ARG_ENABLE(mpbsd,
AC_HELP_STRING([--enable-mpbsd],[build Berkley MP compatibility library [default=no]]),
[case "${enableval}" in
yes|no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-mpbsd, need yes or no]) ;;
esac],
[enable_mpbsd=no])
AM_CONDITIONAL(WANT_MPBSD, test "$enable_mpbsd" = "yes")


AC_ARG_ENABLE(mpfr,
AC_HELP_STRING([--enable-mpfr],[build MPFR [default=no]]),
[case "${enableval}" in
yes|no) ;;
*) AC_MSG_ERROR([bad value ${enableval} for --enable-mpfr, need yes or no]) ;;
esac],
[enable_mpfr=no])
AM_CONDITIONAL(WANT_MPFR, test "$enable_mpfr" = "yes")


dnl Switch on OS and determine what compiler to use.
dnl
dnl  os_64bit	           Set to "yes" if OS is 64-bit capable.
dnl                        FIXME: Rename to `check_64bit_compiler'!
dnl  cclist		   List of compilers, best first.
dnl  gmp_cflags_{cc}	   Flags for compiler named {cc}.
dnl  gmp_cflags64_{cc}     Flags for compiler named {cc} for 64-bit code.
dnl  gmp_optcflags_{cc}	   Optional compiler flags.
dnl  gmp_xoptcflags_{cc}   Exclusive optional compiler flags.
dnl
os_64bit="no"
cclist="gcc cc"		# FIXME: Prefer c89 to cc.
gmp_cflags_gcc="-g -O2"
gmp_cflags64_gcc="-g -O2"
gmp_cflags_cc="-g"
gmp_cflags64_cc="-g"

case "$target" in
  # Alpha
  alpha*-cray-unicos*)
    # Don't perform any assembly syntax tests on this beast.
    gmp_no_asm_syntax_testing=yes
    cclist=cc
    gmp_cflags_cc="$gmp_cflags_cc -O"
    ;;
  alpha*-*-osf*)
    flavour=`echo $target_cpu | sed 's/^alpha//g'`
    if test -n "$flavour"; then
      case $flavour in	   # compilers don't seem to understand `ev67' and such.
	ev6? | ev7*) flavour=ev6;;
      esac
      gmp_optcflags_gcc="-mcpu=$flavour"
      # FIXME: We shouldn't fail fatally if none of these work, but that's
      # how xoptcflags work and we don't have any other mechanism right now.
      # Why do we need this here and not for alpha*-*-* below?
      gmp_xoptcflags_gcc="-Wa,-arch,${flavour} -Wa,-m${flavour}"
      gmp_optcflags_cc="-arch $flavour -tune $flavour"
    fi
    ;;
  alpha*-*-*)
    cclist="gcc"
    flavour=`echo $target_cpu | sed 's/^alpha//g'`
    if test -n "$flavour"; then
      case $flavour in
	ev6? | ev7*) flavour=ev6;;
      esac
      gmp_optcflags_gcc="-mcpu=$flavour"
    fi
    ;;
  # Cray vector machines.  This must come after alpha* so that we can
  # recognize present and future vector processors with a wildcard.
  *-cray-unicos*)
    # Don't perform any assembly syntax tests on this beast.
    gmp_no_asm_syntax_testing=yes
    cclist=cc
    # Don't inherit default gmp_cflags_cc value; it comes with -g which
    # disables all optimization on Cray vector systems
    gmp_cflags_cc="-O"
    ;;

  # AMD and Intel x86 configurations
  [i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-*])
    # Rumour has it -O2 used to give worse register allocation than just -O.
    gmp_cflags_gcc="-g -O -fomit-frame-pointer"

    case "${target}" in
      i386*-*-*)    gmp_optcflags_gcc="-mcpu=i386 -march=i386";;
      i486*-*-*)    gmp_optcflags_gcc="-mcpu=i486 -march=i486";;
      i586*-*-* | pentium-*-* | pentiummmx-*-*)
                    gmp_optcflags_gcc="-mcpu=pentium -march=pentium";;

      # -march=pentiumpro not used because mpz/powm.c (swox cvs rev 1.4)
      # tickles a bug in gcc 2.95.2 (believed fixed in 2.96).
      [i686*-*-* | pentiumpro-*-* | pentium[23]-*-*])
                    gmp_optcflags_gcc="-mcpu=pentiumpro";;

      k6*-*-*)      gmp_optcflags_gcc="-mcpu=k6 -march=k6";;

      # Athlon instruction costs are close to p6: 3 cycle load latency, 4-6
      # cycle mul, 40 cycle div, pairable adc, ...
      # FIXME: Change this when gcc gets something specific for Athlon.
      # -march=pentiumpro not used, per i686 above.
      athlon-*-*)   gmp_optcflags_gcc="-mcpu=pentiumpro";;
    esac
    ;;

  # Sparc
  [ultrasparc*-*-solaris2.[7-9] | sparcv9-*-solaris2.[7-9]])
    os_64bit=yes
    gmp_cflags_gcc="$gmp_cflags_gcc -Wa,-xarch=v8plus"
    gmp_xoptcflags_gcc="-mcpu=v9 -mcpu=v8 -mv8"
    gmp_cflags64_gcc="$gmp_cflags64_gcc -m64 -mptr64 -Wa,-xarch=v9 -mcpu=v9"
    gmp_cflags_cc="-xtarget=native -xarch=v8 -xO4"
    gmp_cflags64_cc="-xtarget=native -xarch=v9 -xO4"
    ;;
  sparc64-*-linux*)
    os_64bit=yes
    gmp_cflags64_gcc="$gmp_cflags64_gcc -m64 -mptr64 -Wa,-xarch=v9 -mcpu=v9"
    gmp_cflags_gcc="$gmp_cflags_gcc -m32"
    gmp_xoptflags_gcc="-mcpu=ultrasparc -mvis"
    ;;
  ultrasparc*-*-* | sparcv9-*-*)
    gmp_cflags_gcc="$gmp_cflags_gcc -Wa,-xarch=v8plus"
    gmp_xoptcflags_gcc="-mcpu=v9 -mcpu=v8 -mv8"
    gmp_cflags_cc="-xtarget=native -xarch=v8 -xO4"
    ;;
  sparcv8*-*-solaris2.* | microsparc*-*-solaris2.*)
    gmp_cflags_gcc="$gmp_cflags_gcc"
    gmp_xoptcflags_gcc="-mcpu=v8 -mv8"
    gmp_cflags_cc="-xtarget=native -xarch=v8 -xO4"
    ;;
  sparcv8*-*-* | microsparc*-*-*)		# SunOS, Linux, *BSD
    cclist="gcc acc cc"
    gmp_cflags_gcc="$gmp_cflags_gcc"
    gmp_xoptcflags_gcc="-mcpu=v8 -mv8"
    gmp_cflags_acc="-g -O2 -cg92"
    gmp_cflags_cc="-O2"		# FIXME: Flag for v8?
    ;;
  supersparc*-*-solaris2.*)
    gmp_cflags_gcc="$gmp_cflags_gcc -DSUPERSPARC"
    gmp_xoptcflags_gcc="-mcpu=v8 -mv8"
    gmp_cflags_cc="-xtarget=native -xarch=v8 -xO4 -DSUPERSPARC"
    ;;
  supersparc*-*-*)		# SunOS, Linux, *BSD
    cclist="gcc acc cc"
    gmp_cflags_gcc="$gmp_cflags_gcc -DSUPERSPARC"
    gmp_xoptcflags_gcc="-mcpu=v8 -mv8"
    gmp_cflags_acc="-g -O2 -cg92 -DSUPERSPARC"
    gmp_cflags_cc="-O2 -DSUPERSPARC"	# FIXME: Flag for v8?
    ;;
  *sparc*-*-*)
    cclist="gcc acc cc"
    gmp_cflags_acc="-g -O2"
    gmp_cflags_cc="-g -O2"
    ;;

  # POWER/PowerPC
  powerpc64-*-aix*)
    cclist="gcc xlc"
    gmp_cflags_gcc="$gmp_cflags_gcc -maix64 -mpowerpc64"
    gmp_cflags_xlc="-g -O2 -q64 -qtune=pwr3"
    ;;
  powerpc*-*-aix*)
    cclist="gcc xlc"
    gmp_cflags_gcc="$gmp_cflags_gcc -mpowerpc"
    gmp_cflags_xlc="$gmp_cflags_cc -qarch=ppc -O2"
    ;;
  power-*-aix*)
    cclist="gcc xlc"
    gmp_cflags_gcc="$gmp_cflags_gcc -mpower"
    gmp_cflags_xlc="$gmp_cflags_cc -qarch=pwr -O2"
    ;;
  powerpc64*-*-*)
    gmp_cflags_gcc="$gmp_cflags_gcc -mpowerpc64"
    AC_DEFINE(_LONG_LONG_LIMB)	dnl FIXME: Remove.
    ;;
  powerpc*-*-*)
    gmp_cflags_gcc="$gmp_cflags_gcc -mpowerpc"
    ;;

  # MIPS
  mips-sgi-irix6.*)
    os_64bit=yes
    gmp_cflags64_gcc="-g -O2 -mabi=n32"
    gmp_cflags64_cc="$gmp_cflags64_cc -O2 -n32"
    ;;

  # Motorola 68k family
  m88110*-*-*)
    gmp_cflags_gcc="-g -O -m88110"	dnl  FIXME: Use `-O2'?
    ;;
  m68*-*-*)
    gmp_cflags_gcc="$gmp_cflags_gcc -fomit-frame-pointer"
    ;;

  # HP
  hppa1.0*-*-*)
    cclist="gcc c89 cc"
    gmp_cflags_c89="$gmp_cflags_cc +O2"
    gmp_cflags_cc="$gmp_cflags_cc +O2"
    ;;
  hppa2.0w*-*-*)
    cclist="c89 cc"
    gmp_cflags_c89="+DD64 +O3"
    gmp_cflags_cc="+DD64 +O3"
    ;;
  hppa2.0*-*-*)
    os_64bit=yes
    cclist="gcc c89 cc"
    gmp_cflags64_gcc="$gmp_cflags64_gcc -mWHAT -D_LONG_LONG_LIMB"
    # +O2 to cc triggers bug in mpz/powm.c (1.4)
    gmp_cflags64_c89="+DA2.0 +e +O3 -D_LONG_LONG_LIMB"
    gmp_cflags64_cc="+DA2.0 +e +O3 -D_LONG_LONG_LIMB"
    gmp_cflags_c89="$gmp_cflags_cc +O2"
    gmp_cflags_cc="$gmp_cflags_cc +O2"
    ;;

  # VAX
  vax*-*-*)
    gmp_cflags_gcc="$gmp_cflags_gcc -fomit-frame-pointer"
    ;;

  # Fujitsu
  [f30[01]-fujitsu-sysv*])
    cclist="gcc vcc"
    gmp_cflags_vcc="-g"		# FIXME: flags for vcc?
    ;;
esac

dnl  Check for programs needed by macros for finding compiler.
dnl  More programs are checked for below, when a compiler is found.
AC_PROG_NM	dnl  Macro from Libtool.
# nm on 64-bit AIX needs to know the object file format 
case "$target" in
  powerpc64*-*-aix*)
    NM="$NM -X 64"
    ;;
esac   

# Save CFLAGS given on command line.
gmp_user_CFLAGS="$CFLAGS"

if test -z "$CC"; then
  # Find compiler.
  GMP_PROG_CC_FIND($cclist, $os_64bit)

  # If 64-bit OS and we have a 64-bit compiler, use it.
  if test -n "$os_64bit" && test -n "$CC64"; then
    CC=$CC64
    CFLAGS=$CFLAGS64
  else
    eval CFLAGS=\$gmp_cflags_$CC  
  fi

  # Try compiler flags that may work with only some compiler versions.
  # gmp_optcflags: All or nothing.
  eval optcflags=\$gmp_optcflags_$CC
  if test -n "$optcflags"; then
    CFLAGS_save="$CFLAGS"
    CFLAGS="$CFLAGS $optcflags"
    AC_MSG_CHECKING([whether $CC accepts $optcflags])
    AC_LANG_C
    AC_TRY_COMPILER([int main(){return(0);}], optok, cross)
    if test "$optok" = "yes"; then
      AC_MSG_RESULT([yes])
    else
      AC_MSG_RESULT([no])
      CFLAGS="$CFLAGS_save"
    fi
  fi
  # gmp_xoptcflags: First is best, one has to work.
  eval xoptcflags=\$gmp_xoptcflags_$CC
  if test -n "$xoptcflags"; then
    gmp_found="no"
    for xopt in $xoptcflags; do
      CFLAGS_save="$CFLAGS"
      CFLAGS="$CFLAGS $xopt"
      AC_MSG_CHECKING([whether $CC accepts $xopt])
      AC_LANG_C
      AC_TRY_COMPILER([int main(){return(0);}], optok, cross)
      if test "$optok" = "yes"; then
        AC_MSG_RESULT([yes])
        gmp_found="yes"
        break
      else
        AC_MSG_RESULT([no])
        CFLAGS="$CFLAGS_save"
      fi
    done
    if test "$gmp_found" = "no"; then
      echo ["$0: fatal: need a compiler that understands one of $xoptcflags"]
      exit 1
    fi
  fi
fi

# Restore CFLAGS given on command line.
# FIXME: We've run through quite some unnecessary code looking for a
# nice compiler and working flags for it, just to spoil that with user
# supplied flags.
test -n "$gmp_user_CFLAGS" && CFLAGS="$gmp_user_CFLAGS"

# Select chosen compiler.
GMP_PROG_CC_SELECT

# How to assemble.
CCAS="$CC -c"
AC_SUBST(CCAS)

dnl Checks for programs.
dnl --------------------
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
GMP_PROG_M4
AC_CHECK_PROG(AR, ar, ar)
# ar on AIX needs to know the object file format 
case "$target" in
  powerpc64*-*-aix*)
    AR="$AR -X 64"
    ;;
esac   
dnl  FIXME: Find good ld?  /usr/ucb/ld on Solaris won't work.

dnl Checks for assembly syntax.
if test "$gmp_no_asm_syntax_testing" != "yes"; then
  GMP_CHECK_ASM_TEXT
  GMP_CHECK_ASM_DATA
  GMP_CHECK_ASM_GLOBL
  GMP_CHECK_ASM_LABEL_SUFFIX
  GMP_CHECK_ASM_TYPE
  GMP_CHECK_ASM_SIZE
  GMP_CHECK_ASM_LSYM_PREFIX
  GMP_CHECK_ASM_W32
  GMP_CHECK_ASM_UNDERSCORE(underscore=yes, underscore=no)
  GMP_CHECK_ASM_ALIGN_LOG(asm_align=log, asm_align=nolog)
fi

dnl  FIXME: Check for FPU and set `floating_point' appropriately.

dnl  ========================================
dnl  Configuring mpn.
dnl  ----------------------------------------
dnl  Set the following target specific variables:
dnl  path		where to search for source files
dnl  family		processor family (Needed for building 
dnl 			asm-syntax.h for now.  FIXME: Remove.)
dnl  extra_functions	extra functions

family=generic

case ${target} in
  arm*-*-*)
    path="arm"
    ;;
  [sparcv9*-*-solaris2.[789]* | sparc64*-*-solaris2.[789]* | ultrasparc*-*-solaris2.[789]*])
    if test -n "$CC64"; then
      path="sparc64"
    else
      path="sparc32/v9 sparc32/v8 sparc32"
    fi
    ;;
  sparc64-*-linux*)
    path="sparc64"
    ;;
  sparcv8*-*-* | microsparc*-*-*)
	path="sparc32/v8 sparc32"
	if test x${floating_point} = xno
	  then extra_functions="udiv_nfp"
	  else extra_functions="udiv_fp"
	fi
	;;
  sparcv9*-*-* | ultrasparc*-*-*)
	path="sparc32/v9 sparc32/v8 sparc32"
	extra_functions="udiv_fp"
	;;
  supersparc*-*-*)
	path="sparc32/v8/supersparc sparc32/v8 sparc32"
	extra_functions="udiv"
	;;
  sparc*-*-*) path="sparc32"
	if test x${floating_point} = xno
	  then extra_functions="udiv_nfp"
	  else extra_functions="udiv_fp"
	fi
	;;
  hppa7000*-*-*)
    path="hppa/hppa1_1 hppa"
    extra_functions="udiv_qrnnd"
    ;;
  hppa1.0*-*-*)
    path="hppa"
    extra_functions="udiv_qrnnd"
    ;;
  hppa2.0w-*-*)
    path="pa64w"
    extra_functions="umul_ppmm udiv_qrnnd"
    ;;
  hppa2.0*-*-*)
    if test -n "$CC64"; then
      path="pa64"
      extra_functions="umul_ppmm udiv_qrnnd"
      # We need to use the system compiler, or actually the system assembler,
      # since GAS has not been ported to understand the 2.0 instructions.
      CCAS="$CC64 -c"
    else
      # FIXME: path should be "hppa/hppa2_0 hppa/hppa1_1 hppa"
      path="hppa/hppa1_1 hppa"
      extra_functions="udiv_qrnnd"
    fi
    ;;
  hppa*-*-*)					#assume pa7100
    path="hppa/hppa1_1/pa7100 hppa/hppa1_1 hppa"
    extra_functions="udiv_qrnnd";;
  [f30[01]-fujitsu-sysv*])
    path=fujitsu;;
  alphaev6*-*-*) path="alpha/ev6 alpha"; extra_functions="invert_limb cntlz";;
  alphaev5*-*-*) path="alpha/ev5 alpha"; extra_functions="invert_limb cntlz";;
  alpha*-*-*) path="alpha"; extra_functions="invert_limb cntlz";;
  # Cray vector machines.  This must come after alpha* so that we can
  # recognize present and future vector processors with a wildcard.
  *-cray-unicos*)
    path="cray"
    extra_functions="mulww";;
  am29000*-*-*) path="a29k";;
  a29k*-*-*) path="a29k";;

  # AMD and Intel x86 configurations

  [i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-*])
    gmp_m4postinc="x86/x86-defs.m4"
    extra_functions="udiv umul"
    CALLING_CONVENTIONS_OBJS="x86call.o x86check.o"

    GMP_CHECK_ASM_SHLDL_CL(
      [GMP_DEFINE(WANT_SHLDL_CL,1)],
      [GMP_DEFINE(WANT_SHLDL_CL,0)])
    GMP_CHECK_ASM_ALIGN_FILL_0x90

    # the CPUs below wanting to know about mmx
    case ${target} in
      [pentiummmx-*-* | pentium[23]-*-* | k6*-*-* | athlon-*-*])
	GMP_CHECK_ASM_MMX(tmp_mmx=yes, tmp_mmx=no)
        ;;
    esac

    # default for anything not otherwise mentioned
    path="x86"
 
    case ${target} in
      [i[34]86*-*-*])
        path="x86"
        ;;
      k5*-*-*)
        # don't know what best suits k5
        path="x86"
        ;;
      i586*-*-* | pentium-*-*)
	path="x86/pentium x86"
        ;;
      pentiummmx-*-*)
	path="x86/pentium x86"
	if test "$tmp_mmx" = yes; then
          path="x86/pentium/mmx $path"
        fi
        ;;
      i686*-*-* | pentiumpro-*-*)
	path="x86/p6 x86"
        ;;
      pentium2-*-*)
	path="x86/p6 x86"
	# The pentium/mmx lshift and rshift are good on p6 and can be used
        # until there's something specific for p6.
	if test "$tmp_mmx" = yes; then
          path="x86/p6/mmx x86/pentium/mmx $path"
        fi
        ;;
      pentium3-*-*)
	path="x86/p6 x86"
	# The pentium/mmx lshift and rshift are good on p6 and can be used
        # until there's something specific for p6.
	if test "$tmp_mmx" = yes; then
          path="x86/p6/p3mmx x86/p6/mmx x86/pentium/mmx $path"
        fi
        ;;
      [k6[23]*-*-*])
	path="x86/k6 x86"
	if test "$tmp_mmx" = yes; then
          path="x86/k6/k62mmx x86/k6/mmx $path"
        fi
        ;;
      k6*-*-*)
	path="x86/k6 x86"
	if test "$tmp_mmx" = yes; then
          path="x86/k6/mmx $path"
        fi
        ;;
      athlon-*-*)
	path="x86/k7 x86"
	if test "$tmp_mmx" = yes; then
          path="x86/k7/mmx $path"
        fi
        ;;
    esac
    ;;


  i960*-*-*) path="i960";;

  ia64*-*-*) path="ia64";;

# Motorola 68k configurations.  Let m68k mean 68020-68040.
  [m680[234]0*-*-* | m68k*-*-* | \
  m68*-next-nextstep*])		# Nexts are at least '020
    path="m68k/mc68020 m68k"
    family=m68k
    ;;
  m68000*-*-*)
    path="m68k"
    family=m68k
    ;;

  m88k*-*-* | m88k*-*-*) path="m88k";;
  m88110*-*-*) path="m88k/mc88110 m88k";;
  ns32k*-*-*) path="ns32k";;

  pyramid-*-*) path="pyr";;

  ppc601-*-*) path="power powerpc32";;
  powerpc64*-*-*) path="powerpc64";;
  powerpc*-*-*) path="powerpc32";;
  rs6000-*-* | power-*-* | power2-*-*)
    path="power"
    extra_functions="udiv_w_sdiv"
    ;;

  sh-*-*) path="sh";;
  sh2-*-*) path="sh/sh2 sh";;

  [mips[34]*-*-*]) path="mips3";;
  mips*-*-irix6*) path="mips3";;
  mips*-*-*) path="mips2";;

  vax*-*-*) path="vax"; extra_functions="udiv_w_sdiv";;

  z8000x*-*-*) path="z8000x"; extra_functions="udiv_w_sdiv";;
  z8000*-*-*) path="z8000"; extra_functions="udiv_w_sdiv";;

  clipper*-*-*) path="clipper";;
esac

AC_SUBST(CALLING_CONVENTIONS_OBJS)
if test -n "$CALLING_CONVENTIONS_OBJS"; then
  AC_DEFINE(HAVE_CALLING_CONVENTIONS,1,
  [Define if mpn/tests has calling conventions checking for the CPU])
fi


case ${target} in
  [i[5-8]86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-*])
    # rdtsc is in pentium and up, not in i386 and i486
    SPEED_CYCLECOUNTER_OBJS=pentium.lo
    ;;
  alpha*-*-*)
    SPEED_CYCLECOUNTER_OBJS=alpha.lo
    ;;
  sparcv9*-*-* | ultrasparc*-*-* | sparc64*-*-*)
    SPEED_CYCLECOUNTER_OBJS=sparcv9.lo
    ;;
  hppa2*-*-*)
    SPEED_CYCLECOUNTER_OBJS=hppa2.lo
    ;;
  hppa*-*-*)
    SPEED_CYCLECOUNTER_OBJS=hppa.lo
    ;;
esac

AC_SUBST(SPEED_CYCLECOUNTER_OBJS)

if test -n "$SPEED_CYCLECOUNTER_OBJS"
then
  AC_DEFINE(HAVE_SPEED_CYCLECOUNTER, 1,
  [Define if a speed_cyclecounter exists (for the tune programs)])
fi


dnl Extensions for executable and object files.
dnl -------------------------------------------
AC_EXEEXT
AC_OBJEXT

dnl Use Libtool.
dnl ------------
dnl  FIXME: Shared libs seem to fail on aix4.3.
dnl  FIXME: Should invoke [AC_DISABLE_SHARED], but m4 recurses to death.
case "$target" in
  [*-*-aix4.[3-9]*]) enable_shared=no ;;
esac
AC_PROG_LIBTOOL

dnl Checks for libraries.
dnl ---------------------
AC_CHECK_DECLS((optarg))

dnl Checks for header files.
dnl ------------------------
AC_HEADER_STDC
AC_CHECK_HEADERS(getopt.h unistd.h sys/sysctl.h sys/time.h)

dnl Checks for typedefs, structures, and compiler characteristics.
dnl --------------------------------------------------------------
AC_CHECK_TYPES((void))
AC_C_STRINGIZE

dnl Checks for library functions.
dnl -----------------------------
dnl Most of these are only for the benefit of supplementary programs.  The
dnl library itself doesn't use anything weird.
dnl AC_FUNC_MEMCMP
dnl AC_TYPE_SIGNAL
dnl AC_CHECK_FUNCS(strtol)
AC_CHECK_FUNCS(getopt_long getpagesize popen processor_info strtoul sysconf sysctlbyname)

dnl Trick automake into thinking we've run AM_C_PROTOTYPES which it wants
dnl for ansi2knr, and instead use our own test.  (It's only a warning
dnl automake prints, but it's good to suppress it.)
ifelse(0,1,[
AM_C_PROTOTYPES
])
GMP_C_ANSI2KNR


dnl  Set `syntax' to one of <blank>, "mit", "elf", "aix", "macho".
syntax=
# For now, we use the old switch for setting syntax.  
# FIXME: Remove when conversion to .asm is completed.
changequote(,)dnl
case "${target}" in
  m680[234]0*-*-linuxaout* | m68k*-*-linuxaout* | \
  m68k-next-nextstep* | \
  m68000*-*-*)
    syntax=mit
    ;;
  m680[234]0*-*-linux* | m68k*-*-linux*)
    syntax=elf
    ;;
  m680[234]0*-*-* | m68k*-*-*)
    syntax=mit
    ;;
esac
changequote([,])dnl

dnl  ----------------------------------------
# Now build an asm-syntax.h file for targets that include that from the
# assembly files.
# FIXME: Remove when conversion to .asm is completed.
case "${family}-${underscore}-${asm_align}-${syntax}" in
  m68k-yes-log-mit)
    echo '#define MIT_SYNTAX' >asm-syntax.h
    cat $srcdir/mpn/underscore.h >>asm-syntax.h
    echo '#include "'$srcdir'/mpn/m68k/syntax.h"' >>asm-syntax.h;;
  m68k-no-nolog-elf)
    echo '#define ELF_SYNTAX' >asm-syntax.h
    echo '#define C_SYMBOL_NAME(name) name' >>asm-syntax.h
    echo '#include "'$srcdir'/mpn/m68k/syntax.h"' >>asm-syntax.h;;
esac


# The pattern here tests for an absolute path the same way as
# _AC_OUTPUT_FILES in autoconf acgeneral.m4.
GMP_DEFINE_RAW(["dnl  CONFIG_TOP_SRCDIR is a path from the mpn builddir to the top srcdir"])
case "$srcdir" in
[[\\/]]* | ?:[[\\/]]* )
     GMP_DEFINE_RAW(["define(<CONFIG_TOP_SRCDIR>,<\`$srcdir'>)"])    ;;
*)   GMP_DEFINE_RAW(["define(<CONFIG_TOP_SRCDIR>,<\`../$srcdir'>)"]) ;;
esac
 
GMP_DEFINE_RAW(["include(CONFIG_TOP_SRCDIR\`/mpn/asm-defs.m4')"], POST)

# Must be after asm-defs.m4
GMP_DEFINE_RAW("define_not_for_expansion(\`HAVE_TARGET_CPU_$target_cpu')", POST)


dnl  config.m4 post-includes
dnl  -----------------------
dnl  (Note x86 post include set with $path above.)
changequote(,)dnl
case "$target" in
  alpha*-cray-unicos*)
    gmp_m4postinc="alpha/unicos.m4"
    ;;
  alpha*-*-*)
    gmp_m4postinc="alpha/default.m4"
    ;;
  power*-*-*)
    case "$target" in
      *-*-mach* | *-*-rhapsody* | *-*-nextstep*)
        ;;	# these use non-conventional assembly syntax.
      powerpc64-*-aix*)
	gmp_m4postinc="powerpc32/regmap.m4 powerpc64/aix.m4"
        ;;
      *-*-aix*)
	gmp_m4postinc="powerpc32/regmap.m4 powerpc32/aix.m4"
        ;;
      *)
	gmp_m4postinc="powerpc32/regmap.m4"
	;;
    esac
    ;;
esac
changequote([, ])dnl

for tmp_f in $gmp_m4postinc; do
  GMP_DEFINE_RAW(["include_mpn(\`$tmp_f')"], POST)
done


# Set up `gmp_links'.  It's a list of link:file pairs that configure will
# process to create link -> file.
gmp_links=

# If the user specified `MPN_PATH', use that instead of the path we've
# come up with.
if test -z "$MPN_PATH"; then
  path="$path generic"
else
  path="$MPN_PATH"
fi

# Pick the correct source files in $path and link them to mpn/.
# $gmp_mpn_functions lists all functions we need.
#
# The rule is to find a file with the function name and a .asm, .S,
# .s, or .c extension.  Certain multi-function files with special names
# can provide some functions too.  (mpn/Makefile.am passes
# -DOPERATION_<func> to get them to generate the right code.)

# FIXME: udiv and umul aren't in $gmp_mpn_functions_optional yet since
# there's some versions of those files which should be checked for bit
# rot first.  Put them in $extra_functions for each target for now,
# change to standard optionals when all are ready.

# Note: The following lines defining $gmp_mpn_functions_optional
#       and $gmp_mpn_functions are parsed by the "macos/configure"
#       Perl script. So if you change the lines in a major way
#       make sure to run and examine the output from
#       
#           % (cd macos; perl configure)

gmp_mpn_functions_optional="copyi copyd com_n		\
  and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n"

gmp_mpn_functions="${extra_functions} inlines add_n sub_n mul_1 addmul_1   \
  submul_1 lshift rshift diveby3 divrem divrem_1 divrem_2                  \
  mod_1 mod_1_rs pre_mod_1 dump                                            \
  mul mul_fft mul_n mul_basecase sqr_basecase random                       \
  random2 sqrtrem get_str set_str scan0 scan1 popcount hamdist cmp perfsqr \
  bdivmod gcd_1 gcd gcdext tdiv_qr bz_divrem_n sb_divrem_mn jacbase        \
  $gmp_mpn_functions_optional"

# the list of all object files used by mpn/Makefile.in and the
# top-level Makefile.in, respectively
mpn_objects=
mpn_objs_in_libgmp="mpn/mp_bases.lo"

for tmp_fn in ${gmp_mpn_functions} ; do
  [rm -f mpn/${tmp_fn}.[Ssc] mpn/${tmp_fn}.asm]

  # functions that can be provided by multi-function files
  tmp_mulfunc=
  case $tmp_fn in
  add_n|sub_n)       tmp_mulfunc="aors_n"    ;;
  addmul_1|submul_1) tmp_mulfunc="aorsmul_1" ;;
  popcount|hamdist)  tmp_mulfunc="popham"    ;;
  and_n|andn_n|nand_n | ior_n|iorn_n|nior_n | xor_n|xnor_n)
                     tmp_mulfunc="logops_n"  ;;
  esac

  found=no
  for tmp_dir in $path; do
    for tmp_base in $tmp_fn $tmp_mulfunc; do
      for tmp_ext in asm S s c; do
        tmp_file=$srcdir/mpn/$tmp_dir/$tmp_base.$tmp_ext
        if test -f $tmp_file; then
          found=yes

          mpn_objects="$mpn_objects ${tmp_fn}.lo"
          mpn_objs_in_libgmp="$mpn_objs_in_libgmp mpn/${tmp_fn}.lo"
          gmp_links="$gmp_links mpn/$tmp_fn.$tmp_ext:mpn/$tmp_dir/$tmp_base.$tmp_ext"

          # duplicate AC_DEFINEs are harmless, so it doesn't matter
          # that multi-function files get grepped here repeatedly
          gmp_ep=["`
            sed -n 's/^[ 	]*MULFUNC_PROLOGUE(\(.*\))/\1/p' $tmp_file ;
            sed -n 's/^[ 	]*PROLOGUE(\(.*\))/\1/p' $tmp_file
          `"]
          for gmp_tmp in $gmp_ep; do
            AC_DEFINE_UNQUOTED(HAVE_NATIVE_${gmp_tmp})
          done

          break
        fi
      done
      if test $found = yes; then break ; fi
    done
    if test $found = yes; then break ; fi
  done

  if test $found = no; then
    for tmp_optional in $gmp_mpn_functions_optional; do
      if test $tmp_optional = $tmp_fn; then
        found=yes
      fi
    done
    if test $found = no; then
      AC_MSG_ERROR([no version of $tmp_fn found in path: $path])
    fi
  fi
done

# Create link for gmp-mparam.h.
for tmp_dir in $path ; do
  rm -f gmp-mparam.h
  if test -f $srcdir/mpn/${tmp_dir}/gmp-mparam.h ; then
    gmp_links="$gmp_links gmp-mparam.h:mpn/${tmp_dir}/gmp-mparam.h"

    # Copy any KARATSUBA_SQR_THRESHOLD in gmp-mparam.h to config.m4.
    # Some versions of sqr_basecase.asm use this.
    tmp_gmp_karatsuba_sqr_threshold="`sed -n 's/^#define KARATSUBA_SQR_THRESHOLD[ 	]*\([0-9][0-9]*\).*$/\1/p' $srcdir/mpn/${tmp_dir}/gmp-mparam.h`"
    if test -n "$tmp_gmp_karatsuba_sqr_threshold"; then
      GMP_DEFINE_RAW(["define(<KARATSUBA_SQR_THRESHOLD>,<$tmp_gmp_karatsuba_sqr_threshold>)"])
    fi

    break
  fi
done

# Dig out the links from `gmp_links' for inclusion in DISTCLEANFILES.
gmp_srclinks=
for f in $gmp_links; do
  gmp_srclinks="$gmp_srclinks `echo $f | sed 's/\(.*\):.*/\1/'`"
done

AC_SUBST(mpn_objects)
AC_SUBST(mpn_objs_in_libgmp)
AC_SUBST(gmp_srclinks)

dnl  ----------------------------------------
dnl  Make links.
AC_CONFIG_LINKS($gmp_links)

dnl  Create config.m4.
GMP_FINISH

dnl  Create Makefiles
dnl  FIXME: Upcoming version of autoconf/automake may not like broken lines.
AC_OUTPUT(Makefile mpf/Makefile mpz/Makefile mpn/Makefile mpq/Makefile \
  mpf/tests/Makefile mpz/tests/Makefile mpq/tests/Makefile mpn/tests/Makefile \
  tests/Makefile tests/rand/Makefile demos/Makefile tune/Makefile \
  mpbsd/Makefile mpbsd/tests/Makefile mpfr/Makefile mpfr/tests/Makefile)