Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0.  If a copy of the MPL was not distributed with this
# file, you can obtain one at https://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

AC_INIT(BIND, [9.16], [https://gitlab.isc.org/isc-projects/bind9/-/issues/new?issuable_template=Bug], [], [https://www.isc.org/downloads/])
AC_PREREQ([2.60])

#
# Enable maintainer mode by default, but allow to disable it in the CI
#
AM_MAINTAINER_MODE([enable])

AC_CONFIG_HEADER(config.h)
AC_CONFIG_MACRO_DIR([m4])

AC_CANONICAL_HOST

#
# Enable system extensions to C and POSIX
#
AC_USE_SYSTEM_EXTENSIONS

#
# Enable large file support
#
AC_SYS_LARGEFILE
AC_FUNC_FSEEKO

LFS_CFLAGS=`getconf LFS_CFLAGS 2>/dev/null`
LFS_LDFLAGS=`getconf LFS_LDFLAGS 2>/dev/null`
LFS_LIBS=`getconf LFS_LIBS 2>/dev/null`

AC_SUBST([LFS_CFLAGS])
AC_SUBST([LFS_LDFLAGS])
AC_SUBST([LFS_LIBS])

# Enable RFC 3542 APIs on macOS
AC_DEFINE([__APPLE_USE_RFC_3542], [1], [Select RFC3542 IPv6 API on macOS])

AC_PROG_MAKE_SET

AC_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_LN_S
AX_POSIX_SHELL
AC_PROG_MKDIR_P

AC_SUBST(STD_CINCLUDES)
AC_SUBST(STD_CDEFINES)
AC_SUBST(STD_CWARNINGS)
AC_SUBST(CCOPT)
AC_SUBST(CCNOOPT)
AC_SUBST(BACKTRACECFLAGS)

#
# Use pkg-config
#

PKG_PROG_PKG_CONFIG
AS_IF([test -z "$PKG_CONFIG"],
      [AC_MSG_ERROR([The pkg-config script could not be found or is too old.])])

# [pairwise: --enable-buffer-useinline, --disable-buffer-useinline]
AC_ARG_ENABLE(buffer_useinline,
	      AS_HELP_STRING([--enable-buffer-useinline],
		             [define ISC_BUFFER_USEINLINE when compiling
				[default=yes]]),
	      if test yes = "${enable}"
	      then
		      AC_DEFINE([ISC_BUFFER_USEINLINE], [1],
			        [Define if you want to use inline buffers])
	      fi,
	      AC_DEFINE([ISC_BUFFER_USEINLINE], [1]))

# [pairwise: --enable-warn-shadow, --disable-warn-shadow]
AC_ARG_ENABLE([warn_shadow],
	      [AS_HELP_STRING([--enable-warn-shadow],
			      [turn on -Wshadow when compiling])])

# [pairwise: --enable-warn-error, --disable-warn-error]
AC_ARG_ENABLE([warn_error],
	      [AS_HELP_STRING([--enable-warn-error],
			      [turn on -Werror when compiling])])

# [pairwise: --enable-developer, --disable-developer]
AC_ARG_ENABLE([developer],
	      [AS_HELP_STRING([--enable-developer],
			      [enable developer build settings])])

XTARGETS=
AS_IF([test "$enable_developer" = "yes"],
      [STD_CDEFINES="$STD_CDEFINES -DISC_MEM_DEFAULTFILL=1 -DISC_LIST_CHECKINIT=1"
       test "${enable_fixed_rrset+set}" = set || enable_fixed_rrset=yes
       test "${enable_querytrace+set}" = set || enable_querytrace=yes
       test "${with_cmocka+set}" = set || with_cmocka=yes
       test "${with_dlz_filesystem+set}" = set || with_dlz_filesystem=yes
       test "${enable_symtable+set}" = set || enable_symtable=all
       test "${enable_warn_error+set}" = set || enable_warn_error=yes
       test "${enable_warn_shadow+set}" = set || enable_warn_shadow=yes
       test "${with_zlib+set}" = set || with_zlib=yes
       XTARGETS='${XTARGETS}'
       ])
AC_SUBST([XTARGETS])

# Fuzzing is not included in pairwise testing as fuzzing tools are
# not present in the relevant Docker image.
#
# [pairwise: skip]
AC_ARG_ENABLE([fuzzing],
	      [AS_HELP_STRING([--enable-fuzzing=<afl|libfuzzer>],
			      [Enable fuzzing using American Fuzzy Lop or libFuzzer (default=no)])],
	      [],
	      [enable_fuzzing=no])

AC_MSG_CHECKING([whether to enable fuzzing mode])
AS_CASE([$enable_fuzzing],
	[no],[AC_MSG_RESULT([no])],
	[afl],[
	  AC_MSG_RESULT([using AFL])
	  AC_DEFINE([ENABLE_AFL], [1],
		    [Define to enable American Fuzzy Lop test harness])
	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1"
	  LIBS="$LIBS -lpthread"],
	[libfuzzer],[
	  AC_MSG_RESULT([using libFuzzer])
	  CFLAGS="$CFLAGS -DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION=1 -fsanitize=fuzzer,address,undefined"
	  LDFLAGS="$LDFLAGS -fsanitize=fuzzer,address,undefined"],
	[*],[AC_MSG_ERROR([You need to explicitly select the fuzzer])])

AS_IF([test "$enable_fuzzing" = "afl"],
      [AC_MSG_CHECKING("for AFL enabled compiler")
       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
					  [#ifndef __AFL_COMPILER
					   #error AFL compiler required
					   #endif
					  ])],
			 [AC_MSG_RESULT([yes])],
			 [AC_MSG_ERROR([set CC=afl-<gcc|clang> when --enable-fuzzing=afl is used])])
      ])

#
# Make very sure that these are the first files processed by
# config.status, since we use the processed output as the input for
# AC_SUBST_FILE() substitutions in other files.
#
AC_CONFIG_FILES([make/rules make/includes])

AC_PATH_PROG(AR, ar)
ARFLAGS="cruv"
AC_SUBST(AR)
AC_SUBST(ARFLAGS)

# The POSIX ln(1) program.  Non-POSIX systems may substitute
# "copy" or something.
LN=ln
AC_SUBST(LN)

case "$AR" in
	"")
		AC_MSG_ERROR([
ar program not found.  Please fix your PATH to include the directory in
which ar resides, or set AR in the environment with the full path to ar.
])

		;;
esac

#
# Look for w3m
#
AC_PATH_PROGS(W3M, w3m, w3m)
AC_SUBST(W3M)

#
# Look for pandoc
#
AC_PATH_PROG(PANDOC, pandoc, pandoc)
AC_SUBST(PANDOC)

#
# Perl is optional; it is used only by some of the system test scripts.
# Note: the backtrace feature (see below) uses perl to build the symbol table,
# but it still compiles without perl, in which case an empty table will be used.
#
AC_PATH_PROGS(PERL, perl5 perl)
AC_SUBST(PERL)

#
# Python is also optional but required by default so that dnssec-keymgr gets
# installed unless explicitly prevented by the user using --without-python.
#
testminvers='import sys
if (sys.version_info < (2,7)) or (sys.version_info < (3,2) and sys.version_info >= (3,0)):
   exit(1)'

testargparse='try: import argparse
except: exit(1)'

testply='try: import ply
except: exit(1)'

testsetuptools='try: from setuptools import setup
except: exit(1)'

testdistutils='try: from distutils.core import setup
except: exit(1)'

default_with_python="python python3 python3.11 python3.10 python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python2 python2.7"

AC_ARG_VAR([PYTHON], [path to python executable])

# [pairwise: --with-python, --without-python]
AC_ARG_WITH([python],
	    AS_HELP_STRING([--with-python=PATH],
			   [specify path to Python interpreter]),
	    [], [with_python=$default_with_python])

# [pairwise: skip]
AC_ARG_WITH([python-install-dir],
	    AS_HELP_STRING([--with-python-install-dir=PATH],
			   [installation directory for Python modules]),
	    [], with_python_install_dir="")

AS_IF([test "$with_python" = "yes"],
      [with_python=$default_with_python])

AS_IF([test "$with_python" = "no"],
      [AC_MSG_CHECKING([for Python support])
       unset PYTHON
       AC_MSG_RESULT([disabled])],
      [for p in $with_python
       do
	 AS_CASE([$p],
		 [/*],[PYTHON="$p"])

	 AC_PATH_PROG([PYTHON], [$p])
	 # Do not cache the result of the check from the previous line.  If the
	 # first found Python interpreter has missing module dependencies and
	 # the result of the above check is cached, subsequent module checks
	 # will erroneously keep on using the cached path to the first found
	 # Python interpreter instead of different ones.
	 unset ac_cv_path_PYTHON

	 AS_IF([test -z "$PYTHON"], [continue])

	 AC_MSG_CHECKING([if $PYTHON is python2 version >= 2.7 or python3 version >= 3.2])
	 AS_IF(["$PYTHON" -c "$testminvers" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		unset PYTHON
		continue])

	 AC_MSG_CHECKING([Python module 'argparse'])
	 AS_IF(["$PYTHON" -c "$testargparse" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		unset PYTHON
		continue])

	 AC_MSG_CHECKING([Python module 'ply'])
	 AS_IF(["$PYTHON" -c "$testply" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		unset PYTHON
		continue])

	 AC_MSG_CHECKING([Python module 'setuptools'])
	 AS_IF(["$PYTHON" -c "$testsetuptools" 2>/dev/null],
	       [AC_MSG_RESULT([yes])],
	       [AC_MSG_RESULT([no])
		AC_MSG_CHECKING([Python module 'distutils'])
		AS_IF(["$PYTHON" -c "$testdistutils" 2>/dev/null],
		      [AC_MSG_RESULT([yes])],
		      [AC_MSG_RESULT([no])
		       unset PYTHON
		       continue])])

	 # Stop looking any further once we find a Python interpreter
	 # satisfying all requirements.
	 break
       done

       AS_IF([test "X$PYTHON" = "X"],
	     [AC_MSG_CHECKING([for Python support])
	      AC_MSG_RESULT([no])
	      AC_MSG_ERROR([m4_normalize(
				[Python >= 2.7 or >= 3.2 and the PLY package
                                 are required for dnssec-keymgr and other
                                 Python-based tools. PLY may be
                                 available from your OS package manager
                                 as python-ply or python3-ply; it can also
                                 be installed via pip. To build without
                                 Python/PLY, use --without-python.]
			    )])])])

PYTHON_TOOLS=''
CHECKDS=''
COVERAGE=''
KEYMGR=''
AS_IF([test "X$PYTHON" != "X"],
      [PYTHON_TOOLS=python
       CHECKDS=checkdstool
       COVERAGE=coverage
       KEYMGR=keymgr
       PYTHON_INSTALL_DIR="$with_python_install_dir"
       AS_IF([test -n "$with_python_install_dir"],
	     [PYTHON_INSTALL_LIB="--install-lib=$with_python_install_dir"])])
AC_SUBST(CHECKDS)
AC_SUBST(COVERAGE)
AC_SUBST(KEYMGR)
AC_SUBST(PYTHON_TOOLS)
AC_SUBST(PYTHON_INSTALL_DIR)
AC_SUBST(PYTHON_INSTALL_LIB)

#
# expanded_sysconfdir is needed for replacement in the python utilities
#
expanded_sysconfdir=`eval echo $sysconfdir`
AC_SUBST(expanded_sysconfdir)

#
# Make sure INSTALL uses an absolute path, else it will be wrong in all
# Makefiles, since they use make/rules.in and INSTALL will be adjusted by
# configure based on the location of the file where it is substituted.
# Since in BIND9 INSTALL is only substituted into make/rules.in, an immediate
# subdirectory of install-sh, This relative path will be wrong for all
# directories more than one level down from install-sh.
#
case "$INSTALL" in
	/*)
		;;
	*)
		#
		# Not all systems have dirname.
		#
		changequote({, })
		ac_dir="`echo $INSTALL | sed 's%/[^/]*$%%'`"
		changequote([, ])

		ac_prog="`echo $INSTALL | sed 's%.*/%%'`"
		test "X$ac_dir" = "X$ac_prog" && ac_dir=.
		test -d "$ac_dir" && ac_dir="`(cd \"$ac_dir\" && pwd)`"
		INSTALL="$ac_dir/$ac_prog"
		;;
esac

AC_PATH_PROGS([PYTEST], [pytest-3 py.test-3 pytest py.test pytest-pypy], [])
AS_IF([test -z "$PYTEST"],
      [AC_MSG_WARN([pytest not found, some system tests will be skipped])])
AC_SUBST([PYTEST])


AC_PROG_CC
AC_PROG_CC_C99

#
# Using Solaris linker with gcc on Solaris breaks Thread Local Storage
#
AS_CASE([$host],
	[*-solaris*],[
	    AS_IF([test "$GCC" = "yes"],
		  [LDFLAGS="$LDFLAGS -zrelax=transtls"
		   AC_MSG_WARN([When using GNU C Compiler on Solaris, -zrelax=transtls linker flag is used to fix bug in Thread Local Storage])
		  ])
	],
	[*-darwin*],[LDFLAGS="$LDFLAGS -Wl,-flat_namespace"])

#
# CCNOOPT defaults to -O0 on gcc and disables optimization when is last
#
if test "X$CCNOOPT" = "X" -a "X$GCC" = "Xyes"; then
	CCNOOPT="-O0"
fi

AC_HEADER_STDC

AC_CHECK_HEADERS(fcntl.h regex.h sys/time.h unistd.h sys/mman.h sys/sockio.h sys/select.h sys/param.h sys/sysctl.h net/if6.h sys/socket.h net/route.h linux/netlink.h linux/rtnetlink.h,,,
[$ac_includes_default
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
])

#
# Check for thread local storage
#
AC_CHECK_HEADERS([threads.h],
		 [
		     AC_MSG_CHECKING([for C11 Thread-Local Storage using thread_local])
		     AC_COMPILE_IFELSE(
			 [AC_LANG_PROGRAM(
			      [
				  #include <threads.h>
			      ],[
				  static thread_local int tls = 0;
				  return (tls);
			      ])
			 ],[
			     AC_MSG_RESULT([yes])
			     AC_DEFINE([HAVE_THREAD_LOCAL],[1],[Define if thread_local keyword is available])
			     AC_DEFINE([HAVE_TLS],[1],[Define if Thread-Local Storage is available])
			 ],[
			     AC_MSG_ERROR([Thread Local Storage support required, update your toolchain to build BIND 9])
			 ])
		 ],[
		     AC_MSG_CHECKING([for Thread-Local Storage using __thread])
		     AC_COMPILE_IFELSE(
			 [AC_LANG_PROGRAM(
			      [
			      ],[
				  static __thread int tls = 0;
				  return (tls);
			      ])
			 ],[
			     AC_MSG_RESULT([yes])
			     AC_DEFINE([HAVE___THREAD],[1],[Define if __thread keyword is available])
			     AC_DEFINE([HAVE_TLS],[1],[Define if Thread-Local Storage is available])
			 ],[
			     AC_MSG_ERROR([Thread Local Storage support required, update your toolchain to build BIND 9])
			 ])
		 ])

AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE
AC_C_FLEXIBLE_ARRAY_MEMBER

#
# Check for yield support on ARM processors
#
AS_CASE([$host],
	[arm*],
	[AC_MSG_CHECKING([for yield instruction support])
	 AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM([[]],
			     [[__asm__ __volatile__ ("yield")]])],
	     [AC_MSG_RESULT([yes])
	      AC_DEFINE([HAVE_ARM_YIELD], [1],
			[define if the ARM yield instruction is available])],
	     [AC_MSG_RESULT([no])])])

#
# Check for pause support on SPARC processors
#
AS_CASE([$host],
	[sparc*],
	[AC_MSG_CHECKING([for pause instruction support])
	 AC_COMPILE_IFELSE(
	     [AC_LANG_PROGRAM([[]],
			     [[__asm__ __volatile__ ("pause")]])],
	     [AC_MSG_RESULT([yes])
	      AC_DEFINE([HAVE_SPARC_PAUSE], [1],
			[define if the SPARC pause instruction is available])],
	     [AC_MSG_RESULT([no])])])

AC_CHECK_FUNCS([sysctlbyname])

#
# Check for the existence of mmap to enable the fast format zones
#
AC_CHECK_FUNCS(mmap)

#
# Older versions of HP/UX don't define seteuid() and setegid()
#
AC_CHECK_FUNCS(seteuid setresuid)
AC_CHECK_FUNCS(setegid setresgid)

AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINTPTR_T

AC_HEADER_TIME

#
# check for uname library routine
#
AC_MSG_CHECKING([for uname])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[#include <sys/utsname.h>
       #include <stdio.h>
      ]],
     [[
       struct utsname uts;
       uname(&uts);
       printf("running on %s %s %s for %s\n",
	      uts.sysname, uts.release, uts.version, uts.machine);
     ]])],
  [AC_MSG_RESULT(yes)
   AC_DEFINE([HAVE_UNAME], [1], [define if uname is available])
  ],
  [AC_MSG_RESULT(no)
   AC_MSG_WARN([uname is not correctly supported])
  ])

