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

AC_INIT([frr], [10.0], [https://github.com/frrouting/frr/issues])
PACKAGE_URL="https://frrouting.org/"
AC_SUBST([PACKAGE_URL])
PACKAGE_FULLNAME="FRRouting"
AC_SUBST([PACKAGE_FULLNAME])

CONFIG_ARGS="`echo $ac_configure_args | sed -e \"s% '[[A-Z]]*FLAGS=[[^']]\+'%%g\"`"
AC_SUBST([CONFIG_ARGS])

AC_CONFIG_SRCDIR([lib/zebra.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([m4/ac])

dnl ------------------------------
dnl system paths
dnl ------------------------------
dnl Versions of FRR (or Quagga, or Zebra) before ca. 9.2 used sysconfdir and
dnl localstatedir as-is, without appending /frr.  The /frr was expected to be
dnl given on ./configure invocations.
dnl
dnl This does not match standard behavior by other packages and makes FRR
dnl specific packaging changes necessary to add these options.  localstatedir
dnl was also misused to include the /run part (it normally is only /var),
dnl leaving no path configuration option that references /var itself.  This
dnl is because runstatedir did not exist in ancient autoconf.
dnl
dnl The path options have been changed to expect plain / system prefix
dnl directories.  As a temporary workaround to not break packaging, eventual
dnl /frr suffixes are stripped and a warning is printed.

path_warn_banner=false

AC_MSG_CHECKING([whether --sysconfdir option is FRR-specific])
case "$sysconfdir" in
  */frr)
    AC_MSG_RESULT([yes, ends in /frr - removing suffix])
    AC_MSG_WARN([Please remove /frr suffix from --sysconfdir="${sysconfdir}" (it should be /etc in 99% of cases)])
    sysconfdir="${sysconfdir%/frr}"
    path_warn_banner=true
    ;;
  *)
    AC_MSG_RESULT([no, as expected])
    ;;
esac

frr_sysconfdir="\${sysconfdir}/frr"

AC_MSG_CHECKING([whether --localstatedir option is FRR-specific])
case "$localstatedir" in
  */run/frr)
    AC_MSG_RESULT([yes, ends in /run/frr - removing suffix])
    AC_MSG_WARN([Please remove /run/frr suffix from --localstatedir=${localstatedir} (it should be /var in 99% of cases)])
    localstatedir="${localstatedir%/run/frr}"
    path_warn_banner=true
    ;;
  */frr)
    AC_MSG_RESULT([yes, ends in /frr - removing suffix])
    AC_MSG_WARN([The --localstatedir=${localstatedir} option seems to include /frr but not /run, this is unexpected.  Please check for consistency.)])
    localstatedir="${localstatedir%/frr}"
    path_warn_banner=true
    ;;
  *)
    AC_MSG_RESULT([no, as expected])
    ;;
esac

dnl runstatedir is either ${localstatedir}/run or plain /run
dnl the change of localstatedir above may impact this
dnl
dnl note runstatedir was never used with /frr as the other two above, so does
dnl not need the same cleanup hack
: "${runstatedir:=\${localstatedir\}/run}"
frr_runstatedir="\${runstatedir}/frr"

if $path_warn_banner; then
  AC_MSG_WARN([^])
  AC_MSG_WARN([^])
  AC_MSG_WARN([^ warnings regarding system path configuration were printed above])
  AC_MSG_WARN([^ paths have been adjusted by temporary workarounds])
  AC_MSG_WARN([^ please fix your ./configure invocation (remove /frr) so it will work without the workarounds])
  AC_MSG_WARN([^])
  AC_MSG_WARN([^])
fi

frr_libstatedir="\${localstatedir}/lib/frr"

dnl -----------------------------------
dnl Get hostname and other information.
dnl -----------------------------------
AC_CANONICAL_BUILD()
AC_CANONICAL_HOST()

AC_ARG_VAR([AR],[archiver command])
AC_ARG_VAR([LD],[linker command])
AC_ARG_VAR([OBJCOPY],[objcopy command])
AC_ARG_VAR([OBJDUMP],[objdump command])
AC_ARG_VAR([RANLIB],[ranlib command])
AC_ARG_VAR([STRIP],[strip command])

hosttools_clippy="false"
build_clippy="true"

dnl case 1: external clippy
if test -n "$with_clippy" -a "$with_clippy" != "no" -a "$with_clippy" != "yes"; then
  if test "$enable_clippy_only" = "yes"; then
    AC_MSG_ERROR([--enable-clippy-only does not make sense with --with-clippy])
  fi

  CLIPPY="$with_clippy"
  build_clippy="false"
  if test ! -x "$with_clippy"; then
    AC_MSG_ERROR([clippy tool ($with_clippy) is not executable])
  fi

dnl case 2: cross-compiling internal clippy
elif test "$host" != "$build"; then
  if test "$srcdir" = "."; then
    AC_MSG_ERROR([cross-compilation is only possible with builddir separate from srcdir or by building clippy separately and using the --with-clippy option.  create a separate directory and run as .../path-to-frr/configure.])
  fi
  test -d hosttools || mkdir hosttools
  abssrc="`cd \"${srcdir}\"; pwd`"

  AC_MSG_NOTICE([...])
  AC_MSG_NOTICE([... cross-compilation: creating hosttools directory and self-configuring for build platform tools])
  AC_MSG_NOTICE([... use HOST_CPPFLAGS / HOST_CFLAGS / HOST_LDFLAGS if necessary])
  AC_MSG_NOTICE([...])

  (
    for var in $ac_precious_vars; do
      dnl special cases
      case "$var" in
      YACC|YFLAGS) continue;;
      PYTHON*)     retain=true;;
      *)           retain=false;
      esac

      eval "hostvar=\"\${HOST_$var}\""
      eval "targetvar=\"\${$var}\""
      if test -n "$hostvar"; then
        eval "$var='$hostvar'"
        _AS_ECHO_LOG([host $var='$hostvar'])
      elif $retain; then
        _AS_ECHO_LOG([host retain $var='$targetvar'])
      else
        eval "unset $var"
        _AS_ECHO_LOG([host unset $var])
      fi
    done
    cd hosttools
    "${abssrc}/configure" "--host=$build" "--build=$build" "--enable-clippy-only" "--disable-nhrpd" "--disable-vtysh"
  ) || exit 1

  AC_MSG_NOTICE([...])
  AC_MSG_NOTICE([... cross-compilation: finished self-configuring for build platform tools])
  AC_MSG_NOTICE([...])

  build_clippy="false"
  hosttools_clippy="true"
  CLIPPY="hosttools/lib/clippy"

dnl case 3: normal build internal clippy
else
  CLIPPY="lib/clippy\$(EXEEXT)"
fi
AC_SUBST([CLIPPY])
AM_CONDITIONAL([BUILD_CLIPPY], [$build_clippy])
AM_CONDITIONAL([HOSTTOOLS_CLIPPY], [$hosttools_clippy])
AM_CONDITIONAL([ONLY_CLIPPY], [test "$enable_clippy_only" = "yes"])

# Disable portability warnings -- our automake code (in particular
# common.am) uses some constructs specific to gmake.
AM_INIT_AUTOMAKE([1.12 -Wno-portability foreign])
m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
AM_SILENT_RULES([yes])
AC_CONFIG_HEADERS([config.h])

AC_PATH_PROG([PERL], [perl])
PKG_PROG_PKG_CONFIG

dnl default is to match previous behavior
pkgsrcrcdir=""
AC_ARG_ENABLE([pkgsrcrcdir],
	  AS_HELP_STRING([--enable-pkgsrcrcdir],
			 [specify directory for rc.d scripts]),
			 pkgsrcrcdir="$enableval",)
dnl XXX add --pkgsrcrcdir to autoconf standard directory list somehow
AC_SUBST([pkgsrcrcdir])
AM_CONDITIONAL([PKGSRC], [test "$pkgsrcrcdir" != ""])

AC_ARG_WITH([moduledir], [AS_HELP_STRING([--with-moduledir=DIR], [module directory (${libdir}/frr/modules)])], [
	moduledir="$withval"
], [
	moduledir="\${libdir}/frr/modules"
])
AC_SUBST([moduledir], [$moduledir])

AC_ARG_WITH([scriptdir], [AS_HELP_STRING([--with-scriptdir=DIR], [script directory (${sysconfdir}/frr/scripts)])], [
	scriptdir="$withval"
], [
	scriptdir="\${frr_sysconfdir}/scripts"
])
AC_SUBST([scriptdir], [$scriptdir])

AC_ARG_WITH([yangmodelsdir], [AS_HELP_STRING([--with-yangmodelsdir=DIR], [yang models directory (${datarootdir}/yang)])], [
	yangmodelsdir="$withval"
], [
	yangmodelsdir="\${datarootdir}/yang"
])
AC_SUBST([yangmodelsdir])

AC_ARG_WITH([vici-socket], [AS_HELP_STRING([--with-vici-socket=PATH], [vici-socket (/var/run/charon.vici)])], [
	vici_socket="$withval"
], [
	vici_socket="/var/run/charon.vici"
])
AC_DEFINE_UNQUOTED([VICI_SOCKET], ["$vici_socket"], [StrongSWAN vici socket path])

AC_ARG_ENABLE(tcmalloc,
	AS_HELP_STRING([--enable-tcmalloc], [Turn on tcmalloc]),
[case "${enableval}" in
  yes) tcmalloc_enabled=true
LIBS="$LIBS -ltcmalloc_minimal"
 ;;
  no)  tcmalloc_enabled=false ;;
  *) AC_MSG_ERROR([bad value ${enableval} for --enable-tcmalloc]) ;;
esac],[tcmalloc_enabled=false])


dnl Thanks autoconf, but we don't want a default -g -O2.  We have our own
dnl flag determination logic.
CFLAGS="${CFLAGS:-}"

dnl --------------------
dnl Check CC and friends
dnl --------------------
dnl note orig_cflags is also used further down
orig_cflags="$CFLAGS"
orig_cxxflags="$CXXFLAGS"
AC_LANG([C])
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AM_PROG_CC_C_O
dnl remove autoconf default "-g -O2"
CFLAGS="$orig_cflags"
CXXFLAGS="$orig_cxxflags"

dnl Some special handling for ICC later on
if test "$CC" = "icc"; then
    cc_is_icc="yes"
fi

PKG_PROG_PKG_CONFIG

dnl it's 2019, sed is sed.
SED=sed
AC_SUBST([SED])

dnl try and enable CFLAGS that are useful for FRR
dnl - specifically, options to control warnings

AC_SUBST([AC_CFLAGS])
AC_USE_SYSTEM_EXTENSIONS
AC_DEFUN([AC_C_FLAG], [{
    m4_pushdef([cachename],[m4_translit([frr_cv_$1],[ =-+/{}$],[________])])
    AC_CACHE_CHECK([[whether $CC supports $1]], cachename, [
	AC_LANG_PUSH([C])
	ac_c_flag_save="$CFLAGS"
	CFLAGS="$CFLAGS $1"
	AC_COMPILE_IFELSE(
		[AC_LANG_PROGRAM([[$4]])],
		[
			cachename=yes
		], [
			cachename=no
		])
	CFLAGS="$ac_c_flag_save"
	AC_LANG_POP([C])
    ])
    if test "$cachename" = "yes"; then
	m4_if([$3], [], [AC_CFLAGS="$AC_CFLAGS $1"], [$3])
    else
	:
	$2
    fi
    m4_popdef([cachename])
}])

AC_DEFUN([AC_LINK_IFELSE_FLAGS], [{
	AC_LANG_PUSH([C])
	ac_cflags_save="$CFLAGS"
	ac_libs_save="$LIBS"
	CFLAGS="$CFLAGS $1"
	LIBS="$LIBS $2"
	AC_LINK_IFELSE(
		[$3],
		[
			CFLAGS="$ac_cflags_save"
			LIBS="$ac_libs_save"
			m4_default([$5], [
				AC_MSG_RESULT([yes])
			])
		], [
			CFLAGS="$ac_cflags_save"
			LIBS="$ac_libs_save"
			m4_default([$4], [
				AC_MSG_RESULT([no])
			])
		])
	AC_LANG_POP([C])
	}])

dnl ICC won't bail on unknown options without -diag-error 10006
dnl need to do this first so we get useful results for the other options
if test "$cc_is_icc" = "yes"; then
    AC_C_FLAG([-diag-error 10006])
fi

dnl autoconf 2.69 AC_PROG_CC_C99 is "state of the art"
dnl autoconf 2.70 AC_PROG_CC_C99 is deprecated and AC_PROC_CC tries to do C11
m4_if(m4_version_compare(m4_defn([AC_AUTOCONF_VERSION]), [2.70]), [-1], [dnl
  dnl autoconf < 2.70
  AC_PROG_CC_C99

  dnl AC_PROG_CC_C99 may change CC to include -std=gnu99 or something
  ac_cc="$CC"
  CC="${CC% -std=gnu99}"
  CC="${CC% -std=c99}"

  AC_C_FLAG([-std=gnu11], [CC="$ac_cc"], [CC="$CC -std=gnu11"])
], [
  dnl autoconf >= 2.70
  if test "$ac_cv_prog_cc_c11" = "no"; then
    AC_MSG_ERROR([ISO C11 compiler support (with GNU extensions) is required.])
  fi
])

dnl if the user has specified any CFLAGS, override our settings
if test "$enable_gcov" = "yes"; then
   if test "$orig_cflags" = ""; then
      AC_C_FLAG([--coverage])
      AC_C_FLAG([-O0])
   fi

   AC_LDFLAGS="${AC_LDFLAGS} --coverage"
fi

if test "$enable_clang_coverage" = "yes"; then
   AC_C_FLAG([-fprofile-instr-generate], [
     AC_MSG_ERROR([$CC does not support -fprofile-instr-generate.])
   ])
   AC_C_FLAG([-fcoverage-mapping], [
     AC_MSG_ERROR([$CC does not support -fcoverage-mapping.])
   ])
fi

AM_CONDITIONAL([SCRIPTING], [test "$enable_scripting" = "yes"])

if test "$enable_scripting" = "yes"; then
   AX_PROG_LUA([5.3], [5.4], [], [
     AC_MSG_ERROR([Lua 5.3 is required to build with Lua support. No other version is supported.])
   ])
   AX_LUA_HEADERS([], [
     AC_MSG_ERROR([Lua 5.3 headers are required to build with Lua support. No other version is supported.])
   ])
   PKG_CHECK_MODULES([LUA], [lua5.3], [
     AC_DEFINE([HAVE_SCRIPTING], [1], [Have support for scripting])
     LIBS="$LIBS $LUA_LIBS"
     SCRIPTING=true
   ], [
      AX_LUA_LIBS([
        AC_DEFINE([HAVE_SCRIPTING], [1], [Have support for scripting])
        LIBS="$LIBS $LUA_LIB"
        SCRIPTING=true
      ], [
        SCRIPTING=false
        AC_MSG_ERROR([Lua 5.3 libraries are required to build with Lua support. No other version is supported.])
      ])
    ])
