-
Notifications
You must be signed in to change notification settings - Fork 2
/
acinclude.m4
3872 lines (3524 loc) · 116 KB
/
acinclude.m4
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
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
dnl GMP specific autoconf macros
dnl Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 Free Software
dnl 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 3 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. If not, see http://www.gnu.org/licenses/.
dnl Some tests use, or must delete, the default compiler output. The
dnl possible filenames are based on what autoconf looks for, namely
dnl
dnl a.out - normal unix style
dnl b.out - i960 systems, including gcc there
dnl a.exe - djgpp
dnl a_out.exe - OpenVMS DEC C called via GNV wrapper (gnv.sourceforge.net)
dnl conftest.exe - various DOS compilers
define(IA64_PATTERN,
[[ia64*-*-* | itanium-*-* | itanium2-*-*]])
dnl Need to be careful not to match m6811, m6812, m68hc11 and m68hc12, all
dnl of which config.sub accepts. (Though none of which are likely to work
dnl with GMP.)
dnl
define(M68K_PATTERN,
[[m68k-*-* | m68[0-9][0-9][0-9]-*-*]])
define(POWERPC64_PATTERN,
[[powerpc64-*-* | powerpc64le-*-* | powerpc620-*-* | powerpc630-*-* | powerpc970-*-* | power[3-9]-*-*]])
define(X86_PATTERN,
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])
define(X86_64_PATTERN,
[[athlon64-*-* | pentium4-*-* | atom-*-* | core2-*-* | corei-*-* | x86_64-*-* | nano-*-*]])
dnl GMP_FAT_SUFFIX(DSTVAR, DIRECTORY)
dnl ---------------------------------
dnl Emit code to set shell variable DSTVAR to the suffix for a fat binary
dnl routine from DIRECTORY. DIRECTORY can be a shell expression like $foo
dnl etc.
dnl
dnl The suffix is directory separators / or \ changed to underscores, and
dnl if there's more than one directory part, then the first is dropped.
dnl
dnl For instance,
dnl
dnl x86 -> x86
dnl x86/k6 -> k6
dnl x86/k6/mmx -> k6_mmx
define(GMP_FAT_SUFFIX,
[[$1=`echo $2 | sed -e '/\//s:^[^/]*/::' -e 's:[\\/]:_:g'`]])
dnl GMP_REMOVE_FROM_LIST(listvar,item)
dnl ----------------------------------
dnl Emit code to remove any occurrence of ITEM from $LISTVAR. ITEM can be a
dnl shell expression like $foo if desired.
define(GMP_REMOVE_FROM_LIST,
[remove_from_list_tmp=
for remove_from_list_i in $[][$1]; do
if test $remove_from_list_i = [$2]; then :;
else
remove_from_list_tmp="$remove_from_list_tmp $remove_from_list_i"
fi
done
[$1]=$remove_from_list_tmp
])
dnl GMP_STRIP_PATH(subdir)
dnl ----------------------
dnl Strip entries */subdir from $path and $fat_path.
define(GMP_STRIP_PATH,
[GMP_STRIP_PATH_VAR(path, [$1])
GMP_STRIP_PATH_VAR(fat_path, [$1])
])
define(GMP_STRIP_PATH_VAR,
[tmp_path=
for i in $[][$1]; do
case $i in
*/[$2]) ;;
*) tmp_path="$tmp_path $i" ;;
esac
done
[$1]="$tmp_path"
])
dnl GMP_INCLUDE_GMP_H
dnl -----------------
dnl Expand to the right way to #include gmp-h.in. This must be used
dnl instead of gmp.h, since that file isn't generated until the end of the
dnl configure.
dnl
dnl Dummy value for GMP_LIMB_BITS is enough
dnl for all current configure-time uses of gmp.h.
define(GMP_INCLUDE_GMP_H,
[[#define __GMP_WITHIN_CONFIGURE 1 /* ignore template stuff */
#define GMP_NAIL_BITS $GMP_NAIL_BITS
#define GMP_LIMB_BITS 123
$DEFN_LONG_LONG_LIMB
#include "$srcdir/gmp-h.in"]
])
dnl GMP_HEADER_GETVAL(NAME,FILE)
dnl ----------------------------
dnl Expand at autoconf time to the value of a "#define NAME" from the given
dnl FILE. The regexps here aren't very rugged, but are enough for gmp.
dnl /dev/null as a parameter prevents a hang if $2 is accidentally omitted.
define(GMP_HEADER_GETVAL,
[patsubst(patsubst(
esyscmd([grep "^#define $1 " $2 /dev/null 2>/dev/null]),
[^.*$1[ ]+],[]),
[[
]*$],[])])
dnl GMP_VERSION
dnl -----------
dnl The gmp version number, extracted from the #defines in gmp-h.in at
dnl autoconf time. Two digits like 3.0 if patchlevel <= 0, or three digits
dnl like 3.0.1 if patchlevel > 0.
define(GMP_VERSION,
[GMP_HEADER_GETVAL(__GNU_MP_VERSION,gmp-h.in)[]dnl
.GMP_HEADER_GETVAL(__GNU_MP_VERSION_MINOR,gmp-h.in)[]dnl
.GMP_HEADER_GETVAL(__GNU_MP_VERSION_PATCHLEVEL,gmp-h.in)])
dnl GMP_SUBST_CHECK_FUNCS(func,...)
dnl ------------------------------
dnl Setup an AC_SUBST of HAVE_FUNC_01 for each argument.
AC_DEFUN([GMP_SUBST_CHECK_FUNCS],
[m4_if([$1],,,
[_GMP_SUBST_CHECK_FUNCS(ac_cv_func_[$1],HAVE_[]m4_translit([$1],[a-z],[A-Z])_01)
GMP_SUBST_CHECK_FUNCS(m4_shift($@))])])
dnl Called: _GMP_SUBST_CHECK_FUNCS(cachevar,substvar)
AC_DEFUN([_GMP_SUBST_CHECK_FUNCS],
[case $[$1] in
yes) AC_SUBST([$2],1) ;;
no) [$2]=0 ;;
esac
])
dnl GMP_SUBST_CHECK_HEADERS(foo.h,...)
dnl ----------------------------------
dnl Setup an AC_SUBST of HAVE_FOO_H_01 for each argument.
AC_DEFUN([GMP_SUBST_CHECK_HEADERS],
[m4_if([$1],,,
[_GMP_SUBST_CHECK_HEADERS(ac_cv_header_[]m4_translit([$1],[./],[__]),
HAVE_[]m4_translit([$1],[a-z./],[A-Z__])_01)
GMP_SUBST_CHECK_HEADERS(m4_shift($@))])])
dnl Called: _GMP_SUBST_CHECK_HEADERS(cachevar,substvar)
AC_DEFUN([_GMP_SUBST_CHECK_HEADERS],
[case $[$1] in
yes) AC_SUBST([$2],1) ;;
no) [$2]=0 ;;
esac
])
dnl GMP_COMPARE_GE(A1,B1, A2,B2, ...)
dnl ---------------------------------
dnl Compare two version numbers A1.A2.etc and B1.B2.etc. Set
dnl $gmp_compare_ge to yes or no according to the result. The A parts
dnl should be variables, the B parts fixed numbers. As many parts as
dnl desired can be included. An empty string in an A part is taken to be
dnl zero, the B parts should be non-empty and non-zero.
dnl
dnl For example,
dnl
dnl GMP_COMPARE($major,10, $minor,3, $subminor,1)
dnl
dnl would test whether $major.$minor.$subminor is greater than or equal to
dnl 10.3.1.
AC_DEFUN([GMP_COMPARE_GE],
[gmp_compare_ge=no
GMP_COMPARE_GE_INTERNAL($@)
])
AC_DEFUN([GMP_COMPARE_GE_INTERNAL],
[ifelse(len([$3]),0,
[if test -n "$1" && test "$1" -ge $2; then
gmp_compare_ge=yes
fi],
[if test -n "$1"; then
if test "$1" -gt $2; then
gmp_compare_ge=yes
else
if test "$1" -eq $2; then
GMP_COMPARE_GE_INTERNAL(m4_shift(m4_shift($@)))
fi
fi
fi])
])
dnl GMP_PROG_AR
dnl -----------
dnl GMP additions to $AR.
dnl
dnl A cross-"ar" may be necessary when cross-compiling since the build
dnl system "ar" might try to interpret the object files to build a symbol
dnl table index, hence the use of AC_CHECK_TOOL.
dnl
dnl A user-selected $AR is always left unchanged. AC_CHECK_TOOL is still
dnl run to get the "checking" message printed though.
dnl
dnl If extra flags are added to AR, then ac_cv_prog_AR and
dnl ac_cv_prog_ac_ct_AR are set too, since libtool (cvs 2003-03-31 at
dnl least) will do an AC_CHECK_TOOL and that will AR from one of those two
dnl cached variables. (ac_cv_prog_AR is used if there's an ac_tool_prefix,
dnl or ac_cv_prog_ac_ct_AR is used otherwise.) FIXME: This is highly
dnl dependent on autoconf internals, perhaps it'd work to put our extra
dnl flags into AR_FLAGS instead.
dnl
dnl $AR_FLAGS is set to "cq" rather than leaving it to libtool "cru". The
dnl latter fails when libtool goes into piecewise mode and is unlucky
dnl enough to have two same-named objects in separate pieces, as happens
dnl for instance to random.o (and others) on vax-dec-ultrix4.5. Naturally
dnl a user-selected $AR_FLAGS is left unchanged.
dnl
dnl For reference, $ARFLAGS is used by automake (1.8) for its ".a" archive
dnl file rules. This doesn't get used by the piecewise linking, so we
dnl leave it at the default "cru".
dnl
dnl FIXME: Libtool 1.5.2 has its own arrangements for "cq", but that version
dnl is broken in other ways. When we can upgrade, remove the forcible
dnl AR_FLAGS=cq.
AC_DEFUN([GMP_PROG_AR],
[dnl Want to establish $AR before libtool initialization.
AC_BEFORE([$0],[AC_PROG_LIBTOOL])
gmp_user_AR=$AR
AC_CHECK_TOOL(AR, ar, ar)
if test -z "$gmp_user_AR"; then
eval arflags=\"\$ar${abi1}_flags\"
test -n "$arflags" || eval arflags=\"\$ar${abi2}_flags\"
if test -n "$arflags"; then
AC_MSG_CHECKING([for extra ar flags])
AR="$AR $arflags"
ac_cv_prog_AR="$AR $arflags"
ac_cv_prog_ac_ct_AR="$AR $arflags"
AC_MSG_RESULT([$arflags])
fi
fi
if test -z "$AR_FLAGS"; then
AR_FLAGS=cq
fi
])
dnl GMP_PROG_M4
dnl -----------
dnl Find a working m4, either in $PATH or likely locations, and setup $M4
dnl and an AC_SUBST accordingly. If $M4 is already set then it's a user
dnl choice and is accepted with no checks. GMP_PROG_M4 is like
dnl AC_PATH_PROG or AC_CHECK_PROG, but tests each m4 found to see if it's
dnl good enough.
dnl
dnl See mpn/asm-defs.m4 for details on the known bad m4s.
AC_DEFUN([GMP_PROG_M4],
[AC_ARG_VAR(M4,[m4 macro processor])
AC_CACHE_CHECK([for suitable m4],
gmp_cv_prog_m4,
[if test -n "$M4"; then
gmp_cv_prog_m4="$M4"
else
cat >conftest.m4 <<\EOF
dnl Must protect this against being expanded during autoconf m4!
dnl Dont put "dnl"s in this as autoconf will flag an error for unexpanded
dnl macros.
[define(dollarhash,``$][#'')ifelse(dollarhash(x),1,`define(t1,Y)',
``bad: $][# not supported (SunOS /usr/bin/m4)
'')ifelse(eval(89),89,`define(t2,Y)',
`bad: eval() doesnt support 8 or 9 in a constant (OpenBSD 2.6 m4)
')ifelse(t1`'t2,YY,`good
')]
EOF
dnl ' <- balance the quotes for emacs sh-mode
echo "trying m4" >&AC_FD_CC
gmp_tmp_val=`(m4 conftest.m4) 2>&AC_FD_CC`
echo "$gmp_tmp_val" >&AC_FD_CC
if test "$gmp_tmp_val" = good; then
gmp_cv_prog_m4="m4"
else
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":"
dnl $ac_dummy forces splitting on constant user-supplied paths.
dnl POSIX.2 word splitting is done only on the output of word expansions,
dnl not every word. This closes a longstanding sh security hole.
ac_dummy="$PATH:/usr/5bin"
for ac_dir in $ac_dummy; do
test -z "$ac_dir" && ac_dir=.
echo "trying $ac_dir/m4" >&AC_FD_CC
gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AC_FD_CC`
echo "$gmp_tmp_val" >&AC_FD_CC
if test "$gmp_tmp_val" = good; then
gmp_cv_prog_m4="$ac_dir/m4"
break
fi
done
IFS="$ac_save_ifs"
if test -z "$gmp_cv_prog_m4"; then
AC_MSG_ERROR([No usable m4 in \$PATH or /usr/5bin (see config.log for reasons).])
fi
fi
rm -f conftest.m4
fi])
M4="$gmp_cv_prog_m4"
AC_SUBST(M4)
])
dnl GMP_M4_M4WRAP_SPURIOUS
dnl ----------------------
dnl Check for spurious output from m4wrap(), as described in mpn/asm-defs.m4.
dnl
dnl The following systems have been seen with the problem.
dnl
dnl - Unicos alpha, but its assembler doesn't seem to mind.
dnl - MacOS X Darwin, its assembler fails.
dnl - NetBSD 1.4.1 m68k, and gas 1.92.3 there gives a warning and ignores
dnl the bad last line since it doesn't have a newline.
dnl - NetBSD 1.4.2 alpha, but its assembler doesn't seem to mind.
dnl - HP-UX ia64.
dnl
dnl Enhancement: Maybe this could be in GMP_PROG_M4, and attempt to prefer
dnl an m4 with a working m4wrap, if it can be found.
AC_DEFUN([GMP_M4_M4WRAP_SPURIOUS],
[AC_REQUIRE([GMP_PROG_M4])
AC_CACHE_CHECK([if m4wrap produces spurious output],
gmp_cv_m4_m4wrap_spurious,
[# hide the d-n-l from autoconf's error checking
tmp_d_n_l=d""nl
cat >conftest.m4 <<EOF
[changequote({,})define(x,)m4wrap({x})$tmp_d_n_l]
EOF
echo test input is >&AC_FD_CC
cat conftest.m4 >&AC_FD_CC
tmp_chars=`$M4 conftest.m4 | wc -c`
echo produces $tmp_chars chars output >&AC_FD_CC
rm -f conftest.m4
if test $tmp_chars = 0; then
gmp_cv_m4_m4wrap_spurious=no
else
gmp_cv_m4_m4wrap_spurious=yes
fi
])
GMP_DEFINE_RAW(["define(<M4WRAP_SPURIOUS>,<$gmp_cv_m4_m4wrap_spurious>)"])
])
dnl GMP_PROG_NM
dnl -----------
dnl GMP additions to libtool AC_PROG_NM.
dnl
dnl Note that if AC_PROG_NM can't find a working nm it still leaves
dnl $NM set to "nm", so $NM can't be assumed to actually work.
dnl
dnl A user-selected $NM is always left unchanged. AC_PROG_NM is still run
dnl to get the "checking" message printed though.
dnl
dnl Perhaps it'd be worthwhile checking that nm works, by running it on an
dnl actual object file. For instance on sparcv9 solaris old versions of
dnl GNU nm don't recognise 64-bit objects. Checking would give a better
dnl error message than just a failure in later tests like GMP_ASM_W32 etc.
dnl
dnl On the other hand it's not really normal autoconf practice to take too
dnl much trouble over detecting a broken set of tools. And libtool doesn't
dnl do anything at all for say ranlib or strip. So for now we're inclined
dnl to just demand that the user provides a coherent environment.
AC_DEFUN([GMP_PROG_NM],
[dnl Make sure we're the first to call AC_PROG_NM, so our extra flags are
dnl used by everyone.
AC_BEFORE([$0],[AC_PROG_NM])
gmp_user_NM=$NM
AC_PROG_NM
# FIXME: When cross compiling (ie. $ac_tool_prefix not empty), libtool
# defaults to plain "nm" if a "${ac_tool_prefix}nm" is not found. In this
# case run it again to try the native "nm", firstly so that likely locations
# are searched, secondly so that -B or -p are added if necessary for BSD
# format. This is necessary for instance on OSF with "./configure
# --build=alphaev5-dec-osf --host=alphaev6-dec-osf".
#
if test -z "$gmp_user_NM" && test -n "$ac_tool_prefix" && test "$NM" = nm; then
$as_unset lt_cv_path_NM
gmp_save_ac_tool_prefix=$ac_tool_prefix
ac_tool_prefix=
NM=
AC_PROG_NM
ac_tool_prefix=$gmp_save_ac_tool_prefix
fi
if test -z "$gmp_user_NM"; then
eval nmflags=\"\$nm${abi1}_flags\"
test -n "$nmflags" || eval nmflags=\"\$nm${abi2}_flags\"
if test -n "$nmflags"; then
AC_MSG_CHECKING([for extra nm flags])
NM="$NM $nmflags"
AC_MSG_RESULT([$nmflags])
fi
fi
])
dnl GMP_PROG_CC_WORKS(cc+cflags,[ACTION-IF-WORKS][,ACTION-IF-NOT-WORKS])
dnl --------------------------------------------------------------------
dnl Check if cc+cflags can compile and link.
dnl
dnl This test is designed to be run repeatedly with different cc+cflags
dnl selections, so the result is not cached.
dnl
dnl For a native build, meaning $cross_compiling == no, we require that the
dnl generated program will run. This is the same as AC_PROG_CC does in
dnl _AC_COMPILER_EXEEXT_WORKS, and checking here will ensure we don't pass
dnl a CC/CFLAGS combination that it rejects.
dnl
dnl sparc-*-solaris2.7 can compile ABI=64 but won't run it if the kernel
dnl was booted in 32-bit mode. The effect of requiring the compiler output
dnl will run is that a plain native "./configure" falls back on ABI=32, but
dnl ABI=64 is still available as a cross-compile.
dnl
dnl The various specific problems we try to detect are done in separate
dnl compiles. Although this is probably a bit slower than one test
dnl program, it makes it easy to indicate the problem in AC_MSG_RESULT,
dnl hence giving the user a clue about why we rejected the compiler.
AC_DEFUN([GMP_PROG_CC_WORKS],
[AC_MSG_CHECKING([compiler $1])
gmp_prog_cc_works=yes
# first see a simple "main()" works, then go on to other checks
GMP_PROG_CC_WORKS_PART([$1], [])
GMP_PROG_CC_WORKS_PART([$1], [function pointer return],
[/* The following provokes an internal error from gcc 2.95.2 -mpowerpc64
(without -maix64), hence detecting an unusable compiler */
void *g() { return (void *) 0; }
void *f() { return g(); }
])
GMP_PROG_CC_WORKS_PART([$1], [cmov instruction],
[/* The following provokes an invalid instruction syntax from i386 gcc
-march=pentiumpro on Solaris 2.8. The native sun assembler
requires a non-standard syntax for cmov which gcc (as of 2.95.2 at
least) doesn't know. */
int n;
int cmov () { return (n >= 0 ? n : 0); }
])
GMP_PROG_CC_WORKS_PART([$1], [double -> ulong conversion],
[/* The following provokes a linker invocation problem with gcc 3.0.3
on AIX 4.3 under "-maix64 -mpowerpc64 -mcpu=630". The -mcpu=630
option causes gcc to incorrectly select the 32-bit libgcc.a, not
the 64-bit one, and consequently it misses out on the __fixunsdfdi
helper (double -> uint64 conversion). */
double d;
unsigned long gcc303 () { return (unsigned long) d; }
])
GMP_PROG_CC_WORKS_PART([$1], [double negation],
[/* The following provokes an error from hppa gcc 2.95 under -mpa-risc-2-0 if
the assembler doesn't know hppa 2.0 instructions. fneg is a 2.0
instruction, and a negation like this comes out using it. */
double fneg_data;
unsigned long fneg () { return -fneg_data; }
])
GMP_PROG_CC_WORKS_PART([$1], [double -> float conversion],
[/* The following makes gcc 3.3 -march=pentium4 generate an SSE2 xmm insn
(cvtsd2ss) which will provoke an error if the assembler doesn't recognise
those instructions. Not sure how much of the gmp code will come out
wanting sse2, but it's easiest to reject an option we know is bad. */
double ftod_data;
float ftod () { return (float) ftod_data; }
])
GMP_PROG_CC_WORKS_PART([$1], [gnupro alpha ev6 char spilling],
[/* The following provokes an internal compiler error from gcc version
"2.9-gnupro-99r1" under "-O2 -mcpu=ev6", apparently relating to char
values being spilled into floating point registers. The problem doesn't
show up all the time, but has occurred enough in GMP for us to reject
this compiler+flags. */
#include <string.h> /* for memcpy */
struct try_t
{
char dst[2];
char size;
long d0, d1, d2, d3, d4, d5, d6;
char overlap;
};
struct try_t param[6];
int
param_init ()
{
struct try_t *p;
memcpy (p, ¶m[ 2 ], sizeof (*p));
memcpy (p, ¶m[ 2 ], sizeof (*p));
p->size = 2;
memcpy (p, ¶m[ 1 ], sizeof (*p));
p->dst[0] = 1;
p->overlap = 2;
memcpy (p, ¶m[ 3 ], sizeof (*p));
p->dst[0] = 1;
p->overlap = 8;
memcpy (p, ¶m[ 4 ], sizeof (*p));
memcpy (p, ¶m[ 4 ], sizeof (*p));
p->overlap = 8;
memcpy (p, ¶m[ 5 ], sizeof (*p));
memcpy (p, ¶m[ 5 ], sizeof (*p));
memcpy (p, ¶m[ 5 ], sizeof (*p));
return 0;
}
])
# __builtin_alloca is not available everywhere, check it exists before
# seeing that it works
GMP_PROG_CC_WORKS_PART_TEST([$1],[__builtin_alloca availability],
[int k; int foo () { __builtin_alloca (k); }],
[GMP_PROG_CC_WORKS_PART([$1], [alloca array],
[/* The following provokes an internal compiler error from Itanium HP-UX cc
under +O2 or higher. We use this sort of code in mpn/generic/mul_fft.c. */
int k;
int foo ()
{
int i, **a;
a = __builtin_alloca (k);
for (i = 0; i <= k; i++)
a[i] = __builtin_alloca (1 << i);
}
])])
GMP_PROG_CC_WORKS_PART([$1], [abs int -> double conversion],
[/* The following provokes an internal error from the assembler on
power2-ibm-aix4.3.1.0. gcc -mrios2 compiles to nabs+fcirz, and this
results in "Internal error related to the source program domain".
For reference it seems to be the combination of nabs+fcirz which is bad,
not either alone. This sort of thing occurs in mpz/get_str.c with the
way double chars_per_bit_exactly is applied in MPN_SIZEINBASE. Perhaps
if that code changes to a scaled-integer style then we won't need this
test. */
double fp[1];
int x;
int f ()
{
int a;
a = (x >= 0 ? x : -x);
return a * fp[0];
}
])
GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 1],
[/* The following provokes a segfault in the compiler on powerpc-apple-darwin.
Extracted from tests/mpn/t-iord_u.c. Causes Apple's gcc 3.3 build 1640 and
1666 to segfault with e.g., -O2 -mpowerpc64. */
#if defined (__GNUC__) && ! defined (__cplusplus)
typedef unsigned long long t1;typedef t1*t2;
static __inline__ t1 e(t2 rp,t2 up,int n,t1 v0)
{t1 c,x,r;int i;if(v0){c=1;for(i=1;i<n;i++){x=up[i];r=x+1;rp[i]=r;}}return c;}
f(){static const struct{t1 n;t1 src[9];t1 want[9];}d[]={{1,{0},{1}},};t1 got[9];int i;
for(i=0;i<1;i++){if(e(got,got,9,d[i].n)==0)h();g(i,d[i].src,d[i].n,got,d[i].want,9);if(d[i].n)h();}}
h(){}g(){}
#else
int dummy;
#endif
])
GMP_PROG_CC_WORKS_PART([$1], [long long reliability test 2],
[/* The following provokes an internal compiler error on powerpc-apple-darwin.
Extracted from mpz/cfdiv_q_2exp.c. Causes Apple's gcc 3.3 build 1640 and
1666 to get an ICE with -O1 -mpowerpc64. */
#if defined (__GNUC__) && ! defined (__cplusplus)
f(int u){int i;long long x;x=u?~0:0;if(x)for(i=0;i<9;i++);x&=g();if(x)g();}
g(){}
#else
int dummy;
#endif
])
GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization],
[/* The following is mis-compiled by HP ia-64 cc version
cc: HP aC++/ANSI C B3910B A.05.55 [Dec 04 2003]
under "cc +O3", both in +DD32 and +DD64 modes. The mpn_lshift_com gets
inlined and its return value somehow botched to be 0 instead of 1. This
arises in the real mpn_lshift_com in mul_fft.c. A lower optimization
level, like +O2 seems ok. This code needs to be run to show the problem,
but that's fine, the offending cc is a native-only compiler so we don't
have to worry about cross compiling. */
#if ! defined (__cplusplus)
unsigned long
lshift_com (rp, up, n, cnt)
unsigned long *rp;
unsigned long *up;
long n;
unsigned cnt;
{
unsigned long retval, high_limb, low_limb;
unsigned tnc;
long i;
tnc = 8 * sizeof (unsigned long) - cnt;
low_limb = *up++;
retval = low_limb >> tnc;
high_limb = low_limb << cnt;
for (i = n - 1; i != 0; i--)
{
low_limb = *up++;
*rp++ = ~(high_limb | (low_limb >> tnc));
high_limb = low_limb << cnt;
}
return retval;
}
int
main ()
{
unsigned long cy, rp[2], up[2];
up[0] = ~ 0L;
up[1] = 0;
cy = lshift_com (rp, up, 2L, 1);
if (cy != 1L)
return 1;
return 0;
}
#else
int
main ()
{
return 0;
}
#endif
])
GMP_PROG_CC_WORKS_PART_MAIN([$1], [mpn_lshift_com optimization 2],
[/* The following is mis-compiled by Intel ia-64 icc version 1.8 under
"icc -O3", After several calls, the function writes parial garbage to
the result vector. Perhaps relates to the chk.a.nc insn. This code needs
to be run to show the problem, but that's fine, the offending cc is a
native-only compiler so we don't have to worry about cross compiling. */
#if ! defined (__cplusplus)
#include <stdlib.h>
void
lshift_com (rp, up, n, cnt)
unsigned long *rp;
unsigned long *up;
long n;
unsigned cnt;
{
unsigned long high_limb, low_limb;
unsigned tnc;
long i;
up += n;
rp += n;
tnc = 8 * sizeof (unsigned long) - cnt;
low_limb = *--up;
high_limb = low_limb << cnt;
for (i = n - 1; i != 0; i--)
{
low_limb = *--up;
*--rp = ~(high_limb | (low_limb >> tnc));
high_limb = low_limb << cnt;
}
*--rp = ~high_limb;
}
int
main ()
{
unsigned long *r, *r2;
unsigned long a[88 + 1];
long i;
for (i = 0; i < 88 + 1; i++)
a[i] = ~0L;
r = malloc (10000 * sizeof (unsigned long));
r2 = r;
for (i = 0; i < 528; i += 22)
{
lshift_com (r2, a,
i / (8 * sizeof (unsigned long)) + 1,
i % (8 * sizeof (unsigned long)));
r2 += 88 + 1;
}
if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
abort ();
return 0;
}
#else
int
main ()
{
return 0;
}
#endif
])
# A certain _GLOBAL_OFFSET_TABLE_ problem in past versions of gas, tickled
# by recent versions of gcc.
#
if test "$gmp_prog_cc_works" = yes; then
case $host in
X86_PATTERN)
# this problem only arises in PIC code, so don't need to test when
# --disable-shared. We don't necessarily have $enable_shared set to
# yes at this point, it will still be unset for the default (which is
# yes); hence the use of "!= no".
if test "$enable_shared" != no; then
GMP_PROG_CC_X86_GOT_EAX_EMITTED([$1],
[GMP_ASM_X86_GOT_EAX_OK([$1],,
[gmp_prog_cc_works="no, bad gas GOT with eax"])])
fi
;;
esac
fi
AC_MSG_RESULT($gmp_prog_cc_works)
case $gmp_prog_cc_works in
yes)
[$2]
;;
*)
[$3]
;;
esac
])
dnl Called: GMP_PROG_CC_WORKS_PART(CC+CFLAGS,FAIL-MESSAGE [,CODE])
dnl A dummy main() is appended to the CODE given.
dnl
AC_DEFUN([GMP_PROG_CC_WORKS_PART],
[GMP_PROG_CC_WORKS_PART_MAIN([$1],[$2],
[$3]
[int main () { return 0; }])
])
dnl Called: GMP_PROG_CC_WORKS_PART_MAIN(CC+CFLAGS,FAIL-MESSAGE,CODE)
dnl CODE must include a main().
dnl
AC_DEFUN([GMP_PROG_CC_WORKS_PART_MAIN],
[GMP_PROG_CC_WORKS_PART_TEST([$1],[$2],[$3],
[],
gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2]",
gmp_prog_cc_works="no[]m4_if([$2],,,[[, ]])[$2][[, program does not run]]")
])
dnl Called: GMP_PROG_CC_WORKS_PART_TEST(CC+CFLAGS,TITLE,[CODE],
dnl [ACTION-GOOD],[ACTION-BAD][ACTION-NORUN])
dnl
AC_DEFUN([GMP_PROG_CC_WORKS_PART_TEST],
[if test "$gmp_prog_cc_works" = yes; then
# remove anything that might look like compiler output to our "||" expression
rm -f conftest* a.out b.out a.exe a_out.exe
cat >conftest.c <<EOF
[$3]
EOF
echo "Test compile: [$2]" >&AC_FD_CC
gmp_compile="$1 conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
cc_works_part=yes
if test "$cross_compiling" = no; then
if AC_TRY_COMMAND([./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest]); then :;
else
cc_works_part=norun
fi
fi
else
cc_works_part=no
fi
if test "$cc_works_part" != yes; then
echo "failed program was:" >&AC_FD_CC
cat conftest.c >&AC_FD_CC
fi
rm -f conftest* a.out b.out a.exe a_out.exe
case $cc_works_part in
yes)
$4
;;
no)
$5
;;
norun)
$6
;;
esac
fi
])
dnl GMP_PROG_CC_WORKS_LONGLONG(cc+cflags,[ACTION-YES][,ACTION-NO])
dnl --------------------------------------------------------------
dnl Check that cc+cflags accepts "long long".
dnl
dnl This test is designed to be run repeatedly with different cc+cflags
dnl selections, so the result is not cached.
AC_DEFUN([GMP_PROG_CC_WORKS_LONGLONG],
[AC_MSG_CHECKING([compiler $1 has long long])
cat >conftest.c <<EOF
long long foo;
long long bar () { return foo; }
int main () { return 0; }
EOF
gmp_prog_cc_works=no
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
gmp_prog_cc_works=yes
else
echo "failed program was:" >&AC_FD_CC
cat conftest.c >&AC_FD_CC
fi
rm -f conftest* a.out b.out a.exe a_out.exe
AC_MSG_RESULT($gmp_prog_cc_works)
if test $gmp_prog_cc_works = yes; then
ifelse([$2],,:,[$2])
else
ifelse([$3],,:,[$3])
fi
])
dnl GMP_C_TEST_SIZEOF(cc/cflags,test,[ACTION-GOOD][,ACTION-BAD])
dnl ------------------------------------------------------------
dnl The given cc/cflags compiler is run to check the size of a type
dnl specified by the "test" argument. "test" can either be a string, or a
dnl variable like $foo. The value should be for instance "sizeof-long-4",
dnl to test that sizeof(long)==4.
dnl
dnl This test is designed to be run for different compiler and/or flags
dnl combinations, so the result is not cached.
dnl
dnl The idea for making an array that has a negative size if the desired
dnl condition test is false comes from autoconf AC_CHECK_SIZEOF. The cast
dnl to "long" in the array dimension also follows autoconf, apparently it's
dnl a workaround for a HP compiler bug.
AC_DEFUN([GMP_C_TEST_SIZEOF],
[echo "configure: testlist $2" >&AC_FD_CC
[gmp_sizeof_type=`echo "$2" | sed 's/sizeof-\([a-z]*\).*/\1/'`]
[gmp_sizeof_want=`echo "$2" | sed 's/sizeof-[a-z]*-\([0-9]*\).*/\1/'`]
AC_MSG_CHECKING([compiler $1 has sizeof($gmp_sizeof_type)==$gmp_sizeof_want])
cat >conftest.c <<EOF
[int
main ()
{
static int test_array [1 - 2 * (long) (sizeof ($gmp_sizeof_type) != $gmp_sizeof_want)];
test_array[0] = 0;
return 0;
}]
EOF
gmp_c_testlist_sizeof=no
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
gmp_c_testlist_sizeof=yes
fi
rm -f conftest*
AC_MSG_RESULT($gmp_c_testlist_sizeof)
if test $gmp_c_testlist_sizeof = yes; then
ifelse([$3],,:,[$3])
else
ifelse([$4],,:,[$4])
fi
])
dnl GMP_PROG_CC_IS_GNU(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
dnl -------------------------------------------------------
dnl Determine whether the given compiler is GNU C.
dnl
dnl This test is the same as autoconf _AC_LANG_COMPILER_GNU, but doesn't
dnl cache the result. The same "ifndef" style test is used, to avoid
dnl problems with syntax checking cpp's used on NeXT and Apple systems.
AC_DEFUN([GMP_PROG_CC_IS_GNU],
[cat >conftest.c <<EOF
#if ! defined (__GNUC__) || defined (__INTEL_COMPILER)
choke me
#endif
EOF
gmp_compile="$1 -c conftest.c >&AC_FD_CC"
if AC_TRY_EVAL(gmp_compile); then
rm -f conftest*
AC_MSG_CHECKING([whether $1 is gcc])
AC_MSG_RESULT(yes)
ifelse([$2],,:,[$2])
else
rm -f conftest*
ifelse([$3],,:,[$3])
fi
])
dnl GMP_PROG_CC_IS_XLC(CC,[ACTIONS-IF-YES][,ACTIONS-IF-NO])
dnl -------------------------------------------------------
dnl Determine whether the given compiler is IBM xlc (on AIX).
dnl
dnl There doesn't seem to be a preprocessor symbol to test for this, or if
dnl there is one then it's well hidden in xlc 3.1 on AIX 4.3, so just grep
dnl the man page printed when xlc is invoked with no arguments.
AC_DEFUN([GMP_PROG_CC_IS_XLC],
[gmp_command="$1 2>&1 | grep xlc >/dev/null"
if AC_TRY_EVAL(gmp_command); then
AC_MSG_CHECKING([whether $1 is xlc])
AC_MSG_RESULT(yes)
ifelse([$2],,:,[$2])
else
ifelse([$3],,:,[$3])
fi
])
dnl GMP_PROG_CC_X86_GOT_EAX_EMITTED(CC+CFLAGS, [ACTION-YES] [, ACTION-NO])
dnl ----------------------------------------------------------------------
dnl Determine whether CC+CFLAGS emits instructions using %eax with
dnl _GLOBAL_OFFSET_TABLE_. This test is for use on x86 systems.
dnl
dnl Recent versions of gcc will use %eax for the GOT in leaf functions, for
dnl instance gcc 3.3.3 with -O3. This avoids having to save and restore
dnl %ebx which otherwise usually holds the GOT, and is what gcc used in the
dnl past.
dnl
dnl %ecx and %edx are also candidates for this sort of optimization, and
dnl are used under lesser optimization levels, like -O2 in 3.3.3. FIXME:
dnl It's not quite clear what the conditions for using %eax are, we might
dnl need more test code to provoke it.
dnl
dnl The motivation for this test is that past versions of gas have bugs
dnl affecting this usage, see GMP_ASM_X86_GOT_EAX_OK.
dnl
dnl This test is not specific to gcc, other compilers might emit %eax GOT
dnl insns like this, though we've not investigated that.
dnl
dnl This is for use by compiler probing in GMP_PROG_CC_WORKS, so we doesn't
dnl cache the result.
dnl
dnl -fPIC is hard coded here, because this test is for use before libtool
dnl has established the pic options. It's right for gcc, but perhaps not
dnl other compilers.
AC_DEFUN([GMP_PROG_CC_X86_GOT_EAX_EMITTED],
[echo "Testing gcc GOT with eax emitted" >&AC_FD_CC
cat >conftest.c <<\EOF
[int foo;
int bar () { return foo; }
]EOF
tmp_got_emitted=no
gmp_compile="$1 -fPIC -S conftest.c >&AC_FD_CC 2>&1"
if AC_TRY_EVAL(gmp_compile); then
if grep "addl.*_GLOBAL_OFFSET_TABLE_.*eax" conftest.s >/dev/null; then
tmp_got_emitted=yes
fi
fi
rm -f conftest.*
echo "Result: $tmp_got_emitted" >&AC_FD_CC
if test "$tmp_got_emitted" = yes; then
ifelse([$2],,:,[$2])
else
ifelse([$3],,:,[$3])
fi
])
dnl GMP_HPC_HPPA_2_0(cc,[ACTION-IF-GOOD][,ACTION-IF-BAD])