summaryrefslogtreecommitdiffstats
path: root/configure.ac
blob: d978e881fff21c7e21d6927ad55d6d84fcf67f30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
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
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
dnl #############################################################
dnl #
dnl #  For information about autoconf, see:
dnl #
dnl #  http://www.gnu.org/software/autoconf/
dnl #
dnl #  The recommended order is:
dnl #
dnl #  AC_INIT(file)
dnl #  0. checks for compiler, libtool, and command line options
dnl #  1. checks for programs
dnl #  2. checks for libraries
dnl #  3. checks for header files
dnl #  4. checks for typedefs
dnl #  5. checks for structures and functions
dnl #  6. checks for compiler characteristics
dnl #  7. checks for library functions
dnl #  8. checks for system services
dnl #  AC_OUTPUT([file...])
dnl #
dnl #############################################################

AC_PREREQ([2.68])
export CFLAGS LIBS LDFLAGS CPPFLAGS

AC_INIT([freeradius],[$]Id[$],[http://bugs.freeradius.org],,[http://www.freeradius.org])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/main/radiusd.c])
AC_CONFIG_HEADER([src/include/autoconf.h])

dnl #############################################################
dnl #
dnl #  Custom hackery to discover version at configure time
dnl #
dnl #############################################################
RADIUSD_MAJOR_VERSION=`cat VERSION | cut -f1 -d.`
RADIUSD_MINOR_VERSION=`cat VERSION | cut -f2 -d.`
RADIUSD_INCRM_VERSION=`cat VERSION | cut -f3 -d. | sed 's/[[\.-]].*$//'`

RADIUSD_VERSION=`printf "%02i%02i%02i" $RADIUSD_MAJOR_VERSION $RADIUSD_MINOR_VERSION $RADIUSD_INCRM_VERSION`

dnl #
dnl #  Still useful for custom builds
dnl #
RADIUSD_VERSION_STRING=`cat VERSION`

dnl #
dnl #  Add definitions to Make.inc as it's used by various build targets
dnl #
AC_SUBST([RADIUSD_VERSION_STRING])

dnl #
dnl #  Add definitions to autoconf.h, so that the headers that we install
dnl #  contain the version number of the server.
dnl #
AC_DEFINE_UNQUOTED([RADIUSD_VERSION], [${RADIUSD_VERSION}], [Version integer in format <ma><ma><mi><mi><in><in>])
AC_DEFINE_UNQUOTED([RADIUSD_VERSION_STRING], ["${RADIUSD_VERSION_STRING}"], [Raw version string from VERSION file])

dnl #############################################################
dnl #
dnl #  Override some of the default autoconf variables such as
dnl #  CFLAGS if were building in developer mode
dnl #
dnl #############################################################

dnl #
dnl #  Unset ASAN_OPTIONS and LSAN_OPTIONS so they don't interfere
dnl #  with the build process.
dnl #
unset ASAN_OPTIONS
unset LSAN_OPTIONS

dnl #
dnl # check for JSON.pm, ASCIIDOCTOR and pandoc
dnl #
AC_PATH_PROG(ASCIIDOCTOR, asciidoctor)
if test "x$ac_cv_path_ASCIIDOCTOR" = "x"; then
  AC_MSG_WARN([asciidoctor not found - Please install if you want build the docs])
fi

AC_PATH_PROG(PANDOC, pandoc)
if test "x$ac_cv_path_PANDOC" = "x"; then
  AC_MSG_WARN([pandoc not found - Please install if you want build the docs])
else
  #
  #  Pandoc v2 onwards renamed --latex-engine to --pdf-engine
  #
  if pandoc --help 2>&1 | grep -q "latex-engine"; then
    PANDOC_ENGINE=latex
  else
    PANDOC_ENGINE=pdf
  fi
  AC_SUBST(PANDOC_ENGINE)
fi

# pandoc and asciidoctor is defined? then check it.
if test "x$ac_cv_path_PANDOC" != "x" && test "x$ac_cv_path_ASCIIDOCTOR" != "x"; then
  AX_PROG_PERL_MODULES(JSON, , AC_MSG_WARN([Perl JSON module not found - Please install if you want build the docs]))
fi

dnl #
dnl # check for doxygen
dnl #
AC_PATH_PROG(DOXYGEN, doxygen)
if test "x$ac_cv_path_DOXYGEN" != "x"; then
  AC_PATH_PROG(GRAPHVIZ_DOT, dot)
  if test "x$ac_cv_path_GRAPHVIZ_DOT" = "x"; then
    AC_MSG_WARN([dot not found - Please install the graphviz if you want to build the docs/source])
  fi
else
  AC_MSG_WARN([doxygen not found - Please install if you want build the docs/source])
fi

dnl #
dnl # check for Antora
dnl #
AC_PATH_PROG(ANTORA, antora)
if test "x$ac_cv_path_ANTORA" = "x"; then
  AC_MSG_WARN([antora not found - Please install if you want build the site])
fi

dnl #
dnl #  Enable developer features like debugging symbols.
dnl #  These checks must be done before expanding the AC_PROG_CC
dnl #  and AC_PROG_CXX macros.
dnl #
AC_ARG_ENABLE(developer,
[  --enable-developer      enables features of interest to developers.],
[ case "$enableval" in
  no)
    developer=no
    ;;
  *)
    developer=yes
  esac ]
)

dnl #
dnl #  Turn on the developer flag when taken from a git checkout (not a release)
dnl #
if test -d $srcdir/.git; then
  if test "x$developer" != "xno"; then
    AC_MSG_NOTICE([found .git directory, enabling developer build implicitly, disable with --disable-developer])
    developer="yes"
  fi
fi

dnl #
dnl #  Autoconf sets -O2 and -g by default, but this is a PITA for debugging
dnl #  so we remove the defaults if were building in developer mode, and set
dnl #  -g3 so nice things like macro values are included. Other arguments are
dnl #  added later when we know what compiler were using.
dnl #
if test "x$developer" = "xyes"; then
  : ${CFLAGS=-g3}
fi

dnl #
dnl #  The developer option WITH_VERIFY_PTR significantly scews profiling so
dnl #  we allow it to be disabled.
dnl #
AC_ARG_ENABLE(verify-ptr,
[  --disable-verify-ptr    disables WITH_VERIFY_PTR developer build option.],
[ case "$enableval" in
  no)
    verify_ptr=""
    ;;
  *)
    verify_ptr="-DWITH_VERIFY_PTR=1"
  esac ],
[ verify_ptr="-DWITH_VERIFY_PTR=1" ],
)

dnl #
dnl #  Hard-code FIPS support/
dnl #
AC_ARG_ENABLE(fips-workaround,
[  --enable-fips-workaround    enables local MD4, MD5, etc. functionality to avoid OpenSSL FIPS issues.],
[ case "$enableval" in
  no)
    fips=""
    ;;
  *)
    fips="-DWITH_FIPS=1"
  esac ],
[ fips="" ],
)

dnl #############################################################
dnl #
dnl #  0. Checks for compiler, libtool, and command line options.
dnl #
dnl #############################################################

dnl #
dnl #  Get system information
dnl #
AC_CANONICAL_SYSTEM

dnl #
dnl #  clang etc. on OSX no longer searches the default paths for things,
dnl #  so we have to add them back in.
dnl #
case "$host" in
  *-darwin*)
    CFLAGS="$CFLAGS -DDARWIN"
    LDFLAGS="-L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib $LDFLAGS"
    LIBS="-F /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/ -framework DirectoryService $LIBS"
    ;;
esac


dnl #
dnl #  Check for GNU cc
dnl #
AC_PROG_CC
AC_PROG_CXX

dnl #
dnl #  check for AIX, to allow us to use some BSD functions
dnl #  must be before macros that call the compiler.
dnl #
AC_AIX

AC_PROG_GCC_TRADITIONAL
AC_PROG_CC_SUNPRO
AC_PROG_RANLIB

dnl #
dnl #  Definitive check for whether the compiler is clang
dnl #
AX_CC_IS_CLANG
if test "x$ax_cv_cc_clang" = "xyes"; then
  AC_SUBST(clang_path, "$CC")
else
  AC_SUBST(clang_path, "")
fi


dnl #
dnl #  Set Default CFLAGS for GCC compatible compilers
dnl #
if test "x$GCC" = "xyes"; then
  CFLAGS="$CFLAGS -Wall -std=c99 -D_GNU_SOURCE"
fi

dnl #
dnl # -Wno-unknown-warning-option means the compiler doesn't complain about diag pragmas
dnl # for warnings it doesn't understand.  This may sound like a bad idea, but consider
dnl # the number of different compiler versions we build under, and the fact that the
dnl # more anally retentive warnings are likely to be added in later versions.
dnl #
AX_CC_NO_UNKNOWN_WARNING_OPTION_FLAG
if test "x$ax_cv_cc_no_unknown_warning_option_flag" = "xyes"; then
  CFLAGS="$CFLAGS -Wno-unknown-warning-option"
fi

dnl #
dnl #  -Qunused-arguments means the compiler won't complain about unsupported arguments
dnl #
AX_CC_QUNUSED_ARGUMENTS_FLAG
if test "x$ax_cv_cc_qunused_arguments_flag" = "xyes"; then
  CFLAGS="$CFLAGS -Qunused-arguments"
  LDFLAGS="$LDFLAGS -Qunused-arguments"
fi

dnl #
dnl # Check for presence of -Wno-date-time warning. Older compilers
dnl # don't have it, and newer compilers warn without it...
dnl #
AX_CC_NO_DATE_TIME_FLAG

dnl #
dnl #  Compile in large (2G+) file support.
dnl #
AC_SYS_LARGEFILE

dnl #
dnl #  check for system bytesex
dnl #  AC_DEFINES WORDS_BIGENDIAN
dnl #
AC_C_BIGENDIAN(
  [AC_DEFINE(FR_BIG_ENDIAN, 1, [Define if your processor stores words with the most significant byte first])],
  [AC_DEFINE(FR_LITTLE_ENDIAN, 1, [Define if your processor stores words with the least significant byte first])]
)

dnl #
dnl #  Find GNU Make.
dnl #
AC_CHECK_PROG(GMAKE, gmake, yes, no)
if test $GMAKE = no; then
  AC_PATH_PROG(MAKE, make, /usr/local/bin/make)
else
  AC_PATH_PROG(MAKE, gmake, /usr/local/gnu/bin/make)