fi

dnl the following flags go in CFLAGS rather than AC_CFLAGS since they make
dnl sense to be overridden by the user
if test "$enable_dev_build" = "yes"; then
   AC_DEFINE([DEV_BUILD], [1], [Build for development])
   if test "$orig_cflags" = ""; then
      AC_C_FLAG([-O0],,[CFLAGS="$CFLAGS -O0"])
      AC_C_FLAG([-g3],,[CFLAGS="$CFLAGS -g3"])
      AC_C_FLAG([-ggdb3],,[CFLAGS="$CFLAGS -ggdb3"])
   fi
else
   if test "$orig_cflags" = ""; then
      AC_C_FLAG([-g],,[CFLAGS="$CFLAGS -g"])
      AC_C_FLAG([-O2],,[CFLAGS="$CFLAGS -O2"])
   fi
fi

dnl just stick -g into LDFLAGS, if we don't have it in CFLAGS it won't do much
LDFLAGS="$LDFLAGS -g"

AM_CONDITIONAL([DEV_BUILD], [test "$enable_dev_build" = "yes"])

dnl -fms-extensions causes clang to have a built-in __wchar_t on OpenBSD,
dnl which just straight up breaks compiling any code.
dnl (2022-04-04 / OpenBSD 7 / clang 11.1.0)
AH_VERBATIM([OpenBSD], [
#ifdef __OpenBSD__
#define __wchar_t __wchar_t_ignore
#include <stdint.h>
#undef __wchar_t
#endif
])

dnl always want these CFLAGS
AC_C_FLAG([-fms-extensions], [
  AC_MSG_ERROR([$CC does not support unnamed struct fields (-fms-extensions)])
])
AC_C_FLAG([-fno-omit-frame-pointer])
AC_C_FLAG([-funwind-tables])
AC_C_FLAG([-Wall])
AC_C_FLAG([-Wextra])
AC_C_FLAG([-Wformat-nonliteral])
AC_C_FLAG([-Wformat-security])
AC_C_FLAG([-Wswitch-enum])
AC_C_FLAG([-Wstrict-prototypes])
AC_C_FLAG([-Wmissing-prototypes])
AC_C_FLAG([-Wmissing-declarations])
AC_C_FLAG([-Wpointer-arith])
AC_C_FLAG([-Wbad-function-cast])
AC_C_FLAG([-Wwrite-strings])
AC_C_FLAG([-Wundef])
AC_C_FLAG([-Wimplicit-fallthrough])
if test "$enable_gcc_ultra_verbose" = "yes" ; then
  AC_C_FLAG([-Wcast-qual])
  AC_C_FLAG([-Wmissing-noreturn])
  AC_C_FLAG([-Wmissing-format-attribute])
  AC_C_FLAG([-Wunreachable-code])
  AC_C_FLAG([-Wpacked])
  AC_C_FLAG([-Wpadded])
  AC_C_FLAG([-Wshadow])
else
  AC_C_FLAG([-Wno-unused-result])
fi
AC_C_FLAG([-Wno-unused-parameter])
AC_C_FLAG([-Wno-missing-field-initializers])
AC_C_FLAG([-Wno-microsoft-anon-tag])

AC_C_FLAG([-Wc++-compat], [], [CXX_COMPAT_CFLAGS="-Wc++-compat"])
AC_SUBST([CXX_COMPAT_CFLAGS])

dnl ICC emits a broken warning for const char *x = a ? "b" : "c";
dnl for some reason the string consts get 'promoted' to char *,
dnl triggering a const to non-const conversion warning.
if test "$cc_is_icc" = "yes"; then
    AC_C_FLAG([-diag-disable 3179])
fi

if test "$enable_werror" = "yes" ; then
  WERROR="-Werror"
fi
AC_SUBST([WERROR])

SAN_FLAGS=""
if test "$enable_address_sanitizer" = "yes"; then
  AC_C_FLAG([-fsanitize=address], [
    AC_MSG_ERROR([$CC does not support Address Sanitizer.])
  ], [
    SAN_FLAGS="$SAN_FLAGS -fsanitize=address"
  ])
fi
if test "$enable_thread_sanitizer" = "yes"; then
  AC_C_FLAG([-fsanitize=thread], [
    AC_MSG_ERROR([$CC does not support Thread Sanitizer.])
  ], [
    SAN_FLAGS="$SAN_FLAGS -fsanitize=thread"
  ])
fi
if test "$enable_memory_sanitizer" = "yes"; then
  AC_C_FLAG([-fsanitize=memory -fPIE -pie], [
    AC_MSG_ERROR([$CC does not support Memory Sanitizer.])
  ], [
    SAN_FLAGS="$SAN_FLAGS -fsanitize=memory -fPIE -pie"
  ])
fi
if test "$enable_undefined_sanitizer" = "yes"; then
  AC_C_FLAG([-fsanitize=undefined], [
    AC_MSG_ERROR([$CC does not support UndefinedBehaviorSanitizer.])
  ], [
    SAN_FLAGS="$SAN_FLAGS -fsanitize=undefined"
  ])
fi
AC_SUBST([SAN_FLAGS])

dnl frr-format.so
if test "$with_frr_format" != "no" -a "$with_frr_format" != "yes" -a -n "$with_frr_format"; then
  AC_C_FLAG([-fplugin=${with_frr_format}], [
    AC_MSG_ERROR([specified frr-format plugin ($with_frr_format) does not work])
  ],,[
#ifndef _FRR_ATTRIBUTE_PRINTFRR
#error plugin not loaded
#endif
#if _FRR_ATTRIBUTE_PRINTFRR < 0x10000
#error plugin too old
#endif
  ])
elif test "$with_frr_format" = "no"; then
  : #nothing
else
  AC_C_FLAG([-fplugin=tools/gcc-plugins/frr-format.so],[
    AC_C_FLAG([-fplugin=frr-format],[
      if test "$with_frr_format" = "yes"; then
        AC_MSG_ERROR([frr-format plugin requested but not found])
      fi
    ],,[
#ifndef _FRR_ATTRIBUTE_PRINTFRR
#error plugin not loaded
#endif
#if _FRR_ATTRIBUTE_PRINTFRR < 0x10000
#error plugin too old
#endif
    ])
  ],,[
#ifndef _FRR_ATTRIBUTE_PRINTFRR
#error plugin not loaded
#endif
#if _FRR_ATTRIBUTE_PRINTFRR < 0x10000
#error plugin too old
#endif
  ])
fi

AC_MSG_CHECKING([whether linker supports __start/stop_section symbols])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
int __attribute__((section("secttest"))) var = 1;
extern int __start_secttest, __stop_secttest;
]], [[
  void *a = &var, *b = &__start_secttest, *c = &__stop_secttest;
  printf("%p %p %p\n", a, b, c);
]])], [
  AC_MSG_RESULT(yes)
  AC_DEFINE(HAVE_SECTION_SYMS, 1, [have __start/stop_section symbols])
], [
  AC_MSG_RESULT(no)
])

dnl ----------
dnl Essentials
dnl ----------

AX_PTHREAD([
  CC="$PTHREAD_CC"
  AC_CFLAGS="$AC_CFLAGS $PTHREAD_CFLAGS"
  LIBS="$PTHREAD_LIBS $LIBS"
], [
  AC_MSG_FAILURE([This FRR version needs pthreads])
])

orig_cflags="$CFLAGS"
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"

AC_SEARCH_LIBS([pthread_condattr_setclock], [],
		[frr_cv_pthread_condattr_setclock=yes],
		[frr_cv_pthread_condattr_setclock=no])
if test "$frr_cv_pthread_condattr_setclock" = "yes"; then
  AC_DEFINE([HAVE_PTHREAD_CONDATTR_SETCLOCK], [1], [Have pthread.h pthread_condattr_setclock])
fi

AC_CHECK_HEADERS([pthread_np.h],,, [
#include <pthread.h>
])
AC_CHECK_FUNCS([pthread_setname_np pthread_set_name_np pthread_getthreadid_np])

CFLAGS="$orig_cflags"

dnl --------------
dnl Check programs
dnl --------------
AC_PROG_INSTALL
AC_PROG_LN_S
AC_CHECK_TOOL([AR], [ar])

dnl -------
dnl libtool
dnl -------
AC_ARG_ENABLE([static-bin],
  AS_HELP_STRING([--enable-static-bin], [link binaries statically]))
LT_INIT
_LT_CONFIG_LIBTOOL([
  patch -N -i "${srcdir}/m4/libtool-whole-archive.patch" libtool >&AS_MESSAGE_LOG_FD || \
    AC_MSG_WARN([Could not patch libtool for static linking support.  Loading modules into a statically linked daemon will fail.])
dnl the -i option is not POSIX sed and the BSDs implement it differently
dnl cat'ing the output back instead of mv/cp keeps permissions on libtool intact
  sed -e 's%func_warning "relinking%true #\0%'                   libtool > libtool.sed && cat libtool.sed > libtool
  sed -e 's%func_warning "remember to run%true #\0%'             libtool > libtool.sed && cat libtool.sed > libtool
  sed -e 's%func_warning ".*has not been installed in%true #\0%' libtool > libtool.sed && cat libtool.sed > libtool
  test -f libtool.sed && rm libtool.sed
])
if test "$enable_static_bin" = "yes"; then
  AC_LDFLAGS_EXEC="-static"
  if test "$enable_static" != "yes"; then
    AC_MSG_ERROR([The --enable-static-bin option must be combined with --enable-static.])
  fi
fi
if test "$enable_shared" != "yes"; then
  AC_MSG_ERROR([FRR cannot be built with --disable-shared.  If you want statically linked daemons, use --enable-shared --enable-static --enable-static-bin])
fi
AC_SUBST([AC_LDFLAGS])
AC_SUBST([AC_LDFLAGS_EXEC])
AM_CONDITIONAL([STATIC_BIN], [test "$enable_static_bin" = "yes"])

dnl libtool, the repository of all knowledge related linkers, is too stupid to
dnl correctly tell the linker how to build modules.
if test -z "$module_cmds"; then
  module_cmds="`echo \"$archive_cmds\" | sed -e 's%$wl-soname $wl$soname%%'`"
fi
if test -z "$module_expsym_cmds"; then
  module_expsym_cmds="`echo \"$archive_expsym_cmds\" | sed -e 's%$wl-soname $wl$soname%%'`"
fi

AC_ARG_ENABLE([rpath],
  [AS_HELP_STRING([--enable-rpath], [set hardcoded rpaths in the executable @<:@default=yes@:>@])],
  [],
  [enable_rpath=yes])

