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
#!/usr/bin/perl
#
# 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.

# Configure
#
# This script builds nmake and visual studio build files
#

require 5.000;
use strict;
use File::Spec;
use Cwd;

# files to configure

my $configfile = "..\\config.h";
my $platformfile = "..\\lib\\isc\\win32\\include\\isc\\platform.h";
my $confshfile = "..\\bin\\tests\\system\\conf.sh";

my @filelist = ("..\\bin\\python\\dnssec-checkds.py",
                "..\\bin\\python\\dnssec-coverage.py",
                "..\\bin\\python\\dnssec-keymgr.py",
                "..\\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\\dnskey_test.py",
                "..\\bin\\python\\isc\\tests\\policy_test.py",
                "..\\bin\\python\\isc\\utils.py",
                "..\\lib\\dns\\win32\\libdns.def",
                "..\\lib\\isc\\win32\\libisc.def");

my @projectlist = ("..\\bin\\check\\win32\\checkconf.vcxproj",
                   "..\\bin\\check\\win32\\checkconf.vcxproj.filters",
                   "..\\bin\\check\\win32\\checktool.vcxproj",
                   "..\\bin\\check\\win32\\checktool.vcxproj.filters",
                   "..\\bin\\check\\win32\\checkzone.vcxproj",
                   "..\\bin\\check\\win32\\checkzone.vcxproj.filters",
                   "..\\bin\\confgen\\win32\\confgentool.vcxproj",
                   "..\\bin\\confgen\\win32\\confgentool.vcxproj.filters",
                   "..\\bin\\confgen\\win32\\ddnsconfgen.vcxproj",
                   "..\\bin\\confgen\\win32\\ddnsconfgen.vcxproj.filters",
                   "..\\bin\\confgen\\win32\\rndcconfgen.vcxproj",
                   "..\\bin\\confgen\\win32\\rndcconfgen.vcxproj.filters",
                   "..\\bin\\delv\\win32\\delv.vcxproj",
                   "..\\bin\\delv\\win32\\delv.vcxproj.filters",
                   "..\\bin\\dig\\win32\\dig.vcxproj",
                   "..\\bin\\dig\\win32\\dig.vcxproj.filters",
                   "..\\bin\\dig\\win32\\dighost.vcxproj",
                   "..\\bin\\dig\\win32\\dighost.vcxproj.filters",
                   "..\\bin\\dig\\win32\\host.vcxproj",
                   "..\\bin\\dig\\win32\\host.vcxproj.filters",
                   "..\\bin\\dig\\win32\\nslookup.vcxproj",
                   "..\\bin\\dig\\win32\\nslookup.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\cds.vcxproj",
                   "..\\bin\\dnssec\\win32\\cds.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\dnssectool.vcxproj",
                   "..\\bin\\dnssec\\win32\\dnssectool.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\dsfromkey.vcxproj",
                   "..\\bin\\dnssec\\win32\\dsfromkey.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\importkey.vcxproj",
                   "..\\bin\\dnssec\\win32\\importkey.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\keyfromlabel.vcxproj",
                   "..\\bin\\dnssec\\win32\\keyfromlabel.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\keygen.vcxproj",
                   "..\\bin\\dnssec\\win32\\keygen.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\revoke.vcxproj",
                   "..\\bin\\dnssec\\win32\\revoke.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\settime.vcxproj",
                   "..\\bin\\dnssec\\win32\\settime.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\signzone.vcxproj",
                   "..\\bin\\dnssec\\win32\\signzone.vcxproj.filters",
                   "..\\bin\\dnssec\\win32\\verify.vcxproj",
                   "..\\bin\\dnssec\\win32\\verify.vcxproj.filters",
                   "..\\bin\\named\\win32\\named.vcxproj",
                   "..\\bin\\named\\win32\\named.vcxproj.filters",
                   "..\\bin\\nsupdate\\win32\\nsupdate.vcxproj",
                   "..\\bin\\nsupdate\\win32\\nsupdate.vcxproj.filters",
                   "..\\bin\\pkcs11\\win32\\pk11destroy.vcxproj",
                   "..\\bin\\pkcs11\\win32\\pk11destroy.vcxproj.filters",
                   "..\\bin\\pkcs11\\win32\\pk11keygen.vcxproj",
                   "..\\bin\\pkcs11\\win32\\pk11keygen.vcxproj.filters",
                   "..\\bin\\pkcs11\\win32\\pk11list.vcxproj",
                   "..\\bin\\pkcs11\\win32\\pk11list.vcxproj.filters",
                   "..\\bin\\pkcs11\\win32\\pk11tokens.vcxproj",
                   "..\\bin\\pkcs11\\win32\\pk11tokens.vcxproj.filters",
                   "..\\bin\\rndc\\win32\\rndc.vcxproj",
                   "..\\bin\\rndc\\win32\\rndc.vcxproj.filters",
                   "..\\bin\\rndc\\win32\\rndcutil.vcxproj",
                   "..\\bin\\rndc\\win32\\rndcutil.vcxproj.filters",
                   "..\\bin\\tools\\win32\\arpaname.vcxproj",
                   "..\\bin\\tools\\win32\\arpaname.vcxproj.filters",
                   "..\\bin\\tools\\win32\\journalprint.vcxproj",
                   "..\\bin\\tools\\win32\\journalprint.vcxproj.filters",
                   "..\\bin\\tools\\win32\\mdig.vcxproj",
                   "..\\bin\\tools\\win32\\mdig.vcxproj.filters",
                   "..\\bin\\tools\\win32\\nsec3hash.vcxproj",
                   "..\\bin\\tools\\win32\\nsec3hash.vcxproj.filters",
                   "..\\bin\\tools\\win32\\rrchecker.vcxproj",
                   "..\\bin\\tools\\win32\\rrchecker.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\bigkey.vcxproj",
                   "..\\bin\\tests\\system\\win32\\bigkey.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\feature-test.vcxproj",
                   "..\\bin\\tests\\system\\win32\\feature-test.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\gencheck.vcxproj",
                   "..\\bin\\tests\\system\\win32\\gencheck.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\keycreate.vcxproj",
                   "..\\bin\\tests\\system\\win32\\keycreate.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\keydelete.vcxproj",
                   "..\\bin\\tests\\system\\win32\\keydelete.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\pipequeries.vcxproj",
                   "..\\bin\\tests\\system\\win32\\pipequeries.vcxproj.filters",
                   "..\\bin\\tests\\system\\win32\\resolve.vcxproj",
                   "..\\bin\\tests\\system\\win32\\resolve.vcxproj.filters",
                   "..\\bin\\tests\\win32\\backtrace_test.vcxproj",
                   "..\\bin\\tests\\win32\\backtrace_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\inter_test.vcxproj",
                   "..\\bin\\tests\\win32\\inter_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\makejournal.vcxproj",
                   "..\\bin\\tests\\win32\\makejournal.vcxproj.filters",
                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj",
                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj",
                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\sock_test.vcxproj",
                   "..\\bin\\tests\\win32\\sock_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\task_test.vcxproj",
                   "..\\bin\\tests\\win32\\task_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\timer_test.vcxproj",
                   "..\\bin\\tests\\win32\\timer_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\inter_test.vcxproj",
                   "..\\bin\\tests\\win32\\inter_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj",
                   "..\\bin\\tests\\win32\\rwlock_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj",
                   "..\\bin\\tests\\win32\\shutdown_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\sock_test.vcxproj",
                   "..\\bin\\tests\\win32\\sock_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\task_test.vcxproj",
                   "..\\bin\\tests\\win32\\task_test.vcxproj.filters",
                   "..\\bin\\tests\\win32\\timer_test.vcxproj",
                   "..\\bin\\tests\\win32\\timer_test.vcxproj.filters",
                   "..\\bin\\win32\\BINDInstall\\BINDInstall.vcxproj",
                   "..\\bin\\win32\\BINDInstall\\BINDInstall.vcxproj.filters",
                   "..\\lib\\bind9\\win32\\libbind9.vcxproj",
                   "..\\lib\\bind9\\win32\\libbind9.vcxproj.filters",
                   "..\\lib\\dns\\win32\\gen.vcxproj",
                   "..\\lib\\dns\\win32\\gen.vcxproj.filters",
                   "..\\lib\\dns\\win32\\libdns.vcxproj",
                   "..\\lib\\dns\\win32\\libdns.vcxproj.filters",
                   "..\\lib\\irs\\win32\\libirs.vcxproj",
                   "..\\lib\\irs\\win32\\libirs.vcxproj.filters",
                   "..\\lib\\isc\\win32\\libisc.vcxproj",
                   "..\\lib\\isc\\win32\\libisc.vcxproj.filters",
                   "..\\lib\\isccc\\win32\\libisccc.vcxproj",
                   "..\\lib\\isccc\\win32\\libisccc.vcxproj.filters",
                   "..\\lib\\isccfg\\win32\\libisccfg.vcxproj",
                   "..\\lib\\isccfg\\win32\\libisccfg.vcxproj.filters",
                   "..\\lib\\ns\\win32\\libns.vcxproj",
                   "..\\lib\\win32\\bindevt\\bindevt.vcxproj",
                   "..\\lib\\win32\\bindevt\\bindevt.vcxproj.filters",
                   "bind9.sln");

# for config.h

my %configdefh;

my @substdefh = ("CONFIGARGS",
                 "DNS_RDATASET_FIXED",
                 "HAVE_GEOIP2",
                 "HAVE_LIBXML2",
                 "USE_BACKTRACE",
                 "USE_OPENSSL",
                 "USE_PKCS11",
                 "HAVE_READLINE",
                 "HAVE_ZLIB",
                 "ISC_LIST_CHECKINIT",
                 "TUNE_LARGE",
                 "WANT_QUERYTRACE",
                 "WITH_IDN",
                 "CPU_RELAX",
                 "VALIDATION_DEFAULT",
    );

# for platform.h

my %configdefp;

my @substdefp = ();

# for conf.sh

my %configtest;

my @substtest = ("CHECKDS",
                 "COVERAGE",
                 "CRYPTO",
                 "DNSTAP",
                 "FSTRM_CAPTURE",
                 "JSONSTATS",
                 "KEYMGR",
                 "NZD_TOOLS",
                 "XMLSTATS",
                 "ZLIB"),

# includes

my %configinc;

my @substinc = ("GSSAPI_INC",
                "GEOIP_INC",
                "IDN_INC",
                "LIBXML2_INC",
                "LIBUV_INC",
                "OPENSSL_INC",
                "READLINE_INC",
                "ZLIB_INC");

# libraries

my %configlib;

my @substlib = ("GSSAPI_LIB",
                "GEOIP_LIB",
                "IDN_LIB",
                "KRB5_LIB",
                "LIBXML2_LIB",
                "LIBUV_LIB",
                "OPENSSL_LIBCRYPTO",
                "OPENSSL_LIBSSL",
                "READLINE_LIB",
                "READLINE_LIBD",
                "ZLIB_LIB");

# DLLs

my %configdll;

my @substdll = ("COMERR_DLL",
                "GSSAPI_DLL",
                "ICONV_DLL",
                "IDN_DLL",
                "KRB5_DLL",
                "K5SPRT_DLL",
                "LIBXML2_DLL",
                "LIBUV_DLL",
                "OPENSSL_DLLCRYPTO",
                "OPENSSL_DLLSSL",
                "WSHELP_DLL",
                "ZLIB_DLL");

# variables