fi
makever=`$ac_cv_path_MAKE --version 2>&1 | grep "GNU Make"`
if test -z "$makever"; then
  AC_MSG_ERROR([GNU Make is not installed.  Please download and install it from ftp://prep.ai.mit.edu/pub/gnu/make/ before continuing.])
fi

dnl #
dnl #  autoconf explicitly sets MAKEFLAGS and MFLAGS to '' even though we
dnl #  didn't tell it to, so we have to use FR_MAKEFLAGS.
dnl #
dnl #  determine the number of cores available and set the number of build
dnl #  processes appropriately.
dnl #
AX_SYSTEM_CORES

dnl #  Temporarily disabled because test and installation targets do not
dnl #  have dependencies set up correctly for multiple build processes.
dnl if test "x$ax_cv_system_cores" != "x"; then
dnl  : ${FR_MAKEFLAGS=-j$ax_cv_system_cores}
dnl fi
AC_SUBST(FR_MAKEFLAGS)

dnl #
dnl #  See if we have Git.
dnl #
AC_CHECK_PROG(GIT, git, yes, no)

dnl Put this in later, when all distributed modules use autoconf.
dnl AC_ARG_WITH(disablemodulefoo,
dnl [  --without-rlm_foo         Disables module compilation.  Module list:]
dnl esyscmd([find src/modules -type d -name rlm_\* -print |\
dnl   sed -e 's%src/modules/.*/% (sub)- %; s%.*/%- %' |\
dnl   awk '{print "                            "$0}']))

AC_ARG_ENABLE(strict-dependencies,
[  --enable-strict-dependencies  fail configure on lack of module dependancy.])

AC_ARG_ENABLE(werror,
[  --enable-werror         causes the build to fail if any warnings are generated.],
[ case "$enableval" in
    no)
      werror=no
    ;;
    *)
      werror=yes
  esac ]
)

dnl #
dnl #  extra argument: --with-docdir
dnl #
docdir='${datadir}/doc/freeradius'
AC_MSG_CHECKING([docdir])
AC_ARG_WITH(docdir,
[  --with-docdir=DIR       directory for documentation [DATADIR/doc/freeradius] ],
[ case "$withval" in
  no)
    docdir=no
    ;;
  yes)
    ;;
  [[\\/$]]* | ?:[[\\/]]* )
    docdir="$withval"
    ;;
  *)
    AC_MSG_ERROR([expected an absolute directory name for --with-docdir: $withval])
    ;;
  esac ]
)
AC_SUBST(docdir)
AC_MSG_RESULT($docdir)
if test "x$docdir" = xno; then
  AC_MSG_WARN([Documentation files will NOT be installed.])
fi

dnl #
dnl #  extra argument: --with-logdir
dnl #
logdir='${localstatedir}/log/radius'
AC_MSG_CHECKING(logdir)
AC_ARG_WITH(logdir,
[  --with-logdir=DIR       directory for logfiles [LOCALSTATEDIR/log/radius] ],
[ case "$withval" in
  no)
    AC_MSG_ERROR([Need logdir])
    ;;
  yes)
    ;;
  [[\\/$]]* | ?:[[\\/]]* )
    logdir="$withval"
    ;;
  *)
    AC_MSG_ERROR([expected an absolute directory name for --with-logdir: $withval])
    ;;
  esac ]
)
AC_SUBST(logdir)
AC_MSG_RESULT($logdir)

dnl #
dnl #  extra argument: --with-radacctdir
dnl #
radacctdir='${logdir}/radacct'
AC_MSG_CHECKING(radacctdir)
AC_ARG_WITH(radacctdir,
[  --with-radacctdir=DIR   directory for detail files [LOGDIR/radacct] ],
[ case "$withval" in
  no)
    AC_MSG_ERROR([Need radacctdir])
    ;;
  yes)
    ;;
  [[\\/$]]* | ?:[[\\/]]* )
    radacctdir="$withval"
    ;;
  *)
    AC_MSG_ERROR([expected an absolute directory name for --with-radacctdir: $withval])
    ;;
  esac ]
)
AC_SUBST(radacctdir)
AC_MSG_RESULT($radacctdir)

dnl #
dnl #  extra argument: --with-raddbdir
dnl #
raddbdir='${sysconfdir}/raddb'
AC_MSG_CHECKING(raddbdir)
AC_ARG_WITH(raddbdir,
[  --with-raddbdir=DIR     directory for config files [SYSCONFDIR/raddb] ],
[ case "$withval" in
  no)
    AC_MSG_ERROR([Need raddbdir])
    ;;
  yes)
    ;;
  [[\\/$]]* | ?:[[\\/]]* )
    raddbdir="$withval"
    ;;
  *)
    AC_MSG_ERROR([expected an absolute directory name for --with-raddbdir: $withval])
    ;;
  esac ]
)
AC_SUBST(raddbdir)
AC_MSG_RESULT($raddbdir)

dnl #
dnl #  extra argument: --with-dictdir
dnl #
dictdir='${datarootdir}/freeradius'
AC_MSG_CHECKING(dictdir)
AC_ARG_WITH(dictdir,
[  --with-dictdir=DIR      directory for dictionary files [DATAROOTDIR/freeradius] ],
[ case "$withval" in
  no)
    AC_MSG_ERROR([Need dictdir])
    ;;
  yes)
    ;;
  [[\\/$]]* | ?:[[\\/]]* )
    dictdir="$withval"
    ;;
  *)
    AC_MSG_ERROR([expected an absolute directory name for --with-dictdir: $withval])
    ;;
  esac ]
)
AC_SUBST(dictdir)
AC_MSG_RESULT($dictdir)

modconfdir='${raddbdir}/mods-config'
AC_SUBST(modconfdir)

dnl #
dnl #  extra argument: --with-ascend-binary
dnl #
WITH_ASCEND_BINARY=yes
AC_ARG_WITH(ascend-binary,
[  --with-ascend-binary    include support for Ascend binary filter attributes (default=yes)],
[ case "$withval" in
  yes)
    ;;
  *)
    WITH_ASCEND_BINARY=no
  esac ]
)
if test "x$WITH_ASCEND_BINARY" = "xyes"; then
  AC_DEFINE(WITH_ASCEND_BINARY, [1], [include support for Ascend binary filter attributes])
fi

dnl #
dnl #  extra argument: --with-threads
dnl #
WITH_THREADS=yes
AC_ARG_WITH(threads,
[  --with-threads          use threads, if available.  (default=yes) ],
[ case "$withval" in
  yes)
    ;;
  *)
    WITH_THREADS=no
  esac ]
)

dnl #
dnl #  extra argument: --with-tcp
dnl #
WITH_TCP=yes
AC_ARG_WITH(tcp,
[  --with-tcp              compile in TCP support. (default=yes)],
[ case "$withval" in
  yes)
    ;;
  *)
    WITH_TCP=no
  esac ]
)
if test "x$WITH_TCP" = "xyes"; then
  AC_DEFINE(WITH_TCP, [1], [define if you want TCP support (For RADSec et al)])
fi

dnl #
dnl #  extra argument: --with-vmps
dnl #
WITH_VMPS=yes
AC_ARG_WITH(vmps,
[  --with-vmps             compile in VMPS support. (default=yes)],
[ case "$withval" in
  yes)
    ;;
  *)
    WITH_VMPS=no
  esac ]
)
if test "x$WITH_VMPS" = "xyes"; then
  AC_DEFINE(WITH_VMPS, [1], [define if you want VMPS support])
fi

dnl #
dnl #  extra argument: --with-dhcp
dnl #
WITH_DHCP=yes
AC_ARG_WITH(dhcp,
[  --with-dhcp             compile in DHCP support. (default=yes)],
[ case "$withval" in
  yes)
    ;;
  *)
    WITH_DHCP=no
  esac ]
)
if test "x$WITH_DHCP" = "xyes"; then
  AC_DEFINE(WITH_DHCP, [1], [define if you want DHCP support])
fi
AC_SUBST(WITH_DHCP)

dnl #
dnl #  Allow the user to specify a list of modules to be linked
dnl #  statically to the server.
dnl #
STATIC_MODULES=
AC_ARG_WITH(static_modules,
[  --with-static-modules=QUOTED-MODULE-LIST],[
  for i in $withval; do
    STATIC_MODULES="$STATIC_MODULES -dlpreopen ../modules/rlm_$i/rlm_$i.la"
  done
])

USE_SHARED_LIBS=yes
AC_ARG_WITH(shared-libs,
[AS_HELP_STRING([--with-shared-libs ],
[build dynamic libraries and link against them. (default=yes)])],
[ case "$withval" in
  no)
    USE_SHARED_LIBS=no
    ;;
  *)
  esac
])

MODULES=
AC_ARG_WITH(modules,
[  --with-modules=QUOTED-MODULE-LIST],[
 for i in $withval; do
   MODULES="$MODULES $i"
 done
])

dnl #
dnl #  extra argument: --with-experimental-modules
dnl #
EXPERIMENTAL=
AC_ARG_WITH(experimental-modules,
[AS_HELP_STRING([--with-experimental-modules],
[use experimental and unstable modules. (default=no, unless --enable-developer=yes)])],
[ case "$withval" in
  yes)
    EXPERIMENTAL=yes
    ;;
  no)
    EXPERIMENTAL=no
    ;;
  *)
  esac ]
)

dnl #
dnl #  extra argument: --with-udpfromto
dnl #
WITH_UDPFROMTO=yes
AC_ARG_WITH(udpfromto,
[  --with-udpfromto        compile in UDPFROMTO support. (default=yes)],
[ case "$withval" in
  yes)
    WITH_UDPFROMTO=yes
    ;;
  *)
    WITH_UDPFROMTO=no
  esac ]
)

if test "x$WITH_UDPFROMTO" = "xyes"; then
  AC_DEFINE(WITH_UDPFROMTO, [], [define if you want udpfromto])
fi

dnl #
dnl #  These next two arguments don't actually do anything.  They're
dnl #  place holders so that the top-level configure script can tell
dnl #  the user how to configure lower-level modules
dnl #

dnl #
dnl #  extra argument: --with-rlm-FOO-lib-dir
dnl #
AC_ARG_WITH(rlm-FOO-lib-dir,
[AS_HELP_STRING([--with-rlm-FOO-lib-dir=DIR],
[directory in which to look for library files used by module FOO])],
[ case "$withval" in
  *)
    ;;
  esac ]
)

dnl #
dnl #  extra argument: --with-rlm-FOO-include-dir
dnl #
AC_ARG_WITH(rlm-FOO-include-dir,
[AS_HELP_STRING([--with-rlm-FOO-include-dir=DIR],
[directory in which to look for include files used by module FOO])],
[ case "$withval" in
  *)
    ;;
  esac ]
)

dnl #
dnl #  extra argument: --with-openssl
dnl #
WITH_OPENSSL=yes
AC_ARG_WITH(openssl,
[  --with-openssl          use OpenSSL. (default=yes)],
[ case "$withval" in
  no)
    WITH_OPENSSL=no
    ;;
  *)
    WITH_OPENSSL=yes
    ;;
  esac ]
)
if test "x$WITH_THREADS" = "xno"; then
  if test "x$WITH_OPENSSL" = "xyes"; then
    AC_MSG_ERROR([[Threads are required when using OpenSSL, use --with-threads=yes]])
  fi
fi