dnl $AR and $RANLIB are set by LT_INIT above
AC_MSG_CHECKING([whether $AR supports D option])
if $AR crD conftest.a >/dev/null 2>/dev/null; then
  AC_MSG_RESULT([yes])
  dnl ARFLAGS is for automake, AR_FLAGS for libtool m-(
  ARFLAGS="crD"
  AR_FLAGS="crD"
else
  AC_MSG_RESULT([no])
  ARFLAGS="cru"
  AR_FLAGS="cru"
fi
AC_SUBST([ARFLAGS])
AC_SUBST([AR_FLAGS])

AC_MSG_CHECKING([whether $RANLIB supports D option])
if $RANLIB -D conftest.a >conftest.err 2>&1; then
  if grep -q -- '-D' conftest.err; then
    AC_MSG_RESULT([no])
  else
    AC_MSG_RESULT([yes])
    RANLIB="$RANLIB -D"
  fi
else
  AC_MSG_RESULT([no])
fi
AC_SUBST([RANLIB])

test -f conftest.err && rm conftest.err
test -f conftest.a && rm conftest.a

dnl ----------------------
dnl Packages configuration
dnl ----------------------
if test -f config.version; then
  . ./config.version
elif test -f "${srcdir}/config.version"; then
  . "${srcdir}/config.version"
fi
AC_ARG_WITH([pkg-extra-version],
  AS_HELP_STRING([--with-pkg-extra-version=VER], [add extra version field, for packagers/distributions]), [
  if test "$withval" = "no"; then
    EXTRAVERSION=
  else
    EXTRAVERSION=$withval
  fi
], [])
AC_ARG_WITH([pkg-git-version],
	AS_HELP_STRING([--with-pkg-git-version], [add git information to MOTD and build version string]),
	[ test "$withval" != "no" && with_pkg_git_version="yes" ])
AC_ARG_WITH([clippy],
  AS_HELP_STRING([--with-clippy=PATH], [use external clippy helper program]))
AC_ARG_WITH([vtysh_pager],
	AS_HELP_STRING([--with-vtysh-pager=PAGER], [control what pager is compiled in as default]),
	VTYSH_PAGER=$withval, VTYSH_PAGER="more")
AC_ARG_ENABLE([vtysh],
  AS_HELP_STRING([--disable-vtysh], [do not build integrated vty shell for FRR]))
AC_ARG_ENABLE([doc],
  AS_HELP_STRING([--disable-doc], [do not build docs]))
AC_ARG_ENABLE([doc-html],
  AS_HELP_STRING([--enable-doc-html], [build HTML docs]))
AC_ARG_ENABLE([zebra],
  AS_HELP_STRING([--disable-zebra], [do not build zebra daemon]))
AC_ARG_ENABLE([bgpd],
  AS_HELP_STRING([--disable-bgpd], [do not build bgpd]))
AC_ARG_ENABLE([mgmtd],
  AS_HELP_STRING([--disable-mgmtd], [do not build mgmtd]))
AC_ARG_ENABLE([mgmtd_local_validations],
  AS_HELP_STRING([--enable-mgmtd-local-validations], [dev: unimplemented local validation]))
AC_ARG_ENABLE([mgmtd_test_be_client],
  AS_HELP_STRING([--enable-mgmtd-test-be-client], [build test backend client]))
AC_ARG_ENABLE([ripd],
  AS_HELP_STRING([--disable-ripd], [do not build ripd]))
AC_ARG_ENABLE([ripngd],
  AS_HELP_STRING([--disable-ripngd], [do not build ripngd]))
AC_ARG_ENABLE([ospfd],
  AS_HELP_STRING([--disable-ospfd], [do not build ospfd]))
AC_ARG_ENABLE([ospf6d],
  AS_HELP_STRING([--disable-ospf6d], [do not build ospf6d]))
AC_ARG_ENABLE([ldpd],
  AS_HELP_STRING([--disable-ldpd], [do not build ldpd]))
AC_ARG_ENABLE([nhrpd],
  AS_HELP_STRING([--disable-nhrpd], [do not build nhrpd]))
AC_ARG_ENABLE([eigrpd],
  AS_HELP_STRING([--disable-eigrpd], [do not build eigrpd]))
AC_ARG_ENABLE([babeld],
  AS_HELP_STRING([--disable-babeld], [do not build babeld]))
AC_ARG_ENABLE([watchfrr],
  AS_HELP_STRING([--disable-watchfrr], [do not build watchfrr]))
AC_ARG_ENABLE([isisd],
  AS_HELP_STRING([--disable-isisd], [do not build isisd]))
AC_ARG_ENABLE([pimd],
  AS_HELP_STRING([--disable-pimd], [do not build pimd]))
AC_ARG_ENABLE([pim6d],
  AS_HELP_STRING([--disable-pim6d], [do not build pim6d]))
AC_ARG_ENABLE([pbrd],
  AS_HELP_STRING([--disable-pbrd], [do not build pbrd]))
AC_ARG_ENABLE([sharpd],
  AS_HELP_STRING([--enable-sharpd], [build sharpd]))
AC_ARG_ENABLE([staticd],
  AS_HELP_STRING([--disable-staticd], [do not build staticd]))
AC_ARG_ENABLE([fabricd],
  AS_HELP_STRING([--disable-fabricd], [do not build fabricd]))
AC_ARG_ENABLE([vrrpd],
  AS_HELP_STRING([--disable-vrrpd], [do not build vrrpd]))
AC_ARG_ENABLE([pathd],
  AS_HELP_STRING([--disable-pathd], [do not build pathd]))
AC_ARG_ENABLE([bgp-announce],
  AS_HELP_STRING([--disable-bgp-announce], [turn off BGP route announcement]))
AC_ARG_ENABLE([bgp-vnc],
  AS_HELP_STRING([--disable-bgp-vnc],[turn off BGP VNC support]))
AC_ARG_ENABLE([bgp-bmp],
  AS_HELP_STRING([--disable-bgp-bmp],[turn off BGP BMP support]))
AC_ARG_ENABLE([snmp],
  AS_HELP_STRING([--enable-snmp], [enable SNMP support for agentx]))
AC_ARG_ENABLE([config_rollbacks],
  AS_HELP_STRING([--enable-config-rollbacks], [enable configuration rollbacks (requires sqlite3)]))
AC_ARG_ENABLE([confd],
  AS_HELP_STRING([--enable-confd=ARG], [enable confd integration]))
AC_ARG_ENABLE([sysrepo],
  AS_HELP_STRING([--enable-sysrepo], [enable sysrepo integration]))
AC_ARG_ENABLE([grpc],
  AS_HELP_STRING([--enable-grpc], [enable the gRPC northbound plugin]))
AC_ARG_ENABLE([zeromq],
  AS_HELP_STRING([--enable-zeromq], [enable ZeroMQ handler (libfrrzmq)]))
AC_ARG_ENABLE([lttng],
  AS_HELP_STRING([--enable-lttng], [enable LTTng tracing]))
AC_ARG_ENABLE([usdt],
  AS_HELP_STRING([--enable-usdt], [enable USDT probes]))
AC_ARG_WITH([libpam],
  AS_HELP_STRING([--with-libpam], [use libpam for PAM support in vtysh]))
AC_ARG_ENABLE([ospfapi],
  AS_HELP_STRING([--disable-ospfapi], [do not build OSPFAPI to access the OSPF LSA Database]))
AC_ARG_ENABLE([ospfclient],
  AS_HELP_STRING([--disable-ospfclient], [do not build OSPFAPI client for OSPFAPI,
                          (this is the default if --disable-ospfapi is set)]))
AC_ARG_WITH([log_timestamp_precision],
  AS_HELP_STRING([--with-log-timestamp-precision=ARG], [set startup log timestamp precision, ARG must be 0-12]))
AC_ARG_ENABLE([multipath],
  AS_HELP_STRING([--enable-multipath=ARG], [enable multipath function, ARG must be digit]))
AC_ARG_WITH([service_timeout],
  AS_HELP_STRING([--with-service-timeout=ARG], [set service timeout value (2 minutes by default), ARG must be digit]))
AC_ARG_ENABLE([user],
  AS_HELP_STRING([--enable-user=USER], [user to run FRR suite as (default frr)]))
AC_ARG_ENABLE([group],
  AS_HELP_STRING([--enable-group=GROUP], [group to run FRR suite as (default frr)]))
AC_ARG_ENABLE([vty_group],
  AS_HELP_STRING([--enable-vty-group=ARG], [set vty sockets to have specified group as owner]))
AC_ARG_ENABLE([configfile_mask],
  AS_HELP_STRING([--enable-configfile-mask=ARG], [set mask for config files]))
AC_ARG_ENABLE([logfile_mask],
  AS_HELP_STRING([--enable-logfile-mask=ARG], [set mask for log files]))
AC_ARG_ENABLE([shell_access],
  AS_HELP_STRING([--enable-shell-access], [Allow users to access shell/telnet/ssh]))
AC_ARG_ENABLE([realms],
  AS_HELP_STRING([--enable-realms], [enable REALMS support under Linux]))
AC_ARG_ENABLE([rtadv],
  AS_HELP_STRING([--disable-rtadv], [disable IPV6 router advertisement feature]))
AC_ARG_ENABLE([irdp],
  AS_HELP_STRING([--enable-irdp], [enable IRDP server support in zebra]))
AC_ARG_ENABLE([capabilities],
  AS_HELP_STRING([--disable-capabilities], [disable using POSIX capabilities]))
AC_ARG_ENABLE([gcc_ultra_verbose],
  AS_HELP_STRING([--enable-gcc-ultra-verbose], [enable ultra verbose GCC warnings]))
AC_ARG_ENABLE([backtrace],
  AS_HELP_STRING([--disable-backtrace], [disable crash backtraces (default autodetect)]))
AC_ARG_ENABLE([pcreposix],
  AS_HELP_STRING([--enable-pcreposix], [enable using PCRE Posix libs for regex functions]))
AC_ARG_ENABLE([pcre2posix],
  AS_HELP_STRING([--enable-pcre2posix], [enable using PCRE2 Posix libs for regex functions]))
AC_ARG_ENABLE([fpm],
  AS_HELP_STRING([--enable-fpm], [enable Forwarding Plane Manager support]))
AC_ARG_ENABLE([werror],
  AS_HELP_STRING([--enable-werror], [enable -Werror (recommended for developers only)]))
AC_ARG_ENABLE([cumulus],
  AS_HELP_STRING([--enable-cumulus], [enable Cumulus Switch Special Extensions]))
AC_ARG_ENABLE([datacenter],
  AS_HELP_STRING([--enable-datacenter], [enable Compilation for Data Center Extensions]))
AC_ARG_ENABLE([protobuf],
  AS_HELP_STRING([--enable-protobuf], [Enable experimental protobuf support]))
AC_ARG_ENABLE([oldvpn_commands],
  AS_HELP_STRING([--enable-oldvpn-commands], [Keep old vpn commands]))
AC_ARG_ENABLE([rpki],
  AS_HELP_STRING([--enable-rpki], [enable RPKI prefix validation support]))
AC_ARG_ENABLE([clippy-only],
  AS_HELP_STRING([--enable-clippy-only], [Only build clippy]))
AC_ARG_ENABLE([numeric_version],
  AS_HELP_STRING([--enable-numeric-version], [Only numeric digits allowed in version (for Alpine)]))
AC_ARG_ENABLE([gcov],
  AS_HELP_STRING([--enable-gcov], [Collect coverage information with gcov]))
AC_ARG_ENABLE([clang_coverage],
  AS_HELP_STRING([--enable-clang-coverage], [Collect coverage information with Clang Coverage]))
AC_ARG_ENABLE([bfdd],
  AS_HELP_STRING([--disable-bfdd], [do not build bfdd]))
AC_ARG_ENABLE([address-sanitizer],
  AS_HELP_STRING([--enable-address-sanitizer], [enable AddressSanitizer support for detecting a wide variety of memory allocation and deallocation errors]))
AC_ARG_ENABLE([thread-sanitizer],
  AS_HELP_STRING([--enable-thread-sanitizer], [enable ThreadSanitizer support for detecting data races]))
AC_ARG_ENABLE([memory-sanitizer],
  AS_HELP_STRING([--enable-memory-sanitizer], [enable MemorySanitizer support for detecting uninitialized memory reads]))
AC_ARG_ENABLE([undefined-sanitizer],
  AS_HELP_STRING([--enable-undefined-sanitizer], [enable UndefinedBehaviorSanitizer support for detecting undefined behavior]))
AC_ARG_WITH([crypto],
  AS_HELP_STRING([--with-crypto=<internal|openssl>], [choose between different implementations of cryptographic functions(default value is --with-crypto=internal)]))
AC_ARG_WITH([frr-format],
  AS_HELP_STRING([--with-frr-format[=<.../frr-format.so>]], [use frr-format GCC plugin]))

AC_ARG_ENABLE([version-build-config],
  AS_HELP_STRING([--disable-version-build-config], [do not include build configs in show version command]))

#if openssl, else use the internal
AS_IF([test "$with_crypto" = "openssl"], [
AC_CHECK_LIB([crypto], [EVP_DigestInit], [LIBS="$LIBS -lcrypto"], [], [])
if test "$ac_cv_lib_crypto_EVP_DigestInit" = "no"; then
  AC_MSG_ERROR([build with openssl has been specified but openssl library was not found on your system])
else
  AC_DEFINE([CRYPTO_OPENSSL], [1], [Compile with openssl support])
fi
], [test "$with_crypto" = "internal" || test "$with_crypto" = "" ], [AC_DEFINE([CRYPTO_INTERNAL], [1], [Compile with internal cryptographic implementation])
], [AC_MSG_ERROR([Unknown value for --with-crypto])]
)

AS_IF([test "$enable_clippy_only" != "yes"], [
AC_CHECK_HEADERS([json-c/json.h])
AC_CHECK_LIB([json-c], [json_object_get], [LIBS="$LIBS -ljson-c"], [], [-lm])
if test "$ac_cv_lib_json_c_json_object_get" = "no"; then
  AC_CHECK_LIB([json], [json_object_get], [LIBS="$LIBS -ljson"])
  if test "$ac_cv_lib_json_json_object_get" = "no"; then
      AC_MSG_ERROR([libjson is needed to compile])
  fi
fi
])

AC_ARG_ENABLE([ccls],
AS_HELP_STRING([--enable-ccls], [Write .ccls config for this build]))

AC_ARG_ENABLE([dev_build],
    AS_HELP_STRING([--enable-dev-build], [build for development]))

AC_ARG_ENABLE([scripting],
    AS_HELP_STRING([--enable-scripting], [Build with scripting support]))

AC_ARG_ENABLE([netlink-debug],
  AS_HELP_STRING([--disable-netlink-debug], [don't pretty print netlink debug messages]))

if test "$enable_netlink_debug" != "no" ; then
  AC_DEFINE([NETLINK_DEBUG], [1], [Netlink extra debugging code])
fi

AM_CONDITIONAL([NETLINK_DEBUG], [test "$enable_netlink_debug" != "no"])

if test "$enable_datacenter" = "yes" ; then
  AC_DEFINE([HAVE_DATACENTER], [1], [Compile extensions for a DataCenter])
  DFLT_NAME="datacenter"
else
  DFLT_NAME="traditional"
fi

if test "$enable_cumulus" = "yes" ; then
  AC_DEFINE([HAVE_CUMULUS], [1], [Compile Special Cumulus Code in])
fi

AC_SUBST([DFLT_NAME])
AC_DEFINE_UNQUOTED([DFLT_NAME], ["$DFLT_NAME"], [Name of the configuration default set])

if test "$enable_shell_access" = "yes"; then
   AC_DEFINE([HAVE_SHELL_ACCESS], [1], [Allow user to use ssh/telnet/bash, be aware this is considered insecure])
fi

#
# Python for clippy
#

AS_IF([test "$host" = "$build"], [
  AM_PATH_PYTHON([3])
  AC_CHECK_HEADER([gelf.h], [], [
    AC_MSG_ERROR([libelf headers are required for building clippy.  (Host only when cross-compiling.)])
  ])

  LIBS_save="$LIBS"
  AC_CHECK_LIB([elf], [elf_memory], [], [
    AC_MSG_ERROR([libelf is required for building clippy.  (Host only when cross-compiling.)])
  ])

  AC_CHECK_LIB([elf], [elf_getdata_rawchunk], [
    AC_DEFINE([HAVE_ELF_GETDATA_RAWCHUNK], [1], [Have elf_getdata_rawchunk()])
  ])
  AC_CHECK_LIB([elf], [gelf_getnote], [
    AC_DEFINE([HAVE_GELF_GETNOTE], [1], [Have gelf_getnote()])
  ])
  LIBS="$LIBS_save"
  unset LIBS_save

  FRR_PYTHON_DEV
], [
  FRR_PYTHON
])

FRR_PYTHON_MODULES([pytest])

if test "$enable_doc" != "no"; then
  FRR_PYTHON_MODULES([sphinx], , [
    if test "$enable_doc" = "yes"; then
      AC_MSG_ERROR([Documentation was explicitly requested with --enable-doc but sphinx is not available for $PYTHON. Please disable docs or install sphinx.])
    fi
  ])
fi
AM_CONDITIONAL([DOC], [test "$enable_doc" != "no" -a "$frr_py_mod_sphinx" != "false"])
AM_CONDITIONAL([DOC_HTML], [test "$enable_doc_html" = "yes"])

FRR_PYTHON_MOD_EXEC([sphinx], [--version], [
  PYSPHINX="-m sphinx"
], [
  PYSPHINX="-c 'import sys; from sphinx import main; sys.exit(main(sys.argv))'"
])
AC_SUBST([PYSPHINX])

#
# Logic for old vpn commands support.
#
if test "$enable_oldvpn_commands" = "yes"; then
   AC_DEFINE([KEEP_OLD_VPN_COMMANDS], [1], [Define for compiling with old vpn commands])
fi

AC_MSG_CHECKING([if zebra should be configurable to send Route Advertisements])
if test "$enable_rtadv" != "no"; then
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_RTADV], [1], [Enable IPv6 Routing Advertisement support])
else
  AC_MSG_RESULT([no])
fi

if test "$enable_user" = "no"; then
  enable_user=""
else
  if test "$enable_user" = "yes" || test "$enable_user" = ""; then
    enable_user="frr"
  fi
  AC_DEFINE_UNQUOTED([FRR_USER], ["${enable_user}"], [frr User])
fi

if test "$enable_group" = "no"; then
  enable_group=""
else
  if test "$enable_group" = "yes" || test "$enable_group" = ""; then
    enable_group="frr"
  fi
  AC_DEFINE_UNQUOTED([FRR_GROUP], ["${enable_group}"], [frr Group])
fi

if test "$enable_vty_group" = "yes" ; then
  AC_MSG_ERROR([--enable-vty-group requires a group as argument, not yes])
elif test "$enable_vty_group" != ""; then
  if test "$enable_vty_group" != "no"; then
    AC_DEFINE_UNQUOTED([VTY_GROUP], ["${enable_vty_group}"], [VTY Sockets Group])
  fi
fi
AC_SUBST([enable_user])
AC_SUBST([enable_group])
AC_SUBST([enable_vty_group])

enable_configfile_mask=${enable_configfile_mask:-0600}
AC_DEFINE_UNQUOTED([CONFIGFILE_MASK], [${enable_configfile_mask}], [Mask for config files])
AC_SUBST([enable_configfile_mask])

enable_logfile_mask=${enable_logfile_mask:-0600}
AC_DEFINE_UNQUOTED([LOGFILE_MASK], [${enable_logfile_mask}], [Mask for log files])

MPATH_NUM=16

case "${enable_multipath}" in
  0)
    MPATH_NUM=64
    ;;
  [[1-9]|[1-9][0-9]|[1-9][0-9][0-9]])
    MPATH_NUM="${enable_multipath}"
    ;;
  "")
    ;;
  *)
    AC_MSG_FAILURE([Please specify digit to enable multipath ARG])
    ;;
