File: configure.ac

package info (click to toggle)
bit-babbler 0.8
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,900 kB
  • sloc: cpp: 10,297; sh: 4,301; perl: 1,017; ansic: 1,013; makefile: 84
file content (1171 lines) | stat: -rw-r--r-- 47,418 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
# Makeup 0.32 generated configure.ac.
# Do not edit this file directly, your changes will be lost.
# Copyright (C) 2003 - 2018, Ron <ron@debian.org>
#
# This file is distributed under the terms of the GNU GPL version 2.
#
# As a special exception to the GPL, it may be distributed without
# modification as a part of a program using a makeup generated build
# system, under the same distribution terms as the program itself.
# Modified versions are not obliged to also offer this exception,
# though if you wish not to do so then you should remove this paragraph
# and make it clear that your modifications are licenced strictly
# according to the GPL 2 or a compatible licence.

AC_INIT([bit-babbler], [0.8], [ron@debian.org])
AC_COPYRIGHT([Copyright (C) 2003 - 2018, Ron <ron@debian.org>])
AC_PREREQ([2.61])
AC_REVISION([generated by Makeup 0.32])

AC_CONFIG_SRCDIR([Makeup/Makeup.conf])

# We need these available before macros that follow.
FIND_AND_LINK_IF_LOCAL([config.guess],[Makeup/ac-aux])
FIND_AND_LINK_IF_LOCAL([config.sub],[Makeup/ac-aux])
# This used to be ..._COPY_UNLESS_LOCAL, but using the
# ..._CONFIG_AUX_DIR macro below has changed what we need.
FIND_AND_LINK_IF_LOCAL([install-sh],[Makeup/ac-aux])

# We need the files above in place, else this will fail.
AC_CONFIG_AUX_DIR([Makeup/ac-aux])

# Find out where we're building and who we're building for.
AC_CANONICAL_BUILD
AC_CANONICAL_HOST

# Select the default language standard to use.
CXX_STANDARD="-std=gnu++98"

dnl ----- Begin: configure.stdtools -----
dnl Makeup configure boilerplate.
dnl
dnl Copyright 2003 - 2018, Ron <ron@debian.org>
dnl
dnl This file is distributed under the terms of the GNU GPL version 2.
dnl
dnl As a special exception to the GPL, it may be distributed without
dnl modification as a part of a program using a makeup generated build
dnl system, under the same distribution terms as the program itself.
dnl Modified versions are not obliged to also offer this exception,
dnl though if you wish not to do so then you should remove this paragraph
dnl and make it clear that your modifications are licenced strictly
dnl according to the GPL 2 or a compatible licence.


# Don't let these get set by AC_PROG_* below.

CFLAGS=${CFLAGS-}
CXXFLAGS=${CXXFLAGS-}


dnl These are separately precious because overriding {C,CXX}FLAGS should not
dnl normally mask the C/C++ standard that a project is built with, and that
dnl might not be an immediately obvious consequence of setting them explictly.
dnl If you really want to override that, do it with these (or by changing the
dnl PACKAGE_{C,XX}STD set for the project), which likewise will also preserve
dnl whatever other compiler flags would normally be used.
AC_ARG_VAR([C_STANDARD], [flags to set the compiler C standard to use])
AC_ARG_VAR([CXX_STANDARD], [flags to set the compiler C++ standard to use])


dnl Not all platforms have GCC as their default compiler anymore, even if it is
dnl still available by default.  Autoconf still prefers to use GCC by default
dnl in the AC_PROG_{CC,CXX} tests though.  These variables let the search order
dnl be explicitly specified by the user, and let us automatically tweak it for
dnl different platforms.
AC_ARG_VAR([CC_SEARCH], [space separated list of which C compiler to prefer])
AC_ARG_VAR([CXX_SEARCH], [space separated list of which C++ compiler to prefer])

# Oddly enough, the most preferred compiler is a platform specific thing, not a
# universal truth.  Who could have guessed ...

dnl Keeping this list current with the changing Winds of Whim could become a
dnl rather tedious and fragile thing, so it's tempting to default to checking
dnl for cc and c++ first everywhere, on the assumption that all modern systems
dnl now have that as an alias to their actually preferred toolchains, but that
dnl has the downside of making it less obvious exactly which compiler is being
dnl used, and making it even more fragile if some user has changed it from what
dnl the normal platform default would otherwise be ...  So let's see how this
dnl goes for a while.  At present the platform needing this most is OpenBSD,
dnl since it still ships an ancient "last of the GPLv2" gcc in its base set,
dnl but actually has clang as its default and preferred compiler.
case $host in
    *-*-openbsd* )
	dnl OpenBSD (as of 6.2) still has GCC 4.2.1 installed in its base set,
	dnl but "defaults" to clang (which is what /usr/bin/cc points to), so
	dnl test for a working clang before gcc there.
	AS_IF([test -z "$CC_SEARCH"],[CC_SEARCH="clang gcc cc"])
	AS_IF([test -z "$CXX_SEARCH"],[CXX_SEARCH="clang++ g++ c++"])
	;;

    * )
	dnl By default, do what autoconf would otherwise do and prefer GCC,
	dnl except our second choice is clang (which it entirely ignores),
	dnl and we don't bother looking for the obscure C++ compilers which
	dnl it would check for if it doesn't find g++ or c++.  When someone
	dnl proves they want them, and that they can compile our code, then
	dnl we can revise this list to add them.
	dnl
	dnl Ideally, we'd have defaulted to calling AC_PROG_{CC,CXX} with an
	dnl empty argument, and just let it do its own default thing, but that
	dnl macro is too broken to enable that, it checks if the argument is
	dnl empty during the m4 pass, so it considers an empty variable to be
	dnl an explicit list (and then fails at runtime with no compilers to
	dnl check) - and we can't AS_IF it and call it either with or without
	dnl arguments at runtime, because there are tests in there which will
	dnl only expand once, and so everything falls apart when they are only
	dnl expanded in the dead branch ...  The assumption that it will only
	dnl ever appear once in one code path goes deep there.
	AS_IF([test -z "$CC_SEARCH"],[CC_SEARCH="gcc clang cc"])
	AS_IF([test -z "$CXX_SEARCH"],[CXX_SEARCH="g++ clang++ c++"])
	;;
esac


# Check standard tools.

AC_PROG_CC([$CC_SEARCH])
AC_PROG_CPP
AC_PROG_CXX([$CXX_SEARCH])
AC_PROG_CXXCPP