dnl #
dnl #  extra argument: --with-openssl-lib-dir=dir
dnl #
openssl_lib_dir=
AC_ARG_WITH(openssl-lib-dir,
[AS_HELP_STRING([--with-openssl-lib-dir=DIR],
[directory to look for OpenSSL library files])],
[ case "$withval" in
  *) openssl_lib_dir="$withval"
    ;;
  esac ]
)

dnl #
dnl #  extra argument: --with-openssl-includes=dir
dnl #
openssl_include_dir=
AC_ARG_WITH(openssl-include-dir,
[AS_HELP_STRING([--with-openssl-include-dir=DIR],
[directory to look for OpenSSL include files])],
[ case "$withval" in
  *) openssl_include_dir="$withval"
    ;;
  esac ]
)

dnl #
dnl #  extra argument: --disable-openssl-version-check
dnl #
AC_ARG_ENABLE(openssl-version-check,
[AS_HELP_STRING([--disable-openssl-version-check],
                [disable vulnerable OpenSSL version check])]
)
if test "x$enable_openssl_version_check" != "xno"; then
  AC_DEFINE(ENABLE_OPENSSL_VERSION_CHECK, [1],
            [Define to 1 to have OpenSSL version check enabled])
  openssl_version_check_config="\
	#
	#  allow_vulnerable_openssl: Allow the server to start with
	#  versions of OpenSSL known to have critical vulnerabilities.
	#
	#  This check is based on the version number reported by libssl
	#  and may not reflect patches applied to libssl by
	#  distribution maintainers.
	#
	allow_vulnerable_openssl = no"
else
  openssl_version_check_config=
fi
AC_SUBST([openssl_version_check_config])

dnl #
dnl #  extra argument: --enable-reproducible-builds
dnl #
AC_ARG_ENABLE(reproducible-builds,
[AS_HELP_STRING([--enable-reproducible-builds],
                [ensure the build does not change each time])],
[ case "$enableval" in
  yes)
    AC_DEFINE(ENABLE_REPRODUCIBLE_BUILDS, [1],
              [Define to ensure each build is the same])
    reproducible_builds=yes
    ;;
  *)
    reproducible_builds=no
  esac ]
)

dnl #
dnl #  Enable the -fsanitize=fuzzer and link in the address sanitizer
dnl #  libraries.
dnl #
AC_ARG_ENABLE(fuzzer,
[AS_HELP_STRING([--enable-fuzzer],
                [build with support for a fuzzer])],
[ case "$enableval" in
  no)
    fuzzer=no
    ;;
  *)
    fuzzer=yes
  esac ]
)

dnl #
dnl #  Enable the -fsanitize=address and link in the address sanitizer
dnl #  libraries.
dnl #
AC_ARG_ENABLE(address-sanitizer,
[AS_HELP_STRING([--enable-address-sanitizer],
                [build with support for address sanitizer.])],
[ case "$enableval" in
  no)
    address_sanitizer=no
    ;;
  *)
    address_sanitizer=yes
  esac ]
)

dnl #
dnl #  Enable -fsanitize=leak and link in the leak sanitizer
dnl #  libraries.
dnl #
AC_ARG_ENABLE(leak-sanitizer,
[AS_HELP_STRING([--enable-leak-sanitizer],
                [build with support for leak sanitizer.])],
[ case "$enableval" in
  no)
    leak_sanitizer=no
    ;;
  *)
    leak_sanitizer=yes
  esac ]
)

dnl #
dnl #  Enable -fsanitize=thread and link in the thread sanitizer
dnl #  libraries.
dnl #
AC_ARG_ENABLE(thread-sanitizer,
[AS_HELP_STRING([--enable-thread-sanitizer],
                [build with support for thread sanitizer.])],
[ case "$enableval" in
  no)
    thread_sanitizer=no
    ;;
  *)
    thread_sanitizer=yes
  esac ]
)

dnl #
dnl #  Enable the -fsanitize=undefined and link in the address sanitizer
dnl #  libraries.
dnl #
AC_ARG_ENABLE(undefined-behaviour-sanitizer,
[AS_HELP_STRING([--enable-undefined-behaviour-sanitizer],
                [build with support for undefined behaviour sanitizer.])],
[ case "$enableval" in
  no)
    undefined_behaviour_sanitizer=no
    ;;
  *)
    undefined_behaviour_sanitizer=yes
  esac ]
)

dnl #############################################################
dnl #
dnl #  1. Checks for programs
dnl #
dnl #############################################################

CHECKRAD=checkrad
AC_PATH_PROG(PERL, perl, /usr/local/bin/perl)
if test "x$ac_cv_path_PERL" = "x"; then
  AC_MSG_WARN([perl not found - Simultaneous-Use and checkrad may not work])
fi
AC_PATH_PROG(SNMPGET, snmpget)
if test "x$ac_cv_path_SNMPGET" = "x"; then
  AC_MSG_WARN([snmpget not found - Simultaneous-Use and checkrad may not work])
fi

AC_PATH_PROG(SNMPWALK, snmpwalk)
if test "x$ac_cv_path_SNMPWALK" = "x"; then
  AC_MSG_WARN([snmpwalk not found - Simultaneous-Use and checkrad may not work])
fi

AC_PATH_PROG(RUSERS, rusers, /usr/bin/rusers)

dnl #
dnl #  FIXME This is truly gross.
dnl #
missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)

AC_PATH_PROG(DIRNAME,dirname)
AC_PATH_PROG(GREP,grep)

dnl #############################################################
dnl #
dnl #  2. Checks for libraries
dnl #
dnl #############################################################

dnl Check for talloc
dnl extra argument: --with-talloc-lib-dir=DIR
talloc_lib_dir=
AC_ARG_WITH(talloc-lib-dir,
  [AS_HELP_STRING([--with-talloc-lib-dir=DIR],
  [directory in which to look for talloc library files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need talloc-lib-dir])
      ;;
    yes)
      ;;
    *)
      talloc_lib_dir="$withval"
      ;;
  esac])

dnl extra argument: --with-talloc-include-dir=DIR
talloc_include_dir=
AC_ARG_WITH(talloc-include-dir,
  [AS_HELP_STRING([--with-talloc-include-dir=DIR],
  [directory in which to look for talloc include files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need talloc-include-dir])
      ;;
    yes)
      ;;
    *)
      talloc_include_dir="$withval"
      ;;
  esac])

smart_try_dir="$talloc_lib_dir"
FR_SMART_CHECK_LIB(talloc, _talloc)
if test "x$ac_cv_lib_talloc__talloc" != "xyes"; then
  AC_MSG_WARN([talloc library not found. Use --with-talloc-lib-dir=<path>.])
  AC_MSG_ERROR([FreeRADIUS requires libtalloc])
fi

TALLOC_LIBS="${smart_lib}"
TALLOC_LDFLAGS="${smart_ldflags}"
AC_SUBST(TALLOC_LIBS)
AC_SUBST(TALLOC_LDFLAGS)
LIBS="$old_LIBS"

dnl #
dnl #  If using pthreads, check for -lpthread (posix) or -lc_r (*BSD)
dnl #
old_CFLAGS=$CFLAGS
if test "x$WITH_THREADS" = "xyes"; then
  if test $ac_cv_prog_suncc = "yes"; then
    CFLAGS="$CFLAGS -mt"
  fi

  AC_CHECK_HEADERS(pthread.h, [],
    [
      WITH_THREADS="no"
      fail=[pthread.h]
    ])

  dnl #
  dnl #  pthread stuff is usually in -lpthread
  dnl #  or in -lc_r, on *BSD
  dnl #
  dnl #  On Some systems, we need extra pre-processor flags, to get them to
  dnl #  to do the threading properly.
  dnl #
  if test "x$WITH_THREADS" != "xno"; then
    AC_CHECK_LIB(pthread, pthread_create,
      [
        HAVE_LPTHREAD='yes'
        CFLAGS="$CFLAGS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
        LIBS="-lpthread $LIBS"

        dnl #
        dnl #  -pthread should add all required CPP definitions and linker
        dnl #  arguments. But not all compilers support it, or some compilers
        dnl #  only support it on certain platforms.
        dnl #
        AX_CC_PTHREAD_FLAG
        if test "x$ax_cv_cc_pthread_flag" != 'xyes'; then
          CFLAGS="$CFLAGS -pthread"
        fi
      ]
    )

    dnl #
    dnl #  Check for libc_r which used to be the threading library used
    dnl #  for FreeBSD. Internet says it may be deprecated, but if we
    dnl #  can't find lpthread it's probably worth checking.
    dnl #
    if test "x$HAVE_LPTHREAD" != "xyes"; then
      AC_CHECK_LIB(c_r, pthread_create,
        [
          CFLAGS="$CFLAGS -D_THREAD_SAFE"

          dnl #
          dnl #  -pthread should add all required CPP definitions and linker
          dnl #  arguments. But not all compilers support it, or some compilers
          dnl #  only support it on certain platforms.
          dnl #
          AX_CC_PTHREAD_FLAG
          if test "x$ax_cv_cc_pthread_flag" != 'xyes'; then
            LIBS="-lc_r $LIBS"
          else
            CFLAGS="$CFLAGS -pthread"
          fi
        ],
        [ fail=[-lc_r or -lpthread] ]
      )
    fi
  fi

  if test "x$WITH_THREADS" != "xyes"; then
    AC_MSG_WARN([silently not building with thread support.])
    AC_MSG_WARN([FAILURE: thread support requires: $fail.])
  else
    AC_DEFINE(WITH_THREADS, [1], [define if you want thread support])
  fi
fi

dnl #
dnl #  If we have NO pthread libraries, remove any knowledge of threads.
dnl #
if test "x$WITH_THREADS" != "xyes"; then
  CFLAGS=$old_CFLAGS
  ac_cv_header_pthread_h="no"
  WITH_THREADS=no