my %configvar = (
	"TOOLS_VERSION" => "4.0",
);

my @substvar = ("BIND9_VERSION",
                "BUILD_MACHINE",
                "BUILD_PLATFORM",
                "COPTI",
                "COPTML",
                "COPTMLD",
                "COPTX",
                "COPTY",
                "DLZ_SYSTEM_TEST",
                "EXEEXT",
                "expanded_sysconfdir",
                "INTRINSIC",
                "MACHINE",
                "OPENSSL_PATH",
                "PLATFORM",
                "PKCS11_TOOLS",
                "PLATFORM_TOOLSET",
                "prefix",
                "PSSUSPEND",
                "PYTHON",
                "PYTHON_INSTALL_DIR",
                "TOOLS_VERSION",
                "VCREDIST_PATH",
                "WINDOWS_TARGET_PLATFORM_VERSION"),

# defines

my %configdefd;

my @substdefd = ("PK11_LIB_LOCATION",
                 "USE_GSSAPI",
                 "USE_PYTHON");

# conditions

my %configcond;

my @substcond = ("ATOMIC",
                 "GSSAPI",
                 "GEOIP",
                 "IDNKIT",
                 "LIBXML2",
                 "OPENSSL",
                 "PKCS11",
                 "PYTHON",
                 "STESTS",
                 "TESTS",
                 "XTESTS",
                 "ZLIB");

my @allcond = (@substcond, "NOTYET", "NOLONGER");

# arguments

# enable-xxx/disable-xxx

my @enablelist = ("developer",
                  "fixed-rrset",
                  "intrinsics",
                  "native-pkcs11",
                  "openssl-hash",
                  "querytrace");

# with-xxx/without-xxx

my @withlist = ("aes",
                "cross-compile",
                "extra-tests",
                "gssapi",
                "geoip2",
                "iconv",
                "idn",
                "openssl",
                "libxml2",
                "pkcs11",
                "pssuspend",
                "python",
                "readline",
                "system-tests",
                "tests",
                "tuning",
                "libuv",
                "vcredist",
                "zlib");

# general arguments

my @optionlist = ("help", "verbose", "legacy", "win32", "x64", "clean");

# usage

my @usage = ("Usage: perl Configure help\n",
             "       perl Configure options* win32|x64\n",
             "       perl Configure clean\n");

# help

my @help = (
"'Configure' configures BIND9 build files.\n\n",
@usage,
"\nGeneral Options and Commands:\n",
"  verbose               (options) print messages\n",
"  help                  (command) print this help\n",
"  win32                 (command) configure for Win32 platform\n",
"  x64                   (command) configure for x64 platform\n",
"  clean                 (command) clean up generated files\n",
"  <none>                (command) print a summary of the configuration\n",
"\nOptional Features:\n",
"  enable-intrinsics     enable intrinsic/atomic functions [default=yes]\n",
"  enable-native-pkcs11  use native PKCS#11 for all crypto [default=no]\n",
"  enable-openssl-hash   use OpenSSL for hash functions [default=yes]\n",
"  enable-fixed-rrset    enable fixed rrset ordering [default=no]\n",
"  enable-developer      enable developer build settings [default=no]\n",
"  enable-querytrace     enable very verbose query trace [default=no]\n",
"\nOptional Packages:\n",
"  with-tests            build with test suite\n",
"  with-extra-tests      build with extra test suite\n",
"  with-system-tests     build with system test suite\n",
"  with-openssl[=PATH]   build with OpenSSL yes|path (mandatory)\n",
"  with-libuv[=PATH]     build with libuv yes|path (mandatory)\n",
"  with-pkcs11[=PATH]    build with PKCS#11 support yes|no|provider-path\n",
"  with-gssapi[=PATH]    build with MIT KfW GSSAPI yes|no|path\n",
"  with-libxml2[=PATH]   build with libxml2 library yes|no|path\n",
"  with-geoip2[=PATH]    build with GeoIP2 support yes|no|path\n",
"  with-pssuspend[=COMMAND] specify pssuspend command\n",
"  with-python[=COMMAND] specify python interpreter python|command\n",
"  with-readline[=PATH]  build with readline library support yes|no|path\n",
"  with-idn[=PATH]       build with IDN kit support yes|no|path\n",
"  with-iconv[=PATH]     path of the iconv DLL [default=same than idn]\n",
"  with-zlib[=PATH]      build with zlib library yes|no|path\n",
"  with-vcredist[=PATH]  visual C++ redistributable package yes|path\n",
"  with-tuning=OPTION    tune for platform size (small|default)\n",
"  with-cross-compile    32 / 64 bit build / host platforms\n",
"\nOptional Visual Studio project parameters:\n",
"  with-tools-version=VERSION     set the ToolsVersion attribute to VERSION\n",
"  with-platform-toolset=VERSION  use supplied toolset VERSION for building\n",
"  with-platform-version=VERSION  use supplied Windows SDK VERSION for building\n");

# Parse arguments

my $verbose = 0;
my $legacy_only = 0;
my $want_help = "no";
my $want_win32 = "no";
my $want_x64 = "no";
my $want_clean = "no";
my $want_unknown = "no";
my $unknown_value;
my $enable_intrinsics = "yes";
my $cryptolib = "";
my $enable_native_pkcs11 = "no";
my $enable_crypto_rand = "yes";
my $enable_fixed_rrset = "no";
my $enable_developer = "no";
my $enable_querytrace = "no";
my $enable_rpz_nsip = "yes";
my $enable_rpz_nsdname = "yes";
my $use_tests = "no";
my $use_xtests = "no";
my $use_stests = "no";
my $use_libuv = "auto";
my $libuv_path = "..\\..\\";
my $use_openssl = "auto";
my $openssl_path = "..\\..\\";
my $use_pkcs11 = "no";
my $pkcs11_path = "unknown";
my $use_aes = "auto";
my $use_gssapi = "no";
my $validation_default = "auto";
my $gssapi_path = "C:\\Program\ Files\\MIT\\Kerberos\\";
my $use_geoip2 = "no";
my $geoip2_path = "";
my $use_libxml2 = "auto";
my $libxml2_path = "..\\..\\";
my $with_pssuspend = "no";
my $pssuspend_command = "pssuspend.exe";
my $use_python = "auto";
my $python_command = "python.exe";
my $use_readline = "no";
my $readline_path = "..\\..\\";
my $use_idn = "no";
my $idn_path = "..\\..\\";
my $iconv_path = " --idn-- ";
my $use_zlib = "no";
my $zlib_path = "..\\..\\";
my $use_vcredist = "yes";
my $vcredist_path = " --infer-- ";
my $cross_compile = "no";
my $tuning = "default";
my $want_checkfiles = "no";

# no arguments -> usage

if ($#ARGV < 0) {
    foreach (@usage) {
        print $_;
    }
    exit 1;
}

# parse arguments

foreach (@ARGV) {
    if (/^verbose$/i) {
        $verbose = 1;
    } elsif (/^help$/i) {
        $want_help = "yes";
    } elsif (/^disable-(.*)$/i) {
        appargs($_);
        myenable($1, "no");
    } elsif (/^enable-(.*)$/i) {
        appargs($_);
        myenable($1, "yes");
    } elsif (/^without-(.*)$/i) {
        appargs($_);
        mywith($1, "no");
    } elsif (/^with-(.*)=(.*)$/i) {
        appargs($_);
        mywith($1, $2);
    } elsif (/^with-(.*)$/i) {
        appargs($_);
        mywith($1, "yes");
    } elsif (/^legacy$/i) {
        $legacy_only = 1;
    } elsif (/^win32$/i) {
        $want_win32 = "yes";
    } elsif (/^x64$/i) {
        appargs($_);
        $want_x64 = "yes";
    } elsif (/^clean$/i) {
        $want_clean = "yes";
    } elsif (/^checkfiles$/i) {
        $want_checkfiles = "yes";
    } else {
        $want_unknown = "yes";
        $unknown_value = $_;
    }
}

# old legacy mode

if ($legacy_only) {
    print "legacy mode is obsolete (so ignored)\n";
}

if ($want_checkfiles eq "yes") {
        my $status=0;
        foreach (@filelist) {
                my $name = $_;
                $name =~ s/\\/\\\\/g;
                next if -r $_ . ".in";
                s/\\/\//g;
                next if -r $_ . ".in";
                print "remove '$name' from filelist in win32utils/Configure or add to repository\n";
                $status = 1;
        }
        foreach (@projectlist) {
                my $name = $_;
                $name =~ s/\\/\\\\/g;
                next if -r $_ . ".in";
                s/\\/\//g;
                next if -r $_ . ".in";
                print "remove '$name' from projectlist in win32utils/Configure or add to repository\n";
                $status = 1;
        }
        exit($status);
}

# configure the platform

if (($want_win32 eq "yes") && ($want_x64 eq "yes")) {
    die "can't ask for both Win32 and x64 platforms\n";
} elsif ($want_win32 eq "yes") {
    $configvar{"PLATFORM"} = "Win32";
    $configvar{"BUILD_PLATFORM"} = "Win32";
    $configvar{"MACHINE"} = "/machine:X86";
    $configvar{"BUILD_MACHINE"} = "/machine:X86";
} elsif ($want_x64 eq "yes") {
    $configvar{"PLATFORM"} = "x64";
    $configvar{"BUILD_PLATFORM"} = "x64";
    $configvar{"MACHINE"} = "/machine:X64";
    $configvar{"BUILD_MACHINE"} = "/machine:X64";
}
# Standard configure variable
$configvar{"EXEEXT"} = ".exe";

# get the version information

my %Versions;

