forked from matrix-construct/construct
-
Notifications
You must be signed in to change notification settings - Fork 7
/
configure.ac
3342 lines (2827 loc) · 86.8 KB
/
configure.ac
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
AC_PREREQ([2.63])
AUTOMAKE_OPTIONS = 1.11
AC_INIT([Construct],[1])
AC_GNU_SOURCE
AC_USE_SYSTEM_EXTENSIONS
AC_CANONICAL_HOST
AC_CANONICAL_BUILD
AC_CANONICAL_TARGET
AC_PREFIX_DEFAULT([/])
AC_CONFIG_MACRO_DIR([tools/m4])
AC_CONFIG_HEADER(include/ircd/config.h)
AC_PATH_PROG(AUTOMAKE, automake)
AC_PATH_PROG(ACLOCAL, aclocal)
AC_PATH_PROG(AUTOHEADER, autoheader)
AC_PATH_PROG(AS, as)
AC_PATH_PROG(RM, rm)
AC_PATH_PROG(CP, cp)
AC_PATH_PROG(MV, mv)
AC_PATH_PROG(LN, ln)
AC_PATH_PROG(LDGOLD, ld.gold)
AC_PATH_PROG(LDLLD, ld.lld)
AC_PATH_PROG(LD, ld.gold)
AC_PATH_PROG(XXD, xxd)
AC_PATH_PROG(TOUCH, touch)
AC_SUBST(CFLAGS, "-pipe $CFLAGS")
AC_SUBST(CXXFLAGS, "-pipe $CXXFLAGS")
AC_SUBST(CCASFLAGS, "$CCASFLAGS")
LT_INIT([dlopen shared disable-static])
LT_LANG([C++])
AM_PROG_AS
AC_PROG_CXX
AC_PROG_CXX_C_O
AC_PROG_LIBTOOL
AC_PROG_MAKE_SET
AC_LANG(C++)
AX_CXX_COMPILE_STDCXX([20], [gnu], [mandatory], 202002)
dnl ***************************************************************************
dnl
dnl Makefile tree
dnl
dnl These (and Makefile.in) are generated from a Makefile.am in the same dir.
dnl
AC_CONFIG_FILES(\
Makefile \
include/ircd/Makefile \
construct/Makefile \
ircd/Makefile \
matrix/Makefile \
modules/Makefile \
share/Makefile \
)
AM_INIT_AUTOMAKE([subdir-objects])
dnl If this is not (un)set, paths are added such as -I../include/ircd to every
dnl build command and that isn't nice because it makes our headers conflict
dnl with standard library/path headers which we don't want or need.
AC_SUBST(DEFAULT_INCLUDES, [])
dnl
dnl Recursive local targets (clean-local is implied)
dnl
#AM_EXTRA_RECURSIVE_TARGETS([
# mrproper
#])
dnl ***************************************************************************
dnl
dnl Platform
dnl
dnl
dnl Hardwares
dnl
AM_CONDITIONAL([AMD64], [[[[ $host_cpu = *x86_64* ]]]])
AM_CONDITIONAL([X86_64], [[[[ $host_cpu = *x86_64* ]]]])
AM_CONDITIONAL([ARM64], [[[[ $host_cpu = *aarch64* ]]]])
AM_CONDITIONAL([AARCH64], [[[[ $host_cpu = *aarch64* ]]]])
dnl
dnl Compiler brand
dnl
AM_CONDITIONAL([GCC], [[[[ $CXX = g\+\+* ]]]])
AM_CONDITIONAL([CLANG], [[[[ $CXX = clang* ]]]])
RB_DEFINE_UNQUOTED([CXX], ["$CXX"], [CXX Compiler])
dnl
dnl Compiler version
dnl
AX_CXX_VERSION
RB_DEFINE_UNQUOTED([CXX_VERSION], ["$CXX_VERSION"], [CXX Compiler Version])
AX_CXX_EPOCH
RB_DEFINE_UNQUOTED([CXX_EPOCH], [$CXX_EPOCH], [CXX Compiler Version (major nr)])
AM_CONDITIONAL([GCC8], [[[[ $CXX = g\+\+* ]] && [[ $CXX_EPOCH -ge 8 ]]]])
AM_CONDITIONAL([GCC9], [[[[ $CXX = g\+\+* ]] && [[ $CXX_EPOCH -ge 9 ]]]])
AM_CONDITIONAL([GCC10], [[[[ $CXX = g\+\+* ]] && [[ $CXX_EPOCH -ge 10 ]]]])
AM_CONDITIONAL([GCC11], [[[[ $CXX = g\+\+* ]] && [[ $CXX_EPOCH -ge 11 ]]]])
AM_CONDITIONAL([GCC12], [[[[ $CXX = g\+\+* ]] && [[ $CXX_EPOCH -ge 12 ]]]])
AM_CONDITIONAL([GCC13], [[[[ $CXX = g\+\+* ]] && [[ $CXX_EPOCH -ge 13 ]]]])
AM_CONDITIONAL([CLANG8], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 8 ]]]])
AM_CONDITIONAL([CLANG9], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 9 ]]]])
AM_CONDITIONAL([CLANG10], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 10 ]]]])
AM_CONDITIONAL([CLANG11], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 11 ]]]])
AM_CONDITIONAL([CLANG12], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 12 ]]]])
AM_CONDITIONAL([CLANG13], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 13 ]]]])
AM_CONDITIONAL([CLANG14], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 14 ]]]])
AM_CONDITIONAL([CLANG15], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 15 ]]]])
AM_CONDITIONAL([CLANG16], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 16 ]]]])
AM_CONDITIONAL([CLANG17], [[[[ $CXX = clang* ]] && [[ $CXX_EPOCH -ge 17 ]]]])
dnl
dnl Coarse operating system test macros
dnl
AM_CONDITIONAL([LINUX], [[[[ $host_os = *linux* ]]]])
AM_CONDITIONAL([NETBSD], [[[[ $host_os = *netbsd* ]]]])
AM_CONDITIONAL([FREEBSD], [[[[ $host_os = *freebsd* ]]]])
AM_CONDITIONAL([MINGW], [[[[ $host_os = *mingw* ]] || [[ $host_os = *msys* ]]]])
AM_CONDITIONAL([CYGWIN], [[[[ $host_os = *cygwin* ]]]])
AM_CONDITIONAL([INTERIX], [[[[ $host_os = *interix* ]]]])
AM_CONDITIONAL([SOLARIS], [[[[ $host_os = *solaris* ]]]])
RB_DEFINE_UNQUOTED([OS], ["$host_os"], [Host operating system])
dnl
dnl Standard libraries
dnl
AC_SEARCH_LIBS([__dynamic_cast], [c++], [],
[
AC_MSG_ERROR([Please install libstdc++ on this system.])
])
dnl ***************************************************************************
dnl
dnl Developer options
dnl
dnl
dnl Debugging mode
dnl
AC_MSG_CHECKING(whether to enable debugging)
AC_ARG_ENABLE(debug, RB_HELP_STRING([--enable-debug=[[no]]], [Enable debugging suite for development]),
[
debug=$enableval
], [
debug="no"
])
AC_MSG_RESULT([$debug])
AM_CONDITIONAL([DEBUG], [[[[ "$debug" = "yes" ]]]])
AM_COND_IF([DEBUG],
[
AC_SUBST(DEBUG, 1)
RB_DEFINE_UNQUOTED([DEBUG], [1], [Not configured for release when lit.])
RB_DEFINE_UNQUOTED([DEBUG_LEVEL], [1], [Defined to 0 for release; or > 0 otherwise])
], [
RB_DEFINE_UNQUOTED([DEBUG_LEVEL], [0], [Defined to 0 for release; or > 0 otherwise])
])
dnl
dnl Compactness
dnl
AC_MSG_CHECKING(Optimize for size; strip symbols; force no debugging)
AC_ARG_ENABLE(compact, RB_HELP_STRING([--enable-compact], [Optimize for size and compactness]),
[
compact=$enableval
], [
compact="no"
])
AC_MSG_RESULT([$compact])
AM_CONDITIONAL([COMPACT], [[[[ "$compact" = "yes" ]]]])
AM_COND_IF([COMPACT],
[
AC_SUBST(COMPACT, 1)
RB_DEFINE_UNQUOTED([COMPACT], [1], [Not configured for compactness when lit.])
])
dnl
dnl Explicit assert switch for still using assert() without --enable-debug
dnl
AC_MSG_CHECKING(whether to explicitly enable assertions)
AC_ARG_ENABLE(assert, RB_HELP_STRING([--enable-assert], [Enable assertions without --enable-debug]),
[
assert=$enableval
AC_MSG_RESULT([$assert])
], [
AM_COND_IF(DEBUG,
[
assert="yes"
AC_MSG_RESULT([$assert, enabled by default with --enable-debug])
], [
assert="no"
AC_MSG_RESULT([$assert])
])
])
AM_CONDITIONAL([ASSERT], [[[[ "$assert" = "yes" ]]]])
AM_COND_IF(ASSERT,
[
assert_type="abort"
AC_SUBST(ASSERT, 1)
], [
CPPDEFINE([NDEBUG])
])
dnl
dnl Switch to control the action of assert()
dnl
AC_MSG_CHECKING(what the result of a failed assertion implies)
AC_ARG_WITH(assert, RB_HELP_STRING([--with-assert[[[=abort]]]], [Change assertion behavior]),
[
assert_type=$withval
])
AM_COND_IF(ASSERT,
[
AC_MSG_RESULT([$assert_type])
AC_SUBST(ASSERT_TYPE, $assert_type)
if [[ ! -z "$assert_type" ]]; then
if [[ "$assert_type" != "abort" ]]; then
RB_DEFINE_UNQUOTED([ASSERT], ["$assert_type"], [Assertion behavior])
fi
if [[ "$assert_type" == "trap" ]]; then
RB_DEFINE([ASSERT_INTRINSIC], [1], [Intrinsic assertion behavior])
fi
if [[ "$assert_type" == "opt" ]]; then
RB_DEFINE([ASSERT_OPTIMISTIC], [1], [Optimistic assertion behavior])
fi
fi
], [
AC_MSG_RESULT([nothing without assertions enabled])
assert_type=""
])
dnl
dnl Explicit optimize switch for enabling optimization when using --enable-debug
dnl
AC_MSG_CHECKING(whether to explicitly enable optimized build)
AC_ARG_ENABLE(optimize, RB_HELP_STRING([--enable-optimize], [Enable optimization even with --enable-debug]),
[
optimize=$enableval
AC_MSG_RESULT([$optimize])
], [
AM_COND_IF(DEBUG,
[
optimize="no"
AC_MSG_RESULT([$optimize, disabled by default with --enable-debug])
], [
optimize="yes"
AC_MSG_RESULT([$optimize])
])
])
AM_CONDITIONAL([OPTIMIZE], [[[[ "$optimize" = "yes" ]]]])
AM_COND_IF([OPTIMIZE],
[
AC_SUBST(OPTIMIZE, 1)
])
dnl
dnl Enable target clones code generation
dnl
AC_MSG_CHECKING(whether to generate code for target clones)
AC_ARG_ENABLE(clones, RB_HELP_STRING([--enable-clones], [Enable target clones generation]),
[
clones="yes"
], [
clones="no"
])
AC_MSG_RESULT([$clones])
AM_CONDITIONAL([CLONES], [[[[ "$clones" = "yes" ]]]])
AM_COND_IF([CLONES],
[
AC_SUBST(CLONES, 1)
RB_DEFINE([CLONES], [1], [Function multi-versioning for different architectures])
])
dnl
dnl Explicit link-time-optimization switch
dnl
AC_MSG_CHECKING(whether to enable link-time optimization)
AC_ARG_ENABLE(lto, RB_HELP_STRING([--enable-lto], [Enable link-time optimization]),
[
lto=$enableval
], [
lto="yes"
])
if test "$lto" = "yes"; then
AM_COND_IF(OPTIMIZE,
[
AM_COND_IF(CLANG,
[
AS_CASE([$host_cpu],
[aarch64],
[
lto="no"
AC_MSG_RESULT([no, doesn't work on aarch64])
], [
lto="yes"
AC_MSG_RESULT([yes])
])
], [
lto="no"
AC_MSG_RESULT([no, only available with clang])
])
], [
lto="no"
AC_MSG_RESULT([no, optimizations disabled])
])
else
AC_MSG_RESULT([no])
fi
AM_CONDITIONAL([LTO], [[[[ "$lto" = "yes" ]]]])
AM_COND_IF([LTO],
[
AC_SUBST(LTO, 1)
])
dnl
dnl Explicit optimization level switch
dnl
AC_MSG_CHECKING(whether to explicitly set the optimization level)
AC_ARG_WITH(optimize-level, RB_HELP_STRING([--with-optimize-level[[[=3]]]], [Explicitly set the optimize level]),
[
optimize_level=$withval
AC_MSG_RESULT([yes, enabling optimization level -O$optimize_level])
AC_SUBST(OPTMIZE_LEVEL, $optimize_level)
RB_DEFINE_UNQUOTED([OPTIMIZE_LEVEL], [$optimize_level], [User configured optimization level])
], [
AM_COND_IF(OPTIMIZE,
[
AM_COND_IF(COMPACT,
[
optimize_level="s"
AC_MSG_RESULT([no, but --enable-optimize and --enable-compact means -O$optimize_level])
AC_SUBST(OPTIMIZE_LEVEL, $optimize_level)
RB_DEFINE_UNQUOTED([OPTIMIZE_LEVEL], [$optimize_level], [Implicitly set release mode optimization])
], [
optimize_level="3"
AC_MSG_RESULT([no, but --enable-optimize has implied level -O$optimize_level])
AC_SUBST(OPTIMIZE_LEVEL, $optimize_level)
RB_DEFINE_UNQUOTED([OPTIMIZE_LEVEL], [$optimize_level], [Explicitly set release mode optimization])
])
], [
AM_COND_IF(DEBUG,
[
optimize_level="g"
AC_MSG_RESULT([no, but --enable-debug has implied level -O$optimize_level])
AC_SUBST(OPTIMIZE_LEVEL, $optimize_level)
RB_DEFINE_UNQUOTED([OPTIMIZE_LEVEL], ['$optimize_level'], [Debug mode optimization level])
], [
optimize_level="3"
AC_MSG_RESULT([no, but release mode has implied level -O$optimize_level])
AC_SUBST(OPTIMIZE_LEVEL, $optimize_level)
RB_DEFINE_UNQUOTED([OPTIMIZE_LEVEL], [$optimize_level], [Release mode optimization])
])
])
])
dnl
dnl Explicit log level
dnl
dnl NOTE: Log levels here must be manually sync'ed with ircd/logger.h
dnl
AC_MSG_CHECKING(whether to explicitly set the logging level ceiling)
AC_ARG_WITH(log-level, RB_HELP_STRING([--with-log-level[[[=INFO]]]], [Explicitly set the log level ceiling]),
[
AC_MSG_RESULT([yes, enabling log level $withval and below])
level=4
if [[ $withval = "DEBUG" ]]; then
level=7
elif [[ $withval = "DWARNING" ]]; then
level=6
elif [[ $withval = "DERROR" ]]; then
level=5
elif [[ $withval = "INFO" ]]; then
level=4
elif [[ $withval = "NOTICE" ]]; then
level=3
elif [[ $withval = "WARNING" ]]; then
level=2
elif [[ $withval = "ERROR" ]]; then
level=1
elif [[ $withval = "CRITICAL" ]]; then
level=0
elif [[ $withval = "-1" ]]; then
level=-1
fi
AC_SUBST(LOG_LEVEL, $level)
RB_DEFINE_UNQUOTED([LOG_LEVEL], [$level], [Log messages for user configured level and below.])
], [
AM_COND_IF(DEBUG,
[
AC_MSG_RESULT([no, but debug mode enables all log levels through DEBUG])
AC_SUBST(LOG_LEVEL, 7)
RB_DEFINE_UNQUOTED([LOG_LEVEL], [7], [Log message level default for DEBUG mode])
], [
AC_MSG_RESULT([no])
AC_SUBST(LOG_LEVEL, 4)
RB_DEFINE_UNQUOTED([LOG_LEVEL], [4], [Log message level default for release mode])
])
])
dnl
dnl Precompiled headers
dnl
AC_MSG_CHECKING(whether to enable precompiled headers)
AC_ARG_ENABLE(pch, RB_HELP_STRING([--enable-pch], [Enable precompiled header generation]),
[
build_pch=$enableval
], [
build_pch="yes"
])
AC_MSG_RESULT([$build_pch])
AM_CONDITIONAL([BUILD_PCH], [[[[ "$build_pch" = "yes" ]]]])
AM_CONDITIONAL([CLANG_PCH], [[[[ "$build_pch" = "yes" ]] && [[ $CXX = clang* ]]]])
AM_COND_IF([BUILD_PCH],
[
CPPDEFINE([PCH])
])
dnl
dnl Generic Mode compilation
dnl
AC_MSG_CHECKING(whether to enable generic mode or emit for this host)
AC_ARG_ENABLE(generic, RB_HELP_STRING([--enable-generic], [Emit more generic code for pkg binaries]),
[
enable_generic="yes"
], [
enable_generic="no"
])
AC_MSG_RESULT([$enable_generic])
AM_CONDITIONAL([GENERIC], [[[[ "$enable_generic" = "yes" ]]]])
AM_COND_IF([GENERIC],
[
RB_DEFINE([GENERIC], [1], [Building binary tuned for generic architectures])
])
dnl
dnl Tuned compilation
dnl
machine=""
AC_MSG_CHECKING(whether to emit specific architecture features)
AC_ARG_WITH(machine, RB_HELP_STRING([--with-machine], [Emit special feature instructions]),
[
if [[ "$withval" != "yes" ]]; then
machine=$withval
fi
])
if [[ ! -z "$machine" ]]; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
dnl
dnl Disable third-party allocators
dnl
AC_MSG_CHECKING(whether to allow available third-party allocator libraries from being used)
AC_ARG_ENABLE(malloc-libs, RB_HELP_STRING([--enable-malloc-libs], [Enable third-party dynamic memory libraries (jemalloc/tcmalloc/etc)]),
[
use_malloc_libs=$enableval
], [
use_malloc_libs="yes"
])
AC_MSG_RESULT([$use_malloc_libs])
AM_CONDITIONAL([MALLOC_LIBS], [[[[ "$use_malloc_libs" = "yes" ]]]])
dnl
dnl Low memory compilation mode
dnl
AC_ARG_ENABLE(lowmem-compile, RB_HELP_STRING([--enable-lowmem-compile], [Enable low-memory compilation options]),
[
lowmem_compile="yes"
], [
lowmem_compile="no"
])
AC_MSG_RESULT([$lowmem_compile])
AM_CONDITIONAL([LOWMEM_COMPILE], [[[[ $lowmem_compile = "yes" ]]]])
dnl
dnl GCC toolchain selection (for clang)
dnl
AC_MSG_CHECKING(whether to use a specific GCC toolchain)
AC_ARG_WITH(gcc-toolchain, RB_HELP_STRING([--with-gcc-toolchain], [Path to GCC toolchain]),
[
with_gcc_toolchain=$withval
AC_MSG_RESULT([yes, "$with_gcc_toolchain"])
AC_SUBST(GCC_TOOLCHAIN, $with_gcc_toolchain)
AM_COND_IF(CLANG,
[
RB_VAR_PREPEND([CXXFLAGS], ["--gcc-toolchain=$with_gcc_toolchain"])
RB_VAR_PREPEND([LDFLAGS], ["--gcc-toolchain=$with_gcc_toolchain"])
], [
AC_MSG_WARN([--with-gcc-toolchain only applies to clang builds.])
])
], [
AC_MSG_RESULT([no])
])
dnl ***************************************************************************
dnl
dnl Compiler flags
dnl
dnl
dnl Reserved for user
dnl
dnl ex. `make EXTRA_CXXFLAGS="-Weverything" ircd` to append CXXFLAGS
dnl AC_SUBST(EXTRA_CPPFLAGS, "$EXTRA_CPPFLAGS")
dnl AC_SUBST(EXTRA_CFLAGS, "$EXTRA_CFLAGS")
dnl AC_SUBST(EXTRA_CXXFLAGS, "$EXTRA_CXXFLAGS")
dnl AC_SUBST(EXTRA_LDFLAGS, "$EXTRA_LDFLAGS")
dnl AC_SUBST(EXTRA_LIBS, "$EXTRA_LIBS")
dnl
dnl Features
dnl
AM_COND_IF([GCC],
[
dnl RB_VAR_PREPEND([CXXFLAGS], ["-fmodules-ts"])
])
AM_COND_IF([CLANG],
[
dnl RB_VAR_PREPEND([CXXFLAGS], ["-fmodules"])
])
AM_COND_IF([CLANG],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fblocks"])
RB_VAR_PREPEND([CXXFLAGS], ["-fasm-blocks"])
])
AM_COND_IF([CLANG11],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fenable-matrix"])
])
dnl
dnl Misc
dnl
dnl This disables thread-safety for static variable initialization
dnl (specifically local static variables inside functions) which reduces
dnl generated code size and complexity. This is alright since construct is
dnl primarily single threaded. Even if other threads are spawned for special
dnl tasks we consider the likelyhood of a static initialization race to either
dnl be sufficiently low or simply immaterial for our uses of them.
dnl
RB_VAR_PREPEND([CXXFLAGS], ["-fno-threadsafe-statics"])
dnl Exception safety at instruction boundary rather than function boundary
dnl This option is needed to enable noexcept(false) i.e to throw from a
dnl destructor; without this noexcept(false) still terminates.
RB_VAR_PREPEND([CXXFLAGS], ["-fasynchronous-unwind-tables"])
dnl -fvisibility-inlines-hidden - for optimization; note the address of inline
dnl functions won't be the same between translation units
RB_VAR_PREPEND([CXXFLAGS], ["-fvisibility-inlines-hidden"])
dnl see gcc(1)
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fnothrow-opt"])
])
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-flax-vector-conversions"])
])
dnl
dnl Optimization
dnl
RB_VAR_PREPEND([CXXFLAGS], ["-O$optimize_level"])
AM_COND_IF([OPTIMIZE],
[
optimize="yes"
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fgcse-sm"])
RB_VAR_PREPEND([CXXFLAGS], ["-fgcse-las"])
RB_VAR_PREPEND([CXXFLAGS], ["-fsched-stalled-insns=0"])
RB_VAR_PREPEND([CXXFLAGS], ["-fsched-pressure"])
RB_VAR_PREPEND([CXXFLAGS], ["-fsched-spec-load"])
dnl RB_VAR_PREPEND([CXXFLAGS], ["-fsched2-use-superblocks"])
dnl RB_VAR_PREPEND([CXXFLAGS], ["-fsched2-use-superblocks"])
RB_VAR_PREPEND([CXXFLAGS], ["-fira-hoist-pressure"])
RB_VAR_PREPEND([CXXFLAGS], ["-fbranch-target-load-optimize"])
RB_VAR_PREPEND([CXXFLAGS], ["-frerun-loop-opt"])
RB_VAR_PREPEND([CXXFLAGS], ["-fdevirtualize-at-ltrans"])
dnl RB_VAR_PREPEND([CXXFLAGS], ["-fbtr-bb-exclusive"])
RB_VAR_PREPEND([CXXFLAGS], ["-fipa-pta"])
RB_VAR_PREPEND([CXXFLAGS], ["-fmodulo-sched"])
RB_VAR_PREPEND([CXXFLAGS], ["-fmodulo-sched-allow-regmoves"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftracer"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-loop-im"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-switch-conversion"])
])
], [
optimize="no"
dnl Optimization options we enable in non-optimized mode. These will be enabled
dnl in non-optimized mode as well as optimized mode so they are as similar as
dnl possible without impacting debuggability.
RB_VAR_PREPEND([CXXFLAGS], ["-falign-functions"])
dnl RB_VAR_PREPEND([CXXFLAGS], ["-fdata-sections"])
dnl RB_VAR_PREPEND([CXXFLAGS], ["-ffunction-sections"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-vectorize"])
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-falign-labels"])
RB_VAR_PREPEND([CXXFLAGS], ["-falign-loops"])
RB_VAR_PREPEND([CXXFLAGS], ["-falign-jumps"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-vrp"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-dce"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-dse"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-loop-im"])
RB_VAR_PREPEND([CXXFLAGS], ["-ftree-switch-conversion"])
])
])
AM_COND_IF([CLANG],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fno-data-sections"])
RB_VAR_PREPEND([CXXFLAGS], ["-fno-function-sections"])
])
dnl
dnl Compiler intrumentation
dnl
dnl XXX workaround for valgrind; remove once valgrind is updated
AM_COND_IF([DEBUG],
[
AM_COND_IF([CLANG14],
[
RB_VAR_PREPEND([CXXFLAGS], ["-gdwarf-4"])
])
])
dnl Enable debugging symbols.
AM_COND_IF([DEBUG],
[
RB_VAR_PREPEND([CXXFLAGS], ["-ggdb"])
RB_VAR_PREPEND([CXXFLAGS], ["-g"])
])
AM_COND_IF([DEBUG],
[
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fvar-tracking-assignments"])
RB_VAR_PREPEND([CXXFLAGS], ["-fvar-tracking"])
])
])
RB_VAR_PREPEND([CXXFLAGS], ["-fverbose-asm"])
dnl Creates an ELF section in the output which contains a list of
dnl the command line arguments used for compilation.
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-frecord-gcc-switches"])
])
AM_COND_IF([CLANG],
[
RB_VAR_PREPEND([CXXFLAGS], ["-grecord-gcc-switches"])
RB_VAR_PREPEND([CXXFLAGS], ["-fno-discard-value-names"])
RB_VAR_PREPEND([CXXFLAGS], ["-fident"])
])
AM_COND_IF([DEBUG],
[
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fmax-errors=2"])
])
AM_COND_IF([CLANG],
[
RB_VAR_PREPEND([CXXFLAGS], ["-ferror-limit=2"])
])
])
AM_COND_IF([BUILD_PCH],
[
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fpch-deps"])
])
AM_COND_IF([CLANG],
[
RB_VAR_PREPEND([CPPFLAGS], ["-fpch-preprocess"])
])
AM_COND_IF([CLANG10],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fpch-validate-input-files-content"])
])
])
dnl
dnl Runtime intrumentation
dnl
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fstack-protector-explicit"])
AS_CASE([$host_cpu],
[x86_64],
[
dnl These flags should not be used on Intel-CET capable platforms
dnl TODO: XXX
AS_IF([test "$CXX_EPOCH" -ge "9"],
[
AM_COND_IF([GENERIC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fcf-protection=return"])
], [
RB_VAR_PREPEND([CXXFLAGS], ["-fcf-protection=none"])
RB_VAR_PREPEND([CXXFLAGS], ["-mmanual-endbr"])
])
])
])
])
AM_COND_IF([GCC],
[
RB_VAR_PREPEND([CXXFLAGS], ["-fvtable-verify=none"])
])
dnl
dnl Machine Tuning
dnl
MACHINE_FLAGS=""
dnl Initial machine
machine_arch="native"
machine_tune="native"
AM_COND_IF([CLANG],
[
AS_IF([test "$CXX_EPOCH" -lt "15"],
[
AS_IF([test "$host_cpu" = "aarch64"],
[
machine_arch=""
])
])
])
AM_COND_IF([GENERIC],
[
machine_tune="generic"
AS_CASE([$host_cpu],
[x86_64],
[
machine_arch="x86-64"
])
])
dnl Specific extension specification
machine_feat=""
for feature in $machine; do
if [[ $(echo $feature | cut -d"=" -f1) == "arch" ]]; then
machine_arch=$(echo $feature | cut -d"=" -f2)
elif [[ $(echo $feature | cut -d"=" -f1) == "tune" ]]; then
machine_tune=$(echo $feature | cut -d"=" -f2)
else
machine_feat="$feature $machine_feat"
RB_VAR_PREPEND([MACHINE_FLAGS], [-m${feature}])
fi
done
dnl Ensures mtune=generic accompanies one of the generic march= options
dnl even if --enable-generic wasn't given, otherwise gcc will reject.
AM_COND_IF_NOT([GENERIC],
[
AS_CASE([$machine_arch],
[x86-64*],
[
machine_tune="generic"
], [
machine_tune=$machine_arch
])
])
dnl Specific extension underrides
AS_CASE([$host_cpu],
[x86_64],
[
dnl AMD K10's SSE4a doesn't work with valgrind
RB_VAR_PREPEND([MACHINE_FLAGS], [-mno-sse4a])
])
if [[ ! -z "$machine_tune" ]]; then
RB_VAR_PREPEND([MACHINE_FLAGS], [-mtune=$machine_tune])
fi
if [[ ! -z "$machine_arch" ]]; then
RB_VAR_PREPEND([MACHINE_FLAGS], [-march=$machine_arch])
fi
machine_tuning="${host_cpu} arch=$machine_arch tune=$machine_tune :$machine_feat"
RB_VAR_PREPEND([CXXFLAGS], [$MACHINE_FLAGS])
dnl Get the target features for this build from gcc into a readable string
AM_COND_IF([GCC],
[
_cxx=$(echo "${CXX}" | cut -d' ' -f1)
_cmd="${_cxx} -Q --help=target ${MACHINE_FLAGS}"
machine_features=$(${_cmd} | grep enabled | grep -v 'mno-')
machine_features=$(printf "\n${machine_features}")
])
dnl Get the target features for this build from clang into a readable string
AM_COND_IF([CLANG],
[
_flag=0
_cxx=$(echo "${CXX}" | cut -d' ' -f1)
_str=$(${_cxx} -E ${MACHINE_FLAGS} - -### 2>&1)
machine_features=""
for i in $_str; do
if [[ $i == '"-target-feature"' ]]; then
_flag=1
elif [[ $_flag == 1 ]]; then
_flag=0
attr=$(echo $i | sed -e 's/^"//' -e 's/"$//')
if [[ ${attr:0:1} == '+' ]]; then
machine_features="${machine_features}${attr} "
fi
fi
done
])
dnl
dnl Compiler warnings
dnl
AC_MSG_CHECKING(whether to enable warnings)
AC_ARG_ENABLE(warnings,
RB_HELP_STRING([--enable-warnings], [Disable all sorts of warnings like a rockstar]),
[
warnings=$enableval
], [
warnings="yes"
])
AC_MSG_RESULT([$warnings])
AM_CONDITIONAL([WARNINGS], [[[[ "$warnings" = "yes" ]]]])
AC_DEFUN([RB_MAYBE_CWARN],
[
AM_COND_IF([WARNINGS],
[
RB_MAYBE_CXXFLAG([$1], [$2])
])
])
STACK_USAGE_WARNING=16384
FRAME_SIZE_WARNING=8192
CWARNS=""
dnl Compatible warnings
RB_MAYBE_CWARN([-Wall], charybdis_cv_c_gcc_w_all)
RB_MAYBE_CWARN([-Wextra], charybdis_cv_c_gcc_w_extra)
RB_MAYBE_CWARN([-Wpointer-arith], charybdis_cv_c_gcc_w_pointer_arith)
RB_MAYBE_CWARN([-Wcast-align], charybdis_cv_c_gcc_w_cast_align)
RB_MAYBE_CWARN([-Wcast-qual], charybdis_cv_c_gcc_w_cast_qual)
RB_MAYBE_CWARN([-Wfloat-equal], charybdis_cv_c_gcc_w_float_equal)
RB_MAYBE_CWARN([-Wwrite-strings], charybdis_cv_c_gcc_w_write_strings)
RB_MAYBE_CWARN([-Wparentheses], charybdis_cv_c_gcc_parentheses)
RB_MAYBE_CWARN([-Wundef], charybdis_cv_c_gcc_w_undef)
RB_MAYBE_CWARN([-Wpacked], charybdis_cv_c_gcc_w_packed)
RB_MAYBE_CWARN([-Wformat -Wformat-y2k -Wformat-nonliteral], charybdis_cv_c_gcc_w_format)
RB_MAYBE_CWARN([-Wstrict-aliasing=2 -Wstrict-overflow=5], charybdis_cv_c_gcc_w_strict)
RB_MAYBE_CWARN([-Wdisabled-optimization], charybdis_cv_c_gcc_w_disabled_optimization)
RB_MAYBE_CWARN([-Winvalid-pch], charybdis_cv_c_gcc_w_invalid_pch)
RB_MAYBE_CWARN([-Winit-self], charybdis_cv_c_gcc_w_init_self)
RB_MAYBE_CWARN([-Wunreachable-code], charybdis_cv_c_gcc_w_unreachable_code)
RB_MAYBE_CWARN([-Wno-overloaded-virtual], charybdis_cv_c_gcc_w_overloaded_virtual)
RB_MAYBE_CWARN([-Wnon-virtual-dtor], charybdis_cv_c_gcc_w_non_virtual_dtor)
RB_MAYBE_CWARN([-Wsized-deallocation], charybdis_cv_c_gcc_w_sized_deallocation)
RB_MAYBE_CWARN([-Wctor-dtor-privacy], charybdis_cv_c_gcc_w_ctor_dtor_privacy)
RB_MAYBE_CWARN([-Wsign-promo], charybdis_cv_c_gcc_w_sign_promo)
RB_MAYBE_CWARN([-Wtrampolines], charybdis_cv_c_gcc_w_trampolines)
RB_MAYBE_CWARN([-Wduplicated-cond], charybdis_cv_c_gcc_w_duplicated_cond)
RB_MAYBE_CWARN([-Wduplicate-branches], charybdis_cv_c_gcc_w_duplicate_branches)
RB_MAYBE_CWARN([-Wrestrict], charybdis_cv_c_gcc_w_restrict)
RB_MAYBE_CWARN([-Wnull-dereference], charybdis_cv_c_gcc_w_null_dereference)
RB_MAYBE_CWARN([-Wplacement-new=2], charybdis_cv_c_gcc_w_placement_new)
RB_MAYBE_CWARN([-Wundef], charybdis_cv_c_gcc_w_undef)
RB_MAYBE_CWARN([-Wodr], charybdis_cv_c_gcc_w_odr)
RB_MAYBE_CWARN([-Wimplicit-fallthrough], charybdis_cv_c_gcc_w_implicit_fallthrough)
RB_MAYBE_CWARN([-Werror=return-type], charybdis_cv_c_gcc_w_error_return_type)
RB_MAYBE_CWARN([-Werror=reorder], charybdis_cv_c_gcc_w_error_reorder)
dnl Compiler specific
AM_COND_IF([GCC],
[
RB_MAYBE_CWARN([-Werror=return-local-addr], charybdis_cv_c_gcc_w_error_return_local_addr)
RB_MAYBE_CWARN([-Wlogical-op], charybdis_cv_c_gcc_w_logical_op)
RB_MAYBE_CWARN([-Wformat-security], charybdis_cv_c_gcc_w_format_security)
RB_MAYBE_CWARN([-Wstack-usage=$STACK_USAGE_WARNING], charybdis_cv_c_gcc_w_stack_usage)
RB_MAYBE_CWARN([-Wframe-larger-than=$FRAME_SIZE_WARNING], charybdis_cv_c_gcc_w_frame_larger_than)
RB_MAYBE_CWARN([-Walloca], charybdis_cv_c_gcc_w_alloca)
RB_MAYBE_CWARN([-Wvector-operation-performance], charybdis_cv_c_gcc_w_vector_operation_performance)
RB_MAYBE_CWARN([-Wstringop-overflow=4], charybdis_cv_c_gcc_w_stringop_overflow)
])
dnl Compiler specific
AM_COND_IF([CLANG],
[
RB_MAYBE_CWARN([-Werror=return-stack-address], charybdis_cv_c_gcc_w_error_return_stack_address)
RB_MAYBE_CWARN([-Werror=abstract-final-class], charybdis_cv_c_gcc_w_error_abstract_final_class)
RB_MAYBE_CWARN([-Wundefined-reinterpret-cast], charybdis_cv_c_gcc_w_undefined_reinterpret_cast)
RB_MAYBE_CWARN([-Wconditional-uninitialized], charybdis_cv_c_gcc_w_conditional_uninitialized)
RB_MAYBE_CWARN([-Wno-mismatched-tags], charybdis_cv_c_gcc_w_mismatched_tags)
RB_MAYBE_CWARN([-Wno-format-security], charybdis_cv_c_gcc_w_format_security)
RB_MAYBE_CWARN([-Wno-unknown-warning-option], charybdis_cv_c_gcc_w_unknown_warning_option)
RB_MAYBE_CWARN([-Wno-profile-instr-unprofiled], charybdis_cv_c_gcc_w_profile_instr_unprofiled)