esac

AC_DEFINE_UNQUOTED([MULTIPATH_NUM], [$MPATH_NUM], [Maximum number of paths for a route])

case "${with_log_timestamp_precision}" in
[[0-9]|1[012]])
;;
"")
;;
*)
AC_MSG_FAILURE([Please specify a number from 0-12 for log precision ARG])
;;
esac
with_log_timestamp_precision=${with_log_timestamp_precision:-0}
AC_DEFINE_UNQUOTED([LOG_TIMESTAMP_PRECISION], [${with_log_timestamp_precision}], [Startup zlog timestamp precision])

AC_DEFINE_UNQUOTED([VTYSH_PAGER], ["$VTYSH_PAGER"], [What pager to use])

TIMEOUT_MIN=2
case "${with_service_timeout}" in
  [[1-9]|[1-9][0-9]|[1-9][0-9][0-9]])
    TIMEOUT_MIN="${with_service_timeout}"
    ;;
  0|"")
    ;;
  *)
    AC_MSG_FAILURE([Please specify digit for timeout ARG])
    ;;
esac
AC_SUBST([TIMEOUT_MIN])

dnl --------------------
dnl Enable code coverage
dnl --------------------
AM_CONDITIONAL([HAVE_GCOV], [test "$enable_gcov" != "no"])

dnl ------------------------------------
dnl Alpine only accepts numeric versions
dnl ------------------------------------
if test "$enable_numeric_version" != "" ; then
  VERSION="`echo ${VERSION} | tr -c -d '[[.0-9]]'`"
  PACKAGE_VERSION="`echo ${PACKAGE_VERSION} | tr -c -d '[[.0-9]]'`"
fi

dnl -----------------------------------
dnl Add extra version string to package
dnl name, string and version fields.
dnl -----------------------------------
if test "$EXTRAVERSION" != "" ; then
  VERSION="${VERSION}${EXTRAVERSION}"
  PACKAGE_VERSION="${PACKAGE_VERSION}${EXTRAVERSION}"
  AC_SUBST(PACKAGE_EXTRAVERSION, ["${EXTRAVERSION}"])
  PACKAGE_STRING="${PACKAGE_STRING}${EXTRAVERSION}"
fi
AC_SUBST([EXTRAVERSION])

if test "$with_pkg_git_version" = "yes"; then
	if test -e "${srcdir}/.git"; then
		AC_DEFINE([GIT_VERSION], [1], [include git version info])
	else	with_pkg_git_version="no"
		AC_MSG_WARN([--with-pkg-git-version given, but this is not a git checkout])
	fi
fi
AM_CONDITIONAL([GIT_VERSION], [test "$with_pkg_git_version" = "yes"])

AC_CHECK_TOOL([OBJCOPY], [objcopy], [:])
if test "$OBJCOPY" != ":"; then
  AC_CACHE_CHECK([for .interp value to use], [frr_cv_interp], [
    frr_cv_interp=""
    AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])], [
      if $OBJCOPY -j.interp -Obinary conftest conftest.interp; then
        frr_cv_interp="`xargs -0 echo < conftest.interp`"
      fi
      test -f conftest.interp && rm conftest.interp
    ])
  ])
fi
if test -n "$frr_cv_interp"; then
  AC_DEFINE_UNQUOTED([INTERP], ["$frr_cv_interp"], [.interp value])
fi

dnl -------------------------
dnl Check other header files.
dnl -------------------------
AC_CHECK_HEADERS([stropts.h sys/ksym.h \
	linux/version.h asm/types.h endian.h sys/endian.h])

ac_stdatomic_ok=false
AC_DEFINE([FRR_AUTOCONF_ATOMIC], [1], [did autoconf checks for atomic funcs])
AC_CHECK_HEADER([stdatomic.h],[

  AC_MSG_CHECKING([whether _Atomic qualifier works])
  AC_LINK_IFELSE([AC_LANG_SOURCE([[
#include <stdatomic.h>
int main(int argc, char **argv) {
  _Atomic int i = 0;
  return i;
}
]])], [
    AC_DEFINE([HAVE_STDATOMIC_H], [1], [found stdatomic.h])
    AC_MSG_RESULT([yes])
    ac_stdatomic_ok=true
  ], [
    AC_MSG_RESULT([no])
  ])
])

AS_IF([$ac_stdatomic_ok], [true], [
  AC_MSG_CHECKING([for __atomic_* builtins])
  AC_LINK_IFELSE([AC_LANG_SOURCE([[
int main(int argc, char **argv) {
  volatile int i = 1;
  __atomic_store_n (&i, 0, __ATOMIC_RELEASE);
  return __atomic_load_n (&i, __ATOMIC_ACQUIRE);
}
]])], [
    AC_DEFINE([HAVE___ATOMIC], [1], [found __atomic builtins])
    AC_MSG_RESULT([yes])
  ], [
    AC_MSG_RESULT([no])

    dnl FreeBSD 9 has a broken stdatomic.h where _Atomic doesn't work
    AC_MSG_CHECKING([for __sync_* builtins])
    AC_LINK_IFELSE([AC_LANG_SOURCE([[
int main(int argc, char **argv) {
  volatile int i = 1;
  __sync_fetch_and_sub (&i, 1);
  return __sync_val_compare_and_swap (&i, 0, 1);
}
]])], [
      AC_DEFINE([HAVE___SYNC], [1], [found __sync builtins])
      AC_MSG_RESULT([yes])

      AC_MSG_CHECKING([for __sync_swap builtin])
      AC_LINK_IFELSE([AC_LANG_SOURCE([[
int main(int argc, char **argv) {
  volatile int i = 1;
  return __sync_swap (&i, 2);
}
]])], [
        AC_DEFINE([HAVE___SYNC_SWAP], 1, [found __sync_swap builtin])
        AC_MSG_RESULT([yes])
      ], [
        AC_MSG_RESULT([no])
      ])

    ], [
      AC_MSG_RESULT([no])
      AC_MSG_FAILURE([stdatomic.h unavailable and $CC has neither __atomic nor __sync builtins])
    ])
  ])
])

needsync=true

AS_IF([$needsync], [
  dnl Linux
  AC_MSG_CHECKING([for Linux futex() support])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h>
#include <limits.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <linux/futex.h>

int main(void);
],
[
{
  return syscall(SYS_futex, NULL, FUTEX_WAIT, 0, NULL, NULL, 0);
}
])], [
    AC_MSG_RESULT([yes])
    AC_DEFINE(HAVE_SYNC_LINUX_FUTEX,,Have Linux futex support)
    needsync=false
  ], [
    AC_MSG_RESULT([no])
  ])
])

AS_IF([$needsync], [
  dnl FreeBSD
  AC_MSG_CHECKING([for FreeBSD _umtx_op() support])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/umtx.h>
int main(void);
],
[
{
  return _umtx_op(NULL, UMTX_OP_WAIT_UINT, 0, NULL, NULL);
}
])], [
    AC_MSG_RESULT([yes])
    AC_DEFINE(HAVE_SYNC_UMTX_OP,,Have FreeBSD _umtx_op() support)
    needsync=false
  ], [
    AC_MSG_RESULT([no])
  ])
])

AS_IF([$needsync], [
  dnl OpenBSD patch (not upstream at the time of writing this)
  dnl https://marc.info/?l=openbsd-tech&m=147299508409549&w=2
  AC_MSG_CHECKING([for OpenBSD futex() support])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([
#include <sys/futex.h>
int main(void);
],
[
{
  return futex(NULL, FUTEX_WAIT, 0, NULL, NULL, 0);
}
])], [
    AC_MSG_RESULT([yes])
    AC_DEFINE(HAVE_SYNC_OPENBSD_FUTEX,,Have OpenBSD futex support)
    needsync=false
  ], [
    AC_MSG_RESULT([no])
  ])
])

dnl Utility macro to avoid retyping includes all the time
m4_define([FRR_INCLUDES],
[#ifdef SUNOS_5
#define _POSIX_C_SOURCE 200809L
#define __EXTENSIONS__
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <sys/types.h>
/* sys/conf.h depends on param.h on FBSD at least */
#include <sys/param.h>
/* Required for MAXSIG */
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <time.h>
#include <net/if.h>
])dnl

dnl Same applies for HAVE_NET_IF_VAR_H, which HAVE_NETINET6_ND6_H and
dnl HAVE_NETINET_IN_VAR_H depend upon. But if_var.h depends on if.h, hence
dnl an additional round for it.

AC_CHECK_HEADERS([net/if_var.h], [], [], [FRR_INCLUDES])

m4_define([FRR_INCLUDES],
FRR_INCLUDES
[#ifdef HAVE_NET_IF_VAR_H
# include <net/if_var.h>
#endif
])dnl

AC_CHECK_HEADERS([netinet/in_var.h \
	net/if_dl.h net/netopt.h \
	inet/nd.h netinet/ip_icmp.h \
	sys/sysctl.h sys/sockio.h sys/conf.h],
	[], [], [FRR_INCLUDES])

AC_CHECK_HEADERS([ucontext.h], [], [],
[#ifndef __USE_GNU
#define __USE_GNU
#endif /* __USE_GNU */
FRR_INCLUDES
])

m4_define([UCONTEXT_INCLUDES],
[#include <ucontext.h>])dnl

AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.uc_regs],
  [], [], [UCONTEXT_INCLUDES])
AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.regs],
  [AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.regs.nip],
   [], [], [UCONTEXT_INCLUDES])],
  [], [UCONTEXT_INCLUDES])
AC_CHECK_MEMBERS([ucontext_t.uc_mcontext.gregs],
  [], [], [UCONTEXT_INCLUDES])

m4_define([FRR_INCLUDES],
FRR_INCLUDES
[
#include <sys/un.h>
#include <netinet/in_systm.h>
#ifdef HAVE_NETINET_IN_VAR_H
# include <netinet/in_var.h>
#endif
#ifdef HAVE_NET_IF_DL_H
# include <net/if_dl.h>
#endif
#ifdef HAVE_NET_NETOPT_H
# include <net/netopt.h>
#endif
#include <net/route.h>
#ifdef HAVE_INET_ND_H
# include <inet/nd.h>
#endif
#include <arpa/inet.h>
/* Required for IDRP */
#ifdef HAVE_NETINET_IP_ICMP_H
# include <netinet/ip_icmp.h>
#endif
])dnl

dnl V6 headers are checked below, after we check for v6

is_linux=false

AC_MSG_CHECKING([which operating system interface to use])
case "$host_os" in
  sunos* | solaris2*)
    AC_MSG_FAILURE([Solaris support has been removed please see versions prior or equal to 7.5])
    ;;
  linux*)
    AC_MSG_RESULT([Linux])

    AC_DEFINE([GNU_LINUX], [1], [GNU Linux])
    AC_DEFINE([HAVE_NETLINK], [1], [netlink])
    AC_DEFINE([LINUX_IPV6], [1], [Linux IPv6 stack])

    dnl Linux has a compilation problem with mixing
    dnl netinet/in.h and linux/in6.h they are not
    dnl compatible.  There has been discussion on
    dnl how to fix it but no real progress on implementation
    dnl when they fix it, remove this
    AC_DEFINE([IPV6_MINHOPCOUNT], [73], [Linux ipv6 Min Hop Count])

    is_linux=true
    ;;
  openbsd*)
    AC_MSG_RESULT([OpenBSD])

    AC_DEFINE([OPEN_BSD], [1], [OpenBSD])
    AC_DEFINE([KAME], [1], [KAME IPv6])
    AC_DEFINE([BSD_V6_SYSCTL], [1], [BSD v6 sysctl to turn on and off forwarding])
    ;;
  *)
    AC_MSG_RESULT([BSD])

    AC_DEFINE([HAVE_NET_RT_IFLIST], [1], [NET_RT_IFLIST])
    AC_DEFINE([KAME], [1], [KAME IPv6])
    AC_DEFINE([BSD_V6_SYSCTL], [1], [BSD v6 sysctl to turn on and off forwarding])
    ;;
esac
AM_CONDITIONAL([LINUX], [${is_linux}])

AC_SYS_LARGEFILE

dnl ------------------------
dnl Integrated REALMS option
dnl ------------------------
if test "$enable_realms" = "yes"; then
    case "$host_os" in
      linux*)
       AC_DEFINE([SUPPORT_REALMS], [1], [Realms support])
       ;;
      *)
       echo "Sorry, only Linux has REALMS support"
       exit 1
       ;;
    esac
fi

dnl ---------------
dnl other functions
dnl ---------------
AC_CHECK_FUNCS([ \
	strlcat strlcpy \
	getgrouplist \
	openat \
	unlinkat \
	posix_fallocate \
	sendmmsg \
	explicit_bzero \
	])

AC_CHECK_MEMBERS([struct mmsghdr.msg_hdr], [], [], FRR_INCLUDES)

dnl ##########################################################################
dnl LARGE if block spans a lot of "configure"!
if test "$enable_clippy_only" != "yes"; then
dnl ##########################################################################

#
# Logic for protobuf support.
#
PROTO3=false
# Enable Protobuf by default at all times.
# Check for protoc & protoc-c
# protoc is not required, it's only for a "be nice" helper target
AC_CHECK_PROGS([PROTOC], [protoc], [/bin/false])

AC_CHECK_PROGS([PROTOC_C], [protoc-c], [/bin/false])
if test "$PROTOC_C" = "/bin/false"; then
  AC_MSG_FAILURE([protobuf requested but protoc-c not found.  Install protobuf-c.])
fi

PKG_CHECK_MODULES([PROTOBUF_C], [libprotobuf-c >= 1.1.0],, [
  AC_MSG_FAILURE([minimum version (1.1.0) of libprotobuf-c not found.  Install minimum required version of protobuf-c.])
])

