-
Notifications
You must be signed in to change notification settings - Fork 245
/
acinclude.m4
1296 lines (1164 loc) · 41.7 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
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
#
# DESCRIPTION
#
# Check whether the given FLAG works with the current language's compiler
# or gives an error. (Warnings, however, are ignored)
#
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
# success/failure.
#
# If EXTRA-FLAGS is defined, it is added to the current language's default
# flags (e.g. CFLAGS) when the check is done. The check is thus made with
# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
# force the compiler to issue an error when a bad flag is given.
#
# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
#
# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
#
# LICENSE
#
# Copyright (c) 2008 Guido U. Draheim <[email protected]>
# Copyright (c) 2011 Maarten Bosmans <[email protected]>
# Copyright (c) 2023 Albin Ahlbäck
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 6
# This code is modified to print CC instead of *language* compiler
AC_DEFUN([AX_CHECK_COMPILE_FLAG],
[AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
AC_CACHE_CHECK([whether $CC accepts $1], CACHEVAR, [
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
AS_VAR_IF(CACHEVAR,yes,
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_COMPILE_FLAGS
# Test for CXX compiler
AC_DEFUN([AX_CXX_CHECK_COMPILE_FLAG],
[AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
AC_CACHE_CHECK([whether $CXX accepts $1], CACHEVAR, [
ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
_AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
[AS_VAR_SET(CACHEVAR,[yes])],
[AS_VAR_SET(CACHEVAR,[no])])
_AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
AS_VAR_IF(CACHEVAR,yes,
[m4_default([$2], :)],
[m4_default([$3], :)])
AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CXX_CHECK_COMPILE_FLAGS
dnl Copyright (C) 2024 Albin Ahlbäck
dnl
dnl This file is part of FLINT.
dnl
dnl FLINT is free software: you can redistribute it and/or modify it under
dnl the terms of the GNU Lesser General Public License (LGPL) as published
dnl by the Free Software Foundation; either version 3 of the License, or
dnl (at your option) any later version. See <https://www.gnu.org/licenses/>.
dnl NOTE: The first two patterns are taken from GMP. The license is down below.
define(X86_PATTERN,
[[i?86*-*-* | k[5-8]*-*-* | pentium*-*-* | athlon-*-* | viac3*-*-* | geode*-*-* | atom-*-*]])
define(X86_64_PATTERN,
[[athlon64-*-* | k8-*-* | k10-*-* | bobcat-*-* | jaguar*-*-* | bulldozer*-*-* | piledriver*-*-* | steamroller*-*-* | excavator*-*-* | zen*-*-* | pentium4-*-* | atom-*-* | silvermont-*-* | goldmont-*-* | tremont-*-* | core2-*-* | corei*-*-* | x86_64-*-* | nano-*-* | nehalem*-*-* | westmere*-*-* | sandybridge*-*-* | ivybridge*-*-* | haswell*-*-* | broadwell*-*-* | skylake*-*-* | kabylake*-*-* | icelake*-*-* | tigerlake*-*-* | rocketlake*-*-* | alderlake*-*-* | raptorlake*-*-*]])
define(ARM64_PATTERN,
[[aarch64-*-*]])
define(SLOW_VROUNDPD_PATTERN,
[[haswell* | broadwell* | skylake* | kabylake* | icelake* | tigerlake* | rocketlake* | alderlake* | raptorlake*]])
define(FAST_VROUNDPD_PATTERN,
[[znver[2-4]* | sandybridge* | ivybridge*]])
dnl FLINT_PREPROC_IFELSE(input,[action-if-true],[action-if-false])
dnl -----------------------
dnl Runs preprocessor with CFLAGS.
dnl
dnl FIXME: Autoconf states that some compilers do not accept CFLAGS in the
dnl preprocessor. Which ones is it? GCC and Clang certainly does. If it does
dnl not allow CFLAGS into preprocessor, we should just compile normally.
AC_DEFUN([FLINT_PREPROC_IFELSE],
[AC_REQUIRE([AC_PROG_CPP])
save_ac_cpp="$ac_cpp"
ac_cpp="$CPP $CFLAGS $CPPFLAGS"
AC_PREPROC_IFELSE($@)
ac_cpp="$ac_cpp"
])
dnl FLINT_ARCH
dnl -----------------------
dnl Checks compiler for architectures.
dnl
dnl NOTE: This has to be called after all CFLAGS has been gathered.
dnl
dnl FIXME: Currently only Clang and GCC. Support more compilers?
AC_DEFUN([FLINT_ARCH],
[AC_CACHE_CHECK([for host architecture],
flint_cv_arch,
[flint_cv_arch="unknown"
is_gnu="no"
AC_PREPROC_IFELSE([AC_LANG_SOURCE([
#ifndef __GNUC__
# error
error
#endif
])],
[is_gnu="yes"])
dnl We only know how to proceed with GCC or Clang
AS_VAR_IF([is_gnu],"yes",[
is_clang="no"
AC_PREPROC_IFELSE([AC_LANG_SOURCE([
#ifndef __clang__
# error
error
#endif
])],
[is_clang="yes"])
AS_VAR_IF([is_clang],"yes",[
flint_cv_arch=[`echo | $CC -v $CFLAGS -E - 2>&1 | grep "cc1" | sed -n 's/.*-target-cpu \([^ ]*\).*/\1/p'`]
],[
flint_cv_arch=[`echo | $CC -v $CFLAGS -E - 2>&1 | grep "cc1" | sed -n 's/.*-march=\([^ ]*\).*/\1/p'`]
])
])
])
])
dnl FLINT_CHECK_GMP_H(MAJOR, MINOR, PATCHLEVEL)
dnl -----------------------
dnl Checks that gmp.h can be found and that its version fullfills the version
dnl requirement.
AC_DEFUN([FLINT_CHECK_GMP_H],
[AC_CHECK_HEADER([gmp.h],,AC_MSG_ERROR([Could not find gmp.h]))
AC_MSG_CHECKING([if version of GMP is greater than $1.$2.$3])
AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
[#include <gmp.h>
],[#if (__GNU_MP_VERSION < $1) \
|| (__GNU_MP_VERSION == $1 && __GNU_MP_VERSION_MINOR < $2) \
|| (__GNU_MP_VERSION == $1 && __GNU_MP_VERSION_MINOR == $2 && __GNU_MP_VERSION_PATCHLEVEL < $3)
# error GMP version $1.$2.$3 or later is required
#endif
]
)],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([no])
AC_MSG_ERROR([GMP version $1.$2.$3 or later is required.])
)
])
dnl FLINT_CHECK_MPFR_H(MAJOR, MINOR, PATCHLEVEL)
dnl -----------------------
dnl Checks that mpfr.h can be found and that its version fullfills the version
dnl requirement.
AC_DEFUN([FLINT_CHECK_MPFR_H],
[AC_REQUIRE([FLINT_CHECK_GMP_H])
AC_CHECK_HEADER([mpfr.h],,AC_MSG_ERROR([Could not find mpfr.h]))
AC_MSG_CHECKING([if version of MPFR is greater than $1.$2.$3])
AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
[#include <mpfr.h>
],[#if (MPFR_VERSION_MAJOR < $1) \
|| (MPFR_VERSION_MAJOR == $1 && MPFR_VERSION_MINOR < $2) \
|| (MPFR_VERSION_MAJOR == $1 && MPFR_VERSION_MINOR == $2 && MPFR_VERSION_PATCHLEVEL < $3)
# error MPFR version $1.$2.$3 or later is required
#endif
]
)],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([no])
AC_MSG_ERROR([MPFR version $1.$2.$3 or later is required.])
)
])
dnl FLINT_GMP_LONG_LONG_LIMB([action-success][,action-fail])
dnl -----------------------
dnl Check if GMP uses long long limb.
AC_DEFUN([FLINT_GMP_LONG_LONG_LIMB],
[AC_REQUIRE([FLINT_CHECK_GMP_H])
AC_CACHE_CHECK([if GMP defines mp_limb_t as unsigned long long int],
flint_cv_gmp_long_long_limb,
[AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
[
#include <gmp.h>
],[
#if !defined(_LONG_LONG_LIMB)
# error mp_limb_t != unsigned long long int
#endif
]
)],
flint_cv_gmp_long_long_limb="yes",
flint_cv_gmp_long_long_limb="no"
)])
AS_VAR_IF([flint_cv_gmp_long_long_limb],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])
dnl FLINT_ABI
dnl -----------------------
dnl Checks what ABI to use. First checks if ABI is given. If none where given,
dnl check GMP's configuration.
AC_DEFUN([FLINT_ABI],
[AC_REQUIRE([FLINT_CHECK_GMP_H])
AC_ARG_VAR(ABI, [Desired ABI])
AC_CACHE_CHECK([for desired ABI],
flint_cv_abi,
[if test -n "$ABI";
then
flint_cv_abi="$ABI"
else
AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
[
#include <gmp.h>
],[
#if GMP_LIMB_BITS == 32
#error Dead man
error
#endif
]
)],
flint_cv_abi="64",
flint_cv_abi="32"
)
fi
])
])
dnl FLINT_SYSTEM_V_ABI([action-success][,action-fail])
dnl -----------------------
dnl Checks if System V ABI.
dnl Do "action-success" if this succeeds, "action-fail" if not.
AC_DEFUN([FLINT_SYSTEM_V_ABI],
[AC_CACHE_CHECK([if system uses System V ABI],
flint_cv_system_v_abi,
AC_PREPROC_IFELSE([AC_LANG_PROGRAM([],[
#if !(defined(__APPLE__) || defined(__unix__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)) || defined(__CYGWIN__)
#error Dead man
error
#endif
])],
[flint_cv_system_v_abi="yes"],
[flint_cv_system_v_abi="no"]
))
AS_VAR_IF([flint_cv_system_v_abi],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])
dnl FLINT_CHECK_ADX([action-success][,action-fail])
dnl -----------------------
dnl Checks if CPU supports the ADX instruction set. Will only run if CPU is
dnl x86_64. Do "action-success" if this succeeds, "action-fail" if not.
AC_DEFUN([FLINT_CHECK_ADX],
[AS_VAR_IF([host_cpu],"x86_64",
[AC_CACHE_CHECK([if ADX instruction set is supported by CPU],
flint_cv_check_adx,
FLINT_PREPROC_IFELSE([AC_LANG_SOURCE([
#if !defined(__ADX__)
#error Dead man
error
#endif
])],
flint_cv_check_adx="yes",
flint_cv_check_adx="no")
)])
AS_VAR_IF(flint_cv_check_adx,yes,
[m4_default([$1], :)],
[m4_default([$2], :)])
])
dnl FLINT_HAVE_ASM([action-success][,action-fail])
dnl -----------------------
dnl Checks if system use FLINT's assembly.
dnl Do "action-success" if this succeeds, "action-fail" if not.
AC_DEFUN([FLINT_HAVE_ASM],
[AC_REQUIRE([FLINT_ABI])
AC_REQUIRE([FLINT_SYSTEM_V_ABI])
AC_REQUIRE([FLINT_CHECK_ADX])
AC_CACHE_CHECK([if system can use FLINT's assembly],
flint_cv_have_asm,
[flint_cv_have_asm="no"
if test "$flint_cv_abi" = "64" && test "$flint_cv_system_v_abi" = "yes";
then
if test "$flint_cv_check_adx" = "yes";
then
flint_cv_have_asm="yes"
fi
fi])
AS_VAR_IF([flint_cv_have_asm],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])
dnl FLINT_HAVE_FFT_SMALL_ARM_H
dnl -----------------------
dnl Checks if system have headers for fft_small on Arm. Will only run if on
dnl arm64.
AC_DEFUN([FLINT_HAVE_FFT_SMALL_ARM_H],
[AS_VAR_IF([host_cpu],"aarch64",
[AC_CHECK_HEADER([arm_neon.h],flint_cv_have_fft_small_arm_h="yes")]
)])
dnl FLINT_HAVE_FFT_SMALL_ARM_I
dnl -----------------------
dnl Checks if system supports Arm NEON instructions.
AC_DEFUN([FLINT_HAVE_FFT_SMALL_ARM_I],
[AS_VAR_IF([host_cpu],"aarch64",
[AC_CACHE_CHECK([if system have required Arm instruction set for fft_small],
flint_cv_have_fft_small_arm_i,
FLINT_PREPROC_IFELSE([AC_LANG_SOURCE([
#ifndef __ARM_NEON
#error Dead man
error
#endif
])],
flint_cv_have_fft_small_arm_i="yes",
flint_cv_have_fft_small_arm_i="no")
)]
)])
dnl FLINT_HAVE_FFT_SMALL_X86_H
dnl -----------------------
dnl Checks if system have headers for fft_small on x86.
AC_DEFUN([FLINT_HAVE_FFT_SMALL_X86_H],
[AS_VAR_IF([host_cpu],"x86_64",
[AC_CHECK_HEADERS([immintrin.h],
flint_cv_have_fft_small_x86_h="yes",
flint_cv_have_fft_small_x86_h="no")]
)])
dnl FLINT_HAVE_FFT_SMALL_X86_I
dnl -----------------------
dnl Checks if system supports AVX2 instructions.
AC_DEFUN([FLINT_HAVE_FFT_SMALL_X86_I],
[AS_VAR_IF([host_cpu],"x86_64",
[AC_CACHE_CHECK([if system have required x86_64 instruction set for fft_small],
flint_cv_have_fft_small_x86_i,
FLINT_PREPROC_IFELSE([AC_LANG_SOURCE([
#if !defined(__AVX2__)
#error Dead man
error
#endif
])],
flint_cv_have_fft_small_x86_i="yes",
flint_cv_have_fft_small_x86_i="no")
)]
)])
dnl FLINT_CHECK_FFT_SMALL([action-success][,action-fail])
dnl -----------------------
dnl Checks if fft_small module is available.
dnl Do "action-success" if this succeeds, "action-fail" if not.
AC_DEFUN([FLINT_CHECK_FFT_SMALL],
[AC_REQUIRE([FLINT_ABI])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_ARM_H])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_ARM_I])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_X86_H])
AC_REQUIRE([FLINT_HAVE_FFT_SMALL_X86_I])
AC_CACHE_CHECK([if system can use FLINT's fft_small module],
flint_cv_check_fft_small,
[flint_cv_check_fft_small="no"
if test "$flint_cv_abi" = "64";
then
if test "$flint_cv_have_fft_small_arm_h" = "yes" && test "$flint_cv_have_fft_small_arm_i" = "yes";
then
flint_cv_check_fft_small="yes"
fi
if test "$flint_cv_have_fft_small_x86_h" = "yes" && test "$flint_cv_have_fft_small_x86_i" = "yes";
then
flint_cv_check_fft_small="yes"
fi
fi
])
AS_VAR_IF([flint_cv_check_fft_small],"yes",
[m4_default([$1], :)],
[m4_default([$2], :)])
])
dnl GMP specific autoconf macros
dnl (Taken from GMP 6.3.0)
dnl
dnl Copyright 2000-2006, 2009, 2011, 2013-2018 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 either:
dnl
dnl * the GNU Lesser General Public License as published by the Free
dnl Software Foundation; either version 3 of the License, or (at your
dnl option) any later version.
dnl
dnl or
dnl
dnl * the GNU General Public License as published by the Free Software
dnl Foundation; either version 2 of the License, or (at your option) any
dnl later version.
dnl
dnl or both in parallel, as here.
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 General Public License
dnl for more details.
dnl
dnl You should have received copies of the GNU General Public License and the
dnl GNU Lesser General Public License along with the GNU MP Library. If not,
dnl see https://www.gnu.org/licenses/.
dnl GMP_INIT([M4-DEF-FILE])
dnl -----------------------
dnl Initializations for GMP config.m4 generation.
dnl
dnl FIXME: The generated config.m4 doesn't get recreated by config.status.
dnl Maybe the relevant "echo"s should go through AC_CONFIG_COMMANDS.
dnl NOTE: This is different from GMP.
AC_DEFUN([GMP_INIT],
[ifelse([$1], , gmp_configm4=config.m4, gmp_configm4="[$1]")
gmp_tmpconfigm4=cnfm4.tmp
gmp_tmpconfigm4i=cnfm4i.tmp
gmp_tmpconfigm4p=cnfm4p.tmp
rm -f $gmp_tmpconfigm4 $gmp_tmpconfigm4i $gmp_tmpconfigm4p
# All CPUs use asm-defs.m4
echo ["include][(\`src/mpn_extras/asm-defs.m4')"] >>$gmp_tmpconfigm4i
])
dnl GMP_FINISH
dnl ----------
dnl Create config.m4 from its accumulated parts.
dnl
dnl __CONFIG_M4_INCLUDED__ is used so that a second or subsequent include
dnl of config.m4 is harmless.
dnl
dnl A separate ifdef on the angle bracket quoted part ensures the quoting
dnl style there is respected. The basic defines from gmp_tmpconfigm4 are
dnl fully quoted but are still put under an ifdef in case any have been
dnl redefined by one of the m4 include files.
dnl
dnl Doing a big ifdef within asm-defs.m4 and/or other macro files wouldn't
dnl work, since it'd interpret parentheses and quotes in dnl comments, and
dnl having a whole file as a macro argument would overflow the string space
dnl on BSD m4.
AC_DEFUN([GMP_FINISH],
[AC_REQUIRE([GMP_INIT])
echo "creating $gmp_configm4"
echo ["d""nl $gmp_configm4. Generated automatically by configure."] > $gmp_configm4
if test -f $gmp_tmpconfigm4; then
echo ["changequote(<,>)"] >> $gmp_configm4
echo ["ifdef(<__CONFIG_M4_INCLUDED__>,,<"] >> $gmp_configm4
cat $gmp_tmpconfigm4 >> $gmp_configm4
echo [">)"] >> $gmp_configm4
echo ["changequote(\`,')"] >> $gmp_configm4
rm $gmp_tmpconfigm4
fi
echo ["ifdef(\`__CONFIG_M4_INCLUDED__',,\`"] >> $gmp_configm4
if test -f $gmp_tmpconfigm4i; then
cat $gmp_tmpconfigm4i >> $gmp_configm4
rm $gmp_tmpconfigm4i
fi
if test -f $gmp_tmpconfigm4p; then
cat $gmp_tmpconfigm4p >> $gmp_configm4
rm $gmp_tmpconfigm4p
fi
echo ["')"] >> $gmp_configm4
echo ["define(\`__CONFIG_M4_INCLUDED__')"] >> $gmp_configm4
])
dnl GMP_INCLUDE_MPN(FILE)
dnl ---------------------
dnl Add an include_mpn(`FILE') to config.m4. FILE should be a path
dnl relative to the mpn source directory, for example
dnl
dnl GMP_INCLUDE_MPN(`x86/x86-defs.m4')
dnl
AC_DEFUN([GMP_INCLUDE_MPN],
[AC_REQUIRE([GMP_INIT])
echo ["include(\`$1')"] >> $gmp_tmpconfigm4i
])
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(eval(9,9),10,`define(t3,Y)',
`bad: eval() doesnt support radix in eval (FreeBSD 8.x,9.0,9.1,9.2 m4)
')ifelse(t1`'t2`'t3,YYY,`good
')]
EOF
dnl ' <- balance the quotes for emacs sh-mode
echo "trying m4" >&AS_MESSAGE_LOG_FD
gmp_tmp_val=`(m4 conftest.m4) 2>&AS_MESSAGE_LOG_FD`
echo "$gmp_tmp_val" >&AS_MESSAGE_LOG_FD
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" >&AS_MESSAGE_LOG_FD
gmp_tmp_val=`($ac_dir/m4 conftest.m4) 2>&AS_MESSAGE_LOG_FD`
echo "$gmp_tmp_val" >&AS_MESSAGE_LOG_FD
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_PATH_NM
dnl -----------
dnl GMP additions to libtool LT_PATH_NM.
dnl
dnl Note that if LT_PATH_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. LT_PATH_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_PATH_NM],
[
gmp_user_NM=$NM
dnl Is already called in LT_INIT
dnl LT_PATH_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=
LT_PATH_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_DEFINE(MACRO, DEFINITION [, LOCATION])
dnl ------------------------------------------
dnl Define M4 macro MACRO as DEFINITION in temporary file.
dnl
dnl If LOCATION is `POST', the definition will appear after any include()
dnl directives inserted by GMP_INCLUDE. Mind the quoting! No shell
dnl variables will get expanded. Don't forget to invoke GMP_FINISH to
dnl create file config.m4. config.m4 uses `<' and '>' as quote characters
dnl for all defines.
AC_DEFUN([GMP_DEFINE],
[AC_REQUIRE([GMP_INIT])
echo ['define(<$1>, <$2>)'] >>ifelse([$3], [POST],
$gmp_tmpconfigm4p, $gmp_tmpconfigm4)
])
dnl GMP_DEFINE_RAW(STRING [, LOCATION])
dnl ------------------------------------
dnl Put STRING into config.m4 file.
dnl
dnl If LOCATION is `POST', the definition will appear after any include()
dnl directives inserted by GMP_INCLUDE. Don't forget to invoke GMP_FINISH
dnl to create file config.m4.
AC_DEFUN([GMP_DEFINE_RAW],
[AC_REQUIRE([GMP_INIT])
echo [$1] >> ifelse([$2], [POST], $gmp_tmpconfigm4p, $gmp_tmpconfigm4)
])
dnl GMP_TRY_ASSEMBLE(asm-code,[action-success][,action-fail])
dnl ----------------------------------------------------------
dnl Attempt to assemble the given code.
dnl Do "action-success" if this succeeds, "action-fail" if not.
dnl
dnl conftest.o and conftest.out are available for inspection in
dnl "action-success". If either action does a "break" out of a loop then
dnl an explicit "rm -f conftest*" will be necessary.
dnl
dnl This is not unlike AC_TRY_COMPILE, but there's no default includes or
dnl anything in "asm-code", everything wanted must be given explicitly.
AC_DEFUN([GMP_TRY_ASSEMBLE],
[cat >conftest.s <<EOF
[$1]
EOF
gmp_assemble="$CC -c $CFLAGS $CPPFLAGS conftest.s >conftest.out 2>&1"
if AC_TRY_EVAL(gmp_assemble); then
cat conftest.out >&AS_MESSAGE_LOG_FD
ifelse([$2],,:,[$2])
else
cat conftest.out >&AS_MESSAGE_LOG_FD
echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
cat conftest.s >&AS_MESSAGE_LOG_FD
ifelse([$3],,:,[$3])
fi
rm -f conftest*
])
dnl GMP_ASM_LABEL_SUFFIX
dnl --------------------
dnl : - is usual.
dnl empty - hppa on HP-UX doesn't use a :, just the label name
dnl
dnl Note that it's necessary to test the empty case first, since HP "as"
dnl will accept "somelabel:", and take it to mean a label with a name that
dnl happens to end in a colon.
AC_DEFUN([GMP_ASM_LABEL_SUFFIX],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_CACHE_CHECK([for assembler label suffix],
gmp_cv_asm_label_suffix,
[gmp_cv_asm_label_suffix=unknown
for i in "" ":"; do
echo "trying $i" >&AS_MESSAGE_LOG_FD
GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_text
somelabel$i],
[gmp_cv_asm_label_suffix=$i
rm -f conftest*
break],
[cat conftest.out >&AS_MESSAGE_LOG_FD])
done
if test "$gmp_cv_asm_label_suffix" = "unknown"; then
AC_MSG_ERROR([Cannot determine label suffix])
fi
])
echo ["define(<LABEL_SUFFIX>, <$gmp_cv_asm_label_suffix>)"] >> $gmp_tmpconfigm4
])
dnl GMP_ASM_UNDERSCORE
dnl ------------------
dnl Determine whether global symbols need to be prefixed with an underscore.
dnl The output from "nm" is grepped to see what a typical symbol looks like.
dnl
dnl This test used to grep the .o file directly, but that failed with greps
dnl that don't like binary files (eg. SunOS 4).
dnl
dnl This test also used to construct an assembler file with and without an
dnl underscore and try to link that to a C file, to see which worked.
dnl Although that's what will happen in the real build we don't really want
dnl to depend on creating asm files within configure for every possible CPU
dnl (or at least we don't want to do that more than we have to).
dnl
dnl The fallback on no underscore is based on the assumption that the world
dnl is moving towards non-underscore systems. There should actually be no
dnl good reason for nm to fail though.
AC_DEFUN([GMP_ASM_UNDERSCORE],
[AC_REQUIRE([GMP_PATH_NM])
AC_CACHE_CHECK([if globals are prefixed by underscore],
gmp_cv_asm_underscore,
[gmp_cv_asm_underscore="unknown"
cat >conftest.c <<EOF
int gurkmacka;
EOF
gmp_compile="$CC $CFLAGS $CPPFLAGS -c conftest.c >&AS_MESSAGE_LOG_FD"
if AC_TRY_EVAL(gmp_compile); then
$NM conftest.$OBJEXT >conftest.out
if grep "[[ ]]_gurkmacka" conftest.out >/dev/null; then
gmp_cv_asm_underscore=yes
elif grep "[[ ]]gurkmacka" conftest.out >/dev/null; then
gmp_cv_asm_underscore=no
else
echo "configure: $NM doesn't have gurkmacka:" >&AS_MESSAGE_LOG_FD
cat conftest.out >&AS_MESSAGE_LOG_FD
fi
else
echo "configure: failed program was:" >&AS_MESSAGE_LOG_FD
cat conftest.c >&AS_MESSAGE_LOG_FD
fi
rm -f conftest*
])
case $gmp_cv_asm_underscore in
yes)
GMP_DEFINE(GSYM_PREFIX, [_]) ;;
no)
GMP_DEFINE(GSYM_PREFIX, []) ;;
*)
AC_MSG_WARN([+----------------------------------------------------------])
AC_MSG_WARN([| Cannot determine global symbol prefix.])
AC_MSG_WARN([| $NM output doesn't contain a global data symbol.])
AC_MSG_WARN([| Will proceed with no underscore.])
AC_MSG_WARN([| If this is wrong then you'll get link errors referring])
AC_MSG_WARN([| to ___gmpn_add_n (note three underscores).])
AC_MSG_WARN([| In this case do a fresh build with an override,])
AC_MSG_WARN([| ./configure gmp_cv_asm_underscore=yes])
AC_MSG_WARN([+----------------------------------------------------------])
GMP_DEFINE(GSYM_PREFIX, [])
;;
esac
])
dnl GMP_ASM_ALIGN_LOG
dnl -----------------
dnl Is parameter to `.align' logarithmic?
AC_DEFUN([GMP_ASM_ALIGN_LOG],
[AC_REQUIRE([GMP_ASM_GLOBL])
AC_REQUIRE([GMP_ASM_BYTE])
AC_REQUIRE([GMP_ASM_DATA])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_REQUIRE([GMP_PATH_NM])
AC_CACHE_CHECK([if .align assembly directive is logarithmic],
gmp_cv_asm_align_log,
[GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_data
.align 4
$gmp_cv_asm_globl foo
$gmp_cv_asm_byte 1
.align 4
foo$gmp_cv_asm_label_suffix
$gmp_cv_asm_byte 2],
[gmp_tmp_val=[`$NM conftest.$OBJEXT | grep foo | \
sed -e 's;[[][0-9][]]\(.*\);\1;' -e 's;[^1-9]*\([0-9]*\).*;\1;'`]
if test "$gmp_tmp_val" = "10" || test "$gmp_tmp_val" = "16"; then
gmp_cv_asm_align_log=yes
else
gmp_cv_asm_align_log=no
fi],
[AC_MSG_ERROR([cannot assemble alignment test])])])
GMP_DEFINE_RAW(["define(<ALIGN_LOGARITHMIC>,<$gmp_cv_asm_align_log>)"])
])
dnl GMP_ASM_ALIGN_FILL_0x90
dnl -----------------------
dnl Determine whether a ",0x90" suffix works on a .align directive.
dnl This is only meant for use on x86, 0x90 being a "nop".
dnl
dnl Old gas, eg. 1.92.3
dnl Needs ",0x90" or else the fill is 0x00, which can't be executed
dnl across.
dnl
dnl New gas, eg. 2.91
dnl Generates multi-byte nop fills even when ",0x90" is given.
dnl
dnl Solaris 2.6 as
dnl ",0x90" is not allowed, causes a fatal error.
dnl
dnl Solaris 2.8 as
dnl ",0x90" does nothing, generates a warning that it's being ignored.
dnl
dnl SCO OpenServer 5 as
dnl Second parameter is max bytes to fill, not a fill pattern.
dnl ",0x90" is an error due to being bigger than the first parameter.
dnl Multi-byte nop fills are generated in text segments.
dnl
dnl Note that both solaris "as"s only care about ",0x90" if they actually
dnl have to use it to fill something, hence the .byte in the test. It's
dnl the second .align which provokes the error or warning.
dnl
dnl The warning from solaris 2.8 is suppressed to stop anyone worrying that
dnl something might be wrong.
AC_DEFUN([GMP_ASM_ALIGN_FILL_0x90],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_CACHE_CHECK([if the .align directive accepts an 0x90 fill in .text],
gmp_cv_asm_align_fill_0x90,
[GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_text
.align 4, 0x90
.byte 0
.align 4, 0x90],
[if grep "Warning: Fill parameter ignored for executable section" conftest.out >/dev/null; then
echo "Suppressing this warning by omitting 0x90" 1>&AS_MESSAGE_LOG_FD
gmp_cv_asm_align_fill_0x90=no
else
gmp_cv_asm_align_fill_0x90=yes
fi],
[gmp_cv_asm_align_fill_0x90=no])])
GMP_DEFINE_RAW(["define(<ALIGN_FILL_0x90>,<$gmp_cv_asm_align_fill_0x90>)"])
])
dnl GMP_ASM_BYTE
dnl ------------
dnl .byte - is usual.
dnl data1 - required by ia64 (on hpux at least).
dnl
dnl This macro is just to support other configure tests, not any actual asm
dnl code.
AC_DEFUN([GMP_ASM_BYTE],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_CACHE_CHECK([for assembler byte directive],
gmp_cv_asm_byte,
[for i in .byte data1; do
echo "trying $i" >&AS_MESSAGE_LOG_FD
GMP_TRY_ASSEMBLE(
[ $gmp_cv_asm_data
$i 0
],
[gmp_cv_asm_byte=$i
rm -f conftest*
break],
[cat conftest.out >&AS_MESSAGE_LOG_FD])
done
if test -z "$gmp_cv_asm_byte"; then
AC_MSG_ERROR([Cannot determine how to emit a data byte])
fi
])
])
dnl GMP_ASM_TEXT
dnl ------------
dnl .text - is usual.
dnl .code - is needed by the hppa on HP-UX (but ia64 HP-UX uses .text)
dnl .csect .text[PR] - is for AIX.
AC_DEFUN([GMP_ASM_TEXT],
[AC_CACHE_CHECK([how to switch to text section],
gmp_cv_asm_text,
[for i in ".text" ".code" [".csect .text[PR]"]; do
echo "trying $i" >&AS_MESSAGE_LOG_FD
GMP_TRY_ASSEMBLE([ $i],
[gmp_cv_asm_text=$i
rm -f conftest*
break])
done
if test -z "$gmp_cv_asm_text"; then
AC_MSG_ERROR([Cannot determine text section directive])
fi
])
echo ["define(<TEXT>, <$gmp_cv_asm_text>)"] >> $gmp_tmpconfigm4
])
dnl GMP_ASM_DATA
dnl ------------
dnl Can we say `.data'?
AC_DEFUN([GMP_ASM_DATA],
[AC_CACHE_CHECK([how to switch to data section],
gmp_cv_asm_data,
[case $host in
*-*-aix*) gmp_cv_asm_data=[".csect .data[RW]"] ;;
*) gmp_cv_asm_data=".data" ;;
esac
])
echo ["define(<DATA>, <$gmp_cv_asm_data>)"] >> $gmp_tmpconfigm4
])
dnl GMP_ASM_RODATA
dnl --------------
dnl Find out how to switch to the read-only data section.
dnl
dnl The compiler output is grepped for the right directive. It's not
dnl considered wise to just probe for ".section .rodata" or whatever works,
dnl since arbitrary section names might be accepted, but not necessarily do
dnl the right thing when they get to the linker.
dnl
dnl Only a few asm files use RODATA, so this code is perhaps a bit
dnl excessive right now, but should find more uses in the future.
dnl
dnl FIXME: gcc on aix generates something like ".csect _foo.ro_c[RO],3"
dnl where foo is the object file. Might need to check for that if we use
dnl RODATA there.
AC_DEFUN([GMP_ASM_RODATA],
[AC_REQUIRE([GMP_ASM_TEXT])
AC_REQUIRE([GMP_ASM_DATA])
AC_REQUIRE([GMP_ASM_LABEL_SUFFIX])
AC_REQUIRE([GMP_ASM_UNDERSCORE])
AC_CACHE_CHECK([how to switch to read-only data section],
gmp_cv_asm_rodata,
[
dnl Default to DATA on CPUs with split code/data caching, and TEXT
dnl elsewhere. i386 means generic x86, so use DATA on it.