dnl If we explicitly set the C/C++ standard to use, then ensure that is passed
dnl when the preprocessor is run during the tests that follow.  This is a bit
dnl sketchy, because really this ought to be done as part of testing for how to
dnl run the preprocessor above - and there are no separate variables for the
dnl preprocessor flags for C and C++, the autoconf tests just use CPPFLAGS for
dnl both, which is a bit difficult when we want to specify a C or C++ standard
dnl to use in mixed code.  If we don't do this though, then we can see dodgy or
dnl misleading test results for things like AC_CHECK_HEADERS which runs both
dnl the compiler and preprocessor as separate tests.  If CFLAGS or CXXFLAGS set
dnl a standard to use and the preprocessor flags do not, then the results could
dnl be conflicting when things which do vary according to the standard that is
dnl being used are involved.  Fortunately, CPP and CXXCPP generally aren't used
dnl very often outside of the feature tests here, and if there is a problem it
dnl will probably shake out fairly early in the first test which does use it.
AS_IF([test -n "$C_STANDARD"],[CPP="$CPP $C_STANDARD"])
AS_IF([test -n "$CXX_STANDARD"],[CXXCPP="$CXXCPP $CXX_STANDARD"])

AC_PROG_LEX
  dnl AC_PROG_YACC
  dnl Do this instead since we want real bison usually,
  dnl not the crippled yaccalike.
AC_CHECK_TOOL([YACC],[bison],[:])

AC_PROG_RANLIB
AC_CHECK_TOOL([AR],[ar],[:])
AC_CHECK_TOOL([WINDRES],[windres],[:])

AC_PROG_LN_S

AC_PROG_INSTALL

AC_CHECK_PROGS([LCOV],[lcov],[:])
AC_CHECK_PROGS([GENHTML],[genhtml],[:])


# Check standard args.

AC_ARG_ENABLE([pipe],
              [AS_HELP_STRING([--enable-pipe],
                              [use pipes instead of temporary files for faster compilation (default yes)])],
              [ac_cv_enable_pipe=$enableval],
              [ac_cv_enable_pipe=yes])

AC_ARG_ENABLE([optimisation],
              [AS_HELP_STRING([--enable-optimisation],
                              [use compiler optimisation flags (default yes)])],
              [ac_cv_enable_optimisation=$enableval],
              [ac_cv_enable_optimisation=yes])

AC_ARG_ENABLE([debug],
              [AS_HELP_STRING([--enable-debug],
                              [enable extra debug code (default yes)])],
              [ac_cv_enable_debug=$enableval],
              [ac_cv_enable_debug=yes])

AC_ARG_ENABLE([profile],
              [AS_HELP_STRING([--enable-profile],
                              [use profiling flags (default no)])],
              [ac_cv_enable_profiling=$enableval],
              [ac_cv_enable_profiling=no])

AC_ARG_ENABLE([extra_warnings],
              [AS_HELP_STRING([--enable-extra_warnings],
                              [use extra compiler warnings (default yes)])],
              [ac_cv_enable_extra_warnings=$enableval],
              [ac_cv_enable_extra_warnings=yes])

AC_ARG_ENABLE([werror],
              [AS_HELP_STRING([--enable-werror],
			      [fail on compile warnings, (default yes for release builds, no for debug builds)])],
	      [
		ac_cv_enable_fail_on_warning=$enableval],
	      [
		AS_IF([test "$ac_cv_enable_debug" = yes],[
		    ac_cv_enable_fail_on_warning=no
		],[
		    dnl ac_cv_enable_fail_on_warning=yes
		    dnl Basic tests like for iconv crap out right now
		    dnl with warnings as errors.  Disable temporarily.
		    ac_cv_enable_fail_on_warning=no
		])
	      ])

AC_ARG_ENABLE([valgrind_friendly],
              [AS_HELP_STRING([--enable-valgrind_friendly],
                              [do extra cleanup to be valgrind clean (default no)])],
              [ac_cv_enable_valgrind_friendly=$enableval],
              [ac_cv_enable_valgrind_friendly=no])

AC_ARG_ENABLE([bison_deprecated_warnings],
              [AS_HELP_STRING([--enable-bison_deprecated_warnings],
                              [let bison3 bark about deprecated bison2 constructs (default no)])],
              [ac_cv_enable_bison_deprecated_warnings=$enableval],
              [ac_cv_enable_bison_deprecated_warnings=no])


AC_ARG_ENABLE([shared],
              [AS_HELP_STRING([--enable-shared],
                              [use dynamic linking (default yes)])],
              [ac_cv_enable_shared=$enableval],
              [ac_cv_enable_shared=yes])

AC_ARG_ENABLE([static],
              [AS_HELP_STRING([--enable-static],
                              [use static linking (default no)])],
              [
                AS_IF([test "$enableval" = yes],[ac_cv_enable_shared=no])
              ])


AC_ARG_VAR([PICFLAGS], [extra linker flags set for shared lib builds])
AC_ARG_VAR([RC_SEP], [a hack for excluding windows resource files])
AC_ARG_VAR([ARFLAGS], [options passed to ar, duh!])
AC_ARG_VAR([YACCFLAGS], [options passed to bison/yacc])
AC_ARG_VAR([LEXFLAGS], [options passed to flex/lex])

AC_ARG_VAR([PTHREAD_CPPFLAGS], [C/C++ preprocessor flags for thread-safe builds])
AC_ARG_VAR([PTHREAD_LDFLAGS], [C/C++ linker flags for thread-safe builds])

dnl the EXTRAFOO variables allow appending additional flags without completely
dnl overriding the normal default set (and/or having to specify them manually
dnl just to add some additional option.
AC_ARG_VAR([EXTRACPPFLAGS], [extra C preprocessor flags])
AC_ARG_VAR([EXTRACFLAGS], [extra C compiler flags])
AC_ARG_VAR([EXTRACXXFLAGS], [extra C++ compiler flags])
AC_ARG_VAR([EXTRALDFLAGS], [extra linker flags])
AC_ARG_VAR([EXTRAYACCFLAGS], [extra options passed to bison/yacc])
AC_ARG_VAR([EXTRALEXFLAGS], [extra options passed to flex/lex])
AC_ARG_VAR([EXTRALIBS], [extra libraries (to link before LIBS)])

AC_ARG_VAR([MAKEUP_HOST_ARCH], [architecture that targets should be built for])
AC_ARG_VAR([MAKEUP_DEFAULT_LINKAGE], [default linkage for binary targets])
AC_ARG_VAR([DSOEXT], [filename extension for dynamic libraries])

RC_SEP="#"

case $host in

    *-*-linux* )

        dnl Used in the make subsystem for rule selection.
        MAKEUP_HOST_ARCH="ELF"

        dnl Used to define the link names to the config header.
        makeup_build_platform="linux"

        DSOEXT=".so"

        dnl Don't do this by default anymore.  It went out of vogue with gcc3.
        dnl CPPFLAGS="$CPPFLAGS -DUSE_GCC_PRAGMA"

        AS_IF([test "$ac_cv_enable_shared" = yes],[PICFLAGS="-fPIC"])
        ;;

    *-*-*bsd* | *-*-darwin* )

        MAKEUP_HOST_ARCH="ELF"
        makeup_build_platform="bsd"

        DSOEXT=".so"

        AS_IF([test "$ac_cv_enable_shared" = yes],[PICFLAGS="-fPIC"])
        ;;

    *-*-cygwin* | *-*-mingw32* )

        MAKEUP_HOST_ARCH="PE"
        makeup_build_platform="msw"

        DSOEXT=".dll"

        AS_IF([test "$ac_cv_enable_shared" = yes],[PICFLAGS="-D_DLL=1 -D_WINDLL=1"])

        AC_ARG_VAR([WINRCFLAGS], [options passed to windres])
        WINRCFLAGS="--include-dir /usr/$host_alias/include"

        AS_IF([test -n "$ac_cv_with_wx_build_dir"],[
            WINRCFLAGS="$WINRCFLAGS --include-dir $ac_cv_with_wx_build_dir/../include"
        ])

        WINRCFLAGS="$WINRCFLAGS --define __WIN32__ --define __WIN95__ --define __GNUWIN32__"

        RC_SEP=
        ;;
    * )
        AC_MSG_ERROR([Unknown host type.  Stopping.])