if test "$enable_protobuf3" = "yes"; then
  PROTO3=true
  AC_CHECK_HEADER([google/protobuf-c/protobuf-c.h],
                  [AC_CHECK_DECLS(PROTOBUF_C_LABEL_NONE,
                                  AC_DEFINE([HAVE_PROTOBUF_VERSION_3],
                                            [1], [Have Protobuf version 3]),
                                  [PROTO3=false],
                                  [#include <google/protobuf-c/protobuf-c.h>])],
                  [PROTO3=false && AC_MSG_FAILURE([protobuf3 requested but protobuf-c.h not found.  Install protobuf-c.])])
fi

if test "$enable_protobuf" != "no"; then
  AC_DEFINE([HAVE_PROTOBUF], [1], [protobuf])
fi
#
# End of logic for protobuf support.
#


dnl ---------------------
dnl Integrated VTY option
dnl ---------------------
case "${enable_vtysh}" in
"no")
  VTYSH="";;
*)
  VTYSH="vtysh";
  AC_DEFINE([VTYSH], [1], [VTY shell])

  prev_libs="$LIBS"
  AC_CHECK_LIB([readline], [readline], [
    LIBREADLINE="-lreadline"
  ], [
    dnl readline failed - it might be incorrectly linked and missing its
    dnl termcap/tinfo/curses dependency.  see if we can fix that...
    AC_SEARCH_LIBS([tputs], [termcap tinfo curses ncurses], [
      LIBREADLINE="$ac_cv_search_tputs"
    ], [
      AC_MSG_ERROR([libreadline (needed for vtysh) not found and/or missing dependencies])
    ])

    dnl re-try with the lib we found above
    unset ac_cv_lib_readline_main
    AC_CHECK_LIB([readline], [main], [
      LIBREADLINE="-lreadline $LIBREADLINE"
    ], [
      AC_MSG_ERROR([libreadline (needed for vtysh) not found and/or missing dependencies])
    ], [$LIBREADLINE])
  ], [])
  LIBS="$LIBS -lreadline"
  AC_CHECK_FUNCS([rl_clear_visible_line])
  LIBS="$prev_libs"

  AC_CHECK_HEADER([readline/history.h])
  if test "$ac_cv_header_readline_history_h" = "no"; then
    AC_MSG_ERROR([readline is too old to have readline/history.h, please update to the latest readline library.])
  fi
  AC_CHECK_LIB([readline], [rl_completion_matches], [true], [], [$LIBREADLINE])
  if test "$ac_cv_lib_readline_rl_completion_matches" = "no"; then
    AC_DEFINE([rl_completion_matches], [completion_matches], [Old readline])
  fi
  AC_CHECK_LIB([readline], [append_history], [frr_cv_append_history=yes], [frr_cv_append_history=no], [$LIBREADLINE])
  if test "$frr_cv_append_history" = "yes"; then
    AC_DEFINE([HAVE_APPEND_HISTORY], [1], [Have history.h append_history])
  fi
  ;;
esac
AC_SUBST([LIBREADLINE])

dnl ----------
dnl PAM module
dnl
dnl FRR detects the PAM library it is built against by checking for a
dnl functional pam_misc.h (Linux-PAM) or openpam.h (OpenPAM) header. pam_misc.h
dnl is known to #include pam_appl.h, the standard header of a PAM library, and
dnl openpam.h doesn't do that, although depends on the header too. Hence a
dnl little assistance to AC_CHECK_HEADER is necessary for the proper detection
dnl of OpenPAM.
dnl ----------
if test "$with_libpam" = "yes"; then
  AC_CHECK_HEADER([security/pam_misc.h],
    [AC_DEFINE([HAVE_PAM_MISC_H], [1], [Have pam_misc.h])
     AC_DEFINE([PAM_CONV_FUNC], [misc_conv], [Have misc_conv])
     pam_conv_func="misc_conv"
    ],
    [], FRR_INCLUDES)
  AC_CHECK_HEADER([security/openpam.h],
    [AC_DEFINE([HAVE_OPENPAM_H], [1], [Have openpam.h])
     AC_DEFINE([PAM_CONV_FUNC], [openpam_ttyconv], [Have openpam_ttyconv])
     pam_conv_func="openpam_ttyconv"
    ],
    [], FRR_INCLUDES[#include <security/pam_appl.h>])
  if test -z "$ac_cv_header_security_pam_misc_h$ac_cv_header_security_openpam_h" ; then
    AC_MSG_WARN([*** pam support will not be built ***])
    with_libpam="no"
  fi
fi

if test "$with_libpam" = "yes"; then
dnl took this test from proftpds configure.in and suited to our needs
dnl -------------------------------------------------------------------------
dnl
dnl This next check looks funky due to a linker problem with some versions
dnl of the PAM library.  Prior to 0.72 release, the Linux PAM shared library
dnl omitted requiring libdl linking information. PAM-0.72 or better ships
dnl with RedHat 6.2 and Debian 2.2 or better.
AC_CHECK_LIB([pam], [pam_start],
  [AC_CHECK_LIB([pam], [$pam_conv_func],
    [AC_DEFINE([USE_PAM], [1], [Use PAM for authentication])
     LIBPAM="-lpam"],
    [AC_DEFINE([USE_PAM], [1], [Use PAM for authentication])
     LIBPAM="-lpam -lpam_misc"]
    )
  ],

  [AC_CHECK_LIB([pam], [pam_end],
    [AC_CHECK_LIB([pam], [$pam_conv_func],
      [AC_DEFINE([USE_PAM], [1], [Use PAM for authentication])
       LIBPAM="-lpam -ldl"],
      [AC_DEFINE([USE_PAM], [1], [Use PAM for authentication])
       LIBPAM="-lpam -ldl -lpam_misc"]
     )
  ],AC_MSG_WARN([*** pam support will not be built ***]),
  [-ldl])
  ]
)
fi
AC_SUBST([LIBPAM])

dnl -------------------------------
dnl bgpd needs pow() and hence libm
dnl -------------------------------
TMPLIBS="$LIBS"
LIBS=""
AC_SEARCH_LIBS([pow], [m], [
  LIBM="$LIBS"
], [
  AC_MSG_WARN([Unable to find working pow function - bgpd may not link])
])
LIBS="$TMPLIBS"
AC_SUBST([LIBM])

AC_CHECK_FUNCS([ppoll], [
  AC_DEFINE([HAVE_PPOLL], [1], [have Linux/BSD ppoll()])
])
AC_CHECK_FUNCS([pollts], [
  AC_DEFINE([HAVE_POLLTS], [1], [have NetBSD pollts()])
])

AC_CHECK_HEADER([asm-generic/unistd.h],
                [AC_CHECK_DECL(__NR_setns,
                               AC_DEFINE([HAVE_NETNS], [1], [Have netns]),,
                               FRR_INCLUDES [#include <asm-generic/unistd.h>
                               ])
                 AC_CHECK_FUNCS([setns])]
               )

dnl --------------------------
dnl Determine IS-IS I/O method
dnl --------------------------
AC_DEFINE([ISIS_METHOD_PFPACKET], [1], [constant value for isis method pfpacket])
AC_DEFINE([ISIS_METHOD_DLPI], [2], [constant value for isis method dlpi])
AC_DEFINE([ISIS_METHOD_BPF], [3], [constant value for isis method bpf])
AC_CHECK_HEADER([net/bpf.h])
AC_CHECK_HEADER([sys/dlpi.h])
AC_MSG_CHECKING([zebra IS-IS I/O method])

case "$host_os" in
  linux*)
    AC_MSG_RESULT([pfpacket])
    ISIS_METHOD_MACRO="ISIS_METHOD_PFPACKET"
    ;;
  *)
    if test "$ac_cv_header_net_bpf_h" = "no"; then
      if test "$ac_cv_header_sys_dlpi_h" = "no"; then
        AC_MSG_RESULT([none])
        if test "$enable_isisd" = "yes" -o "$enable_fabricd" = "yes"; then
          AC_MSG_FAILURE([IS-IS support requested but no packet backend found])
        fi
        AC_MSG_WARN([*** IS-IS support will not be built ***])
        enable_isisd="no"
        enable_fabricd="no"
      else
        AC_MSG_RESULT([DLPI])
      fi
      ISIS_METHOD_MACRO="ISIS_METHOD_DLPI"
    else
      AC_MSG_RESULT([BPF])
      ISIS_METHOD_MACRO="ISIS_METHOD_BPF"
    fi
    ;;
esac
AC_DEFINE_UNQUOTED([ISIS_METHOD], [$ISIS_METHOD_MACRO], [selected method for isis, == one of the constants])

dnl ---------------------------------------------------------------
dnl figure out how to specify an interface in multicast sockets API
dnl ---------------------------------------------------------------
AC_CHECK_MEMBERS([struct ip_mreqn.imr_ifindex], [], [], FRR_INCLUDES)

AC_CHECK_HEADERS([linux/mroute.h], [], [],[
	#include <sys/socket.h>
	#include <netinet/in.h>
	#define _LINUX_IN_H             /* For Linux <= 2.6.25 */
	#include <linux/types.h>
])

AC_CHECK_HEADERS([linux/mroute6.h], [], [],[
	#include <sys/socket.h>
	#include <netinet/in.h>
	#define _LINUX_IN_H             /* For Linux <= 2.6.25 */
	#include <linux/types.h>
])

m4_define([FRR_INCLUDES],
FRR_INCLUDES
[#ifdef HAVE_LINUX_MROUTE_H
# include <linux/mroute.h>
#endif
])dnl

AC_CHECK_HEADERS([netinet/ip_mroute.h], [], [],[
	#include <sys/socket.h>
	#include <sys/types.h>
	#include <netinet/in.h>
	#include <net/route.h>
])

m4_define([FRR_INCLUDES],
FRR_INCLUDES
[#ifdef HAVE_NETINET_IP_MROUTE_H
# include <netinet/ip_mroute.h>
#endif
])dnl

AC_CHECK_HEADERS([netinet6/ip6_mroute.h], [], [],[
	#include <sys/socket.h>
	#include <sys/param.h>
	#include <sys/types.h>
	#include <netinet/in.h>
	#include <net/route.h>
])

m4_define([FRR_INCLUDES],
FRR_INCLUDES
[#ifdef HAVE_NETINET_IP6_MROUTE_H
# include <netinet6/ip6_mroute.h>
#endif
])dnl

AC_MSG_CHECKING([for RFC3678 protocol-independed API])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
      #include <sys/types.h>
      #include <netinet/in.h>
  ]], [[
      struct group_req gr;
      int sock;
      setsockopt(sock, IPPROTO_IP, MCAST_JOIN_GROUP, (void*)&gr, sizeof(gr));
  ]])
],[
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_RFC3678], [1], [Have RFC3678 protocol-independed API])
],[
  AC_MSG_RESULT(no)
])

dnl ---------------------------------------------------------------
dnl figure out how to check link-state
dnl ---------------------------------------------------------------
AC_CHECK_HEADER([net/if_media.h],
  [m4_define([LINK_DETECT_INCLUDES],
    FRR_INCLUDES
    [#include <net/if_media.h>
  ])
  AC_CHECK_MEMBERS([struct ifmediareq.ifm_status],
    AC_DEFINE([HAVE_BSD_LINK_DETECT], [1], [BSD link-detect]),
    [], LINK_DETECT_INCLUDES)],
  [],
  FRR_INCLUDES)

dnl ---------------------------------------------------------------
dnl Additional, newer way to check link-state using ifi_link_state.
dnl Not available in all BSD's when ifmediareq available
dnl ---------------------------------------------------------------
AC_CHECK_MEMBERS([struct if_data.ifi_link_state],
  AC_DEFINE([HAVE_BSD_IFI_LINK_STATE], [1], [BSD ifi_link_state available]),
  [], FRR_INCLUDES)

dnl ------------------------
dnl TCP_MD5SIG socket option
dnl ------------------------

AC_CHECK_HEADER([netinet/tcp.h],
   [m4_define([MD5_INCLUDES],
      FRR_INCLUDES
      [#include <netinet/tcp.h>
    ])
    AC_CHECK_DECLS([TCP_MD5SIG], [], [], MD5_INCLUDES)],
   [],
   FRR_INCLUDES)
if test "$ac_cv_have_decl_TCP_MD5SIG" = "no"; then
  AC_CHECK_HEADER([linux/tcp.h],
       [m4_define([MD5_INCLUDES],
          FRR_INCLUDES
          [#include <linux/tcp.h>
        ])
       AC_CHECK_DECLS([TCP_MD5SIG], [], [], MD5_INCLUDES)])
fi

LIBS_save="$LIBS"
AC_CHECK_LIB([crypt], [crypt], [], [
  AC_CHECK_LIB([crypto], [DES_crypt])
])
LIBCRYPT="$LIBS"
LIBCRYPT="${LIBCRYPT%$LIBS_save}"
LIBCRYPT="${LIBCRYPT#$LIBS_save}"
AC_SUBST([LIBCRYPT])
LIBS="$LIBS_save"
unset LIBS_save

AC_CHECK_LIB([resolv], [res_init])

dnl ---------------------------
dnl check system has PCRE regexp
dnl ---------------------------
if test "$enable_pcreposix" = "yes"; then
  AC_CHECK_LIB([pcreposix], [regexec], [], [
    AC_MSG_ERROR([--enable-pcreposix given but unable to find libpcreposix])
  ])
fi
AC_SUBST([HAVE_LIBPCREPOSIX])

dnl ---------------------------
dnl check system has PCRE2 regexp
dnl ---------------------------
if test "$enable_pcre2posix" = "yes"; then
  AC_CHECK_LIB([pcre2-posix], [regexec], [], [
    AC_MSG_ERROR([--enable-pcre2posix given but unable to find libpcre2-posix])
  ])
fi
AC_SUBST([HAVE_LIBPCRE2_POSIX])

dnl ##########################################################################
dnl test "$enable_clippy_only" != "yes"
fi
dnl END OF LARGE if block
dnl ##########################################################################

dnl ------------------
dnl check C-Ares library
dnl ------------------
PKG_CHECK_MODULES([CARES], [libcares], [
  c_ares_found=true
],[
  c_ares_found=false
])
AM_CONDITIONAL([CARES], [$c_ares_found])