#
# check for GCC noreturn attribute
#
AC_MSG_CHECKING(for GCC noreturn attribute)
AC_TRY_COMPILE([],[void foo() __attribute__((noreturn));],
	[AC_MSG_RESULT(yes)
		ISC_PLATFORM_NORETURN_PRE="#define ISC_PLATFORM_NORETURN_PRE"
		ISC_PLATFORM_NORETURN_POST="#define ISC_PLATFORM_NORETURN_POST __attribute__((noreturn))"],
	[AC_MSG_RESULT(no)
		ISC_PLATFORM_NORETURN_PRE="#define ISC_PLATFORM_NORETURN_PRE"
		ISC_PLATFORM_NORETURN_POST="#define ISC_PLATFORM_NORETURN_POST"])
AC_SUBST(ISC_PLATFORM_NORETURN_PRE)
AC_SUBST(ISC_PLATFORM_NORETURN_POST)

#
# check for GCC malloc attribute
#
AX_GCC_FUNC_ATTRIBUTE([malloc])

AC_MSG_CHECKING([for extended malloc attributes])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[
       #include <stddef.h>
       #include <stdlib.h>
       __attribute__ ((malloc, malloc (free, 1))
       void * xmalloc(size_t sz) { return malloc(sz); }
     ]],
     [[
       void *p = xmalloc(8);
       free(p);
     ]])],
  [AC_MSG_RESULT(yes)
   AC_DEFINE([HAVE_MALLOC_EXT_ATTR], [1], [define if extended attributes for malloc are available])
  ],
  [AC_MSG_RESULT(no)])

#
# check for GCC returns_nonnull attribute
#
AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])

#
# check if we have kqueue
#
# [pairwise: --enable-kqueue, --disable-kqueue]
AC_ARG_ENABLE([kqueue],
	      [AS_HELP_STRING([--enable-kqueue],
			      [use BSD kqueue when available [default=yes]])],
	      [], enable_kqueue="yes")

AS_IF([test "$enable_kqueue" = "yes"],
      [AC_CHECK_FUNCS([kqueue])])

#
# check if we have epoll.  Linux kernel 2.4 has epoll_create() which fails,
# so we need to try running the code, not just test its existence.
#
# [pairwise: --enable-epoll, --disable-epoll]
AC_ARG_ENABLE([epoll],
	      [AS_HELP_STRING([--enable-epoll],
			      [use Linux epoll when available [default=auto]])],
	      [], [enable_epoll="yes"])

AS_IF([test "$enable_epoll" = "yes"],
      [AC_CHECK_FUNCS([epoll_create1])])

#
# check if we support /dev/poll
#
# [pairwise: --enable-devpoll, --disable-devpoll]
AC_ARG_ENABLE([devpoll],
	      [AS_HELP_STRING([--enable-devpoll],
			      [use /dev/poll when available [default=yes]])],
	      [], [enable_devpoll="yes"])
AS_IF([test "$enable_devpoll" = "yes"],
      [AC_CHECK_HEADERS([sys/devpoll.h devpoll.h])])

#
# Find the machine's endian flavor.
#
AC_C_BIGENDIAN

#
# GeoIP support?
#
# Should be on by default if libmaxminddb exists.
#
# [pairwise: skip]
AC_ARG_WITH([geoip2],
	    [AS_HELP_STRING([--with-geoip2],
			    [deprecated, use --with-maxminddb])],
	    [AC_MSG_WARN([--with-geoip2 is DEPRECATED and will be removed in a future release, use --with-maxminddb instead])],
	    [with_geoip2="auto"])

# [pairwise: --enable-geoip --with-maxminddb=auto, --enable-geoip --with-maxminddb=yes, --disable-geoip]
AC_ARG_ENABLE([geoip],
	      [AS_HELP_STRING([--disable-geoip],
			      [support GeoIP2 geolocation ACLs if available [default=yes]])],
	      [], [enable_geoip="yes"])

# [pairwise: skip]
AC_ARG_WITH([maxminddb],
	    [AS_HELP_STRING([--with-maxminddb=PATH],
			    [Build with MaxMind GeoIP2 support (auto|yes|no|path) [default=auto]])],
	    [], [with_maxminddb="$with_geoip2"])

GEOIP2LINKSRCS=
GEOIP2LINKOBJS=
AS_IF([test "$enable_geoip" = "yes"],
      [AS_CASE([$with_maxminddb],
	       [no],[AC_MSG_ERROR([Use '--disable-geoip' to disable the GeoIP])],
	       [auto],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
					 [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
					  PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
					  GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
					  GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
					 ],[:])],
	       [yes],[PKG_CHECK_MODULES([MAXMINDDB], [libmaxminddb],
					[AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
					 PKG_CHECK_VAR([MAXMINDDB_PREFIX], [libmaxminddb], [prefix], [], [AC_MSG_ERROR([libmaxminddb prefix not found in pkg-config; set MAXMINDDB_PREFIX in the environment])])
					 GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
					 GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
					])],
	       [ # default
		   AX_SAVE_FLAGS([maxminddb])
		   MAXMINDDB_CFLAGS="-I$with_maxminddb/include"
		   MAXMINDDB_LIBS="-L$with_maxminddb/lib"
		   CFLAGS="$CFLAGS $MAXMINDDB_CFLAGS"
		   LDFLAGS="$LDFLAGS $MAXMINDDB_LIBS"
		   AC_SEARCH_LIBS([MMDB_open], [maxminddb],
				  [AC_DEFINE([HAVE_GEOIP2], [1], [Build with GeoIP2 support])
				   GEOIP2LINKSRCS='${GEOIP2LINKSRCS}'
				   GEOIP2LINKOBJS='${GEOIP2LINKOBJS}'
				   MAXMINDDB_LIBS="$MAXMINDDB_LIBS $ac_cv_search_MMDB_open"
				   AC_MSG_NOTICE([GeoIP2 default database path set to $with_maxminddb/share/GeoIP])
				   AS_VAR_COPY([MAXMINDDB_PREFIX], [with_maxminddb])
				  ],
				  [AC_MSG_ERROR([GeoIP2 requested, but libmaxminddb not found])])
		   AX_RESTORE_FLAGS([maxminddb])
	       ])
       AC_ARG_VAR([MAXMINDDB_PREFIX], [value of prefix for MAXMINDDB, overriding pkg-config])
])

AC_SUBST([MAXMINDDB_CFLAGS])
AC_SUBST([MAXMINDDB_LIBS])
AC_SUBST([GEOIP2LINKSRCS])
AC_SUBST([GEOIP2LINKOBJS])

#
# Do we have arc4random(), etc ?
#
AC_CHECK_FUNCS(arc4random arc4random_buf arc4random_uniform getrandom)

AX_PTHREAD

LIBS="$PTHREAD_LIBS $LIBS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
CC="$PTHREAD_CC"

AC_CHECK_FUNCS([pthread_attr_getstacksize pthread_attr_setstacksize])

# [pairwise: --with-locktype=adaptive, --with-locktype=standard]
AC_ARG_WITH([locktype],
	    AS_HELP_STRING([--with-locktype=ARG],
			   [Specify mutex lock type
			    (adaptive or standard)]),
	    [], [with_locktype="adaptive"])

AS_CASE([$with_locktype],
	[adaptive],[
	  AC_MSG_CHECKING([for PTHREAD_MUTEX_ADAPTIVE_NP])
	  AC_COMPILE_IFELSE(
	    [AC_LANG_PROGRAM(
	       [[
		 #ifndef _GNU_SOURCE
		 #define _GNU_SOURCE
		 #endif
		 #include <pthread.h>
	       ]],
	       [[
		 return (PTHREAD_MUTEX_ADAPTIVE_NP);
	       ]]
	     )],
	    [AC_MSG_RESULT([using adaptive lock type])
	     AC_DEFINE([HAVE_PTHREAD_MUTEX_ADAPTIVE_NP], 1,
		       [Support for PTHREAD_MUTEX_ADAPTIVE_NP]) ],
	    [AC_MSG_RESULT([using standard lock type])]
	  )],
	[standard],[AC_MSG_RESULT([using standard lock type])],
	[AC_MSG_ERROR([You must specify "adaptive" or "standard" for --with-locktype.])]
       )

AC_CHECK_HEADERS([sched.h])

AC_SEARCH_LIBS([sched_yield],[rt])
AC_CHECK_FUNCS([sched_yield pthread_yield pthread_yield_np])

# Look for functions relating to thread naming
AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np])
AC_CHECK_HEADERS([pthread_np.h], [], [], [#include <pthread.h>])

# libuv
PKG_CHECK_MODULES([LIBUV], [libuv >= 1.37.0], [],
		  [PKG_CHECK_MODULES([LIBUV], [libuv >= 1.0.0 libuv < 1.35.0], [],
				     [AC_MSG_ERROR([libuv >= 1.0.0 (except 1.35.0 and 1.36.0) not found])])])

AX_SAVE_FLAGS([libuv])
CFLAGS="$CFLAGS $LIBUV_CFLAGS"
LIBS="$LIBS $LIBUV_LIBS"

# libuv recvmmsg support
AC_CHECK_DECLS([UV_UDP_MMSG_FREE, UV_UDP_MMSG_CHUNK], [], [], [[#include <uv.h>]])
AC_MSG_CHECKING([whether struct msghdr uses padding for alignment])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/socket.h>],
				   [const struct msghdr h = { .__pad1 = 0, .__pad2 = 0 };])],
		  [AC_MSG_RESULT([yes])
		   AC_DEFINE([HAVE_DECL_UV_UDP_RECVMMSG],
			     [0], [Disable recvmmsg support on systems with MUSL glibc])],
		  [AC_MSG_RESULT([no])
		   AC_CHECK_DECLS([UV_UDP_RECVMMSG], [], [], [[#include <uv.h>]])])

AX_RESTORE_FLAGS([libuv])

#
# flockfile is usually provided by pthreads
#
AC_CHECK_FUNCS([flockfile getc_unlocked])

#
# Look for sysconf to allow detection of the number of processors.
#
AC_CHECK_FUNCS([sysconf])

AC_SUBST(ALWAYS_DEFINES)

AC_MSG_CHECKING(for libtool)

# [pairwise: --with-libtool, --without-libtool]
AC_ARG_WITH(libtool, AS_HELP_STRING([--with-libtool], [use GNU libtool]),
	    use_libtool="$withval", use_libtool="no")
NO_LIBTOOL_ISCLIBS=
NO_LIBTOOL_DNSLIBS=
case $use_libtool in
	yes)
		AC_MSG_RESULT(yes)
		AM_PROG_LIBTOOL
		O=lo
		A=la
		LIBTOOL_MKDEP_SED='s;\.o;\.lo;'
		LIBTOOL_MODE_COMPILE='--mode=compile'
		LIBTOOL_MODE_INSTALL='--mode=install'
		LIBTOOL_MODE_LINK='--mode=link'
		LIBTOOL_MODE_UNINSTALL='--mode=uninstall'
		INSTALL_LIBRARY='${INSTALL_PROGRAM}'
		AC_DEFINE([USE_LIBTOOL],[1],[Define if libtool is used for compilation])
		;;
	*)
		AC_MSG_RESULT(no)
		O=o
		A=a
		LIBTOOL=
		AC_SUBST(LIBTOOL)
		LIBTOOL_MKDEP_SED=
		LIBTOOL_MODE_COMPILE=
		LIBTOOL_MODE_INSTALL=
		LIBTOOL_MODE_LINK=
		LIBTOOL_MODE_UNINSTALL=
		INSTALL_LIBRARY='${INSTALL_DATA}'
		NO_LIBTOOL_ISCLIBS='${NO_LIBTOOL_ISCLIBS}'
		NO_LIBTOOL_DNSLIBS='${NO_LIBTOOL_DNSLIBS}'
		;;
esac
AC_SUBST(INSTALL_LIBRARY)
AC_SUBST(NO_LIBTOOL_ISCLIBS)
AC_SUBST(NO_LIBTOOL_DNSLIBS)

#
# Do we want to use pthread rwlock?
#
# [pairwise: --enable-pthread-rwlock, --disable-pthread-rwlock]
AC_ARG_ENABLE([pthread_rwlock],
	      [AS_HELP_STRING([--enable-pthread-rwlock],
			      [use pthread rwlock instead of internal rwlock implementation])],
	      [], [enable_pthread_rwlock=no])

AS_IF([test "$enable_pthread_rwlock" = "yes"],
      [AC_CHECK_FUNCS([pthread_rwlock_rdlock], [],
		      [AC_MSG_ERROR([pthread_rwlock_rdlock requested but not found])])
       AC_DEFINE([USE_PTHREAD_RWLOCK],[1],[Define if you want to use pthread rwlock implementation])
      ])

CRYPTO=OpenSSL

#
# OpenSSL/LibreSSL is mandatory
#
PKG_CHECK_MODULES([OPENSSL], [libssl libcrypto], [],
		  [AX_CHECK_OPENSSL([:],[AC_MSG_FAILURE([OpenSSL/LibreSSL not found])])])

AX_SAVE_FLAGS([openssl])

#
# This maintenance branch of BIND 9 does not support new OpenSSL APIs
# introduced in version 3.0.0.  Suppress compiler warnings about using
# functions deprecated in newer OpenSSL versions as they will not be
# addressed in BIND 9.16.
#
OPENSSL_CFLAGS="$OPENSSL_CFLAGS -DOPENSSL_SUPPRESS_DEPRECATED"

CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
LIBS="$LIBS $OPENSSL_LIBS"

AC_MSG_CHECKING([for OpenSSL >= 1.0.0 or LibreSSL >= 2.7.0])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/opensslv.h>]],
		     [[#if (!defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER < 0x1000000fL)) || \\
			   (defined(LIBRESSL_VERSION_NUMBER) && (LIBRESSL_VERSION_NUMBER < 0x02070000fL))
		       #error OpenSSL >= 1.0.0 or LibreSSL >= 2.7.0 required
		       #endif
		      ]])],
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found])])