esac

dnl This one may be added to later by user config that adds flavours.
dnl At this level there are only two flavours, 'd' - debug, and 'r' - release.
AS_IF([test "$ac_cv_enable_debug" = yes],[makeup_build_flavour=d],[makeup_build_flavour=r])

AS_IF([test "$ac_cv_enable_shared" = yes],[
    MAKEUP_DEFAULT_LINKAGE="shared"
],[
    MAKEUP_DEFAULT_LINKAGE="static"
])


dnl These may all go in platform dependent conditionals one day.
dnl We no longer use -Wconversion.  It was mainly designed as
dnl a filter for porting old C code where parameters may be type
dnl promoted in the absence of a new style prototype, and should
dnl not be used to check new code.  False positives in the xlocale
dnl xwctype.h (iswctype, towlower, towupper, just for a start)
dnl make it officially more trouble than it is presently worth.
cc_warnings=" -Wall"
cc_fail_on_warn=" -Werror"
cc_extra_warnings=" -W -Wpointer-arith -Wcast-qual -Wcast-align -Wformat=2 -Wfloat-equal"

cc_optimise=" -O2"
cc_profile=" -pg"
cc_debug=" -g"
cc_pipe=" -pipe"

dnl Only for C or ObjC compilers.
c_extra_warnings=" -Wstrict-prototypes -Wmissing-prototypes"

dnl Only for C++.
cxx_extra_warnings=" -Woverloaded-virtual"

dnl Build the lists of common compiler flags, C compiler flags
dnl and C++ compiler flags.
cc_flags=
c_flags=
cxx_flags=

AS_IF([test "$ac_cv_enable_pipe" = yes],[cc_flags="$cc_flags$cc_pipe"])

AS_IF([test "$ac_cv_enable_optimisation" = yes],[cc_flags="$cc_flags$cc_optimise"])

AS_IF([test "$ac_cv_enable_debug" = yes],[cc_flags="$cc_flags$cc_debug"])

AS_IF([test "$ac_cv_enable_profiling" = yes],[
    cc_flags="$cc_flags$cc_profile"
    LDFLAGS="$LDFLAGS$cc_profile"
])

cc_flags="$cc_flags$cc_warnings"

AS_IF([test "$ac_cv_enable_extra_warnings" = yes],[
    cc_flags="$cc_flags$cc_extra_warnings"
    c_flags="$c_flags$c_extra_warnings"
    cxx_flags="$cxx_flags$cxx_extra_warnings"
])

AS_IF([test "$ac_cv_enable_fail_on_warning" = yes],[cc_flags="$cc_flags$cc_fail_on_warn"])

CFLAGS=${CFLAGS:-$cc_flags$c_flags}
CXXFLAGS=${CXXFLAGS:-$cc_flags$cxx_flags}

AS_IF([test -n "$C_STANDARD"],[CFLAGS="$C_STANDARD $CFLAGS"])
AS_IF([test -n "$CXX_STANDARD"],[CXXFLAGS="$CXX_STANDARD $CXXFLAGS"])

# add 's' here and omit ranlib from the build step
ARFLAGS=rDvs


dnl We need to test if these extra warnings are actually supported by the
dnl toolchain in use, we can't safely assume that it does with this lot.
dnl The -Wsuggest-attribute options are currently GCC specific.
AS_IF([test "$ac_cv_enable_extra_warnings" = yes],[
    ACM_ADD_COMPILER_WARNING([C,CXX],[suggest-attribute=format,
                                      suggest-attribute=const,
                                      suggest-attribute=pure,
                                      suggest-attribute=noreturn])
])


PTHREAD_CPPFLAGS="-pthread"
PTHREAD_LDFLAGS="-pthread"

save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $PTHREAD_CPPFLAGS"

AC_CACHE_CHECK([if _REENTRANT is defined by the compiler], [ac_cv_have_reentrant],
  [AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[
#ifndef _REENTRANT
#error "_REENTRANT was not defined"
#endif
				      ]])
    ],
    [ac_cv_have_reentrant=yes],
    [ac_cv_have_reentrant=no]
  )]
)

CPPFLAGS=$save_CPPFLAGS

AS_IF([test "$ac_cv_have_reentrant" != "yes"],[
  PTHREAD_CPPFLAGS="$PTHREAD_CPPFLAGS -D_REENTRANT"
])


dnl bison3 complains loudly about a bunch of constructs that must still be used
dnl if compatibility with bison2 is required, and appears to give us no clean
dnl way to deal with that at all.  We can tell bison3 not to bark by passing it
dnl the -Wno-deprecated option, except bison2 chokes and dies on that too ...
dnl Disabling those warnings is sub-optimal, but so is scaring end-users with
dnl them and/or maintaining two sets of grammar files, or autogenerating them
dnl just for a couple of gratuitously renamed defines. So the least ugly option
dnl we have appears to be to test for bison3 here and disable those warnings if
dnl it's the version in use, unless they were enabled explicitly by the user
dnl who ran configure.  At least for the next few years while most of the world
dnl is still using bison2 ...
AS_IF([test "$ac_cv_enable_bison_deprecated_warnings" = no],[
    AS_IF([test "$YACC" != ":"],[
        AS_IF([$YACC -Wno-deprecated -V > /dev/null 2>&1],[
            yacc_flags=" -Wno-deprecated"
            AC_MSG_NOTICE([disabled bison3 deprecation warnings])
        ])
    ])
])