dnl ----------------------------------------------------------------------------
dnl figure out if domainname is available in the utsname struct (GNU extension).
dnl ----------------------------------------------------------------------------
AC_CHECK_MEMBERS([struct utsname.domainname], [], [], [#include <sys/utsname.h>])

dnl ------------------
dnl IPv6 header checks
dnl ------------------
AC_CHECK_HEADERS([netinet6/in6.h netinet/in6_var.h \
	netinet6/in6_var.h netinet6/nd6.h], [], [],
	FRR_INCLUDES)

m4_define([FRR_INCLUDES],dnl
FRR_INCLUDES
[#ifdef HAVE_NETINET6_IN6_H
#include <netinet6/in6.h>
#endif
#ifdef HAVE_NETINET_IN6_VAR_H
#include <netinet/in6_var.h>
#endif
#include <netinet/icmp6.h>
#ifdef HAVE_NETINET6_IN6_VAR_H
# include <netinet6/in6_var.h>
#endif
#ifdef HAVE_NETINET6_ND6_H
# include <netinet6/nd6.h>
#endif
])dnl

dnl --------------------
dnl Daemon disable check
dnl --------------------

AS_IF([test "$enable_bgpd" != "no"], [
  AC_DEFINE([HAVE_BGPD], [1], [bgpd])
])

AS_IF([test "$enable_mgmtd" != "no"], [

  AC_DEFINE([HAVE_MGMTD], [1], [mgmtd])

  # Enable MGMTD local validations
  AS_IF([test "$enable_mgmtd_local_validations" == "yes"], [
    AC_DEFINE([MGMTD_LOCAL_VALIDATIONS_ENABLED], [1], [Enable mgmtd local validations.])
  ])
])

AS_IF([test "$enable_mgmtd_test_be_client" = "yes"], [
  AC_DEFINE([HAVE_MGMTD_TESTC], [1], [mgmtd_testc])
])

AS_IF([test "$enable_ripd" != "no"], [
  AC_DEFINE([HAVE_RIPD], [1], [ripd])
])

AS_IF([test "$enable_ripngd" != "no"], [
  AC_DEFINE([HAVE_RIPNGD], [1], [ripngd])
])

AS_IF([test "$enable_ospfd" != "no"], [
  AC_DEFINE([HAVE_OSPFD], [1], [ospfd])
])

AS_IF([test "$enable_ospf6d" != "no"], [
  AC_DEFINE([HAVE_OSPF6D], [1], [ospf6d])
])

AS_IF([test "$enable_ldpd" != "no"], [
  AC_DEFINE([HAVE_LDPD], [1], [ldpd])
])

AS_IF([test "$enable_nhrpd" != "no"], [
  AC_DEFINE([HAVE_NHRPD], [1], [nhrpd])
])

AS_IF([test "$enable_eigrpd" != "no"], [
  AC_DEFINE([HAVE_EIGRPD], [1], [eigrpd])
])

AS_IF([test "$enable_babeld" != "no"], [
  AC_DEFINE([HAVE_BABELD], [1], [babeld])
])

AS_IF([test "$enable_isisd" != "no"], [
  AC_DEFINE([HAVE_ISISD], [1], [isisd])
])

AS_IF([test "$enable_pimd" != "no"], [
  AC_DEFINE([HAVE_PIMD], [1], [pimd])
])

AS_IF([test "$enable_pim6d" != "no"], [
  AC_DEFINE([HAVE_PIM6D], [1], [pim6d])
])

AS_IF([test "$enable_pbrd" != "no"], [
  AC_DEFINE([HAVE_PBRD], [1], [pbrd])
])

AS_IF([test "$enable_sharpd" = "yes"], [
  AC_DEFINE([HAVE_SHARPD], [1], [sharpd])
])

AS_IF([test "$enable_staticd" != "no"], [
  AC_DEFINE([HAVE_STATICD], [1], [staticd])
])

AS_IF([test "$enable_fabricd" != "no"], [
  AC_DEFINE([HAVE_FABRICD], [1], [fabricd])
])

AS_IF([test "$enable_vrrpd" != "no"], [
  AC_DEFINE([HAVE_VRRPD], [1], [vrrpd])
])

if test "$enable_bfdd" = "no"; then
  AC_DEFINE([HAVE_BFDD], [0], [bfdd])
  BFDD=""
else
  AC_DEFINE([HAVE_BFDD], [1], [bfdd])
  BFDD="bfdd"

  case $host_os in
    linux*)
      AC_DEFINE([BFD_LINUX], [1], [bfdd])
      ;;

    *)
      AC_DEFINE([BFD_BSD], [1], [bfdd])
      ;;
  esac
fi

AS_IF([test "$enable_pathd" != "no"], [
  AC_DEFINE([HAVE_PATHD], [1], [pathd])
])

if test "$ac_cv_lib_json_c_json_object_get" = "no" -a "$BFDD" = "bfdd"; then
  AC_MSG_ERROR(["you must use json-c library to use bfdd"])
fi

NHRPD=""
case "$host_os" in
  linux*)
    case "${enable_nhrpd}" in
      no)
        ;;
      yes)
	if test "$enable_clippy_only" != "yes"; then
        if test "$c_ares_found" != "true" ; then
          AC_MSG_ERROR([nhrpd requires libcares.  Please install c-ares and its -dev headers.])
        fi
	fi
        NHRPD="nhrpd"
        ;;
      *)
        if test "$c_ares_found" = "true" ; then
          NHRPD="nhrpd"
        fi
        ;;
    esac
    ;;
  *)
    if test "$enable_nhrpd" = "yes"; then
      AC_MSG_ERROR([nhrpd requires kernel APIs that are only present on Linux.])
    fi
    ;;
esac

if test "$enable_watchfrr" = "no";then
  WATCHFRR=""
else
  WATCHFRR="watchfrr"
fi

OSPFCLIENT=""
if test "$enable_ospfapi" != "no";then
    AC_DEFINE([SUPPORT_OSPF_API], [1], [OSPFAPI])

  if test "$enable_ospfclient" != "no";then
      OSPFCLIENT="ospfclient"
  fi
fi

if test "$enable_bgp_announce" = "no";then
  AC_DEFINE([DISABLE_BGP_ANNOUNCE], [1], [Disable BGP installation to zebra])
else
  AC_DEFINE([DISABLE_BGP_ANNOUNCE], [0], [Disable BGP installation to zebra])
fi

if test "$enable_bgp_vnc" != "no";then
  AC_DEFINE([ENABLE_BGP_VNC], [1], [Enable BGP VNC support])
fi

bgpd_bmp=false
case "${enable_bgp_bmp}" in
  no)
    ;;
  yes)
    if test "$c_ares_found" != "true" ; then
      AC_MSG_ERROR([BMP support requires libcares.  Please install c-ares and its -dev headers.])
    fi
    bgpd_bmp=true
    ;;
  *)
    if test "$c_ares_found" = "true" ; then
      bgpd_bmp=true
    fi
    ;;
esac

if test "$enable_version_build_config" != "no";then
  AC_DEFINE([ENABLE_VERSION_BUILD_CONFIG], [1], [Report build configs in show version])
fi

dnl ##########################################################################
dnl LARGE if block
if test "$enable_clippy_only" != "yes"; then
dnl ##########################################################################

dnl ------------------
dnl check Net-SNMP library
dnl ------------------
if test "$enable_snmp" != "" -a "$enable_snmp" != "no"; then
   AC_PATH_TOOL([NETSNMP_CONFIG], [net-snmp-config], [no])
   if test "$NETSNMP_CONFIG" = "no"; then
      AC_MSG_ERROR([--enable-snmp given but unable to find net-snmp-config])
   fi
   SNMP_LIBS="`${NETSNMP_CONFIG} --agent-libs`"
   SNMP_CFLAGS="`${NETSNMP_CONFIG} --base-cflags`"
   # net-snmp lists all of its own dependencies.  we absolutely do not want that
   # among other things we avoid a GPL vs. OpenSSL license conflict here
   for removelib in crypto ssl sensors pci wrap; do
     SNMP_LIBS="`echo $SNMP_LIBS | sed -e 's/\(^\|\s\)-l'$removelib'\b/ /g' -e 's/\(^\|\s\)\([^\s]*\/\)\?lib'$removelib'\.[^\s]\+\b/ /g'`"
   done
   AC_MSG_CHECKING([whether we can link to Net-SNMP])
   AC_LINK_IFELSE_FLAGS([$SNMP_CFLAGS], [$SNMP_LIBS], [AC_LANG_PROGRAM([
int main(void);
],
[
{
  return 0;
}
])], [
     AC_MSG_RESULT([no])
     AC_MSG_ERROR([--enable-snmp given but not usable])])
   case "${enable_snmp}" in
     yes)
      SNMP_METHOD=agentx
      ;;
     agentx)
      SNMP_METHOD="${enable_snmp}"
      ;;
     *)
      AC_MSG_ERROR([--enable-snmp given with an unknown method (${enable_snmp}). Use yes or agentx])
      ;;
   esac
   AH_TEMPLATE([SNMP_AGENTX], [Use SNMP AgentX to interface with snmpd])
   AC_DEFINE_UNQUOTED(AS_TR_CPP(SNMP_${SNMP_METHOD}),,[SNMP method to interface with snmpd])
fi
AC_SUBST([SNMP_LIBS])
AC_SUBST([SNMP_CFLAGS])

dnl ---------------
dnl libyang
dnl ---------------
PKG_CHECK_MODULES([LIBYANG], [libyang >= 2.1.128], , [
AC_MSG_ERROR([m4_normalize([libyang >= 2.1.128 is required, and was not found on your system.
Pleaes consult doc/developer/building-libyang.rst for instructions on installing or building libyang.])])])
ac_cflags_save="$CFLAGS"
CFLAGS="$CFLAGS $LIBYANG_CFLAGS"
AC_CHECK_MEMBER([struct lyd_node.priv], [], [
  AC_MSG_ERROR([m4_normalize([
    libyang needs to be compiled with ENABLE_LYD_PRIV=ON.
    Instructions for this are included in the build documentation for your platform at http://docs.frrouting.org/projects/dev-guide/en/latest/building.html])
  ])
], [[#include <libyang/libyang.h>]])

AC_CHECK_LIB([yang],[lyd_find_xpath3],[],[AC_MSG_ERROR([m4_normalize([
libyang missing lyd_find_xpath3])])])
dnl -- don't add lyd_new_list3 to this list unless bug is fixed upstream
dnl -- https://github.com/CESNET/libyang/issues/2149
AC_CHECK_FUNCS([ly_strerrcode ly_strvecode lyd_trim_xpath])

CFLAGS="$ac_cflags_save"

dnl ---------------
dnl configuration rollbacks
dnl ---------------
SQLITE3=false
if test "$enable_config_rollbacks" = "yes"; then
  PKG_CHECK_MODULES([SQLITE3], [sqlite3], [
    AC_DEFINE([HAVE_CONFIG_ROLLBACKS], [1], [Enable configuration rollbacks])
    AC_DEFINE([HAVE_SQLITE3], [1], [Enable sqlite3 database])
    SQLITE3=true
  ], [
    AC_MSG_ERROR([--enable-config-rollbacks given but sqlite3 was not found on your system.])
  ])
fi

dnl ---------------
dnl confd
dnl ---------------
if test "$enable_confd" != "" -a "$enable_confd" != "no"; then
   AC_CHECK_PROG([CONFD], [confd], [confd], [/bin/false], "${enable_confd}/bin")
   if test "$CONFD" = "/bin/false"; then
      AC_MSG_ERROR([confd was not found on your system.])]
   fi
   AC_CHECK_PROG([CONFDC], [confdc], [confdc], [/bin/false], "${enable_confd}/bin")
   CONFD_CFLAGS="-I${enable_confd}/include -L${enable_confd}/lib"
   AC_SUBST([CONFD_CFLAGS])
   CONFD_LIBS="-lconfd"
   AC_SUBST([CONFD_LIBS])
   AC_DEFINE([HAVE_CONFD], [1], [Enable confd integration])
fi

dnl ---------------
dnl sysrepo
dnl ---------------
if test "$enable_sysrepo" = "yes"; then
  PKG_CHECK_MODULES([SYSREPO], [sysrepo >= 2.1.42],
      [AC_DEFINE([HAVE_SYSREPO], [1], [Enable sysrepo integration])
      SYSREPO=true],
      [SYSREPO=false
      AC_MSG_ERROR([sysrepo was not found on your system.])]
  )
fi

dnl ---------------
dnl gRPC
dnl ---------------
if test "$enable_grpc" = "yes"; then
  AC_LANG_PUSH([C++])
  AX_CXX_COMPILE_STDCXX([11], [ext])
  PKG_CHECK_MODULES([GRPC], [grpc >= 6.0.0 grpc++ >= 1.16.1 protobuf >= 3.6.1 ], [
    AC_CHECK_PROGS([PROTOC], [protoc], [/bin/false])
    if test "$PROTOC" = "/bin/false"; then
      AC_MSG_FAILURE([grpc requested but protoc not found.])
    fi

    AC_DEFINE([HAVE_GRPC], [1], [Enable the gRPC northbound plugin])
    GRPC=true
  ], [
    GRPC=false
    AC_MSG_ERROR([grpc/grpc++ were not found on your system.])
  ])
  AC_LANG_POP([C++])
fi

dnl ---------
dnl DPDK
dnl ---------
if test "$enable_dp_dpdk" = "yes"; then
  PKG_CHECK_MODULES([DPDK], [libdpdk], [
    AC_DEFINE([HAVE_DPDK], [1], [Enable DPDK backend])
    DPDK=true
  ], [
    AC_MSG_ERROR([configuration specifies --enable-dp-dpdk but DPDK libs were not found])
  ])
fi

dnl -----
dnl LTTng
dnl -----
if test "$enable_lttng" = "yes"; then
  PKG_CHECK_MODULES([UST], [lttng-ust >= 2.9.0], [
    AC_DEFINE([HAVE_LTTNG], [1], [Enable LTTng support])
    LTTNG=true
  ], [
    AC_MSG_ERROR([configuration specifies --enable-lttng but lttng-ust was not found])
  ])
fi

dnl ----
dnl USDT
dnl ----
if test "$enable_usdt" = "yes"; then
  AC_CHECK_HEADERS([sys/sdt.h], [
    AC_DEFINE([HAVE_USDT], [1], [Enable USDT probes])
    USDT=true
  ], [
    AC_MSG_ERROR([configuration specifies --enable-usdt but no USDT kernel headers (sys/sdt.h) found])
  ])
fi

dnl ------
dnl ZeroMQ
dnl ------
if test "$enable_zeromq" != "no"; then
  PKG_CHECK_MODULES([ZEROMQ], [libzmq >= 4.0.0], [
    AC_DEFINE([HAVE_ZEROMQ], [1], [Enable ZeroMQ support])
    ZEROMQ=true
  ], [
    if test "$enable_zeromq" = "yes"; then
      AC_MSG_ERROR([configuration specifies --enable-zeromq but libzmq was not found])
    fi
  ])
fi

dnl ------------------------------------
dnl Enable RPKI and add librtr to libs
dnl ------------------------------------
if test "$enable_rpki" = "yes"; then
  PKG_CHECK_MODULES([RTRLIB], [rtrlib >= 0.8.0],
      [RPKI=true],
      [RPKI=false
      AC_MSG_ERROR([rtrlib was not found on your system or is too old.])]
  )
fi

dnl ------------------------------------
dnl pimd and pim6d not supported on OpenBSD and MacOS
dnl ------------------------------------
if test "$enable_pimd" != "no"; then
AC_MSG_CHECKING([for pimd OS support])
case "$host_os" in
  darwin*)
    AC_MSG_RESULT([no])
    enable_pimd="no"
    ;;
  openbsd*)
    AC_MSG_RESULT([no])
    enable_pimd="no"
    ;;
  *)
    AC_MSG_RESULT([yes])
    ;;
esac
fi

if test "$enable_pim6d" != "no"; then
AC_MSG_CHECKING([for pim6d OS support])
case "$host_os" in
  linux*)
    AC_MSG_RESULT([yes])
    ;;
  *)
    AC_MSG_RESULT([no])
    enable_pim6d="no"
    ;;
esac
fi

dnl -------------------------------------
dnl VRRP is only supported on linux
dnl -------------------------------------
if test "$enable_vrrpd" != "no"; then
AC_MSG_CHECKING([for VRRP OS support])
case "$host_os" in
  linux*)
    AC_MSG_RESULT([yes])
    ;;
  *)
    AC_MSG_RESULT([no])
    enable_vrrpd="no"
    ;;
esac
fi

dnl ------------------------------------------
dnl Check whether rtrlib was build with ssh support
dnl ------------------------------------------
AC_MSG_CHECKING([whether the RTR Library is compiled with SSH])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include "rtrlib/rtrlib.h"]],
			[[struct tr_ssh_config config;]])],
	[AC_MSG_RESULT([yes])
	AC_DEFINE([FOUND_SSH], [1], [found_ssh])],
	AC_MSG_RESULT([no])
)

dnl ---------------
dnl dlopen & dlinfo
dnl ---------------
LIBS_save="$LIBS"
AC_SEARCH_LIBS([dlopen], [dl dld], [], [
  AC_MSG_ERROR([unable to find the dlopen()])
])

AC_CHECK_HEADERS([link.h])

AC_CACHE_CHECK([for dlinfo(RTLD_DI_ORIGIN)], [frr_cv_rtld_di_origin], [
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#ifdef HAVE_LINK_H
#include <link.h>
#endif
#include <dlfcn.h>
]], [[
  char origin[1];
  dlinfo (NULL, RTLD_DI_ORIGIN, &origin);
]])], [
    frr_cv_rtld_di_origin=yes
  ], [
    frr_cv_rtld_di_origin=no
  ])
])
if test "$frr_cv_rtld_di_origin" = "yes"; then
  AC_DEFINE([HAVE_DLINFO_ORIGIN], [1], [Have dlinfo RTLD_DI_ORIGIN])
fi

AC_CACHE_CHECK([for dlinfo(RTLD_DI_LINKMAP)], [frr_cv_rtld_di_linkmap], [
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <stdlib.h>
#ifdef HAVE_LINK_H
#include <link.h>
#endif
#include <dlfcn.h>
]], [[
  struct link_map *lm = NULL;
  dlinfo (NULL, RTLD_DI_LINKMAP, &lm);
]])], [
    frr_cv_rtld_di_linkmap=yes
  ], [
    frr_cv_rtld_di_linkmap=no
  ])
])
if test "$frr_cv_rtld_di_linkmap" = "yes"; then
  AC_DEFINE([HAVE_DLINFO_LINKMAP], [1], [Have dlinfo RTLD_DI_LINKMAP])
fi

LIBDL="$LIBS"
LIBDL="${LIBDL%$LIBS_save}"
LIBDL="${LIBDL#$LIBS_save}"
AC_SUBST([LIBDL])
LIBS="$LIBS_save"
unset LIBS_save

dnl ##########################################################################
dnl test "$enable_clippy_only" != "yes"
fi
dnl END OF LARGE if block
dnl ##########################################################################

dnl ---------------------------
dnl sockaddr and netinet checks
dnl ---------------------------
AC_CHECK_TYPES([
	struct sockaddr_dl,
	struct vifctl, struct mfcctl, struct sioc_sg_req,
	vifi_t, struct sioc_vif_req, struct igmpmsg,
	struct ifaliasreq, struct if6_aliasreq, struct in6_aliasreq,
	struct nd_opt_adv_interval,
	struct nd_opt_homeagent_info, struct nd_opt_adv_interval,
	struct nd_opt_rdnss, struct nd_opt_dnssl],
	[], [], FRR_INCLUDES)

AC_CHECK_MEMBERS([struct sockaddr.sa_len,
	struct sockaddr_in.sin_len, struct sockaddr_un.sun_len,
	struct sockaddr_dl.sdl_len,
	struct if6_aliasreq.ifra_lifetime,
	struct nd_opt_adv_interval.nd_opt_ai_type],
	[], [], FRR_INCLUDES)

dnl ---------------------------
dnl IRDP/pktinfo/icmphdr checks
dnl ---------------------------

AC_CHECK_TYPES([struct in_pktinfo], [
  AC_CHECK_TYPES([struct icmphdr], [
    IRDP=true
  ], [
    IRDP=false
  ], [FRR_INCLUDES])
], [
  IRDP=false
], [FRR_INCLUDES])

case "${enable_irdp}" in
yes)
  $IRDP || AC_MSG_ERROR(['IRDP requires in_pktinfo at the moment!'])
  ;;
no)
  IRDP=false
  ;;
*)
  IRDP=false
  ;;
esac


dnl -----------------------
dnl checking for IP_PKTINFO
dnl -----------------------
AC_MSG_CHECKING([for IP_PKTINFO])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
        #include <netdb.h>
   ]], [[
        int opt = IP_PKTINFO;
   ]])
],[
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_IP_PKTINFO], [1], [Have IP_PKTINFO])
],[
  AC_MSG_RESULT([no])
])

dnl ---------------------------
dnl checking for IP_RECVDSTADDR
dnl ---------------------------
AC_MSG_CHECKING([for IP_RECVDSTADDR])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
        #include <netinet/in.h>
  ]], [[
        int opt = IP_RECVDSTADDR;
  ]])
],[
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_IP_RECVDSTADDR], [1], [Have IP_RECVDSTADDR])
],[
  AC_MSG_RESULT([no])
])

dnl ----------------------
dnl checking for IP_RECVIF
dnl ----------------------
AC_MSG_CHECKING([for IP_RECVIF])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
        #include <netinet/in.h>
  ]], [[
        int opt = IP_RECVIF;
  ]])
],[
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_IP_RECVIF], [1], [Have IP_RECVIF])
],[
  AC_MSG_RESULT([no])
])

dnl ----------------------
dnl checking for SO_BINDANY
dnl ----------------------
AC_MSG_CHECKING([for SO_BINDANY])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
        #include <sys/socket.h>
  ]], [[
        int opt = SO_BINDANY;
  ]])
],[
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_SO_BINDANY], [1], [Have SO_BINDANY])
],[
  AC_MSG_RESULT([no])
])

dnl ----------------------
dnl checking for IP_FREEBIND
dnl ----------------------
AC_MSG_CHECKING([for IP_FREEBIND])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
        #include <netinet/in.h>
  ]], [[
        int opt = IP_FREEBIND;
  ]])
],[
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_IP_FREEBIND], [1], [Have IP_FREEBIND])
],[
  AC_MSG_RESULT([no])
])

dnl --------------------------------------
dnl checking for be32dec existence or not
dnl --------------------------------------
AC_CHECK_DECLS([be32enc, be32dec], [], [], [
        #ifdef HAVE_SYS_ENDIAN_H
        #include <sys/endian.h>
        #endif
        #ifdef HAVE_ENDIAN_H
        #include <endian.h>
        #endif
])

dnl --------------------------------------
dnl checking for clock_time monotonic struct and call
dnl --------------------------------------
AC_CHECK_DECL([CLOCK_MONOTONIC],
	[AC_CHECK_LIB([rt], [clock_gettime], [LIBS="$LIBS -lrt"])
	 AC_DEFINE([HAVE_CLOCK_MONOTONIC], [1], [Have monotonic clock])
], [AC_MSG_RESULT([no])], [FRR_INCLUDES])

AC_CHECK_DECL([CLOCK_THREAD_CPUTIME_ID], [
	 AC_DEFINE([HAVE_CLOCK_THREAD_CPUTIME_ID], [1], [Have cpu-time clock])
], [AC_MSG_RESULT([no])], [FRR_INCLUDES])

AC_SEARCH_LIBS([clock_nanosleep], [rt], [
  AC_DEFINE([HAVE_CLOCK_NANOSLEEP], [1], [Have clock_nanosleep()])
])

dnl --------------------------------------
dnl checking for flex and bison
dnl --------------------------------------

dnl autoconf 2.69 AC_PROG_LEX has no parameters
dnl autoconf 2.70 AC_PROG_LEX prints a deprecation warning without params
m4_if(m4_version_compare(m4_defn([AC_AUTOCONF_VERSION]), [2.70]), [-1], [dnl
  dnl autoconf < 2.70
  AC_PROG_LEX
], [
  dnl autoconf >= 2.70
  AC_PROG_LEX([noyywrap])
])

AC_MSG_CHECKING([version of flex])
frr_ac_flex_version="$(eval $LEX -V | grep flex | head -n 1)"
frr_ac_flex_version="${frr_ac_flex_version##* }"
AC_MSG_RESULT([$frr_ac_flex_version])
AX_COMPARE_VERSION([$frr_ac_flex_version], [lt], [2.5.20], [
  LEX="$SHELL $missing_dir/missing flex"
  if test -f "${srcdir}/lib/command_lex.c" -a -f "${srcdir}/lib/command_lex.h"; then
    AC_MSG_WARN([using pregenerated flex output files])
  else
    AC_MSG_ERROR([flex failure and pregenerated files not included (probably a git build)])
  fi
  AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
  AC_SUBST([LEXLIB], [''])
])

AC_PROG_YACC
dnl thanks GNU bison for this b*llshit...
AC_MSG_CHECKING([version of bison])
frr_ac_bison_version="$(eval $YACC -V | grep bison | head -n 1)"
frr_ac_bison_version="${frr_ac_bison_version##* }"
frr_ac_bison_missing="false"
case "x${frr_ac_bison_version}x" in
  x2.7*)
    BISON_OPENBRACE='"'
    BISON_CLOSEBRACE='"'
    BISON_VERBOSE=''
    AC_MSG_RESULT([$frr_ac_bison_version - 2.7 or older])
    ;;
  x2.*|x1.*)
    AC_MSG_RESULT([$frr_ac_bison_version])
    AC_MSG_WARN([installed bison is too old.  Please install GNU bison 2.7.x or newer.])
    frr_ac_bison_missing="true"
    ;;
  x)
    AC_MSG_RESULT([none])
    AC_MSG_WARN([could not determine bison version.  Please install GNU bison 2.7.x or newer.])
    frr_ac_bison_missing="true"
    ;;
  x3.[012][^0-9]*)
    BISON_OPENBRACE='{'
    BISON_CLOSEBRACE='}'
    BISON_VERBOSE='-Dparse.error=verbose'
    AC_MSG_RESULT([$frr_ac_bison_version - 3.0 to 3.2])
    ;;
  *)
    BISON_OPENBRACE='{'
    BISON_CLOSEBRACE='}'
    BISON_VERBOSE='-Dparse.error=verbose -Wno-yacc'
    AC_MSG_RESULT([$frr_ac_bison_version - 3.3 or newer])
    ;;
esac
AC_SUBST([BISON_OPENBRACE])
AC_SUBST([BISON_CLOSEBRACE])
AC_SUBST([BISON_VERBOSE])

if $frr_ac_bison_missing; then
  YACC="$SHELL $missing_dir/missing bison -y"
  if test -f "${srcdir}/lib/command_parse.c" -a -f "${srcdir}/lib/command_parse.h"; then
    AC_MSG_WARN([using pregenerated bison output files])
  else
    AC_MSG_ERROR([bison failure and pregenerated files not included (probably a git build)])
  fi
fi

dnl -------------------
dnl capabilities checks
dnl -------------------
if test "$enable_capabilities" != "no"; then
  AC_MSG_CHECKING([whether prctl PR_SET_KEEPCAPS is available])
  AC_COMPILE_IFELSE(
  [ AC_LANG_PROGRAM([[
        #include <sys/prctl.h>
    ]], [[
        prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
    ]])
  ],[AC_MSG_RESULT([yes])
     AC_DEFINE([HAVE_PR_SET_KEEPCAPS], [1], [prctl])
     frr_ac_keepcaps="yes"
  ],[AC_MSG_RESULT(no)
  ])
  if test "$frr_ac_keepcaps" = "yes"; then
    AC_CHECK_HEADERS([sys/capability.h])
  fi
  if test "$ac_cv_header_sys_capability_h" = "yes"; then
    AC_CHECK_LIB([cap], [cap_init],
      [AC_DEFINE([HAVE_LCAPS], [1], [Capabilities])
       LIBCAP="-lcap"
       frr_ac_lcaps="yes"]
    )
  fi
  if test "$frr_ac_scaps" = "yes" \
       -o "$frr_ac_lcaps" = "yes"; then
    AC_DEFINE([HAVE_CAPABILITIES], [1], [capabilities])
  fi

  case "$host_os" in
  linux*)
    if test "$enable_clippy_only" != "yes"; then
    if test "$frr_ac_lcaps" != "yes"; then
      AC_MSG_ERROR([libcap and/or its headers were not found.  Running FRR without libcap support built in causes a huge performance penalty.])
    fi
    fi
    ;;
  esac
else
  case "$host_os" in
  linux*)
    AC_MSG_WARN([Running FRR without libcap support built in causes a huge performance penalty.])
    ;;
  esac
fi
AC_SUBST([LIBCAP])

dnl ---------------------------
dnl check for glibc 'backtrace'
dnl ---------------------------
if test "$enable_backtrace" != "no" ; then
  backtrace_ok=no
  PKG_CHECK_MODULES([UNWIND], [libunwind], [
    AC_DEFINE([HAVE_LIBUNWIND], [1], [libunwind])
    backtrace_ok=yes
  ], [
    true
  ])

  if test "$backtrace_ok" = "no"; then
    AC_CHECK_HEADER([unwind.h], [
      AC_SEARCH_LIBS([unw_getcontext], [unwind], [
        AC_DEFINE([HAVE_LIBUNWIND], [1], [libunwind])
        backtrace_ok=yes
      ])
    ])
  fi

  if test "$backtrace_ok" = "no"; then
    AC_CHECK_HEADER([execinfo.h], [
      AC_SEARCH_LIBS([backtrace], [execinfo], [
        AC_DEFINE([HAVE_GLIBC_BACKTRACE], [1], [Glibc backtrace])
        backtrace_ok=yes
      ],, [-lm])
    ])
  fi

  if test "$enable_backtrace" = "yes" -a "$backtrace_ok" = "no"; then
    dnl user explicitly requested backtrace but we failed to find support
    AC_MSG_FAILURE([failed to find backtrace or libunwind support])
  fi
fi

dnl -----------------------------------------
dnl check for malloc mallinfo struct and call
dnl this must try and link using LIBS, in
dnl order to check no alternative allocator
dnl has been specified, which might not provide
dnl mallinfo
dnl -----------------------------------------
AC_CHECK_HEADERS([malloc.h malloc_np.h malloc/malloc.h],,, [FRR_INCLUDES])

AC_CACHE_CHECK([whether mallinfo is available], [frr_cv_mallinfo], [
  AC_LINK_IFELSE([AC_LANG_PROGRAM([FRR_INCLUDES [
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_MALLOC_NP_H
#include <malloc_np.h>
#endif
#ifdef HAVE_MALLOC_MALLOC_H
#include <malloc/malloc.h>
#endif
]], [[
struct mallinfo ac_x; ac_x = mallinfo ();
]])], [
    frr_cv_mallinfo=yes
  ], [
    frr_cv_mallinfo=no
  ])
])
if test "$frr_cv_mallinfo" = "yes"; then
  AC_DEFINE([HAVE_MALLINFO], [1], [mallinfo])
fi

AC_CACHE_CHECK([whether mallinfo2 is available], [frr_cv_mallinfo2], [
  AC_LINK_IFELSE([AC_LANG_PROGRAM([FRR_INCLUDES [
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_MALLOC_NP_H
#include <malloc_np.h>
#endif
#ifdef HAVE_MALLOC_MALLOC_H
#include <malloc/malloc.h>
#endif
]], [[
struct mallinfo2 ac_x; ac_x = mallinfo2 ();
]])], [
    frr_cv_mallinfo2=yes
  ], [
    frr_cv_mallinfo2=no
  ])
])
if test "$frr_cv_mallinfo2" = "yes"; then
  AC_DEFINE([HAVE_MALLINFO2], [1], [mallinfo2])
fi

AC_MSG_CHECKING([whether malloc_usable_size is available])
AC_LINK_IFELSE([AC_LANG_PROGRAM([FRR_INCLUDES [
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_MALLOC_MALLOC_H
#include <malloc/malloc.h>
#endif
]], [[
size_t ac_x; ac_x = malloc_usable_size(NULL);
]])], [
  AC_MSG_RESULT([yes])
  AC_DEFINE([HAVE_MALLOC_USABLE_SIZE], [1], [malloc_usable_size])
], [
  AC_MSG_RESULT([no])

  AC_MSG_CHECKING([whether malloc_size is available])
  AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
#ifdef HAVE_MALLOC_MALLOC_H
#include <malloc/malloc.h>
#endif
]], [[
size_t ac_x; ac_x = malloc_size(NULL);
]])], [
    AC_MSG_RESULT([yes])
    AC_DEFINE([HAVE_MALLOC_SIZE], [1], [malloc_size])
  ], [
    AC_MSG_RESULT([no])
  ])
])

dnl ----------
dnl configure date
dnl ----------
dev_version=`echo $VERSION | grep dev`
#don't expire deprecated code in non 'dev' branch
if test "$dev_version" = ""; then
   CONFDATE=0
else
   CONFDATE=`date '+%Y%m%d'`
fi
AC_SUBST([CONFDATE])

dnl get the full path, recursing through variables...
AC_DEFUN([AX_SUBST_EXPANDED], [
  AX_RECURSIVE_EVAL([[$]$1], [e_$1])
  AC_SUBST([e_$1])
])

AX_SUBST_EXPANDED([bindir])
AX_SUBST_EXPANDED([sbindir])
AX_SUBST_EXPANDED([frr_sysconfdir])
AX_SUBST_EXPANDED([frr_runstatedir])
AX_SUBST_EXPANDED([frr_libstatedir])
AX_SUBST_EXPANDED([moduledir])
AX_SUBST_EXPANDED([yangmodelsdir])
AX_SUBST_EXPANDED([scriptdir])

dnl strip duplicate trailing slashes if necessary
dnl note this uses e_bindir / e_sbindir created above
watchfrr_sh="\${e_sbindir%/}/watchfrr.sh"
AX_SUBST_EXPANDED([watchfrr_sh])
vtysh_bin="\${e_bindir%/}/vtysh"
AX_SUBST_EXPANDED([vtysh_bin])

dnl various features
AM_CONDITIONAL([SUPPORT_REALMS], [test "$enable_realms" = "yes"])
AM_CONDITIONAL([ENABLE_BGP_VNC], [test "$enable_bgp_vnc" != "no"])
AM_CONDITIONAL([BGP_BMP], [$bgpd_bmp])
dnl northbound
AM_CONDITIONAL([SQLITE3], [$SQLITE3])
AM_CONDITIONAL([CONFD], [test "$enable_confd" != ""])
AM_CONDITIONAL([SYSREPO], [test "$enable_sysrepo" = "yes"])
AM_CONDITIONAL([GRPC], [test "$enable_grpc" = "yes"])
AM_CONDITIONAL([ZEROMQ], [test "$ZEROMQ" = "true"])
dnl plugins
AM_CONDITIONAL([RPKI], [test "$RPKI" = "true"])
AM_CONDITIONAL([SNMP], [test "$SNMP_METHOD" = "agentx"])
AM_CONDITIONAL([IRDP], [$IRDP])
AM_CONDITIONAL([FPM], [test "$enable_fpm" = "yes"])
AM_CONDITIONAL([HAVE_PROTOBUF], [test "$enable_protobuf" != "no"])
AM_CONDITIONAL([HAVE_PROTOBUF3], [$PROTO3])

dnl PCEP plugin
AS_IF([test "$enable_pathd" != "no"], [
       AC_SUBST([PATHD_PCEP_LIBS], ["pceplib/libpcep_pcc.la"])
       AC_SUBST([PATHD_PCEP_INCL], ["-I./pceplib "])
       ])
AC_CHECK_LIB([cunit], [CU_initialize_registry], [pcep_cunit=yes],[pcep_cunit=no])
AM_CONDITIONAL([PATHD_PCEP_TEST], [test "x${pcep_cunit}" = xyes])
AC_CHECK_PROG(VALGRIND_CHECK, valgrind, yes)
AM_CONDITIONAL([HAVE_VALGRIND_PCEP], [test "$VALGRIND_CHECK" = "yes"])

dnl daemons
AM_CONDITIONAL([VTYSH], [test "$VTYSH" = "vtysh"])
AM_CONDITIONAL([ZEBRA], [test "$enable_zebra" != "no"])
AM_CONDITIONAL([BGPD], [test "$enable_bgpd" != "no"])
AM_CONDITIONAL([MGMTD], [test "$enable_mgmtd" != "no"])
AM_CONDITIONAL([MGMTD_TESTC], [test "$enable_mgmtd_test_be_client" = "yes"])
AM_CONDITIONAL([RIPD], [test "$enable_ripd" != "no"])
AM_CONDITIONAL([OSPFD], [test "$enable_ospfd" != "no"])
AM_CONDITIONAL([LDPD], [test "$enable_ldpd" != "no"])
AM_CONDITIONAL([BFDD], [test "$BFDD" = "bfdd"])
AM_CONDITIONAL([NHRPD], [test "$NHRPD" = "nhrpd"])
AM_CONDITIONAL([EIGRPD], [test "$enable_eigrpd" != "no"])
AM_CONDITIONAL([WATCHFRR], [test "$WATCHFRR" = "watchfrr"])
AM_CONDITIONAL([OSPFCLIENT], [test "$OSPFCLIENT" = "ospfclient"])
AM_CONDITIONAL([RIPNGD], [test "$enable_ripngd" != "no"])
AM_CONDITIONAL([BABELD], [test "$enable_babeld" != "no"])
AM_CONDITIONAL([OSPF6D], [test "$enable_ospf6d" != "no"])
AM_CONDITIONAL([ISISD], [test "$enable_isisd" != "no"])
AM_CONDITIONAL([PIMD], [test "$enable_pimd" != "no"])
AM_CONDITIONAL([PIM6D], [test "$enable_pim6d" != "no"])
AM_CONDITIONAL([PBRD], [test "$enable_pbrd" != "no"])
AM_CONDITIONAL([SHARPD], [test "$enable_sharpd" = "yes"])
AM_CONDITIONAL([STATICD], [test "$enable_staticd" != "no"])
AM_CONDITIONAL([FABRICD], [test "$enable_fabricd" != "no"])
AM_CONDITIONAL([VRRPD], [test "$enable_vrrpd" != "no"])
AM_CONDITIONAL([PATHD], [test "$enable_pathd" != "no"])
AM_CONDITIONAL([PATHD_PCEP], [test "$enable_pathd" != "no"])
AM_CONDITIONAL([DP_DPDK], [test "$enable_dp_dpdk" = "yes"])

AC_CONFIG_FILES([Makefile],[
	test "$enable_dev_build" = "yes" && makefile_devbuild="--dev-build"
	${PYTHON} "${ac_abs_top_srcdir}/python/makefile.py" ${makefile_devbuild} || exit 1
], [
	PYTHON="$PYTHON"
	enable_dev_build="$enable_dev_build"
])

AC_CONFIG_FILES([
	  config.version
	  redhat/frr.spec
	  alpine/APKBUILD
	  snapcraft/snapcraft.yaml
	  lib/version.h
	  lib/config_paths.h
	  tests/lib/cli/test_cli.refout pkgsrc/mgmtd.sh
	  pkgsrc/bgpd.sh pkgsrc/ospf6d.sh pkgsrc/ospfd.sh
	  pkgsrc/ripd.sh pkgsrc/ripngd.sh pkgsrc/zebra.sh
	  pkgsrc/eigrpd.sh])

AC_CONFIG_FILES([tools/frr], [chmod +x tools/frr])
AC_CONFIG_FILES([tools/watchfrr.sh], [chmod +x tools/watchfrr.sh])
AC_CONFIG_FILES([tools/frrinit.sh], [chmod +x tools/frrinit.sh])
AC_CONFIG_FILES([tools/frrcommon.sh])
AC_CONFIG_FILES([tools/frr.service])
AC_CONFIG_FILES([tools/frr@.service])

# dnl write out a ccls file with our compile configuration
# dnl have to add -Wno-unused-function otherwise foobar_cmd_magic causes
# dnl all DEFPY(), et al., macros to flag as errors.
AS_IF([test "$enable_ccls" = "yes"], [
    AC_CONFIG_COMMANDS([gen-dot-ccls], [
        cat > "${srcdir}/.ccls" <<EOF
clang
-DHAVE_CONFIG_H
-I.
-I./include
-I./lib
-I./lib/assert
-DSYSCONFDIR="${ac_frr_sysconfdir}"
-DCONFDATE=${ac_frr_confdate}
EOF
        if test "$ac_abs_top_builddir" != "$ac_abs_top_srcdir"; then
            echo "-I${ac_abs_top_builddir}" >> "${srcdir}/.ccls"
        fi
        if test -n "$FRR_ALL_CCLS_FLAGS"; then
            echo ${FRR_ALL_CCLS_FLAGS} | tr ' ' '\n' >> "${srcdir}/.ccls"
        fi
        if test -n "$FRR_ALL_CCLS_CFLAGS"; then
            cat >> "${srcdir}/.ccls" <<EOF
%c $(echo ${FRR_ALL_CCLS_CFLAGS} | sed -e 's/  */\n%c /g')
%c -Wno-unused-function
%c -Wno-microsoft
EOF
fi
    ], [
    FRR_ALL_CCLS_FLAGS="$(echo ${LIBYANG_CFLAGS} ${LUA_INCLUDE} ${SQLITE3_CFLAGS} | sed -e 's/  */ /g')"
    FRR_ALL_CCLS_CFLAGS="$(echo ${CFLAGS} ${WERROR} ${AC_CFLAGS} ${SAN_FLAGS} | sed -e 's/  */ /g')"
    ac_frr_confdate="${CONFDATE}"
    ac_frr_sysconfdir="${frr_sysconfdir}/"
    ])
])


AS_IF([test "$with_pkg_git_version" = "yes"], [
    AC_CONFIG_COMMANDS([lib/gitversion.h], [
	dst="${ac_abs_top_builddir}/lib/gitversion.h"
	${PERL} "${ac_abs_top_srcdir}/lib/gitversion.pl" \
		"${ac_abs_top_srcdir}" \
		> "${dst}.tmp"
	test -f "$dst" \
		&& diff "${dst}.tmp" "${dst}" >/dev/null 2>/dev/null \
		&& rm "${dst}.tmp" \
		|| mv "${dst}.tmp" "${dst}"
    ], [
	PERL="$PERL"
    ])
])

## Hack, but working solution to avoid rebuilding of frr.info.
## It's already in CVS until texinfo 4.7 is more common.
AC_OUTPUT

if test "$enable_rpath" = "yes" ; then
	true
else
	# See https://old-en.opensuse.org/openSUSE:Packaging_Guidelines#Removing_Rpath
	sed -e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool > libtool.sed && cat libtool.sed > libtool
	sed -e 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g'         libtool > libtool.sed && cat libtool.sed > libtool
	test -f libtool.sed && rm libtool.sed
fi

echo "
FRRouting configuration
------------------------------
FRR version             : ${PACKAGE_VERSION}
host operating system   : ${host_os}
source code location    : ${srcdir}
compiler                : ${CC}
compiler flags          : ${CFLAGS} ${WERROR} ${AC_CFLAGS} ${SAN_FLAGS}
make                    : ${MAKE-make}
linker flags            : ${LDFLAGS} ${SAN_FLAGS} ${LIBS} ${LIBCAP} ${LIBREADLINE} ${LIBM}
state file directory    : ${e_frr_runstatedir}
config file directory   : ${e_frr_sysconfdir}
module directory        : ${e_moduledir}
script directory        : ${e_scriptdir}
user to run as          : ${enable_user}
group to run as         : ${enable_group}
group for vty sockets   : ${enable_vty_group}
config file mask        : ${enable_configfile_mask}
log file mask           : ${enable_logfile_mask}
zebra protobuf enabled  : ${enable_protobuf:-no}
vici socket path        : ${vici_socket}

The above user and group must have read/write access to the state file
directory and to the config files in the config file directory."

if test -n "$enable_datacenter"; then
  AC_MSG_WARN([The --enable-datacenter compile time option is deprecated.  Please modify the init script to pass -F datacenter to the daemons instead.])
fi

if test "$enable_doc" != "no" -a "$frr_py_mod_sphinx" = "false"; then
  AC_MSG_WARN([sphinx is missing but required to build documentation])
fi
if test "$frr_py_mod_pytest" = "false"; then
  AC_MSG_WARN([pytest is missing, unit tests cannot be performed])
fi

if $path_warn_banner; then
  AC_MSG_WARN([^])
  AC_MSG_WARN([^])
  AC_MSG_WARN([^ warnings regarding system path configuration were printed at the very top of output])
  AC_MSG_WARN([^ paths have been adjusted by temporary workarounds])
  AC_MSG_WARN([^ please fix your ./configure invocation (remove /frr) so it will work without the workarounds])
fi