else
  dnl #
  dnl #  We need sem_init() and friends, as they're the friendliest
  dnl #  semaphore functions for threading.
  dnl #
  dnl #  HP/UX requires linking with librt, too, to get the sem_* symbols.
  dnl #  Some systems have them in -lsem
  dnl #  Solaris has them in -lposix4
  dnl #  NetBSD has them in -lsemaphore
  dnl #

  AC_SEARCH_LIBS(sem_init, pthread sem posix4 rt semaphore,
    [],
    [AC_MSG_ERROR([[-lsem not found.  You may want to download it from ftp://ftp.to.gd-es.com/pub/BSDI/libsem.tar.bz2 or ftp://ftp.freeradius.org/pub/radius/contrib/libsem.tar.gz]])]
  )
fi

dnl #
dnl #  Check if we have -ldl
dnl #
AC_CHECK_LIB(dl, dlopen)

dnl #
dnl #  Check if we need -lsocket
dnl #
AC_CHECK_LIB(socket, getsockname)

dnl #
dnl #  Check for -lresolv
dnl #  This library may be needed later.
dnl #
AC_CHECK_LIB(resolv, inet_aton)

dnl #
dnl #  Check if we need -lnsl. Usually if we want to
dnl #  link against -lsocket we need to include -lnsl as well.
dnl #
AC_CHECK_LIB(nsl, inet_ntoa)
AC_CHECK_LIB(ws2_32, htonl)

dnl #
dnl #  Check the pcap library for the RADIUS sniffer.
dnl #
dnl extra argument: --with-pcap-lib-dir=DIR
pcap_lib_dir=
AC_ARG_WITH(pcap-lib-dir,
  [AS_HELP_STRING([--with-pcap-lib-dir=DIR],
  [directory in which to look for pcap library files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need pcap-lib-dir])
      ;;
    yes)
      ;;
    *)
      pcap_lib_dir="$withval"
      ;;
  esac])

dnl extra argument: --with-pcap-include-dir=DIR
pcap_include_dir=
AC_ARG_WITH(pcap-include-dir,
  [AS_HELP_STRING([--with-pcap-include-dir=DIR],
  [directory in which to look for pcap include files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need pcap-include-dir])
      ;;
    yes)
      ;;
    *)
      pcap_include_dir="$withval"
      ;;
  esac])

smart_try_dir="$pcap_lib_dir"
FR_SMART_CHECK_LIB(pcap, pcap_open_live)
if test "x$ac_cv_lib_pcap_pcap_open_live" != "xyes"; then
  AC_MSG_WARN([pcap library not found, silently disabling the RADIUS sniffer, and ARP listener.  Use --with-pcap-lib-dir=<path>.])
else
  AC_CHECK_FUNCS(\
    pcap_fopen_offline \
    pcap_dump_fopen \
    pcap_create \
    pcap_activate
  )

  PCAP_LIBS="${smart_lib}"
  PCAP_LDFLAGS="${smart_ldflags}"
fi
dnl Set by FR_SMART_CHECK_LIB
LIBS="${old_LIBS}"

dnl Check for collectdclient
dnl extra argument: --with-collectdclient-lib-dir=DIR
collectdclient_lib_dir=
AC_ARG_WITH(collectdclient-lib-dir,
  [AS_HELP_STRING([--with-collectdclient-lib-dir=DIR],
  [directory in which to look for collectdclient library files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need collectdclient-lib-dir])
      ;;
    yes)
      ;;
    *)
      collectdclient_lib_dir="$withval"
      ;;
  esac])

dnl extra argument: --with-collectdclient-include-dir=DIR
collectdclient_include_dir=
AC_ARG_WITH(collectdclient-include-dir,
  [AS_HELP_STRING([--with-collectdclient-include-dir=DIR],
  [directory in which to look for collectdclient include files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need collectdclient-include-dir])
      ;;
    yes)
      ;;
    *)
      collectdclient_include_dir="$withval"
      ;;
  esac])

smart_try_dir="$collectdclient_lib_dir"
FR_SMART_CHECK_LIB(collectdclient, lcc_connect)
if test "x$ac_cv_lib_collectdclient_lcc_connect" != "xyes"; then
  AC_MSG_WARN([collectdclient library not found. Use --with-collectdclient-lib-dir=<path>.])
else
  COLLECTDC_LIBS="${smart_lib}"
  COLLECTDC_LDFLAGS="${smart_ldflags}"
fi
dnl Set by FR_SMART_CHECKLIB
LIBS="${old_LIBS}"

dnl Check for cap
dnl extra argument: --with-cap-lib-dir=DIR
cap_lib_dir=
AC_ARG_WITH(cap-lib-dir,
  [AS_HELP_STRING([--with-cap-lib-dir=DIR],
  [directory in which to look for cap library files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need cap-lib-dir])
      ;;
    yes)
      ;;
    *)
      cap_lib_dir="$withval"
      ;;
  esac])

dnl extra argument: --with-cap-include-dir=DIR
cap_include_dir=
AC_ARG_WITH(cap-include-dir,
  [AS_HELP_STRING([--with-cap-include-dir=DIR],
  [directory in which to look for cap include files])],
  [case "$withval" in
    no)
      AC_MSG_ERROR([Need cap-include-dir])
      ;;
    yes)
      ;;
    *)
      cap_include_dir="$withval"
      ;;
  esac])

smart_try_dir="$cap_lib_dir"
FR_SMART_CHECK_LIB(cap, cap_get_proc)
if test "x$ac_cv_lib_cap_cap_get_proc" != "xyes"; then
  AC_MSG_WARN([cap library not found, debugger checks will not be enabled. Use --with-cap-lib-dir=<path>.])