YACCFLAGS="-d$yacc_flags \$(EXTRAYACCFLAGS)"
LEXFLAGS="\$(EXTRALEXFLAGS)"


dnl Macros to define in the private config header.

AC_DEFINE_UNQUOTED([EMDEBUG],
                   [$(test "$ac_cv_enable_debug" != yes)$?],
                   [build with additional debugging code])

AC_DEFINE_UNQUOTED([EM_USE_VALGRIND_FRIENDLY],
                   [$(test "$ac_cv_enable_valgrind_friendly" != yes)$?],
                   [do extra cleanup to be valgrind clean])

dnl ------- End: configure.stdtools -----

dnl ----- Begin: configure.i18n -----
dnl Makeup i18n configure boilerplate.
dnl
dnl Copyright 2003 - 2015, Ron <ron@debian.org>
dnl
dnl This file is distributed under the terms of the GNU GPL version 2.
dnl
dnl As a special exception to the GPL, it may be distributed without
dnl modification as a part of a program using a makeup generated build
dnl system, under the same distribution terms as the program itself.
dnl Modified versions are not obliged to also offer this exception,
dnl though if you wish not to do so then you should remove this paragraph
dnl and make it clear that your modifications are licenced strictly
dnl according to the GPL 2 or a compatible licence.

dnl Internal string encoding.

dnl XXX Expand this to specify the actual encoding to use.
dnl eg.  WCHAR_T, utf8, iso88591 etc.

AC_ARG_ENABLE([wide_strings],
              [AS_HELP_STRING([--enable-wide_strings],
                             [use wide characters by default for internal string storage (default NO)])],
              [ac_cv_enable_wide_strings=$enableval],
              [ac_cv_enable_wide_strings=no])

AC_DEFINE_UNQUOTED([EM_USE_WIDE_STRINGS],
                   [$(test "$ac_cv_enable_wide_strings" != yes)$?],
                   [use wide characters by default for internal string storage])

AS_IF([test "$ac_cv_enable_wide_strings" = yes],[

    makeup_build_flavour="${makeup_build_flavour}w"

    case $host in
        *-*-cygwin* | *-*-mingw32* )
            AC_DEFINE([UNICODE],[1],[Enable billware in 'UNICODE' mode])
            AC_MSG_NOTICE([using UNICODE])
            ;;
        * )
            ;;
    esac

])


dnl String encoding conversion.
AC_ARG_WITH([iconv],
            [AS_HELP_STRING([--with-iconv],
                [use iconv (from glibc or libiconv) for string encoding conversion (default YES)])],
            [ac_cv_with_iconv=$withval],
            [ac_cv_with_iconv=yes])

dnl Localised string substitution.
AC_ARG_WITH([gettext],
            [AS_HELP_STRING([--with-gettext],
                [use gettext (from glibc or libintl) to localise selected literal strings (default YES)])],
            [ac_cv_with_gettext=$withval],
            [ac_cv_with_gettext=yes])


dnl Some of these are covered by AM_GNU_GETTEXT now.
dnl AC_ARG_VAR([XGETTEXT],[xgettext command])
dnl AC_ARG_VAR([MSGMERGE],[msgmerge command])
dnl AC_ARG_VAR([MSGFMT],[msgfmt command])

dnl A couple still are not.
AC_ARG_VAR([XGETTEXT_ARGS],[xgettext arguments])
AC_ARG_VAR([MSGINIT],[msginit command])
AC_ARG_VAR([ALL_LINGUAS],[The list of supported ISO 639 language codes])
AC_ARG_VAR([GETTEXT_MSG_SRC],[Limit the search for messages to $(GETTEXT_MSG_SRC)/])