#
# Check for functions added in OpenSSL or LibreSSL
#

AC_CHECK_FUNCS([OPENSSL_init_ssl OPENSSL_init_crypto OPENSSL_cleanup])
AC_CHECK_FUNCS([CRYPTO_zalloc])
AC_CHECK_FUNCS([EVP_CIPHER_CTX_new EVP_CIPHER_CTX_free])
AC_CHECK_FUNCS([EVP_MD_CTX_new EVP_MD_CTX_free EVP_MD_CTX_reset])
AC_CHECK_FUNCS([HMAC_CTX_new HMAC_CTX_free HMAC_CTX_reset HMAC_CTX_get_md])
AC_CHECK_FUNCS([SSL_read_ex SSL_peek_ex SSL_write_ex])
AC_CHECK_FUNCS([BIO_read_ex BIO_write_ex])
AC_CHECK_FUNCS([BN_GENCB_new])
AC_CHECK_FUNCS([SSL_CTX_up_ref])
AC_CHECK_FUNCS([SSL_CTX_set_min_proto_version])

#
# Check for algorithm support in OpenSSL
#

AC_CHECK_FUNCS([ECDSA_sign ECDSA_verify], [:],
	       [AC_MSG_FAILURE([ECDSA support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for ECDSA P-256 support])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);]])],
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found.  ECDSA P-256 support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for ECDSA P-384 support])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_secp384r1);]])],
    [AC_MSG_RESULT([yes])],
    [AC_MSG_FAILURE([not found.  ECDSA P-384 support in OpenSSL is mandatory.])])

AC_MSG_CHECKING([for Ed25519 support])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED25519);]])],
    [AC_DEFINE([HAVE_OPENSSL_ED25519], [1], [define if OpenSSL supports Ed25519])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])

AC_MSG_CHECKING([for Ed448 support])
AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[#include <openssl/evp.h>
		       #include <openssl/ec.h>]],
		     [[EC_KEY *key = EC_KEY_new_by_curve_name(NID_ED448);]])],
    [AC_DEFINE([HAVE_OPENSSL_ED448], [1], [define if OpenSSL supports Ed448])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])

#
# Check for OpenSSL SHA-1 support
#
AC_CHECK_FUNCS([EVP_sha1], [:],
	       [AC_MSG_FAILURE([SHA-1 support in OpenSSL is mandatory.])])

#
# Check for OpenSSL SHA-2 support
#
AC_CHECK_FUNCS([EVP_sha224 EVP_sha256 EVP_sha384 EVP_sha512], [:],
	       [AC_MSG_FAILURE([SHA-2 support in OpenSSL is mandatory.])])

#
# Check for OpenSSL AES support
#
AC_CHECK_FUNCS([EVP_aes_128_ecb EVP_aes_192_ecb EVP_aes_256_ecb], [:],
	       [AC_MSG_FAILURE([AES support in OpenSSL is mandatory.])])

#
# Check for OpenSSL 1.1.x/LibreSSL functions
#
AC_CHECK_FUNCS([DH_get0_key ECDSA_SIG_get0 RSA_set0_key])

AC_CHECK_FUNCS([TLS_server_method TLS_client_method])

#
# Check whether FIPS mode is available and whether we should enable it
#
# FIPS is not included in pairwise testing as the relevant Docker image
# does not support FIPS mode.
#
# [pairwise: skip]
AC_ARG_ENABLE([fips-mode],
	      [AS_HELP_STRING([--enable-fips-mode],
			      [enable FIPS mode in OpenSSL library [default=no]])],
	      [], [enable_fips_mode="no"])

AC_MSG_CHECKING([whether to enable FIPS mode in OpenSSL library])
AS_CASE([$enable_fips_mode],
	[yes], [AC_MSG_RESULT([yes])
		AC_CHECK_FUNCS([FIPS_mode],
			       [], [AC_MSG_FAILURE([OpenSSL FIPS mode requested but not available.])])],
	[no], [AC_MSG_RESULT([no])])

AX_RESTORE_FLAGS([openssl])

AC_SUBST([OPENSSL_CFLAGS])
AC_SUBST([OPENSSL_LIBS])

PKCS11_TOOLS=
PKCS11_TEST=
PKCS11_MANS=
#
# was --enable-native-pkcs11 specified?
#
# DNSRPS builds are included in pairwise testing here and not later because both
# --enable-native-pkcs11 and --enable-dnsrps-dl require --with-dlopen and the
# ordering of the set of ./configure arguments generated during pairwise testing
# is random.
#
# [pairwise: --enable-native-pkcs11 --enable-dnsrps --enable-dnsrps-dl --with-dlopen, --disable-native-pkcs11 --enable-dnsrps --enable-dnsrps-dl --with-dlopen, --disable-native-pkcs11 --enable-dnsrps --enable-dnsrps-dl --with-dlopen, --disable-native-pkcs11 --disable-dnsrps --without-dlopen]
AC_ARG_ENABLE(native-pkcs11,
	      AS_HELP_STRING([--enable-native-pkcs11],
			     [use native PKCS11 for public-key crypto [default=no]]),
	      [:], [enable_native_pkcs11="no"])

AC_MSG_CHECKING([for PKCS11 for Public-Key Cryptography])
AS_CASE([$enable_native_pkcs11],
	[no],[AC_MSG_RESULT([no])],
	[yes],[PKCS11_TOOLS=pkcs11
	       PKCS11_TEST=pkcs11
	       PKCS11_MANS='${pkcs11_man8_MANS}'
	       CRYPTO=pkcs11
	       AS_IF([$use_threads],
		     [:],
		     [AC_MSG_ERROR([PKCS11 requires threading support])])
	       AC_MSG_RESULT([yes])
	       AC_CHECK_FUNCS([getpassphrase])
	      ])
AC_SUBST([PKCS11_TEST])
AC_SUBST([PKCS11_TOOLS])
AC_SUBST([PKCS11_MANS])

AC_SUBST([CRYPTO])
AS_CASE([$CRYPTO],
	[pkcs11],[AC_DEFINE([USE_PKCS11], [1], [define if PKCS11 is used for Public-Key Cryptography])],
	[AC_DEFINE([USE_OPENSSL], [1], [define if OpenSSL is used for Public-Key Cryptography])])

# preparation for automake
# AM_CONDITIONAL([PKCS11_TOOLS], [test "$with_native_pkcs11" = "yes"])

#
# was --with-pkcs11 specified?
#
# [pairwise: skip]
AC_ARG_WITH([pkcs11],
	    [AS_HELP_STRING([--with-pkcs11[=PATH]],
			    [Build with PKCS11 support [no|path] (PATH is for the PKCS11 provider)])],
	    [:], [with_pkcs11="undefined"])

AS_CASE([$with_pkcs11],
	[yes|auto],[AC_MSG_ERROR([--with-pkcs11 needs explicit path to the PKCS11 library])],
	[no|undefined],[with_pkcs11="undefined"])
AC_DEFINE_UNQUOTED([PK11_LIB_LOCATION], ["$with_pkcs11"], [define the default PKCS11 library path])

# for PKCS11 benchmarks

have_clock_gt=no
AC_CHECK_FUNC(clock_gettime,have_clock_gt=yes,)
if test "no" = "$have_clock_gt"; then
	AC_CHECK_LIB(rt,clock_gettime,have_clock_gt=rt,)
fi

if test "no" != "$have_clock_gt"; then
	AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if clock_gettime is available.])
fi

if test "rt" = "$have_clock_gt"; then
	LIBS="-lrt $LIBS"
fi

AC_MSG_CHECKING(for GSSAPI library)

# [pairwise: --with-gssapi=yes, --with-gssapi=auto, --without-gssapi]
AC_ARG_WITH(gssapi,
	    AS_HELP_STRING([--with-gssapi=[PATH|[/path/]krb5-config]],
			   [Specify path for system-supplied GSSAPI
				[default=auto]]),
	    use_gssapi="$withval", use_gssapi="auto")

# first try using krb5-config, if that does not work then fall back to "yes" method.

case "$use_gssapi" in
*/krb5-config|krb5-config)
    AC_MSG_RESULT(trying $use_gssapi)
    if test krb5-config = "$use_gssapi"
    then
	AC_PATH_PROG(KRB5_CONFIG, $use_gssapi)
    else
	KRB5_CONFIG="$use_gssapi"
    fi
    gssapi_cflags=`$KRB5_CONFIG --cflags gssapi`
    gssapi_libs=`$KRB5_CONFIG --libs gssapi`
    krb5_cflags=`$KRB5_CONFIG --cflags krb5`
    krb5_libs=`$KRB5_CONFIG --libs krb5`
    saved_cppflags="$CPPFLAGS"
    CPPFLAGS="$gssapi_cflags $krb5_cflags $CPPFLAGS"
    AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
	[ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"])
    if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
	AC_MSG_RESULT([krb5-config: gssapi.h not found])
	CPPFLAGS="$saved_cppflags"
	use_gssapi="yes"
    else
	AC_CHECK_HEADERS(krb5/krb5.h krb5.h,
	    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"])
	if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
	    AC_MSG_RESULT([krb5-config: krb5.h not found])
	    CPPFLAGS="$saved_cppflags"
	    use_gssapi="yes"
	else
	    CPPFLAGS="$saved_cppflags"
	    saved_libs="$LIBS"
	    LIBS="$gssapi_libs $krb5_libs $LIBS"
	    AC_MSG_CHECKING([krb5-config linking as $LIBS])
	    AC_TRY_LINK( , [gss_acquire_cred();krb5_init_context()],
		gssapi_linked=yes, gssapi_linked=no)
	    case $gssapi_linked in
		yes) AC_MSG_RESULT([krb5-config: linked]);;
		no)  AC_MSG_RESULT([krb5-config: could not determine proper GSSAPI linkage])
		    use_gssapi="yes"
		    ;;
	    esac
	    LIBS=$saved_libs
	fi
    fi
    if test "yes" = "$use_gssapi"; then
	AC_MSG_CHECKING([for GSSAPI library, non krb5-config method])
    fi
    ;;
esac

case "$host" in
*darwin*)
	if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
	then
		use_gssapi=framework
	fi
	;;
esac

# gssapi is just the framework, we really require kerberos v5, so
# look for those headers (the gssapi headers must be there, too)
# The problem with this implementation is that it doesn't allow
# for the specification of gssapi and krb5 headers in different locations,
# which probably ought to be fixed although fixing might raise the issue of
# trying to build with incompatible versions of gssapi and krb5.
if test "yes" = "$use_gssapi" -o "auto" = "$use_gssapi"
then
	# first, deal with the obvious
	if test \( -f /usr/include/kerberosv5/krb5.h -o \
		   -f /usr/include/krb5/krb5.h -o \
		   -f /usr/include/krb5.h \)   -a \
		\( -f /usr/include/gssapi.h -o \
		   -f /usr/include/gssapi/gssapi.h \)
	then
		use_gssapi=/usr
	else
	    krb5dirs="/usr/local /usr/local/krb5 /usr/local/kerberosv5 /usr/local/kerberos /usr/pkg /usr/krb5 /usr/kerberosv5 /usr/kerberos /usr"
	    for d in $krb5dirs
	    do
		if test -f $d/include/gssapi/gssapi_krb5.h -o \
			-f $d/include/krb5.h
		then
			if test -f $d/include/gssapi/gssapi.h -o \
				-f $d/include/gssapi.h
			then
				use_gssapi=$d
				break
			fi
		fi
	    done
	    if test "auto" = "$use_gssapi"
	    then
		use_gssapi="no"
	    fi
	fi
fi