sub getversion {
    my $data;
    my $name;
    my $value;
    my $version;

    open V, "..\\version" || die $!;
    while (<V>) {
        chomp;
        ($data) = split(/\#/);
        if ($data) {
            ($name, $value) = split(/=/, $data);
            ($name) = split(/\s+/, $name);
            if ($name eq 'PRODUCT' || $name eq 'DESCRIPTION') {
                ($value) =~ s/^["\s]+//;
                ($value) =~ s/["\s]+$//;
            } else {
                ($value) = split(/\s+/, $value);
            }
            $Versions{$name} = $value;
        }
    }
    close V;

    $version = "$Versions{'MAJORVER'}.$Versions{'MINORVER'}";
    if ($Versions{'PATCHVER'} ne "") {
        $version = "$version.$Versions{'PATCHVER'}";
    }
    $version = "$version$Versions{'RELEASETYPE'}$Versions{'RELEASEVER'}";
    $version = "$version$Versions{'EXTENSIONS'}";
    $configvar{"BIND9_VERSION"} = "$version";
}

getversion();

# append seen args to CONFIGARGS define

sub appargs {
    my $arg = $_[0];
    # escape backslashes and double quotes
    $arg =~ s/([\\"])/\\$1/g;
    $arg =~ s/([\s])/\\\\$1/g;
    if (defined($configdefh{"CONFIGARGS"})) {
        $configdefh{"CONFIGARGS"} .= " " . $arg;
    } else {
        $configdefh{"CONFIGARGS"} = $arg;
    }
}

if (!$configdefh{"CONFIGARGS"}) {
    # CONFIGARGS default is "default"
    $configdefh{"CONFIGARGS"} = "\"default\"";
} else {
    my $val = $configdefh{"CONFIGARGS"};
    $configdefh{"CONFIGARGS"} = "\"'$val'\"";
}

# parse enable/disable

sub myenable {
    my $key = $_[0];
    my $val = $_[1];

    if ($key =~ /^intrinsics$/i) {
        if ($val =~ /^no$/i) {
            $enable_intrinsics = "no";
        }
    } elsif ($key =~ /^native-pkcs11$/i) {
        if ($val =~ /^yes$/i) {
            $enable_native_pkcs11 = "yes";
        }
    } elsif ($key =~ /^fixed-rrset$/i) {
        if ($val =~ /^yes$/i) {
            $enable_fixed_rrset = "yes";
        }
    } elsif ($key =~ /^developer$/i) {
        if ($val =~ /^yes$/i) {
            $enable_developer = "yes";
        }
    } elsif ($key =~ /^querytrace$/i) {
        if ($val =~ /^yes$/i) {
            $enable_querytrace = "yes";
        }
    } elsif ($key =~ /^auto-validation$/i) {
        if ($val =~ /^no$/i) {
            $validation_default = "yes";
        }
    } else {
        $want_unknown = "yes";
        if ($val eq "no") {
            $unknown_value = "disable-" . $key;
        } else {
            $unknown_value = "enable-". $key;
        }
    }
}

# enable-developer expansion now

if ($enable_developer eq "yes") {
    $configdefh{"ISC_LIST_CHECKINIT"} = 1;
    $enable_querytrace = "yes";
    # no atf on WIN32
    $enable_fixed_rrset = "yes";
    # TODO: dlz filesystem
    $use_tests = "yes";
    $use_xtests = "yes";
    $use_stests = "yes";
}

# parse with/without

sub mywith {
    my $key = $_[0];
    my $val = $_[1];

    if ($key =~ /^tests$/i) {
        if ($val =~ /^yes$/i) {
            $use_tests = "yes";
        }
    } elsif ($key =~ /^extra-tests$/i) {
        if ($val =~ /^yes$/i) {
            $use_tests = "yes";
            $use_xtests = "yes";
        }
    } elsif ($key =~ /^system-tests$/i) {
        if ($val =~ /^yes$/i) {
            $use_tests = "yes";
            $use_stests = "yes";
        }
    } elsif ($key =~ /^openssl$/i) {
        if ($val =~ /^no$/i) {
            die "OpenSSL support is now mandatory\n";
        } elsif ($val !~ /^yes$/i) {
            $use_openssl = "yes";
            $openssl_path = $val;
        }
    } elsif ($key =~ /^libuv$/i) {
        if ($val =~ /^no$/i) {
            die "libuv is required\n";
        } elsif ($val !~ /^yes$/i) {
            $use_libuv = "yes";
            $libuv_path = $val;
        }
    } elsif ($key =~ /^pkcs11$/i) {
        if ($val =~ /^yes$/i) {
            $use_pkcs11 = "yes";
        } elsif ($val !~ /^no$/i) {
            $use_pkcs11= "yes";
            $pkcs11_path = $val;
            $pkcs11_path =~ s/\.dll$//i;
        }
    } elsif ($key =~ /^aes$/i) {
        if ($val =~ /^no$/i) {
            $use_aes = "no";
        } elsif ($val =~ /^yes$/i) {
            $use_aes = "yes";
        }
    } elsif ($key =~ /^gssapi$/i) {
        if ($val !~ /^no$/i) {
            $use_gssapi = "yes";
            if ($val !~ /^yes$/i) {
                $gssapi_path = $val;
            }
        }
    } elsif ($key =~ /^libxml2$/i) {
        if ($val =~ /^no$/i) {
            $use_libxml2 = "no";
        } elsif ($val !~ /^yes$/i) {
            $use_libxml2 = "yes";
            $libxml2_path = $val;
        }
    } elsif ($key =~ /^geoip2$/i) {
        if ($val !~ /^no$/i) {
            $use_geoip2 = "yes";
            if ($val !~ /^yes$/i) {
                $geoip2_path = $val;
            } else {
                $geoip2_path = "..\\..\\GeoIP2";
            }
        }
    } elsif ($key =~ /^readline$/i) {
        if ($val !~ /^no$/i) {
            $use_readline = "yes";
            if ($val !~ /^yes$/i) {
                $readline_path = $val;
            }
        }
    } elsif ($key =~ /^idn$/i) {
        if ($val !~ /^no$/i) {
            $use_idn = "yes";
            if ($val !~ /^yes$/i) {
                $idn_path = $val;
            }
        }
    } elsif ($key =~ /^iconv$/i) {
        if ($val =~ /^no$/i) {
            $want_unknown = "yes";
            $unknown_value = "without-iconv doesn't make sense)";
        } elsif ($val !~ /^yes$/i) {
            $iconv_path = $val;
        }
    } elsif ($key =~ /^zlib$/i) {
        if ($val !~ /^no$/i) {
            $use_zlib = "yes";
            if ($val !~ /^yes$/i) {
                $zlib_path = $val;
            }
        }
    } elsif ($key =~ /^pssuspend$/i) {
        if ($val =~ /^no$/i) {
            $with_pssuspend = "no";
        } else {
            if ($val !~ /^yes$/i) {
                $pssuspend_command = $val;
            }
        }
    } elsif ($key =~ /^python$/i) {
        if ($val =~ /^no$/i) {
            $use_python = "no";
        } else {
            $use_python = "yes";
            if ($val !~ /^yes$/i) {
                $python_command = $val;
            }
        }
    } elsif ($key =~ /^vcredist$/i) {
        if ($val =~ /^no$/i) {
            $want_unknown = "yes";
            $unknown_value = "without-vcredist (vcredist is required)";
        } elsif ($val !~ /^yes$/i) {
            $vcredist_path = $val;
        }
    } elsif ($key =~ /^cross-compile$/i) {
        if ($val =~ /^yes$/i) {
            $cross_compile = "yes";
        }
    } elsif ($key =~ /^tuning$/i) {
        if ($val =~ /^small$/i) {
            $tuning = "small";
        }
    } elsif ($key =~ /^tools-version$/i) {
        $configvar{"TOOLS_VERSION"} = $val;
    } elsif ($key =~ /^platform-version$/i) {
        $configvar{"WINDOWS_TARGET_PLATFORM_VERSION"} = "<WindowsTargetPlatformVersion>$val</WindowsTargetPlatformVersion>";
    } elsif ($key =~ /^platform-toolset$/i) {
        $configvar{"PLATFORM_TOOLSET"} = "<PlatformToolset>$val</PlatformToolset>";
    } else {
        $want_unknown = "yes";
        if ($val eq "no") {
            $unknown_value = "without-" . $key;
        } else {
            $unknown_value = "with-" . $key;
        }
    }
}

if ($want_help ne "no") {
    foreach (@help) {
        print $_;
    }
    exit 1;
}

# clean up and exit if requested
if ($want_clean eq "yes") {
    my $file;

    unlink($configfile);
    unlink($platformfile);
    unlink($confshfile);

    foreach $file (@filelist) {
        unlink($file);
    }

    foreach $file (@projectlist) {
        unlink($file);
    }

    exit 0;
}

if ($want_unknown ne "no") {
    print STDERR "can't parse $unknown_value\n";
    exit 1;
}

if ($verbose) {
    if ($want_win32 eq "yes") {
        print "configure for win32\n";
    }
    if ($want_x64 eq "yes") {
        print "configure for x64\n";
    }
    if ($cross_compile eq "yes") {
        print "cross compiling";
        if ($want_x64 eq "yes") {
            print ": build on win32 for x64 host\n";
        } elsif ($want_win32 eq "yes") {
            print ": build on x64 for win32 host\n";
        } else {
            print "\n";
        }
    }
    if ($enable_intrinsics eq "yes") {
        print "intrinsics: enabled\n";
    } else {
        print "intrinsics: disabled\n";
    }
    if ($enable_native_pkcs11 eq "yes") {
        print "native-pkcs11: enabled\n";
    } else {
        print "native-pkcs11: disabled\n";
    }
    print "openssl-hash: enabled\n";
    if ($enable_fixed_rrset eq "yes") {
        print "fixed-rrset: enabled\n";
    } else {
        print "fixed-rrset: disabled\n";
    }
    if ($enable_developer eq "yes") {
        print "developer: enabled\n";
    } else {
        print "developer: disabled\n";
    }
    if ($enable_querytrace eq "yes") {
        print "querytrace: enabled\n";
    } else {
        print "querytrace: disabled\n";
    }
    print "libuv-path: $libuv_path\n";
    print "openssl-path: $openssl_path\n";
    if ($use_tests eq "yes") {
        print "tests: enabled\n";
    }
    if ($use_xtests eq "yes") {
        print "extra tests: enabled\n";
    }
    if ($use_stests eq "yes") {
        print "system tests: enabled\n";
    }
    if ($use_pkcs11 eq "no") {
        print "pkcs11: disabled\n";
    } else {
        print "pkcs11-provider-path: $pkcs11_path\n";
    }
    if ($use_aes eq "no") {
        print "aes: disabled\n";
    } else {
        print "aes: enabled\n";
    }
    if ($use_gssapi eq "no") {
        print "gssapi: disabled\n";
    } else {
        print "gssapi-path: $gssapi_path\n";
    }
    if ($use_libxml2 eq "no") {
        print "libxml2: disabled\n";
    } else {
        print "libxml2-path: $libxml2_path\n";
    }
    if ($use_geoip2 eq "no") {
        print "geoip2: disabled\n";
    } else {
        print "geoip2-path: $geoip2_path\n";
    }
    if ($use_readline eq "no") {
        print "readline: disabled\n";
    } else {
        print "readline-path: $readline_path\n";
    }
    if ($use_idn eq "no") {
        print "idn: disabled\n";
    } else {
        print "idn-path: $idn_path\n";
        if ($iconv_path ne " --idn-- ") {
            print "iconv-path: $iconv_path\n";
        }
    }
    if ($use_zlib eq "no") {
        print "zlib: disabled\n";
    } else {
        print "zlib-path: $zlib_path\n";
    }
    if ($with_pssuspend eq "no") {
        print "pssuspend: disabled\n";
    } else {
        print "pssuspend-command: $pssuspend_command\n";
    }
    if ($use_python eq "no") {
        print "python: disabled\n";
    } else {
        print "python-command: $python_command\n";
    }
    print "vcredist-path: $vcredist_path\n";
}

# Check environment

# infer vcredist when not given
if ($vcredist_path eq " --infer-- ") {
    if ($verbose) {
        print "trying to infer vcredist path from build environment\n";
    }

    my @vcpaths = {};
    push(@vcpaths, $ENV{"VCRedistPath"}) if ($ENV{"VCRedistPath"} ne "");
    push(@vcpaths, File::Spec->catfile( cwd(), "..", ".." ));

    if ($ENV{"FrameworkSDKDir"} ne "" && $want_win32 eq "yes") {
        push(@vcpaths, File::Spec->catfile($ENV{"FrameworkSDKDir"},
                                           "BootStrapper", "Packages",
                                           "vcredist_x86"));
    } elsif ($ENV{"FrameworkSDKDir"} ne "" && $want_x64 eq "yes") {
        push(@vcpaths, File::Spec->catfile($ENV{"FrameworkSDKDir"},
                                           "BootStrapper", "Packages",
                                           "vcredist_x64"));
    }

    if ($ENV{"WindowsSDKDir"} ne "" && $want_win32 eq "yes") {
        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir"},
                                           "BootStrapper", "Packages",
                                           "vcredist_x86"));
    } elsif ($ENV{"WindowsSDKDir"} ne "" && $want_x64 eq "yes") {
        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir"},
                                           "BootStrapper", "Packages",
                                           "vcredist_x64"));
    }

    if ($ENV{"WindowsSDKDir_old"} ne "" && $want_win32 eq "yes") {
        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir_old"},
                                           "BootStrapper", "Packages",
                                           "vcredist_x86"));
    } elsif ($ENV{"WindowsSDKDir_old"} ne "" && $want_x64 eq "yes") {
        push(@vcpaths, File::Spec->catfile($ENV{"WindowsSDKDir_old"},
                                           "BootStrapper", "Packages",
                                           "vcredist_x64"));
    }

    if ($ENV{"VCINSTALLDIR"}) {
        push(@vcpaths, File::Spec->catfile($ENV{"VCINSTALLDIR"},
                                           "redist", "1033"));
    }

    # 'VCToolsRedistDir' is available since Visual Studio 2017.
    if ($ENV{"VCToolsRedistDir"}) {
        push(@vcpaths, $ENV{"VCToolsRedistDir"});
    }

    my $rfile;
    if ($want_win32 eq "yes") {
        $rfile = "vcredist_x86.exe";
    } else {
        $rfile = "vcredist_x64.exe";
    }

    foreach (@vcpaths) {
        my $vp = File::Spec->catfile($_, $rfile);
        if (-f $vp) {
            $vcredist_path = $vp;
            last;
        }
    }

    if ($vcredist_path eq " --infer-- ") {
        die "with-vcredist is REQUIRED\n";
    }

    if ($verbose) {
        print "found vcredist at " . $vcredist_path . "\n";
    }
}

my $msc_ver = 0;

open F, ">mscver.c" || die $!;
print F << 'EOF';
#include <windows.h>
#include <stdio.h>

int
main(void)
{
        printf("%d\n", _MSC_VER);
        return(0);
}
EOF
close F;
my $compret = `cl /nologo /MD mscver.c`;
if (grep { -f and -x } ".\\mscver.exe") {
    $msc_ver = `.\\mscver.exe`;
} else {
    die "can't get _MSC_VER value: $compret\n";
}
if ($verbose) {
    print "_MSC_VER == $msc_ver\n";
}
if ($msc_ver < 1600) {
    print STDERR "too old version of C++ compiler/Visual Studio\n";
    exit 1;
}

# gen single threaded for < VS 2005

if ($msc_ver < 1400) {
    $configvar{"COPTML"} = "/ML";
    $configvar{"COPTMLD"} = "/MLD";
}

# /GX deprecated in VS 2005

if ($msc_ver < 1400) {
    $configvar{"COPTX"} = "/GX";
} else {
    $configvar{"COPTX"} = "/EHsc";
}

# /YX for < VS 2005

if ($msc_ver < 1400) {
    $configvar{"COPTY"} = "/YX";
}

# backtrace for >= VS 2012

if ($msc_ver >= 1700) {
    $configdefh{"USE_BACKTRACE"} = 1;
}

# warn when cross compiling

if ($cross_compile eq "yes") {
    if ($want_x64 eq "yes") {
        $configvar{"BUILD_PLATFORM"} = "Win32";
        $configvar{"BUILD_MACHINE"} = "/machine:X86";
    }
    if ($want_win32 eq "yes") {
        $configvar{"BUILD_PLATFORM"} = "x64";
        $configvar{"BUILD_MACHINE"} = "/machine:X64";
    }
} elsif ($want_win32 eq "yes") {
    open F, ">cross.c" || die $!;
    print F << 'EOF';
#include <windows.h>
#include <stdio.h>

int
main(void)
{
#ifdef _WIN64
        fprintf(stderr, "compiling for x64 when win32 was asked?!\n");
#endif
        return(0);
}
EOF
    close F;
    my $compret = `cl /nologo /MD cross.c`;
    if (grep { -f and -x } ".\\cross.exe") {
        my $cross = `.\\cross.exe`;
        if ($cross) {
            print STDERR $cross;
        }
    } else {
        print STDERR "can't check cross compile: $compret\n";
    }
} else {
    open F, ">cross.c" || die $!;
    print F << 'EOF';
#include <windows.h>
#include <stdio.h>

int
main(void)
{
#ifndef _WIN64
        fprintf(stderr, "compiling in 32 bits when x64 was asked?!\n");
#endif
        return(0);
}
EOF
    close F;
    my $compret = `cl /nologo /MD cross.c`;
    if (grep { -f and -x } ".\\cross.exe") {
        my $cross = `.\\cross.exe`;
        if ($cross) {
            print STDERR $cross;
        }
    } else {
        print STDERR "can't check cross compile: $compret\n";
    }
}

# Process arguments

# enable-native-pkcs11
if ($enable_native_pkcs11 eq "yes") {
    $cryptolib = "pkcs11";
    if ($use_pkcs11 ne "yes") {
        if ($verbose) {
            print "native PKCS#11 support: force with-pkcs11\n";
        }
        $use_pkcs11 = "yes";
    }
    if ($pkcs11_path eq "unknown") {
        if ($verbose) {
            print "native PKCS#11 support: no PKCS#11 provider defined?\n";
        }
    }
}

# enable-fixed-rrset
if ($enable_fixed_rrset eq "yes") {
    $configdefh{"DNS_RDATASET_FIXED"} = 1;
}

# enable-querytrace
if ($enable_querytrace eq "yes") {
    $configdefh{"WANT_QUERYTRACE"} = 1;
}

# with-tests
if ($use_tests eq "yes") {
    $configcond{"TESTS"} = 1;
}

# with-extra-tests
if ($use_xtests eq "yes") {
    $configcond{"XTESTS"} = 1;
}

# with-system-tests
if ($use_stests eq "yes") {
    $configcond{"STESTS"} = 1;
}

# with-libuv
if ($use_libuv eq "auto") {
    if ($verbose) {
        print "checking for an libuv built directory at sibling root\n";
    }
    opendir DIR, $libuv_path || die "No Directory: $!\n";
    my @dirlist = grep (/^libuv-v[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+){0,1}$/i,
                        readdir(DIR));
    closedir(DIR);

    # Make sure we have something
    if (scalar(@dirlist) == 0) {
        die "can't find an libuv at sibling root\n";
    }
    # Now see if we have a directory or just a file.
    # Make sure we are case insensitive
    my $file;
    foreach $file (sort {uc($b) cmp uc($a)} @dirlist) {
        if (-f File::Spec->catfile($libuv_path,
                                   $file,
                                   "include\\uv.h")) {
            $libuv_path = File::Spec->catdir($libuv_path, $file);
            $use_libuv = "yes";
            last;
        }
    }

    # If we have one use it otherwise report the error
    if ($use_libuv eq "auto") {
        die "can't find an libuv built directory at sibling root\n";
    }
}
# falls into (so no else)
if ($use_libuv eq "yes") {
    $libuv_path = File::Spec->rel2abs($libuv_path);
    if ($verbose) {
        print "checking for libuv built directory at \"$libuv_path\"\n";
    }
    my $libuv_new = 0;
    if (!-f File::Spec->catfile($libuv_path,
                                "include\\uv.h")) {
        die "can't find libuv uv.h include\n";
    }
    my $libuv_inc = File::Spec->catdir($libuv_path, "include");
    my $libuv_libdir = File::Spec->catdir($libuv_path, "build\\Release");
    my $libuv_lib = File::Spec->catfile($libuv_libdir, "uv.lib");
    my $libuv_dll = File::Spec->catfile($libuv_libdir, "uv.dll");
    if (!-f $libuv_lib) {
       die "can't find uv.lib library\n";
    }
    if (!-f $libuv_dll) {
       die "can't find uv.dll library\n";
    }
    $configvar{"LIBUV_PATH"} = "$libuv_path";
    $configinc{"LIBUV_INC"} = "$libuv_inc";
    $configlib{"LIBUV_LIB"} = "$libuv_lib";
    $configdll{"LIBUV_DLL"} = "$libuv_dll";
}

# with-openssl
if ($use_openssl eq "auto") {
    if ($verbose) {
        print "checking for an OpenSSL built directory at sibling root\n";
    }
    opendir DIR, $openssl_path || die "No Directory: $!\n";
    my @dirlist = grep (/^openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]{0,1}$/i,
                        readdir(DIR));
    closedir(DIR);

    # Make sure we have something
    if (scalar(@dirlist) == 0) {
        die "can't find an OpenSSL at sibling root\n";
    }
    # Now see if we have a directory or just a file.
    # Make sure we are case insensitive
    my $file;
    foreach $file (sort {uc($b) cmp uc($a)} @dirlist) {
        if (-f File::Spec->catfile($openssl_path,
                                   $file,
                                   "inc32\\openssl\\opensslv.h")) {
            $openssl_path = File::Spec->catdir($openssl_path, $file);
            $use_openssl = "yes";
            last;
        }
        if (-f File::Spec->catfile($openssl_path,
                                   $file,
                                   "include\\openssl\\opensslv.h")) {
            $openssl_path = File::Spec->catdir($openssl_path, $file);
            $use_openssl = "yes";
            last;
        }
    }

    # If we have one use it otherwise report the error
    if ($use_openssl eq "auto") {
        die "can't find an OpenSSL built directory at sibling root\n";
    }
}
# falls into (so no else)
if ($use_openssl eq "yes") {
    my @dirlist;
    $openssl_path = File::Spec->rel2abs($openssl_path);
    if ($verbose) {
        print "checking for OpenSSL built directory at \"$openssl_path\"\n";
    }
    if (!-f File::Spec->catfile($openssl_path,
                                "include/openssl/opensslv.h")) {
	die "can't find OpenSSL 1.1 opensslv.h include\n";
    }
    my $openssl_inc = File::Spec->catdir($openssl_path, "include");
    my $openssl_libdir = $openssl_path;
    my $openssl_libcrypto = File::Spec->catfile($openssl_path, "libcrypto.lib");
    my $openssl_libssl = File::Spec->catfile($openssl_libdir, "libssl.lib");
    my $openssl_dllcrypto = File::Spec->catfile($openssl_libdir, "libcrypto.dll");
    my $openssl_dllssl = File::Spec->catfile($openssl_libdir, "libssl.dll");

    if (!-f $openssl_libcrypto) {
	die "can't find OpenSSL libcrypto.lib library\n";
    }
    opendir DIR, $openssl_path || die "No Directory: $!\n";
    @dirlist = grep (/^libcrypto-[^.]+\.dll$/i, readdir(DIR));
    closedir(DIR);
    # We must get one file only
    if (scalar(@dirlist) == 0) {
	die "can't find OpenSSL libcrypto-*.dll DLL\n";
    }
    if (scalar(@dirlist) != 1) {
	die "found more than one OpenSSL libcrypto-*.dll DLL candidate\n";
    }
    $openssl_dllcrypto = File::Spec->catdir($openssl_path, "$dirlist[0]");

    if (!-f $openssl_libssl) {
	die "can't find OpenSSL libssl.lib library\n";
    }
    opendir DIR, $openssl_path || die "No Directory: $!\n";
    @dirlist = grep (/^libssl-[^.]+\.dll$/i, readdir(DIR));
    closedir(DIR);
    # We must get one file only
    if (scalar(@dirlist) == 0) {
	die "can't find OpenSSL libssl-*.dll DLL\n";
    }
    if (scalar(@dirlist) != 1) {
	die "found more than one OpenSSL libssl-*.dll DLL candidate\n";
    }
    $openssl_dllssl = File::Spec->catdir($openssl_path, "$dirlist[0]");

    $cryptolib = "openssl";
    $configvar{"OPENSSL_PATH"} = "$openssl_path";
    $configinc{"OPENSSL_INC"} = "$openssl_inc";
    $configlib{"OPENSSL_LIBCRYPTO"} = "$openssl_libcrypto";
    $configdll{"OPENSSL_DLLCRYPTO"} = "$openssl_dllcrypto";
    $configlib{"OPENSSL_LIBSSL"} = "$openssl_libssl";
    $configdll{"OPENSSL_DLLSSL"} = "$openssl_dllssl";
}

if ($cryptolib eq "openssl") {
    $configdefh{"USE_OPENSSL"} = 1;
    $configtest{"CRYPTO"} = "OpenSSL";
} else {
    $configdefh{"USE_PKCS11"} = 1;
    $configtest{"CRYPTO"} = "pkcs11";
}

# check OpenSSL
if ($use_openssl eq "yes") {
#prepare the environment
    my $dll = $configdll{"OPENSSL_DLLCRYPTO"};
    my $ret = `copy "$dll" .`;
    if ($? != 0) {
        die "Can't copy OpenSSL DLL to working directory: $ret\n";
    }

    $dll = $configdll{"OPENSSL_DLLSSL"};
    $ret = `copy "$dll" .`;
    if ($? != 0) {
        die "Can't copy OpenSSL DLL to working directory: $ret\n";
    }

    my $include = $configinc{"OPENSSL_INC"};
    my $libcrypto = $configlib{"OPENSSL_LIBCRYPTO"};
    my $libssl = $configlib{"OPENSSL_LIBSSL"};

# check libcrypto
    if ($verbose) {
        print "checking whether linking with OpenSSL libcrypto works\n";
    }

    open F, ">testossl.c" || die $!;
    print F << 'EOF';
#include <openssl/err.h>

int
main(void)
{
        ERR_clear_error();
        return(0);
}
EOF
    close F;

    $compret = `cl /nologo /MD /I "$include" testossl.c "$libcrypto"`;
    if (grep { -f and -x } "./testossl.exe") {
        `./testossl.exe`;
        if ($? != 0) {
            die "OpenSSL libcrypto test failed\n";
        }
    } else {
        die "can't compile OpenSSL libcrypto test: $compret\n";
    }

    if ($verbose) {
	print "checking whether linking with OpenSSL libssl works\n";
    }

    open F, ">testossl.c" || die $!;
    print F << 'EOF';
#include <openssl/ssl.h>

int
main(void)
{
        SSL_CTX *ctx = SSL_CTX_new(SSLv23_method());
        SSL_CTX_free(ctx);
        return(0);
}
EOF
    close F;
    $compret = `cl /nologo /MD /I "$include" testossl.c "$libcrypto" "$libssl"`;
    if (grep { -f and -x } "./testossl.exe") {
        `./testossl.exe`;
        if ($? != 0) {
            die "OpenSSL libssl test failed\n";
        }
    } else {
        die "can't compile OpenSSL libssl test: $compret\n";
    }

# check OpenSSL version
    if ($verbose) {
        printf "checking OpenSSL library version\n";
    }
    open F, ">testosslv.c" || die $!;
    print F << 'EOF';
#include <stdio.h>
#include <openssl/opensslv.h>

int main() {
        if (OPENSSL_VERSION_NUMBER >= 0x10101000L) {
                return (0);
        }
        printf("\n\nFound   OPENSSL_VERSION_NUMBER %#010x\n",
               OPENSSL_VERSION_NUMBER);
        printf("Require OPENSSL_VERSION_NUMBER 0x10101000L or greater (1.1.1)\n\n");
        return (1);
}
EOF
    close F;

    $compret = `cl /nologo /MD /I "$include" testosslv.c "$libcrypto"`;
    if (grep { -f and -x } "./testosslv.exe") {
        `./testosslv.exe`;
        if ($? != 0) {
            die "OpenSSL version test failed\n";
        }
    } else {
        die "can't compile OpenSSL version test: $compret\n";
    }

    if ($verbose) {
        print "checking for OpenSSL Ed25519 support\n";
    }
    open F, ">tested25519.c" || die $!;
    print F << 'EOF';
#include <openssl/evp.h>
#include <openssl/objects.h>

int
main(void)
{
        EVP_PKEY_CTX *ctx;

        ctx = EVP_PKEY_CTX_new_id(NID_ED25519, NULL);
        if (ctx == NULL)
                return (2);
        return (0);
}
EOF
    close F;

    $compret = `cl /nologo /MD /I "$include" tested25519.c "$libcrypto"`;
    if (grep { -f and -x } "./tested25519.exe") {
        `./tested25519.exe`;
        if ($? == 0) {
            $configdefh{"HAVE_OPENSSL_ED25519"} = 1;
        } else {
            if ($verbose) {
                print "Ed25519 test failed: disabling Ed25519\n";
            }
        }
    } else {
        if ($verbose) {
            print "can't compile Ed25519 test: $compret\n";
            print "disabling Ed25519\n";
        }
    }

    if ($verbose) {
        print "checking for OpenSSL Ed448 support\n";
    }
    open F, ">tested448.c" || die $!;
    print F << 'EOF';
#include <openssl/evp.h>
#include <openssl/objects.h>

int
main(void)
{
        EVP_PKEY_CTX *ctx;

        ctx = EVP_PKEY_CTX_new_id(NID_ED448, NULL);
        if (ctx == NULL)
                return (2);
        return (0);
}
EOF
    close F;

    $compret = `cl /nologo /MD /I "$include" tested448.c "$libcrypto"`;
    if (grep { -f and -x } "./tested448.exe") {
        `./tested448.exe`;
        if ($? == 0) {
            $configdefh{"HAVE_OPENSSL_ED448"} = 1;
        } else {
            if ($verbose) {
                print "Ed448 test failed: disabling Ed448\n";
            }
        }
    } else {
        if ($verbose) {
            print "can't compile Ed448 test: $compret\n";
            print "disabling Ed448\n";
        }
    }
}

# with-aes
if ($use_openssl eq "no") {
    if ($use_aes ne "pkcs11") {
        $use_aes = "no";
    }
}

if ($cryptolib ne "") {
    print "Cryptographic library for DNSSEC: $cryptolib\n";
} else {
    die "No cryptography library has been found or provided."
}

# with-pkcs11
if ($use_pkcs11 ne "no") {
    $configcond{"PKCS11"} = 1;
    $configvar{"PKCS11_TOOLS"} = "pkcs11";
    $configdefd{"PK11_LIB_LOCATION"} = "PK11_LIB_LOCATION=\"$pkcs11_path\"";
}

# with-gssapi
if ($use_gssapi eq "no") {
    if ($verbose) {
        print "gssapi library is disabled\n";
    }
} else {
    $gssapi_path = File::Spec->rel2abs($gssapi_path);
    if ($verbose) {
        print "checking for gssapi directory at \"$gssapi_path\"\n";
    }
    $configcond{"GSSAPI"} = 1;
    $configdefd{"USE_GSSAPI"} = "GSSAPI";
    if (!-f File::Spec->catfile($gssapi_path, "include",
                                "gssapi", "gssapi.h")) {
        die "can't find gssapi.h include\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "include",
                                "gssapi", "gssapi_krb5.h")) {
        die "can't find gssapi_krb5.h include\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "include",
                                "krb5", "krb5.h")) {
        die "can't find krb5.h include\n";
    }
    $configinc{"GSSAPI_INC"} = File::Spec->catdir($gssapi_path, "include");
    my $bits = "32";
    my $gssapi_lib;
    my $krb5_lib;
    if ($want_win32 eq "yes") {
        $bits = "32";
        if (!-f File::Spec->catfile($gssapi_path, "lib", "i386",
                                    "gssapi${bits}.lib")) {
            die "can't find gssapi${bits}.lib library\n";
        }
        $gssapi_lib = File::Spec->catfile($gssapi_path, "lib", "i386",
                                          "gssapi${bits}.lib");
        if (!-f File::Spec->catfile($gssapi_path, "lib", "i386",
                                    "krb5_${bits}.lib")) {
            die "can't find krb5_${bits}.lib library\n";
        }
        $krb5_lib = File::Spec->catfile($gssapi_path, "lib", "i386",
                                             "krb5_${bits}.lib");
    } elsif ($want_x64 eq "yes") {
        $bits = "64";
        if (!-f File::Spec->catfile($gssapi_path, "lib", "amd64",
                                    "gssapi${bits}.lib")) {
            die "can't find gssapi${bits}.lib library\n";
        }
        $gssapi_lib = File::Spec->catfile($gssapi_path, "lib", "amd64",
                                             "gssapi${bits}.lib");
        if (!-f File::Spec->catfile($gssapi_path, "lib", "amd64",
                                    "krb5_${bits}.lib")) {
            die "can't find krb5_${bits}.lib library\n";
        }
        $krb5_lib = File::Spec->catfile($gssapi_path, "lib", "amd64",
                                        "krb5_${bits}.lib");
    } else {
        die "can't happen: no choice between Win32 and x64\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "bin", "gssapi${bits}.dll")) {
        die "can't find gssapi${bits}.dll DLL\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "bin", "krb5_${bits}.dll")) {
        die "can't find krb5_${bits}.dll DLL\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "bin", "comerr${bits}.dll")) {
        die "can't find comerr${bits}.dll DLL\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "bin", "k5sprt${bits}.dll")) {
        die "can't find k5sprt${bits}.dll DLL\n";
    }
    if (!-f File::Spec->catfile($gssapi_path, "bin", "wshelp${bits}.dll")) {
        die "can't find wshelp${bits}.dll DLL\n";
    }
    $configlib{"GSSAPI_LIB"} = "$gssapi_lib";
    $configlib{"KRB5_LIB"} = "$krb5_lib";
    my $gssapi_dll = File::Spec->catfile($gssapi_path, "bin",
                                         "gssapi${bits}.dll");
    $configdll{"GSSAPI_DLL"} = "$gssapi_dll";
    my $krb5_dll = File::Spec->catfile($gssapi_path, "bin",
                                         "krb5_${bits}.dll");
    $configdll{"KRB5_DLL"} = "$krb5_dll";
    my $comerr_dll = File::Spec->catfile($gssapi_path, "bin",
                                         "comerr${bits}.dll");
    $configdll{"COMERR_DLL"} = "$comerr_dll";
    my $k5sprt_dll = File::Spec->catfile($gssapi_path, "bin",
                                         "k5sprt${bits}.dll");
    $configdll{"K5SPRT_DLL"} = "$k5sprt_dll";
    my $wshelp_dll = File::Spec->catfile($gssapi_path, "bin",
                                         "wshelp${bits}.dll");
    $configdll{"WSHELP_DLL"} = "$wshelp_dll";
}

# disable-auto-validation
$configdefh{"VALIDATION_DEFAULT"} = "\"$validation_default\"";

# with-geoip2
if ($use_geoip2 eq "no") {
    if ($verbose) {
        print "geoip2 library is disabled\n";
    }
} else {
    $configcond{"GEOIP"} = 1;
    $geoip2_path = File::Spec->rel2abs($geoip2_path);
    if ($verbose) {
        print "checking for geoip2 directory at \"$geoip2_path\"\n";
    }
    if (!-f File::Spec->catfile($geoip2_path, "maxminddb.h")) {
        die "can't find maxminddb.h include\n";
    }
    if (!-f File::Spec->catfile($geoip2_path, "maxminddb_config.h")) {
        die "can't find maxminddb_config.h include\n";
    }
    if (!-f File::Spec->catfile($geoip2_path, "libmaxminddb.lib")) {
        die "can't find libmaxminddb.lib library\n";
    }
    $configinc{"GEOIP_INC"} = "$geoip2_path";
    my $geoip2_lib = File::Spec->catfile($geoip2_path, "libmaxminddb.lib");
    $configlib{"GEOIP_LIB"} = "$geoip2_lib";
    my $geoip_inc = qq(/I "$geoip2_path");
    my $geoip2_libs = qq("$geoip2_lib" Ws2_32.Lib);

    if ($verbose) {
        print "checking for GeoIP2 support\n";
    }
    open F, ">testgeoip2.c" || die $!;
    print F << 'EOF';
#include <maxminddb.h>
int main(void) {
       return MMDB_lib_version() != 0;
}
EOF
    close F;
    $compret = `cl /nologo $geoip_inc /MD testgeoip2.c $geoip2_libs`;
    if (grep { -f and -x } ".\\testgeoip2.exe") {
        `.\\testgeoip2.exe`;
        if ($? == 0) {
            die "GeoIP2 test failed\n";
        }
    } else {
        die "can't compile GeoIP2 test: $compret\n";
    }
    $configdefh{"HAVE_GEOIP2"} = 1;
}

# with-readline
if ($use_readline eq "no") {
    if ($verbose) {
        print "readline library is disabled\n";
    }
} else {
    $readline_path = File::Spec->rel2abs($readline_path);
    if ($verbose) {
        print "checking for readline directory at \"$readline_path\"\n";
    }
    if (!-f File::Spec->catfile($readline_path, "readline", "readline.h")) {
        die "can't find readline.h include\n";
    }
    if (!-f File::Spec->catfile($readline_path, "readline", "readline.lib")) {
        die "can't find readline.lib library\n";
    }
    $configdefh{"HAVE_READLINE"} = 1;
    $configinc{"READLINE_INC"} = "$readline_path";
    my $readline_lib = File::Spec->catfile($readline_path,
                                           "readline", "readline.lib");
    $configlib{"READLINE_LIB"} = "$readline_lib";
    if (-f File::Spec->catfile($readline_path, "readline", "readlineD.lib")) {
        my $readline_libd = File::Spec->catfile($readline_path,
                                                "readline", "readlineD.lib");
        $configlib{"READLINE_LIBD"} = "$readline_libd";
    } else {
        $configlib{"READLINE_LIBD"} = "$readline_lib";
    }
}

# with-idn (including with-iconv)
if ($use_idn eq "no") {
    if ($verbose) {
        print "IDN kit is disabled\n";
    }
} else {
    $idn_path = File::Spec->rel2abs($idn_path);
    if ($verbose) {
        print "checking for IDN kit directory at \"$idn_path\"\n";
    }
    if (!-f File::Spec->catfile($idn_path, "idn", "api.h")) {
        die "can't find idn\\api.h include\n";
    }
    if (!-f File::Spec->catfile($idn_path, "idn", "idnkit.lib")) {
        die "can't find idnkit.lib library\n";
    }
    if (!-f File::Spec->catfile($idn_path, "idn", "idnkit.dll")) {
        die "can't find idnkit.dll DLL\n";
    }
    $configcond{"IDNKIT"} = 1;
    $configdefh{"WITH_IDN"} = 1;
    $configinc{"IDN_INC"} = "$idn_path";
    my $idn_lib = File::Spec->catfile($idn_path, "idn", "idnkit.lib");
    $configlib{"IDN_LIB"} = "$idn_lib";
    my $idn_dll = File::Spec->catfile($idn_path, "idn", "idnkit.dll");
    $configdll{"IDN_DLL"} = "$idn_dll";
    if ($iconv_path eq " --idn-- ") {
        my $iconv_dll = File::Spec->catfile($idn_path, "idn", "iconv.dll");
        $configdll{"ICONV_DLL"} = "$iconv_dll";
    } else {
        my $iconv_dll =File::Spec->catfile($iconv_path, "iconv.dll");
        $configdll{"ICONV_DLL"} = "$iconv_dll";
    }
}

# with-libxml2
if ($use_libxml2 eq "no") {
    if ($verbose) {
        print "libxml2 library is disabled\n";
    }
} elsif ($use_libxml2 eq "auto") {
    if ($verbose) {
        print "checking for a libxml2 built directory at sibling root\n";
    }
    opendir DIR, $libxml2_path || die "No Directory: $!\n";
    my @dirlist = grep (/^libxml2-[0-9]+\.[0-9]+\.[0-9]+[a-z]*/i,
                        readdir(DIR));
    closedir(DIR);

    # Make sure we have something
    if (scalar(@dirlist) == 0) {
        die "can't find a libxml2 at sibling root\n";
    }
    # Now see if we have a directory or just a file.
    # Make sure we are case insensitive
    my $file;
    foreach $file (sort {uc($b) cmp uc($a)} @dirlist) {
        if (-f File::Spec->catfile($libxml2_path,
                                   $file,
                                   "include\\libxml",
                                   "xmlversion.h")) {
            $libxml2_path = File::Spec->catdir($libxml2_path, $file);
            $use_libxml2 = "yes";
            last;
        }
    }

    # If we have one use it otherwise report the error
    if ($use_libxml2 eq "auto") {
        die "can't find a libxml2 built directory at sibling root\n";
    }
}
# falls into (so no else)
if ($use_libxml2 eq "yes") {
    $libxml2_path = File::Spec->rel2abs($libxml2_path);
    if ($verbose) {
        print "checking for libxml2 built directory at \"$libxml2_path\"\n";
    }
    if (!-f File::Spec->catfile($libxml2_path,
                                "include\\libxml",
                                "xmlversion.h")) {
        die "can't find libxml2 xmlversion.h include\n";
    }
    if (!-f File::Spec->catfile($libxml2_path,
                                "win32\\bin.msvc",
                                "libxml2.lib")) {
        die "can't find Libxml2 libxml2.lib library\n";
    }
    if (!-f File::Spec->catfile($libxml2_path,
                                "win32\\bin.msvc",
                                "libxml2.dll")) {
        die "can't find Libxml2 DLL\n";
    }
    $configcond{"LIBXML2"} = 1;
    $configdefh{"HAVE_LIBXML2"} = 1;
    $configtest{"XMLSTATS"} = 1;
    my $libxml2_inc = File::Spec->catdir($libxml2_path, "include");
    $configinc{"LIBXML2_INC"} = "$libxml2_inc";
    my $libxml2_libdir = File::Spec->catdir($libxml2_path, "win32\\bin.msvc");
    my $libxml2_lib = File::Spec->catfile($libxml2_libdir, "libxml2.lib");
    $configlib{"LIBXML2_LIB"} = "$libxml2_lib";
    my $libxml2_dll = File::Spec->catfile($libxml2_libdir, "libxml2.dll");
    $configdll{"LIBXML2_DLL"} = "$libxml2_dll";
}

# with-zlib
if ($use_zlib eq "no") {
    if ($verbose) {
        print "zlib library is disabled\n";
    }
} else {
    $configcond{"ZLIB"} = 1;
    $configtest{"ZLIB"} = 1;
    $zlib_path = File::Spec->rel2abs($zlib_path);
    if ($verbose) {
        print "checking for zlib directory at \"$zlib_path\"\n";
    }
    if (!-f File::Spec->catfile($zlib_path, "zlib.h")) {
        die "can't find zlib.h include\n";
    }
    if (!-f File::Spec->catfile($zlib_path, "zdll.lib")) {
        die "can't find zdll.lib library\n";
    }
    if (!-f File::Spec->catfile($zlib_path, "zlib1.dll")) {
        die "can't find zlib1.dll DLL\n";
    }
    $configdefh{"HAVE_ZLIB"} = 1;
    $configinc{"ZLIB_INC"} = "$zlib_path";
    my $zlib_lib = File::Spec->catfile($zlib_path, "zdll.lib");
    $configlib{"ZLIB_LIB"} = "$zlib_lib";
    my $zlib_dll = File::Spec->catfile($zlib_path, "zlib1.dll");
    $configdll{"ZLIB_DLL"} = "$zlib_dll";
}

if ($with_pssuspend ne "no") {
    $configvar{"PSSUSPEND"} = "$pssuspend_command";
}

# with-python
if ($use_python eq "no") {
    if ($verbose) {
        print "python is disabled\n";
    }
} elsif ($use_python eq "auto") {
    if ($verbose) {
        print "checking for python in path\n";
    }
    my $pythonret = `python.exe -c "quit()" 2>&1`;
    if ($? != 0) {
        print STDERR "can't launch the python interpreter: $pythonret\n";
        $use_python = "no";
    }
}
if ($use_python ne "no") {
    if ($use_python ne "auto") {
        if ($verbose) {
           print "checking for $python_command\n";
        }
        my $pythonret = `"$python_command" -c "quit()" 2>&1`;
        if ($? != 0) {
            die "can't launch $python_command: $pythonret\n";
        }
    }
    if ($python_command !~ /\.exe$/i) {
        $python_command = $python_command . ".exe";
    }
    # tried to use the full path without success here
    if ($verbose) {
        print "checking for python module 'argparse'\n";
    }
    my $pythonret = `"$python_command" -c "import argparse" 2>&1`;
    if ($? != 0) {
        if ($use_python ne "auto") {
            die "can't find python module 'argparse': $pythonret\n";
        } else {
            print STDERR "can't find python module 'argparse': $pythonret\n";
            $use_python = "no";
        }
    }
    if ($use_python ne "no") {
        if ($verbose) {
            print "checking for python module 'ply'\n";
        }
        $pythonret = `"$python_command" -c "from ply import *" 2>&1`;
        if ($? != 0) {
            if ($use_python ne "auto") {
                die "can't find python module 'ply': $pythonret\n";
            } else {
                print STDERR "can't find python module 'ply': $pythonret\n";
                $use_python = "no";
            }
        }
    }
    if ($use_python ne "no") {
        if ($verbose) {
            print "checking for python module 'win32api'\n";
        }
        $pythonret = `"$python_command" -c "import win32api" 2>&1`;
        if ($? != 0) {
            if ($use_python ne "auto") {
                die "can't find python module 'win32api': $pythonret\n";
            } else {
                print STDERR
                    "can't find python module 'win32api': $pythonret\n";
                $use_python = "no";
            }
        }
    }
    if ($use_python ne "no") {
        if ($verbose) {
            print "checking for python module 'win32con'\n";
        }
        $pythonret = `"$python_command" -c "import win32con" 2>&1`;
        if ($? != 0) {
            if ($use_python ne "auto") {
                die "can't find python module 'win32con': $pythonret\n";
            } else {
                print STDERR
                    "can't find python module 'win32con': $pythonret\n";
                $use_python = "no";
            }
        }
    }
    if ($use_python ne "no") {
        $configcond{"PYTHON"} = 1;
        $configdefd{"USE_PYTHON"} = "USE_PYTHON";
        $configvar{"PYTHON"} = "$python_command";
        $configtest{"CHECKDS"} = "checkdstool";
        $configtest{"COVERAGE"} = "coverage";
        $configtest{"KEYMGR"} = "keymgr";
        # Doesn't matter
        $configvar{"prefix"} = "__prefix__";
        $configvar{"expanded_sysconfdir"} = "__prefix__\\etc";
    }
}

# with-vcredist
$vcredist_path = File::Spec->rel2abs($vcredist_path);
if (!grep { -f and -x } $vcredist_path) {
    die "$vcredist_path is not correct\n";
} else {
    $configvar{"VCREDIST_PATH"} = "$vcredist_path";
}

# tuning
if ($tuning ne "small") {
    $configdefh{"TUNE_LARGE"} = 1;
}

# escape spaces

sub kw {
    if ($_[0] =~ / /) {
        return "\"$_[0]\"";
    } else {
        return "$_[0]";
    }
}

# setup config.h with %configdefh

sub setupconfigh {
    my $line;
    my @Lines;

    open F, $configfile . ".win32" || die $!;
    @Lines = <F>;
    close F;

    foreach $line (@Lines) {
        chomp $line;
        if ($line =~ /^@([^@]+)\@$/) {
            if (defined($configdefh{$1})) {
                $line = "#define $1 $configdefh{$1}";
            } else {
                $line = "/* #undef $1 */";
            }
        }
    }

    open F, ">" . $configfile || die $!;
    if ($verbose) {
        print "Setting up $configfile\n";
    }
    foreach $line (@Lines) {
        print F $line . "\n";
    }
    close F;
}

# setup platform.h with %configdefp

sub setupplatformh {
    my $line;
    my @Lines;

    open F, $platformfile . ".in" || die $!;
    @Lines = <F>;
    close F;

    foreach $line (@Lines) {
        chomp $line;
        if ($line =~ /^@([^@]+)\@$/) {
            if (defined($configdefp{$1})) {
                $line = "#define $1 $configdefp{$1}";
            } else {
                $line = "/* #undef $1 */";
            }
        }
    }

    open F, ">" . $platformfile || die $!;
    if ($verbose) {
        print "Setting up $platformfile\n";
    }
    foreach $line (@Lines) {
        print F $line . "\n";
    }
    close F;
}

# setup conf.sh with %configtest and %configvar