dnl This one is needed for the AC_LIB_RPATH macro, required by AM_GNU_GETTEXT.
FIND_AND_LINK_IF_LOCAL([config.rpath],[${ac_aux_dir#$srcdir/}],[/usr/share/gettext])

dnl We check this before iconv, as it _may_ do some iconv tests
dnl that we will not need to repeat, or even hit the cache for.
AS_IF([test "$ac_cv_with_gettext" != no],[

    dnl FIXME: AM_GNU_GETTEXT pollutes CPPFLAGS with the default path
    dnl        for mingw-cross builds...  so for now:
    eg_save_CPPFLAGS=$CPPFLAGS

    dnl imported from /usr/share/aclocal/gettext.m4
    AM_GNU_GETTEXT([external],[need-ngettext])
    CPPFLAGS=$eg_save_CPPFLAGS

    dnl These are set by AM_GNU_GETTEXT above now.
    dnl AC_CHECK_TOOL(XGETTEXT, xgettext)
    dnl AC_CHECK_TOOL(MSGMERGE, msgmerge)
    dnl AC_CHECK_TOOL(MSGFMT, msgfmt)

    dnl This is done implicitly by linking to a built test.
    dnl AC_CHECK_HEADERS(libintl.h)

    dnl Making this test useless.
    dnl if test "$ac_cv_header_libintl_h" != "yes"; then

    dnl and we must do this obscenity instead
    AS_IF([test "$gt_cv_func_gnugettext2_libc" != yes &&
           test "$gt_cv_func_gnugettext2_libintl" != yes],[
        AC_MSG_WARN([gettext not supported on this platform.  disabling.])
        ac_cv_with_gettext=no
    ],[
        dnl These we must still do for ourself.
        AC_CHECK_TOOL([MSGINIT],[msginit],[:])
        XGETTEXT_ARGS="-C -k_ -k_P:1,2 -s"
        I18N_LIBS="\$(LIBINTL) $I18N_LIBS"

        dnl Do we really want to always add this unconditionally here?
        LIBS=$(echo $LIBINTL $LIBS)
    ])
])

AC_DEFINE_UNQUOTED([EM_USE_GETTEXT],
                   [$(test "$ac_cv_with_gettext" != yes)$?],
                   [use gettext to localise selected literal strings])


dnl String encoding conversion.
AS_IF([test "$ac_cv_with_iconv" != no],[

    dnl FIXME: AM_ICONV_LINK pollutes CPPFLAGS with the default path
    dnl        for mingw-cross builds...  so for now:
    eg_save_CPPFLAGS=$CPPFLAGS

    dnl imported from /usr/share/aclocal/iconv.m4
    AM_ICONV
    CPPFLAGS=$eg_save_CPPFLAGS

    dnl and a couple of useful things it does not do.
    AS_IF([test "$am_cv_func_iconv" = yes],[

        case $host in
            *-*-cygwin* | *-*-mingw32* )  eg_path_iconv=iconv                   ;;
            * )                           AC_PATH_PROG([eg_path_iconv],[iconv]) ;;
        esac

        AS_IF([test -n "$eg_path_iconv"],[
            AC_DEFINE_UNQUOTED([ICONV_UTIL_PATH],
                               ["$eg_path_iconv"],
                               [Define this with the path to the iconv utility])
        ])

        AC_DEFINE_UNQUOTED([HAVE_ICONV_CONST],
                           [$(test "$am_cv_proto_iconv_arg1" != const)$?],
                           [The system iconv requires a const char** second argument])

        I18N_LIBS="\$(LIBICONV) $I18N_LIBS"

        dnl Do we really want to always add this unconditionally too?
        LIBS=$(echo $LIBICONV $LIBS)
    ])
])

dnl ------- End: configure.i18n -----

dnl ----- Begin: ./Makeup/config/configure.bit-babbler -----
dnl Makeup extra configuration for bit-babbler.
dnl
dnl Copyright 2003 - 2018, Ron Lee.
dnl
AC_LANG_PUSH([C++])

expect_udev=no

case $host in
    *-*-linux* )
	expect_udev=yes
    ;;

    *-*-cygwin* | *-*-mingw32* )
	dnl We don't have unix domain sockets on windows, so default to TCP there.
	AS_IF([test -z "$SEEDD_CONTROL_SOCKET"],
	      [SEEDD_CONTROL_SOCKET=tcp:localhost:56789])

	dnl We need at least 0x0600 to get AI_ADDRCONFIG for getaddrinfo
	ac_cv_env_winver=0x0600
	ac_cv_env__win32_winnt=0x0600
	AC_DEFINE_UNQUOTED([WINVER], [$ac_cv_env_winver],
			   [Select the MSW version to be compatible with])
	AC_DEFINE_UNQUOTED([_WIN32_WINNT], [$ac_cv_env__win32_winnt],
			   [The MSW NT version to be compatible with])

	AC_MSG_NOTICE([using WINVER = '$ac_cv_env_winver', _WIN32_WINNT = '$ac_cv_env__win32_winnt'])

	dnl Testing for vasprintf has the opposite problem to what localtime_r does
	dnl as described below.  It's included in the system library, so a link test
	dnl passes with a faked prototype, but an actual build fails because it is
	dnl not visible in stdio.h unless _GNU_SOURCE is defined.
	AC_DEFINE([_GNU_SOURCE],[1],[Include support for vasprintf et al.])
    ;;

    *-*-openbsd* )
	dnl We don't have a /run directory by default, so use /var/run
	AS_IF([test -z "$SEEDD_CONTROL_SOCKET"],
	      [SEEDD_CONTROL_SOCKET=/var/run/bit-babbler/seedd.socket])

	dnl The default pthread stack size on OpenBSD 6.1 is 512kB, so fix that.
	AS_IF([test -z "$THREAD_STACK_SIZE"],[THREAD_STACK_SIZE=8192])

	AC_DEFINE([HAVE_BROKEN_STDIO_LOCKING],[1],
                  [Workaround OpenBSD _thread_flockfile cancellation bug])
    ;;

    *-*-freebsd* )
	dnl We don't have a /run directory by default, so use /var/run
	AS_IF([test -z "$SEEDD_CONTROL_SOCKET"],
	      [SEEDD_CONTROL_SOCKET=/var/run/bit-babbler/seedd.socket])

	dnl The default pthread stack size on FreeBSD 11 is 2MB, so fix that.
	dnl So far we haven't actually had this smash the stack there with
	dnl the default size (unlike OpenBSD, MacOS and Windows), but let's
	dnl not wait until we do, just use the same size as everywhere else.
	AS_IF([test -z "$THREAD_STACK_SIZE"],[THREAD_STACK_SIZE=8192])

	dnl On FreeBSD 11, both gcc6 and gcc7 will miscompile code when the
	dnl -fguess-branch-probability optimisation is enabled (which it is
	dnl with anything above -O0).  We don't currently have a trivial test
	dnl case for that which we can use here, but the symptom is having an
	dnl exception which should normally be safely caught, instead invoke
	dnl terminate and kill the application.  It would appear that the
	dnl stack context for unwinding is being lost in some code paths by
	dnl this optimisation, since an exception thrown in one path will be
	dnl fine, but one right next to it in another will explode.
	dnl
	dnl So until we have some proof of it being fixed, disable that when
	dnl using gcc.  We can't actually directly test if we are using gcc,
	dnl because clang lies and defines all of gcc's macros, so instead
	dnl we can only test if we are not using clang (which would choke on
	dnl this test anyway, since it doesn't currently support that flag
	dnl in any case.
	save_CXXFLAGS="$CXXFLAGS"
	CXXFLAGS="$CXXFLAGS -fno-guess-branch-probability"
	AC_CACHE_CHECK([if $CXX needs -fno-guess-branch-probability],
		       [bb_cv_flag_guess_branch_probability],
		       [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
							   [[ #ifdef __clang__
								using the clang compiler
							      #endif
							   ]]
							  )],
					  [bb_cv_flag_guess_branch_probability=yes],
					  [bb_cv_flag_guess_branch_probability=no]
					 )
		      ])

	AS_IF([test "$bb_cv_flag_guess_branch_probability" = "yes"],[],[CXXFLAGS="$save_CXXFLAGS"])

	dnl And as above -freorder-blocks can cause the same symptom to manifest
	dnl on FreeBSD 11 with both gcc6 and gcc7, just in different places in
	dnl the code.
	save_CXXFLAGS="$CXXFLAGS"
	CXXFLAGS="$CXXFLAGS -fno-reorder-blocks"
	AC_CACHE_CHECK([if $CXX needs -fno-reorder-blocks],
		       [bb_cv_flag_reorder_blocks],
		       [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
							   [[ #ifdef __clang__
								using the clang compiler
							      #endif
							   ]]
							  )],
					  [bb_cv_flag_reorder_blocks=yes],
					  [bb_cv_flag_reorder_blocks=no]
					 )
		      ])

	AS_IF([test "$bb_cv_flag_reorder_blocks" = "yes"],[],[CXXFLAGS="$save_CXXFLAGS"])

	dnl And yet one more, that does it in yet another place.
	dnl If these continue to shake out, it might be safer to just build
	dnl with -O0 on FreeBSD 11 with gcc ...
	save_CXXFLAGS="$CXXFLAGS"
	CXXFLAGS="$CXXFLAGS -fno-tree-dominator-opts"
	AC_CACHE_CHECK([if $CXX needs -fno-tree-dominator-opts],
		       [bb_cv_flag_tree_dominator_opts],
		       [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
							   [[ #ifdef __clang__
								using the clang compiler
							      #endif
							   ]]
							  )],
					  [bb_cv_flag_tree_dominator_opts=yes],
					  [bb_cv_flag_tree_dominator_opts=no]
					 )
		      ])

	AS_IF([test "$bb_cv_flag_tree_dominator_opts" = "yes"],[],[CXXFLAGS="$save_CXXFLAGS"])
    ;;

    *-*-darwin* )
	dnl We don't have a /run directory by default, so use /var/run
	AS_IF([test -z "$SEEDD_CONTROL_SOCKET"],
	      [SEEDD_CONTROL_SOCKET=/var/run/bit-babbler/seedd.socket])

	dnl The default pthread stack size on MacOS is only 512kB, and we expect to
	dnl need more than that, so bring it into line with the normal Linux default.
	AS_IF([test -z "$THREAD_STACK_SIZE"],[THREAD_STACK_SIZE=8192])
    ;;