case "$use_gssapi" in
	no)
		AC_MSG_RESULT(disabled)
		USE_GSSAPI=''
		;;
	yes)
		AC_MSG_ERROR([--with-gssapi must specify a path])
		;;
	*/krb5-config|krb5-config)
		USE_GSSAPI='-DGSSAPI'
		DST_GSSAPI_INC="$gssapi_cflags $krb5_cflags"
		DNS_GSSAPI_LIBS="$gssapi_libs $krb5_libs"
		;;
	framework)
		USE_GSSAPI='-DGSSAPI'
		ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <Kerberos/Kerberos.h>"
		ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <Kerberos/Kerberos.h>"
		DNS_GSSAPI_LIBS="-framework Kerberos"
		AC_MSG_RESULT(framework)
		;;

	*)
		AC_MSG_RESULT(looking in $use_gssapi/lib)
		USE_GSSAPI='-DGSSAPI'
		saved_cppflags="$CPPFLAGS"
		CPPFLAGS="-I$use_gssapi/include $CPPFLAGS"
		AC_CHECK_HEADERS(gssapi.h gssapi/gssapi.h,
		    [ISC_PLATFORM_GSSAPIHEADER="#define ISC_PLATFORM_GSSAPIHEADER <$ac_header>"
		     gssapi_hack="#include <$ac_header>"])

		if test "" = "$ISC_PLATFORM_GSSAPIHEADER"; then
		    AC_MSG_ERROR([gssapi.h not found])
		fi

		AC_CHECK_HEADERS(gssapi_krb5.h gssapi/gssapi_krb5.h,
		    [ISC_PLATFORM_GSSAPI_KRB5_HEADER="#define ISC_PLATFORM_GSSAPI_KRB5_HEADER <$ac_header>"
		     gssapi_krb5_hack="#include <$ac_header>"])

		AC_CHECK_HEADERS(krb5.h krb5/krb5.h kerberosv5/krb5.h,
		    [ISC_PLATFORM_KRB5HEADER="#define ISC_PLATFORM_KRB5HEADER <$ac_header>"
		    krb5_hack="#include <$ac_header>"])

		if test "" = "$ISC_PLATFORM_KRB5HEADER"; then
		    AC_MSG_ERROR([krb5.h not found])
		fi

		#
		# XXXDCL This probably doesn't work right on all systems.
		# It will need to be worked on as problems become evident.
		#
		# Essentially the problems here relate to two different
		# areas.  The first area is building with either KTH
		# or MIT Kerberos, particularly when both are present on
		# the machine.  The other is static versus dynamic linking.
		#
		# On the KTH vs MIT issue, Both have libkrb5 that can mess
		# up the works if one implementation ends up trying to
		# use the other's krb.  This is unfortunately a situation
		# that very easily arises.
		#
		# Dynamic linking when the dependency information is built
		# into MIT's libgssapi_krb5 or KTH's libgssapi magically makes
		# all such problems go away, but when that setup is not
		# present, because either the dynamic libraries lack
		# dependencies or static linking is being done, then the
		# problems start to show up.
		saved_libs="$LIBS"
		for TRY_LIBS in \
		    "-lgssapi_krb5" \
		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err" \
		    "-lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lresolv" \
		    "-lgssapi" \
		    "-lgssapi -lkrb5 -ldes -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgssapi -lkrb5 -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgssapi -lkrb5 -lgssapi_krb5 -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgssapi -lkrb5 -lhx509 -lcrypt -lasn1 -lroken -lcom_err" \
		    "-lgss -lkrb5"
		do
		    # Note that this does not include $saved_libs, because
		    # on FreeBSD machines this configure script has added
		    # -L/usr/local/lib to LIBS, which can make the
		    # -lgssapi_krb5 test succeed with shared libraries even
		    # when you are trying to build with KTH in /usr/lib.
		    if test "/usr" = "$use_gssapi"
		    then
			    LIBS="$TRY_LIBS $ISC_OPENSSL_LIBS"
		    else
			    LIBS="-L$use_gssapi/lib $TRY_LIBS $ISC_OPENSSL_LIBS"
		    fi
		    AC_MSG_CHECKING(linking as $TRY_LIBS)
		    AC_TRY_LINK([
#include <sys/types.h>
$gssapi_hack
$gssapi_krb5_hack
$krb5_hack
				] , [gss_acquire_cred(NULL, NULL, 0, NULL, 0, NULL, NULL, NULL);krb5_init_context(NULL);
#if defined(HAVE_GSSAPI_KRB5_H) || defined(HAVE_GSSAPI_GSSAPI_KRB5_H)
gsskrb5_register_acceptor_identity(NULL);
#endif],
				gssapi_linked=yes, gssapi_linked=no)
		    case $gssapi_linked in
		    yes) AC_MSG_RESULT(yes); break ;;
		    no)  AC_MSG_RESULT(no) ;;
		    esac
		done

		CPPFLAGS="$saved_cppflags"

		case $gssapi_linked in
		no) AC_MSG_ERROR(could not determine proper GSSAPI linkage) ;;
		esac

		#
		# XXXDCL Major kludge.  Tries to cope with KTH in /usr/lib
		# but MIT in /usr/local/lib and trying to build with KTH.
		# /usr/local/lib can end up earlier on the link lines.
		# Like most kludges, this one is not only inelegant it
		# is also likely to be the wrong thing to do at least as
		# many times as it is the right thing.  Something better
		# needs to be done.
		#
		if test "/usr" = "$use_gssapi" -a \
			-f /usr/local/lib/libkrb5.a; then
		    FIX_KTH_VS_MIT=yes
		fi

		case "$FIX_KTH_VS_MIT" in
		yes)
		    case "$enable_static_linking" in
		    yes) gssapi_lib_suffix=".a"  ;;
		    *)   gssapi_lib_suffix=".so" ;;
		    esac

		    for lib in $LIBS; do
			case $lib in
			-L*)
			    ;;
			-l*)
			    new_lib=`echo $lib |
				     sed -e s%^-l%$use_gssapi/lib/lib% \
					 -e s%$%$gssapi_lib_suffix%`
			    NEW_LIBS="$NEW_LIBS $new_lib"
			    ;;
			*)
			   AC_MSG_ERROR([KTH vs MIT Kerberos confusion!])
			    ;;
			esac
		    done
		    LIBS="$NEW_LIBS"
		    ;;
		esac

		DST_GSSAPI_INC="-I$use_gssapi/include"
		DNS_GSSAPI_LIBS="$LIBS"

		AC_MSG_RESULT(using GSSAPI from $use_gssapi/lib and $use_gssapi/include)
		LIBS="$saved_libs"
		;;
esac

AC_SUBST(ISC_PLATFORM_GSSAPIHEADER)
AC_SUBST(ISC_PLATFORM_GSSAPI_KRB5_HEADER)
AC_SUBST(ISC_PLATFORM_KRB5HEADER)

AC_SUBST(USE_GSSAPI)
AC_SUBST(DST_GSSAPI_INC)
AC_SUBST(DNS_GSSAPI_LIBS)
DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS"

#
# Applications linking with libdns also need to link with these libraries.
#

AC_SUBST(DNS_CRYPTO_LIBS)

#
# was --with-lmdb specified?
#
AC_MSG_CHECKING(for lmdb library)

# [pairwise: --with-lmdb=auto, --with-lmdb=yes, --without-lmdb]
AC_ARG_WITH(lmdb,
	    AS_HELP_STRING([--with-lmdb[=PATH]],
			   [build with LMDB library [yes|no|path]]),
    use_lmdb="$withval", use_lmdb="auto")

have_lmdb=""
case "$use_lmdb" in
	no)
		LMDB_LIBS=""
		;;
	auto|yes)
		for d in /usr /usr/local /opt/local
		do
			if test -f "${d}/include/lmdb.h"
			then
				if test ${d} != /usr
				then
					LMDB_CFLAGS="-I ${d}/include"
					LMDB_LIBS="-L${d}/lib"
				fi
				have_lmdb="yes"
			fi
		done
		;;
	*)
		if test -f "${use_lmdb}/include/lmdb.h"
		then
			LMDB_CFLAGS="-I${use_lmdb}/include"
			LMDB_LIBS="-L${use_lmdb}/lib"
			have_lmdb="yes"
		else
			AC_MSG_ERROR([$use_lmdb/include/lmdb.h not found.])
		fi
		;;
esac

if test "X${have_lmdb}" != "X"
then
	AC_MSG_RESULT(yes)
	AX_SAVE_FLAGS([lmdb])
	CFLAGS="$CFLAGS $LMDB_CFLAGS"
	LIBS="$LIBS $LMDB_LIBS"
	AC_SEARCH_LIBS([mdb_env_create], [lmdb], [],
		       [AC_MSG_ERROR([found lmdb include but not library.])
			have_lmdb=""])
	LMDB_LIBS="$LMDB_LIBS $ac_cv_search_mdb_env_create"
	AX_RESTORE_FLAGS([lmdb])
elif test "X$use_lmdb" = Xyes
then
	AC_MSG_ERROR([include/lmdb.h not found.])
else
	AC_MSG_RESULT(no)
fi
AC_SUBST([LMDB_CFLAGS])
AC_SUBST([LMDB_LIBS])

NZD_TOOLS=""
NZDSRCS=
NZDTARGETS=
if test "X${have_lmdb}" != "X"
then
	AC_DEFINE(HAVE_LMDB, 1, [Define if lmdb was found])
	NZD_TOOLS="nzd"
	NZDSRCS='${NZDSRCS}'
	NZDTARGETS='${NZDTARGETS}'
	NZD_MANS='${nzd_man8_MANS}'
fi
AC_SUBST(NZD_TOOLS)
AC_SUBST(NZDSRCS)
AC_SUBST(NZDTARGETS)
AC_SUBST(NZD_MANS)

#
# was --with-libxml2 specified?
#
# [pairwise: --with-libxml2=auto, --with-libxml2=yes, --without-libxml2]
AC_ARG_WITH([libxml2],
	    [AS_HELP_STRING([--with-libxml2],
			    [build with libxml2 library [yes|no|auto] (default is auto)])],
	    [], [with_libxml2="auto"])

AS_CASE([$with_libxml2],
	[no],[],
	[auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
				  [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])],
				  [:])],
	[yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0],
				 [AC_DEFINE([HAVE_LIBXML2], [1], [Use libxml2 library])])],
	[AC_MSG_ERROR([Specifying libxml2 installation path is not supported, adjust PKG_CONFIG_PATH instead])])

#
# DEPRECATED
#
# [pairwise: skip]
AC_ARG_WITH([libjson],
	    [AS_HELP_STRING([--with-libjson],
			    [deprecated, use --with-json-c])],
	    [AC_MSG_WARN([--with-libjson is DEPRECATED and will be removed in a future release, use --with-json-c instead])],
	    [with_libjson="detect"])

#
# was --with-json-c specified?
#
# [pairwise: --with-json-c=detect, --with-json-c=yes, --without-json-c]
AC_ARG_WITH([json-c],
	    [AS_HELP_STRING([--with-json-c],
			    [build with json-c library [yes|no|detect] (default is detect)])],
	    [], [with_json_c="$with_libjson"])

AS_CASE([$with_json_c],
	[no],[],
	[detect],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
				    [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])],
				    [:])],
	[yes],[PKG_CHECK_MODULES([JSON_C], [json-c >= 0.11],
				 [AC_DEFINE([HAVE_JSON_C], [1], [Use json-c library])])],
	[AC_MSG_ERROR([Specifying json-c installation path is not supported, adjust PKG_CONFIG_PATH instead])]
       )

AC_SUBST([JSON_C_CFLAGS])
AC_SUBST([JSON_C_LIBS])

# [pairwise: --with-zlib=auto, --with-zlib=yes, --without-zlib]
AC_ARG_WITH([zlib],
           [AS_HELP_STRING([--with-zlib],
                           [build with zlib for HTTP compression
                            [default=yes]])],
	   [], with_zlib="auto")

AS_CASE([$with_zlib],
       [no],[],
       [auto],[PKG_CHECK_MODULES([ZLIB], [zlib],
                                 [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])],
                                 [:])],
       [yes],[PKG_CHECK_MODULES([ZLIB], [zlib],
                                [AC_DEFINE([HAVE_ZLIB], [1], [Use zlib library])])],
       [AC_MSG_ERROR([Specifying zlib installation path is not supported, adjust PKG_CONFIG_PATH instead])])
AC_SUBST([ZLIB_CFLAGS])
AC_SUBST([ZLIB_LIBS])

#
# In solaris 10, SMF can manage named service
#
AC_CHECK_LIB(scf, smf_enable_instance)

#
# Additional compiler settings.
#
MKDEPCC="$CC"

MKDEPCFLAGS="-M"
AS_CASE([$host],
	[*-solaris*],[
	    AS_IF([test "$GCC" != "yes"],
		  [MKDEPCFLAGS="-xM"])])

AS_IF([test "$GCC" = "yes"],
      [STD_CWARNINGS="$STD_CWARNINGS -W -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wformat -Wpointer-arith -Wno-missing-field-initializers"]
      )

AX_CHECK_COMPILE_FLAG([-fno-strict-aliasing],
		      [STD_CWARNINGS="$STD_CWARNINGS -fno-strict-aliasing"])
AX_CHECK_COMPILE_FLAG([-Werror -fno-delete-null-pointer-checks],
		      [STC_CWARNINGS="$STD_CWARNINGS -fno-delete-null-pointer-checks"])
AS_IF([test "$enable_warn_shadow" = "yes"],
      [AX_CHECK_COMPILE_FLAG([-Wshadow],
			     [STD_CWARNINGS="$STD_CWARNINGS -Wshadow"])])
AS_IF([test "$enable_warn_error" = "yes"],
      [AX_CHECK_COMPILE_FLAG([-Werror],
			     [STD_CWARNINGS="$STD_CWARNINGS -Werror"])])

AC_SUBST([MKDEPCC])
AC_SUBST([MKDEPCFLAGS])
AC_SUBST([MKDEPPROG])

#
# -lxnet buys us one big porting headache...  standards, gotta love 'em.
#
# AC_CHECK_LIB(xnet, socket, ,
#    AC_CHECK_LIB(socket, socket)
# )
#
# Use this for now, instead:
#
case "$host" in
	*-linux*)
		;;
	*)
		AC_CHECK_LIB(socket, socket)
		AC_CHECK_LIB(nsl, inet_addr)
		;;
esac

#
# Work around Solaris's select() limitations.
#
case "$host" in
	*-solaris2.[[89]]|*-solaris2.1?)
	AC_DEFINE(FD_SETSIZE, 65536,
		  [Solaris hack to get select_large_fdset.])
	;;
esac

#
# Purify support
#
AC_MSG_CHECKING(whether to use purify)

# Purify is not included in pairwise testing as that tool is not present
# in the relevant Docker image.
#
# [pairwise: skip]
AC_ARG_WITH(purify,
	    AS_HELP_STRING([--with-purify[=PATH]],[use Rational purify]),
	    use_purify="$withval", use_purify="no")

case "$use_purify" in
	no)
		;;
	yes)
		AC_PATH_PROG(purify_path, purify, purify)
		;;
	*)
		purify_path="$use_purify"
		;;
esac

case "$use_purify" in
	no)
		AC_MSG_RESULT(no)
		PURIFY=""
		;;
	*)
		if test -f "$purify_path" || test purify = "$purify_path"; then
			AC_MSG_RESULT($purify_path)
			PURIFYFLAGS="`echo $PURIFYOPTIONS`"
			PURIFY="$purify_path $PURIFYFLAGS"
		else
			AC_MSG_ERROR([$purify_path not found.

Please choose the proper path with the following command:

    configure --with-purify=PATH
])
		fi
		;;
esac

AC_SUBST(PURIFY)

#
# Google/Great Performance Tools CPU Profiler
#
AC_MSG_CHECKING(whether to use gperftools profiler)

# Google/Great Performance Tools CPU Profiler is not included in
# pairwise testing as that tool is not present in the relevant Docker
# image.
#
# [pairwise: skip]
AC_ARG_WITH(gperftools-profiler,
	    AS_HELP_STRING([--with-gperftools-profiler],
			   [use gperftools CPU profiler]),
	    use_profiler="$withval", use_profiler="no")

case $use_profiler in
	yes)
		AC_MSG_RESULT(yes)
		AC_DEFINE([HAVE_GPERFTOOLS_PROFILER], 1,
		[Define to use gperftools CPU profiler.])
		LIBS="$LIBS -lprofiler"
		;;
	*)
		AC_MSG_RESULT(no)
		;;
esac

#
# enable/disable dumping stack backtrace.  Also check if the system supports
# glibc-compatible backtrace() function.
#
# [pairwise: --enable-backtrace, --disable-backtrace]
AC_ARG_ENABLE([backtrace],
	      [AS_HELP_STRING([--enable-backtrace],
			      [log stack backtrace on abort [default=yes]])],
	      [], [enable_backtrace="yes"])