else
  AC_DEFINE(HAVE_LIBCAP, 1,
    [Define to 1 if you have the `cap' library (-lcap).]
  )
  HAVE_LIBCAP=1
fi

dnl #
dnl #  Check for libreadline
dnl #
VL_LIB_READLINE

dnl #
dnl #  Checks for systemd
dnl #
dnl #  extra argument: --with-systemd
dnl #
AC_ARG_WITH([systemd],
            AS_HELP_STRING([--with-systemd], [add systemd support, if available (default=no)]),
            [ case "$withval" in
              no)
                WITH_SYSTEMD=no
                ;;
              *)
                WITH_SYSTEMD=yes
              esac ],
            [WITH_SYSTEMD=no])

dnl #
dnl #  extra argument: --systemd-lib-dir=dir
dnl #
systemd_lib_dir=
AC_ARG_WITH(systemd-lib-dir,
  [AS_HELP_STRING([--with-systemd-lib-dir=DIR],
  [directory to look for systemd library files])],
  [ case "$withval" in
    *) systemd_lib_dir="$withval"
      ;;
    esac ]
)

dnl #
dnl #  extra argument: --with-systemd-includes=dir
dnl #
systemd_include_dir=
AC_ARG_WITH(systemd-include-dir,
  [AS_HELP_STRING([--with-systemd-include-dir=DIR],
  [directory to look for systemd include files])],
  [ case "$withval" in
    *) systemd_include_dir="$withval"
      ;;
    esac ]
)

if test "x$WITH_SYSTEMD" = xyes; then
  smart_try_dir="$systemd_lib_dir"
  FR_SMART_CHECK_LIB(systemd, sd_notify)
  if test "x$ac_cv_lib_systemd_sd_notify" != "xyes"; then
    AC_MSG_WARN([systemd library not found. Use --with-systemd-lib-dir=<path>.])
  else
    AC_DEFINE([HAVE_SYSTEMD], [1],
      [Define to 1 if you have the `systemd' library (-lsystemd).]
    )
    HAVE_SYSTEMD=1
    SYSTEMD_LIBS="${smart_lib}"
    SYSTEMD_LDFLAGS="${smart_ldflags}"
  fi
  dnl Set by FR_SMART_CHECKLIB
  LIBS="${old_LIBS}"
fi

if test "x$HAVE_SYSTEMD" = x; then
  AC_MSG_NOTICE([skipping test for systemd watchdog])
else
  smart_try_dir="$systemd_lib_dir"
  FR_SMART_CHECK_LIB(systemd, sd_watchdog_enabled)
  if test "x$ac_cv_lib_systemd_sd_watchdog_enabled" != "xyes"; then
    AC_MSG_WARN([systemd watchdog is only available from systemd 209.])
  else
    AC_DEFINE([HAVE_SYSTEMD_WATCHDOG], [1],
      [Define to 1 if you have watchdog support in the `systemd' library (-lsystemd).]
    )
  fi
  dnl Set by FR_SMART_CHECKLIB
  LIBS="${old_LIBS}"
fi

dnl #
dnl #  Check for the systemd headers
dnl #
if test "x$WITH_SYSTEMD" != xyes || test "x$SYSTEMD_LIBS" = x; then
  AC_MSG_NOTICE([skipping test for systemd/sd-daemon.h.])
else
  smart_try_dir="$systemd_include_dir"
  FR_SMART_CHECK_INCLUDE([systemd/sd-daemon.h])
  if test "x$ac_cv_header_systemd_sdmdaemon_h" = "xyes"; then
    AC_DEFINE(HAVE_SYSTEMD_SD_DAEMON_H, 1, [Define to 1 if you have the <systemd/sd-daemon.h> header file.])
    AC_SUBST(SYSTEMD_LIBS)
    AC_SUBST(SYSTEMD_LDFLAGS)
  else
    AC_MSG_WARN([systemd headers not found.  Use --with-systemd-include-dir=<path>.])
  fi
fi

dnl #############################################################
dnl #
dnl #  3. Checks for header files
dnl #
dnl #############################################################

dnl #
dnl # Check for talloc header files
dnl #
smart_try_dir="$talloc_include_dir"
FR_SMART_CHECK_INCLUDE([talloc.h])
if test "x$ac_cv_header_talloc_h" != "xyes"; then
  AC_MSG_WARN([talloc headers not found. Use --with-talloc-include-dir=<path>.])
  AC_MSG_ERROR([FreeRADIUS requires libtalloc])
fi

dnl #
dnl #  Interix requires us to set -D_ALL_SOURCE, otherwise
dnl #  getopt will be #included, but won't link.  <sigh>
dnl #
dnl #  On the other hand, it's 20222.  Interix has likely been dead for a decade. :(
dnl #
case "$host" in
  *-interix*)
    CFLAGS="$CFLAGS -D_ALL_SOURCE"
    ;;
  *-darwin*)
    AC_DEFINE([__APPLE_USE_RFC_3542], 1, [Force OSX >= 10.7 Lion to use RFC2292 IPv6 socket options])
    ;;
esac

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
AC_HEADER_SYS_WAIT

AC_CHECK_HEADERS( \
  arpa/inet.h \
  crypt.h \
  dlfcn.h \
  errno.h \
  fcntl.h \
  features.h \
  fnmatch.h \
  getopt.h \
  glob.h \
  grp.h \
  inttypes.h \
  limits.h \
  linux/if_packet.h \
  malloc.h \
  netdb.h \
  netinet/in.h \
  prot.h \
  pwd.h \
  resource.h \
  semaphore.h \
  sia.h \
  siad.h \
  signal.h \
  stdatomic.h \
  stdalign.h \
  stdbool.h \
  stddef.h \
  stdint.h \
  stdio.h \
  sys/event.h \
  sys/fcntl.h \
  sys/prctl.h \
  sys/procctl.h \
  sys/ptrace.h \
  sys/resource.h \
  sys/security.h \
  sys/select.h \
  sys/socket.h \
  sys/time.h \
  sys/types.h \
  sys/un.h \
  sys/wait.h \
  syslog.h \
  unistd.h \
  utime.h \
  utmp.h \
  utmpx.h \
  winsock.h
)

dnl #
dnl #  FreeBSD requires sys/socket.h before net/if.h
dnl #
AC_CHECK_HEADERS(net/if.h, [], [],
  [
    #ifdef HAVE_SYS_SOCKET_H
    #  include <sys/socket.h>
    #endif
  ]
)

dnl #
dnl #  other checks which require headers
dnl #
if test "x$ac_cv_header_sys_security_h" = "xyes" && test "x$ac_cv_header_prot_h" = "xyes"
then
  AC_DEFINE(OSFC2, [], [define if you have OSFC2 authentication])
fi

if test "x$ac_cv_header_sia_h" = "xyes" && test "x$ac_cv_header_siad_h" = "xyes"
then
  AC_DEFINE(OSFSIA, [], [define if you have OSFSIA authentication])
fi

dnl #
dnl #  Were we told to use OpenSSL, if we were and we find an error, call AC_MSG_FAILURE and exit
dnl #
if test "x$WITH_OPENSSL" = xyes; then
  OLD_LIBS="$LIBS"

  dnl #
  dnl #  Apparently OpenSSL will attempt to build with kerberos if we don't pass this?!
  dnl #
  CFLAGS="$CFLAGS -DOPENSSL_NO_KRB5"

  dnl #
  dnl #  Check we can link to libcrypto and libssl
  dnl #
  smart_try_dir="$openssl_lib_dir"
  FR_SMART_CHECK_LIB(crypto, DH_new)
  if test "x$ac_cv_lib_crypto_DH_new" = "xyes"; then
    AC_DEFINE(HAVE_LIBCRYPTO, 1, [Define to 1 if you have the `crypto' library (-lcrypto).])
    OPENSSL_LIBS="$smart_lib"
    OPENSSL_LDFLAGS="$smart_ldflags"

    FR_SMART_CHECK_LIB(ssl, SSL_new)
    if test "x$ac_cv_lib_ssl_SSL_new" != "xyes"; then
      AC_MSG_FAILURE([failed linking to libssl. Use --with-openssl-lib-dir=<path>, or --with-openssl=no (builds without OpenSSL)])
    else
      AC_DEFINE(HAVE_LIBSSL, 1, [Define to 1 if you have the `ssl' library (-lssl).])
      OPENSSL_LIBS="$OPENSSL_LIBS $smart_lib"

      if test "$OPENSSL_LDFLAGS" != "$smart_ldflags"; then
        AC_MSG_FAILURE(["inconsistent LDFLAGS between -lssl '$smart_ldflags' and -lcrypto '$OPENSSL_LDFLAGS'"])
      fi
    fi
  else
    AC_MSG_FAILURE([failed linking to libcrypto. Use --with-openssl-lib-dir=<path>, or --with-openssl=no (builds without OpenSSL)])
  fi

  smart_try_dir="$openssl_include_dir"
  FR_SMART_CHECK_INCLUDE(openssl/ssl.h)
  if test "x$ac_cv_header_openssl_ssl_h" = "xyes"; then
    AC_DEFINE(HAVE_OPENSSL_SSL_H, 1, [Define to 1 if you have the <openssl/ssl.h> header file.])

    AC_CHECK_HEADERS( \
      openssl/asn1.h \
      openssl/conf.h \
      openssl/crypto.h \
      openssl/err.h \
      openssl/evp.h \
      openssl/hmac.h \
      openssl/md5.h \
      openssl/md4.h \
      openssl/rand.h \
      openssl/sha.h \
      openssl/ssl.h \
      openssl/ocsp.h \
      openssl/engine.h,
      [ OPENSSL_CPPFLAGS="$smart_include" ],
      [
        AC_MSG_FAILURE([failed locating OpenSSL headers. Use --with-openssl-include-dir=<path>, or --with-openssl=no (builds without OpenSSL)])
      ]
    )

    AC_MSG_CHECKING([for OpenSSL version >= 1.0.2])
    AC_EGREP_CPP(yes,
      [#include <openssl/crypto.h>
       #if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
       yes
       #endif
      ],
      [
        AC_MSG_RESULT(yes)
      ],
      [
        AC_MSG_RESULT(no)
        AC_MSG_FAILURE([OpenSSL version too old])
      ]
    )

    dnl #
    dnl #  CPPFLAGS are passed to the compiler first, so we use
    dnl #  them to ensure things like --sysroot don't override the
    dnl #  library location we discovered previously.
    dnl #
    old_CPPFLAGS="$CPPFLAGS"
    CPPFLAGS="$OPENSSL_CPPFLAGS $CPPFLAGS"

    dnl #
    dnl #  Now check that the header versions match the library
    dnl #
    AC_MSG_CHECKING([OpenSSL library and header version consistency])
    AC_RUN_IFELSE(
      [AC_LANG_PROGRAM(
        [[
          #include <stdio.h>
          #include <openssl/opensslv.h>
          #include <openssl/crypto.h>
        ]],
        [[
          printf("library: %lx header: %lx... ", (unsigned long) SSLeay(), (unsigned long) OPENSSL_VERSION_NUMBER);
          if (SSLeay() == OPENSSL_VERSION_NUMBER) {
            return 0;
          } else {
            return 1;
          }
        ]]
      )],
      [
        AC_MSG_RESULT(yes)
      ],
      [
        AC_MSG_RESULT(no)
        AC_MSG_FAILURE([OpenSSL library version does not match header version])
      ],
      [
        AC_MSG_RESULT([cross-compiling (assuming yes)])
      ]
    )
    dnl #
    dnl #  Check if the new HMAC_CTX interface is defined
    dnl #
    AC_CHECK_FUNCS( \
      SSL_get_client_random \
      SSL_get_server_random \
      SSL_SESSION_get_master_key \
      HMAC_CTX_new \
      HMAC_CTX_free \
      ASN1_STRING_get0_data \
      CONF_modules_load_file \
      CRYPTO_set_id_callback \
      CRYPTO_set_locking_callback
    )
    CPPFLAGS="$old_CPPFLAGS"
  fi

  LIBS="$OLD_LIBS"
  AC_SUBST(OPENSSL_LIBS)
  AC_SUBST(OPENSSL_LDFLAGS)
  AC_SUBST(OPENSSL_CPPFLAGS)
  export OPENSSL_LIBS OPENSSL_LDFLAGS OPENSSL_CPPFLAGS
fi

dnl #
dnl #  Check the pcap includes for the RADIUS sniffer.
dnl #
if test "x$PCAP_LIBS" = x; then
  AC_MSG_NOTICE([skipping test for pcap.h.])
else
  dnl #
  dnl # Check for pcap header files
  dnl #
  smart_try_dir="$pcap_include_dir"
  FR_SMART_CHECK_INCLUDE([pcap.h])
  if test "x$ac_cv_header_pcap_h" = "xyes" && test "x$ac_cv_lib_pcap_pcap_open_live" = "xyes"; then
    AC_DEFINE(HAVE_LIBPCAP, 1, [Define to 1 if you have the `pcap' library (-lpcap) and header file <pcap.h>.])
    AC_SUBST(PCAP_LIBS)
    AC_SUBST(PCAP_LDFLAGS)
  else
    AC_MSG_WARN([pcap headers not found, silently disabling the RADIUS sniffer, and ARP listener. Use --with-pcap-include-dir=<path>.])
  fi
fi

dnl Check for collectd-client
if test "x$COLLECTDC_LIBS" = x; then
  AC_MSG_NOTICE([skipping test for collectd/client.h.])
else
  dnl #
  dnl # Check for collectd-client header files
  dnl #
  smart_try_dir="$collectdclient_include_dir"
  FR_SMART_CHECK_INCLUDE([collectd/client.h])
  if test "x$ac_cv_header_collectd_client_h" = "xyes"; then
    AC_DEFINE(HAVE_COLLECTDC_H, 1, [Define to 1 if you have the `collectdclient' library (-lcollectdclient).])
    AC_SUBST(COLLECTDC_LIBS)
    AC_SUBST(COLLECTDC_LDFLAGS)
  else
    AC_MSG_WARN([collectdclient headers not found. Use --with-collectdclient-include-dir=<path>.])
  fi
fi

dnl #
dnl #  Check the CAP includes for debugger checks
dnl #
if test "x$HAVE_LIBCAP" = x; then
  AC_MSG_NOTICE([skipping test for cap.h.])
else
  dnl #
  dnl # Check for CAP header files
  dnl #
  smart_try_dir="$cap_include_dir"
  FR_SMART_CHECK_INCLUDE([sys/capability.h])
  if test "x$ac_cv_header_sys_capability_h" = "xyes"; then
    AC_DEFINE(HAVE_CAPABILITY_H, 1, [Define to 1 if you have the <sys/capability.h> header file.])
  else
    AC_MSG_WARN([cap headers not found, will not perform debugger checks. Use --with-cap-include-dir=<path>.])
  fi
fi

dnl #############################################################
dnl #
dnl #  4. Checks for typedefs
dnl #
dnl #############################################################

dnl #
dnl #  Ensure that these are defined
dnl #
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T

dnl #
dnl #  Check for socklen_t
dnl #
FR_CHECK_TYPE_INCLUDE(
  [
    #ifdef HAVE_SYS_TYPES_H
    #  include <sys/types.h>
    #endif

    #ifdef HAVE_SYS_SOCKET_H
    #  include <sys/socket.h>
    #endif
  ],
  socklen_t, int, [socklen_t is generally 'int' on systems which don't use it]
)

dnl #
dnl #  Check for uint8_t
dnl #
FR_CHECK_TYPE_INCLUDE(
  [
    #ifdef HAVE_INTTYPES_H
    #  include <inttypes.h>
    #endif

    #ifdef HAVE_STDINT_H
    #  include <stdint.h>
    #endif
  ],
  uint8_t, unsigned char, [uint8_t should be the canonical 'octet' for network traffic]
)

dnl #
dnl #  Check for uint16_t
dnl #
FR_CHECK_TYPE_INCLUDE(
  [
    #ifdef HAVE_INTTYPES_H
    #  include <inttypes.h>
    #endif

    #ifdef HAVE_STDINT_H
    #  include <stdint.h>
    #endif
  ],
  uint16_t, unsigned short, [uint16_t should be the canonical '2 octets' for network traffic]
)

dnl #
dnl #  Check for uint32_t
dnl #
FR_CHECK_TYPE_INCLUDE(
  [
    #ifdef HAVE_INTTYPES_H
    #  include <inttypes.h>
    #endif

    #ifdef HAVE_STDINT_H
    #  include <stdint.h>
    #endif
  ],
  uint32_t, unsigned int, [uint32_t should be the canonical 'network integer']
)

dnl #
dnl #  Check for uint64_t
dnl #
FR_CHECK_TYPE_INCLUDE(
  [
    #ifdef HAVE_INTTYPES_H
    #  include <inttypes.h>
    #endif

    #ifdef HAVE_STDINT_H
    #  include <stdint.h>
    #endif
  ],
  uint64_t, unsigned long long, [uint64_t is required for larger counters]
)

dnl #
dnl #  Check for __uint128_t (compiler builtin)
dnl #
AC_CHECK_TYPE(__uint128_t, AC_DEFINE(HAVE___UINT128_T, 1, [compiler specific 128 bit unsigned integer]), [], [])

dnl #
dnl #  Check for uint128_t (fictitious future data type)
dnl #
AC_CHECK_TYPE(uint128_t, AC_DEFINE(HAVE_UINT128_T, 1, [128 bit unsigned integer]), [],
  [
    #ifdef HAVE_INTTYPES_H
    #  include <inttypes.h>
    #endif

    #ifdef HAVE_STDINT_H
    #  include <stdint.h>
    #endif
  ]
)

AC_CHECK_TYPE(struct in6_addr, AC_DEFINE(HAVE_STRUCT_IN6_ADDR, 1, [IPv6 address structure]), [],
  [
    #ifdef HAVE_NETINET_IN_H
    #  include <netinet/in.h>
    #endif
  ]
)

AC_CHECK_TYPE(struct sockaddr_storage, AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1, [Generic socket addresses]), [],
  [
    #ifdef HAVE_NETINET_IN_H
    #  include <netinet/in.h>
    #endif

    #ifdef HAVE_SYS_SOCKET_H
    #  include <sys/socket.h>
    #endif
])

AC_CHECK_TYPE(struct sockaddr_in6, AC_DEFINE(HAVE_STRUCT_SOCKADDR_IN6, 1, [IPv6 socket addresses]), [],
  [
    #ifdef HAVE_NETINET_IN_H
    #  include <netinet/in.h>
    #endif
])

AC_CHECK_TYPE(struct addrinfo, AC_DEFINE(HAVE_STRUCT_ADDRINFO, 1, [Generic DNS lookups]), [],
  [
    #ifdef HAVE_SYS_TYPES_H
    #  include <sys/types.h>
    #endif

    #ifdef HAVE_SYS_SOCKET_H
    #  include <sys/socket.h>
    #endif

    #ifdef HAVE_NETDB_H
    #  include <netdb.h>
    #endif
  ]
)

dnl #
dnl #  Check for sig_t
dnl #
dnl #  FR_CHECK_TYPE_INCLUDE doesn't work for callbacks as it doesn't produce typedefs
dnl #
AC_MSG_CHECKING([if sig_t is defined])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
    [[
      #ifdef HAVE_SIGNAL_H
      #  include <signal.h>
      #endif
    ]],
    [[
      sig_t func;
      return 0;
    ]]
  )],
  [
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_SIG_T, 1, [Define if the type sig_t is defined by signal.h])
  ],
  [
      AC_MSG_RESULT(no)
  ]
)

dnl #############################################################
dnl #
dnl #  5. Checks for structures and functions
dnl #
dnl #############################################################
AC_CHECK_FUNCS( \
  bindat \
  clock_gettime \
  closefrom \
  ctime_r \
  dladdr \
  fcntl \
  fopencookie \
  funopen \
  getaddrinfo \
  getnameinfo \
  getopt_long \
  getpeereid \
  getresuid \
  gettimeofday \
  getusershell \
  gmtime_r \
  if_indextoname \
  inet_aton \
  inet_ntop \
  inet_pton \
  initgroups \
  kqueue \
  localtime_r \
  mallopt \
  mkdirat \
  openat \
  pthread_sigmask \
  setlinebuf \
  setresuid \
  setsid \
  setuid \
  setvbuf \
  sigaction \
  sigprocmask \
  snprintf \
  strcasecmp \
  strlcat \
  strlcpy \
  strncasecmp \
  strsep \
  strsignal \
  unlinkat \
  vdprintf \
  vsnprintf
)

AC_TYPE_SIGNAL

dnl #
dnl #  Check if we have utmpx.h
dnl #  if so, check if struct utmpx has entry ut_xtime
dnl #  if not, set it to define ut_xtime = ut_tv.tv_sec
dnl #
if test "x$ac_cv_header_utmpx_h" = "xyes"; then
 FR_CHECK_STRUCT_HAS_MEMBER([#include <utmpx.h>], [struct utmpx], ut_xtime)
 if test "x$ac_cv_type_struct_utmpx_has_ut_xtime" = "x"; then
   AC_DEFINE(ut_xtime, ut_tv.tv_sec, [define to something if you don't have ut_xtime in struct utmpx])
 fi
fi

dnl #
dnl #  struct ip_pktinfo
dnl #
FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in_pktinfo], ipi_addr)
if test "x$ac_cv_type_struct_in_pktinfo_has_ipi_addr" = "xyes"; then
  AC_DEFINE(HAVE_IP_PKTINFO, [], [define if you have IP_PKTINFO (Linux)])
fi

dnl #
dnl #  struct in6_pktinfo
dnl #
FR_CHECK_STRUCT_HAS_MEMBER([#include <netinet/in.h>], [struct in6_pktinfo], ipi6_addr)
if test "x$ac_cv_type_struct_in6_pktinfo_has_ipi6_addr" = "xyes"; then
  AC_DEFINE(HAVE_IN6_PKTINFO, [], [define if you have IN6_PKTINFO (Linux)])
fi

dnl #
dnl #  Check for htonll and htonlll
dnl #
AC_MSG_CHECKING([if htonll is defined])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
    [[
      #include <sys/types.h>
      #include <netinet/in.h>
    ]],
    [[
      return htonll(0);
    ]]
  )],
  [
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_HTONLL, 1, [Define if the function (or macro) htonll exists.])
  ],
  [
      AC_MSG_RESULT(no)
  ]
)

AC_MSG_CHECKING([if htonlll is defined])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
    [[
      #include <sys/types.h>
      #include <netinet/in.h>
    ]],
    [[
      return htonlll(0);
    ]]
  )],
  [
      AC_MSG_RESULT(yes)
      AC_DEFINE(HAVE_HTONLLL, 1, [Define if the function (or macro) htonlll exists.])
  ],
  [
      AC_MSG_RESULT(no)
  ]
)

dnl #############################################################
dnl #
dnl #  6. Checks for compiler characteristics
dnl #
dnl #############################################################

dnl #
dnl #  Ensure that these are defined
dnl #
AC_C_CONST

dnl #
dnl #  See if this is OS/2
dnl #
AC_MSG_CHECKING([type of OS])
OS=`uname -s`
AC_MSG_RESULT($OS)
if test "$OS" = "OS/2"; then
  LIBPREFIX=
else
  LIBPREFIX=lib
fi
AC_SUBST(LIBPREFIX)

if test "x$developer" = "xyes"; then
  AC_MSG_NOTICE([Setting additional developer CFLAGS])

  dnl #
  dnl #  Tell the compiler to parse doxygen documentation and verify it against function and variable declarations
  dnl #
  AX_CC_WDOCUMENTATION_FLAG
  if test "x$ax_cv_cc_wdocumentation_flag" = "xyes"; then
    devcflags="-Wdocumentation"
    AC_DEFINE([HAVE_WDOCUMENTATION],1,[Define if the compiler supports -Wdocumentation])
  fi

  dnl #
  dnl #  If we have -Weverything, it really means *everything* unlike -Wall
  dnl #  It's so verbose we need to turn off warnings which aren't useful.
  dnl #
  AX_CC_WEVERYTHING_FLAG
  if test "x$ax_cv_cc_weverything_flag" = "xyes"; then
    devcflags="$devcflags -W -Weverything -Wformat=2 -Wno-missing-field-initializers -Wno-date-time -Wno-padded -Wno-gnu-zero-variadic-macro-arguments -Wno-shorten-64-to-32 -Wno-sign-conversion -Wno-conversion -Wno-switch-enum -Wno-gnu-statement-expression -Wno-extended-offsetof -Wno-cast-align -Wno-documentation-unknown-command -Wno-covered-switch-default -Wno-packed $verify_ptr $fips"
  else
    if test "x$GCC" = "xyes"; then
      devcflags="$devcflags -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -W -Wredundant-decls -Wundef -Wformat-y2k -Wno-format-extra-args -Wno-format-zero-length -Wno-cast-align -Wformat-nonliteral -Wformat-security -Wformat=2 $verify_ptr $fips"
      INSTALLSTRIP=""
    fi
  fi

  dnl #
  dnl #  Can't use mutliple -fsanitize flags, so we need to combine
  dnl #  the values into one.
  dnl #
  fsanitizeflags=

  dnl #
  dnl #  If running with clang, add in FUZZER
  dnl #
  if test "x$fuzzer" = "xyes" && test "x$ax_cv_cc_clang" = "xyes"; then
    dnl #
    dnl #  -fsanitize=fuzzer  - Build with fuzzer support
    dnl #
    fsanitizeflags="$fsanitizeflags,fuzzer"
  fi

  dnl #
  dnl #  Add in ASAN
  dnl #
  if test "x$address_sanitizer" = "xyes"; then
    dnl #
    dnl #  -fsanitize=address		- Build with address sanitizer support
    dnl #  -fno-omit-frame-pointer	- Always keep the frame pointer in a register
    dnl #  -fno-optimize-sibling-calls	- Don't optimize away tail recursion.
    dnl #
    devcflags="$devcflags -fno-omit-frame-pointer -fno-optimize-sibling-calls"

    AX_CC_SANITZE_ADDRESS_USE_AFTER_SCOPE_FLAG
    if test "x$ax_cv_cc_sanitize_address_use_after_scope" = "xyes"; then
      devcflags="$devcflags -fsanitize-address-use-after-scope"
    fi

    AC_CHECK_HEADERS(sanitizer/lsan_interface.h)
    fsanitizeflags="$fsanitizeflags,address"
  fi

  dnl #
  dnl #  Add in LSAN
  dnl #
  if test "x$leak_sanitizer" = "xyes"; then
    dnl #
    dnl #  -fsanitize=leak	- Build with lsan support
    dnl #
    fsanitizeflags="$fsanitizeflags,leak"
  fi

  dnl #
  dnl #  Add in TSAN
  dnl #
  if test "x$thread_sanitizer" = "xyes"; then
    dnl #
    dnl #  -fsanitize=thread	- Build with tsan support
    dnl #
    fsanitizeflags="$fsanitizeflags,thread"
  fi

  dnl #
  dnl #  Add in UBSAN
  dnl #
  if test "x$undefined_behaviour_sanitizer" = "xyes"; then
    dnl #
    dnl #  -fsanitize=undefined		- Build with ubsan support
    dnl #  -fno-omit-frame-pointer	- Always keep the frame pointer in a register
    dnl #
    devcflags="$devcflags -fno-sanitize-recover=undefined -fno-omit-frame-pointer"
    devldflags="$devldflags -fno-sanitize-recover=undefined"
    fsanitizeflags="$fsanitizeflags,undefined"
  fi

  if test "x$fsanitizeflags" != "x"; then
    fsanitizeflags="$(echo $fsanitizeflags | sed 's/^,*//')"
    devcflags="-fsanitize=$fsanitizeflags $devcflags"
    devldflags="-fsanitize=$fsanitizeflags $devldflags"
  fi

  dnl #
  dnl # Clean the flags up
  dnl #
  devcflags="$(echo $devcflags | sed -e 's/\\t//g;s/  //g')"
  devldflags="$(echo $devldflags | sed -e 's/\\t//g;s/  //g')"

  AC_MSG_NOTICE([Developer CFLAGS are "$devcflags"])
  AC_MSG_NOTICE([Developer LDFLAGS are "$devldflags"])

  dnl #
  dnl #  Enable experimental modules (we want to know if code changes breaks one of them)
  dnl #
  if test "x$EXPERIMENTAL" != "xno"; then
    AC_MSG_NOTICE([is developer build, enabling experimental modules implicitly, disable with --without-experimental-modules])
    EXPERIMENTAL=yes
  fi
else
  devcflags=""
  devldflags=""
  CFLAGS="$CFLAGS -DNDEBUG"
  INSTALLSTRIP=""
fi

dnl #
dnl #  May of been set outside of this configure script
dnl #
AC_MSG_CHECKING([if building with -DNDEBUG])
if echo "$CFLAGS" | grep '\-DNDEBUG' > /dev/null; then
  AC_MSG_RESULT([yes])
  AC_DEFINE([WITH_NDEBUG], [1], [define if the server was built with -DNDEBUG])
else
  AC_MSG_RESULT([no])
fi

export EXPERIMENTAL

dnl #
dnl #  append the current git hash onto the version string
dnl #
if test -d $srcdir/.git -a "x$GIT" = "xyes"; then
  RADIUSD_VERSION_COMMIT=`git log --pretty=format:'%h' -n 1 | cut -c1-9`
  AC_DEFINE_UNQUOTED([RADIUSD_VERSION_COMMIT],[${RADIUSD_VERSION_COMMIT}],[Commit HEAD at time of configuring])
fi

dnl #
dnl #  check for some compiler features
dnl #
FR_TLS
FR_HAVE_BUILTIN_CHOOSE_EXPR
FR_HAVE_BUILTIN_TYPES_COMPATIBLE_P
FR_HAVE_BUILTIN_BSWAP64
FR_HAVE_BOUNDED_ATTRIBUTE

dnl #############################################################
dnl #
dnl #  7. Checks for library functions
dnl #
dnl #############################################################

dnl #
dnl # Check for talloc_set_memlimit
dnl # This was only included in version 2.0.8
dnl #
AC_CHECK_LIB(talloc, talloc_set_memlimit,
  [
    AC_DEFINE(HAVE_TALLOC_SET_MEMLIMIT, 1, [Define to 1 if you have the function talloc_set_memlimit.])
  ]
)

dnl #
dnl # Check for libcrypt
dnl # We use crypt(3) which may be in libc, or in libcrypt (eg FreeBSD)
dnl #
AC_CHECK_LIB(crypt, crypt,
  CRYPTLIB="-lcrypt"
)

if test "$CRYPTLIB" != ""; then
  AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function])
else
  AC_CHECK_FUNC(crypt, AC_DEFINE(HAVE_CRYPT, [], [Do we have the crypt function]))
fi

dnl crypt_r is the GNU thread-safe version
AC_CHECK_LIB(crypt, crypt_r, AC_DEFINE(HAVE_CRYPT_R, [], [Do we have the crypt_r function]))

dnl Check for libcipher
AC_CHECK_LIB(cipher, setkey,
   CRYPTLIB="${CRYPTLIB} -lcipher"
)
AC_SUBST(CRYPTLIB)

dnl #
dnl #  Check for libexecinfo support, on some systems this is built into libc
dnl #  on others it's a separate library.
dnl #
dnl extra argument: --with-execinfo-lib-dir
execinfo_lib_dir=
AC_ARG_WITH(execinfo-lib-dir,
[AS_HELP_STRING([--with-execinfo-lib-dir=DIR],
[directory in which to look for execinfo library files])],
[ case "$withval" in
    no)
        AC_MSG_ERROR([Need execinfo-lib-dir])
	;;
    yes)
	;;
    *)
	execinfo_lib_dir="$withval"
	;;
  esac ]
)

dnl extra argument: --with-execinfo-include-dir
execinfo_include_dir=
AC_ARG_WITH(execinfo-include-dir,
[AS_HELP_STRING([--with-execinfo-include-dir=DIR],
[directory in which to look for execinfo include files])],
[ case "$withval" in
    no)
        AC_MSG_ERROR([Need execinfo-include-dir])
	;;
    yes)
	;;
    *)
	execinfo_include_dir="$withval"
	;;
  esac ]
)

dnl #
dnl #  Look for execinfo.h and symbols
dnl #
smart_try_dir=$execinfo_include_dir
FR_SMART_CHECK_INCLUDE(execinfo.h)
if test "x$ac_cv_header_execinfo_h" = "xyes"; then
  smart_try_dir=$execinfo_lib_dir
  FR_SMART_CHECK_LIB(execinfo, backtrace_symbols)
  if test "x$ac_cv_lib_execinfo_backtrace_symbols" != "xyes"; then
    dnl # Might be provided as part of libc
    AC_MSG_CHECKING([if execinfo provided as part of libc])
    AC_TRY_LINK(
      [
        #include <execinfo.h>
      ],
      [
        void *sym[1];
        backtrace_symbols(&sym, sizeof(sym)) ],
      [
        AC_MSG_RESULT(yes)
        ac_cv_lib_execinfo_backtrace_symbols="yes"
      ],
      [
        AC_MSG_RESULT(no)
      ]
    )
  fi

  if test "x$ac_cv_lib_execinfo_backtrace_symbols" = "xyes"; then
    AC_DEFINE(HAVE_EXECINFO, [1], [define this if we have <execinfo.h> and symbols])
  fi
fi

dnl #
dnl #  Check for regular expression support.
dnl #
dnl extra argument: --with-pcre
PCRE=yes
AC_ARG_WITH(pcre,
[AS_HELP_STRING([--with-pcre],
[use libpcre (if available). (default=yes)])],
[ case "$withval" in
    no)
    PCRE=no
	;;
    yes)
    PCRE=yes
	;;
  esac ]
)

dnl extra argument: --with-pcre-lib-dir
pcre_lib_dir=
AC_ARG_WITH(pcre-lib-dir,
[AS_HELP_STRING([--with-pcre-lib-dir=DIR],
[directory in which to look for pcre library files])],
[ case "$withval" in
    no)
	AC_MSG_ERROR(Need pcre-lib-dir)
	;;
    yes)
	;;
    *)
	pcre_lib_dir="$withval"
	;;
  esac ]
)

dnl extra argument: --with-pcre-include-dir
pcre_include_dir=
AC_ARG_WITH(pcre-include-dir,
[AS_HELP_STRING([--with-pcre-include-dir=DIR],
[directory in which to look for pcre include files])],
[ case "$withval" in
    no)
	AC_MSG_ERROR(Need pcre-include-dir)
	;;
    yes)
	;;
    *)
	pcre_include_dir="$withval"
	;;
  esac ]
)

dnl extra argument: --with-regex
REGEX=
AC_ARG_WITH(regex,
[AS_HELP_STRING([--with-regex],
[Whether to build with regular expressions (default=yes)])],
[ case "$withval" in
    no)
	REGEX=no
	;;
    *)
	;;
  esac ]
)

dnl #
dnl #  First look for PCRE
dnl #
if test "x$REGEX" != "xno" && test "x$PCRE" != "xno"; then
  smart_try_dir=$pcre_include_dir
  FR_SMART_CHECK_INCLUDE(pcre.h)
  if test "x$ac_cv_header_pcre_h" = "xyes"; then
    smart_try_dir=$pcre_lib_dir
    FR_SMART_CHECK_LIB(pcre, pcre_compile)
    if test "x$ac_cv_lib_pcre_pcre_compile" = "xyes"; then
      REGEX=yes
      AC_DEFINE(HAVE_PCRE, [1], [define this if we have libpcre])
      AC_DEFINE(HAVE_BINSAFE_REGEX, 1, [Define if we have a binary safe regular expression library])
    fi
  fi
fi

dnl #
dnl #  If no PCRE, fallback to POSIX regular expressions
dnl #
if test "x$REGEX" = "x"; then
  smart_try_dir=
  FR_SMART_CHECK_INCLUDE(regex.h)
  if test "x$ac_cv_header_regex_h" = "xyes"; then
    REGEX=yes
    AC_MSG_CHECKING([for extended regular expressions])
    AC_EGREP_CPP(yes,
      [
        #include <regex.h>
        #ifdef REG_EXTENDED
        yes
        #endif
      ],
      [
        AC_MSG_RESULT(yes)
        AC_DEFINE(HAVE_REG_EXTENDED, [1], [define this if we have REG_EXTENDED (from <regex.h>)])
      ],
      [
        AC_MSG_RESULT(no)
      ]
    )

    dnl #
    dnl #  Some platforms require the regex library to be linked explicitly
    dnl #
    AC_CHECK_LIB(regex, regcomp,
      [
        LIBS="-lregex $LIBS"
      ]
    )

    dnl #
    dnl #  Check for some BSD extensions which allow normal regexes to be
    dnl #  binary safe.
    dnl #
    AC_CHECK_FUNCS(\
      regncomp \
      regnexec
    )
    if test x"$ac_cv_func_regncomp" = x"yes" && test  x"$ac_cv_func_regnexec" = x"yes"; then
      AC_DEFINE(HAVE_BINSAFE_REGEX, 1, [Define if we have a binary safe regular expression library])
    fi
  fi
fi

#
#  Some platforms require an explicit -latomic
#
AC_SEARCH_LIBS([__atomic_load_4], [atomic])

if test "x$REGEX" = "xyes"; then
  AC_DEFINE(HAVE_REGEX, 1, [Define if we have any regular expression library])
fi

dnl #
dnl #  Check the style of gethostbyaddr, in order of preference
dnl #  GNU (_r eight args)
dnl #
AC_DEFINE(GNUSTYLE, [1], [GNU-Style get*byaddr_r])

dnl #
dnl #  SYSV (_r six args)
dnl #
AC_DEFINE(SYSVSTYLE, [2], [SYSV-Style get*byaddr_r])

dnl #
dnl #  BSD (three args, may not be thread safe)
dnl #
AC_DEFINE(BSDSTYLE, [3], [BSD-Style get*byaddr_r])

dnl #
dnl #  Tru64 has BSD version, but it is thread safe
dnl #  http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1739____.HTM
dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
dnl #
gethostbyaddrrstyle=""
AC_MSG_CHECKING([gethostbyaddr_r() syntax])
case "$host" in
  *-freebsd*)
    dnl #
    dnl #  With FreeBSD, check if there's a prototype for gethostbyaddr_r.
    dnl #  Some versions (FreeBSD 5.1?) have a symbol but no prototype - so we
    dnl #  override this test to BSDSTYLE. FreeBSD 6.2 and up have proper GNU
    dnl #  style support.
    dnl #
    AC_CHECK_DECLS([gethostbyaddr_r], [],
      [
        AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE,
          [style of gethostbyaddr_r functions ])
        gethostbyaddrrstyle=BSD
        AC_MSG_WARN([FreeBSD overridden to BSD-style])
      ],
      [
        #ifdef HAVE_NETDB_H
        #include <netdb.h>
        #endif
      ])
    ;;
esac

if test "x$gethostbyaddrrstyle" = "x"; then
  AC_TRY_LINK(
    [
      #include <stdio.h>
      #include <netdb.h>
    ],
    [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL, NULL) ],
    [
      AC_DEFINE(GETHOSTBYADDRRSTYLE, GNUSTYLE, [style of gethostbyaddr_r functions ])
      gethostbyaddrrstyle=GNU
    ]
  )
fi

if test "x$gethostbyaddrrstyle" = "x"; then
  AC_TRY_LINK(
    [
      #include <stdio.h>
      #include <netdb.h>
    ],
    [ gethostbyaddr_r(NULL, 0, 0, NULL, NULL, 0, NULL) ] ,
    [
      AC_DEFINE(GETHOSTBYADDRRSTYLE, SYSVSTYLE, [style of gethostbyaddr_r functions ])
      gethostbyaddrrstyle=SYSV
    ]
  )
fi


if test "x$gethostbyaddrrstyle" = "x"; then
  AC_TRY_LINK(
    [
      #include <stdio.h>
      #include <netdb.h>
    ],
    [ gethostbyaddr(NULL, 0, 0)  ],
    [
      AC_DEFINE(GETHOSTBYADDRRSTYLE, BSDSTYLE, [style of gethostbyaddr_r functions ])
      gethostbyaddrrstyle=BSD
    ]
  )
fi

if test "x$gethostbyaddrrstyle" = "x"; then
  AC_MSG_RESULT([none!  It must not exist, here.])
else
  AC_MSG_RESULT([${gethostbyaddrrstyle}-style])
fi

if test "x$gethostbyaddrrstyle" = "xBSD"; then
  AC_MSG_WARN([ ****** BSD-style gethostbyaddr might NOT be thread-safe! ****** ])
fi

dnl #
dnl #  Check the style of gethostbyname, in order of preference
dnl #  GNU (_r seven args)
dnl #  SYSV (_r five args)
dnl #  BSD (two args, may not be thread safe)
dnl #  Tru64 has BSD version, but it _is_ thread safe
dnl #    http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/1946____.HTM
dnl #  We need #stdio.h to define NULL on FreeBSD (at least)
dnl #
gethostbynamerstyle=""
AC_MSG_CHECKING([gethostbyname_r() syntax])
AC_TRY_LINK(
  [
    #include <stdio.h>
    #include <netdb.h>
  ],
  [ gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL) ],
  [
    AC_DEFINE(GETHOSTBYNAMERSTYLE, GNUSTYLE, [style of gethostbyname_r functions ])
    gethostbynamerstyle=GNU
  ]
)

if test "x$gethostbynamerstyle" = "x"; then
  AC_TRY_LINK(
    [
      #include <stdio.h>
      #include <netdb.h>
    ],
    [ gethostbyname_r(NULL, NULL, NULL, 0, NULL) ] ,
    [
      AC_DEFINE(GETHOSTBYNAMERSTYLE, SYSVSTYLE, [style of gethostbyname_r functions ])
      gethostbynamerstyle=SYSV
    ]
  )
fi

if test "x$gethostbynamerstyle" = "x"; then
  AC_TRY_LINK(
    [
      #include <stdio.h>
      #include <netdb.h>
    ],
    [ gethostbyname(NULL) ],
    [
      AC_DEFINE(GETHOSTBYNAMERSTYLE, BSDSTYLE, [style of gethostbyname_r functions ])
      gethostbynamerstyle=BSD
    ]
  )
fi

if test "x$gethostbynamerstyle" = "x"; then
  AC_MSG_RESULT([none!  It must not exist, here.])
else
  AC_MSG_RESULT([${gethostbynamerstyle}-style])
fi

if test "x$gethostbynamerstyle" = "xBSD"; then
  AC_MSG_WARN([ ****** BSD-style gethostbyname might NOT be thread-safe! ****** ])
fi

dnl #
dnl #  Check for thread-safe getpwnam_r and getgrnam_r
dnl #
if test "x$ac_cv_header_pwd_h" = "xyes"; then
  AC_MSG_CHECKING([getpwnam_r])
  AC_TRY_LINK(
    [
      #include <stdlib.h>
      #include <sys/types.h>
      #include <pwd.h>
    ],
    [ getpwnam_r(NULL, NULL, NULL, 0, NULL) ],
    [
      AC_MSG_RESULT([yes])
      AC_DEFINE(HAVE_GETPWNAM_R, 1,
                [Define to 1 if you have the getpwnam_r.]
                )
    ],
    [
        AC_MSG_RESULT(no)
    ]
  )
fi

if test "x$ac_cv_header_grp_h" = "xyes"; then
  AC_MSG_CHECKING([getgrnam_r])
  AC_TRY_LINK(
    [
      #include <stdlib.h>
      #include <sys/types.h>
      #include <grp.h>
    ],
    [ getgrnam_r(NULL, NULL, NULL, 0, NULL) ],
    [
      AC_MSG_RESULT([yes])
      AC_DEFINE(HAVE_GETGRNAM_R, 1,
                [Define to 1 if you have the getgrnam_r.]
                )
    ],
    [
        AC_MSG_RESULT(no)
    ]
  )
fi


dnl #
dnl #  Check for non-posix solaris ctime_r (extra buflen int arg)
dnl #
AC_DEFINE(POSIXSTYLE, [1], [Posix-Style ctime_r])
AC_DEFINE(SOLARISSTYLE, [2], [Solaris-Style ctime_r])
ctimerstyle=""
AC_MSG_CHECKING([ctime_r() syntax])
AC_TRY_LINK(
  [
    #include <time.h>
  ],
  [ ctime_r(NULL, NULL, 0) ],
  [
    AC_DEFINE(CTIMERSTYLE, SOLARISSTYLE, [style of ctime_r function])
    ctimerstyle="SOLARIS"
  ]
)

if test "x$ctimerstyle" = "x"; then
  AC_TRY_LINK(
    [
      #include <time.h>
    ],
    [ ctime_r(NULL, NULL) ],
    [
      AC_DEFINE(CTIMERSTYLE, POSIXSTYLE, [style of ctime_r function])
      ctimerstyle="POSIX"
    ]
  )
fi

if test "x$ctimerstyle" = "x"; then
    AC_MSG_RESULT([none!  It must not exist, here.])
else
    AC_MSG_RESULT([${ctimerstyle}-style])
fi

AC_SUBST(HOSTINFO, $host)

dnl #############################################################
dnl #
dnl #  8. Checks for system services
dnl #
dnl #############################################################

dnl #
dnl #  Figure out where libtool is located,
dnl #
top_builddir=`pwd`
export top_builddir
AC_MSG_RESULT([top_builddir=$top_builddir])
dnl #  AC_SUBST(top_builddir)

dnl #
dnl #  import libtool stuff
dnl #
dnl #############################################################
dnl #
dnl #  Configure in any module directories.
dnl #
dnl #############################################################

dnl ############################################################
dnl #  Remove any conflicting definitions if autoconf.h
dnl #  is being included by a module.
dnl #############################################################
AH_BOTTOM([#include <freeradius-devel/automask.h>])

dnl ############################################################
dnl #  make modules by list
dnl #############################################################
if test "x$EXPERIMENTAL" = "xyes"; then
  for foo in `ls -1 "${srcdir}"/src/modules | grep rlm_`; do
    MODULES="$MODULES $foo"
  done
else
   dnl #
   dnl #  make ONLY the stable modules
   dnl #
   for foo in `cat "${srcdir}"/src/modules/stable`; do
      MODULES="$MODULES $foo"
   done
fi

dnl ############################################################
dnl #  Add autoconf subdirs, based on the module list we
dnl #  previously created.
dnl #############################################################
mysubdirs=""
for bar in $MODULES; do
  if test -f "${srcdir}"/src/modules/$bar/configure; then
    mysubdirs="$mysubdirs src/modules/$bar"
  fi
done

dnl #
dnl #  Don't change the variable name here.  Autoconf goes bonkers
dnl #  if you do.
dnl #
AC_CONFIG_SUBDIRS($mysubdirs)
AC_SUBST(MODULES)

dnl #
dnl #  If reproducible builds are not enabled, disable
dnl #  -Wdate-time so the compiler doesn't croak.
dnl #
if test "x$ax_cv_cc_no_date_time_flag" = "xyes" && test "x$reproducible_builds" != "xyes"; then
  CFLAGS="-Wno-date-time $CFLAGS"
fi

dnl #############################################################
dnl #
dnl #  Add $devcflags, $devldflags and -Werror last, so they don't
dnl #  interfere with autoconf's test programs.
dnl #
dnl #############################################################
CFLAGS="$CFLAGS $devcflags"
LDFLAGS="$LDFLAGS $devldflags"

if test "x$werror" = "xyes"; then
  CFLAGS="-Werror $CFLAGS"
fi

dnl #############################################################
dnl #
dnl #  And finally, output the results.
dnl #
dnl #############################################################
AC_CONFIG_COMMANDS([stamp-h], [echo timestamp > src/include/stamp-h])
AC_CONFIG_COMMANDS([build-radpaths-h], [(cd ./src/include && /bin/sh ./build-radpaths-h)])
AC_CONFIG_COMMANDS([main-chmod], [(cd ./src/main && chmod +x checkrad radlast radtest)])
AC_CONFIG_COMMANDS([scripts-chmod], [(cd ./scripts && chmod +x rc.radiusd cron/radiusd.cron.daily cron/radiusd.cron.monthly cryptpasswd)])

dnl #
dnl #  Substitute whatever libraries we found to be necessary
dnl #
AC_SUBST(LIBS)
AC_SUBST(INSTALLSTRIP)

AC_SUBST(USE_SHARED_LIBS)
USE_STATIC_LIBS="yes"
AC_SUBST(USE_STATIC_LIBS)
AC_SUBST(STATIC_MODULES)

AC_OUTPUT(\
  ./Make.inc \
  ./src/include/build-radpaths-h \
  ./src/main/radsniff.mk \
  ./src/main/checkrad \
  ./src/main/radlast \
  ./src/main/radtest \
  ./scripts/rc.radiusd \
  ./scripts/cron/radiusd.cron.daily \
  ./scripts/cron/radiusd.cron.monthly \
  ./scripts/cryptpasswd \
  ./raddb/radrelay.conf \
  ./raddb/radiusd.conf
)