esac


dnl /var could be a remote mount which isn't available at early boot when seedd
dnl is first started, but /run is supposed to be ready before any ordinary early
dnl boot process even if it is a separate mount like a tmpfs, so default to it
dnl unless we know it's not expected to be supported.  FHS 3.0 allows /var/run
dnl to be an alias to /run, and that is what most (but not all) Linux distros
dnl currently do.  The BSDs (aside from Debian's kFreeBSD port) aren't riding
dnl this train yet though, so we still use /var/run there instead of rudely
dnl creating a new directory in the root of people's systems.
AS_IF([test -z "$SEEDD_CONTROL_SOCKET"],
      [SEEDD_CONTROL_SOCKET=/run/bit-babbler/seedd.socket])

AC_ARG_VAR([SEEDD_CONTROL_SOCKET], [Set the default to use for the seedd control socket])
AS_IF([test -n "$SEEDD_CONTROL_SOCKET"],[
      AC_DEFINE_UNQUOTED([SEEDD_CONTROL_SOCKET],["$SEEDD_CONTROL_SOCKET"],
                         [Set the default to use for the seedd control socket])
    ])


dnl Clang bitches about "GNU old-style field designator extension" in C++ code
dnl even though the C99 designated initialiser style isn't supported by C++,
dnl even as a GNU extension.  We use the old initialiser style though, so hush
dnl the warnings about it until we have some real alternative we can use instead.
dnl
dnl We test explicitly for clang as part of this, because gcc will silently ignore
dnl it as an unknown warning type, unless there is some other compile time warning
dnl in which case it will also warn about the unrecognised command line option too.
save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS -Wno-gnu-designator"
AC_CACHE_CHECK([if $CXX needs -Wno-gnu-designator],[bb_cv_flag_gnu_designator],
               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],
                                                   [[ #ifndef __clang__
                                                        not using the clang compiler
                                                      #endif
                                                   ]]
                                                  )],
                                  [bb_cv_flag_gnu_designator=yes],
                                  [bb_cv_flag_gnu_designator=no]
                                 )
              ])

AS_IF([test "$bb_cv_flag_gnu_designator" = "yes"],[],[CXXFLAGS="$save_CXXFLAGS"])


AC_C_BIGENDIAN

AC_CHECK_FUNCS([vasprintf])

dnl See if clock_gettime is available even without librt.  On some systems
dnl it is, and as of glibc 2.17 the clock_* functions moved from librt to
dnl the main C library as well.  We don't particularly want to depend upon
dnl librt, for lots of reasons, but using this if we do have it is sane.
dnl
dnl Testing for localtime_r and gmtime_r in this way fails on mingw-w64 4.9.2
dnl even though it does actually have them when either of _POSIX_C_SOURCE or
dnl _POSIX_THREAD_SAFE_FUNCTIONS are defined - because AC_CHECK_FUNCS tries to
dnl link a faked prototype, but in the mingw time.h they are inline functions
dnl only, wrapping the system localtime_s function. We could do a more complex
dnl test here, but it's probably ok to just let them fall back to using the
dnl non-reentrant versions, because on MSW, localtime and gmtime are in theory
dnl implemented using thread-local storage, so they are thread-safe anyway.
AC_CHECK_FUNCS([gettimeofday localtime_r gmtime_r timegm clock_gettime])


dnl On FreeBSD we need xlocale.h for strtod_l.  That header is available on
dnl Linux (though we shouldn't normally include it directly), but is not
dnl available for mingw, and possibly some other platforms too (since it is
dnl not a standard header at this time).
AC_CHECK_HEADERS([xlocale.h])

dnl Windows has it's own incarnations of newlocale/strtod_l, and some platforms
dnl like OpenBSD (as of 6.1) don't implement the POSIX newlocale at all, let
dnl alone the xlocale extensions which use it.  All we can really do for those
dnl is fall back to using strtod, and if the user is in a locale where the
dnl decimal point is a comma or something similar, they get to keep the pieces
dnl or will need to override their default locale for running this.
AC_CHECK_FUNCS([newlocale])

dnl The _create_locale function needs a later C runtime than the default.
AS_IF([test "$ac_cv_func_newlocale" = "yes"],[],
      [save_LIBS=$LIBS
       LIBS="$LIBS -lmsvcr110"
       AC_CHECK_FUNCS([_create_locale])
       LIBS=$save_LIBS
    ])

AC_CHECK_FUNCS([strtod_l _strtod_l], [break])

AS_IF([test "$ac_cv_func_strtod_l" = "yes"],[],
      [test "$ac_cv_func__strtod_l" = "yes"],[],
      [AC_MSG_WARN([No localisable strtod available on this system.])
       AC_MSG_WARN([Binaries will need to be run in the "C" locale.])])


dnl Check if SIGRTMIN is available.  MacOS 10.12.1 still doesn't have it
dnl (though FreeBSD added support for it in version 7).
AC_CHECK_DECLS([SIGRTMIN],[],[],[[#include <signal.h>]])

dnl OpenBSD as of at least 6.1 doesn't provide this (though FreeBSD and MacOS
dnl at least do) and it isn't required by POSIX.1-2008 (SuSv4 TC2 2016).
AC_CHECK_DECLS([LOG_MAKEPRI],[],[],[[#include <syslog.h>]])


dnl The C++ stack unwinding exception for thread cancellation was a GNU extension
dnl and though it is supported on some platforms by clang too, it isn't supported
dnl on every platform that is using gcc either.  So first, test if we have it.
AC_CACHE_CHECK([for abi::__forced_unwind],[bb_cv_type_forced_unwind],
               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <cxxabi.h> ]],
                                                   [[ void f(const abi::__forced_unwind&); ]]
                                                  )],
                               [bb_cv_type_forced_unwind=yes],
                               [bb_cv_type_forced_unwind=no]
                              )
             ])