AS_IF([test "$enable_backtrace" = "yes"],
      [AC_DEFINE([USE_BACKTRACE], [1], [define if we can use backtrace])
       AC_CHECK_LIB(execinfo,backtrace,EXILIBS=-lexecinfo,EXILIBS=)
       LIBS="$LIBS $EXILIBS"
       AC_LINK_IFELSE(
	 [AC_LANG_PROGRAM(
	    [[#include <execinfo.h>]],
	    [[return (backtrace((void **)0, 0));]]
	  )],
	 [AC_DEFINE([HAVE_LIBCTRACE], [1], [define if system have backtrace function])],
	 [AC_LINK_IFELSE(
	    [AC_LANG_PROGRAM(
	       [[#include <stddef.h>]],
	       [[return _Unwind_Backtrace(NULL, NULL);]]
	     )],
	    [AC_DEFINE([HAVE_UNWIND_BACKTRACE], [1], [define if the compiler supports _Unwind_Backtrace()])]
	  )]
       )])

# [pairwise: --enable-symtable, --disable-symtable]
AC_ARG_ENABLE(symtable,
	      AS_HELP_STRING([--enable-symtable],
			     [use internal symbol table for backtrace
			      [all|minimal(default)|none]]),
		want_symtable="$enableval",  want_symtable="minimal")
case $want_symtable in
yes|all|minimal)     # "yes" is a hidden value equivalent to "minimal"
	if test "" = "$PERL"
	then
		AC_MSG_ERROR([Internal symbol table requires perl but no perl is found.
Install perl or explicitly disable the feature by --disable-symtable.])
	fi
	if test "yes" = "$use_libtool"; then
		AC_MSG_WARN([Internal symbol table does not work with libtool.  Disabling symbol table.])
	else
		# we generate the internal symbol table only for those systems
		# known to work to avoid unexpected build failure.  Also, warn
		# about unsupported systems when the feature is enabled
		#  manually.
		case $host_os in
		freebsd*|netbsd*|openbsd*|linux*|solaris*|darwin*)
			MKSYMTBL_PROGRAM="$PERL"
			if test "all" = "$want_symtable"; then
				ALWAYS_MAKE_SYMTABLE="yes"
			fi
			;;
		*)
			if test "yes" = "$want_symtable" -o "all" = "$want_symtable"
			then
				AC_MSG_WARN([this system is not known to generate internal symbol table safely; disabling it])
			fi
		esac
	fi
	;;
*)
	;;
esac
AC_SUBST(MKSYMTBL_PROGRAM)
AC_SUBST(ALWAYS_MAKE_SYMTABLE)

#
# File name extension for static archive files, for those few places
# where they are treated differently from dynamic ones.
#
SA=a

AC_SUBST(O)
AC_SUBST(A)
AC_SUBST(SA)
AC_SUBST(LIBTOOL_MKDEP_SED)
AC_SUBST(LIBTOOL_MODE_COMPILE)
AC_SUBST(LIBTOOL_MODE_INSTALL)
AC_SUBST(LIBTOOL_MODE_LINK)
AC_SUBST(LIBTOOL_MODE_UNINSTALL)

BIND9_CO_RULE=".c.$O:"
AC_SUBST(BIND9_CO_RULE)

#
# Here begins a very long section to determine the system's networking
# capabilities.  The order of the tests is significant.
#

#
# We do the IPv6 compilation checking after libtool so that we can put
# the right suffix on the files.
#
AC_MSG_CHECKING([for IPv6 structures])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[
       #include <sys/types.h>
       #include <sys/socket.h>
       #include <netinet/in.h>
     ]],
     [[
       struct sockaddr_in6 sin6;
       struct in6_addr in6;
       struct in6_pktinfo in6_pi;
       struct sockaddr_storage storage;
       in6 = in6addr_any;
       in6 = in6addr_loopback;
       sin6.sin6_scope_id = 0;
       return (0);
     ]])],
  [AC_MSG_RESULT([yes])],
  [AC_MSG_FAILURE([IPv6 support is mandatory])])

#
# Allow forcibly disabling TCP Fast Open support as autodetection might yield
# confusing results on some systems (e.g. FreeBSD; see set_tcp_fastopen()
# comment in lib/isc/unix/socket.c).
#
# [pairwise: --enable-tcp-fastopen, --disable-tcp-fastopen]
AC_ARG_ENABLE([tcp_fastopen],
	      [AS_HELP_STRING([--disable-tcp-fastopen],
			      [disable TCP Fast Open support [default=yes]])],
	     [], [enable_tcp_fastopen="yes"])

AS_IF([test "$enable_tcp_fastopen" = "yes"],
      [AC_DEFINE([ENABLE_TCP_FASTOPEN], [1], [define if you want TCP_FASTOPEN enabled if available])])

#
# Check for some other useful functions that are not ever-present.
#
AC_CHECK_FUNCS([strlcpy strlcat strnstr])

AC_SUBST(READLINE_LIB)

# [pairwise: --with-readline=auto, --with-readline=yes, --without-readline]
AC_ARG_WITH(readline,
	    AS_HELP_STRING([--with-readline[=LIBSPEC]],
			   [specify readline library [default auto]]),
	    use_readline="$withval", use_readline="auto")
case "$use_readline" in
no)	;;
*)
	saved_LIBS="$LIBS"
	case "$use_readline" in
	yes|auto) try_readline="-ledit"; or_readline="-lreadline" ;;
	*) try_readline="$use_readline"
	esac
	for readline in "$try_readline" $or_readline
	do
		LIBS="$readline"
		AC_MSG_NOTICE(checking for readline with $readline)
		AC_CHECK_FUNCS(readline)
		if test "yes" = "$ac_cv_func_readline"
		then
			READLINE_LIB="$readline"
			break
		fi
		for lib in -lterminfo -ltermcap -lncurses -lcurses
		do
			AC_MSG_NOTICE(checking for readline with $readline $lib)
			unset ac_cv_func_readline
			LIBS="$readline $lib"
			AC_CHECK_FUNCS(readline)
			if test "yes" = "$ac_cv_func_readline"
			then
				READLINE_LIB="$readline $lib"
				break
			fi
		done
		if test "yes" = "$ac_cv_func_readline"
		then
			break
		fi
	done
	if test "auto" != "$use_readline" &&
	   test "X$READLINE_LIB" = "X"
	then
		AC_MSG_ERROR([The readline library was not found.])
	fi
	LIBS="$saved_LIBS"
	;;
esac
if test "yes" = "$ac_cv_func_readline"
then
	case "$READLINE_LIB" in
	*edit*)
		AC_CHECK_HEADERS(editline/readline.h)
		AC_CHECK_HEADERS(edit/readline/readline.h)
		AC_CHECK_HEADERS(edit/readline/history.h)
		;;
	esac
	AC_CHECK_HEADERS(readline/readline.h)
	AC_CHECK_HEADERS(readline/history.h)
fi

AC_SUBST(DST_EXTRA_OBJS)
AC_SUBST(DST_EXTRA_SRCS)

#
# Security Stuff
#
# Note it is very recommended to *not* disable chroot(),
# this is only because chroot() was made obsolete by Posix.
#
# [pairwise: --enable-chroot, --disable-chroot]
AC_ARG_ENABLE(chroot, AS_HELP_STRING([--disable-chroot], [disable chroot]))
case "$enable_chroot" in
	yes|'')
		AC_CHECK_FUNCS(chroot)
		;;
	no)
		;;
esac

LIBCAP_LIBS=""
AC_MSG_CHECKING([whether to enable Linux capabilities])

# [pairwise: --enable-linux-caps, --disable-linux-caps]
AC_ARG_ENABLE([linux-caps],
	      [AS_HELP_STRING([--disable-linux-caps],
			      [disable Linux capabilities])],
	      [],
	      [AS_CASE([$host],
		       [*-linux*],[enable_linux_caps=yes],
		       [enable_linux_caps=no])])

AS_IF([test "$enable_linux_caps" = "yes"],
      [AC_MSG_RESULT([yes])
       AC_CHECK_HEADERS([sys/capability.h],
			[],
			[AC_MSG_ERROR(m4_normalize([sys/capability.h header is required for Linux capabilities support.
						    Either install libcap or use --disable-linux-caps.]))])
       AX_SAVE_FLAGS([cap])
       AC_SEARCH_LIBS([cap_set_proc], [cap],
		      [LIBCAP_LIBS="$ac_cv_search_cap_set_proc"],
		      [AC_MSG_ERROR(m4_normalize([libcap is required for Linux capabilities support.
						  Either install libcap or use --disable-linux-caps.]))])
       AX_RESTORE_FLAGS([cap])],
      [AC_MSG_RESULT([no])])
AC_SUBST([LIBCAP_LIBS])

AC_CHECK_HEADERS(sys/un.h,
ISC_PLATFORM_HAVESYSUNH="#define ISC_PLATFORM_HAVESYSUNH 1"
,
ISC_PLATFORM_HAVESYSUNH="#undef ISC_PLATFORM_HAVESYSUNH"
)
AC_SUBST(ISC_PLATFORM_HAVESYSUNH)

case "$host" in
*-solaris*)
	AC_DEFINE(NEED_SECURE_DIRECTORY, 1,
		  [Define if connect does not honour the permission on the UNIX domain socket.])
	;;
esac

#
# Time Zone Stuff
#
AC_CHECK_FUNCS([tzset])

AC_MSG_CHECKING(for optarg declaration)
AC_TRY_COMPILE([
#include <unistd.h>
],
[optarg = 0;],
[AC_MSG_RESULT(yes)],
[AC_MSG_RESULT(no)
GEN_NEED_OPTARG="-DNEED_OPTARG=1"
AC_DEFINE(NEED_OPTARG, 1, [Defined if extern char *optarg is not declared.])])

#
# Check for nanoseconds in file stats
#
AC_MSG_CHECKING([for st_mtim.tv_nsec])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[#include <sys/fcntl.h>]],
     [[struct stat s;
       return(s.st_mtim.tv_nsec);
      ]])],
   [AC_DEFINE([HAVE_STAT_NSEC], [1], [define if struct stat has st_mtim.tv_nsec field])])

#
# Check for if_nametoindex() for IPv6 scoped addresses support
#
AC_CHECK_FUNCS([if_nametoindex])