sub setupconfsh {
    my $line;
    my @Lines;
    my $val;

    open F, $confshfile . ".win32" || die $!;
    @Lines = <F>;
    close F;

    foreach $line (@Lines) {
        chomp $line;
        while ($line =~ /@([^@]+)\@/) {
            if ($1 ~~ @substtest) {
                if (defined($configtest{$1})) {
                    $val = kw($configtest{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substvar) {
                if (defined($configvar{$1})) {
                    $val = kw($configvar{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            }  else {
                die "unknown control $& in $confshfile.win32\n";
            }
        }
    }

    open F, ">" . $confshfile || die $!;
    if ($verbose) {
        print "Setting up $confshfile\n";
    }
    binmode(F);
    foreach $line (@Lines) {
        print F $line . "\n";
    }
    close F;
}

# setup a file with %configcond stack and %config{var,defd,inc,lib,dll,test}

sub setupfile {
    my $line;
    my @Linesin;
    my @Linesout;
    my $filename = $_[0];
    my $cond;
    my @conds;
    my $pass = 1;
    my @passes;
    my $val;

    open F, $filename . ".in" || die $!;
    @Linesin = <F>;
    close F;

    foreach $line (@Linesin) {
        chomp $line;
        if ($line =~ /^\@IF (.*)$/) {
            if (defined($cond)) {
                unshift(@conds, $cond);
                unshift(@passes, $pass);
            }
            if ($1 ~~ @allcond) {
                $cond = $1;
                if (defined($configcond{$cond})) {
                    # do nothing
                } else {
                    $pass = 0;
                }
            } else {
                die "unknown condition \@IF $1 in $filename\n";
            }
            next;
        } elsif ($line =~ /^\@ELSE (.*)$/) {
            if ($cond ne $1) {
                die "\@ELSE $1 mismatch in $filename\n";
            }
            if (defined($configcond{$cond})) {
                $pass = 0;
            } else {
                if (scalar(@conds) > 0) {
                    $pass = $passes[0];
                } else {
                    $pass = 1;
                }
            }
            next;
        } elsif ($line =~ /^\@END (.*)$/) {
            if ($cond ne $1) {
                die "\@END $1 mismatch in $filename\n";
            }
            $cond = shift(@conds);
            if (scalar(@passes) > 0) {
                $pass = shift(@passes);
            } else {
                $pass = 1;
            }
            next;
        }
        if ($pass == 0) {
            next;
        }
        while ($line =~ /@([^@ ]*)@/) {
            if ($1 ~~ @substvar) {
                if (defined($configvar{$1})) {
                    $val = kw($configvar{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substdefd) {
                if (defined($configdefd{$1})) {
                    my $def = $configdefd{$1};
                    my $pre = "$`";
                    my $post = "$'";
                    $def =~ s/([\\ "])/\\$1/g;
                    $line = qq($pre/D "$def"$post);
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substinc) {
                if (defined($configinc{$1})) {
                    $line = qq($`/I "$configinc{$1}"$');
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substlib) {
                if (defined($configlib{$1})) {
                    $val = kw($configlib{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substdll) {
                if (defined($configdll{$1})) {
                    $val = kw($configdll{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            } else {
                die "unknown control $& in $filename\n";
            }
        }
        push @Linesout, $line;
    }

    open F, ">" . $filename || die $!;
    if ($verbose) {
        print "Setting up $filename\n";
    }
    binmode(F);
    foreach $line (@Linesout) {
        print F $line . "\n";
    }
    close F;
}

# setup a project with %configcond stack and %config{var,defd,inc,lib,dll}

sub setupproject {
    my $line;
    my @Linesin;
    my @Linesout;
    my $projectname = $_[0];
    my $cond;
    my @conds;
    my $pass = 1;
    my @passes;
    my $val;

    open F, $projectname . ".in" || die $!;
    @Linesin = <F>;
    close F;

    foreach $line (@Linesin) {
        chomp $line;
        if ($line =~ /^\@IF (.*)$/) {
            if (defined($cond)) {
                unshift(@conds, $cond);
                unshift(@passes, $pass);
            }
            if ($1 ~~ @allcond) {
                $cond = $1;
                if (defined($configcond{$cond})) {
                    # do nothing
                } else {
                    $pass = 0;
                }
            } else {
                die "unknown condition \@IF $1 in $projectname\n";
            }
            next;
        } elsif ($line =~ /^\@ELSE (.*)$/) {
            if ($cond ne $1) {
                die "\@ELSE $1 mismatch in $projectname\n";
            }
            if (defined($configcond{$cond})) {
                $pass = 0;
            } else {
                if (scalar(@conds) > 0) {
                    $pass = $passes[0];
                } else {
                    $pass = 1;
                }
            }
            next;
        } elsif ($line =~ /^\@END (.*)$/) {
            if ($cond ne $1) {
                die "\@END $1 mismatch in $projectname\n";
            }
            $cond = shift(@conds);
            if (scalar(@passes) > 0) {
                $pass = shift(@passes);
            } else {
                $pass = 1;
            }
            next;
        }
        if ($pass == 0) {
            next;
        }
        while ($line =~ /@([^@ ]*)@/) {
            if ($1 ~~ @substvar) {
                if (defined($configvar{$1})) {
                    $val = kw($configvar{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substdefd) {
                if (defined($configdefd{$1})) {
                    $val = kw($configdefd{$1});
                    $line = "$`$val;$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substinc) {
                if (defined($configinc{$1})) {
                    $val = kw($configinc{$1});
                    $line = "$`$val;$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substlib) {
                if (defined($configlib{$1})) {
                    $val = kw($configlib{$1});
                    $line = "$`$val;$'";
                } else {
                    $line = "$`$'";
                }
            } elsif ($1 ~~ @substdll) {
                if (defined($configdll{$1})) {
                    $val = kw($configdll{$1});
                    $line = "$`$val$'";
                } else {
                    $line = "$`$'";
                }
            } else {
                die "unknown control $& in $projectname\n";
            }
        }
        push @Linesout, $line;
    }

    open F, ">" . $projectname || die $!;
    if ($verbose) {
        print "Setting up $projectname\n";
    }
    foreach $line (@Linesout) {
        print F $line . "\n";
    }
    close F;
}

# make versions.h

sub makeversion {
    # List of directories with version files

    my $Version;
    my $Mapapi;
    my $versionfile = "versions.h";
    my $versionpath = "..\\$versionfile";

    my $data;
    my $name;
    my $value;

    # And the mapapi one

    open M, "..\\lib\\dns\\mapapi" || die $!;
    while (<M>) {
        chomp;
        ($data) = split(/\#/);
        if ($data) {
            ($name, $value) = split(/=/, $data);
            ($name) = split(/\s+/, $name);
            if ($name eq 'MAPAPI') {
                ($value) =~ s/^["\s]+//;
                ($value) =~ s/["\s]+$//;
            } else {
                ($value) = split(/\s+/, $value);
            }
            $Mapapi = $value;
        }
    }
    close M;

    # Now set up the output version file

    my $ThisDate = scalar localtime();
    open O, ">$versionpath" ||
        die "Can't open output file $versionpath: $!\n";

    # Standard Header

    print O '/*
 * Copyright (C) 2001  Internet Systems Consortium, Inc. ("ISC")
 *
 * 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 http://mozilla.org/MPL/2.0/.
 */

';

    print O "/*\n";
    print O " * $versionfile.";
    print O "  Generated automatically by Configure.pl.\n";
    print O " * Date generated: $ThisDate\n";
    print O " */\n\n";

    print O '
#ifndef  VERSIONS_H
#define VERSIONS_H 1

';

    $Version = "$Versions{'MAJORVER'}.$Versions{'MINORVER'}";
    if ($Versions{'PATCHVER'} ne "") {
        $Version = "$Version.$Versions{'PATCHVER'}";
    }
    $Version = "$Version$Versions{'RELEASETYPE'}$Versions{'RELEASEVER'}";
    $Version = "$Version$Versions{'EXTENSIONS'}";
    if ($verbose) {
        print "BIND Version: $Version\n";
    }

    print O "#define VERSION \"$Version\"\n";
    print O "#define PRODUCT \"$Versions{'PRODUCT'}\"\n\n";
    print O "#define DESCRIPTION \"$Versions{'DESCRIPTION'}\"\n\n";
    print O
        "#define MAJOR \"$Versions{'MAJORVER'}.$Versions{'MINORVER'}\"\n\n";
    print O "#define MAPAPI \"$Mapapi\"\n\n";

    print O "#endif /* VERSIONS_H */\n";
    close O;
}

# make srcid.h

sub makesrcid {
    my $data;
    my $name;
    my $value;
    my $srcid = "unset_id";

    open SOUT, ">..\\srcid.h" || die "cannot open srcid.h: $!\n";
    if (open (SIN, "..\\srcid")) {
      LOOP: while (<SIN>) {
          chomp;
          ($data) = split(/\#/);
          if ($data) {
              ($name, $value) = split(/=/, $data);
              ($name) = split(/\s+/, $name);
              ($value) = split(/\s+/, $value);
              next LOOP if ($name != "SRCID");
              $srcid = $value;
          }
        }
        close SIN;
    }

    if ($srcid eq "unset_id" and -d "..\\.git") {
        $data = `git rev-list --max-count=1 HEAD`;
        if (length($data) > 0) {
            $srcid = substr($data, 0, 7);
        }
    }

    # Now set up the output version file

    my $ThisDate = scalar localtime();

    # Standard Header

    print SOUT '/*
 * Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
 *
 * 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 http://mozilla.org/MPL/2.0/.
 */

';

    print SOUT "/*\n";
    print SOUT " * srcid.h";
    print SOUT " * Generated automatically by Configure.pl.\n";
    print SOUT " * Date generated: $ThisDate\n";
    print SOUT " */\n\n";

    print SOUT '
#ifndef  SRCID_H
#define SRCID_H 1
';

    if ($verbose) {
        print "BIND SRCID: $srcid\n";
    }

    print SOUT "#define SRCID\t\"$srcid\"\n";
    print SOUT "#endif /* SRCID_H */\n";
    close SOUT;
}

# Build install files

sub makeinstallfile {
    open FOUT, ">InstallFlags" || die "cannot open InstallFlags: $!\n";
    print FOUT "# Flags for BINDInstall\n";
    if ($msc_ver >= 1400) {
        print FOUT "runvcredist\n";
    }
    if ($want_x64 eq "yes") {
        print FOUT "forwin64\n";
    }
    close FOUT;

    open LOUT, ">InstallFiles" || die "cannot open InstallFiles: $!\n";
    print LOUT "# File list for BINDInstall\n";
    if ($msc_ver < 1400) {
        if ($msc_ver >= 1310) {
            print LOUT "mfc71.dll-WCTT\n";
            print LOUT "msvcr71.dll-WCTT\n";
        } elsif (($msc_ver > 1200) && ($msc_ver < 1310)) {
            print LOUT "mfc70.dll-WCTT\n";
            print LOUT "msvcr70.dll-WCTT\n";
        }
    }
    print LOUT "bindevt.dll-BNFT\n";
    print LOUT "libbind9.dll-BCFT\n";
    print LOUT "libisc.dll-BCFT\n";
    print LOUT "libisccfg.dll-BCFT\n";
    print LOUT "libisccc.dll-BCFT\n";
    print LOUT "libdns.dll-BCFT\n";
    print LOUT "libirs.dll-BCFT\n";
    print LOUT "libns.dll-BCFT\n";
    print LOUT "uv.dll-BCFT\n";
    if ($use_openssl eq "yes") {
        my $v;
        my $d;
        my $name;
        ($v, $d, $name) =File::Spec->splitpath($configdll{"OPENSSL_DLLCRYPTO"});
        print LOUT "${name}-BCFT\n";
        ($v, $d, $name) =File::Spec->splitpath($configdll{"OPENSSL_DLLSSL"});
        print LOUT "${name}-BCFT\n";
    }
    if ($use_libxml2 eq "yes") {
        print LOUT "libxml2.dll-BCFT\n";
    }
    if ($use_gssapi eq "yes") {
        if ($want_x64 eq "yes") {
            print LOUT "gssapi64.dll-BCFT\n";
            print LOUT "krb5_64.dll-BCFT\n";
        } else {
            print LOUT "gssapi32.dll-BCFT\n";
            print LOUT "krb5_32.dll-BCFT\n";
        }
    }
    if ($use_idn eq "yes") {
        print LOUT "idnkit.dll-BCFT\n";
        print LOUT "iconv.dll-BCFT\n";
    }
    print LOUT "named.exe-BCFF\n";
    print LOUT "nsupdate.exe-BNFT\n";
    print LOUT "BINDInstall.exe-BNFT\n";
    print LOUT "InstallFlags-BNFT\n";
    print LOUT "InstallFiles-BNFT\n";
    print LOUT "rndc.exe-BNFF\n";
    print LOUT "dig.exe-BNFT\n";
    print LOUT "host.exe-BNFT\n";
    print LOUT "mdig.exe-BNFT\n";
    print LOUT "nslookup.exe-BNFT\n";
    print LOUT "delv.exe-BNFT\n";
    print LOUT "arpaname.exe-BNFT\n";
    print LOUT "nsec3hash.exe-BNFF\n";
    print LOUT "rndc-confgen.exe-BNFF\n";
    print LOUT "ddns-confgen.exe-BNFF\n";
    print LOUT "tsig-keygen.exe-BNFF\n";
    print LOUT "dnssec-keygen.exe-BNFF\n";
    print LOUT "dnssec-signzone.exe-BNFF\n";
    print LOUT "dnssec-dsfromkey.exe-BNFF\n";
    print LOUT "dnssec-importkey.exe-BNFF\n";
    print LOUT "dnssec-keyfromlabel.exe-BNFF\n";
    print LOUT "dnssec-revoke.exe-BNFF\n";
    print LOUT "dnssec-settime.exe-BNFF\n";
    print LOUT "dnssec-verify.exe-BNFF\n";
    print LOUT "named-checkconf.exe-BNFF\n";
    print LOUT "named-checkzone.exe-BNFF\n";
    print LOUT "named-compilezone.exe-BNFF\n";
    print LOUT "named-journalprint.exe-BNFF\n";
    print LOUT "named-rrchecker.exe-BNFF\n";
    if ($use_pkcs11 eq "yes") {
        print LOUT "pkcs11-destroy.exe-BNFF\n";
        print LOUT "pkcs11-keygen.exe-BNFF\n";
        print LOUT "pkcs11-list.exe-BNFF\n";
        print LOUT "pkcs11-tokens.exe-BNFF\n";
    }
    if ($use_python ne "no") {
        print LOUT "dnssec-checkds.py-BNFF\n";
        print LOUT "dnssec-coverage.py-BNFF\n";
        print LOUT "dnssec-keymgr.py-BNFF\n";
    }
    print LOUT "readme1st.txt-BTFT\n";
    close LOUT;
}

# Adjust system tests

# dnstap not supported
#$configtest{"DNSTAP"} = "dnstap";
#$configtest{"FSTRM_CAPTURE"} = "fstrm_capture";

# no json-c library for WIN32
#$configtest{"JSONSTATS"} = 1;

# lmdb not supported
#$configtest{"NZD_TOOLS"} = "nzd";

# TODO check for pkcs11ssl and set PKCS11_TEST

# Status

if ($verbose) {
    my $name;

    print "Configuration Status\n";

    print "\tconfig.h:\n";
    foreach $name (@substdefh) {
        if (defined($configdefh{$name})) {
            print qq(\t\t$name defined to "$configdefh{$name}"\n);
        } else {
            printf qq(\t\t$name undefined\n);
        }
    }

    print "\tplatform.h:\n";
    foreach $name (@substdefp) {
        if (defined($configdefp{$name})) {
            print qq(\t\t$name defined to "$configdefp{$name}"\n);
        } else {
            printf qq(\t\t$name undefined\n);
        }
    }

    print "\tconf.sh:\n";
    foreach $name (@substtest) {
        if (defined($configtest{$name})) {
            print qq(\t\t$name defined to "$configtest{$name}"\n);
        } else {
            printf qq(\t\t$name undefined\n);
        }
    }

    print "\tconditions:\n";
    foreach $name (@substcond) {
        if (defined($configcond{$name})) {
            print "\t\t$name is true\n";
        } else {
            print "\t\t$name is false\n";
        }
    }

    print "\tsubstitutions:\n";
    foreach $name (@substvar) {
        if (defined($configvar{$name})) {
            print qq(\t\t$name -> "$configvar{$name}"\n);
        }
    }

    print "\tdefines:\n";
    foreach $name (@substdefd) {
        if (defined($configdefd{$name})) {
            print qq(\t\t/D "$configdefd{$name}"\n);
        }
    }

    print "\tincludes:\n";
    foreach $name (@substinc) {
        if (defined($configinc{$name})) {
            print qq(\t\t/I "$configinc{$name}"\n);
        }
    }

    print "\tlibraries:\n";
    foreach $name (@substlib) {
        if (defined($configlib{$name})) {
            print "\t\t$configlib{$name}\n";
        }
    }

    print "\tDLLs:\n";
    foreach $name (@substdll) {
        if (defined($configdll{$name})) {
            print "\t\t$configdll{$name}\n";
        }
    }

    print "\n";
}

# Setup
if (($want_win32 eq "yes") || ($want_x64 eq "yes")) {
    setupconfigh();

    setupplatformh();

    setupconfsh();

    my $file;
    foreach $file (@filelist) {
        setupfile($file);
    }

    foreach $file (@projectlist) {
        setupproject($file);
    }

    makeversion();

    makesrcid();

    makeinstallfile();

    print "Configured.\n";
} else {
    print "add win32 or x64 to commit configuration to build files\n";
}

exit 0;

# Notes: Unix configure.in options
#  --enable-developer partially supported
#  --enable-newstats (9.9/9.9sub only)
#  --enable-native-pkcs11 supported
#  --enable-openssl-version-check included without a way to disable it
#  --enable-openssl-hash supported
#  --enable-threads included without a way to disable it
#  --enable-backtrace backtrace included without a way to disable it
#  --enable-symtable incompatible with DLLs (or libtool)
#  --enable-ipv6 included without a way to disable it
#  --enable-atomic supported (renamed to intrinsic)
#  --enable-fixed-rrset supported
#  --enable-querytrace supported
#  --enable-full-report supported by verbose
#  --enable-dnstap not supported (requires libfstrm support on WIN32)
#  --enable-afl not supported (not yet available on Visual Studio C++)
#  --disable-auto-validation supported
#  --with-python supported
#  --with-openssl supported
#  --with-pkcs11 supported
#  --with-aes supported
#  --with-randomdev not supported on WIN32 (makes no sense)
#  --with-geoip2 supported
#  --with-gssapi supported with MIT (K)erberos (f)or (W)indows
#  --with-lmdb no supported on WIN32 (port is not reliable)
#  --with-libxml2 supported
#  --with-json-c not supported on WIN32 (package not available on WIN32)
#  --with-zlib supported
#  --with-purify not supported (package available on WIN32 but for free?)
#  --with-gperftools-profiler not supported (package not available on WIN32)
#  --with-libtool not supported on WIN32 (never)
#  --with-locktype not supported on WIN32 (not yet available on WIN32)
#  --with-readline supported
#  --with-protobuf-c not supported (no reason to until libfstrm is ready)
#  --with-libfrtrm not supported (not yet available on WIN32)
#  --with-docbook-xsl not supported (?)
#  --with-idn[lib] supported
#  --with-[lib]iconv supported (part of IDN)
#  --with-atf not supported on WIN32 (package not available on WIN32)
#  --with-tuning supported
#  --with-dlopen included without a way to disable it
#  --with-dlz-* ?
#
# Notes: MSVC versions
# MSVC 15.x _MSC_VER == 191y (VS 2017)
# MSVC 14.0 _MSC_VER == 1900 (VS 2015)
# MSVC 12.0 _MSC_VER == 1800 (VS 2013)
# MSVC 11.0 _MSC_VER == 1700 (VS 2012)
# MSVC 10.0 _MSC_VER == 1600 (VS 2010)
# MSVC 9.0  _MSC_VER == 1500 (VS 2008)
# MSVC 8.0  _MSC_VER == 1400 (VS 2005)
# MSVC 7.1  _MSC_VER == 1310 (VS .NET 2003)
# MSVC 7.0  _MSC_VER == 1300 (VS .NET (2002))
# MSVC 6.0  _MSC_VER == 1200 (VS 6.0 (1998))
# MSVC 5.0  _MSC_VER == 1100 (VS 97)