dnl If we don't, test if we at least have the "abi" namespace defined.
AS_IF([test "$bb_cv_type_forced_unwind" = "yes"],
      [AC_DEFINE([HAVE_ABI_FORCED_UNWIND],[1],
                 [Have abi::__forced_unwind support])],
      [AC_CACHE_CHECK([for namespace abi],[bb_cv_namespace_abi],
                      [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <cxxabi.h> ]],
                                                          [[ using namespace abi; ]]
                                                         )],
                                         [bb_cv_namespace_abi=yes],
                                         [bb_cv_namespace_abi=no]
                                        )
                    ])
    ])

dnl If the "abi" namespace is defined, we still might not be able to place our
dnl own replacement type into it, since that is an illegal construct if "abi"
dnl is an alias to some other namespace.  Right now, on all platforms we know
dnl of, it is an alias to __cxxabiv1, so test for that, and use it if so.
dnl If it's not, then either "abi" is a real namespace and we can just use it
dnl directly (which is what we attempt if this test fails), or it's aliased to
dnl some other internal namespace name - in which case the build should fail
dnl and we'll need to add a new test for additional names if/when someone ever
dnl hits that.
AS_IF([test "$bb_cv_namespace_abi" = "yes"],
      [AC_CACHE_CHECK([for namespace abi alias to __cxxabiv1],[bb_cv_namespace_alias_abi],
                      [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <cxxabi.h>
                                                             namespace __cxxabiv1 { struct xx {}; }
                                                          ]],
                                                          [[ abi::xx x; ]]
                                                         )],
                                         [bb_cv_namespace_alias_abi=yes],
                                         [bb_cv_namespace_alias_abi=no]
                                        )
                    ])
    ])

AS_IF([test "$bb_cv_namespace_alias_abi" = "yes"],
      [AC_DEFINE([HAVE_ABI_ALIAS_TO_CXXABIV1],[1],
                 [Have namespace abi alias to __cxxabiv1])
    ])


dnl Check for pthread_setname_np.  We can't just use AC_CHECK_FUNCS for this one
dnl because it has different signatures on different platforms.  Right now we
dnl mostly care about distinguishing the GNU version which takes two parameters
dnl and the MacOS one which only takes a name and must be called from the thread
dnl where the name is to be set.
save_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS"

AC_CACHE_CHECK([for GNU pthread_setname_np],[bb_cv_func_gnu_pthread_setname_np],
               [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <pthread.h> ]],
                                                [[ pthread_setname_np(pthread_self(),"x"); ]]
                                               )],
                               [bb_cv_func_gnu_pthread_setname_np=yes],
                               [bb_cv_func_gnu_pthread_setname_np=no]
                              )
             ])

AS_IF([test "$bb_cv_func_gnu_pthread_setname_np" = "yes"],
      [AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_GNU],[1],
                 [Have GNU style pthread_setname_np(pthread_t thread, const char *name)])],
      [AC_CACHE_CHECK([for MacOS pthread_setname_np],[bb_cv_func_mac_pthread_setname_np],
                      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <pthread.h> ]],
                                                       [[ pthread_setname_np("x"); ]]
                                                      )],
                                      [bb_cv_func_mac_pthread_setname_np=yes],
                                      [bb_cv_func_mac_pthread_setname_np=no]
                                     )
                    ])
    ])

AS_IF([test "$bb_cv_func_mac_pthread_setname_np" = "yes"],
      [AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_MAC],[1],
                 [Have MacOS style pthread_setname_np(const char *name)])
    ])

dnl OpenBSD and FreeBSD have pthread_set_name_np declared in pthread_np.h
AS_IF([test "$bb_cv_func_gnu_pthread_setname_np" != "yes" && test "$bb_cv_func_mac_pthread_setname_np" != "yes"],
      [AC_CHECK_FUNCS([pthread_set_name_np])
    ])

LDFLAGS=$save_LDFLAGS

AC_ARG_VAR([THREAD_STACK_SIZE], [Explicitly set the per-thread stack size in kB (if non-zero)])
AS_IF([test -n "$THREAD_STACK_SIZE"],[
      AC_DEFINE_UNQUOTED([THREAD_STACK_SIZE],[$THREAD_STACK_SIZE],
                         [Explicitly set the per-thread stack size in kB (if non-zero)])
    ])


dnl Check what support we have for a hashed map type.  We should almost never
dnl need to fall back as far as the __gnu_cxx::hash_map anymore, but we are
dnl still at that awkward stage in the transition between the tr1 implementation
dnl and the standardised in C++11 one.  For bonus fun, in some cases, like clang
dnl in FreeBSD 10.3, the tr1 header is provided (as a symlink to the "standard"
dnl one), but the type is not actually included in the std::tr1 namespace at all.
AC_CHECK_HEADERS([unordered_map],[],
                 [AC_CHECK_HEADERS([tr1/unordered_map],[],
	                           [AC_CHECK_HEADERS([ext/hash_map])])])


dnl The FreeBSD libusb3 provides compatibility for libusb-0.1, libusb-1.0 and
dnl their own libusb2 interface, with libusb.so as the -dev link to it.
dnl On Linux libusb.so usually points to libusb-0.1, which we don't want.
dnl The header file is usually in $prefix/include/libusb-1.0 on linux, and in
dnl the system include dir on FreeBSD.
AC_ARG_VAR([LIBUSB_DIR], [Path for libusb (mostly for cross-compiling)])
AC_ARG_VAR([USB_CPPFLAGS], [Extra CPPFLAGS for libusb (mostly for cross-compiling)])
AC_ARG_VAR([USB_LDFLAGS], [Extra LDFLAGS for libusb (mostly for cross-compiling)])

AS_IF([test -n "$LIBUSB_DIR"],[
    USB_CPPFLAGS="-I$LIBUSB_DIR/include $USB_CPPFLAGS"
    USB_LDFLAGS="-L$LIBUSB_DIR/lib $USB_LDFLAGS"
])


save_CPPFLAGS=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $USB_CPPFLAGS"

AC_CHECK_HEADERS([libusb-1.0/libusb.h libusb.h],[break])

AS_IF([test "$ac_cv_header_libusb_1_0_libusb_h" = "yes"],[
	libusb_header="<libusb-1.0/libusb.h>"
      ],[test "$ac_cv_header_libusb_h" = "yes"],[
	libusb_header="<libusb.h>"
])

AS_IF([test -n "$libusb_header"],[
    AC_DEFINE_UNQUOTED([LIBUSB_HEADER],[$libusb_header],[libusb header location])
])

CPPFLAGS=$save_CPPFLAGS


save_LDFLAGS=$LDFLAGS
save_LIBS=$LIBS
LDFLAGS="$LDFLAGS $USB_LDFLAGS"

AC_SEARCH_LIBS([libusb_init], [usb-1.0 usb],
	       [
		  AC_DEFINE([HAVE_LIBUSB],[1],[libusb is available])
		  AS_CASE([$ac_cv_search_libusb_init],
			  [-l*],[[USB_LIBS=${ac_cv_search_libusb_init#-l}]])

		  dnl We need the double quoting in the case above or the # in
		  dnl the prefix removal breaks the macro expansion horribly.
	       ],[
		  AC_MSG_WARN([libusb not found])
		  case $host in
		    *-*-openbsd* )
			bb_missing_deps="$bb_missing_deps libusb1-1.0"
		    ;;

		    *-*-kfreebsd* )
			bb_missing_deps="$bb_missing_deps libusb2-dev"
		    ;;

		    * )
			bb_missing_deps="$bb_missing_deps libusb-1.0-0-dev"
		    ;;
		  esac
	       ])

dnl We need to test for these explicitly, because LIBUSB_API_VERSION won't do.
dnl It wasn't bumped when libusb_strerror was added, and it just doesn't exist
dnl at all in the FreeBSD libusb3, which does provide libusb_get_port_numbers
dnl even though it currently just returns LIBUSB_ERROR_NOT_SUPPORTED ...
dnl And that kids, is why we have autoconf.
dnl As of FreeBSD 11, we also need to test for libusb_has_capability, since it
dnl appears they added the hotplug support API and bumped the compatibility
dnl version, but didn't actually add the capability test function ...
AC_CHECK_FUNCS([libusb_strerror libusb_get_port_numbers libusb_has_capability])

LIBS=$save_LIBS
LDFLAGS=$save_LDFLAGS

AC_SUBST([USB_LIBS])


dnl Option, check, and substvars for libudev.
dnl We default to yes for this one, because most people probably will want the
dnl hotplug (and hot reconfiguration) support this provides, but likely won't
dnl already have libudev installed.  If the static scan option is sufficient,
dnl that can be selected by disabling this explicitly.
AC_ARG_WITH([udev],
            [AS_HELP_STRING([--with-udev],
                            [use libudev for device detection (default yes on Linux, else no)])],
            [ac_cv_with_udev=$withval],
            [ac_cv_with_udev=$expect_udev])

AS_IF([test "$ac_cv_with_udev" != no],[
    AC_CHECK_LIB([udev],[udev_new],
		 [
		    AC_DEFINE([HAVE_LIBUDEV],[1],[libudev is available])
		    UDEV_LIBS="udev"
		    ac_cv_with_udev=yes

		    dnl The udev_device_get_tags_list_entry function was added in udev 154
		    dnl and udev_device_get_sysattr_list_entry was added in udev release 167,
		    dnl which is newer than some current distro releases are shipping still.
		    dnl RHEL/CentOS 6 at least appears to ship udev 147 and it isn't EOL yet.
		    save_LIBS=$LIBS
		    LIBS="$LIBS -l$UDEV_LIBS"
		    AC_CHECK_FUNCS([udev_device_get_tags_list_entry udev_device_get_sysattr_list_entry])
		    LIBS=$save_LIBS
		 ],[
		    AS_IF([test "$ac_cv_with_udev" != auto],[
			AC_MSG_WARN([libudev not found])
			bb_missing_deps="$bb_missing_deps libudev-dev (or configure --without-udev)"
                    ])
		    ac_cv_with_udev=no
		 ])
])

AC_SUBST([UDEV_LIBS])

AC_LANG_POP([C++])


AS_IF([test -n "$bb_missing_deps"],[
    AC_MSG_ERROR([You'll also need these packages installed:$bb_missing_deps])
])

dnl We defer failing out on this until here, because the most likely reason is
dnl just that libusb itself is missing, which will be reported above, and that
dnl is a more useful explaination to give if so.  This should only trigger if
dnl the lib is installed but the header is in some wacky place we didn't look.
AS_IF([test -z "$libusb_header"],[
    AC_MSG_ERROR([No libusb header file found])
])


AC_MSG_NOTICE([Configured bit-babbler $PACKAGE_VERSION])
AC_MSG_NOTICE([  with udev:            $ac_cv_with_udev])
AC_MSG_NOTICE([  SEEDD_CONTROL_SOCKET: $SEEDD_CONTROL_SOCKET])
AS_IF([test -n "$THREAD_STACK_SIZE"],[
AC_MSG_NOTICE([  THREAD_STACK_SIZE:    $THREAD_STACK_SIZE])
])


case $host in
    *-*-openbsd* )
	AC_MSG_NOTICE([NOTE: On OpenBSD you will need to build this by using gmake,])
	AC_MSG_NOTICE([      and you will need to have the bash package installed.])
    ;;

    *-*-freebsd* )
	AC_MSG_NOTICE([NOTE: On FreeBSD you will need to build this by using gmake,])
	AC_MSG_NOTICE([      and you will need to have the bash package installed.])

	dnl Also warn if the default compiler (which is probably clang) is missing
	dnl important things which you could get support for just by using g++,
	AS_IF([test "$bb_cv_type_forced_unwind" = "yes"],[],
	      [AC_MSG_NOTICE([      Also you would have better functionality if built using gcc.])
	       AC_MSG_NOTICE([      See doc/README.FreeBSD for more details.])
	    ])
    ;;
esac

AC_CONFIG_FILES([munin/bit_babbler],[chmod +x munin/bit_babbler])
dnl ------- End: ./Makeup/config/configure.bit-babbler -----

AC_ARG_VAR([MAKEUP_PLATFORM_HEADER],[platform specific config header])
AC_ARG_VAR([MAKEUP_FLAVOUR_HEADER],[feature specific config header])

MAKEUP_PLATFORM_HEADER="${makeup_build_platform}_setup.h"
MAKEUP_FLAVOUR_HEADER="$makeup_build_platform${makeup_build_flavour}_setup.h"

CPPFLAGS="$CPPFLAGS -I\$(top_builddir)/include \$(EXTRACPPFLAGS)"
CFLAGS="$CFLAGS \$(EXTRACFLAGS)"
CXXFLAGS="$CXXFLAGS \$(EXTRACXXFLAGS)"

AH_BOTTOM([#include <setup.h>])

ACM_CONFIG_MAKEFILE([Makeup/gmake-fragments],
                    [
                     makeup_version="0.32"
                     package_name="bit-babbler"
                     package_version="0.8"
                     __package_config_dir=""
                     __package_config_public="setup.h"
                    ])
AC_CONFIG_HEADERS([include/private_setup.h:private_setup.h.in],[],
                  [
                   if test ! -e $srcdir/private_setup.h.in; then
                       touch $srcdir/private_setup.h.in;
                   fi;
                  ])
ACM_CONFIG_HEADER([setup.h])

AC_CONFIG_FILES([Makefile.acsubst.bit-babbler:Makeup/config/acsubst.bit-babbler])

AC_OUTPUT