ISC_ATOMIC_LIBS=""
AC_CHECK_HEADERS(
  [stdatomic.h],
  [AC_MSG_CHECKING([for memory model aware atomic operations])
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM(
	[[#include <stdatomic.h>]],
	[[atomic_int_fast32_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
      )],
     [AC_MSG_RESULT([stdatomic.h])
      AC_MSG_CHECKING([whether -latomic is needed for 64-bit stdatomic.h functions])
      AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
	   [[#include <stdatomic.h>]],
	   [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
	 )],
	[AC_MSG_RESULT([no])],
	[ISC_ATOMIC_LIBS="-latomic"
	 AX_SAVE_FLAGS([atomic])
	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
	 AC_LINK_IFELSE(
	   [AC_LANG_PROGRAM(
	      [[#include <stdatomic.h>]],
	      [[atomic_int_fast64_t val = 0; atomic_fetch_add_explicit(&val, 1, memory_order_relaxed);]]
	    )],
	   [AC_MSG_RESULT([yes])],
	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
	 AX_RESTORE_FLAGS([atomic])
	])
     ],
     [AC_MSG_FAILURE([stdatomic.h header found, but compilation failed, please fix your toolchain.])]
   )],
  [AC_MSG_CHECKING([for memory model aware atomic operations])
   AC_COMPILE_IFELSE(
     [AC_LANG_PROGRAM(
	[[#include <inttypes.h>]],
	[[int32_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
      )],
     [AC_MSG_RESULT([__atomic builtins])
      AC_DEFINE([HAVE___ATOMIC], [1], [define if __atomic builtins are not available])
      AC_MSG_CHECKING([whether -latomic is needed for 64-bit __atomic builtins])
      AC_LINK_IFELSE(
	[AC_LANG_PROGRAM(
	   [[#include <inttypes.h>]],
	   [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
	 )],
	[AC_MSG_RESULT([no])],
	[ISC_ATOMIC_LIBS="-latomic"
	 AX_SAVE_FLAGS([atomic])
	 LIBS="$LIBS $ISC_ATOMIC_LIBS"
	 AC_LINK_IFELSE(
	   [AC_LANG_PROGRAM(
	      [[#include <inttypes.h>]],
	      [[int64_t val = 0; __atomic_fetch_add(&val, 1, __ATOMIC_RELAXED);]]
	    )],
	   [AC_MSG_RESULT([yes])],
	   [AC_MSG_FAILURE([libatomic needed, but linking with -latomic failed, please fix your toolchain.])])
	 AX_RESTORE_FLAGS([atomic])
	])
     ],
     [AC_MSG_RESULT([__sync builtins])
     ])
  ])
LIBS="$LIBS $ISC_ATOMIC_LIBS"

AC_CHECK_HEADERS([stdalign.h])

AC_CHECK_HEADERS([uchar.h])

#
# Check for __builtin_unreachable
#
AC_MSG_CHECKING([compiler support for __builtin_unreachable()])
AC_LINK_IFELSE(
  [AC_LANG_PROGRAM(
     [[]],
     [[__builtin_unreachable();]]
   )],
  [AC_MSG_RESULT([yes])
   AC_DEFINE([HAVE_BUILTIN_UNREACHABLE], [1], [define if the compiler supports __builtin_unreachable().])
  ],
  [AC_MSG_RESULT([no])
  ])

#
# Check for __builtin_expect
#
AC_MSG_CHECKING([compiler support for __builtin_expect])
AC_TRY_LINK(, [
	return (__builtin_expect(1, 1) ? 1 : 0);
], [
	have_builtin_expect=yes
	AC_MSG_RESULT(yes)
], [
	have_builtin_expect=no
	AC_MSG_RESULT(no)
])
if test "yes" = "$have_builtin_expect"; then
	AC_DEFINE(HAVE_BUILTIN_EXPECT, 1, [Define to 1 if the compiler supports __builtin_expect.])
fi

#
# Check for __builtin_clz
#
AC_MSG_CHECKING([compiler support for __builtin_clz])
AC_TRY_LINK(, [
	return (__builtin_clz(0xff) == 24 ? 1 : 0);
], [
	have_builtin_clz=yes
	AC_MSG_RESULT(yes)
], [
	have_builtin_clz=no
	AC_MSG_RESULT(no)
])
if test "yes" = "$have_builtin_clz"; then
	AC_DEFINE(HAVE_BUILTIN_CLZ, 1, [Define to 1 if the compiler supports __builtin_clz.])
fi

#
# Activate "rrset-order fixed" or not?
#
# [pairwise: --enable-fixed-rrset, --disable-fixed-rrset]
AC_ARG_ENABLE(fixed-rrset,
	      AS_HELP_STRING([--enable-fixed-rrset],
			     [enable fixed rrset ordering [default=no]]),
	      enable_fixed="$enableval", enable_fixed="no")
case "$enable_fixed" in
	yes)
		AC_DEFINE(DNS_RDATASET_FIXED, 1,
			  [Define to enable "rrset-order fixed" syntax.])
		;;
	no)
		;;
	*)
		;;
esac

#
# Activate dnstap?
#
# [pairwise: --enable-dnstap, --disable-dnstap]
AC_ARG_ENABLE(dnstap,
	      AS_HELP_STRING([--enable-dnstap],
			     [enable dnstap support
				(requires fstrm, protobuf-c)]),
	      use_dnstap=$enableval, use_dnstap=no)

DNSTAP=
DNSTAPSRCS=
DNSTAPOBJS=
DNSTAPTARGETS=
if test "x$use_dnstap" != "xno"; then

	# [pairwise: skip]
	AC_ARG_WITH([protobuf-c],
		    AS_HELP_STRING([--with-protobuf-c=path],
				   [Path where protobuf-c is installed, for dnstap]), [
	    # workaround for protobuf-c includes at old dir
	    # before protobuf-c-1.0.0
	    if test -f $withval/include/google/protobuf-c/protobuf-c.h
	    then
		PROTOBUF_C_CFLAGS="-I$withval/include/google"
	    else
		PROTOBUF_C_CFLAGS="-I$withval/include"
	    fi
	    PROTOBUF_C_LIBS="-L$withval/lib"
	    AC_PATH_PROG([PROTOC_C], [protoc-c], [],
			 [$PATH$PATH_SEPARATOR$withval/bin])
	], [
	    # workaround for protobuf-c includes at old dir
	    # before protobuf-c-1.0.0
	    if test -f /usr/include/google/protobuf-c/protobuf-c.h
	    then
		PROTOBUF_C_CFLAGS="-I/usr/include/google"
	    else
		if test -f /usr/local/include/google/protobuf-c/protobuf-c.h
		then
		    PROTOBUF_C_CFLAGS="-I/usr/local/include/google"
		    PROTOBUF_C_LIBS="-L/usr/local/lib"
		elif test -f /opt/local/include/google/protobuf-c/protobuf-c.h
		then
		    PROTOBUF_C_CFLAGS="-I/opt/local/include/google"
		    PROTOBUF_C_LIBS="-L/opt/local/lib"
		fi
	    fi
	    AC_PATH_PROG([PROTOC_C],[protoc-c])
	])
	if test -z "$PROTOC_C"; then
		AC_MSG_ERROR([The protoc-c program was not found.])
	fi

	# [pairwise: skip]
	AC_ARG_WITH([libfstrm], AS_HELP_STRING([--with-libfstrm=path],
		    [Path where libfstrm is installed, for dnstap]), [
	    FSTRM_CFLAGS="-I$withval/include"
	    FSTRM_LIBS="-L$withval/lib"
	    AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture], [], [$PATH$PATH_SEPARATOR$withval/bin])
	],[
	    for d in /usr /usr/local /opt/local
	    do
		if test -f "${d}/include/fstrm.h"
		then
		    if test ${d} != /usr
		    then
			FSTRM_CFLAGS="-I${d}/include"
			FSTRM_LIBS="-L${d}/lib"
		    fi
		    have_fstrm="$d"
		    break
		fi
	    done
	    if test -z "$have_fstrm"; then
		AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture])
	    else
		AC_PATH_PROG([FSTRM_CAPTURE], [fstrm_capture], [], [$PATH$PATH_SEPARATOR$have_fstrm/bin])
	    fi
	])
	AX_SAVE_FLAGS([dnstap])
	CFLAGS="$CFLAGS $PROTOBUF_C_CFLAGS $FSTRM_CFLAGS"
	LIBS="$LDFLAGS $PROTOBUF_C_LIBS $FSTRM_LIBS"

	AC_SEARCH_LIBS([fstrm_iothr_init], [fstrm], [],
		       AC_MSG_ERROR([The fstrm library was not found. Please install fstrm!]))
	FSTRM_LIBS="$FSTRM_LIBS $ac_cv_search_fstrm_iothr_init"

	AC_SEARCH_LIBS([protobuf_c_message_pack], [protobuf-c], [],
		       AC_MSG_ERROR([The protobuf-c library was not found. Please install protobuf-c!]))
	PROTOBUF_C_LIBS="$PROTOBUF_C_LIBS $ac_cv_search_protobuf_c_message_pack"

	AX_RESTORE_FLAGS([dnstap])
	AC_DEFINE(HAVE_DNSTAP, 1, [Define to 1 to enable dnstap support])
	DNSTAP=dnstap
	DNSTAPSRCS='${DNSTAPSRCS}'
	DNSTAPOBJS='${DNSTAPOBJS}'
	DNSTAPTARGETS='${DNSTAPTARGETS}'
	DNSTAP_MANS='${dnstap_man1_MANS}'
fi
AC_SUBST(DNSTAP)
AC_SUBST(DNSTAPSRCS)
AC_SUBST(DNSTAPOBJS)
AC_SUBST(DNSTAPTARGETS)
AC_SUBST(DNSTAP_MANS)
AC_SUBST([PROTOBUF_C_CFLAGS])
AC_SUBST([PROTOBUF_C_LIBS])
AC_SUBST([FSTRM_CFLAGS])
AC_SUBST([FSTRM_LIBS])

#
#  The following sets up how non-blocking i/o is established.
#  cygwin and solaris 2.x (x<5) require special handling.
#
case "$host" in
*-cygwin*) AC_DEFINE(PORT_NONBLOCK, O_NDELAY);;
*-solaris2.[[01234]])
	AC_DEFINE(PORT_NONBLOCK, O_NONBLOCK)
	AC_DEFINE(USE_FIONBIO_IOCTL, 1,
		  [Defined if you need to use ioctl(FIONBIO) instead a fcntl call to make non-blocking.])
	;;
*) AC_DEFINE(PORT_NONBLOCK, O_NONBLOCK,
	     [Sets which flag to pass to open/fcntl to make non-blocking (O_NDELAY/O_NONBLOCK).])
	;;
esac
#
# Solaris 2.5.1 and earlier cannot bind() then connect() a TCP socket.
# This prevents the source address being set.
#
case "$host" in
*-solaris2.[[012345]]|*-solaris2.5.1)
	AC_DEFINE(BROKEN_TCP_BIND_BEFORE_CONNECT, 1,
		  [Define if you cannot bind() before connect() for TCP sockets.])
	;;
esac
#
# The following sections deal with tools used for formatting
# the documentation.  They are all optional, unless you are
# a developer editing the documentation source.
#

#
# The following sections deal with tools used for formatting
# the documentation.  They are all optional, unless you are
# a developer editing the documentation source.
#

#
# Look for sphinx-build
#
AC_ARG_VAR([SPHINX_BUILD], [path to sphinx-build binary used to build the documentation])
AC_PATH_PROG([SPHINX_BUILD], [sphinx-build], [:])
AM_CONDITIONAL([HAVE_SPHINX_BUILD], [test "$SPHINX_BUILD" != ":"])

AC_PATH_PROG([XELATEX], [xelatex], [:])
AC_PATH_PROG([LATEXMK], [latexmk], [:])
AM_CONDITIONAL([HAVE_XELATEX], [test "$XELATEX" != ":" && test "$LATEXMK" != ":"])

#
# Build the man pages only if we have prebuilt manpages or we can build them from RST sources
#
BUILD_MANPAGES=
AS_IF([test -e doc/man/named.conf.5in || test "$SPHINX_BUILD" != ":"],
      [BUILD_MANPAGES=man])
AC_SUBST([BUILD_MANPAGES])

#
# Pull release date from CHANGES file last modification date
# for reproducible builds
#
release_date=`date -u -r CHANGES +%Y-%m-%d`
AC_SUBST([RELEASE_DATE], $release_date)

# Don't build the documentation if the sphinx-build is not present
PDFTARGET=
HTMLTARGET=
MANSRCS=
AS_IF([test -n "$SPHINX_BUILD"],[
	  MANSRCS='$(MANPAGES_IN)'
	  HTMLTARGET='html dirhtml'
	  AC_PATH_PROGS([PDFLATEX], [pdflatex], [])
	  AC_PATH_PROGS([LATEXMK], [latexmk], [])
	  AS_IF([test -n "$PDFLATEX" && test -n "$LATEXMK"],[
		    PDFTARGET='pdf'
		])
      ])
AC_SUBST([HTMLTARGET])
AC_SUBST([PDFTARGET])
AC_SUBST([MANSRCS])

#
# Look for Doxygen
#
AC_PATH_PROGS([DOXYGEN], [doxygen])
AC_SUBST(DOXYGEN)

#
# Look for curl
#

AC_PATH_PROG(CURL, curl, curl)
AC_SUBST(CURL)

#
# Look for xsltproc
#

AC_PATH_PROG(XSLTPROC, xsltproc, xsltproc)
AC_SUBST(XSLTPROC)

#
# IDN support using libidn2
#

LIBIDN2_CFLAGS=
LIBIDN2_LDFLAGS=
LIBIDN2_LIBS=

# [pairwise: --with-libidn2=yes, --without-libidn2]
AC_ARG_WITH([libidn2],
	    [AS_HELP_STRING([--with-libidn2[=PATH]], [enable IDN support using GNU libidn2 [yes|no(default)|path]])],
	    [with_libidn2="$withval"], [with_libidn2="no"])
AS_CASE([$with_libidn2],
	[yes],	[PKG_CHECK_MODULES([LIBIDN2], [libidn2],
				   [AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])])],
	[no],	[],
	[*],	[AX_SAVE_FLAGS([libidn2])
		 LIBIDN2_CFLAGS="-I$with_libidn2/include"
		 LIBIDN2_LDFLAGS="-L$with_libidn2/lib"
		 CFLAGS="$LIBIDN2_CFLAGS $CFLAGS"
		 CPPFLAGS="$LIBIDN2_CFLAGS $CPPFLAGS"
		 LDFLAGS="$LIBIDN2_LDFLAGS $LDFLAGS"
		 AC_CHECK_HEADERS([idn2.h],
				  [],
				  [AC_MSG_ERROR([idn2.h not found])])
		 AC_SEARCH_LIBS([idn2_to_ascii_lz], [idn2],
				[LIBIDN2_LIBS="$ac_cv_search_idn2_to_ascii_lz"
				 AC_DEFINE([HAVE_LIBIDN2], [1], [Define if libidn2 was found])],
				[AC_MSG_ERROR([libidn2 requested, but not found])])
		AX_RESTORE_FLAGS([libidn2])])
AC_SUBST([LIBIDN2_CFLAGS])
AC_SUBST([LIBIDN2_LDFLAGS])
AC_SUBST([LIBIDN2_LIBS])

#
# Check whether to build with cmocka unit testing framework
#
# [pairwise: --with-cmocka=detect, --with-cmocka=yes, --without-cmocka]
AC_ARG_WITH([cmocka],
	    [AS_HELP_STRING([--with-cmocka=detect],[enable CMocka based tests (default is detect)])],
	    [],[with_cmocka=detect])

AS_CASE([$with_cmocka],
	[no],[],
	[detect],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
				    [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])
				     with_cmocka=yes],[with_cmocka=no])],
	[yes],[PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.3],
				 [AC_DEFINE([HAVE_CMOCKA], [1], [Use CMocka])])],
	[AC_MSG_ERROR([Use PKG_CONFIG_PATH to specify path to CMocka library])]
       )
AC_SUBST([CMOCKA_CFLAGS])
AC_SUBST([CMOCKA_LIBS])

AC_DEFINE([SKIPPED_TEST_EXIT_CODE], [0], [Exit code for skipped tests])

#
# Check for kyua execution engine if CMocka was requested
# and bail out if execution engine was not found
#
AC_ARG_VAR([KYUA], [path to kyua execution engine])
AS_IF([test "$with_cmocka" != "no"],
      [AC_PATH_PROGS([KYUA], [kyua], [])
       AS_IF([test -z "$KYUA"],
             [AC_MSG_WARN([kyua test execution engine not found])],
             [UNITTESTS=tests])])
AC_SUBST([KYUA])
AC_SUBST([UNITTESTS])

#
# Check for -Wl,--wrap= support
#

LD_WRAP_TESTS=false
AC_MSG_CHECKING([for linker support for --wrap option])
AX_SAVE_FLAGS([wrap])
LDFLAGS="-Wl,--wrap,exit"
AC_LINK_IFELSE(
    [AC_LANG_PROGRAM([[#include <stdlib.h>
		       void __real_exit (int status);
		       void __wrap_exit (int status) { __real_exit (0); }
		      ]],
		     [[exit (1);]])],
    [LD_WRAP_TESTS=true
     AC_DEFINE([LD_WRAP], [1], [define if the linker supports --wrap option])
     AC_MSG_RESULT([yes])],
    [AC_MSG_RESULT([no])])
AX_RESTORE_FLAGS([wrap])

AC_SUBST([LD_WRAP_TESTS])

#
# Check for i18n
#
AC_CHECK_HEADERS(locale.h)
AC_CHECK_FUNCS(setlocale)

#
# was --with-tuning specified?
#
# [pairwise: --with-tuning=small, --without-tuning]
AC_ARG_WITH([tuning],
	    AS_HELP_STRING([--with-tuning=ARG],
			   [Specify server tuning (default or small)]),
	    [],[with_tuning=no])

AS_CASE([$with_tuning],
	[small],[AC_MSG_NOTICE(using small system tuning)],
	[AC_DEFINE(TUNE_LARGE, 1, [Define to use default system tuning.])
	 AC_MSG_NOTICE(using default system tuning)])

#
# was --enable-querytrace specified?
#
# [pairwise: --enable-querytrace, --disable-querytrace]
AC_ARG_ENABLE(querytrace,
	      AS_HELP_STRING([--enable-querytrace],
			     [enable very verbose query trace logging
				[default=no]]),
	      want_querytrace="$enableval", want_querytrace="no")

AC_MSG_CHECKING([whether to enable query trace logging])
case "$want_querytrace" in
yes)
	AC_MSG_RESULT(yes)
	AC_DEFINE(WANT_QUERYTRACE, 1, [Define to enable very verbose query trace logging.])
	;;
no)
	AC_MSG_RESULT(no)
	;;
*)
	AC_MSG_ERROR("--enable-querytrace requires yes or no")
	;;
esac

#
# Was --disable-auto-validation specified?
#

validation_default=auto

# [pairwise: --enable-auto-validation, --disable-auto-validation]
AC_ARG_ENABLE(auto-validation,
	      AS_HELP_STRING([--enable-auto-validation],
			     [turn on DNSSEC validation by default, using the IANA root key [default=yes]]),
	      [:],[enable_auto_validation=yes])
AS_IF([test "$enable_auto_validation" = "no"],[validation_default=yes])
AC_DEFINE_UNQUOTED([VALIDATION_DEFAULT], ["$validation_default"], [the default value of dnssec-validation option])

#
# Substitutions
#
AC_SUBST(BIND9_TOP_BUILDDIR)
BIND9_TOP_BUILDDIR=`pwd`

AC_SUBST(BIND9_ISC_BUILDINCLUDE)
AC_SUBST(BIND9_ISCCC_BUILDINCLUDE)
AC_SUBST(BIND9_ISCCFG_BUILDINCLUDE)
AC_SUBST(BIND9_DNS_BUILDINCLUDE)
AC_SUBST(BIND9_NS_BUILDINCLUDE)
AC_SUBST(BIND9_BIND9_BUILDINCLUDE)
AC_SUBST(BIND9_IRS_BUILDINCLUDE)
if test "X$srcdir" != "X"; then
	BIND9_ISC_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isc/include"
	BIND9_ISCCC_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isccc/include"
	BIND9_ISCCFG_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/isccfg/include"
	BIND9_DNS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/dns/include"
	BIND9_NS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/ns/include"
	BIND9_BIND9_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/bind9/include"
	BIND9_IRS_BUILDINCLUDE="-I${BIND9_TOP_BUILDDIR}/lib/irs/include"
else
	BIND9_ISC_BUILDINCLUDE=""
	BIND9_ISCCC_BUILDINCLUDE=""
	BIND9_ISCCFG_BUILDINCLUDE=""
	BIND9_DNS_BUILDINCLUDE=""
	BIND9_NS_BUILDINCLUDE=""
	BIND9_BIND9_BUILDINCLUDE=""
	BIND9_IRS_BUILDINCLUDE=""
fi

AC_SUBST_FILE(BIND9_MAKE_INCLUDES)
BIND9_MAKE_INCLUDES=$BIND9_TOP_BUILDDIR/make/includes

AC_SUBST_FILE(BIND9_MAKE_RULES)
BIND9_MAKE_RULES=$BIND9_TOP_BUILDDIR/make/rules

. "$srcdir/version"
BIND9_PRODUCT="PRODUCT=\"${PRODUCT}\""
AC_SUBST(BIND9_PRODUCT)
BIND9_DESCRIPTION="DESCRIPTION=\"${DESCRIPTION}\""
AC_SUBST(BIND9_DESCRIPTION)
BIND9_VERSION="${MAJORVER}.${MINORVER}${PATCHVER:+.}${PATCHVER}${RELEASETYPE}${RELEASEVER}${EXTENSIONS}"
AC_SUBST(BIND9_VERSION)
BIND9_MAJOR="MAJOR=${MAJORVER}.${MINORVER}"
AC_SUBST(BIND9_MAJOR)
BIND9_VERSIONSTRING="${PRODUCT} ${MAJORVER}.${MINORVER}${PATCHVER:+.}${PATCHVER}${RELEASETYPE}${RELEASEVER}${EXTENSIONS}${DESCRIPTION:+ }${DESCRIPTION}"
AC_SUBST(BIND9_VERSIONSTRING)

BIND9_SRCID="SRCID=unset_id"
if test -f "${srcdir}/srcid"; then
	. "${srcdir}/srcid"
	BIND9_SRCID="SRCID=$SRCID"
elif test -d "${srcdir}/.git"; then
	BIND9_SRCID="SRCID="`(cd "${srcdir}";git rev-parse --short HEAD)`
fi

AC_SUBST(BIND9_SRCID)

if test -z "$ac_configure_args"; then
	BIND9_CONFIGARGS="defaults"
else
	for a in $ac_configure_args
	do
		BIND9_CONFIGARGS="$BIND9_CONFIGARGS $a"
	done
fi
BIND9_CONFIGARGS="`echo $BIND9_CONFIGARGS | sed 's/^ //'`"
BIND9_CONFIGARGS="CONFIGARGS=${BIND9_CONFIGARGS}"
AC_SUBST(BIND9_CONFIGARGS)

AC_SUBST_FILE(LIBDNS_MAPAPI)
LIBDNS_MAPAPI="$srcdir/lib/dns/mapapi"

#
# Configure any DLZ drivers.
#
# If config.dlz.in selects one or more DLZ drivers, it will set
# CONTRIB_DLZ to a non-empty value, which will be our clue to
# build DLZ drivers in contrib.
#
# This section has to come after the libtool stuff because it needs to
# know how to name the driver object files.
#

CONTRIB_DLZ=""
DLZ_DRIVER_INCLUDES=""
DLZ_DRIVER_LIBS=""
DLZ_DRIVER_SRCS=""
DLZ_DRIVER_OBJS=""
DLZ_SYSTEM_TEST=""
DLZ_DRIVER_MYSQL_INCLUDES=""
DLZ_DRIVER_MYSQL_LIBS=""

#
# Configure support for building a shared library object
#
# Even when libtool is available it can't always be relied upon
# to build an object that can be dlopen()'ed, but this is necessary
# for building the dlzexternal system test, so we'll try it the
# old-fashioned way.
#
SO="so"
SO_CFLAGS=""
SO_LDFLAGS=""
SO_LD=""
SO_TARGETS=""
SO_STRIP="cat"

# [pairwise: skip]
AC_ARG_WITH([dlopen],
	    AS_HELP_STRING([--with-dlopen=ARG],
			   [support dynamically loadable DLZ and DYNDB drivers]),
	    [], [with_dlopen="auto"])


#
# If PIC is disabled, dlopen must also be
#
AS_IF([test "$pic_mode" = "no"],
      [AS_CASE([$with_dlopen],
	       [auto],[with_dlopen="no"],
	       [yes],[AC_MSG_ERROR([--with-dlopen requires PIC])])])

AS_CASE([$with_dlopen],
	[auto|yes],[
	  # -fsanitize=thread hijacks dlopen and dlclose so use dlsym.
	  AC_SEARCH_LIBS([dlsym],[dl])
	  AC_CHECK_FUNCS([dlopen dlclose dlsym],
			 [with_dlopen="yes"],
			 [with_dlopen="no"])
	])

AS_IF([test "$with_dlopen" = "yes"],
      [AS_CASE([$host],
	       [*-linux*|*-gnu*],[
		 LDFLAGS="${LDFLAGS} -Wl,--export-dynamic"
		 SO_CFLAGS="-fPIC"
		 SO_LDFLAGS=""
		 AS_IF([test "$use_libtool" = "yes"],[
			 SO_LDFLAGS="-Xcompiler -shared"
			 SO_LD="${CC}"
		       ],[
			 SO_LDFLAGS="-shared"
			 SO_LD="${CC}"
		       ])
	       ],
	       [*-freebsd*|*-openbsd*|*-netbsd*],[
		 LDFLAGS="${LDFLAGS} -Wl,-E"
		 SO_CFLAGS="-fpic"
		 AS_IF([test "$use_libtool" = "yes"],[
			 SO_LDFLAGS="-Xcompiler -shared"
			 SO_LD="${CC}"
		       ],[
			 SO_LDFLAGS="-shared"
			 SO_LD="${CC}"
		       ])
	       ],
	       [*-darwin*],[
		 SO_CFLAGS="-fPIC"
                 SO_LD="${CC}"
		 AS_IF([test "$use_libtool" = "yes"],[
			 SO_LDFLAGS="-Xcompiler -dynamiclib -undefined dynamic_lookup"
		       ],[
			 SO_LDFLAGS="-dynamiclib -undefined dynamic_lookup"
		       ])
	       ],
	       [*-solaris*],[
		 SO_CFLAGS="-KPIC"
		 SO_LDFLAGS="-G -z text"
		 SO_LD="ld"
	       ],
	       [ia64-hp-hpux*],[
		 SO_CFLAGS="+z"
	         SO_LDFLAGS="-b"
		 SO_LD="${CC}"
	       ],
	       [
		 SO_CFLAGS="-fPIC"
	       ])
       AS_IF([test "$GCC" = "yes"],[
	       SO_CFLAGS="-fPIC"
	       AS_IF([test -z "$SO_LD"],
		     [AS_IF([test "$use_libtool" = "yes"],[
			      SO_LDFLAGS="-Xcompiler -shared"
			      SO_LD="${CC}"
			    ],[
			      SO_LDFLAGS="-shared"
			      SO_LD="${CC}"
			    ])
		     ])
	     ])
       # If we still don't know how to make shared objects, don't make any.
       AS_IF([test -n "$SO_LD"],
	     [SO_TARGETS="\${SO_TARGETS}"
	      AC_DEFINE([ISC_DLZ_DLOPEN], [1],
			[Define to allow building of objects for dlopen().])
	     ])
      ])

AS_IF([test "$with_dlopen" = "no" -a "$enable_native_pkcs11" = "yes"],
      [AC_MSG_ERROR([PKCS11 requires dlopen() support])])

CFLAGS="$CFLAGS $SO_CFLAGS"

AC_SUBST(SO)
AC_SUBST(SO_CFLAGS)
AC_SUBST(SO_LDFLAGS)
AC_SUBST(SO_LD)
AC_SUBST(SO_STRIP)
AC_SUBST(SO_TARGETS)

#
# Response policy rewriting using DNS Response Policy Service (DNSRPS)
# interface.
#
# DNSRPS can be compiled into BIND everywhere with a reasonably
# modern C compiler.  It is enabled on systems with dlopen() and librpz.so.
#
dnsrps_avail=yes
AC_MSG_CHECKING([for librpz __attribute__s])
AC_COMPILE_IFELSE(
  [AC_LANG_PROGRAM(
     [[]],
     [[
       extern void f(char *p __attribute__((unused)), ...)
       __attribute__((format(printf,1,2))) __attribute__((__noreturn__));
     ]])],
  [
    librpz_have_attr=yes
    AC_DEFINE([LIBRPZ_HAVE_ATTR], [1], [have __attribute__s used in librpz.h])
    AC_MSG_RESULT([yes])
  ],[
    librpz_have_attr=no
    AC_MSG_RESULT([no])
  ])

# DNSRPS builds are included in pairwise testing along --enable-native-pkcs11
# tests above as both of these features require --with-dlopen (see also the
# relevant comment there).
#
# [pairwise: skip]
AC_ARG_ENABLE([dnsrps-dl],
	      [AS_HELP_STRING([--enable-dnsrps-dl],
			      [DNS Response Policy Service delayed link
			       [default=$librpz_dl]])],
	      [enable_librpz_dl="$enableval"], [enable_librpz_dl="$with_dlopen"])

AS_IF([test "$enable_librpz_dl" = "yes" -a "$with_dlopen" = "no"],
      [AC_MSG_ERROR([DNS Response Policy Service delayed link requires dlopen to be enabled])])

# [pairwise: skip]
AC_ARG_WITH([dnsrps-libname],
	    [AS_HELP_STRING([--with-dnsrps-libname],
			    [DNSRPS provider library name (librpz.so)])],
	    [librpz_name="$withval"], [librpz_name="librpz.so"])

# [pairwise: skip]
AC_ARG_WITH([dnsrps-dir],
	    [AS_HELP_STRING([--with-dnsrps-dir],
			    [path to DNSRPS provider library])],
	    [librpz_path="$withval/$librpz_name"], [librpz_path="$librpz_name"])
AC_DEFINE_UNQUOTED([DNSRPS_LIBRPZ_PATH], ["$librpz_path"],
		   [dnsrps $librpz_name])
AS_IF([test "$enable_librpz_dl" = "yes"],
      [
	dnsrps_lib_open=2
      ],[
	dnsrps_lib_open=1
	# Add librpz.so to linked libraries if we are not using dlopen()
	AC_SEARCH_LIBS([librpz_client_create], [rpz], [],
		[dnsrps_lib_open=0
		 dnsrps_avail=no])
      ])
AC_DEFINE_UNQUOTED([DNSRPS_LIB_OPEN], [$dnsrps_lib_open],
		   [0=no DNSRPS  1=static link  2=dlopen()])

# [pairwise: skip]
AC_ARG_ENABLE([dnsrps],
	      AS_HELP_STRING([--enable-dnsrps],
			     [enable DNS Response Policy Service API]),
	      [enable_dnsrps=$enableval], [enable_dnsrps=no])

AS_IF([test "$enable_dnsrps" != "no"],[
	AS_IF([test "$dnsrps_avail" != "yes"],
	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
	AS_IF([test "$dnsrps_lib_open" = "0"],
	      [AC_MSG_ERROR([dlopen and librpz.so needed for DNSRPS])])
	AC_DEFINE([USE_DNSRPS], [1], [Enable DNS Response Policy Service API])
      ])

sinclude(contrib/dlz/config.dlz.in)
AC_MSG_CHECKING(contributed DLZ drivers)

#
# Support for constructor and destructor attributes
#
AX_GCC_FUNC_ATTRIBUTE([constructor])
AX_GCC_FUNC_ATTRIBUTE([destructor])

if test -n "$CONTRIB_DLZ"
then
	AC_MSG_RESULT(yes)
	DLZ_DRIVER_RULES=contrib/dlz/drivers/rules
	AC_CONFIG_FILES([$DLZ_DRIVER_RULES
		contrib/dlz/modules/mysql/Makefile
		contrib/dlz/modules/mysqldyn/Makefile])
else
	AC_MSG_RESULT(no)
	DLZ_DRIVER_RULES=/dev/null
fi

AC_SUBST(CONTRIB_DLZ)
AC_SUBST(DLZ_DRIVER_INCLUDES)
AC_SUBST(DLZ_DRIVER_LIBS)
AC_SUBST(DLZ_DRIVER_SRCS)
AC_SUBST(DLZ_DRIVER_OBJS)
AC_SUBST(DLZ_SYSTEM_TEST)
AC_SUBST(DLZ_DRIVER_MYSQL_INCLUDES)
AC_SUBST(DLZ_DRIVER_MYSQL_LIBS)
AC_SUBST_FILE(DLZ_DRIVER_RULES)

if test "yes" = "$cross_compiling"; then
	if test -z "$BUILD_CC"; then
		AC_MSG_ERROR([BUILD_CC not set])
	fi
	BUILD_CFLAGS="$BUILD_CFLAGS"
	BUILD_CPPFLAGS="$BUILD_CPPFLAGS"
	BUILD_LDFLAGS="$BUILD_LDFLAGS"
	BUILD_LIBS="$BUILD_LIBS"
else
	BUILD_CC="$CC"
	BUILD_CFLAGS="$CFLAGS"
	BUILD_CPPFLAGS="$CPPFLAGS $GEN_NEED_OPTARG"
	BUILD_LDFLAGS="$LDFLAGS"
	BUILD_LIBS="$LIBS"
fi

NEWFLAGS=""
for e in $BUILD_LDFLAGS ; do
    case $e in
	-L*)
	    case $host_os in
		netbsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		freebsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		solaris*)
		    ee=`echo $e | sed -e 's%^-L%-R%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		*)
		    NEWFLAGS="$NEWFLAGS $e"
		    ;;
		esac
	    ;;
	*)
	    NEWFLAGS="$NEWFLAGS $e"
	    ;;
    esac
done
BUILD_LDFLAGS="$NEWFLAGS"

NEWFLAGS=""
for e in $DNS_GSSAPI_LIBS ; do
    case $e in
	-L*)
	    case $host_os in
		netbsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		freebsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		solaris*)
		    ee=`echo $e | sed -e 's%^-L%-R%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		*)
		    NEWFLAGS="$NEWFLAGS $e"
		    ;;
		esac
	    ;;
	*)
	    NEWFLAGS="$NEWFLAGS $e"
	    ;;
    esac
done
DNS_GSSAPI_LIBS="$NEWFLAGS"

NEWFLAGS=""
for e in $ISC_OPENSSL_LIBS ; do
    case $e in
	-L*)
	    case $host_os in
		netbsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		freebsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		solaris*)
		    ee=`echo $e | sed -e 's%^-L%-R%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		*)
		    NEWFLAGS="$NEWFLAGS $e"
		    ;;
		esac
	    ;;
	*)
	    NEWFLAGS="$NEWFLAGS $e"
	    ;;
    esac
done
ISC_OPENSSL_LIBS="$NEWFLAGS"

NEWFLAGS=""
for e in $DNS_CRYPTO_LIBS ; do
    case $e in
	-L*)
	    case $host_os in
		netbsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		freebsd*)
		    ee=`echo $e | sed -e 's%^-L%-Wl,-rpath,%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		solaris*)
		    ee=`echo $e | sed -e 's%^-L%-R%'`
		    NEWFLAGS="$NEWFLAGS $e $ee"
		    ;;
		*)
		    NEWFLAGS="$NEWFLAGS $e"
		    ;;
		esac
	    ;;
	*)
	    NEWFLAGS="$NEWFLAGS $e"
	    ;;
    esac
done
DNS_CRYPTO_LIBS="$NEWFLAGS"

AC_SUBST(BUILD_CC)
AC_SUBST(BUILD_CFLAGS)
AC_SUBST(BUILD_CPPFLAGS)
AC_SUBST(BUILD_LDFLAGS)
AC_SUBST(BUILD_LIBS)

#
# Commands to run at the end of config.status.
# Don't just put these into configure, it won't work right if somebody
# runs config.status directly (which autoconf allows).
#

AC_CONFIG_COMMANDS(
	[chmod],
	[chmod a+x doc/doxygen/doxygen-input-filter])

#
# Files to configure.  These are listed here because we used to
# specify them as arguments to AC_OUTPUT.  It's (now) ok to move these
# elsewhere if there's a good reason for doing so.
#

AC_CONFIG_FILES([
	Makefile
	bin/Makefile
	bin/check/Makefile
	bin/confgen/Makefile
	bin/confgen/unix/Makefile
	bin/delv/Makefile
	bin/dig/Makefile
	bin/dnssec/Makefile
	bin/named/Makefile
	bin/named/unix/Makefile
	bin/nsupdate/Makefile
	bin/pkcs11/Makefile
	bin/plugins/Makefile
	bin/python/Makefile
	bin/python/dnssec-checkds.py
	bin/python/dnssec-coverage.py
	bin/python/dnssec-keymgr.py
	bin/python/isc/Makefile
	bin/python/isc/__init__.py
	bin/python/isc/checkds.py
	bin/python/isc/coverage.py
	bin/python/isc/dnskey.py
	bin/python/isc/eventlist.py
	bin/python/isc/keydict.py
	bin/python/isc/keyevent.py
	bin/python/isc/keymgr.py
	bin/python/isc/keyseries.py
	bin/python/isc/keyzone.py
	bin/python/isc/policy.py
	bin/python/isc/rndc.py
	bin/python/isc/tests/Makefile
	bin/python/isc/tests/dnskey_test.py
	bin/python/isc/tests/policy_test.py
	bin/python/isc/utils.py
	bin/rndc/Makefile
	bin/tests/Makefile
	bin/tests/headerdep_test.sh
	bin/tests/optional/Makefile
	bin/tests/pkcs11/Makefile
	bin/tests/pkcs11/benchmarks/Makefile
	bin/tests/system/Makefile
	bin/tests/system/conf.sh
	bin/tests/system/dlzexternal/Makefile
	bin/tests/system/dlzexternal/ns1/dlzs.conf
	bin/tests/system/dyndb/Makefile
	bin/tests/system/dyndb/driver/Makefile
	bin/tests/system/pipelined/Makefile
	bin/tests/system/rndc/Makefile
	bin/tests/system/rpz/Makefile
	bin/tests/system/rsabigexponent/Makefile
	bin/tests/system/tkey/Makefile
	bin/tools/Makefile
	contrib/scripts/check-secure-delegation.pl
	contrib/scripts/zone-edit.sh
	doc/Makefile
	doc/arm/Makefile
	doc/doxygen/Doxyfile
	doc/doxygen/Makefile
	doc/doxygen/doxygen-input-filter
	doc/man/Makefile
	doc/misc/Makefile
	fuzz/Makefile
	lib/Makefile
	lib/bind9/Makefile
	lib/bind9/include/Makefile
	lib/bind9/include/bind9/Makefile
	lib/dns/Makefile
	lib/dns/include/Makefile
	lib/dns/include/dns/Makefile
	lib/dns/include/dst/Makefile
	lib/dns/tests/Makefile
	lib/irs/Makefile
	lib/irs/include/Makefile
	lib/irs/include/irs/Makefile
	lib/irs/include/irs/netdb.h
	lib/irs/include/irs/platform.h
	lib/irs/tests/Makefile
	lib/isc/Makefile
	lib/isc/include/Makefile
	lib/isc/include/isc/Makefile
	lib/isc/include/isc/platform.h
	lib/isc/include/pk11/Makefile
	lib/isc/include/pkcs11/Makefile
	lib/isc/netmgr/Makefile
	lib/isc/pthreads/Makefile
	lib/isc/pthreads/include/Makefile
	lib/isc/pthreads/include/isc/Makefile
	lib/isc/tests/Makefile
	lib/isc/unix/Makefile
	lib/isc/unix/include/Makefile
	lib/isc/unix/include/isc/Makefile
	lib/isccc/Makefile
	lib/isccc/include/Makefile
	lib/isccc/include/isccc/Makefile
	lib/isccc/tests/Makefile
	lib/isccfg/Makefile
	lib/isccfg/include/Makefile
	lib/isccfg/include/isccfg/Makefile
	lib/isccfg/tests/Makefile
	lib/ns/Makefile
	lib/ns/include/Makefile
	lib/ns/include/ns/Makefile
	lib/ns/tests/Makefile
	make/Makefile
	make/mkdep
	unit/unittest.sh
	util/check-make-install
])

#
# Do it
#

AC_OUTPUT

#
# Now that the Makefiles exist we can ensure that everything is rebuilt.
#
# [pairwise: --with-make-clean, --without-make-clean]
AC_ARG_WITH(make-clean,
	    AS_HELP_STRING([--with-make-clean],
			   [run "make clean" at end of configure [yes|no]]),
    make_clean="$withval", make_clean="yes")
case "$make_clean" in
yes)
	if test "yes" != "$no_create"
	then
		if test "yes" = "$silent"
		then
			make clean > /dev/null
		else
			make clean
		fi
	fi
	;;
esac

# [pairwise: --enable-full-report, --disable-full-report]
AC_ARG_ENABLE(full-report,
	      AS_HELP_STRING([--enable-full-report],
			     [report values of all configure options]))

report() {
    echo "==============================================================================="
    echo "Configuration summary:"
    echo "-------------------------------------------------------------------------------"
    echo "Optional features enabled:"
    if test "yes" = "$enable_full_report" -o "standard" = "$with_locktype"; then
	echo "    Mutex lock type: $with_locktype"
    fi
    test "small" = "$with_tuning" && echo "    Small-system tuning (--with-tuning)"
    test "no" = "$use_dnstap" || \
	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
    test -z "$MAXMINDDB_LIBS" || echo "    GeoIP2 access control (--enable-geoip)"
    test "no" = "$use_gssapi" || echo "    GSS-API (--with-gssapi)"

    # these lines are only printed if run with --enable-full-report
    if test "yes" = "$enable_full_report"; then
	test "no" = "$found_ipv6" || echo "    IPv6 support (--enable-ipv6)"
	test "X$PYTHON" = "X" || echo "    Python tools (--with-python)"
	test "X$LIBXML2_LIBS" = "X" || echo "    XML statistics (--with-libxml2)"
	test "X$JSON_C_LIBS" = "X" || echo "    JSON statistics (--with-json-c): $JSON_C_CFLAGS $JSON_C_LIBS"
	test "X$ZLIB_LIBS" = "X" || echo "    HTTP zlib compression (--with-zlib)"
	test "X$NZD_TOOLS" = "X" || echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
	test "no" = "$with_libidn2" || echo "    IDN support (--with-libidn2)"
    fi

    test "yes" = "$enable_dnsrps" && \
	echo "    DNS Response Policy Service interface (--enable-dnsrps)"
    test "yes" = "$enable_fixed" && \
	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"
    test "yes" = "$enable_backtrace" && \
	echo "    Print backtrace on crash (--enable-backtrace)"
    test "minimal" = "$want_symtable" && \
	echo "    Use symbol table for backtrace, named only (--enable-symtable)"
    test "yes" = "$want_symtable" -o "all" = "$want_symtable" && \
	echo "    Use symbol table for backtrace, all binaries (--enable-symtable=all)"
    test "no" = "$use_libtool" || echo "    Use GNU libtool (--with-libtool)"
    test "yes" = "$want_querytrace" && \
	echo "    Very verbose query trace logging (--enable-querytrace)"
    test "no" = "$with_cmocka" || echo "    CMocka Unit Testing Framework (--with-cmocka)"

    test "auto" = "$validation_default" && echo "    DNSSEC validation active by default (--enable-auto-validation)"

    test "$CRYPTO" = "pkcs11" && (
	echo "    Using PKCS#11 for Public-Key Cryptography (--with-native-pkcs11)"
	echo "    PKCS#11 module (--with-pkcs11): $with_pkcs11"
	echo "    +--------------------------------------------+"
	echo "    |             ==== WARNING ====              |"
	echo "    |                                            |"
	echo "    | The use of native PKCS#11 for Public-Key   |"
	echo "    | Cryptography in BIND 9 has been deprecated |"
	echo "    | in favor of OpenSSL engine_pkcs11 from the |"
	echo "    | OpenSC project. The --with-native-pkcs11   |"
	echo "    | configuration option will be removed from  |"
	echo "    | the next major BIND 9 release. The option  |"
	echo "    | to use the engine_pkcs11 OpenSSL engine is |"
	echo "    | already available in BIND 9; please see    |"
	echo "    | the ARM section on PKCS#11 for details.    |"
	echo "    +--------------------------------------------+"
    )

    dlz_enabled=no

    echo "    Dynamically loadable zone (DLZ) drivers:"
    AS_IF([test "$use_dlz_bdb" != "no"],
	  [AS_ECHO(["        Berkeley DB (--with-dlz-bdb)"])
	   dlz_enabled=yes])
    AS_IF([test "$use_dlz_ldap" != "no"],
	  [AS_ECHO(["        LDAP (--with-dlz-ldap)"])
	   dlz_enabled=yes])
    AS_IF([test "$use_dlz_mysql" != "no"],
	  [AS_ECHO(["        MySQL (--with-dlz-mysql)"])
	   dlz_enabled=yes])
    AS_IF([test "$use_dlz_odbc" != "no"],
	  [AS_ECHO(["        ODBC (--with-dlz-odbc)"])
	   dlz_enabled=yes])
    AS_IF([test "$use_dlz_postgres" != "no"],
	  [AS_ECHO(["        Postgres (--with-dlz-postgres)"])
	   dlz_enabled=yes])
    AS_IF([test "$use_dlz_filesystem" != "no"],
	  [AS_ECHO(["        Filesystem (--with-dlz-filesystem)"])
	   dlz_enabled=yes])
    AS_IF([test "$use_dlz_stub" != "no"],
	  [AS_ECHO(["        Stub (--with-dlz-stub)"])
	   dlz_enabled=yes])

    AS_IF([test "$dlz_enabled" = "no"],
	  [AS_ECHO(["        None"])],
	  [AS_ECHO(["    +--------------------------------------------------------+"])
	   AS_ECHO(["    |             ==== DEPRECATION WARNING ====              |"])
	   AS_ECHO(["    +--------------------------------------------------------+"])
	   AS_ECHO(["    | Old-style DLZ drivers have been deprecated in favor of |"])
	   AS_ECHO(["    | DLZ modules. The DLZ drivers configuration option will |"])
	   AS_ECHO(["    | be removed from the next major BIND 9 release.         |"])
	   AS_ECHO(["    |                                                        |"])
	   AS_ECHO(["    | The option to use the DLZ modules is already available |"])
	   AS_ECHO(["    | in BIND 9; please see the ARM section on DLZ modules.  |"])
	   AS_ECHO(["    +--------------------------------------------------------+"])
	  ])

    echo "-------------------------------------------------------------------------------"

    echo "Features disabled or unavailable on this platform:"
    test "no" = "$found_ipv6" && echo "    IPv6 support (--enable-ipv6)"
    test "small" = "$with_tuning" || echo "    Small-system tuning (--with-tuning)"

    test "no" = "$use_dnstap" && \
	    echo "    Allow 'dnstap' packet logging (--enable-dnstap)"
    test -z "$MAXMINDDB_LIBS" && echo "    GeoIP2 access control (--enable-geoip)"
    test "no" = "$use_gssapi" && echo "    GSS-API (--with-gssapi)"

    test "no" = "$enable_dnsrps" && \
	echo "    DNS Response Policy Service interface (--enable-dnsrps)"

    test "yes" = "$enable_fixed" || \
	echo "    Allow 'fixed' rrset-order (--enable-fixed-rrset)"

    test "yes" = "$validation_default" && echo "    DNSSEC validation requires configuration (--enablee-auto-validation)"

    test "$CRYPTO" = "pkcs11" || (
	echo "    Using PKCS#11 for Public-Key Cryptography (--with-native-pkcs11)"
    )

    test "yes" = "$enable_backtrace" || \
	echo "    Print backtrace on crash (--enable-backtrace)"
    test "yes" = "$want_querytrace" || \
	echo "    Very verbose query trace logging (--enable-querytrace)"

    test "yes" = "$use_libtool" || echo "    Use GNU libtool (--with-libtool)"
    test "no" = "$with_cmocka" && echo "    CMocka Unit Testing Framework (--with-cmocka)"

    test "X$PYTHON" = "X" && echo "    Python tools (--with-python)"
    test "X$LIBXML2_LIBS" = "X" && echo "    XML statistics (--with-libxml2)"
    test "X$JSON_C_LIBS" = "X" && echo "    JSON statistics (--with-json-c)"
    test "X$ZLIB_LIBS" = "X" && echo "    HTTP zlib compression (--with-zlib)"
    test "X$NZD_TOOLS" = "X" && echo "    LMDB database to store configuration for 'addzone' zones (--with-lmdb)"
    test "no" = "$with_libidn2" && echo "    IDN support (--with-libidn2)"

    echo "-------------------------------------------------------------------------------"
    echo "Configured paths:"
    echo "    prefix: $prefix"
    echo "    sysconfdir: $sysconfdir"
    echo "    localstatedir: $localstatedir"
    echo "-------------------------------------------------------------------------------"
    echo "Compiler: $CC"
    AS_IF([test "$GCC" = "yes"],
	  [$CC --version 2>&1 | sed 's/^/    /'],
	  [AS_CASE([$host],
		   [*-solaris*],[$CC -V 2>&1 | sed 's/^/    /'],
		   [$CC --version 2>&1 | sed 's/^/    /'])])

    if test "X$ac_unrecognized_opts" != "X"; then
	echo "Unrecognized options:"
	echo "    $ac_unrecognized_opts"
    fi

    if test "yes" != "$enable_full_report"; then
	echo "-------------------------------------------------------------------------------"
	echo "For more detail, use --enable-full-report."
    fi
    echo "==============================================================================="
}

if test "yes" != "$silent"; then
	report
fi

# Tell Emacs to edit this file in shell mode.
# Local Variables:
# mode: sh
# End: